📄 odereditdlg.cpp
字号:
// OderEditDlg.cpp : implementation file
//
#include "stdafx.h"
#include "ordermanagement.h"
#include "OderEditDlg.h"
#include "ADOConn.h"
#include "time.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// OderEditDlg dialog
OderEditDlg::OderEditDlg(CWnd* pParent /*=NULL*/)
: CDialog(OderEditDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(OderEditDlg)
m_str1 = _T("");
m_str10 = _T("");
m_str11 = _T("");
m_str2 = _T("");
m_str3 = _T("");
m_str5 = _T("");
m_str6 = _T("");
m_str7 = _T("");
m_str8 = _T("");
m_str9 = _T("");
m_str4Date = _T("");
//}}AFX_DATA_INIT
}
void OderEditDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(OderEditDlg)
DDX_Control(pDX, IDC_EDIT5, m_EditCtr5);
DDX_Control(pDX, IDC_EDIT1, m_EditCtr1);
DDX_Text(pDX, IDC_EDIT1, m_str1);
DDX_Text(pDX, IDC_EDIT10, m_str10);
DDX_Text(pDX, IDC_EDIT11, m_str11);
DDX_Text(pDX, IDC_EDIT2, m_str2);
DDX_Text(pDX, IDC_EDIT3, m_str3);
DDX_Text(pDX, IDC_EDIT5, m_str5);
DDX_Text(pDX, IDC_EDIT6, m_str6);
DDX_Text(pDX, IDC_EDIT7, m_str7);
DDX_Text(pDX, IDC_EDIT8, m_str8);
DDX_Text(pDX, IDC_EDIT9, m_str9);
DDX_Text(pDX, IDC_EDIT4_DATE, m_str4Date);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(OderEditDlg, CDialog)
//{{AFX_MSG_MAP(OderEditDlg)
ON_EN_KILLFOCUS(IDC_EDIT5, OnKillfocusEdit5)
ON_WM_CTLCOLOR()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// OderEditDlg message handlers
ADOConn oEconn;
_bstr_t oESQL;
_bstr_t oESQL2;
BOOL OderEditDlg::OnInitDialog()
{
CDialog::OnInitDialog();
//添加窗口图标
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
//取当前日期
COleDateTime dtNow = COleDateTime::GetCurrentTime();
CString strNow,oderNum;
//生成随机数作为订单的编码
srand( (unsigned)time( 0 ) ); //srand()函数产生一个以当前时间开始的随机种子
int num,snum;
loop:num =rand()%10000;//订单编码
if(num < 1000)
goto loop;
lo: snum = rand()%100;//出货单编码
if(snum < 10)
goto lo;
//以当前日期和订单编码前带 D 组成订单编号
oderNum.Format("D%d%d%d%d" , dtNow.GetYear(), dtNow.GetMonth(), dtNow.GetDay(),num);
//以当前日期和出货单编码前带 S 组成出货单编号
sendNum.Format("S%d%d%d%d" , dtNow.GetYear(), dtNow.GetMonth(), dtNow.GetDay(),snum);
//获取当前日期
strNow.Format("%d-%d-%d",dtNow.GetYear(), dtNow.GetMonth(), dtNow.GetDay());
//订单有效截止日期默认为当订单生成后三个月
strEDate.Format("%d-%d-%d",dtNow.GetYear(), dtNow.GetMonth()+3, dtNow.GetDay());
m_str1.Format("%s",oderNum); //订单ID号
m_str4Date.Format("%s",strNow); //签订日期
try{
//如果Concection对象为空,则重新连接
if(oEconn.m_pConn == NULL)
oEconn.OnInitADOConn();
oESQL ="select * from ClientMessage where currState=1";
oEconn.m_pRs = oEconn.GetRecordSet(oESQL);
oEconn.vCID = oEconn.m_pRs->GetCollect("clientID");
oEconn.vCN = oEconn.m_pRs->GetCollect("company");
cliID = (char *)(_bstr_t)oEconn.vCID;
cliName = (char *)(_bstr_t)oEconn.vCN;
m_str2 = cliID;
m_str3 = cliName;
oEconn.m_pRs->Close();
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
return false;
}
UpdateData(false);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void OderEditDlg::OnOK()
{
UpdateData(true);
CString storeNum,pdnum,odernum;
oESQL="select * from ProductMessage where productID='"+m_str5+"'";
oEconn.m_pRs = oEconn.GetRecordSet(oESQL);
oEconn.vSto = oEconn.m_pRs->GetCollect("storeNum");
storeNum = (char *)(_bstr_t)oEconn.vSto;
oEconn.vSto = oEconn.m_pRs->GetCollect("pdnum");
pdnum = (char *)(_bstr_t)oEconn.vSto;
oEconn.vSto = oEconn.m_pRs->GetCollect("odernum");
odernum = (char *)(_bstr_t)oEconn.vSto;
if(AddOder())
{
AfxMessageBox("您已经成功签订了订单!");
oEconn.m_pRs->Close();//关闭订单记录集
oESQL ="SELECT * FROM ConsignmentForm";//打开发货单记录集
oEconn.m_pRs = oEconn.GetRecordSet(oESQL);
CString mm="N";
oESQL ="INSERT INTO ConsignmentForm (sendOderID,oderFormID,orderstate) VALUES('"+sendNum+"','"+m_str1+"','"+mm+"')";
if(oEconn.ExecuteSQL(oESQL))
{
// AfxMessageBox("生成了一个发货单!");
SubPro();//更新产品记录
}
oESQL ="SELECT * FROM ProductMessage WHERE productID ='"+m_str5+"' and storeNum<'"+m_str7+"'";
oEconn.m_pRs = oEconn.GetRecordSet(oESQL);
if(!oEconn.m_pRs->adoBOF)//当订购的产品数量大于库存时添加生产计划单
{
m_str7.Format("%d",atoi(m_str7)-atoi(storeNum));
if(AddPlan())
// AfxMessageBox("成功添加生产单!")
;
}
m_str7.Format("%d",atoi(m_str7)+atoi(pdnum));
odernum.Format("%d",atoi(odernum)+1);
oESQL2 ="UPDATE ProductMessage SET pdnum='"+m_str7+"',odernum='"+odernum+"' WHERE ProductID ='"+m_str5+"'";
oEconn.ExecuteSQL(oESQL2);
DestroyWindow(); //关闭无模式对话框
delete this;
}
else
{
m_EditCtr5.SetFocus();
}
}
void OderEditDlg::OnCancel()
{
DestroyWindow(); //关闭无模式对话框
delete this;
}
bool OderEditDlg::AddOder()
{
if(!_ROW())
{
AfxMessageBox("所有信息必须都填写,请重新输入!!!");
return false;
}
else
{
try{
if(MessageBox("是否确定?","请确认",MB_YESNO) == IDYES)
{
//如果Concection对象为空,则重新连接
if(oEconn.m_pConn == NULL)
oEconn.OnInitADOConn();
oESQL ="SELECT * FROM OderFormMessage ";//打开订单记录集
oEconn.m_pRs = oEconn.GetRecordSet(oESQL);
//添加订单
oESQL ="INSERT INTO OderFormMessage (oderFormID,clientID,clientName,productID,productName,productNum,companyContactPerson,clientContactPerson,consignmentAddress,formDate,endDate,remark) VALUES('"+m_str1+"','"+m_str2+"','"+m_str3+"','"+m_str5+"','"+m_str6+"','"+m_str7+"','"+m_str8+"','"+m_str9+"','"+m_str10+"','"+m_str4Date+"','"+strEDate+"','"+m_str11+"')";
if(oEconn.ExecuteSQL(oESQL))
return true;
}
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
return false;
}
}
return false;
}
bool OderEditDlg::_ROW()
{
if(m_str1.IsEmpty() || m_str2.IsEmpty() || m_str3.IsEmpty() || m_str5.IsEmpty()
|| m_str6.IsEmpty() || m_str7.IsEmpty() || m_str8.IsEmpty() || m_str9.IsEmpty())
return false;
else
return true;
}
//当产品ID编辑框失去焦点时使产品名称编辑框显示相应的值
void OderEditDlg::OnKillfocusEdit5()
{
UpdateData(true);
if(!m_str5.IsEmpty())//当产品ID编辑框不为空时进行操作
{
if(oEconn.m_pConn == NULL)
oEconn.OnInitADOConn();
oESQL ="SELECT * FROM ProductMessage WHERE productID ='"+m_str5+"'";//取对应ID的产品记录
oEconn.m_pRs = oEconn.GetRecordSet(oESQL);
oEconn.vPN = oEconn.m_pRs->GetCollect("productName");
m_str6 = (char *)(_bstr_t)oEconn.vPN;
UpdateData(false);
oEconn.m_pRs->Close();//关闭产品记录集
}
}
bool OderEditDlg::AddPlan()
{
//取当前日期
COleDateTime dtNow = COleDateTime::GetCurrentTime();
CString strNow,planNum,rem;
//生成随机数作为生产单的编码
srand( (unsigned)time( 0 ) ); //srand()函数产生一个以当前时间开始的随机种子
int num;
l: num =rand()%100;//生产单编码(两位)
if(num < 10)
goto l;
//以当前日期和生产单编码前带 M 组成生产单编号
planNum.Format("M%d%d%d%d" , dtNow.GetYear(), dtNow.GetMonth(), dtNow.GetDay(),num);
//获取当前日期
strNow.Format("%d-%d-%d",dtNow.GetYear(), dtNow.GetMonth(), dtNow.GetDay());
//生成生产计划单,期限默认为30天,生产数量为客户所订购的数量
oESQL = "INSERT INTO PlanFormMessage (planID,productID,productName,produceNum,limitedTime,formDate) VALUES ('"+planNum+"','"+m_str5+"','"+m_str6+"','"+m_str7+"', '30','"+strNow+"')";
if(oEconn.ExecuteSQL(oESQL))
return true;
return false;
}
void OderEditDlg::SubPro()
{
oESQL ="SELECT * FROM ProductMessage WHERE productID ='"+m_str5+"' and storeNum<'"+m_str7+"'";
oEconn.m_pRs = oEconn.GetRecordSet(oESQL);
if(!oEconn.m_pRs->adoBOF) oESQL ="UPDATE ProductMessage SET storeNum=0 WHERE productID='"+m_str5+"'";
else oESQL ="UPDATE ProductMessage SET storeNum=storeNum -'"+m_str7+"' WHERE productID='"+m_str5+"'";
oEconn.ExecuteSQL(oESQL);
// AfxMessageBox("成功更新产品信息!");
}
HBRUSH OderEditDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
//HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
COLORREF backColor = RGB(231, 231, 231); //office 2003背景色
pDC->SetBkMode(TRANSPARENT); //设置控件背景透明
return CreateSolidBrush(backColor); //创建背景刷子
// TODO: Return a different brush if the default is not desired
//return hbr;
//HBRUSH hbr = CDialog::OnCtlColor(pDC,pWnd,nCtlColor);
//pDC->SetBkMode(TRANSPARENT);
//return (HBRUSH)GetStockObject(NULL_BRUSH);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -