📄 buinessquerydialog.cpp
字号:
strValue = (LPCSTR)_bstr_t(var);
m_BuinessMerList.SetItemText (index, 3, strValue);
BuinessTotalPrice += (float)_variant_t(strValue);
var = m_pRecordsetSMer->GetCollect ("PowerName");
strValue = (LPCSTR)_bstr_t(var);
m_BuinessMerList.SetItemText (index, 4, strValue);
index++;
m_pRecordsetSMer->MoveNext ();
}
m_BuinessTotalPrice = (LPCSTR)_bstr_t(BuinessTotalPrice);
UpdateData(FALSE);
}//if
m_pRecordsetSMer->Close ();
m_pRecordsetSMer = NULL;
}//try
catch(_com_error &e)
{
AfxMessageBox(e.ErrorMessage ());
*pResult = 0;
return;
}
*pResult = 0;
}
void CBuinessQueryDialog::OnLvnItemActivateListBusinessmerlist(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMITEMACTIVATE pNMIA = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
int sel = m_BuinessList.GetSelectionMark ();
CString MerName = m_BuinessMerList.GetItemText (sel, 0);
HRESULT hrMerG;
_RecordsetPtr m_pRecordsetMerG;
try
{
hrMerG = m_pRecordsetMerG.CreateInstance (__uuidof(Recordset));
if(FAILED(hrMerG))
{
AfxMessageBox (_T("创建实例失败!"));
*pResult = 0;
return;
}
CString strSQL;
strSQL.Format ("select * from MerGroupbyGoodsTable where MerchandiseName = '%s'", MerName);
hrMerG = m_pRecordsetMerG->Open (_bstr_t(strSQL),
m_pConnection.GetInterfacePtr(),
adOpenDynamic,
adLockOptimistic,
adCmdText);
if(SUCCEEDED(hrMerG))
{
_variant_t var;
CString strValue;
int index = 0;
if(m_BuinessGoodsList.GetItemCount())
m_BuinessGoodsList.DeleteAllItems();
while(!m_pRecordsetMerG->adoEOF)
{
var = m_pRecordsetMerG->GetCollect ("GoodsName");
strValue = (LPCSTR)_bstr_t(var);
m_BuinessGoodsList.InsertItem (index, strValue);
var = m_pRecordsetMerG->GetCollect ("Units");
strValue = (LPCSTR)_bstr_t(var);
m_BuinessGoodsList.SetItemText (index, 1, strValue);
var = m_pRecordsetMerG->GetCollect ("GoodsNum");
strValue = (LPCSTR)_bstr_t(var);
m_BuinessGoodsList.SetItemText (index, 2, strValue);
index++;
m_pRecordsetMerG->MoveNext ();
}
m_pRecordsetMerG->Close ();
m_pRecordsetMerG = NULL;
}//if
}//if
catch(_com_error &e)
{
AfxMessageBox(e.ErrorMessage());
*pResult = 0;
return;
}
*pResult = 0;
}
//void CBuinessQueryDialog::OnBnClickedButton2()
//{
// // TODO: 在此添加控件通知处理程序代码
//}
void CBuinessQueryDialog::OnBnClickedButtonBusinesstoexcel()
{
UpdateData(TRUE);
HRESULT hrAS;
_RecordsetPtr m_pRecordsetAS;
try
{
hrAS = m_pRecordsetAS.CreateInstance (__uuidof (Recordset));
if(FAILED(hrAS))
{
AfxMessageBox (_T("创建实例失败!"));
return;
}
CString strSQL, OperateName,time;
m_BuinessOperatorName.GetWindowText (OperateName);
m_BusinessData.GetWindowText (time);
if( m_BusinessNum =="" && OperateName == "")
{
strSQL.Format ("select * from ActionSaleTable where ActionDate = '%s'", time);
}
else if(m_BusinessNum =="" && OperateName != "")
{
strSQL.Format ("select * from ActionSaleTable where OperatorName = '%s' and \
ActionDate = '%s'", OperateName,time);
}
else
strSQL.Format ("select * from ActionSaleTable where listNum = '%s' and ActionDate = '%s'",
m_BusinessNum, time);
hrAS = m_pRecordsetAS->Open (_bstr_t(strSQL),
m_pConnection.GetInterfacePtr(),
adOpenDynamic,
adLockOptimistic,
adCmdText);
if(m_pRecordsetAS->adoEOF)
{
MessageBox(_T("没有任何数据,不能导出!"), _T("交易查询"), MB_ICONERROR | MB_OK);
m_pRecordsetAS->Close ();
m_pRecordsetAS = NULL;
return;
}
}
catch(_com_error &e)
{
AfxMessageBox (e.ErrorMessage());
return;
}
m_pRecordsetAS->Close ();
m_pRecordsetAS = NULL;
char strDirectory[100];
memset(strDirectory,0,100);
GetCurrentDirectory(100,strDirectory);
CFileDialog dlg (FALSE, _T ("xls"), m_strPathName,
OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY,
m_szFilters );
if (dlg.DoModal () == IDOK)
if (SaveFile (dlg.GetPathName ()))
{ m_strPathName = dlg.GetPathName ();
MessageBox(_T("导出信息成功!"), _T("交易查询"), MB_ICONASTERISK | MB_OK);
}
SetCurrentDirectory(strDirectory);
}
BOOL CBuinessQueryDialog::SaveFile (LPCSTR pszFile)
{
UpdateData(TRUE);
BOOL nResult = FALSE;
HRESULT hrAS;
_RecordsetPtr m_pRecordsetAS;
try
{
hrAS = m_pRecordsetAS.CreateInstance (__uuidof (Recordset));
if(FAILED(hrAS))
{
AfxMessageBox (_T("创建实例失败!"));
return nResult;
}
CString strSQL, OperateName,time;
m_BuinessOperatorName.GetWindowText (OperateName);
m_BusinessData.GetWindowText (time);
if( m_BusinessNum =="" && OperateName == "")
{
strSQL.Format ("select * from ActionSaleTable where ActionDate = '%s'", time);
}
else if(m_BusinessNum =="" && OperateName != "")
{
strSQL.Format ("select * from ActionSaleTable where OperatorName = '%s' and \
ActionDate = '%s'", OperateName,time);
}
else
strSQL.Format ("select * from ActionSaleTable where listNum = '%s' and ActionDate = '%s'",
m_BusinessNum, time);
hrAS = m_pRecordsetAS->Open (_bstr_t(strSQL),
m_pConnection.GetInterfacePtr(),
adOpenDynamic,
adLockOptimistic,
adCmdText);
if(m_BuinessList.GetItemCount())
m_BuinessList.DeleteAllItems ();
if(!m_pRecordsetAS->adoEOF)
{
_variant_t var;
CString strValue;
int index = 0;
CStdioFile file (pszFile, CFile::modeWrite | CFile::modeCreate);
CString string = "";
string += _T("交易单号");
string += '\t';
string += _T("交易日期");
string += '\t';
string += _T("交易时间");
string += '\t';
string += _T("操作员");
string += '\t';
string += _T("交易金额");
string += '\t';
string += _T("被退单号");
string += '\t';
string += _T("原价");
string += '\t';
string += '\n';
file.WriteString (string);
while(!m_pRecordsetAS->adoEOF)
{
string = "";
var = m_pRecordsetAS->GetCollect ("listNum");
strValue = (LPCSTR)_bstr_t(var);
m_BuinessList.InsertItem ( index, strValue);
string += strValue;
string += '\t';
var = m_pRecordsetAS->GetCollect ("ActionDate");
strValue = (LPCSTR)_bstr_t(var);
m_BuinessList.SetItemText (index, 1, strValue);
string += strValue;
string += '\t';
var = m_pRecordsetAS->GetCollect ("ActionTime");
strValue = (LPCSTR)_bstr_t(var);
m_BuinessList.SetItemText (index, 2, strValue);
string += strValue;
string += '\t';
var = m_pRecordsetAS->GetCollect ("OperatorName");
strValue = (LPCSTR)_bstr_t(var);
m_BuinessList.SetItemText (index, 3, strValue);
string += strValue;
string += '\t';
var = m_pRecordsetAS->GetCollect ("AllSaleNum");
strValue = (LPCSTR)_bstr_t(var);
m_BuinessList.SetItemText (index, 4, strValue);
string += strValue;
string += '\t';
var = m_pRecordsetAS->GetCollect ("listNum");
strValue = (LPCSTR)_bstr_t(var);
m_BuinessList.SetItemText (index, 5, strValue);
string += strValue;
string += '\t';
var = m_pRecordsetAS->GetCollect ("FormerPrice");
strValue = (LPCSTR)_bstr_t(var);
m_BuinessList.SetItemText (index, 6, strValue);
string += strValue;
string += '\t';
index++;
m_pRecordsetAS->MoveNext ();
file.WriteString (string);
}//while
m_pRecordsetAS->Close ();
m_pRecordsetAS = NULL;
}//if
else{
MessageBox(_T("没有任何数据,不能导出!"), _T("交易查询"), MB_ICONERROR | MB_OK);
return nResult;
}
}
catch(_com_error &e)
{
AfxMessageBox (e.ErrorMessage());
return nResult;
}
nResult = TRUE;
return nResult;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -