📄 materialoutputform.cpp
字号:
// TODO: Add your control notification handler code here
*pResult = 0;
}
void CMaterialOutputForm::OnAdd()
{
flag=1;
bt_add->EnableWindow(false);
bt_delete->EnableWindow(false);
bt_save->EnableWindow(true);
bt_modify->EnableWindow(false);
bt_addLine->EnableWindow(true);
bt_deleteLine->EnableWindow(true);
bt_cancelation->EnableWindow(true);
tx_materialGetID->EnableWindow(true);
tx_storeHouse->EnableWindow(true);
tx_department->EnableWindow(true);
tx_dealer->EnableWindow(true);
tx_projectID->EnableWindow(true);
tx_projectName->EnableWindow(true);
tx_houseOutType->EnableWindow(true);
tx_formDate->EnableWindow(true);
tx_remark->EnableWindow(true);
int formID=((CStoreApp*)AfxGetApp())->m_pIDRecordset->GetCollect("materialOutputFormID").intVal;
if(formID<10)
m_materialOutputFormID.Format("CLCK0000%d",formID);
else if(formID<100&&formID>9)
m_materialOutputFormID.Format("CLCK000%d",formID);
else if(formID<1000&&formID>99)
m_materialOutputFormID.Format("CLCK00%d",formID);
CString str;
str.Format("%d",formID+1);
((CStoreApp*)AfxGetApp())->m_pIDRecordset->PutCollect("materialOutputFormID",_variant_t(str));
((CStoreApp*)AfxGetApp())->m_pIDRecordset->Update();
m_list.DeleteAllItems();
m_storeHouse = _T("");
m_department = _T("");
m_dealer = _T("");
m_projectID = _T("");
m_projectName = _T("");
m_houseOutType = _T("");
m_formDate = COleDateTime::GetCurrentTime();
m_remark = _T("");
is_search=0;
flag=1;
UpdateData(false);
}
void CMaterialOutputForm::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_materialGetID->EnableWindow(true);
tx_storeHouse->EnableWindow(true);
tx_department->EnableWindow(true);
tx_dealer->EnableWindow(true);
tx_projectID->EnableWindow(true);
tx_projectName->EnableWindow(true);
tx_houseOutType->EnableWindow(true);
tx_formDate->EnableWindow(true);
tx_remark->EnableWindow(true);
}
void CMaterialOutputForm::OnDelete()
{
CAffirm dlg;
if(dlg.DoModal()!=IDOK)
{
return;
}
_variant_t RecordsAffected;
CString strSQL;
strSQL="delete from materialOutputForm where materialOutputFormID='";
strSQL=strSQL+m_materialOutputFormID+"'";
(((CStoreApp*)AfxGetApp())->m_pConn)->Execute((_bstr_t)strSQL,&RecordsAffected,adCmdText);
m_list.DeleteAllItems();
UpdateData(false);
AfxMessageBox("该单已删除!");
tx_materialGetID->EnableWindow(false);
tx_storeHouse->EnableWindow(false);
tx_department->EnableWindow(false);
tx_dealer->EnableWindow(false);
tx_projectID->EnableWindow(false);
tx_projectName->EnableWindow(false);
tx_houseOutType->EnableWindow(false);
tx_formDate->EnableWindow(false);
tx_remark->EnableWindow(false);
m_materialGetID = _T("");
m_storeHouse = _T("");
m_materialOutputFormID = _T("");
m_department = _T("");
m_dealer = _T("");
m_projectID = _T("");
m_projectName = _T("");
m_houseOutType = _T("");
m_formDate = COleDateTime::GetCurrentTime();
m_remark = _T("");
is_search=0;
flag=1;
UpdateData(false);
}
void CMaterialOutputForm::OnAddLine()
{
CSelectMaterial 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_materialID);
m_list.SetItemText(i,1,dlg.m_materialName);
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 CMaterialOutputForm::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 CMaterialOutputForm::OnSave()
{
UpdateData(true);
CString strSQL;
_RecordsetPtr m_pRecordset; //用于创建一个查询记录集
_RecordsetPtr m_pMaterialOutputFormRecordset;
strSQL="select * from materialOutputForm";
HRESULT hTRes;
hTRes = m_pMaterialOutputFormRecordset.CreateInstance(_T("ADODB.Recordset"));
hTRes = m_pMaterialOutputFormRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
((CStoreApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
if(flag==1) //添加
{
m_pMaterialOutputFormRecordset->AddNew();
m_pMaterialOutputFormRecordset->PutCollect("materialOutputFormID",_variant_t(m_materialOutputFormID.Left(25)));
m_pMaterialOutputFormRecordset->PutCollect("formDate",_variant_t(m_formDate));
m_pMaterialOutputFormRecordset->PutCollect("materialReceiveFormID",_variant_t(m_materialGetID.Left(50)));
m_pMaterialOutputFormRecordset->PutCollect("storeHouse",_variant_t(m_storeHouse.Left(50)));
m_pMaterialOutputFormRecordset->PutCollect("receiveDepartment",_variant_t(m_department.Left(50)));
m_pMaterialOutputFormRecordset->PutCollect("dealer",_variant_t(m_dealer.Left(50)));
m_pMaterialOutputFormRecordset->PutCollect("projectID",_variant_t(m_projectID.Left(50)));
m_pMaterialOutputFormRecordset->PutCollect("projectName",_variant_t(m_projectName.Left(50)));
m_pMaterialOutputFormRecordset->PutCollect("houseOutputType",_variant_t(m_houseOutType.Left(50)));
m_pMaterialOutputFormRecordset->PutCollect("remark",_variant_t(m_remark.Left(100)));
m_pMaterialOutputFormRecordset->Update();
strSQL="SELECT * FROM materialOutputFormCommidity" ;
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("materialOutputFormID",_variant_t(m_materialOutputFormID.Left(25)));
m_pRecordset->PutCollect("materialID",_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 materialOutputFormCommidity where materialOutputFormID='";
strSQL=strSQL+m_materialOutputFormID+"'";
(((CStoreApp*)AfxGetApp())->m_pConn)->Execute((_bstr_t)strSQL,&RecordsAffected,adCmdText);
m_pMaterialOutputFormRecordset->Update();
strSQL="SELECT * FROM materialOutputFormCommidity" ;
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("materialOutputFormID",_variant_t(m_materialOutputFormID.Left(25)));
m_pRecordset->PutCollect("materialID",_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_materialGetID->EnableWindow(false);
tx_storeHouse->EnableWindow(false);
tx_department->EnableWindow(false);
tx_dealer->EnableWindow(false);
tx_projectID->EnableWindow(false);
tx_projectName->EnableWindow(false);
tx_houseOutType->EnableWindow(false);
tx_formDate->EnableWindow(false);
tx_remark->EnableWindow(false);
UpdateData(false);
}
void CMaterialOutputForm::OnCancelation()
{
int formID=((CStoreApp*)AfxGetApp())->m_pIDRecordset->GetCollect("materialMoveFormID").intVal;
formID-=1;
CString str;
str.Format("%d",formID);
((CStoreApp*)AfxGetApp())->m_pIDRecordset->PutCollect("materialMoveFormID",(_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_materialGetID->EnableWindow(false);
tx_storeHouse->EnableWindow(false);
tx_department->EnableWindow(false);
tx_dealer->EnableWindow(false);
tx_projectID->EnableWindow(false);
tx_projectName->EnableWindow(false);
tx_houseOutType->EnableWindow(false);
tx_formDate->EnableWindow(false);
tx_remark->EnableWindow(false);
m_storeHouse = _T("");
m_materialOutputFormID = _T("");
m_department = _T("");
m_dealer = _T("");
m_projectID = _T("");
m_projectName = _T("");
m_houseOutType = _T("");
m_formDate = COleDateTime::GetCurrentTime();
m_remark = _T("");
m_materialOutputFormID="";
UpdateData(false);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -