📄 totalpaydlg.cpp
字号:
m_listmsg.SetItemText(numline,0,(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("a"));
m_listmsg.SetItemText(numline,1,(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("b"));
m_listmsg.SetItemText(numline,2,(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("c"));
numline++;
m_pRecordset->MoveNext();
}
}
m_pRecordset->Close();
}
catch(_com_error e)///捕捉异常
{
CString temp;
temp.Format("连接数据库错误信息:%s",e.ErrorMessage());
AfxMessageBox(temp);
return;
}
}
void CTotalPayDlg::OnStudy()
{
// TODO: Add your command handler code here
m_listmsg.SetBkColor(RGB(240,247,233));
m_listmsg.SetTextBkColor(RGB(240,247,233));
//清空list控件的数据
for(int delcolumn=100;delcolumn>=0;delcolumn--)
m_listmsg.DeleteColumn(delcolumn);
//设置list对话框的列
DWORD dwStyle;
RECT rect;
LV_COLUMN lvc;
dwStyle = m_listmsg.GetStyle();
dwStyle |= LVS_EX_GRIDLINES |LVS_EX_FULLROWSELECT|LVS_SHOWSELALWAYS ;
m_listmsg.SetExtendedStyle(dwStyle);
m_listmsg.GetClientRect(&rect);
lvc.mask = LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH |LVCF_FMT;
lvc.fmt=LVCFMT_LEFT;
lvc.iSubItem = 0;
lvc.pszText = _T(" 姓 名");
lvc.cx = 200;
m_listmsg.InsertColumn(1,&lvc);
lvc.iSubItem = 1;
lvc.pszText = _T(" 开支类型");
lvc.cx = 400;
m_listmsg.InsertColumn(2,&lvc);
lvc.iSubItem = 2;
lvc.pszText = _T(" 开支金额");
lvc.cx = 400;
m_listmsg.InsertColumn(3,&lvc);
CString sql;
sql = "select name as a,paytype as b,sum(money) as c "
" from total "
" where name ='" + theApp.name+"'"
+"group by name, paytype";
m_listmsg.DeleteAllItems();
int numline=0;
try
{
m_pRecordset.CreateInstance("ADODB.Recordset");
m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
if(m_pRecordset->adoEOF)
{
AfxMessageBox("还没有任何开支!");
}
else
{
LV_ITEM lvitem;
lvitem.pszText="";
lvitem.mask=LVIF_TEXT;
lvitem.iSubItem=0;
while(!m_pRecordset->adoEOF)
{
lvitem.iItem=numline;
m_listmsg.InsertItem(&lvitem);
//读出数据写入到list中
m_listmsg.SetItemText(numline,0,(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("a"));
m_listmsg.SetItemText(numline,1,(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("b"));
m_listmsg.SetItemText(numline,2,(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("c"));
numline++;
m_pRecordset->MoveNext();
}
}
m_pRecordset->Close();
}
catch(_com_error e)///捕捉异常
{
CString temp;
temp.Format("连接数据库错误信息:%s",e.ErrorMessage());
AfxMessageBox(temp);
return;
}
}
void CTotalPayDlg::OnTotal()
{
// TODO: Add your command handler code here
m_listmsg.SetBkColor(RGB(240,247,233));
m_listmsg.SetTextBkColor(RGB(240,247,233));
//清空list控件的数据
for(int delcolumn=100;delcolumn>=0;delcolumn--)
m_listmsg.DeleteColumn(delcolumn);
//设置list对话框的列
DWORD dwStyle;
RECT rect;
LV_COLUMN lvc;
dwStyle = m_listmsg.GetStyle();
dwStyle |= LVS_EX_GRIDLINES |LVS_EX_FULLROWSELECT|LVS_SHOWSELALWAYS ;
m_listmsg.SetExtendedStyle(dwStyle);
m_listmsg.GetClientRect(&rect);
lvc.mask = LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH |LVCF_FMT;
lvc.fmt=LVCFMT_LEFT;
lvc.iSubItem = 0;
lvc.pszText = _T(" 姓 名");
lvc.cx = 200;
m_listmsg.InsertColumn(1,&lvc);
lvc.iSubItem = 1;
lvc.pszText = _T(" 总开支");
lvc.cx = 400;
m_listmsg.InsertColumn(2,&lvc);
CString sql;
sql = "select name as a,sum(money) as b "
" from total"
" where name ='" + theApp.name+"'"
+"group by name";
m_listmsg.DeleteAllItems();
int numline=0;
try
{
m_pRecordset.CreateInstance("ADODB.Recordset");
m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
if(m_pRecordset->adoEOF)
{
AfxMessageBox("还没有任何开支!");
}
else
{
LV_ITEM lvitem;
lvitem.pszText="";
lvitem.mask=LVIF_TEXT;
lvitem.iSubItem=0;
while(!m_pRecordset->adoEOF)
{
lvitem.iItem=numline;
m_listmsg.InsertItem(&lvitem);
//读出数据写入到list中
m_listmsg.SetItemText(numline,0,(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("a"));
m_listmsg.SetItemText(numline,1,(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("b"));
numline++;
m_pRecordset->MoveNext();
}
}
m_pRecordset->Close();
}
catch(_com_error e)///捕捉异常
{
CString temp;
temp.Format("连接数据库错误信息:%s",e.ErrorMessage());
AfxMessageBox(temp);
return;
}
}
void CTotalPayDlg::OnRegister()
{
// TODO: Add your command handler code here
CRegister dlg;
dlg.DoModal();
}
void CTotalPayDlg::OnLogonAdmin()
{
CLogonAdmin dlg;
dlg.DoModal();
// TODO: Add your command handler code here
}
int CTotalPayDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialog::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
CSplashWnd::ShowSplashScreen(this);
return 0;
}
void CTotalPayDlg::OnIn()
{
try
{
CString sql2;
sql2 = "delete * from photo where name = '"+theApp.name +"'";
_variant_t RecordsAffected;
theApp.m_pConnection->Execute((_bstr_t)sql2,&RecordsAffected,adCmdText);
m_pRecordset4.CreateInstance("ADODB.Recordset");
CString sql = "SELECT * FROM photo where name = '"+theApp.name +"'";
m_pRecordset4->Open((_bstr_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
}
catch(_com_error e)///捕捉异常
{
AfxMessageBox("读取数据库失败!");///显示错误信息
}
CFile f;
CString FilePathName;
CFileException e;
CFileDialog dlg(TRUE,NULL,NULL,0,"jpg Files (*.jpg)|*.jpg||",this);///TRUE为OPEN对话框,FALSE为SAVE AS对话框
if(dlg.DoModal()==IDOK)
{
FilePathName=dlg.GetPathName();
if(m_Pic.m_IPicture != NULL) m_Pic.FreePictureData(); // Important - Avoid Leaks...
if(f.Open(FilePathName, CFile::modeRead | CFile::typeBinary, &e)) //打开了一个jpg文件
{
int nSize = f.GetLength(); //先得到jpg文件长度
BYTE * pBuffer = new BYTE [nSize]; //按文件的大小在堆上申请一块内存
if (f.Read(pBuffer, nSize) > 0 ) //把jpg文件读到pBuffer(堆上申请一块内存)
{ // +----------------------------------------------
BYTE *pBuf = pBuffer; ///下面这一大段是把pBuffer里的jpg数据放到库中
VARIANT varBLOB;
SAFEARRAY *psa;
SAFEARRAYBOUND rgsabound[1];
CString username;
username = theApp.name ;
m_pRecordset3->AddNew();
m_pRecordset3->PutCollect("name",_variant_t(username));
if(pBuf)
{
rgsabound[0].lLbound = 0;
rgsabound[0].cElements = nSize;
psa = SafeArrayCreate(VT_UI1, 1, rgsabound);
for (long i = 0; i < (long)nSize; i++)
SafeArrayPutElement (psa, &i, pBuf++);
varBLOB.vt = VT_ARRAY | VT_UI1;
varBLOB.parray = psa;
m_pRecordset3->GetFields()->GetItem("photo")->AppendChunk(varBLOB);
}
m_pRecordset3->Update();
(m_Pic.LoadPictureData(pBuffer, nSize));//接作调用函数读pBuffer的jpg数据准备显示
delete [] pBuffer; //删掉堆上申请的那一块内存
pBuf=0; //以防二次乱用
}
f.Close();
}
CClientDC dc(this);
m_Pic.UpdateSizeOnDC(&dc); // Get Picture Dimentions In Pixels
// m_Pic.Show(&dc, CRect(200,0,200+m_Pic.m_Width,m_Pic.m_Height) );//显示出来看看
}
}
void CTotalPayDlg::OnOut()
{
// TODO: Add your control notification handler code here
try
{
long nSize = m_pRecordset3->GetFields()->GetItem("photo")->ActualSize;
if(nSize > 0)
{
_variant_t varBLOB;
varBLOB = m_pRecordset3->GetFields()->GetItem("photo")->GetChunk(nSize);
if(varBLOB.vt == (VT_ARRAY | VT_UI1))
{
if(BYTE *pBuffer = new BYTE [nSize+1]) ///重新申请必要的存储空间
{
char *pBuf = NULL;
SafeArrayAccessData(varBLOB.parray,(void **)&pBuf);
memcpy(pBuffer,pBuf,nSize); ///复制数据到缓冲区m_pBMPBuffer
SafeArrayUnaccessData (varBLOB.parray);
// int nSize = lDataSize;
(m_Pic.LoadPictureData(pBuffer, nSize));
delete [] pBuffer;
pBuf=0;
///生成BITMAP对象
CClientDC dc(this);
m_Pic.UpdateSizeOnDC(&dc); // Get Picture Dimentions In Pixels
m_Pic.Show(&dc, CRect(1,461,108,660) );
//m_Pic.Show(&dc, CRect(0,500,m_Pic.m_Width,500+m_Pic.m_Height) );
}
}
}
}
catch (_com_error e) {
}
}
void CTotalPayDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
try
{
m_pRecordset3.CreateInstance("ADODB.Recordset");
CString sql = "SELECT * FROM photo where name = '"+theApp.name +"'";
m_pRecordset3->Open((_bstr_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
}
catch(_com_error e)///捕捉异常
{
AfxMessageBox("读取数据库失败!");///显示错误信息
}
if(theApp.name!="")
{
GetDlgItem(IDC_IN)->EnableWindow(true);
m_photo.ShowWindow(SW_HIDE);
try
{
long nSize = m_pRecordset3->GetFields()->GetItem("photo")->ActualSize;
if(nSize > 0)
{
_variant_t varBLOB;
varBLOB = m_pRecordset3->GetFields()->GetItem("photo")->GetChunk(nSize);
if(varBLOB.vt == (VT_ARRAY | VT_UI1))
{
if(BYTE *pBuffer = new BYTE [nSize+1]) ///重新申请必要的存储空间
{
char *pBuf = NULL;
SafeArrayAccessData(varBLOB.parray,(void **)&pBuf);
memcpy(pBuffer,pBuf,nSize); ///复制数据到缓冲区m_pBMPBuffer
SafeArrayUnaccessData (varBLOB.parray);
// int nSize = lDataSize;
(m_Pic.LoadPictureData(pBuffer, nSize));
delete [] pBuffer;
pBuf=0;
///生成BITMAP对象
CClientDC dc(this);
m_Pic.UpdateSizeOnDC(&dc); // Get Picture Dimentions In Pixels
m_Pic.Show(&dc, CRect(1,463,101,588) );
//m_Pic.Show(&dc, CRect(0,500,m_Pic.m_Width,500+m_Pic.m_Height) );
}
}
}
else
{
m_photo.ShowWindow(SW_SHOW);
}
}
catch (_com_error e) {
}
}
CDialog::OnTimer(nIDEvent);
}
void CTotalPayDlg::OnGo()
{
// TODO: Add your control notification handler code here
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -