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

📄 proinfodlg.cpp

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

#include "stdafx.h"
#include "ordermanagement.h"
#include "ProInfoDlg.h"
#include "ADOConn.h"

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

/////////////////////////////////////////////////////////////////////////////
// ProInfoDlg dialog


ProInfoDlg::ProInfoDlg(CWnd* pParent /*=NULL*/)
	: CDialog(ProInfoDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(ProInfoDlg)
	m_pStr = _T("");
	m_nSearch = -1;
	m_nSort = -1;
	//}}AFX_DATA_INIT
}


void ProInfoDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(ProInfoDlg)
	DDX_Control(pDX, IDC_LIST_PRO, m_listCtr);
	DDX_Control(pDX, IDC_KSORT_COMB, m_soCtr);
	DDX_Control(pDX, IDC_KSEARCH_COMB, m_seCtr);
	DDX_Text(pDX, IDC_KEY_EDIT, m_pStr);
	DDX_CBIndex(pDX, IDC_KSEARCH_COMB, m_nSearch);
	DDX_CBIndex(pDX, IDC_KSORT_COMB, m_nSort);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(ProInfoDlg, CDialog)
	//{{AFX_MSG_MAP(ProInfoDlg)
	ON_BN_CLICKED(IDC_SEARCH_BTN, OnSearchBtn)
	ON_BN_CLICKED(IDC_SORT_BTN, OnSortBtn)
	ON_NOTIFY(NM_CLICK, IDC_LIST_PRO, OnClickListPro)
	ON_NOTIFY(NM_DBLCLK, IDC_LIST_PRO, OnDblclkListPro)
	ON_BN_CLICKED(IDC_ADD_BNT, OnAddBnt)
	ON_BN_CLICKED(IDC_CHAN_BNT, OnChanBnt)
	ON_BN_CLICKED(IDC_REFRESH_BNT, OnRefreshBnt)
	ON_BN_CLICKED(IDC_DEL_BNT, OnDelBnt)
	ON_WM_CTLCOLOR()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// ProInfoDlg message handlers
ProAddDlg addPdlg;
ADOConn connn;
_bstr_t sSQL2;
BOOL ProInfoDlg::OnInitDialog() 
{
		CDialog::OnInitDialog();
	m_ncurrSel = -1;
	//初始化图标
	m_imagelist.Create(16, 16,ILC_MASK,1,4);
	HICON hIcon=AfxGetApp()->LoadIcon(IDI_ICON2);
	m_imagelist.Add(hIcon);

	//初始化列表框表头
	m_listCtr.SetImageList(&m_imagelist,LVSIL_SMALL);

	m_listCtr.InsertColumn(0,"产 品 ID",LVCFMT_LEFT,150);
	m_listCtr.InsertColumn(1,"产品名称",LVCFMT_LEFT,100);
	m_listCtr.InsertColumn(2,"产品单价/元",LVCFMT_LEFT,80);
	m_listCtr.InsertColumn(3,"生产日期",LVCFMT_LEFT,100);
	m_listCtr.InsertColumn(4,"保质期(天)",LVCFMT_LEFT,80);
	m_listCtr.InsertColumn(5,"库存数量",LVCFMT_LEFT,80);
	m_listCtr.InsertColumn(6,"计数单位",LVCFMT_LEFT,80);
	m_listCtr.InsertColumn(7,"颜色类别",LVCFMT_LEFT,80);
	m_listCtr.InsertColumn(8,"产品备注",LVCFMT_LEFT,200);
	/* -- 设置单列全选,显示网格 -- */
	m_listCtr.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);	

	m_nSortType = 0;
	this->pBindList();

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
void ProInfoDlg::pBindList()
{
	ADOConn pconn;
	_RecordsetPtr  m_pPRecordset;
	_bstr_t vSQL;

	CString sKey,sort;
	int nItem;
	m_listCtr.DeleteAllItems();
	
	try{
		//如果Concection对象为空,则重新连接order by productID DESC 
		if(pconn.m_pConn == NULL)  
			pconn.OnInitADOConn();

			if(m_soCtr.GetCurSel() == 0)
				sort = "ASC";
			else 
			    sort = "DESC";

		switch(m_nSortType)
		{
		case 0: 
			vSQL = "select * from ProductMessage order by productID "+sort;
			m_pPRecordset = pconn.GetRecordSet(vSQL);	
			break;
		case 1: 
			vSQL="select * from ProductMessage where productID='"+m_pStr+"'order by productID "+sort;
			m_pPRecordset = pconn.GetRecordSet(vSQL);
			break;
		case 2: vSQL= "select * from ProductMessage where productName='" +m_pStr+ "'order by productID "+sort;
			m_pPRecordset = pconn.GetRecordSet(vSQL);
			break;
		default: break;
		}	
		while(!m_pPRecordset->adoEOF)
		{
			pconn.vPID = m_pPRecordset->GetCollect("productID");
			pconn.vPN  = m_pPRecordset->GetCollect("productName");
			pconn.vPr = m_pPRecordset->GetCollect("price");
			pconn.vPD = m_pPRecordset->GetCollect("produceDate");	
			pconn.vMtance = m_pPRecordset->GetCollect("maintance");
			pconn.vSto = m_pPRecordset->GetCollect("storeNum");	
			pconn.vUnit = m_pPRecordset->GetCollect("unit");
			pconn.vCo = m_pPRecordset->GetCollect("colorType");
			pconn.vRemark = m_pPRecordset->GetCollect("remark");
			// -- 添加数据到列表控件中 -- //
			nItem = m_listCtr.InsertItem(0xffff,(_bstr_t)pconn.vPID,0);
			m_listCtr.SetItemText(nItem,1,(_bstr_t)pconn.vPN);
			m_listCtr.SetItemText(nItem,2,(_bstr_t)pconn.vPr);
			m_listCtr.SetItemText(nItem,3,(_bstr_t)pconn.vPD);
			m_listCtr.SetItemText(nItem,4,(_bstr_t)pconn.vMtance);
			m_listCtr.SetItemText(nItem,5,(_bstr_t)pconn.vSto);
			m_listCtr.SetItemText(nItem,6,(_bstr_t)pconn.vUnit);
			m_listCtr.SetItemText(nItem,7,(_bstr_t)pconn.vCo);
			m_listCtr.SetItemText(nItem,8,(_bstr_t)pconn.vRemark);

			m_pPRecordset->MoveNext();
		}
		m_pPRecordset->Close();
	}
	catch(_com_error e)
	{
		AfxMessageBox(e.ErrorMessage());
	}
}
void ProInfoDlg::OnSearchBtn() 
{
	UpdateData(true);
	if(m_seCtr.GetCurSel() == 0)
		m_nSortType = 1;
	else 
		m_nSortType = 2;
	this->pBindList();	
}

void ProInfoDlg::OnSortBtn() 
{
if(m_soCtr.GetCurSel()!=-1)
{m_nSortType = 0;
	this->pBindList();
}
}

void ProInfoDlg::OnClickListPro(NMHDR* pNMHDR, LRESULT* pResult) 
{
	m_ncurrSel = -1;
	/* -- 获取当前记录编号 -- */
	NM_LISTVIEW *pNMListView = (NM_LISTVIEW *)pNMHDR;
	m_ncurrSel = pNMListView->iItem;//获当前行值m_ncurrSel
//	m_ncurrSel = m_listCtr.GetSelectionMark();
	if(m_ncurrSel >= 0)
	{
		IID = m_listCtr.GetItemText(m_ncurrSel,0);//取当前项的订单号,0表示列号
	}
	
	*pResult = 0;
}

