📄 billadd.cpp
字号:
// BillAdd.cpp : implementation file
//
#include "stdafx.h"
#include "OIL.h"
#include "BillAdd.h"
#include "CustomerAdd.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CBillAdd dialog
CBillAdd::CBillAdd(CWnd* pParent /*=NULL*/)
: CDialog(CBillAdd::IDD, pParent)
{
//{{AFX_DATA_INIT(CBillAdd)
m_strAgentBH = _T("");
m_bPrint = FALSE;
m_nDeadDays = 0;
m_lInitQuantity = 0;
m_lOutFee = 0;
m_lRemain = 0;
m_strTydID = _T("");
m_strCustomerName = _T("");
m_strOilName = _T("");
//}}AFX_DATA_INIT
}
void CBillAdd::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CBillAdd)
DDX_Control(pDX, IDC_DT_DEADDATE, m_dtcDeadDate);
DDX_Control(pDX, IDC_DT_MAKEOUTDATE, m_dtcMakeOut);
DDX_Text(pDX, IDC_AGENTBH, m_strAgentBH);
DDX_Check(pDX, IDC_CK_PRINT, m_bPrint);
DDX_Text(pDX, IDC_DEADDAYS, m_nDeadDays);
DDX_Text(pDX, IDC_INITQUANTITY, m_lInitQuantity);
DDX_Text(pDX, IDC_OUTFEE, m_lOutFee);
DDX_Text(pDX, IDC_REMAIN, m_lRemain);
DDX_Text(pDX, IDC_TYDID, m_strTydID);
DDX_CBString(pDX, IDC_COMBO_CUSTOMERNAME, m_strCustomerName);
DDX_CBString(pDX, IDC_COMBO_OILNAME, m_strOilName);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CBillAdd, CDialog)
//{{AFX_MSG_MAP(CBillAdd)
ON_BN_CLICKED(IDC_CUSTOMER_ADD, OnCustomerAdd)
ON_CBN_SELCHANGE(IDC_COMBO_CUSTOMERNAME, OnSelchangeComboCustomername)
ON_EN_CHANGE(IDC_INITQUANTITY, OnChangeInitquantity)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBillAdd message handlers
void CBillAdd::OnOK()
{
// TODO: Add extra validation here
UpdateData();
//检查数据完整性
if(m_lInitQuantity==0)
{
AfxMessageBox("发油量不能为空!");
GetDlgItem(IDC_INITQUANTITY)->SetFocus();
return;
}
//根据实际情况插入或修改数据
CString sql;
if(m_nDoWhat==ADD) //新开提油单
{
UpdateData();
CString strMakeOut=FormatTimeCtrl(&m_dtcMakeOut);
CString strDeadTime=FormatTimeCtrl(&m_dtcDeadDate);
CString strInitQuantity;
strInitQuantity.Format("%d",m_lInitQuantity);
CString strnow=GetSysDateTime();
CString strCustomerID=GetCustomerID(m_strCustomerName);
//生成SQL语句
sql="insert into \
tiyoudan(TydID,AgentBH,MakeOutDate,deadline,initQuantity,\
CustomerID,OilName,state,Remain,MakeoutName,invoicetime) \
values ('"+m_strTydID+"','"+m_strAgentBH+"','"+strMakeOut
+"','"+strDeadTime+"',"+strInitQuantity+",'"+strCustomerID
+"','"+m_strOilName+"','T',"+strInitQuantity+",'"
+theGlobal.strUserName+"','"+strnow+"')";
//执行语句
_variant_t RecordsAffected;
theApp.m_pConnection->Execute((_bstr_t)sql,&RecordsAffected,adCmdText);
}
//修改提油单资料
if(m_nDoWhat==EDIT)
{
//准备参数
CString strMakeOut=FormatTimeCtrl(&m_dtcMakeOut);
CString strDeadTime=FormatTimeCtrl(&m_dtcDeadDate);
CString strInitQuantity;
strInitQuantity.Format("%d",m_lInitQuantity);
CString strRemain;
strRemain.Format("%d",m_lRemain);
//生成动态sql语句
sql="update tiyoudan set AgentBH='"+m_strAgentBH+
"',MakeOutDate='"+strMakeOut+
"',deadline='"+strDeadTime+
"',initQuantity='"+strInitQuantity+
"',Remain='"+strRemain+
"',OilName='"+m_strOilName+
"' where TydID='"+m_strTydID+"' ";
//执行语句
_variant_t RecordsAffected;
theApp.m_pConnection->Execute((_bstr_t)sql,&RecordsAffected,adCmdText);
//返回主界面
OnCancel();
}
//提油单延期
if(m_nDoWhat==DELAY)
{
}
//提油单作费
if(m_nDoWhat==UNUSE)
{
}
//提油单分单
if(m_nDoWhat==DIV)
{
}
CDialog::OnOK();
}
//开票时新增客户
void CBillAdd::OnCustomerAdd()
{
// TODO: Add your control notification handler code here
CCustomerAdd aCustomerAdd;
aCustomerAdd.m_nDoWhat=ADD; //新增客户资料
aCustomerAdd.m_pParent=NULL; //无需更新List控件
aCustomerAdd.DoModal();
}
//初始化对话框
BOOL CBillAdd::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
//显示所有客户名
CString sql="select customerName from customer";
CComboBox *m_pComboBox = (CComboBox *) GetDlgItem(IDC_COMBO_CUSTOMERNAME);
ReadtoComBoBox(m_pComboBox,sql);
//设置一个默认客户
//设置油品种类
m_pComboBox = (CComboBox *) GetDlgItem(IDC_COMBO_OILNAME);
m_pComboBox->AddString("柴油");
m_pComboBox->AddString("汽油");
m_pComboBox->AddString("重油");
//设置相应的标题
switch(m_nDoWhat)
{
case ADD: //新开提油单
{
SetWindowText("新开提油单");
SetDlgItemText(IDOK,"增加");
GetDlgItem(IDC_REMAIN)->EnableWindow(false);
GetDlgItem(IDC_OUTFEE)->EnableWindow(false);
GetDlgItem(IDC_DEADDAYS)->EnableWindow(false);
//设置当前日期为开票日期及过期时间
CTime now=CTime::GetCurrentTime();
m_dtcMakeOut.SetTime(&now);
now+=CTimeSpan(15,0,0,0);
m_dtcDeadDate.SetTime(&now);
//默认为柴油
m_strOilName="柴油";
UpdateData(false);
}
break;
case 2: //修改提油单
SetWindowText("修改提油单");
SetDlgItemText(IDOK,"修改");
GetDlgItem(IDC_TYDID)->EnableWindow(false);
GetDlgItem(IDC_COMBO_CUSTOMERNAME)->EnableWindow(false);
DisplayComBoBox((CComboBox *)GetDlgItem(IDC_COMBO_CUSTOMERNAME),m_strCustomerName);
//设置开票日期及失效日期
m_dtcMakeOut.SetTime(&m_dtMakeOut);
m_dtcDeadDate.SetTime(&m_dtDeadDate);
break;
case 3: //提油单延期
SetWindowText("提油单延期");
SetDlgItemText(IDOK,"修改");
GetDlgItem(IDC_TYDID)->EnableWindow(false);
GetDlgItem(IDC_COMBO_CUSTOMERNAME)->EnableWindow(false);
DisplayComBoBox((CComboBox *)GetDlgItem(IDC_COMBO_CUSTOMERNAME),m_strCustomerName);
//设置开票日期及失效日期
m_dtcMakeOut.SetTime(&m_dtMakeOut);
m_dtcDeadDate.SetTime(&m_dtDeadDate);
break;
case 4: //default;
ASSERT("Failure");
break;
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CBillAdd::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
void CBillAdd::OnSelchangeComboCustomername()
{
// TODO: Add your control notification handler code here
CString strTemp;
CComboBox * m_pComboBox;
m_pComboBox=(CComboBox *)GetDlgItem(IDC_COMBO_CUSTOMERNAME);
int index=((CComboBox *)m_pComboBox)->GetCurSel();
m_pComboBox->GetLBText(index,strTemp);//strContent中就是选中的内容
//得到自动流水号
SetDlgItemText(IDC_TYDID,GetAutoTydID(strTemp));
}
void CBillAdd::OnChangeInitquantity()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
if(m_nDoWhat==ADD)
{
CString tmp;
GetDlgItemText(IDC_INITQUANTITY,tmp);
SetDlgItemText(IDC_REMAIN,tmp);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -