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

📄 newdlg.cpp

📁 RFID 的实用例子,登陆使用了标准动态库类
💻 CPP
📖 第 1 页 / 共 3 页
字号:
// NewDlg.cpp : implementation file
//

#include "stdafx.h"
#include "New.h"
#include "NewDlg.h"
#include "..\common\iniFile.h"
#include <math.h>
#include "SelectItem.h"



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

extern COperDb OperDb;
extern CSelectItemInfo pSel;

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CNewDlg dialog

CNewDlg::CNewDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CNewDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CNewDlg)
	m_strProductType = _T("");
	m_timeRepairEnd = 0;
	m_strProductCode = _T("");
	m_strProductName = _T("");
	m_strSaleTime = _T("");
	m_strPlanRepairDate = _T("");
	m_strMemo = _T("");
	m_Descriptions = _T("");
	m_strMClass = _T("");
	m_strMName = _T("");
	m_strCustomer = _T("");
	m_strMType = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}


CNewDlg::CNewDlg(bool bRightNew,bool bRightDel,bool bRightEdit,bool bRightRequery,CString strOperatorCode,CString strOperatorName,CWnd* pParent/* = NULL*/)
    	: CDialog(CNewDlg::IDD, pParent)
{

	m_RightNew = bRightNew;
	m_RightDel = bRightDel;
	m_RightEdit = bRightEdit;
	m_RightRequery = bRightRequery;
	m_strOperatorCode = strOperatorCode;
	m_strOperatorName = strOperatorName;

	m_strProductType = _T("");
	//m_strCustomer = _T("");
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);


}




void CNewDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CNewDlg)
	DDX_Control(pDX, IDCANCEL, m_btnCancel);
	DDX_Control(pDX, IDC_BUTTON_WR_CARD, m_btnWriteCar);
	DDX_Control(pDX, IDC_BUTTON_SELECTCUSTOMER, m_btnSelectCustomer);
	DDX_Control(pDX, IDC_COMBO_MTYPE, m_CbxMType);
	DDX_Control(pDX, IDC_COMBO_MNAME, m_CbxMName);
	DDX_Control(pDX, IDC_COMBO_MCLASS, m_CbxMClass);
	DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER1, m_timeRepairEnd);
	DDX_Text(pDX, IDC_EDIT_PRODUCTCODE, m_strProductCode);
	DDX_Text(pDX, IDC_EDIT_MEMO, m_strMemo);
	DDX_Text(pDX, IDC_EDIT_DESCRIPTIONS, m_Descriptions);
	DDX_CBString(pDX, IDC_COMBO_MCLASS, m_strMClass);
	DDX_CBString(pDX, IDC_COMBO_MNAME, m_strMName);
	DDX_CBString(pDX, IDC_COMBO_MTYPE, m_strMType);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CNewDlg, CDialog)
	//{{AFX_MSG_MAP(CNewDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON_WR_CARD, OnButtonWrCard)
	ON_EN_KILLFOCUS(IDC_EDIT_PRODUCTCODE, OnKillfocusEditProductcode)
	ON_BN_CLICKED(IDC_BUTTON_SELECTCUSTOMER, OnButtonSelectcustomer)
	ON_CBN_KILLFOCUS(IDC_COMBO_MCLASS, OnKillfocusComboMclass)
	ON_CBN_KILLFOCUS(IDC_COMBO_MNAME, OnKillfocusComboMname)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CNewDlg message handlers

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

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here

	m_btnSelectCustomer.SetIcon(IDI_ICON_CUSTOMER);
	m_btnSelectCustomer.DrawTransparent();
	m_btnSelectCustomer.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, OFFSET_COLOR);
	m_btnSelectCustomer.SetColor(CButtonST::BTNST_COLOR_FG_IN, RGB(255, 0, 255));


	
	m_btnWriteCar.SetIcon(IDI_ICON_WRTCAR);
	m_btnWriteCar.DrawTransparent();
	m_btnWriteCar.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, OFFSET_COLOR);
	m_btnWriteCar.SetColor(CButtonST::BTNST_COLOR_FG_IN, RGB(255, 0, 255));


	
	m_btnCancel.SetIcon(IDI_ICON_CANCEL);
	m_btnCancel.DrawTransparent();
	m_btnCancel.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, OFFSET_COLOR);
	m_btnCancel.SetColor(CButtonST::BTNST_COLOR_FG_IN, RGB(255, 0, 255));

	

	InitMClass();


	InitComBoxProductType();
	InitComBoxCustomer();
	m_timeRepairEnd = CTime::GetCurrentTime();
	CTimeSpan ts( 3, 0, 0, 0 );
	m_timeRepairEnd = m_timeRepairEnd +ts;
	UpdateData(FALSE);

	//计算并更新计划修复日期
	m_strPlanRepairDate = GetPlanRepairDate();
	SetDlgItemText(IDC_EDIT_PLANREPAIRDATE,m_strPlanRepairDate);

	SetDlgItemText(IDC_STATIC_OPERATORNAME,m_strOperatorName);



	
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CNewDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CNewDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CNewDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}


//初始化产品类型列表框
void CNewDlg::InitComBoxProductType()
{

	try
	{
		CString strBuf;
		strBuf.Format("SELECT * FROM tb_ProductType ORDER BY ProductTypeCode");

		_bstr_t CommText;
		CommText = strBuf;
		_variant_t vRecordsAffected;
		OperDb.pRecordset = OperDb.pConn->Execute(CommText, &vRecordsAffected, adCmdText);
		if(vRecordsAffected.lVal == VT_NULL) return;

		OperDb.pRecordset->MoveFirst();
		CComboBox *p=(CComboBox*)GetDlgItem(IDC_COMBO_PRODUCTTYPE);
		p->ResetContent();
		do
		{
			_variant_t vtGet = OperDb.pRecordset->GetCollect("ProductTypeName");
			if(vtGet.vt != NULL)
			{
				strBuf.Format("%s", OperDb.CrackStrVariant(vtGet));
				p->AddString(strBuf);
			}
			OperDb.pRecordset->MoveNext();
		}while(!(OperDb.pRecordset->EndOfFile));
	}
	catch(_com_error  &e)
	{
		_bstr_t  bstrSource(e.Source());  
		_bstr_t  bstrDescription(e.Description());  
		AfxMessageBox(e.Description());
		return;
	}
	catch(...)
	{
		return;
	}

}

CString CNewDlg::GetProductTypeCode(CString strProductTypeName)
{
	try
	{
		CString strBuf;
		strBuf.Format("SELECT ProductTypeCode FROM tb_ProductType WHERE ProductTypeName  = '%s'", strProductTypeName);

		_bstr_t CommText;
		CommText = strBuf;
		_variant_t vRecordsAffected;
		OperDb.pRecordset = OperDb.pConn->Execute(CommText, &vRecordsAffected, adCmdText);
		if(vRecordsAffected.lVal==VT_NULL)	return _T("");

		OperDb.pRecordset->MoveFirst();
		_variant_t vtGet = OperDb.pRecordset->GetCollect("ProductTypeCode");
		if(vtGet.vt != NULL)  strBuf.Format("%s", OperDb.CrackStrVariant(vtGet));
		return strBuf;
			
	}
	catch(_com_error  &e)
	{
		_bstr_t  bstrSource(e.Source());  
		_bstr_t  bstrDescription(e.Description());  
//		AfxMessageBox(e.Description());
		return _T("");
	}
	catch(...)
	{
		return _T("");
	}	


}





void CNewDlg::InitComBoxCustomer()
{
	
		try
	{
		CString strBuf;
		strBuf.Format("SELECT * FROM tb_Customer ORDER BY CustomerCode");

		_bstr_t CommText;
		CommText = strBuf;
		_variant_t vRecordsAffected;
		OperDb.pRecordset = OperDb.pConn->Execute(CommText, &vRecordsAffected, adCmdText);
		if(vRecordsAffected.lVal == VT_NULL) return;

		OperDb.pRecordset->MoveFirst();
		CComboBox *p=(CComboBox*)GetDlgItem(IDC_COMBO_CUSTOMER);
		p->ResetContent();
		do
		{
			_variant_t vtGet = OperDb.pRecordset->GetCollect("CustomerName");
			if(vtGet.vt != NULL)
			{
				strBuf.Format("%s", OperDb.CrackStrVariant(vtGet));
				p->AddString(strBuf);
			}
			OperDb.pRecordset->MoveNext();
		}while(!(OperDb.pRecordset->EndOfFile));
	}
	catch(_com_error  &e)
	{
		_bstr_t  bstrSource(e.Source());  
		_bstr_t  bstrDescription(e.Description());  
		AfxMessageBox(e.Description());
		return;
	}
	catch(...)
	{
		return;
	}


}


⌨️ 快捷键说明

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