📄 materialinfo.cpp
字号:
// MaterialInfo.cpp : implementation file
//
#include "stdafx.h"
#include "Store.h"
#include "MaterialInfo.h"
#include "Affirm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMaterialInfo dialog
CMaterialInfo::CMaterialInfo(CWnd* pParent /*=NULL*/)
: CDialog(CMaterialInfo::IDD, pParent)
{
//{{AFX_DATA_INIT(CMaterialInfo)
m_materialID = _T("");
m_materialName = _T("");
m_standard = _T("");
m_model = _T("");
m_unit = _T("");
m_qualityGuarantee = 0;
m_colorType = _T("");
m_qualityLevel = _T("");
m_taxRate = 0;
m_loseRate = 0;
m_storeHouse = _T("");
m_provider = _T("");
m_planPrice = 0.0f;
m_standardPrice = 0.0f;
m_remark = _T("");
m_numMax = 0;
m_numMin = 0;
//}}AFX_DATA_INIT
}
void CMaterialInfo::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMaterialInfo)
DDX_Control(pDX, IDC_provider, m_providerCombo);
DDX_Control(pDX, IDC_storeHouse, m_storeHouseCombo);
DDX_Control(pDX, IDC_LIST1, m_list);
DDX_Text(pDX, IDC_materialID, m_materialID);
DDX_Text(pDX, IDC_materialName, m_materialName);
DDX_Text(pDX, IDC_standard, m_standard);
DDX_Text(pDX, IDC_model, m_model);
DDX_CBString(pDX, IDC_unit, m_unit);
DDX_Text(pDX, IDC_qualityGuarantee, m_qualityGuarantee);
DDX_CBString(pDX, IDC_colorType, m_colorType);
DDX_CBString(pDX, IDC_qualityLevel, m_qualityLevel);
DDX_Text(pDX, IDC_taxRate, m_taxRate);
DDX_Text(pDX, IDC_loseRate, m_loseRate);
DDX_CBString(pDX, IDC_storeHouse, m_storeHouse);
DDX_CBString(pDX, IDC_provider, m_provider);
DDX_Text(pDX, IDC_planPrice, m_planPrice);
DDX_Text(pDX, IDC_standardPrice, m_standardPrice);
DDX_Text(pDX, IDC_remark, m_remark);
DDX_Text(pDX, IDC_numMax, m_numMax);
DDX_Text(pDX, IDC_numMin1, m_numMin);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMaterialInfo, CDialog)
//{{AFX_MSG_MAP(CMaterialInfo)
ON_BN_CLICKED(IDC_add, OnAdd)
ON_BN_CLICKED(IDC_delete, OnDelete)
ON_BN_CLICKED(IDC_modify, OnModify)
ON_BN_CLICKED(IDC_save, OnSave)
ON_BN_CLICKED(IDC_exit, OnExit)
ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMaterialInfo message handlers
void CMaterialInfo::OnAdd()
{
UpdateData(true);
int materialID=((CStoreApp*)AfxGetApp())->m_pIDRecordset->GetCollect("materialID").intVal;
if(materialID<10)
m_materialID.Format("material0000%d",materialID);
else if(materialID<100&&materialID>9)
m_materialID.Format("material000%d",materialID);
else if(materialID<1000&&materialID>99)
m_materialID.Format("material00%d",materialID);
CString str;
str.Format("%d",materialID+1);
((CStoreApp*)AfxGetApp())->m_pIDRecordset->PutCollect("materialID",_variant_t(str));
((CStoreApp*)AfxGetApp())->m_pIDRecordset->Update();
m_materialName = _T("");
m_standard = _T("");
m_model = _T("");
m_unit = _T("");
m_qualityGuarantee = 0;
m_colorType = _T("");
m_qualityLevel = _T("");
m_taxRate = 0;
m_loseRate = 0;
m_storeHouse = _T("");
m_provider = _T("");
m_planPrice = 0.0f;
m_standardPrice = 0.0f;
m_remark = _T("");
m_numMax = 0;
m_numMin = 0;
flag=1;
tx_materialID->EnableWindow(false);
tx_materialName->EnableWindow(true);
tx_standard->EnableWindow(true);
tx_model->EnableWindow(true);
tx_unit->EnableWindow(true);
tx_qualityGuarantee->EnableWindow(true);
tx_colorType->EnableWindow(true);
tx_qualityLevel->EnableWindow(true);
tx_taxRate->EnableWindow(true);
tx_loseRate->EnableWindow(true);
tx_storeHouse->EnableWindow(true);
tx_provider->EnableWindow(true);
tx_planPrice->EnableWindow(true);
tx_standardPrice->EnableWindow(true);
tx_remark->EnableWindow(true);
tx_numMax->EnableWindow(true);
tx_numMin->EnableWindow(true);
bt_save->EnableWindow(true);
bt_add->EnableWindow(false);
bt_modify->EnableWindow(false);
bt_delete->EnableWindow(false);
UpdateData(false);
}
void CMaterialInfo::OnDelete()
{
CAffirm dlg;
if(dlg.DoModal()!=IDOK)
{
return;
}
_variant_t RecordsAffected;
CString strSQL;
strSQL="delete from material where materialID='";
strSQL=strSQL+m_materialID+"'";
(((CStoreApp*)AfxGetApp())->m_pConn)->Execute((_bstr_t)strSQL,&RecordsAffected,adCmdText);
POSITION pos = m_list.GetFirstSelectedItemPosition();
if(pos)
{
int nFirstSelItem = m_list.GetNextSelectedItem(pos);
m_list.DeleteItem(nFirstSelItem);
}
bt_delete->EnableWindow(false);
m_materialID = _T("");
m_materialName = _T("");
m_standard = _T("");
m_model = _T("");
m_unit = _T("");
m_qualityGuarantee = 0;
m_colorType = _T("");
m_qualityLevel = _T("");
m_taxRate = 0;
m_loseRate = 0;
m_storeHouse = _T("");
m_provider = _T("");
m_planPrice = 0.0f;
m_standardPrice = 0.0f;
m_remark = _T("");
m_numMax = 0;
m_numMin = 0;
Refresh();
UpdateData(false);
}
void CMaterialInfo::OnModify()
{
tx_materialID->EnableWindow(false);
tx_materialName->EnableWindow(true);
tx_standard->EnableWindow(true);
tx_model->EnableWindow(true);
tx_unit->EnableWindow(true);
tx_qualityGuarantee->EnableWindow(true);
tx_colorType->EnableWindow(true);
tx_qualityLevel->EnableWindow(true);
tx_taxRate->EnableWindow(true);
tx_loseRate->EnableWindow(true);
tx_storeHouse->EnableWindow(true);
tx_provider->EnableWindow(true);
tx_planPrice->EnableWindow(true);
tx_standardPrice->EnableWindow(true);
tx_remark->EnableWindow(true);
tx_numMax->EnableWindow(true);
tx_numMin->EnableWindow(true);
flag=2;
bt_save->EnableWindow(true);
}
void CMaterialInfo::OnSave()
{
UpdateData(true);
_RecordsetPtr m_pRecordset;
CString strSQL;
if(flag==1) //添加
{
strSQL="SELECT * FROM material" ;
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"));
CString str;
//------------------------------------------
m_pRecordset->AddNew();
m_pRecordset->PutCollect("materialID",_variant_t(m_materialID));
m_pRecordset->PutCollect("materialName",_variant_t(m_materialName));
m_pRecordset->PutCollect("standard",_variant_t(m_standard));
m_pRecordset->PutCollect("model",_variant_t(m_model));
m_pRecordset->PutCollect("unit",_variant_t(m_unit));
str.Format("%d",m_qualityGuarantee);
m_pRecordset->PutCollect("qualityGuarantee",_variant_t(str));
m_pRecordset->PutCollect("colorType",_variant_t(m_colorType));
m_pRecordset->PutCollect("qualityLevel",_variant_t(m_qualityLevel));
str.Format("%d",m_taxRate);
m_pRecordset->PutCollect("taxRate",_variant_t(str));
str.Format("%d",m_loseRate);
m_pRecordset->PutCollect("loseRate",_variant_t(str));
m_pRecordset->PutCollect("storeHouse",_variant_t(m_storeHouse));
m_pRecordset->PutCollect("provider",_variant_t(m_provider));
str.Format("%d",m_planPrice);
m_pRecordset->PutCollect("planPrice",_variant_t(str));
str.Format("%d",m_standardPrice);
m_pRecordset->PutCollect("standardPrice",_variant_t(str));
str.Format("%d",m_numMax);
m_pRecordset->PutCollect("numMax",_variant_t(str));
str.Format("%d",m_numMin);
m_pRecordset->PutCollect("numMin",_variant_t(str));
m_pRecordset->PutCollect("remark",_variant_t(m_remark));
m_pRecordset->Update();
int j;
j=m_list.GetItemCount();
m_list.InsertItem(j,m_materialID);
m_list.SetItemText(j,1,m_materialName);
m_list.SetItemText(j,2,m_standard);
m_list.SetItemText(j,3,m_model);
m_list.SetItemText(j,4,m_unit);
str.Format("%d",m_qualityGuarantee);
m_list.SetItemText(j,5,str);
m_list.SetItemText(j,6,m_colorType);
m_list.SetItemText(j,7,m_qualityLevel);
str.Format("%d",m_taxRate);
m_list.SetItemText(j,8,str);
str.Format("%d",m_loseRate);
m_list.SetItemText(j,9,str);
m_list.SetItemText(j,10,m_storeHouse);
m_list.SetItemText(j,11,m_provider);
str.Format("%d",m_planPrice);
m_list.SetItemText(j,12,str);
str.Format("%d",m_standardPrice);
m_list.SetItemText(j,13,str);
str.Format("%d",m_numMax);
m_list.SetItemText(j,14,str);
str.Format("%d",m_numMin);
m_list.SetItemText(j,15,str);
m_list.SetItemText(j,16,m_remark);
AfxMessageBox("插入成功!");
}
}
}
catch(_com_error e)///捕捉异常
{
CString errormessage;
MessageBox("创建记录集失败!","错误");
}
}
else if(flag==2) //修改
{
strSQL="SELECT * FROM material where materialID='" ;
strSQL=strSQL+m_materialID+"'";
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"));
CString str;
m_pRecordset->PutCollect("materialName",_variant_t(m_materialName));
m_pRecordset->PutCollect("standard",_variant_t(m_standard));
m_pRecordset->PutCollect("model",_variant_t(m_model));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -