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

📄 productinputform.cpp

📁 完整功能的企业库存管理系统源码,vc++和sqlserver技术开发
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// ProductInputForm.cpp : implementation file
//

#include "stdafx.h"
#include "Store.h"
#include "ProductInputForm.h"
#include "SelectProduct.h"
#include "Affirm.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CProductInputForm dialog


CProductInputForm::CProductInputForm(CWnd* pParent /*=NULL*/)
	: CDialog(CProductInputForm::IDD, pParent)
{
	//{{AFX_DATA_INIT(CProductInputForm)
	m_formDate = COleDateTime::GetCurrentTime();
	m_productInputFormID = _T("");
	m_produceDate = COleDateTime::GetCurrentTime();
	m_storeHouse = _T("");
	m_department = _T("");
	m_dealer = _T("");
	m_houseInType = _T("");
	m_remark = _T("");

	is_search=0;
	flag=1;
	//}}AFX_DATA_INIT
}


void CProductInputForm::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CProductInputForm)
	DDX_Control(pDX, IDC_houseInType, m_houseInTypeCombo);
	DDX_Control(pDX, IDC_dealer, m_dealerCombo);
	DDX_Control(pDX, IDC_department, m_departmentCombo);
	DDX_Control(pDX, IDC_storeHouse, m_storeHouseCombo);
	DDX_Control(pDX, IDC_LIST1, m_list);
	DDX_DateTimeCtrl(pDX, IDC_formDate, m_formDate);
	DDX_Text(pDX, IDC_productInputFormID, m_productInputFormID);
	DDX_DateTimeCtrl(pDX, IDC_produceDate, m_produceDate);
	DDX_CBString(pDX, IDC_storeHouse, m_storeHouse);
	DDX_CBString(pDX, IDC_department, m_department);
	DDX_CBString(pDX, IDC_dealer, m_dealer);
	DDX_CBString(pDX, IDC_houseInType, m_houseInType);
	DDX_Text(pDX, IDC_remark, m_remark);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CProductInputForm, CDialog)
	//{{AFX_MSG_MAP(CProductInputForm)
	ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
	ON_BN_CLICKED(IDC_add, OnAdd)
	ON_BN_CLICKED(IDC_modify2, OnModify2)
	ON_BN_CLICKED(IDC_delete, OnDelete)
	ON_BN_CLICKED(IDC_addLine, OnAddLine)
	ON_BN_CLICKED(IDC_deleteLine, OnDeleteLine)
	ON_BN_CLICKED(IDC_save, OnSave)
	ON_BN_CLICKED(IDC_cancelation, OnCancelation)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CProductInputForm message handlers

BOOL CProductInputForm::OnInitDialog() 
{
	CDialog::OnInitDialog();

	DWORD style;
	style=m_list.GetExStyle();
	style=(style|LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT)&(~LVS_EX_CHECKBOXES) ;
	m_list.SetExtendedStyle(style);
	
	m_list.InsertColumn(0,"产品编号",LVCFMT_LEFT,100);
	m_list.InsertColumn(1,"产品名称",LVCFMT_LEFT,100);
	m_list.InsertColumn(2,"产品单位",LVCFMT_LEFT,100);
	m_list.InsertColumn(3,"产品型号",LVCFMT_LEFT,100);
	m_list.InsertColumn(4,"数量",LVCFMT_LEFT,100);
	m_list.InsertColumn(5,"单价",LVCFMT_LEFT,100);
	m_list.InsertColumn(6,"金额",LVCFMT_LEFT,100);

	bt_add=GetDlgItem(IDC_add);
	bt_delete=GetDlgItem(IDC_delete);
	bt_modify=GetDlgItem(IDC_modify2);
	bt_addLine=GetDlgItem(IDC_addLine);
	bt_deleteLine=GetDlgItem(IDC_deleteLine);
	bt_save=GetDlgItem(IDC_save);
	bt_cancelation=GetDlgItem(IDC_cancelation);

	tx_formDate=GetDlgItem(IDC_formDate);
	tx_productInputFormID=GetDlgItem(IDC_productInputFormID);
	tx_produceDate=GetDlgItem(IDC_produceDate);
	tx_storeHouse=GetDlgItem(IDC_storeHouse);
	tx_department=GetDlgItem(IDC_department);
	tx_dealer=GetDlgItem(IDC_dealer);
	tx_houseInType=GetDlgItem(IDC_houseInType);
	tx_remark=GetDlgItem(IDC_remark);

	tx_productInputFormID->EnableWindow(false);

	CString strSQL;
	HRESULT hTRes;
	_RecordsetPtr m_pRecordset;
	strSQL="select distinct departmentName from department";	
	hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
	if (SUCCEEDED(hTRes))
	{
		//----------------------------------------------------
		hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
		((CStoreApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
				adOpenDynamic,adLockPessimistic,adCmdText);
		if(SUCCEEDED(hTRes))
		{
			while(!(m_pRecordset->adoEOF))
			{		
			m_departmentCombo.AddString(((CStoreApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("departmentName")));
			m_pRecordset->MoveNext();
			}
		}
	}
	m_pRecordset->Close();

	strSQL="select distinct staffName from staff";	
	hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
	if (SUCCEEDED(hTRes))
	{
		//----------------------------------------------------
		hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
		((CStoreApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
				adOpenDynamic,adLockPessimistic,adCmdText);
		if(SUCCEEDED(hTRes))
		{
			while(!(m_pRecordset->adoEOF))
			{		
			m_dealerCombo.AddString(((CStoreApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("staffName")));
			m_pRecordset->MoveNext();
			}
		}
	}
	m_pRecordset->Close();

	strSQL="select distinct houseInTypeName from houseInType";	
	hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
	if (SUCCEEDED(hTRes))
	{
		//----------------------------------------------------
		hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
		((CStoreApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
				adOpenDynamic,adLockPessimistic,adCmdText);
		if(SUCCEEDED(hTRes))
		{
			while(!(m_pRecordset->adoEOF))
			{		
			m_houseInTypeCombo.AddString(((CStoreApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("houseInTypeName")));
			m_pRecordset->MoveNext();
			}
		}
	}
	m_pRecordset->Close();

	strSQL="select distinct storeHouseName from storeHouse";	
	hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
	if (SUCCEEDED(hTRes))
	{
		//----------------------------------------------------
		hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
		((CStoreApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
				adOpenDynamic,adLockPessimistic,adCmdText);
		if(SUCCEEDED(hTRes))
		{
			while(!(m_pRecordset->adoEOF))
			{		
			m_storeHouseCombo.AddString(((CStoreApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("storeHouseName")));
			m_pRecordset->MoveNext();
			}
		}
	}
	m_pRecordset->Close();

	if(is_search==1)
	{
		bt_add->EnableWindow(true);
		bt_delete->EnableWindow(true);
		bt_modify->EnableWindow(true);	
		bt_addLine->EnableWindow(false);
		bt_deleteLine->EnableWindow(false);
		bt_save->EnableWindow(false);
		bt_cancelation->EnableWindow(false);

		CString strSQL;
		_RecordsetPtr m_pRecordset;    //用于创建一个查询记录集
		_RecordsetPtr m_pProductInputFormRecordset;
		strSQL="select * from productInputForm where productInputFormID='";
		strSQL=strSQL+m_productInputFormID+"'";
		HRESULT hTRes;
		hTRes = m_pProductInputFormRecordset.CreateInstance(_T("ADODB.Recordset"));				
		hTRes = m_pProductInputFormRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
			((CStoreApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
			adOpenDynamic,adLockPessimistic,adCmdText);
		if(!(m_pProductInputFormRecordset->adoEOF))
		{
			DATE dt;
			COleDateTime da;
			dt=m_pProductInputFormRecordset->GetCollect("formDate").date;
			da=COleDateTime(dt); 
			m_formDate.SetDate(da.GetYear(),da.GetMonth(),da.GetDay());
			dt=m_pProductInputFormRecordset->GetCollect("produceDate").date;
			da=COleDateTime(dt);
			m_produceDate.SetDate(da.GetYear(),da.GetMonth(),da.GetDay());
			m_storeHouse = ((CStoreApp*)AfxGetApp())->GetStringFromVariant(m_pProductInputFormRecordset->GetCollect("storeHouse"));
			m_department = ((CStoreApp*)AfxGetApp())->GetStringFromVariant(m_pProductInputFormRecordset->GetCollect("produceDepartment"));
			m_dealer = ((CStoreApp*)AfxGetApp())->GetStringFromVariant(m_pProductInputFormRecordset->GetCollect("dealer"));
			m_houseInType = ((CStoreApp*)AfxGetApp())->GetStringFromVariant(m_pProductInputFormRecordset->GetCollect("houseInType"));
			m_remark = ((CStoreApp*)AfxGetApp())->GetStringFromVariant(m_pProductInputFormRecordset->GetCollect("remark"));
			
			
			strSQL="select * from productInputFormView where productInputFormID='";
			strSQL=strSQL+m_productInputFormID+"'";
			hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));				
			hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
				((CStoreApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
				adOpenDynamic,adLockPessimistic,adCmdText);
			int i=0;
			while(!(m_pRecordset->adoEOF))
			{
				m_list.InsertItem(i,((CStoreApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("productID")));
				m_list.SetItemText(i,1,((CStoreApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("productName")));
				m_list.SetItemText(i,2,((CStoreApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("unit")));
				m_list.SetItemText(i,3,((CStoreApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("model")));
				AfxMessageBox(((CStoreApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("model")));
				m_list.SetItemText(i,4,((CStoreApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("num")));
				m_list.SetItemText(i,5,((CStoreApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("price")));
				m_list.SetItemText(i,6,((CStoreApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("total")));
				i++;
				m_pRecordset->MoveNext();
			}			
		}
		tx_formDate->EnableWindow(false);
		tx_produceDate->EnableWindow(false);
		tx_storeHouse->EnableWindow(false);
		tx_department->EnableWindow(false);
		tx_dealer->EnableWindow(false);
		tx_houseInType->EnableWindow(false);
		tx_remark->EnableWindow(false);
	}
	else
	{
		bt_add->EnableWindow(false);
		bt_delete->EnableWindow(false);
		bt_modify->EnableWindow(false);
		bt_addLine->EnableWindow(true);
		bt_deleteLine->EnableWindow(true);
		bt_save->EnableWindow(true);
		bt_cancelation->EnableWindow(true);

		tx_formDate->EnableWindow(true);
		tx_produceDate->EnableWindow(true);
		tx_storeHouse->EnableWindow(true);
		tx_department->EnableWindow(true);
		tx_dealer->EnableWindow(true);
		tx_houseInType->EnableWindow(true);
		tx_remark->EnableWindow(true);

		int formID=((CStoreApp*)AfxGetApp())->m_pIDRecordset->GetCollect("productInputFormID").intVal;
		if(formID<10)
			m_productInputFormID.Format("CPRK0000%d",formID);
		else if(formID<100&&formID>9)
			m_productInputFormID.Format("CPRK000%d",formID);
		else if(formID<1000&&formID>99)
			m_productInputFormID.Format("CPRK00%d",formID);

		CString str;
		str.Format("%d",formID+1);
		((CStoreApp*)AfxGetApp())->m_pIDRecordset->PutCollect("productInputFormID",_variant_t(str));
		((CStoreApp*)AfxGetApp())->m_pIDRecordset->Update();
	}
	
	

	UpdateData(false);
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CProductInputForm::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	
	*pResult = 0;
}

void CProductInputForm::OnAdd() 
{
	flag=1;
	bt_add->EnableWindow(false);
	bt_delete->EnableWindow(false);

⌨️ 快捷键说明

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