Files
geomative/GeomativeStudio/cpp/Views/DialTimerTask.cpp
T
coco df489d5640 a
2026-07-03 16:05:30 +08:00

238 lines
7.1 KiB
C++

// DialTimerTask.cpp : implementation file
//
#include "stdafx.h"
#include "geomative.h"
#include "DialTimerTask.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDialTimerTask dialog
extern int g_UIOffset;
extern SYSTEMTIME g_sysCurTime;
extern int g_iUILanguage;
CDialTimerTask::CDialTimerTask(CWnd* pParent /*=NULL*/)
: CDialog(CDialTimerTask::IDD, pParent)
{
//{{AFX_DATA_INIT(CDialTimerTask)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_vtDleTimerTask.clear();
}
void CDialTimerTask::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDialTimerTask)
DDX_Control(pDX, IDC_DATETIMEPICKER_TIME, m_ctrlTime);
DDX_Control(pDX, IDC_DATETIMEPICKER_DATE, m_ctrlDate);
DDX_Control(pDX, IDC_LIST_TIMER_TASK, m_listTimerTask);
DDX_Control(pDX, IDC_COMBO_TASK_NAME, m_cmbTaskName);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDialTimerTask, CDialog)
//{{AFX_MSG_MAP(CDialTimerTask)
ON_BN_CLICKED(IDC_BUTTON_SAVE, OnButtonSave)
ON_BN_CLICKED(IDC_BUTTON_ADD, OnButtonAdd)
ON_BN_CLICKED(IDC_BUTTON_DEL, OnButtonDel)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDialTimerTask message handlers
void CDialTimerTask::OnButtonSave()
{
// TODO: Add your control notification handler code here
//如果有删除任务的话,则先删除掉那些定时任务
if (m_vtDleTimerTask.size() > 0)
{
if (!m_dataOper.DeleteTimerTask(m_vtDleTimerTask))
{
return;
}
}
int iItemCnt = m_listTimerTask.GetItemCount();
DWORD dwTdID = 0;
for (int i = 0; i < iItemCnt; i++)
{
dwTdID = m_listTimerTask.GetItemData(i);
if (IsAutoTaskByTimer(dwTdID))
continue;
if (!m_dataOper.AddTimerTask(dwTdID, m_listTimerTask.GetItemText(i,1), m_listTimerTask.GetItemText(i, 2),m_listTimerTask.GetItemText(i, 3)))
return;
}
CDialog::OnOK();
}
void CDialTimerTask::OnButtonAdd()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
int iCurSel = m_cmbTaskName.GetCurSel();
if (-1 == iCurSel)
{
if (LANG_ZHCN == g_iUILanguage)
AfxMessageBox(_T("请先选择任务"));
else
MessageBoxEx(NULL, _T("Please choose one task first"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
return;
}
CString strPlcID = _T("");
GetDlgItem(IDC_EDIT_PLC_ID)->GetWindowText(strPlcID);
if (strPlcID.IsEmpty())
{
if (LANG_ZHCN == g_iUILanguage)
AfxMessageBox(_T("请输入plc id"));
else
MessageBoxEx(NULL, _T("Please input plc id"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
return;
}
CTime date,time;
m_ctrlDate.GetTime(date);
m_ctrlTime.GetTime(time);
int iItem = m_listTimerTask.GetItemCount();
int iID = (iItem > 0) ? atoi(m_listTimerTask.GetItemText(iItem-1,0)) + 1 : 1;
m_listTimerTask.InsertItem(iItem, _T(""));
CString strTxt = _T("");
strTxt.Format(_T("%d"),iID);
m_listTimerTask.SetItemText(iItem, 0, strTxt);
m_cmbTaskName.GetLBText(iCurSel, strTxt);
CString strNewTaskName = strTxt;
m_listTimerTask.SetItemText(iItem, 1, strTxt);
SYSTEMTIME sysDate,sysTime;
m_ctrlDate.GetTime(&sysDate);
m_ctrlTime.GetTime(&sysTime);
strTxt.Empty();
strTxt.Format(_T("%04d-%02d-%02d %02d:%02d:00"), sysDate.wYear, sysDate.wMonth, sysDate.wDay, sysTime.wHour, sysTime.wMinute);
CString strTmp = _T("");
strTmp.Format(_T("%04d-%02d-%02d %02d:%02d:00"), g_sysCurTime.wYear, g_sysCurTime.wMonth, g_sysCurTime.wDay,
g_sysCurTime.wHour, g_sysCurTime.wMinute);
if (strcmp(strTmp, strTxt) >= 0)
{
if (LANG_ZHCN == g_iUILanguage)
AfxMessageBox(_T("The timer information error"));
else
MessageBoxEx(NULL, _T("Please choose one task first"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
return;
}
m_listTimerTask.SetItemText(iItem, 2, strTxt);
strTxt = strTxt.Left(strTxt.GetLength()-3);
strTxt.Remove(' ');
strTxt.Remove('-');
strTxt.Remove(':');
CString strTaskName;
strTaskName.Format(_T("%s_%s"),strNewTaskName, strTxt);
m_listTimerTask.SetItemText(iItem, 1, strTaskName);
m_listTimerTask.SetItemText(iItem, 3, strPlcID);
m_listTimerTask.SetItemData(iItem, m_cmbTaskName.GetItemData(iCurSel));
}
void CDialTimerTask::OnButtonDel()
{
// TODO: Add your control notification handler code here
int iCurSel = m_listTimerTask.GetSelectionMark();
if (-1 == iCurSel)
{
if (LANG_ZHCN == g_iUILanguage)
AfxMessageBox(_T("请先选择任务"));
else
MessageBoxEx(NULL, _T("Please choose one task first!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
return;
}
DWORD dwTaskID = m_listTimerTask.GetItemData(iCurSel);
if (IsAutoTaskByTimer(dwTaskID))
{
m_vtDleTimerTask.push_back(RestoreAutoTaskID(dwTaskID));
}
m_listTimerTask.DeleteItem(iCurSel);
}
//通过判断最高位是否为1来决定是否为定时而自动产生的任务
bool CDialTimerTask::IsAutoTaskByTimer(DWORD dwTaskID)
{
return (dwTaskID&0x80000000) > 0 ? true : false;
}
BOOL CDialTimerTask::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
CString strColTitle;
int iColIndex = 0;
m_listTimerTask.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_HEADERDRAGDROP
| LVS_EX_ONECLICKACTIVATE | LVS_EX_GRIDLINES);
m_listTimerTask.InsertColumn(iColIndex++, _T("ID"),LVCFMT_LEFT,100);
strColTitle.Empty();
strColTitle.LoadString(IDS_TIMER_DIAL_TASK_NAME+g_UIOffset);
m_listTimerTask.InsertColumn(iColIndex++, strColTitle, LVCFMT_CENTER, 150);
strColTitle.Empty();
strColTitle.LoadString(IDS_TIMER_DIAL_TASK_TIMER+g_UIOffset);
m_listTimerTask.InsertColumn(iColIndex++,strColTitle, LVCFMT_CENTER, 150);
//
// strColTitle.Empty();
// strColTitle.LoadString(IDS_TIMER_DIAL_TASK_TIMER+g_UIOffset);
m_listTimerTask.InsertColumn(iColIndex++,_T("PLCID"), LVCFMT_CENTER, 150);
((CEdit*)GetDlgItem(IDC_EDIT_PLC_ID))->SetLimitText(10);
std::vector<STTimerTask> vtTimerTd;
m_dataOper.QueryTimerTaskValiad(vtTimerTd, g_sysCurTime);
int iRow = 0;
CString strTxt;
DWORD dwID = 0;
int i;
for (i = 0; i < vtTimerTd.size(); i++)
{
m_listTimerTask.InsertItem(i, _T(""));
strTxt.Empty();
strTxt.Format(_T("%d"), i+1);
m_listTimerTask.SetItemText(i, 0, strTxt);
m_listTimerTask.SetItemText(i, 1, vtTimerTd[i].strTaskName);
m_listTimerTask.SetItemText(i, 2, vtTimerTd[i].strRunTime);
m_listTimerTask.SetItemText(i, 3, vtTimerTd[i].strPlcID);
m_listTimerTask.SetItemData(i, GetAutoTaskIDByTimer(vtTimerTd[i].uiTaskID));
}
std::vector<STTdBrowseInfo> vtTdBroInfo;
m_dataOper.QueryTdBrowseInfo(vtTdBroInfo);
for (i = 0; i < vtTdBroInfo.size(); i++)
{
int iItem = m_cmbTaskName.GetCount();
m_cmbTaskName.AddString(vtTdBroInfo[i].strTaskName);
m_cmbTaskName.SetItemData(iItem, vtTdBroInfo[i].iTaskID);
}
m_ctrlDate.SetTime(&g_sysCurTime);
m_ctrlTime.SetTime(&g_sysCurTime);
UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}