📄 commodityinfor.cpp
字号:
m_commodityType = _T("");
m_remark = _T("");
flag=1;
tx_commodityID->EnableWindow(false);
tx_commodityName->EnableWindow(true);
tx_standard->EnableWindow(true);
tx_model->EnableWindow(true);
tx_price->EnableWindow(true);
tx_qualityGuarantee->EnableWindow(true);
tx_maintenance->EnableWindow(true);
tx_unit->EnableWindow(true);
tx_colorType->EnableWindow(true);
tx_qualityLevel->EnableWindow(true);
tx_finishedProductRate->EnableWindow(true);
tx_storedHouse->EnableWindow(true);
tx_taxRate->EnableWindow(true);
tx_commodityType->EnableWindow(true);
tx_remark->EnableWindow(true);
bt_save->EnableWindow(true);
bt_add->EnableWindow(false);
bt_modify->EnableWindow(false);
bt_delete->EnableWindow(false);
UpdateData(false);
}
void CCommodityInfor::OnDelete()
{
CAffirm dlg;
if(dlg.DoModal()!=IDOK)
{
return;
}
_variant_t RecordsAffected;
CString strSQL;
strSQL="delete from commodity where commodityID='";
strSQL=strSQL+m_commodityID+"'";
(((CSaleApp*)AfxGetApp())->m_pConn)->Execute((_bstr_t)strSQL,&RecordsAffected,adCmdText);
POSITION pos = m_commodityList.GetFirstSelectedItemPosition();
if(pos)
{
int nFirstSelItem = m_commodityList.GetNextSelectedItem(pos);
m_commodityList.DeleteItem(nFirstSelItem);
}
bt_delete->EnableWindow(false);
Refresh();
m_commodityID = _T("");
m_commodityName = _T("");
m_standard = _T("");
m_model = _T("");
m_price = 0.0f;
m_qualityGuarantee = 0;
m_maintenance = _T("");
m_unit = _T("");
m_colorType = _T("");
m_qualityLevel = _T("");
m_finishedProductRate = 0;
m_storedHouse = _T("");
m_taxRate = 0;
m_commodityType = _T("");
m_remark = _T("");
UpdateData(false);
}
void CCommodityInfor::OnModify()
{
tx_commodityID->EnableWindow(false);
tx_commodityName->EnableWindow(true);
tx_standard->EnableWindow(true);
tx_model->EnableWindow(true);
tx_price->EnableWindow(true);
tx_qualityGuarantee->EnableWindow(true);
tx_maintenance->EnableWindow(true);
tx_unit->EnableWindow(true);
tx_colorType->EnableWindow(true);
tx_qualityLevel->EnableWindow(true);
tx_finishedProductRate->EnableWindow(true);
tx_storedHouse->EnableWindow(true);
tx_taxRate->EnableWindow(true);
tx_commodityType->EnableWindow(true);
tx_remark->EnableWindow(true);
flag=2;
bt_save->EnableWindow(true);
}
void CCommodityInfor::OnSave()
{
UpdateData(true);
_RecordsetPtr m_pRecordset; //用于创建一个查询记录集
//----------------------------------------------
CString strSQL;
// AfxMessageBox(TreeCurrent);
if(flag==1) //添加
{
strSQL="SELECT * FROM commodity";
try
{
HRESULT hTRes;
hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
if (SUCCEEDED(hTRes))
{
//----------------------------------------------------
hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
((CSaleApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
if(SUCCEEDED(hTRes))
{
TRACE(_T("连接成功!\n"));
//------------------------------------------
m_pRecordset->AddNew();
int m;
CString str;
m_pRecordset->PutCollect("commodityID",_variant_t(m_commodityID));
m_pRecordset->PutCollect("commodityName",_variant_t(m_commodityName));
m_pRecordset->PutCollect("standard",_variant_t(m_standard));
m_pRecordset->PutCollect("model",_variant_t(m_model));
str.Format("%f",m_price);
m_pRecordset->PutCollect("price",_variant_t(str));
str.Format("%d",m_qualityGuarantee);
m_pRecordset->PutCollect("qualityGuarantee",_variant_t(str));
m=atoi(m_maintenance);
str.Format("%d",m);
m_pRecordset->PutCollect("maintenance",_variant_t(str));
m_pRecordset->PutCollect("unit",_variant_t(m_unit));
m_pRecordset->PutCollect("colorType",_variant_t(m_colorType));
m_pRecordset->PutCollect("quanlityLevel",_variant_t(m_qualityLevel));
str.Format("%d",m_finishedProductRate);
m_pRecordset->PutCollect("finishedProductRate",_variant_t(str));
m_pRecordset->PutCollect("storedHouse",_variant_t(m_storedHouse));
str.Format("%d",m_taxRate);
m_pRecordset->PutCollect("taxRate",_variant_t(str));
m_pRecordset->PutCollect("commodityType",_variant_t(m_commodityType));
m_pRecordset->PutCollect("remark",_variant_t(m_remark));
m_pRecordset->Update();
int j;
j=m_commodityList.GetItemCount();
m_commodityList.InsertItem(j,m_commodityID);
m_commodityList.SetItemText(j,1,(LPCTSTR)(_bstr_t)(m_commodityName));
m_commodityList.SetItemText(j,2,m_standard);
m_commodityList.SetItemText(j,3,m_model);
str.Format("%f",m_price);
m_commodityList.SetItemText(j,4,str);
str.Format("%d",m_qualityGuarantee);
m_commodityList.SetItemText(j,5,str);
m_commodityList.SetItemText(j,6,m_maintenance);
m_commodityList.SetItemText(j,7,m_unit);
m_commodityList.SetItemText(j,8,m_colorType);
m_commodityList.SetItemText(j,9,m_qualityLevel);
str.Format("%d",m_finishedProductRate);
m_commodityList.SetItemText(j,10,str);
m_commodityList.SetItemText(j,11,m_storedHouse);
str.Format("%d",m_taxRate);
m_commodityList.SetItemText(j,12,str);
m_commodityList.SetItemText(j,13,m_commodityType);
m_commodityList.SetItemText(j,14,m_remark);
AfxMessageBox("插入成功!");
}
}
}
catch(_com_error e)///捕捉异常
{
CString errormessage;
MessageBox("创建记录集失败!","错误");
}
}
else if(flag==2) //修改
{
strSQL="SELECT * FROM commodity where commodityID='" ;
strSQL=strSQL+m_commodityID+"'";
try
{
HRESULT hTRes;
hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
if (SUCCEEDED(hTRes))
{
//----------------------------------------------------
hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
((CSaleApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
if(SUCCEEDED(hTRes))
{
TRACE(_T("连接成功!\n"));
//------------------------------------------
int m;
CString str;
m_pRecordset->PutCollect("commodityID",_variant_t(m_commodityID));
m_pRecordset->PutCollect("commodityName",_variant_t(m_commodityName));
m_pRecordset->PutCollect("standard",_variant_t(m_standard));
m_pRecordset->PutCollect("model",_variant_t(m_model));
str.Format("%f",m_price);
m_pRecordset->PutCollect("price",_variant_t(str));
str.Format("%d",m_qualityGuarantee);
m_pRecordset->PutCollect("qualityGuarantee",_variant_t(str));
m=atoi(m_maintenance);
str.Format("%d",m);
m_pRecordset->PutCollect("maintenance",_variant_t(str));
m_pRecordset->PutCollect("unit",_variant_t(m_unit));
m_pRecordset->PutCollect("colorType",_variant_t(m_colorType));
m_pRecordset->PutCollect("quanlityLevel",_variant_t(m_qualityLevel));
str.Format("%d",m_finishedProductRate);
m_pRecordset->PutCollect("finishedProductRate",_variant_t(str));
m_pRecordset->PutCollect("storedHouse",_variant_t(m_storedHouse));
str.Format("%d",m_taxRate);
m_pRecordset->PutCollect("taxRate",_variant_t(str));
m_pRecordset->PutCollect("commodityType",_variant_t(m_commodityType));
m_pRecordset->PutCollect("remark",_variant_t(m_remark));
m_pRecordset->Update();
Refresh();
AfxMessageBox("修改成功!");
}
}
}
catch(_com_error e)///捕捉异常
{
CString errormessage;
MessageBox("创建记录集失败!","错误");
}
}
bt_add->EnableWindow(true);
bt_delete->EnableWindow(true);
bt_modify->EnableWindow(true);
bt_save->EnableWindow(true);
tx_commodityID->EnableWindow(false);
tx_commodityName->EnableWindow(false);
tx_standard->EnableWindow(false);
tx_model->EnableWindow(false);
tx_price->EnableWindow(false);
tx_qualityGuarantee->EnableWindow(false);
tx_maintenance->EnableWindow(false);
tx_unit->EnableWindow(false);
tx_colorType->EnableWindow(false);
tx_qualityLevel->EnableWindow(false);
tx_finishedProductRate->EnableWindow(false);
tx_storedHouse->EnableWindow(false);
tx_taxRate->EnableWindow(false);
tx_commodityType->EnableWindow(false);
tx_remark->EnableWindow(false);
UpdateData(false);//
}
void CCommodityInfor::Refresh()
{
_RecordsetPtr m_pListRecordset; //用于创建一个查询记录集
CString strSQL;
HRESULT hTRes;
m_commodityList.DeleteAllItems();
strSQL="SELECT * FROM commodity";
try
{
HRESULT hTRes;
hTRes = m_pListRecordset.CreateInstance(_T("ADODB.Recordset"));
if (SUCCEEDED(hTRes))
{
hTRes = m_pListRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
((CSaleApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
if(SUCCEEDED(hTRes))
{
TRACE(_T("连接成功!\n"));
m_pListRecordset->MoveFirst();
if (!(m_pListRecordset->adoEOF))
{
int i=0;
while(!m_pListRecordset->adoEOF)
{
m_commodityList.InsertItem(i,((CSaleApp*)AfxGetApp())->GetStringFromVariant(m_pListRecordset->GetCollect("commodityID")));
m_commodityList.SetItemText(i,1,((CSaleApp*)AfxGetApp())->GetStringFromVariant(m_pListRecordset->GetCollect("commodityName")));
m_commodityList.SetItemText(i,2,((CSaleApp*)AfxGetApp())->GetStringFromVariant(m_pListRecordset->GetCollect("standard")));
m_commodityList.SetItemText(i,3,((CSaleApp*)AfxGetApp())->GetStringFromVariant(m_pListRecordset->GetCollect("model")));
m_commodityList.SetItemText(i,4,((CSaleApp*)AfxGetApp())->GetStringFromVariant(m_pListRecordset->GetCollect("price")));
m_commodityList.SetItemText(i,5,((CSaleApp*)AfxGetApp())->GetStringFromVariant(m_pListRecordset->GetCollect("qualityGuarantee")));
m_commodityList.SetItemText(i,6,((CSaleApp*)AfxGetApp())->GetStringFromVariant(m_pListRecordset->GetCollect("maintenance")));
m_commodityList.SetItemText(i,7,((CSaleApp*)AfxGetApp())->GetStringFromVariant(m_pListRecordset->GetCollect("unit")));
m_commodityList.SetItemText(i,8,((CSaleApp*)AfxGetApp())->GetStringFromVariant(m_pListRecordset->GetCollect("colorType")));
m_commodityList.SetItemText(i,9,((CSaleApp*)AfxGetApp())->GetStringFromVariant(m_pListRecordset->GetCollect("quanlityLevel")));
m_commodityList.SetItemText(i,10,((CSaleApp*)AfxGetApp())->GetStringFromVariant(m_pListRecordset->GetCollect("finishedProductRate")));
m_commodityList.SetItemText(i,11,((CSaleApp*)AfxGetApp())->GetStringFromVariant(m_pListRecordset->GetCollect("storedHouse")));
m_commodityList.SetItemText(i,12,((CSaleApp*)AfxGetApp())->GetStringFromVariant(m_pListRecordset->GetCollect("taxRate")));
m_commodityList.SetItemText(i,13,((CSaleApp*)AfxGetApp())->GetStringFromVariant(m_pListRecordset->GetCollect("commodityType")));
m_commodityList.SetItemText(i,14,((CSaleApp*)AfxGetApp())->GetStringFromVariant(m_pListRecordset->GetCollect("remark")));
if (!(m_pListRecordset->adoEOF))
{
m_pListRecordset->MoveNext();
i++;
}
}
}
}
}
}
catch(_com_error e)///捕捉异常
{
CString errormessage;
MessageBox("创建客户记录集失败!","错误");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -