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

📄 dialogproductware.cpp

📁 以前给一个印刷厂开发的业务管理软件
💻 CPP
字号:
// AccountView.cpp : implementation file
//

#include "stdafx.h" 
#include "DialogProductWare.h"
#include "MDIChild.H"

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

/////////////////////////////////////////////////////////////////////////////
// CDialogProductWare

IMPLEMENT_DYNCREATE(CDialogProductWare, CDialog)

CDialogProductWare::CDialogProductWare()
	: CDialog(CDialogProductWare::IDD)
{
	//{{AFX_DATA_INIT(CDialogProductWare)
	m_strWareMode = _T("");
	m_strWarePurpose = _T("");
	m_strWareType = _T("");
	m_strBanLei = _T("");
	m_strBaoKe = _T("头");
	m_strChengPinShu = _T("");
	m_strAddress = _T("");
	m_strDanSeCheSu = _T("");
	m_strDingSi = _T("头");
	m_strDraft = _T("");
	m_strNumber = _T("");
	m_strPinHouSize = _T("");
	m_strPrice = _T("");
	m_strPrintColorNumber = _T("黄红兰黑");
	m_strPrintJiTai = _T("");
	m_strProduceType = _T("");
	m_strShangJiao = _T("头");
	m_strSize = _T("");
	m_strUnit = _T("");
	m_strUserName = _T("");
	m_strWareNumber = _T("");
	m_strWareUnit = _T("");
	m_strXiaoHaoCheShu = _T("");
	m_strSerial = _T("");
	m_strPinBanNumber = _T("");
	m_strChengPinShuUnit = _T("本");
	//}}AFX_DATA_INIT

	m_nId = 0;
}


void CDialogProductWare::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDialogProductWare)
	DDX_Control(pDX, IDC_BUTTON_DELETE_METER, m_btnDelete);
	DDX_Control(pDX, IDC_COMBO_WareType, m_ComboWareType);
	DDX_Control(pDX, IDC_COMBO_WARE_PURPOSE, m_ComboWarePurpose);
	DDX_Control(pDX, IDC_COMBO_WARE_MODE, m_ComboWareMode);
	DDX_Control(pDX, IDC_BUTTON_EDIT_METER, m_btnEdit);
	DDX_Control(pDX, IDC_BUTTON_ADD_NEW_METER, m_btnAdd);
	DDX_CBString(pDX, IDC_COMBO_WARE_MODE, m_strWareMode);
	DDX_CBString(pDX, IDC_COMBO_WARE_PURPOSE, m_strWarePurpose);
	DDX_CBString(pDX, IDC_COMBO_WareType, m_strWareType);
	DDX_Text(pDX, IDC_EDIT_BAN_LEI, m_strBanLei);
	DDX_CBString(pDX, IDC_COMBO_BaoKe, m_strBaoKe);
	DDX_Text(pDX, IDC_EDIT_ChengPingShu, m_strChengPinShu);
	DDX_Text(pDX, IDC_EDIT_ADDRESS, m_strAddress);
	DDX_Text(pDX, IDC_EDIT_DanSeCheSu, m_strDanSeCheSu);
	DDX_CBString(pDX, IDC_COMBO_DingSi, m_strDingSi);
	DDX_Text(pDX, IDC_EDIT_DRAFT, m_strDraft);
	DDX_Text(pDX, IDC_EDIT_NUMBER, m_strNumber);
	DDX_Text(pDX, IDC_EDIT_PIN_HOU_SIZE, m_strPinHouSize);
	DDX_Text(pDX, IDC_EDIT_Price, m_strPrice);
	DDX_Text(pDX, IDC_EDIT_PRINT_COLOR_NUMBER, m_strPrintColorNumber);
	DDX_Text(pDX, IDC_EDIT_PRINT_JITAI, m_strPrintJiTai);
	DDX_Text(pDX, IDC_EDIT_PRODUCE_TYPE, m_strProduceType);
	DDX_CBString(pDX, IDC_COMBO_ShangJiao, m_strShangJiao);
	DDX_Text(pDX, IDC_EDIT_SIZE, m_strSize);
	DDX_Text(pDX, IDC_EDIT_UNIT, m_strUnit);
	DDX_Text(pDX, IDC_EDIT_USER_NAME, m_strUserName);
	DDX_Text(pDX, IDC_EDIT_WARE_NUMBER, m_strWareNumber);
	DDX_Text(pDX, IDC_EDIT_WARE_UNIT, m_strWareUnit);
	DDX_Text(pDX, IDC_EDIT_XiaoHaoCheSu, m_strXiaoHaoCheShu);
	DDX_Text(pDX, IDC_EDIT_SERIAL, m_strSerial);
	DDX_Text(pDX, IDC_EDIT_PIN_BAN_NUMBER, m_strPinBanNumber);
	DDX_CBString(pDX, IDC_COMBO_ChengPingShu_UNIT, m_strChengPinShuUnit);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDialogProductWare, CDialog)
	//{{AFX_MSG_MAP(CDialogProductWare)
    ON_MESSAGE(WM_KICKIDLE, OnKickIdle)
	ON_BN_CLICKED(IDC_BUTTON_ADD_NEW_METER, OnButtonAddNewMeter)
	ON_BN_CLICKED(IDC_BUTTON_EDIT_METER, OnButtonEditMeter)
	ON_BN_CLICKED(IDC_BUTTON_DELETE_METER, OnButtonDeleteMeter)
	ON_CBN_SELCHANGE(IDC_COMBO_WARE_PURPOSE, OnSelchangeComboWarePurpose)
	ON_CBN_SELCHANGE(IDC_COMBO_WareType, OnSelchangeCOMBOWareType)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDialogProductWare message handlers

void CDialogProductWare::OnButtonAddNewMeter() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	if(m_strDraft.IsEmpty())
		return;

	int answer = MessageBox("确定增加?","确定增加", MB_OKCANCEL);
	if(answer != IDOK)
		return;

	m_pWarePurposeSet->MoveFirst();
	while(!m_pWarePurposeSet->IsEOF())
	{
		if(m_strWarePurpose == m_pWarePurposeSet->m_WarePurpose)
			break;
		m_pWarePurposeSet->MoveNext();
	}	
	m_pWareTypeSet->MoveFirst();
	while(!m_pWareTypeSet->IsEOF())
	{
		if(m_strWareType == m_pWareTypeSet->m_WareType)
			break;
		m_pWareTypeSet->MoveNext();
	}
	m_pWareModeSet->MoveFirst();
	while(!m_pWareModeSet->IsEOF())
	{
		if(m_strWareMode == m_pWareModeSet->m_WareMode)
			break;
		m_pWareModeSet->MoveNext();
	}

	if(!m_pProductWareSet->IsOpen())
		m_pProductWareSet->Open();
	m_pProductWareSet->AddNew();
	m_pProductWareSet->m_ProduceClientSerial = m_strSerial;
	m_pProductWareSet->m_Draft = m_strDraft;
	m_pProductWareSet->m_Size = m_strSize;
	m_pProductWareSet->m_Unit = m_strUnit;
	m_pProductWareSet->m_Number = atof(m_strNumber);
	m_pProductWareSet->m_Price = m_strPrice;
	m_pProductWareSet->m_ProduceType = m_strProduceType;
	m_pProductWareSet->m_WarePurposeId = m_pWarePurposeSet->m_Id;
	m_pProductWareSet->m_WareTypeId = m_pWareTypeSet->m_Id;
	m_pProductWareSet->m_WareModeId = m_pWareModeSet->m_Id;
	m_pProductWareSet->m_WareNumber = atof(m_strWareNumber);
	m_pProductWareSet->m_PinHouSize = m_strPinHouSize;
	m_pProductWareSet->m_PinBanNumber = atoi(m_strPinBanNumber);
	m_pProductWareSet->m_BanLei = m_strBanLei;
	m_pProductWareSet->m_PrintColorNumber = m_strPrintColorNumber;
	m_pProductWareSet->m_PrintJiTai = m_strPrintJiTai;
	m_pProductWareSet->m_DanSeCheSu = m_strDanSeCheSu;
	m_pProductWareSet->m_XiaoHaoCheSu = m_strXiaoHaoCheShu;
	m_pProductWareSet->m_DingSi = m_strDingSi;
	m_pProductWareSet->m_ShangJiao = m_strShangJiao;
	m_pProductWareSet->m_BaoKe = m_strBaoKe;
	m_pProductWareSet->m_ChengPingShu = m_strChengPinShu + m_strChengPinShuUnit;
//TRY
{
	m_pProductWareSet->Update();
}
/*CATCH_ALL(e)
{
	MessageBox("数据加入失败。请重试。");
	return;
}
END_CATCH_ALL;
*/
	MessageBox("数据加入成功。");
}

void CDialogProductWare::OnButtonEditMeter() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	if(m_nId == 0)
		return;
	if(m_strDraft.IsEmpty())
		return;

	int answer = MessageBox("确定修改?","确定修改", MB_OKCANCEL);
	if(answer != IDOK)
		return;

	m_pWarePurposeSet->MoveFirst();
	while(!m_pWarePurposeSet->IsEOF())
	{
		if(m_strWarePurpose == m_pWarePurposeSet->m_WarePurpose)
			break;
		m_pWarePurposeSet->MoveNext();
	}	
	m_pWareTypeSet->MoveFirst();
	while(!m_pWareTypeSet->IsEOF())
	{
		if(m_strWareType == m_pWareTypeSet->m_WareType)
			break;
		m_pWareTypeSet->MoveNext();
	}
	m_pWareModeSet->MoveFirst();
	while(!m_pWareModeSet->IsEOF())
	{
		if(m_strWareMode == m_pWareModeSet->m_WareMode)
			break;
		m_pWareModeSet->MoveNext();
	}

	m_pProductWareSet->Edit();
	m_pProductWareSet->m_Draft = m_strDraft;
	m_pProductWareSet->m_Size = m_strSize;
	m_pProductWareSet->m_Unit = m_strUnit;
	m_pProductWareSet->m_Number = atof(m_strNumber);
	m_pProductWareSet->m_Price = m_strPrice;
	m_pProductWareSet->m_ProduceType = m_strProduceType;
	m_pProductWareSet->m_WarePurposeId = m_pWarePurposeSet->m_Id;
	m_pProductWareSet->m_WareTypeId = m_pWareTypeSet->m_Id;
	m_pProductWareSet->m_WareModeId = m_pWareModeSet->m_Id;
	m_pProductWareSet->m_WareNumber = atof(m_strWareNumber);
	m_pProductWareSet->m_PinHouSize = m_strPinHouSize;
	m_pProductWareSet->m_PinBanNumber = atoi(m_strPinBanNumber);
	m_pProductWareSet->m_BanLei = m_strBanLei;
	m_pProductWareSet->m_PrintColorNumber = m_strPrintColorNumber;
	m_pProductWareSet->m_PrintJiTai = m_strPrintJiTai;
	m_pProductWareSet->m_DanSeCheSu = m_strDanSeCheSu;
	m_pProductWareSet->m_XiaoHaoCheSu = m_strXiaoHaoCheShu;
	m_pProductWareSet->m_DingSi = m_strDingSi;
	m_pProductWareSet->m_ShangJiao = m_strShangJiao;
	m_pProductWareSet->m_BaoKe = m_strBaoKe;
	m_pProductWareSet->m_ChengPingShu = m_strChengPinShu + m_strChengPinShuUnit;
	TRY
	{
		m_pProductWareSet->Update();
	}
	CATCH_ALL(e)
	{
		MessageBox("数据修改失败。请重试。");
		return;
	}
	END_CATCH_ALL;

	MessageBox("数据修改成功。");
}

void CDialogProductWare::OnButtonDeleteMeter() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	if(m_nId == 0)
		return;

	int answer = MessageBox("确定删除?","确定删除", MB_OKCANCEL);
	if(answer != IDOK)
		return;

	m_pProductWareSet->Delete();
	TRY
	{
		m_pProductWareSet->Update();
	}
	CATCH_ALL(e)
	{
		MessageBox("数据删除失败!");
		return;
	}
	END_CATCH_ALL;
		
	MessageBox("删除完毕");

}

BOOL CDialogProductWare::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	m_pWarePurposeSet->MoveFirst();
	while(!m_pWarePurposeSet->IsEOF())
	{
		m_ComboWarePurpose.AddString(m_pWarePurposeSet->m_WarePurpose);
		m_pWarePurposeSet->MoveNext();
	}
	m_ComboWarePurpose.SetCurSel(0);
	OnSelchangeComboWarePurpose();

	if(m_nId != 0)
	{
		m_btnAdd.EnableWindow(FALSE);
		SetIdInfo();
	}
	else
	{
		m_btnEdit.EnableWindow(FALSE);
		m_btnDelete.EnableWindow(FALSE);
	}
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

LRESULT CDialogProductWare::OnKickIdle(WPARAM, LPARAM lCount)
{
       // Do idle processing here, just like CWinApp::OnIdle
       //
	Sleep(100); //1ms

	if(lCount >= 6000) //10分钟10*60*1000=6000*100
	{
		CDialogEnter dlg;
		dlg.m_strUser = m_strOperatorId;
		dlg.m_pOperatorSet = m_pOperatorSet;
		dlg.DoModal();
		return FALSE;
	}
   return TRUE;
}

void CDialogProductWare::SetIdInfo() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	if(m_nId == 0)
		return;

	CString strSql;
	strSql.Format("select * from [ProductWare] where [Id] = %d", m_nId);
	if(m_pProductWareSet->IsOpen())
		m_pProductWareSet->Close();
	m_pProductWareSet->Open(CRecordset::snapshot, strSql);
	if(m_pProductWareSet->IsEOF())
	{
		m_nId = 0;
		MessageBox("错误");
		return;
	}

	m_pWarePurposeSet->MoveFirst();
	while(!m_pWarePurposeSet->IsEOF())
	{
		if(m_pWarePurposeSet->m_Id == m_pProductWareSet->m_WarePurposeId)
			break;

		m_pWarePurposeSet->MoveNext();
	}
	m_strWarePurpose = m_pWarePurposeSet->m_WarePurpose;
	UpdateData(FALSE);
	OnSelchangeComboWarePurpose();

	m_pWareTypeSet->MoveFirst();
	while(!m_pWareTypeSet->IsEOF())
	{
		if(m_pWareTypeSet->m_Id == m_pProductWareSet->m_WareTypeId)
			break;

		m_pWareTypeSet->MoveNext();
	}
	m_strWareType = m_pWareTypeSet->m_WareType;
	UpdateData(FALSE);
	OnSelchangeCOMBOWareType();

	m_pWareModeSet->MoveFirst();
	while(!m_pWareModeSet->IsEOF())
	{
		if(m_pWareModeSet->m_Id == m_pProductWareSet->m_WareModeId)
			break;

		m_pWareModeSet->MoveNext();
	}

	m_strDraft = m_pProductWareSet->m_Draft;
	m_strSize = m_pProductWareSet->m_Size;
	m_strUnit = m_pProductWareSet->m_Unit;
	m_strNumber.Format("%.2f", m_pProductWareSet->m_Number);
	m_strPrice = m_pProductWareSet->m_Price;
	m_strProduceType = m_pProductWareSet->m_ProduceType;
	m_strWareMode = m_pWareModeSet->m_WareMode;
	m_strWareNumber.Format("%.2f", m_pProductWareSet->m_WareNumber);
	m_strPinHouSize = m_pProductWareSet->m_PinHouSize;
	m_strPinBanNumber.Format("%d", m_pProductWareSet->m_PinBanNumber);
	m_strBanLei = m_pProductWareSet->m_BanLei;
	m_strPrintColorNumber = m_pProductWareSet->m_PrintColorNumber;
	m_strPrintJiTai = m_pProductWareSet->m_PrintJiTai;
	m_strDanSeCheSu = m_pProductWareSet->m_DanSeCheSu;
	m_strXiaoHaoCheShu = m_pProductWareSet->m_XiaoHaoCheSu;
	m_strDingSi = m_pProductWareSet->m_DingSi;
	m_strShangJiao = m_pProductWareSet->m_ShangJiao;
	m_strBaoKe = m_pProductWareSet->m_BaoKe;
	strSql = m_pProductWareSet->m_ChengPingShu;
	m_strChengPinShu = strSql.Left(strSql.GetLength() - 2);

	strSql = m_pProductWareSet->m_ChengPingShu;
	m_strChengPinShuUnit = strSql.Right(2);
	UpdateData(FALSE);
	
}

void CDialogProductWare::OnSelchangeComboWarePurpose() 
{
	// TODO: Add your control notification handler code here
	UpdateData();

	m_pWarePurposeSet->MoveFirst();
	while(!m_pWarePurposeSet->IsEOF())
	{
		if(m_strWarePurpose == m_pWarePurposeSet->m_WarePurpose)
		{
			m_pWareTypeSet->MoveFirst();
			m_ComboWareType.ResetContent();
			while(!m_pWareTypeSet->IsEOF())
			{
				if(m_pWareTypeSet->m_WarePurposeId == m_pWarePurposeSet->m_Id)
					m_ComboWareType.AddString(m_pWareTypeSet->m_WareType);
				m_pWareTypeSet->MoveNext();
			}
			m_ComboWareType.SetCurSel(0);
			OnSelchangeCOMBOWareType();
			break;
		}

		m_pWarePurposeSet->MoveNext();
	}	
	
}

void CDialogProductWare::OnSelchangeCOMBOWareType() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	m_pWareTypeSet->MoveFirst();
	while(!m_pWareTypeSet->IsEOF())
	{
		if(m_strWareType == m_pWareTypeSet->m_WareType)
		{
			m_pWareModeSet->MoveFirst();
			m_ComboWareMode.ResetContent();
			while(!m_pWareModeSet->IsEOF())
			{
				if(m_pWareModeSet->m_WareTypeId == m_pWareTypeSet->m_Id)
					m_ComboWareMode.AddString(m_pWareModeSet->m_WareMode);
				m_pWareModeSet->MoveNext();
			}
			m_ComboWareMode.SetCurSel(0);
			m_strWareUnit = m_pWareTypeSet->m_Unit;
			UpdateData(FALSE);
			break;
		}

		m_pWareTypeSet->MoveNext();
	}
	
}

⌨️ 快捷键说明

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