📄 progressmanamgedlg.cpp
字号:
// ProgressManamgeDlg.cpp : implementation file
//
#include "stdafx.h"
#include "ProgressManamge.h"
#include "ProgressManamgeDlg.h"
#include "CSpreadSheet.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// 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()
/////////////////////////////////////////////////////////////////////////////
// CProgressManamgeDlg dialog
CProgressManamgeDlg::CProgressManamgeDlg(CWnd* pParent /*=NULL*/)
: CDialog(CProgressManamgeDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CProgressManamgeDlg)
m_sDatetime = _T("");
m_sDiviation = _T("");
m_sFact = _T("");
m_sOpration = _T("");
m_sPlan = _T("");
m_sSetup = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
CTime t = CTime::GetCurrentTime();
year = t.GetYear();
mouth = t.GetMonth();
day = t.GetDay();
hour = t.GetHour();
minute = t.GetMinute();
second = t.GetSecond();
date = t.GetDayOfWeek();
setDateString();
sendDateTime =FALSE;
sendFact = FALSE;
sendTest = FALSE;
sendPlan = FALSE;
sendSetup =FALSE;
receiveFact=FALSE;
receiveSetup=FALSE;
receivePlan=FALSE;
receiveTest=FALSE;
receiveFactCount =0;
receivePlanCount =0;
receiveSetupCount =0;
iFactSendCount = 0;
iSetupSendCount =0;
iPerSetupSendCount=0;
iPerFactSendCount =0;
iPlanSendCount =0;
iDateSendCount =0;
recentMatchine = 1;
perFact = _T("");
perSetup = _T("");
lastFactUp = CTime::GetCurrentTime();
}
void CProgressManamgeDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CProgressManamgeDlg)
DDX_Control(pDX, IDC_COMBO_BOARD_CHOICE, m_boardChoice);
DDX_Control(pDX, ID_BUTTON_TEST, m_ctlOpenComm);
DDX_Control(pDX, IDC_COMBO_COM, m_Combo_Com);
DDX_Control(pDX, IDC_SHOW_STAT, m_showState);
DDX_Text(pDX, IDC_EDIT_DATETIME, m_sDatetime);
DDX_Text(pDX, IDC_EDIT_DIVIATION, m_sDiviation);
DDX_Text(pDX, IDC_EDIT_FACT, m_sFact);
DDX_Text(pDX, IDC_EDIT_OPRATION, m_sOpration);
DDX_Text(pDX, IDC_EDIT_PALN, m_sPlan);
DDX_Text(pDX, IDC_EDIT_SETUP, m_sSetup);
DDX_Control(pDX, IDC_MSCOMM1, m_ctrlMSComm);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CProgressManamgeDlg, CDialog)
//{{AFX_MSG_MAP(CProgressManamgeDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_CREATE()
ON_BN_CLICKED(ID_EXIT, OnExit)
ON_WM_CLOSE()
ON_BN_CLICKED(ID_BUTTON_TEST, OnButtonTest)
ON_WM_TIMER()
ON_BN_CLICKED(IDC_BUTTON_PLAN, OnButtonPlan)
ON_BN_CLICKED(IDC_BUTTON_FACT, OnButtonFact)
ON_BN_CLICKED(IDC_BUTTON_SETUP, OnButtonSetup)
ON_BN_CLICKED(IDC_BUTTON_DATETIME, OnButtonDatetime)
ON_CBN_SELCHANGE(IDC_COMBO_COM, OnSelchangeComboCom)
ON_WM_CTLCOLOR()
ON_CBN_SELCHANGE(IDC_COMBO_BOARD_CHOICE, OnSelchangeComboBoardChoice)
ON_BN_CLICKED(IDC_BUTTON_DUMP, OnButtonDump)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CProgressManamgeDlg message handlers
BOOL CProgressManamgeDlg::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
setStaticStyle();
titleColor = RGB(255,0,0);
m_strCom = "串口1";
CString str[9] ={"串口1","串口2","串口3","串口4","串口5","串口6","串口7","串口8","串口9"};
int n;
for (int i=0;i<=8;i++)
{
n = m_Combo_Com.AddString(str[i]);
m_Combo_Com.SetItemData(n,i);
}
m_Combo_Com.SetCurSel(0);
CString boardTemp;
for (int index=0;index<20;index++)
{
boardTemp.Format("%d",index+1);
n = m_boardChoice.InsertString(index,"看板"+boardTemp);
m_boardChoice.SetItemData(n,index);
}
m_boardChoice.SetCurSel(0);
// ((CButton *)GetDlgItem(IDC_RADIO1))->SetCheck(TRUE);
redIcon =AfxGetApp()->LoadIcon(IDI_ICON_RED);
nomalIcon = AfxGetApp()->LoadIcon(IDI_ICON_NOMAL);
yellowIcon = AfxGetApp()->LoadIcon(IDI_ICON_YELLOW);
greenIcon = AfxGetApp()->LoadIcon(IDI_ICON_GREEN);
m_showState.SetIcon(nomalIcon);
SetTimer(IDT_TIMER_CHECKHASRECEIVEDATE,checkHasReceiveData,NULL);
SetTimer(IDT_TIMER_CHANGEDATETIME,1000*60,NULL);
// TODO: Add extra initialization here
m_ctrlMSComm.SetCommPort(1);
m_ctrlMSComm.SetInputMode(1);
m_ctrlMSComm.SetInBufferSize(1024);
m_ctrlMSComm.SetOutBufferSize(512);
m_ctrlMSComm.SetSettings("9600,n,8,1");
comOpened = FALSE;
if(!m_ctrlMSComm.GetPortOpen()){
m_ctrlMSComm.SetPortOpen(TRUE);
comOpened = true;
m_Combo_Com.EnableWindow(FALSE);
m_ctlOpenComm.SetWindowText("关闭串口");
processDateTime();
// MessageBox("port opend!");
}
m_ctrlMSComm.SetRThreshold(15);
m_ctrlMSComm.SetInputLen(0);
m_ctrlMSComm.GetInput();
return TRUE; // return TRUE unless you set the focus to a control
}
void CProgressManamgeDlg::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 CProgressManamgeDlg::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 CProgressManamgeDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
BEGIN_EVENTSINK_MAP(CProgressManamgeDlg, CDialog)
//{{AFX_EVENTSINK_MAP(CProgressManamgeDlg)
ON_EVENT(CProgressManamgeDlg, IDC_MSCOMM1, 1 /* OnComm */, OnCommMscomm1, VTS_NONE)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
void CProgressManamgeDlg::OnCommMscomm1()
{
VARIANT variant;
COleSafeArray safearray_inp;
LONG len,k;
BYTE rxdata[15];
CString strtemp;
switch(m_ctrlMSComm.GetCommEvent())
{
case 2:
variant = m_ctrlMSComm.GetInput();
safearray_inp = variant;
len = safearray_inp.GetOneDimSize();
//strtemp.Format("%d",len);
//MessageBox("received data,length is "+strtemp);
for (k=0;k<len;k++)
{
safearray_inp.GetElement(&k,rxdata+k);
}
//strtemp.Format("%d",rxdata[0]);
//MessageBox("data[0]="+strtemp);
processReceiveData(rxdata,len);
break;
default:
break;
}
}
void CProgressManamgeDlg::processReceiveData(BYTE rxdata[],int len){
CString temp;
int index;
/*CString strtemp;
temp.Format("%x",rxdata[0]);
strtemp += temp;
strtemp += " ,planprefix = 0x";
temp.Format("%x",planDownSuccessPrefix);
strtemp += temp;
MessageBox("rxdata[0]=0x"+strtemp);*/
/* if(receivePlan){
for(int index=0;index<len;index++)
receivePlanTemp[index+len*receivePlanCount]=rxdata[index];
receivePlanCount++;
if (receivePlanCount==2)
{
return;
}
if(!validateData(rxdata,len))
return;
}
else if(receiveFact){
m_sFact += temp;
return;
}
else if(receiveSetup){
m_sSetup += temp;
return;
}*/
switch(rxdata[0])
{
case setupUpSendPrefix:
//MessageBox("setup received data!");
{
if(!validateData(rxdata,len)){
//returnMessage(setupUpFailPrefix);
return;
}
CString tempsSetup=_T("");
for(index =2;index<=5;){
if(rxdata[index]==0 && tempsSetup.IsEmpty())
{
index++;
continue;
}
temp.Format("%x",rxdata[index]);
tempsSetup += temp;
index++;
}
if(tempsSetup.IsEmpty())
tempsSetup="0";
saveOldData();
int matchId=getMatchIdByDirectory(rxdata[1]);
CString matchineMessage;
matchineMessage.Format("%d",rxdata[1]+1);
map<int,DlgDate>::iterator it = matchineData.find(matchId);
DlgDate dlgDate;
if(it!=matchineData.end())
{
dlgDate= it->second;
dlgDate.m_sSetup = tempsSetup;
if(!dlgDate.m_sFact.IsEmpty()){
temp.Format("%d",atoi(dlgDate.m_sFact)-atoi(dlgDate.m_sSetup));
dlgDate.m_sDiviation=temp;
}
dlgDate.m_sOpration += "接收";
dlgDate.m_sOpration += matchineMessage;
dlgDate.m_sOpration += "号看板的'设定原来数据'";
dlgDate.m_sOpration +="\r\n";
if(recentMatchine == matchId){
copyDateFromDlgDate(dlgDate);
changeShowIcon();
}
}
else{
dlgDate.m_sSetup = tempsSetup;
dlgDate.m_sOpration += "接收";
dlgDate.m_sOpration += matchineMessage;
dlgDate.m_sOpration += "号看板的'设定原来数据'";
dlgDate.m_sOpration +="\r\n";
if(recentMatchine == matchId){
copyDateFromDlgDate(dlgDate);
changeShowIcon();
}
}
matchineData[matchId] = dlgDate;
//((CButton *)GetDlgItem(recentMatchine))->SetCheck(FALSE);
// recentMatchine = matchId;
// ((CButton *)GetDlgItem(matchId))->SetCheck(TRUE);
lastFactUp = CTime::GetCurrentTime();
UpdateData(FALSE);
changeShowIcon();
}
// returnMessage(setupUpSuccessPrefix);
break;
case setupDownSuccessPrefix:
if (sendSetup)
{
KillTimer(IDT_TIMER_SETUP);
sendSetup = FALSE;
}
break;
case setupDownFailPrefix:
/*if(!sendSetup){
iSetupSendCount = 0;
sendSetup = TRUE;
SetTimer(IDT_TIMER_SETUP,elapseTime,NULL);
}*/
break;
case perSetupUpSendPrefix:
{
if(!validateData(rxdata,len)){
// returnMessage(factSetupUPFailPrefix);
return;
}
CString tempsSetup = _T("");
for(index =2;index<=5;){
if(rxdata[index]==0 && tempsSetup.IsEmpty())
{
index++;
continue;
}
temp.Format("%x",rxdata[index]);
tempsSetup += temp;
index++;
}
if(tempsSetup.IsEmpty())
tempsSetup="0";
saveOldData();
int matchId=getMatchIdByDirectory(rxdata[1]);
CString matchineMessage;
matchineMessage.Format("%d",rxdata[1]+1);
map<int,DlgDate>::iterator it = matchineData.find(matchId);
DlgDate dlgDate;
if(it!=matchineData.end())
{
dlgDate= it->second;
dlgDate.perSetup = tempsSetup;
dlgDate.m_sOpration += "接收";
dlgDate.m_sOpration += matchineMessage;
dlgDate.m_sOpration += "号看板的'设定新值数据'";
dlgDate.m_sOpration +="\r\n";
if(recentMatchine == matchId)
copyDateFromDlgDate(dlgDate);
}
else{
dlgDate.perSetup = tempsSetup;
dlgDate.m_sOpration += "接收";
dlgDate.m_sOpration += matchineMessage;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -