⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 proadddlg.cpp

📁 订单管理系统
💻 CPP
字号:
// ProAddDlg.cpp : implementation file
//

#include "stdafx.h"
#include "ordermanagement.h"
#include "ProAddDlg.h"
#include "ADOConn.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// ProAddDlg dialog


ProAddDlg::ProAddDlg(CWnd* pParent /*=NULL*/)
	: CDialog(ProAddDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(ProAddDlg)
	m_str1 = _T("");
	m_str2 = _T("");
	m_str3 = _T("");
	m_str4 = _T("");
	m_str5 = _T("");
	m_str6 = _T("");
	m_str7 = _T("");
	m_str8 = _T("");
	m_str9 = _T("");
	//}}AFX_DATA_INIT
}


void ProAddDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(ProAddDlg)
	DDX_Control(pDX, IDC_EDIT1, m_EditCtr1);
	DDX_Text(pDX, IDC_EDIT1, m_str1);
	DDX_Text(pDX, IDC_EDIT2, m_str2);
	DDX_Text(pDX, IDC_EDIT3, m_str3);
	DDX_Text(pDX, IDC_EDIT4, m_str4);
	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);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(ProAddDlg, CDialog)
	//{{AFX_MSG_MAP(ProAddDlg)
	ON_WM_CTLCOLOR()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// ProAddDlg message handlers

ADOConn aPconn;
_bstr_t aPSQL;

BOOL ProAddDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	//添加窗口图标
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon

	AfxMessageBox("注意!日期格式为:年-月-日");

	if(dBMod)
	{
		pID = m_str1;
	}	
	else
	{
		//生成随机数作为产品的编码
		srand( (unsigned)time( 0 ) ); //srand()函数产生一个以当前时间开始的随机种子
		int pnum;
loop:   pnum =rand()%1000;
		if(pnum < 100)
		   goto loop;
		
		//获取当前日期
		COleDateTime dtNow = COleDateTime::GetCurrentTime();
		CString strNow;
		
		//以当前日期和订单编码前带 P 组成产品编号
		strNow.Format("P%d%d%d%d" , dtNow.GetYear(), dtNow.GetMonth(), dtNow.GetDay(),pnum);
		m_str1 = strNow;
	}
	UpdateData(false);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void ProAddDlg::OnOK() 
{
	UpdateData(true);
	if(!_ROW())
	{
		AfxMessageBox("所有信息必须都填写,请重新输入!");
		m_EditCtr1.SetFocus();			  //焦点返回产品ID输入框
	}
	else
	{	
		if(MessageBox("是否确定?","请确认",MB_YESNO) == IDYES)
		{
			if(!dBMod)
				pAdd();
			else
			{
				dBMod = false;
				pMod();
			}
		}
		else
			m_EditCtr1.SetFocus();
	}
	
//	
}

bool ProAddDlg::_ROW()
{
	if(m_str1.IsEmpty() || m_str2.IsEmpty() || m_str3.IsEmpty() || m_str4.IsEmpty() || m_str5.IsEmpty()
		|| m_str5.IsEmpty() || m_str6.IsEmpty() || m_str7.IsEmpty() || m_str8.IsEmpty() || m_str9.IsEmpty())
		return false;
	else
		return true;
}


void ProAddDlg::pAdd()
{
	aPSQL ="INSERT INTO ProductMessage (productID,productName,price,produceDate,maintance,storeNum,unit,colorType,remark) VALUES('"+m_str1+"','"+m_str2+"','"+m_str3+"','"+m_str4+"','"+m_str5+"','"+m_str6+"','"+m_str7+"','"+m_str8+"','"+m_str9+"')";
	if(aPconn.ExecuteSQL(aPSQL))
	{
		AfxMessageBox("产品信息添加成功!");
		CDialog::OnOK();
	}
}

void ProAddDlg::pMod()
{
	aPSQL ="UPDATE ProductMessage SET productID='"+m_str1+"',productName='"+m_str2+"',price='"+m_str3+"',produceDate='"+m_str4+"',maintance='"+m_str5+"',storeNum='"+m_str6+"',unit='"+m_str7+"',colorType='"+m_str8+"',remark='"+m_str9+"' WHERE ProductID ='"+pID+"'";
	if(aPconn.ExecuteSQL(aPSQL))
		AfxMessageBox("产品信息修改成功!");
		CDialog::OnOK();
}


HBRUSH ProAddDlg::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 + -