📄 materialsummary.cpp
字号:
// MaterialSummary.cpp : implementation file
//
#include "stdafx.h"
#include "Store.h"
#include "MaterialSummary.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMaterialSummary dialog
CMaterialSummary::CMaterialSummary(CWnd* pParent /*=NULL*/)
: CDialog(CMaterialSummary::IDD, pParent)
{
//{{AFX_DATA_INIT(CMaterialSummary)
m_storeHouse = _T("");
m_num = 0;
//}}AFX_DATA_INIT
}
void CMaterialSummary::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMaterialSummary)
DDX_Control(pDX, IDC_LIST1, m_list);
DDX_Control(pDX, IDC_storeHouse, m_storeHouseCombo);
DDX_CBString(pDX, IDC_storeHouse, m_storeHouse);
DDX_Text(pDX, IDC_trueNum, m_num);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMaterialSummary, CDialog)
//{{AFX_MSG_MAP(CMaterialSummary)
ON_BN_CLICKED(IDC_save, OnSave)
ON_BN_CLICKED(IDC_exit, OnExit)
ON_CBN_SELCHANGE(IDC_storeHouse, OnSelchangestoreHouse)
ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMaterialSummary message handlers
void CMaterialSummary::OnSave()
{
UpdateData(true);
CString strSQL;
_RecordsetPtr m_pRecordset; //用于创建一个查询记录集
_RecordsetPtr m_psummaryFormRecordset;
HRESULT hTRes;
hTRes = m_psummaryFormRecordset.CreateInstance(_T("ADODB.Recordset"));
strSQL="SELECT * FROM accountFormCommidity" ;
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"));
int count=m_list.GetItemCount();
for(int i=0;i<count;i++)
{
m_pRecordset->AddNew();
m_pRecordset->PutCollect("accountID",_variant_t(m_summaryFormID.Left(25)));
m_pRecordset->PutCollect("storeHouse",_variant_t(m_storeHouse.Left(25)));
m_pRecordset->PutCollect("productID",_variant_t(m_list.GetItemText(i,1).Left(25)));
CString str;
str.Format("%d",m_num);
m_pRecordset->PutCollect("num",_variant_t(str));
m_pRecordset->PutCollect("price",_variant_t(m_list.GetItemText(i,4)));
m_pRecordset->Update();
// m_list.DeleteItem(nFirstSelItem);
m_list.SetItemText(nFirstSelItem,5,str);
}
AfxMessageBox("保存成功!");
}
}
}
catch(_com_error e)///捕捉异常
{
CString errormessage;
MessageBox("创建记录集失败!","错误");
}
}
void CMaterialSummary::OnExit()
{
this->OnCancel();
}
BOOL CMaterialSummary::OnInitDialog()
{
CDialog::OnInitDialog();
DWORD style;
style=m_list.GetExStyle();
style=(style|LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT)&(~LVS_EX_CHECKBOXES) ;
m_list.SetExtendedStyle(style);
m_list.InsertColumn(0,"仓库名称",LVCFMT_LEFT,100);
m_list.InsertColumn(1,"物料编号",LVCFMT_LEFT,100);
m_list.InsertColumn(2,"物料名称",LVCFMT_LEFT,100);
m_list.InsertColumn(3,"账面数量",LVCFMT_LEFT,100);
m_list.InsertColumn(4,"单价",LVCFMT_LEFT,100);
m_list.InsertColumn(5,"实际数量",LVCFMT_LEFT,100);
int formID=((CStoreApp*)AfxGetApp())->m_pIDRecordset->GetCollect("summaryFormID").intVal;
if(formID<10)
m_summaryFormID.Format("CLPD0000%d",formID);
else if(formID<100&&formID>9)
m_summaryFormID.Format("CLPD000%d",formID);
else if(formID<1000&&formID>99)
m_summaryFormID.Format("CLPD00%d",formID);
CString str;
str.Format("%d",formID+1);
((CStoreApp*)AfxGetApp())->m_pIDRecordset->PutCollect("summaryFormID",_variant_t(str));
((CStoreApp*)AfxGetApp())->m_pIDRecordset->Update();
_RecordsetPtr m_psummaryFormRecordset;
CString strSQL;
strSQL="select * from accountForm";
HRESULT hTRes;
hTRes = m_psummaryFormRecordset.CreateInstance(_T("ADODB.Recordset"));
hTRes = m_psummaryFormRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
((CStoreApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
m_psummaryFormRecordset->AddNew();
m_psummaryFormRecordset->PutCollect("accountID",_variant_t(m_summaryFormID.Left(25)));
m_psummaryFormRecordset->PutCollect("formDate",_variant_t(COleDateTime::GetCurrentTime()));
m_psummaryFormRecordset->PutCollect("formType",_variant_t("2"));
m_psummaryFormRecordset->Update();
_RecordsetPtr m_pRecordset;
strSQL="select distinct storeHouseName from storeHouse";
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))
{
while(!(m_pRecordset->adoEOF))
{
m_storeHouseCombo.AddString(((CStoreApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("storeHouseName")));
m_pRecordset->MoveNext();
}
}
}
m_pRecordset->Close();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CMaterialSummary::OnSelchangestoreHouse()
{
UpdateData(true);
CString strSQL;
_RecordsetPtr m_pRecordset;
HRESULT hTRes;
m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
strSQL="select * from temp";
hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
((CStoreApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
DATE dt;
COleDateTime da;
dt=m_pRecordset->GetCollect("lastAccountDate").date;
da=COleDateTime(dt);
m_pRecordset->Close();
strSQL="exec accountMaterial '";
strSQL=strSQL+m_storeHouse+"','";
CString str;
str.Format("%d",da.GetYear());
strSQL=strSQL+str+"-";
str.Format("%d",da.GetMonth());
strSQL=strSQL+str+"-";
str.Format("%d",da.GetDay());
strSQL=strSQL+str+"'";
// AfxMessageBox(strSQL);
m_list.DeleteAllItems();
int i=0;
m_pRecordset=(((CStoreApp*)AfxGetApp())->m_pConn)->Execute(_bstr_t(strSQL),NULL,adCmdText);
while (!(m_pRecordset->adoEOF))
{
m_list.InsertItem(i,((CStoreApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("storeHouse")));
m_list.SetItemText(i,1,((CStoreApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("materialID")));
m_list.SetItemText(i,2,((CStoreApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("materialName")));
m_list.SetItemText(i,3,((CStoreApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("sumNum")));
m_list.SetItemText(i,4,((CStoreApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("sumPrice")));
m_pRecordset->MoveNext();
i++;
}
}
void CMaterialSummary::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult)
{
UpdateData(true);
POSITION pos = m_list.GetFirstSelectedItemPosition();
if(pos)
{
nFirstSelItem = m_list.GetNextSelectedItem(pos);
m_materialID=m_list.GetItemText(nFirstSelItem,1);
m_storeHouse=m_list.GetItemText(nFirstSelItem,0);
}
*pResult = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -