📄 商品库存管理系统.cpp
字号:
// 商品库存管理系统.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "商品库存管理系统.h"
#include "MainDlg.h"
#include "DLogin.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMyApp
BEGIN_MESSAGE_MAP(CMyApp, CWinApp)
//{{AFX_MSG_MAP(CMyApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyApp construction
CMyApp::CMyApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CMyApp object
CMyApp theApp;
_ConnectionPtr cnn;
CString UserName;
/////////////////////////////////////////////////////////////////////////////
// CMyApp initialization
BOOL CMyApp::InitInstance()
{
AfxEnableControlContainer();
::CoInitialize(NULL);
cnn=NULL;
cnn.CreateInstance(__uuidof(Connection));
cnn->ConnectionString="uid=admin;pwd=111;DRIVER={Microsoft Access Driver (*.mdb)};DBQ=spkc.mdb;";
cnn->Open(L"",L"",L"",adCmdUnspecified);
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
CDlogin dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}
void CMyApp::ADOError(_RecordsetPtr ADORecordset)
{
ErrorsPtr pErrors=cnn->GetErrors();
for (int i=0;i<pErrors->GetCount();i++)
{
_bstr_t desc=pErrors->GetItem((long)i)->GetDescription();
AfxMessageBox(desc);
}
}
int CMyApp::GetRecordCount(_RecordsetPtr rRecord)
{
int recordcount=0;
try{
rRecord->MoveFirst();
}
catch(...)
{
return 0;
}
if(rRecord->_EOF)
return 0;
while (!rRecord->_EOF)
{
rRecord->MoveNext();
recordcount=recordcount+1;
}
return recordcount;
}
CString CMyApp::AutoNumber(CString TableName, CString sLater, int nflg)
{
CTime _time,_CurrentTime;
CString MaxNumber,_sDay,_sYear,_sMonth,NewNumber,ReturnNumber,sSQL;
int _Day,_Year,_Month;
_RecordsetPtr AutoNumber_Rst;
AutoNumber_Rst.CreateInstance(__uuidof(Recordset));
::CoInitialize(NULL);
_variant_t value;
if(sLater.GetLength()>2)
sLater=sLater.Left(2);
if(nflg==1)
{
sSQL.Format("SELECT MAX(编号) as 最大编号 FROM %s",TableName);
AutoNumber_Rst = cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
value=AutoNumber_Rst->GetCollect("最大编号");
if(value.vt==VT_NULL)
{
ReturnNumber.Format("%s00000001",sLater);
}
else
{
MaxNumber=(char*)(_bstr_t)value;
MaxNumber=MaxNumber.Mid(3);
NewNumber.Format("%d",atoi(MaxNumber)+1);
ReturnNumber.Format("%s%s",sLater,this->Padl(NewNumber,8,"0"));
}
}
else
{
_time=_CurrentTime.GetCurrentTime();
_Year=_time.GetYear();
_Month=_time.GetMonth();
_Day=_time.GetDay();
_sDay.Format("%d",_Day);
_sDay=this->Padl(_sDay,2,"0");
_sMonth.Format("%d",_Month);
_sMonth=this->Padl(_sMonth,2,"0");
_sYear.Format("%d",_Year);
_sYear=_sYear.Mid(2);
sSQL.Format("SELECT MAX(票号) as 最大编号 FROM %s",TableName);
AutoNumber_Rst = cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
if(AutoNumber_Rst->_EOF)
{
ReturnNumber.Format("%s%s%s%s-000001 ",sLater,_sYear,_sMonth,_sDay);
goto retu;
}
value=AutoNumber_Rst->GetCollect("最大编号");//取出最大编号
if(value.vt==VT_NULL)
{
ReturnNumber.Format("%s%s%s%s-000001 ",sLater,_sYear,_sMonth,_sDay);
}
else
{
CString sOldDate,sNewDate;
sOldDate=(char*)(_bstr_t)value;
sOldDate=sOldDate.Mid(2,6);
sNewDate.Format("%s%s%s",_sYear,_sMonth,_sDay);
if(sOldDate==sNewDate)
{
MaxNumber.Format((char*)(_bstr_t)value);
MaxNumber=MaxNumber.Mid(9);
NewNumber.Format("%d",atoi(MaxNumber)+1);
ReturnNumber.Format("%s%s%s%s-%s",sLater,_sYear,_sMonth,_sDay,this->Padl(NewNumber,6,"0"));
}
else
{
ReturnNumber.Format("%s%s%s%s-000001 ",sLater,_sYear,_sMonth,_sDay);
}
}
}
retu: AutoNumber_Rst->Close();
return ReturnNumber;
}
int CMyApp::NumberTOName(CString TableName, CString field, CString value)
{
_RecordsetPtr NumberTOName_rst;
CString cSQL;
_bstr_t val;
int backnumber=0;
NumberTOName_rst.CreateInstance(__uuidof(Recordset));
cSQL.Format("SELECT * FROM %s WHERE %s='%s'",TableName,field,value);
NumberTOName_rst=cnn->Execute((_bstr_t)cSQL,NULL,adCmdText);
if(NumberTOName_rst->_EOF)
goto end;
else
{
val=NumberTOName_rst->GetCollect("编号");
backnumber=atoi((char*)(_bstr_t)val);
}
end: NumberTOName_rst->Close();
return backnumber;
}
CString CMyApp::NumberTOName(CString TableName, CString Returnfield, CString field, CString value, int nflg)
{
_RecordsetPtr NumberTOName_rst2;
CString cSQL,backnumber;
_bstr_t val;
NumberTOName_rst2.CreateInstance(__uuidof(Recordset));
cSQL.Format("SELECT * FROM %s WHERE %s='%s'",TableName,field,value);
NumberTOName_rst2=cnn->Execute((_bstr_t)cSQL,NULL,adCmdText);
if(NumberTOName_rst2->_EOF)
backnumber.Format("WRONG");
else
{
if(nflg==1)
{
val=NumberTOName_rst2->GetCollect("编号");
}
else
{
val=NumberTOName_rst2->GetCollect((_variant_t)Returnfield);
}
backnumber.Format((char*)(_bstr_t)val);
}
NumberTOName_rst2->Close();
return backnumber;
}
CString CMyApp::CharToLetterCode(CString string)
{
unsigned short i; //无符号短整型
CString value,ReturnValue;
char chr[3];
BYTE bHeight;
BYTE bLow;
for(int m=0;m<=string.GetLength()-1;m=m+2)
{
if(m%2!=0)
{
if(m<string.GetLength()-1)
m=m+1;
}
chr[0]=string.GetAt(m);
if((((BYTE)chr[0]>=0x20&&(BYTE)chr[0]<=0x80)||(BYTE)chr[0]==0xbf))
{
int StringLength=string.GetLength();
if(m+1<StringLength)
{
chr[1]=string.GetAt(m+1);
if(chr[1]<0)
{
chr[2]=0;
bHeight=chr[1];
bLow=chr[0];
i=bHeight+bLow*256;
if(i==((unsigned short)'科'))
value.Format("%s","K");
}
else
{
chr[1]=0;
chr[2]=0;
value.Format("");
m++;
}
}
else
{
chr[1]=0;
chr[2]=0;
value.Format("");
m++;
}
}
else
{
chr[1]=string.GetAt(m+1);
chr[2]=0;
bHeight=chr[1];
bLow=chr[0];
i=bHeight+bLow*256;
if(i < (unsigned short)'啊')
value.Format("%s ",chr);
if( i>= (unsigned short)'啊'&& i<(unsigned short)'芭')
value.Format("A");
if( i>= (unsigned short)'芭'&& i<(unsigned short)'擦')
value.Format("B");
if( i>= (unsigned short)'擦'&& i<(unsigned short)'搭')
value.Format("C");
if( i>= (unsigned short)'搭'&& i<(unsigned short)'蛾')
value.Format("D");
if( i>= (unsigned short)'蛾'&& i<(unsigned short)'发')
value.Format("E");
if( i>= (unsigned short)'发'&& i<(unsigned short)'噶')
value.Format("F");
if( i>= (unsigned short)'噶'&& i<(unsigned short)'哈')
value.Format("G");
if( i>= (unsigned short)'哈'&& i<(unsigned short)'击')
value.Format("H");
if(( i>= (unsigned short)'击'&& i<(unsigned short)'喀')|| i==(unsigned short)'科')
value.Format("J");
if( i>= (unsigned short)'喀'&& i<(unsigned short)'垃')
value.Format("K");
if( i>= (unsigned short)'垃'&& i<(unsigned short)'妈')
value.Format("L");
if( i>= (unsigned short)'妈'&& i<(unsigned short)'拿')
value.Format("M");
if( i>= (unsigned short)'拿'&& i<(unsigned short)'哦')
value.Format("N");
if( i>= (unsigned short)'哦'&& i<(unsigned short)'啪')
value.Format("O");
if( i>= (unsigned short)'啪'&& i<(unsigned short)'期')
value.Format("P");
if( i>= (unsigned short)'期'&& i<(unsigned short)'然')
value.Format("Q");
if( i>= (unsigned short)'然'&& i<(unsigned short)'撒')
value.Format("R");
if( i>= (unsigned short)'撒'&& i<(unsigned short)'塌')
value.Format("S");
if( i>= (unsigned short)'塌'&& i<(unsigned short)'挖')
value.Format("T");
if( i>= (unsigned short)'挖'&& i<(unsigned short)'昔')
value.Format("W");
if( i>= (unsigned short)'昔'&& i<(unsigned short)'压')
value.Format("X");
if( i>= (unsigned short)'压'&& i<(unsigned short)'匝')
value.Format("Y");
if( i>= (unsigned short)'匝' && i!=(unsigned short)'炜' && i!=(unsigned short)'馨' && i!=(unsigned short)'懿')
value.Format("Z");
}
ReturnValue=ReturnValue+value;
}
return ReturnValue;
}
int CMyApp::AutoNumber(int nflg, CString TableName)
{
_RecordsetPtr AutoNumber_Rst2;
AutoNumber_Rst2.CreateInstance(__uuidof(Recordset));
CString sSQL;
_variant_t value;
int nNumber=1;
sSQL.Format("SELECT MAX(编号) as 最大编号 FROM %s",TableName);
AutoNumber_Rst2 = cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
value=AutoNumber_Rst2->GetCollect("最大编号");
if(value.vt==VT_NULL)
{
nNumber=1;
}
else
{
nNumber=atoi((char*)(_bstr_t)value)+1;
}
AutoNumber_Rst2->Close();
return nNumber;
}
CString CMyApp::Padl(CString String, int digit, CString Fill, int Way)
{
int Padl_n;
CString Padl_string;
Padl_string.Empty();
for(Padl_n=1;Padl_n<=digit-String.GetLength();Padl_n++)
{
Padl_string=Padl_string+Fill;
}
if(Way==1)
return Padl_string+String;
else
return String+Padl_string;
}
CTime CMyApp::CStringTOCTime(CString cDate)
{
int nYear,nMonth,nDay;
char cYear[5],cMonth[3],cDay[3];
CTime tDate;
cYear[0]=cDate.GetAt(0);
cYear[1]=cDate.GetAt(1);
cYear[2]=cDate.GetAt(2);
cYear[3]=cDate.GetAt(3);
cYear[4]=NULL;
cMonth[0]=cDate.GetAt(5);
cMonth[1]=cDate.GetAt(6);
cMonth[2]=NULL;
cDay[0]=cDate.GetAt(8);
cDay[1]=cDate.GetAt(9);
cDay[2]=NULL;
nYear=atoi(&cYear[0]);
nMonth=atoi(&cMonth[0]);
nDay=atoi(&cDay[0]);
tDate=CTime::CTime(nYear,nMonth,nDay,0,0,0);
return tDate;
}
CString CMyApp::CTimeToCString(CTime date)
{
int nYear,nMonth,nDay;
CString sMonth,sDay,sDate;
nYear=date.GetYear();
nMonth=date.GetMonth();
nDay=date.GetDay();
sMonth.Format("%d",nMonth);
sMonth=theApp.Padl(sMonth,2,"0");
sDay.Format("%d",nDay);
sDay=theApp.Padl(sDay,2,"0");
sDate.Format("%d-%s-%s",nYear,sMonth,sDay);
return sDate;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -