📄 productloseform.cpp
字号:
if(formID<10)
m_productLoseFormID.Format("CPBS0000%d",formID);
else if(formID<100&&formID>9)
m_productLoseFormID.Format("CPBS000%d",formID);
else if(formID<1000&&formID>99)
m_productLoseFormID.Format("CPBS00%d",formID);
CString str;
str.Format("%d",formID+1);
((CStoreApp*)AfxGetApp())->m_pIDRecordset->PutCollect("productLoseFormID",_variant_t(str));
((CStoreApp*)AfxGetApp())->m_pIDRecordset->Update();
m_list.DeleteAllItems();
m_storeHouseLose = _T("");
m_houseOutType = _T("");
m_formDate = COleDateTime::GetCurrentTime();
m_remark = _T("");
m_dealer="";
is_search=0;
flag=1;
UpdateData(false);
}
void CProductLoseForm::OnModify()
{
flag=2;
bt_add->EnableWindow(false);
bt_delete->EnableWindow(false);
bt_save->EnableWindow(true);
bt_modify->EnableWindow(false);
bt_addLine->EnableWindow(true);
bt_deleteLine->EnableWindow(true);
tx_storeHouseLose->EnableWindow(true);
tx_houseOutType->EnableWindow(true);
tx_formDate->EnableWindow(true);
tx_remark->EnableWindow(true);
tx_dealer->EnableWindow(true);
}
void CProductLoseForm::OnDelete()
{
CAffirm dlg;
if(dlg.DoModal()!=IDOK)
{
return;
}
_variant_t RecordsAffected;
CString strSQL;
strSQL="delete from productLoseForm where productLoseFormID='";
strSQL=strSQL+m_productLoseFormID+"'";
(((CStoreApp*)AfxGetApp())->m_pConn)->Execute((_bstr_t)strSQL,&RecordsAffected,adCmdText);
m_list.DeleteAllItems();
UpdateData(false);
AfxMessageBox("该单已删除!");
tx_storeHouseLose->EnableWindow(false);
tx_houseOutType->EnableWindow(false);
tx_formDate->EnableWindow(false);
tx_remark->EnableWindow(false);
tx_dealer->EnableWindow(false);
m_productLoseFormID = _T("");
m_storeHouseLose = _T("");
m_houseOutType = _T("");
m_formDate = COleDateTime::GetCurrentTime();
m_remark = _T("");
bt_modify->EnableWindow(false);
bt_delete->EnableWindow(false);
is_search=0;
flag=1;
UpdateData(false);
}
void CProductLoseForm::OnAddLine()
{
CSelectProduct dlg;
if(dlg.DoModal()==IDOK)
{
float total=dlg.m_num*dlg.m_price;
int i=m_list.GetItemCount();
CString str;
m_list.InsertItem(i,dlg.m_productID);
m_list.SetItemText(i,1,dlg.m_productName);
m_list.SetItemText(i,2,dlg.m_unit);
m_list.SetItemText(i,3,dlg.m_model);
str.Format("%d",dlg.m_num);
m_list.SetItemText(i,4,str);
str.Format("%f",dlg.m_price);
m_list.SetItemText(i,5,str);
str.Format("%f",total);
m_list.SetItemText(i,6,str);
}
}
void CProductLoseForm::OnDeleteLine()
{
CAffirm dlg;
if(dlg.DoModal()!=IDOK)
{
return;
}
POSITION pos = m_list.GetFirstSelectedItemPosition();
if(pos)
{
int nFirstSelItem = m_list.GetNextSelectedItem(pos);
m_list.DeleteItem(nFirstSelItem);
}
}
void CProductLoseForm::OnSave()
{
UpdateData(true);
CString strSQL;
_RecordsetPtr m_pRecordset; //用于创建一个查询记录集
_RecordsetPtr m_pProductLoseFormRecordset;
strSQL="select * from productLoseForm";
HRESULT hTRes;
hTRes = m_pProductLoseFormRecordset.CreateInstance(_T("ADODB.Recordset"));
hTRes = m_pProductLoseFormRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
((CStoreApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
if(flag==1) //添加
{
m_pProductLoseFormRecordset->AddNew();
m_pProductLoseFormRecordset->PutCollect("productLoseFormID",_variant_t(m_productLoseFormID.Left(25)));
m_pProductLoseFormRecordset->PutCollect("formDate",_variant_t(m_formDate));
m_pProductLoseFormRecordset->PutCollect("storeHouse",_variant_t(m_storeHouseLose.Left(50)));
m_pProductLoseFormRecordset->PutCollect("dealer",_variant_t(m_dealer.Left(50)));
m_pProductLoseFormRecordset->PutCollect("houseOutType",_variant_t(m_houseOutType.Left(50)));
m_pProductLoseFormRecordset->PutCollect("remark",_variant_t(m_remark.Left(100)));
m_pProductLoseFormRecordset->Update();
strSQL="SELECT * FROM productLoseFormCommidity" ;
try
{
hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
if (SUCCEEDED(hTRes))
{
hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
((CStoreApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
if(SUCCEEDED(hTRes))
{
TRACE(_T("连接成功!\n"));
for(int i=0;i<m_list.GetItemCount();i++)
{
m_pRecordset->AddNew();
m_pRecordset->PutCollect("productLoseFormID",_variant_t(m_productLoseFormID.Left(25)));
m_pRecordset->PutCollect("productID",_variant_t(m_list.GetItemText(i,0).Left(25)));
m_pRecordset->PutCollect("num",_variant_t(m_list.GetItemText(i,4)));
m_pRecordset->PutCollect("price",_variant_t(m_list.GetItemText(i,5)));
m_pRecordset->Update();
}
AfxMessageBox("保存成功!");
}
}
}
catch(_com_error e)///捕捉异常
{
CString errormessage;
MessageBox("创建记录集失败!","错误");
}
}
else if(flag==2) //修改
{
_variant_t RecordsAffected;
CString strSQL;
strSQL="delete from productLoseFormCommidity where productLoseFormID='";
strSQL=strSQL+m_productLoseFormID+"'";
(((CStoreApp*)AfxGetApp())->m_pConn)->Execute((_bstr_t)strSQL,&RecordsAffected,adCmdText);
m_pProductLoseFormRecordset->Update();
strSQL="SELECT * FROM productLoseFormCommidity" ;
try
{
HRESULT hTRes;
hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
if (SUCCEEDED(hTRes))
{
hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
((CStoreApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
if(SUCCEEDED(hTRes))
{
TRACE(_T("连接成功!\n"));
for(int i=0;i<m_list.GetItemCount();i++)
{
m_pRecordset->AddNew();
m_pRecordset->PutCollect("productLoseFormID",_variant_t(m_productLoseFormID.Left(25)));
m_pRecordset->PutCollect("productID",_variant_t(m_list.GetItemText(i,0).Left(25)));
m_pRecordset->PutCollect("num",_variant_t(m_list.GetItemText(i,4)));
m_pRecordset->PutCollect("price",_variant_t(m_list.GetItemText(i,5)));
m_pRecordset->Update();
}
AfxMessageBox("保存成功!");
}
}
}
catch(_com_error e)///捕捉异常
{
CString errormessage;
MessageBox("创建记录集失败!","错误");
}
}
bt_add->EnableWindow(true);
bt_modify->EnableWindow(true);
bt_delete->EnableWindow(true);
bt_save->EnableWindow(false);
bt_addLine->EnableWindow(false);
bt_deleteLine->EnableWindow(false);
bt_cancelation->EnableWindow(false);
tx_storeHouseLose->EnableWindow(false);
tx_houseOutType->EnableWindow(false);
tx_formDate->EnableWindow(false);
tx_remark->EnableWindow(false);
tx_dealer->EnableWindow(false);
UpdateData(false);
}
void CProductLoseForm::OnCancelation()
{
int formID=((CStoreApp*)AfxGetApp())->m_pIDRecordset->GetCollect("productLoseFormID").intVal;
formID-=1;
CString str;
str.Format("%d",formID);
((CStoreApp*)AfxGetApp())->m_pIDRecordset->PutCollect("productLoseFormID",(_variant_t)str);
((CStoreApp*)AfxGetApp())->m_pIDRecordset->Update();
bt_cancelation->EnableWindow(false);
bt_add->EnableWindow(true);
bt_delete->EnableWindow(false);
bt_modify->EnableWindow(false);
bt_deleteLine->EnableWindow(false);
bt_addLine->EnableWindow(false);
bt_save->EnableWindow(false);
tx_storeHouseLose->EnableWindow(false);
tx_houseOutType->EnableWindow(false);
tx_formDate->EnableWindow(false);
tx_remark->EnableWindow(false);
tx_dealer->EnableWindow(false);
m_productLoseFormID = _T("");
m_storeHouseLose = _T("");
m_houseOutType = _T("");
m_formDate = COleDateTime::GetCurrentTime();
m_remark = _T("");
is_search=0;
flag=1;
m_dealer = _T("");
UpdateData(false);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -