📄 materialmoveform.cpp
字号:
// MaterialMoveForm.cpp : implementation file
//
#include "stdafx.h"
#include "Store.h"
#include "MaterialMoveForm.h"
#include "SelectMaterial.h"
#include "Affirm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMaterialMoveForm dialog
CMaterialMoveForm::CMaterialMoveForm(CWnd* pParent /*=NULL*/)
: CDialog(CMaterialMoveForm::IDD, pParent)
{
//{{AFX_DATA_INIT(CMaterialMoveForm)
m_materialMoveFormID = _T("");
m_storeHouseIn = _T("");
m_storeHouseOut = _T("");
m_dealer = _T("");
m_houseOutType = _T("");
m_FormDate = COleDateTime::GetCurrentTime();
m_remark = _T("");
is_search=0;
flag=1;
//}}AFX_DATA_INIT
}
void CMaterialMoveForm::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMaterialMoveForm)
DDX_Control(pDX, IDC_houseOutType, m_houseOutTypeCombo);
DDX_Control(pDX, IDC_dealer, m_dealerCombo);
DDX_Control(pDX, IDC_storehouseOut, m_storeHouseOutCombo);
DDX_Control(pDX, IDC_storehouseIn, m_storeHouseInCombo);
DDX_Control(pDX, IDC_LIST1, m_list);
DDX_Text(pDX, IDC_materialMoveFormID, m_materialMoveFormID);
DDX_CBString(pDX, IDC_storehouseIn, m_storeHouseIn);
DDX_CBString(pDX, IDC_storehouseOut, m_storeHouseOut);
DDX_CBString(pDX, IDC_dealer, m_dealer);
DDX_CBString(pDX, IDC_houseOutType, m_houseOutType);
DDX_DateTimeCtrl(pDX, IDC_formDate, m_FormDate);
DDX_Text(pDX, IDC_remark, m_remark);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMaterialMoveForm, CDialog)
//{{AFX_MSG_MAP(CMaterialMoveForm)
ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList)
ON_BN_CLICKED(IDC_add, OnAdd)
ON_BN_CLICKED(IDC_modify1, OnModify1)
ON_BN_CLICKED(IDC_delete, OnDelete)
ON_BN_CLICKED(IDC_addLine, OnAddLine)
ON_BN_CLICKED(IDC_deleteLine, OnDeleteLine)
ON_BN_CLICKED(IDC_save, OnSave)
ON_BN_CLICKED(IDC_cancelation, OnCancelation)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMaterialMoveForm message handlers
void CMaterialMoveForm::OnClickList(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
*pResult = 0;
}
void CMaterialMoveForm::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_storeHouseIn->EnableWindow(true);
tx_storeHouseOut->EnableWindow(true);
tx_dealer->EnableWindow(true);
tx_houseOutType->EnableWindow(true);
tx_FormDate->EnableWindow(true);
tx_remark->EnableWindow(true);
int formID=((CStoreApp*)AfxGetApp())->m_pIDRecordset->GetCollect("materialMoveFormID").intVal;
if(formID<10)
m_materialMoveFormID.Format("CLDB0000%d",formID);
else if(formID<100&&formID>9)
m_materialMoveFormID.Format("CLDB000%d",formID);
else if(formID<1000&&formID>99)
m_materialMoveFormID.Format("CLDB00%d",formID);
CString str;
str.Format("%d",formID+1);
((CStoreApp*)AfxGetApp())->m_pIDRecordset->PutCollect("materialMoveFormID",_variant_t(str));
((CStoreApp*)AfxGetApp())->m_pIDRecordset->Update();
m_list.DeleteAllItems();
m_storeHouseIn = _T("");
m_storeHouseOut = _T("");
m_dealer = _T("");
m_houseOutType = _T("");
m_FormDate = COleDateTime::GetCurrentTime();
m_remark = _T("");
flag=1;
is_search=0;
UpdateData(false);
}
void CMaterialMoveForm::OnModify1()
{
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_storeHouseIn->EnableWindow(true);
tx_storeHouseOut->EnableWindow(true);
tx_dealer->EnableWindow(true);
tx_houseOutType->EnableWindow(true);
tx_FormDate->EnableWindow(true);
tx_remark->EnableWindow(true);
}
void CMaterialMoveForm::OnDelete()
{
CAffirm dlg;
if(dlg.DoModal()!=IDOK)
{
return;
}
_variant_t RecordsAffected;
CString strSQL;
strSQL="delete from materialMoveForm where materialMoveFormID='";
strSQL=strSQL+m_materialMoveFormID+"'";
(((CStoreApp*)AfxGetApp())->m_pConn)->Execute((_bstr_t)strSQL,&RecordsAffected,adCmdText);
m_list.DeleteAllItems();
UpdateData(false);
AfxMessageBox("该单已删除!");
bt_add->EnableWindow(true);
bt_delete->EnableWindow(false);
bt_modify->EnableWindow(false);
bt_addLine->EnableWindow(false);
bt_deleteLine->EnableWindow(false);
bt_save->EnableWindow(false);
bt_cancelation->EnableWindow(false);
m_materialMoveFormID = _T("");
m_storeHouseIn = _T("");
m_storeHouseOut = _T("");
m_dealer = _T("");
m_houseOutType = _T("");
m_FormDate = COleDateTime::GetCurrentTime();
m_remark = _T("");
is_search=0;
flag=1;
tx_storeHouseIn->EnableWindow(false);
tx_storeHouseOut->EnableWindow(false);
tx_dealer->EnableWindow(false);
tx_houseOutType->EnableWindow(false);
tx_FormDate->EnableWindow(false);
tx_remark->EnableWindow(false);
UpdateData(false);
}
void CMaterialMoveForm::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 CMaterialMoveForm::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 CMaterialMoveForm::OnSave()
{
UpdateData(true);
CString strSQL;
_RecordsetPtr m_pRecordset; //用于创建一个查询记录集
_RecordsetPtr m_pMaterialMoveFormRecordset;
strSQL="select * from materialMoveForm";
HRESULT hTRes;
hTRes = m_pMaterialMoveFormRecordset.CreateInstance(_T("ADODB.Recordset"));
hTRes = m_pMaterialMoveFormRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
((CStoreApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
if(flag==1) //添加
{
m_pMaterialMoveFormRecordset->AddNew();
m_pMaterialMoveFormRecordset->PutCollect("materialMoveFormID",_variant_t(m_materialMoveFormID.Left(25)));
m_pMaterialMoveFormRecordset->PutCollect("formDate",_variant_t(m_FormDate));
m_pMaterialMoveFormRecordset->PutCollect("storeHouseIn",_variant_t(m_storeHouseIn.Left(50)));
m_pMaterialMoveFormRecordset->PutCollect("storeHouseOut",_variant_t(m_storeHouseOut.Left(50)));
m_pMaterialMoveFormRecordset->PutCollect("dealer",_variant_t(m_dealer.Left(50)));
m_pMaterialMoveFormRecordset->PutCollect("houseOutType",_variant_t(m_houseOutType.Left(50)));
m_pMaterialMoveFormRecordset->PutCollect("remark",_variant_t(m_remark.Left(100)));
m_pMaterialMoveFormRecordset->Update();
strSQL="SELECT * FROM materialMoveFormCommidity" ;
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("materialMoveFormID",_variant_t(m_materialMoveFormID.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("创建记录集失败!","错误");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -