📄 consignmentinvoice.cpp
字号:
// ConsignmentInvoice.cpp : implementation file
//
#include "stdafx.h"
#include "Sale.h"
#include "ConsignmentInvoice.h"
#include "SelectCommodityForQuote.h"
#include "Affirm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CConsignmentInvoice dialog
CConsignmentInvoice::CConsignmentInvoice(CWnd* pParent /*=NULL*/)
: CDialog(CConsignmentInvoice::IDD, pParent)
{
//{{AFX_DATA_INIT(CConsignmentInvoice)
m_consignmentFormID = _T("");
m_orderFormID = _T("");
m_formDate = COleDateTime::GetCurrentTime();
m_transportType = _T("");
m_transportCompany = _T("");
m_clientName = _T("");
m_payCondition = _T("");
m_seller = _T("");
m_saleType = _T("");
m_department = _T("");
m_consignmentAddress = _T("");
m_storeHouse = _T("");
m_remark = _T("");
consignmentFormID=_T("");
//}}AFX_DATA_INIT
}
void CConsignmentInvoice::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CConsignmentInvoice)
DDX_Control(pDX, IDC_storeHouse, m_storeHouseCombo);
DDX_Control(pDX, IDC_department, m_departmentCombo);
DDX_Control(pDX, IDC_saleType, m_saleTypeCombo);
DDX_Control(pDX, IDC_seller, m_sellerCombo);
DDX_Control(pDX, IDC_payCondition, m_payConditionCombo);
DDX_Control(pDX, IDC_clientName, m_clientNameCombo);
DDX_Control(pDX, IDC_transportCompany, m_transportCompanyCombo);
DDX_Control(pDX, IDC_transportType, m_transportTypeCombo);
DDX_Control(pDX, IDC_orderFormID, m_orderFormIDCombo);
DDX_Control(pDX, IDC_LIST1, m_consignmentFormList);
DDX_Text(pDX, IDC_consignmentFormID, m_consignmentFormID);
DDX_CBString(pDX, IDC_orderFormID, m_orderFormID);
DDX_DateTimeCtrl(pDX, IDC_formDate, m_formDate);
DDX_CBString(pDX, IDC_transportType, m_transportType);
DDX_CBString(pDX, IDC_transportCompany, m_transportCompany);
DDX_CBString(pDX, IDC_clientName, m_clientName);
DDX_CBString(pDX, IDC_payCondition, m_payCondition);
DDX_CBString(pDX, IDC_seller, m_seller);
DDX_CBString(pDX, IDC_saleType, m_saleType);
DDX_CBString(pDX, IDC_department, m_department);
DDX_Text(pDX, IDC_consignmentAddress, m_consignmentAddress);
DDX_CBString(pDX, IDC_storeHouse, m_storeHouse);
DDX_Text(pDX, IDC_remark, m_remark);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CConsignmentInvoice, CDialog)
//{{AFX_MSG_MAP(CConsignmentInvoice)
ON_BN_CLICKED(IDC_exit, OnExit)
ON_BN_CLICKED(IDC_save, OnSave)
ON_BN_CLICKED(IDC_deleteLine, OnDeleteLine)
ON_BN_CLICKED(IDC_addLine, OnAddLine)
ON_BN_CLICKED(IDC_delete, OnDelete)
ON_BN_CLICKED(IDC_modify, OnModify)
ON_BN_CLICKED(IDC_new, OnNew)
ON_BN_CLICKED(IDC_lastPage, OnLastPage)
ON_BN_CLICKED(IDC_nextPage, OnNextPage)
ON_BN_CLICKED(IDC_prevPage, OnPrevPage)
ON_BN_CLICKED(IDC_firstPage, OnFirstPage)
ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickConsignmenFormList)
ON_CBN_KILLFOCUS(IDC_orderFormID, OnKillfocusOrderFormID)
ON_BN_CLICKED(IDC_auditing, OnAuditing)
ON_BN_CLICKED(IDC_cancellation, OnCancellation)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CConsignmentInvoice message handlers
void CConsignmentInvoice::OnExit()
{
this->OnCancel();
}
void CConsignmentInvoice::OnSave()
{
UpdateData(true);
_RecordsetPtr m_pRecordset; //用于创建一个查询记录集
CString strSQL;
if(flag==1) //添加
{
m_pConsignmentFormRecordset->AddNew();
m_pConsignmentFormRecordset->PutCollect("orderFormID",_variant_t(m_orderFormID.Left(25)));
m_pConsignmentFormRecordset->PutCollect("consignmentFormID",_variant_t(m_consignmentFormID.Left(25)));
m_pConsignmentFormRecordset->PutCollect("formDate",_variant_t(m_formDate));
m_pConsignmentFormRecordset->PutCollect("clientName",_variant_t(m_clientName.Left(50)));
m_pConsignmentFormRecordset->PutCollect("transportType",_variant_t(m_transportType.Left(50)));
m_pConsignmentFormRecordset->PutCollect("payCondition",_variant_t(m_payCondition.Left(50)));
m_pConsignmentFormRecordset->PutCollect("seller",_variant_t(m_seller.Left(50)));
m_pConsignmentFormRecordset->PutCollect("department",_variant_t(m_department.Left(50)));
m_pConsignmentFormRecordset->PutCollect("consignmentAddress",_variant_t(m_consignmentAddress.Left(50)));
m_pConsignmentFormRecordset->PutCollect("remark",_variant_t(m_remark.Left(100)));
m_pConsignmentFormRecordset->PutCollect("saleType",_variant_t(m_saleType.Left(50)));
m_pConsignmentFormRecordset->PutCollect("storeHouse",_variant_t(m_storeHouse.Left(50)));
m_pConsignmentFormRecordset->PutCollect("transportCompany",_variant_t(m_transportCompany.Left(50)));
m_pConsignmentFormRecordset->PutCollect("checked",_variant_t("F"));
m_pConsignmentFormRecordset->Update();
strSQL="SELECT * FROM consignmentFormCommidity" ;
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"));
for(int i=0;i<m_consignmentFormList.GetItemCount();i++)
{
m_pRecordset->AddNew();
m_pRecordset->PutCollect("consignmentFormID",_variant_t(m_consignmentFormID.Left(25)));
m_pRecordset->PutCollect("commidityID",_variant_t(m_consignmentFormList.GetItemText(i,0)));
m_pRecordset->PutCollect("num",_variant_t(m_consignmentFormList.GetItemText(i,4)));
m_pRecordset->PutCollect("price",_variant_t(m_consignmentFormList.GetItemText(i,3)));
m_pRecordset->Update();
}
AfxMessageBox("保存成功!");
}
}
}
catch(_com_error e)///捕捉异常
{
CString errormessage;
MessageBox("创建记录集失败!","错误");
}
}
else if(flag==2) //修改
{
m_pConsignmentFormRecordset->PutCollect("orderFormID",_variant_t(m_orderFormID.Left(25)));
m_pConsignmentFormRecordset->PutCollect("consignmentFormID",_variant_t(m_consignmentFormID.Left(25)));
m_pConsignmentFormRecordset->PutCollect("formDate",_variant_t(m_formDate));
m_pConsignmentFormRecordset->PutCollect("clientName",_variant_t(m_clientName.Left(50)));
m_pConsignmentFormRecordset->PutCollect("transportType",_variant_t(m_transportType.Left(50)));
m_pConsignmentFormRecordset->PutCollect("payCondition",_variant_t(m_payCondition.Left(50)));
m_pConsignmentFormRecordset->PutCollect("seller",_variant_t(m_seller.Left(50)));
m_pConsignmentFormRecordset->PutCollect("department",_variant_t(m_department.Left(50)));
m_pConsignmentFormRecordset->PutCollect("consignmentAddress",_variant_t(m_consignmentAddress.Left(50)));
m_pConsignmentFormRecordset->PutCollect("remark",_variant_t(m_remark.Left(100)));
m_pConsignmentFormRecordset->PutCollect("saleType",_variant_t(m_saleType.Left(50)));
m_pConsignmentFormRecordset->PutCollect("storeHouse",_variant_t(m_storeHouse.Left(50)));
m_pConsignmentFormRecordset->PutCollect("transportCompany",_variant_t(m_transportCompany.Left(50)));
m_pConsignmentFormRecordset->PutCollect("checked",_variant_t("F"));
m_pConsignmentFormRecordset->Update();
_variant_t RecordsAffected;
CString strSQL;
strSQL="delete from consignmentFormCommidity where consignmentFormID='";
strSQL=strSQL+m_consignmentFormID+"'";
(((CSaleApp*)AfxGetApp())->m_pConn)->Execute((_bstr_t)strSQL,&RecordsAffected,adCmdText);
strSQL="SELECT * FROM consignmentFormCommidity" ;
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"));
for(int i=0;i<m_consignmentFormList.GetItemCount();i++)
{
m_pRecordset->AddNew();
m_pRecordset->PutCollect("consignmentFormID",_variant_t(m_consignmentFormID.Left(30)));
m_pRecordset->PutCollect("commidityID",_variant_t(m_consignmentFormList.GetItemText(i,0)));
m_pRecordset->PutCollect("num",_variant_t(m_consignmentFormList.GetItemText(i,4)));
m_pRecordset->PutCollect("price",_variant_t(m_consignmentFormList.GetItemText(i,3)));
m_pRecordset->Update();
}
AfxMessageBox("保存成功!");
}
}
}
catch(_com_error e)///捕捉异常
{
CString errormessage;
MessageBox("创建记录集失败!","错误");
}
}
bt_add->EnableWindow(true);
bt_prevPage->EnableWindow(true);
bt_firstPage->EnableWindow(true);
bt_nextPage->EnableWindow(true);
bt_lastPage->EnableWindow(true);
bt_modify->EnableWindow(true);
bt_addLine->EnableWindow(false);
bt_deleteLine->EnableWindow(false);
bt_checked->EnableWindow(true);
bt_cancellation->EnableWindow(false);
UpdateData(false);
}
void CConsignmentInvoice::OnDeleteLine()
{
CAffirm dlg;
if(dlg.DoModal()!=IDOK)
{
return;
}
POSITION pos = m_consignmentFormList.GetFirstSelectedItemPosition();
if(pos)
{
int nFirstSelItem = m_consignmentFormList.GetNextSelectedItem(pos);
m_consignmentFormList.DeleteItem(nFirstSelItem);
}
}
void CConsignmentInvoice::OnAddLine()
{
CSelectCommodityForQuote dlg;
if(dlg.DoModal()==IDOK)
{
int i=m_consignmentFormList.GetItemCount();
m_consignmentFormList.InsertItem(i,dlg.commodityID);
m_consignmentFormList.SetItemText(i,1,dlg.commodityName);
m_consignmentFormList.SetItemText(i,2,dlg.price);
CString str;
str.Format("%f",dlg.m_truePrice);
m_consignmentFormList.SetItemText(i,3,str);
str.Format("%d",dlg.m_num);
m_consignmentFormList.SetItemText(i,4,str);
AfxMessageBox("插入成功!");
}
else
{
AfxMessageBox("没有增加商品!");
}
UpdateData(false);
}
void CConsignmentInvoice::OnDelete()
{
CAffirm dlg;
if(dlg.DoModal()!=IDOK)
{
return;
}
_variant_t RecordsAffected;
CString strSQL;
strSQL="delete from consignmentForm where consignmentFormID='";
strSQL=strSQL+m_consignmentFormID+"'";
(((CSaleApp*)AfxGetApp())->m_pConn)->Execute((_bstr_t)strSQL,&RecordsAffected,adCmdText);
m_consignmentFormList.DeleteAllItems();
UpdateData(false);
AfxMessageBox("该发货单已删除!");
OnNextPage();
}
void CConsignmentInvoice::OnModify()
{
CString str;
if(m_pConsignmentFormRecordset->adoEOF)
m_pConsignmentFormRecordset->MovePrevious();
str=((CSaleApp*)AfxGetApp())->GetStringFromVariant(m_pConsignmentFormRecordset->GetCollect("checked"));
if(str=="T")
{
AfxMessageBox("已经通过审核,不可以修改!");
return;
}
else
{
SetDlgItemText(IDC_auditing,"审核");
CString strSQL;
HRESULT hTRes;
strSQL="select * from client";
_RecordsetPtr m_pClientRecordset;
hTRes = m_pClientRecordset.CreateInstance(_T("ADODB.Recordset"));
if (SUCCEEDED(hTRes))
{
//----------------------------------------------------
hTRes = m_pClientRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
((CSaleApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
if(SUCCEEDED(hTRes))
{
TRACE(_T("连接成功!\n"));
// CComboBox clientList=GetDlgItem(IDC_client);
// AfxMessageBox(((CSaleApp*)AfxGetApp())->GetStringFromVariant(m_pClientRecordset->GetCollect("clientID")));
while(!(m_pClientRecordset->adoEOF))
{
m_clientNameCombo.AddString(((CSaleApp*)AfxGetApp())->GetStringFromVariant(m_pClientRecordset->GetCollect("clientID")));
m_pClientRecordset->MoveNext();
}
}
}
m_pClientRecordset->Close();
strSQL="select * from transportType";
_RecordsetPtr m_pTransportTypeRecordset;
hTRes = m_pTransportTypeRecordset.CreateInstance(_T("ADODB.Recordset"));
if (SUCCEEDED(hTRes))
{
hTRes = m_pTransportTypeRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
((CSaleApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
if(SUCCEEDED(hTRes))
{
TRACE(_T("连接成功!\n"));
while(!(m_pTransportTypeRecordset->adoEOF))
{
m_transportTypeCombo.AddString(((CSaleApp*)AfxGetApp())->GetStringFromVariant(m_pTransportTypeRecordset->GetCollect("transportTypeName")));
m_pTransportTypeRecordset->MoveNext();
}
}
}
m_pTransportTypeRecordset->Close();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -