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

📄 dlgcomset.cpp

📁 本程序采用VC++和MySql编写的田间信息自动采集系统
💻 CPP
字号:
// DLGComSet.cpp : implementation file
//

#include "stdafx.h"
#include "rt.h"
#include "DLGComSet.h"

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

/////////////////////////////////////////////////////////////////////////////
// CDLGComSet dialog


CDLGComSet::CDLGComSet(CWnd* pParent /*=NULL*/)
	: CDialog(CDLGComSet::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDLGComSet)
	m_iBaudRate = -1;
	m_iDataBit = -1;
	m_iHand = -1;
	m_iParity = -1;
	m_Port = -1;
	m_StopBit = -1;
	//}}AFX_DATA_INIT
}


void CDLGComSet::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDLGComSet)
	DDX_Radio(pDX, IDC_BaudRate_600, m_iBaudRate);
	DDX_Radio(pDX, IDC_DataBit_4, m_iDataBit);
	DDX_Radio(pDX, IDC_Hand_N, m_iHand);
	DDX_Radio(pDX, IDC_Parity_E, m_iParity);
	DDX_Radio(pDX, IDC_Port_1, m_Port);
	DDX_Radio(pDX, IDC_StopBit_1, m_StopBit);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDLGComSet, CDialog)
	//{{AFX_MSG_MAP(CDLGComSet)
	ON_BN_CLICKED(IDC_BaudRate_1200, OnBaudRate1200)
	ON_BN_CLICKED(IDC_BaudRate_1400, OnBaudRate1400)
	ON_BN_CLICKED(IDC_BaudRate_2400, OnBaudRate2400)
	ON_BN_CLICKED(IDC_BaudRate_2880, OnBaudRate2880)
	ON_BN_CLICKED(IDC_BaudRate_38400, OnBaudRate38400)
	ON_BN_CLICKED(IDC_BaudRate_4800, OnBaudRate4800)
	ON_BN_CLICKED(IDC_BaudRate_5600, OnBaudRate5600)
	ON_BN_CLICKED(IDC_BaudRate_600, OnBaudRate600)
	ON_BN_CLICKED(IDC_BaudRate_9600, OnBaudRate9600)
	ON_BN_CLICKED(IDC_DataBit_4, OnDataBit4)
	ON_BN_CLICKED(IDC_DataBit_5, OnDataBit5)
	ON_BN_CLICKED(IDC_DataBit_6, OnDataBit6)
	ON_BN_CLICKED(IDC_DataBit_7, OnDataBit7)
	ON_BN_CLICKED(IDC_DataBit_8, OnDataBit8)
	ON_BN_CLICKED(IDC_Hand_N, OnHandN)
	ON_BN_CLICKED(IDC_Hand_OF, OnHandOF)
	ON_BN_CLICKED(IDC_Hand_RTS, OnHandRTS)
	ON_BN_CLICKED(IDC_Hand_RTSOF, OnHandRTSOF)
	ON_BN_CLICKED(IDC_Parity_E, OnParityE)
	ON_BN_CLICKED(IDC_Parity_M, OnParityM)
	ON_BN_CLICKED(IDC_Parity_N, OnParityN)
	ON_BN_CLICKED(IDC_Parity_O, OnParityO)
	ON_BN_CLICKED(IDC_Parity_S, OnParityS)
	ON_BN_CLICKED(IDC_Port_1, OnPort1)
	ON_BN_CLICKED(IDC_Port_2, OnPort2)
	ON_BN_CLICKED(IDC_Port_3, OnPort3)
	ON_BN_CLICKED(IDC_Port_4, OnPort4)
	ON_BN_CLICKED(IDC_StopBit_1, OnStopBit1)
	ON_BN_CLICKED(IDC_StopBit_11, OnStopBit11)
	ON_BN_CLICKED(IDC_StopBit_2, OnStopBit2)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDLGComSet message handlers

BOOL CDLGComSet::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
    theResult=m_cDM.select();
	UpdateData(TRUE);
	if(theResult.Next()){
	   //CString port = (theResult.GetString("port")).Mid(3,4);
	  // m_Port=	atoi(port)-1;
	   UpdatePort(theResult.GetString("port"));
	   UpdateStopBit(theResult.GetString("stopBit"));
	   UpdateParity(theResult.GetString("parity"));
	   UpdateHand(theResult.GetString("hand"));
	   UpdateDataBit(theResult.GetString("dataBit"));
	   UpdateBaudRate(theResult.GetString("baudRate"));

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






void CDLGComSet::UpdateStopBit(CString str)
{
	m_sStopBit = str;
	if(str == "1"){
		m_StopBit = 0;
	}
	else if(str == "1.5"){
		m_StopBit = 1;
	} 
	else if(str == "2"){
		m_StopBit = 2;
	} 
}

void CDLGComSet::UpdateBaudRate(CString str)
{
	m_sBaudRate = str;
	if(str == "600"){
		m_iBaudRate = 0;
	} 
	else if(str == "1200"){
		m_iBaudRate = 1;
	} 
	else if(str == "2400"){
		m_iBaudRate = 2;
	}
	if(str == "4800"){
		m_iBaudRate = 3;
	}
	else if(str == "9600"){
		m_iBaudRate = 4;
	} 
	else if(str == "56000"){
		m_iBaudRate = 8;
	} 
	else if(str == "14400"){
		m_iBaudRate = 5;
	} 
	if(str == "38400"){
		m_iBaudRate = 7;
	}
	else if(str == "2880"){
		m_iBaudRate = 6;
	} 
	

}

void CDLGComSet::UpdateHand(CString str)
{
	m_sHand = str;
    if(str == "None"){
		m_iHand = 0;
	}
	else if(str == "XonXoff"){
		m_iHand = 1;
	} 
	else if(str == "RTS"){
		m_iHand = 2;
	} 
	else if(str == "RTSXonXoff"){
		m_iHand = 3;
	} 

}

void CDLGComSet::UpdateDataBit(CString str)
{
  m_sDataBit = str;
  m_iDataBit = atoi(str)-4;
}

void CDLGComSet::UpdateParity(CString str)
{
	m_sParity = str;
	if(str == "E"){
		m_iParity = 0;
	}
	else if(str == "M"){
		m_iParity = 1;
	}
	else if(str == "N"){
		m_iParity = 2;
	}
	else if(str == "O"){
		m_iParity = 3;
	}
	else if(str == "S"){
		m_iParity = 4;
	}


}

void CDLGComSet::UpdatePort(CString str)
{
   m_sPort = str;
   m_Port=	atoi(str.Mid(3,4))-1;
}

void CDLGComSet::OnBaudRate1200() 
{
	// TODO: Add your control notification handler code here
	m_sBaudRate = "1200";
	::SendMessage(hWnd, WM_BAUND_SET, (WPARAM)('3'), (LPARAM)4);
}

void CDLGComSet::OnBaudRate1400() 
{
	// TODO: Add your control notification handler code here
	m_sBaudRate = "14400";
	::SendMessage(hWnd, WM_BAUND_SET, (WPARAM)('0'), (LPARAM)4);
}

void CDLGComSet::OnBaudRate2400() 
{
	// TODO: Add your control notification handler code here
	m_sBaudRate = "2400";
	::SendMessage(hWnd, WM_BAUND_SET, (WPARAM)('4'), (LPARAM)4);
}

void CDLGComSet::OnBaudRate2880() 
{
	// TODO: Add your control notification handler code here
	m_sBaudRate = "2880";
	::SendMessage(hWnd, WM_BAUND_SET, (WPARAM)('8'), (LPARAM)4);
}

void CDLGComSet::OnBaudRate38400() 
{
	// TODO: Add your control notification handler code here
	m_sBaudRate = "38400";
	::SendMessage(hWnd, WM_BAUND_SET, (WPARAM)('9'), (LPARAM)4);
}

void CDLGComSet::OnBaudRate4800() 
{
	// TODO: Add your control notification handler code here
	m_sBaudRate = "4800";
	::SendMessage(hWnd, WM_BAUND_SET, (WPARAM)('5'), (LPARAM)4);
}

void CDLGComSet::OnBaudRate5600() 
{
	// TODO: Add your control notification handler code here
	m_sBaudRate = "56000";
	::SendMessage(hWnd, WM_BAUND_SET, (WPARAM)('6'), (LPARAM)4);
}

void CDLGComSet::OnBaudRate600() 
{
	// TODO: Add your control notification handler code here
	m_sBaudRate = "600";
	::SendMessage(hWnd, WM_BAUND_SET, (WPARAM)('1'), (LPARAM)4);
}

void CDLGComSet::OnBaudRate9600() 
{
	// TODO: Add your control notification handler code here
	m_sBaudRate = "9600";
	::SendMessage(hWnd, WM_BAUND_SET, (WPARAM)('7'), (LPARAM)4);
}

void CDLGComSet::OnDataBit4() 
{
	// TODO: Add your control notification handler code here
	m_sDataBit ="4";
	::SendMessage(hWnd, WM_DATA_SET, (WPARAM)('4'), (LPARAM)3);
}

void CDLGComSet::OnDataBit5() 
{
	// TODO: Add your control notification handler code here
	m_sDataBit ="5";
	::SendMessage(hWnd, WM_DATA_SET, (WPARAM)('5'), (LPARAM)3);
}

void CDLGComSet::OnDataBit6() 
{
	// TODO: Add your control notification handler code here
	m_sDataBit ="6";
	::SendMessage(hWnd, WM_DATA_SET, (WPARAM)('6'), (LPARAM)3);
}

void CDLGComSet::OnDataBit7() 
{
	// TODO: Add your control notification handler code here
	m_sDataBit ="7";
	::SendMessage(hWnd, WM_DATA_SET, (WPARAM)('7'), (LPARAM)3);
}

void CDLGComSet::OnDataBit8() 
{
	// TODO: Add your control notification handler code here
	m_sDataBit ="8";
	::SendMessage(hWnd, WM_DATA_SET, (WPARAM)('8'), (LPARAM)3);
}

void CDLGComSet::OnHandN() 
{
	// TODO: Add your control notification handler code here
	m_sHand="None";
	::SendMessage(hWnd, WM_HAND_SET, (WPARAM)('N'), (LPARAM)5);
}

void CDLGComSet::OnHandOF() 
{
	// TODO: Add your control notification handler code here
	m_sHand="XonXoff";
	::SendMessage(hWnd, WM_HAND_SET, (WPARAM)('X'), (LPARAM)5);
}

void CDLGComSet::OnHandRTS() 
{
	// TODO: Add your control notification handler code here
	m_sHand="RTS";
	::SendMessage(hWnd, WM_HAND_SET, (WPARAM)('T'), (LPARAM)5);
}

void CDLGComSet::OnHandRTSOF() 
{
	// TODO: Add your control notification handler code here
	m_sHand="RTSXonXoff";
	::SendMessage(hWnd, WM_HAND_SET, (WPARAM)('R'), (LPARAM)5);
}

void CDLGComSet::OnParityE() 
{
	// TODO: Add your control notification handler code here
	m_sParity = "E";
	::SendMessage(hWnd, WM_PARITY_SET, (WPARAM)('E'), (LPARAM)2);
}

void CDLGComSet::OnParityM() 
{
	// TODO: Add your control notification handler code here
	m_sParity = "M";
	::SendMessage(hWnd, WM_PARITY_SET, (WPARAM)('M'), (LPARAM)2);
}

void CDLGComSet::OnParityN() 
{
	// TODO: Add your control notification handler code here
	m_sParity = "N";
	::SendMessage(hWnd, WM_PARITY_SET, (WPARAM)('N'), (LPARAM)2);
}

void CDLGComSet::OnParityO() 
{
	// TODO: Add your control notification handler code here
	m_sParity = "O";
	::SendMessage(hWnd, WM_PARITY_SET, (WPARAM)('O'), (LPARAM)2);
}

void CDLGComSet::OnParityS() 
{
	// TODO: Add your control notification handler code here
	m_sParity = "S";
	::SendMessage(hWnd, WM_PARITY_SET, (WPARAM)('S'), (LPARAM)2);
}

void CDLGComSet::OnPort1() 
{
	// TODO: Add your control notification handler code here
	m_sPort = "COM1";
	::SendMessage(hWnd, WM_COM_SET, (WPARAM)('COM1'), (LPARAM)1);
}

void CDLGComSet::OnPort2() 
{
	// TODO: Add your control notification handler code here
	m_sPort = "COM2";
	::SendMessage(hWnd, WM_COM_SET, (WPARAM)('COM2'), (LPARAM)1);
	
}

void CDLGComSet::OnPort3() 
{
	// TODO: Add your control notification handler code here
	m_sPort = "COM3";
	::SendMessage(hWnd, WM_COM_SET, (WPARAM)('COM3'), (LPARAM)1);
}

void CDLGComSet::OnPort4() 
{
	// TODO: Add your control notification handler code here
	m_sPort = "COM4";
	::SendMessage(hWnd, WM_COM_SET, (WPARAM)('COM4'), (LPARAM)1);
}

void CDLGComSet::OnStopBit1() 
{
	// TODO: Add your control notification handler code here
	m_sStopBit = "1";
	::SendMessage(hWnd, WM_STOP_SET, (WPARAM)('1'), (LPARAM)0);
}

void CDLGComSet::OnStopBit11() 
{
	// TODO: Add your control notification handler code here
	m_sStopBit = "1.5";
	::SendMessage(hWnd, WM_STOP_SET, (WPARAM)('1.5'), (LPARAM)0);
}

void CDLGComSet::OnStopBit2() 
{
	// TODO: Add your control notification handler code here
	m_sStopBit = "2";
	::SendMessage(hWnd, WM_STOP_SET, (WPARAM)('2'), (LPARAM)0);
}

void CDLGComSet::SetWnd(HWND wnd)
{
  hWnd =wnd;
}

void CDLGComSet::OnOK() 
{
	// TODO: Add extra validation here
	UpdateData(TRUE);
    CString temp ="update ComSet set Port='";
	temp +=m_sPort+"',stopBit ='";
    temp +=m_sStopBit+"',parity='";
    temp +=m_sParity+"',hand='";
    temp +=m_sHand+"',dataBit='";
	temp +=m_sDataBit+"',baudRate='";
	temp +=m_sBaudRate+"'";
	//AfxMessageBox(temp);
	m_cDM.Modify(temp);
    UpdateData(FALSE);
	CDialog::OnOK();
}

⌨️ 快捷键说明

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