void ProInfoDlg::OnDblclkListPro(NMHDR* pNMHDR, LRESULT* pResult) 
{
		ADOConn pconn;
	_RecordsetPtr  m_pPRecordset;
	_bstr_t vSQL;

	m_ncurrSel = -1;
	/* -- 获取当前记录编号 -- */
	NM_LISTVIEW *pNMListView = (NM_LISTVIEW *)pNMHDR;
	m_ncurrSel = pNMListView->iItem;
	if(m_ncurrSel >= 0)
	{
		try{
			if(pconn.m_pConn == NULL)  
				pconn.OnInitADOConn();
			_bstr_t sSQL;
			sSQL = "select * from ProductMessage";
			pconn.m_pRs = pconn.GetRecordSet(sSQL);
			/* -- 指针移动到相应记录 -- */
			pconn.m_pRs->Move(m_ncurrSel);

			//获取当前记录各项值
			pconn.vPID    = pconn.m_pRs->GetCollect("productID");
			pconn.vPN     = pconn.m_pRs->GetCollect("productName");
			pconn.vPr     = pconn.m_pRs->GetCollect("price");
			pconn.vPD     = pconn.m_pRs->GetCollect("produceDate");	
			pconn.vMtance = pconn.m_pRs->GetCollect("maintance");
			pconn.vSto    = pconn.m_pRs->GetCollect("storeNum");	
			pconn.vUnit   = pconn.m_pRs->GetCollect("unit");
			pconn.vCo     = pconn.m_pRs->GetCollect("colorType");
			pconn.vRemark = pconn.m_pRs->GetCollect("remark");

			//赋给EDIT变量相应的记录值
			addPdlg.m_str1 = (char *)(_bstr_t)pconn.vPID;
			addPdlg.m_str2 = (char *)(_bstr_t)pconn.vPN;
			addPdlg.m_str3 = (char *)(_bstr_t)pconn.vPr;
			addPdlg.m_str4 = (char *)(_bstr_t)pconn.vPD;
			addPdlg.m_str5 = (char *)(_bstr_t)pconn.vMtance;
			addPdlg.m_str6 = (char *)(_bstr_t)pconn.vSto;
			addPdlg.m_str7 = (char *)(_bstr_t)pconn.vUnit;
			addPdlg.m_str8 = (char *)(_bstr_t)pconn.vCo;
			addPdlg.m_str9 = (char *)(_bstr_t)pconn.vRemark;

			addPdlg.dBMod  = true;
			addPdlg.DoModal();
		}
		catch(_com_error e)
		{
			AfxMessageBox(e.ErrorMessage());
		}
	}
	*pResult = 0;
	ProInfoDlg::OnRefreshBnt();
}

void ProInfoDlg::OnAddBnt() 
{
	ProAddDlg *aPdlg = new ProAddDlg;
	aPdlg->Create(IDD_PROADD_DLG);
	aPdlg->ShowWindow(SW_NORMAL);
ProInfoDlg::OnRefreshBnt();
}

void ProInfoDlg::OnChanBnt() 
{
AfxMessageBox("请双击要操作的项!");	
}

void ProInfoDlg::OnRefreshBnt() 
{
	m_nSearch = -1;
	m_nSort = -1;
	m_pStr  = "";
	UpdateData(false);
	m_ncurrSel = -1;
	m_nSortType = 0;
	this->pBindList();	
}

void ProInfoDlg::OnDelBnt() 
{

	if(m_ncurrSel < 0)
			AfxMessageBox("请在列表中选中要删除的项!");
		else
		{
			if(MessageBox("是否确定删除?","请确认",MB_YESNO) == IDYES)
	{
			try
			{ 
				if(connn.m_pConn == NULL)  
					connn.OnInitADOConn();
				ProductFormDel(IID);
			}
			catch(_com_error e)
			{
				AfxMessageBox(e.Description());
			}
			}
		}
}
void ProInfoDlg::ProductFormDel(CString pID)
{
    sSQL2 ="select * from OderFormMessage where productID='"+pID+"'";
    connn.m_pRs =connn.GetRecordSet(sSQL2);
    
    if(!connn.m_pRs->adoBOF)//若订单中存在相应的产品ID则不删除产品
	{
		AfxMessageBox("该产品与订单关联,不能删除!");
	}
	else 
	{
		sSQL2 = "select * from PlanFormMessage where productID='"+pID+"'";
		connn.m_pRs = connn.GetRecordSet(sSQL2);
    
		if(!connn.m_pRs->adoBOF)//若生产单中存在相应的产品ID则不删除生产单
		{
			AfxMessageBox("该产品与生产单关联,不能删除!");
		}
		else
		{  //当生产单和订单中都不存在相应产品ID时删除该产品
		   sSQL2 = "DELETE  FROM ProductMessage WHERE productID ='"+pID+"'";	
		   if(connn.ExecuteSQL(sSQL2))
		   {
			   AfxMessageBox("产品信息删除!");
				m_nSortType = 0;
				this->pBindList();
		   }
		}
	}
}


HBRUSH ProInfoDlg::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);  
}

void ProInfoDlg::OnCancel() 
{
	// TODO: Add extra cleanup here
	//if(MessageBox("是否确定退出?","请确认",MB_YESNO) == IDYES)
	//{
	CDialog::OnCancel();
	//}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -