📄 productinputform.cpp
字号:
bt_save->EnableWindow(true);
bt_modify->EnableWindow(false);
bt_addLine->EnableWindow(true);
bt_deleteLine->EnableWindow(true);
bt_cancelation->EnableWindow(true);
tx_formDate->EnableWindow(true);
tx_produceDate->EnableWindow(true);
tx_storeHouse->EnableWindow(true);
tx_department->EnableWindow(true);
tx_dealer->EnableWindow(true);
tx_houseInType->EnableWindow(true);
tx_remark->EnableWindow(true);
int formID=((CStoreApp*)AfxGetApp())->m_pIDRecordset->GetCollect("productInputFormID").intVal;
if(formID<10)
m_productInputFormID.Format("CPRK0000%d",formID);
else if(formID<100&&formID>9)
m_productInputFormID.Format("CPRK000%d",formID);
else if(formID<1000&&formID>99)
m_productInputFormID.Format("CPRK00%d",formID);
CString str;
str.Format("%d",formID+1);
((CStoreApp*)AfxGetApp())->m_pIDRecordset->PutCollect("productInputFormID",_variant_t(str));
((CStoreApp*)AfxGetApp())->m_pIDRecordset->Update();
m_list.DeleteAllItems();
m_formDate = COleDateTime::GetCurrentTime();
m_produceDate = COleDateTime::GetCurrentTime();
m_storeHouse = _T("");
m_department = _T("");
m_dealer = _T("");
m_houseInType = _T("");
m_remark = _T("");
is_search=0;
flag=1;
UpdateData(false);
}
void CProductInputForm::OnModify2()
{
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_formDate->EnableWindow(true);
tx_produceDate->EnableWindow(true);
tx_storeHouse->EnableWindow(true);
tx_department->EnableWindow(true);
tx_dealer->EnableWindow(true);
tx_houseInType->EnableWindow(true);
tx_remark->EnableWindow(true);
}
void CProductInputForm::OnDelete()
{
CAffirm dlg;
if(dlg.DoModal()!=IDOK)
{
return;
}
_variant_t RecordsAffected;
CString strSQL;
strSQL="delete from productInputForm where productInputFormID='";
strSQL=strSQL+m_productInputFormID+"'";
(((CStoreApp*)AfxGetApp())->m_pConn)->Execute((_bstr_t)strSQL,&RecordsAffected,adCmdText);
m_list.DeleteAllItems();
UpdateData(false);
AfxMessageBox("该单已删除!");
tx_formDate->EnableWindow(false);
tx_produceDate->EnableWindow(false);
tx_storeHouse->EnableWindow(false);
tx_department->EnableWindow(false);
tx_dealer->EnableWindow(false);
tx_houseInType->EnableWindow(false);
tx_remark->EnableWindow(false);
m_formDate = COleDateTime::GetCurrentTime();
m_produceDate = COleDateTime::GetCurrentTime();
m_storeHouse = _T("");
m_department = _T("");
m_dealer = _T("");
m_houseInType = _T("");
m_remark = _T("");
bt_modify->EnableWindow(false);
bt_delete->EnableWindow(false);
m_productInputFormID="";
is_search=0;
flag=1;
UpdateData(false);
}
void CProductInputForm::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 CProductInputForm::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 CProductInputForm::OnSave()
{
UpdateData(true);
CString strSQL;
_RecordsetPtr m_pRecordset; //用于创建一个查询记录集
_RecordsetPtr m_pProductInputFormRecordset;
strSQL="select * from productInputForm";
HRESULT hTRes;
hTRes = m_pProductInputFormRecordset.CreateInstance(_T("ADODB.Recordset"));
hTRes = m_pProductInputFormRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
((CStoreApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
if(flag==1) //添加
{
m_pProductInputFormRecordset->AddNew();
m_pProductInputFormRecordset->PutCollect("productInputFormID",_variant_t(m_productInputFormID.Left(25)));
m_pProductInputFormRecordset->PutCollect("formDate",_variant_t(m_formDate));
m_pProductInputFormRecordset->PutCollect("produceDate",_variant_t(m_produceDate));
m_pProductInputFormRecordset->PutCollect("storeHouse",_variant_t(m_storeHouse.Left(50)));
m_pProductInputFormRecordset->PutCollect("produceDepartment",_variant_t(m_department.Left(50)));
m_pProductInputFormRecordset->PutCollect("dealer",_variant_t(m_dealer.Left(50)));
m_pProductInputFormRecordset->PutCollect("houseInType",_variant_t(m_houseInType.Left(50)));
m_pProductInputFormRecordset->PutCollect("remark",_variant_t(m_remark.Left(100)));
m_pProductInputFormRecordset->Update();
strSQL="SELECT * FROM productInputFormCommidity" ;
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("productInputFormID",_variant_t(m_productInputFormID.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 productInputFormCommidity where productInputFormID='";
strSQL=strSQL+m_productInputFormID+"'";
(((CStoreApp*)AfxGetApp())->m_pConn)->Execute((_bstr_t)strSQL,&RecordsAffected,adCmdText);
m_pProductInputFormRecordset->Update();
strSQL="SELECT * FROM productInputFormCommidity" ;
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("productInputFormID",_variant_t(m_productInputFormID.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_formDate->EnableWindow(false);
tx_produceDate->EnableWindow(false);
tx_storeHouse->EnableWindow(false);
tx_department->EnableWindow(false);
tx_dealer->EnableWindow(false);
tx_houseInType->EnableWindow(false);
tx_remark->EnableWindow(false);
UpdateData(false);
}
void CProductInputForm::OnCancelation()
{
int formID=((CStoreApp*)AfxGetApp())->m_pIDRecordset->GetCollect("productInputFormID").intVal;
formID-=1;
CString str;
str.Format("%d",formID);
((CStoreApp*)AfxGetApp())->m_pIDRecordset->PutCollect("productInputFormID",(_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_formDate->EnableWindow(false);
tx_produceDate->EnableWindow(false);
tx_storeHouse->EnableWindow(false);
tx_department->EnableWindow(false);
tx_dealer->EnableWindow(false);
tx_houseInType->EnableWindow(false);
tx_remark->EnableWindow(false);
m_formDate = COleDateTime::GetCurrentTime();
m_productInputFormID = _T("");
m_produceDate = COleDateTime::GetCurrentTime();
m_storeHouse = _T("");
m_department = _T("");
m_dealer = _T("");
m_houseInType = _T("");
m_remark = _T("");
UpdateData(false);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -