📄 optiondlg.cpp
字号:
// OptionDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Alarm.h"
#include "OptionDlg.h"
#include "alarmdlg.h"
#include "messagedisplay.h"
#include ".\optiondlg.h"
#include "MyStringTime.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// COptionDlg dialog
COptionDlg::COptionDlg(CWnd* pParent /*=NULL*/)
: CDialog(COptionDlg::IDD, pParent)
, bIsSelected(FALSE)
{
//{{AFX_DATA_INIT(COptionDlg)
m_tPlanTime = CTime::GetCurrentTime();
m_tPlanDate = CTime::GetCurrentTime();
m_strPlan = _T("");
m_nMode = 0;
m_nPri = 0;
//}}AFX_DATA_INIT
}
void COptionDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(COptionDlg)
DDX_Control(pDX, IDC_LIST_PLAN, m_ctlListBox);
DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER1, m_tPlanTime);
DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER2, m_tPlanDate);
DDX_Text(pDX, IDC_EDIT_PLAN, m_strPlan);
DDX_CBIndex(pDX, IDC_COMBOB_MODE, m_nMode);
DDX_CBIndex(pDX, IDC_COMBOPRI, m_nPri);
//}}AFX_DATA_MAP
DDX_Control(pDX, IDC_COMBOB_MODE, m_ctlComboMode);
}
BEGIN_MESSAGE_MAP(COptionDlg, CDialog)
//{{AFX_MSG_MAP(COptionDlg)
ON_BN_CLICKED(IDC_RECORDSET_EDIT, OnRecordsetEdit)
ON_BN_CLICKED(IDC_RECORDSET_DEL, OnRecordsetDel)
ON_EN_KILLFOCUS(IDC_EDIT_PLAN, OnKillfocusEditPlan)
//}}AFX_MSG_MAP
// ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST_PLAN, OnLvnItemchangedListPlan)
// ON_BN_CLICKED(IDOK, OnBnClickedOk)
ON_NOTIFY(NM_DBLCLK, IDC_LIST_PLAN, OnNMDblclkListPlan)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// COptionDlg message handlers
BOOL COptionDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
CRect rect;
GetWindowRect(rect);
int nScreenCX = ::GetSystemMetrics(SM_CXSCREEN);
int nScreenCY = ::GetSystemMetrics(SM_CYSCREEN);
int nPosX = (nScreenCX / 2) - (rect.Width() / 2);
int nPosY = (nScreenCY / 2) - (rect.Height() / 2);
SetWindowPos(&wndTop ,nPosX,nPosY,rect.Width(),rect.Height(),SWP_SHOWWINDOW );
m_ctlListBox.InsertColumn(0,"序号", LVCFMT_CENTER,50);
m_ctlListBox.InsertColumn(1,"事件", LVCFMT_CENTER,100);
m_ctlListBox.InsertColumn(2,"时间", LVCFMT_CENTER,80);
m_ctlListBox.InsertColumn(3,"日期", LVCFMT_CENTER,80);
m_ctlListBox.InsertColumn(4,"级别", LVCFMT_CENTER,30);
m_ctlListBox.InsertColumn(5,"模式", LVCFMT_CENTER,100);
m_ctlListBox.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES );
CAlarmDlg* m_pwnd = (CAlarmDlg*)this->GetOwner();
this->m_strPlan = m_pwnd->message.GetPlan();
if(!this->m_strPlan.IsEmpty())
{
this->m_nPri = m_pwnd->message.GetPri();
this->m_tPlanDate = m_pwnd->message.GetPlanDate();
this->m_tPlanTime = m_pwnd->message.GetPlanTime();
this->m_nPri = m_pwnd->message.GetPri();
this->m_nMode = m_pwnd->message.GetMode();
UpdateData(FALSE);
}
ReadPlanFromDB();
bIsSelected = FALSE;
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void COptionDlg::OnOK()
{
// TODO: Add extra validation here
UpdateData(TRUE);
CAlarmDlg* m_pwnd = (CAlarmDlg*)this->GetOwner();
CDaoRecordset rs(&m_pwnd->db);
rs.Open(AFX_DAO_USE_DEFAULT_TYPE,
"SELECT * FROM plan", 0);
//加入第一个记录,用SQL语句
rs.AddNew();
rs.SetFieldValue("事件",(LPCTSTR )m_strPlan);
rs.SetFieldValue("时间",(LPCTSTR )m_tPlanTime.Format("%H:%M:%S"));
rs.SetFieldValue("日期",(LPCTSTR )m_tPlanDate.Format("%Y年%m月%d日"));
CString strTemp;
strTemp.Format("%d",m_nPri);
rs.SetFieldValue("级别",(LPCTSTR )strTemp);
strTemp.Format("%d",m_nMode);
rs.SetFieldValue("提示模式",(LPCTSTR )strTemp);
rs.Update();
CDialog::OnOK();
}
void COptionDlg::ReadPlanFromDB()
{
CAlarmDlg* m_pwnd = (CAlarmDlg*)this->GetOwner();
CDaoRecordset rs(&m_pwnd->db);
int nRecord = 0;
CString strTemp;
try
{
rs.Open( dbOpenTable,"plan");
while( !rs.IsEOF( ) )
{
COleVariant var;
int nFields = rs.GetFieldCount( );
COleDateTime time;
strTemp.Format("%d",nRecord);
m_ctlListBox.InsertItem(nRecord,strTemp);
for ( int i=0; i < nFields; i++ )
{
var = rs.GetFieldValue( i );
switch(var.vt)
{
case VT_BSTR:
strTemp.Format("%s",var.bstrVal);
break;
case VT_DATE:
time = var.date;
if(i == 2)
{
strTemp = time.Format("%H:%M:%S");
}
else
{
strTemp = time.Format("%Y-%m-%d");
}
break;
case VT_I4:
strTemp.Format("%d",var.intVal);
break;
default:
break;
}
m_ctlListBox.SetItemText(nRecord,i,strTemp);
}
nRecord++;
rs.MoveNext( );
}
}
catch( CDaoException* e )
{
e->Delete( );
}
if(rs.IsOpen())
{
rs.Close();
}
//modify list box 4ST content;
for(int j = 0; j < m_ctlListBox.GetItemCount(); j++)
{
strTemp = m_ctlListBox.GetItemText(j,5);
m_ctlListBox.SetItemText(j,5,m_pwnd->message.m_strModeList.GetAt(atoi(strTemp)));
}
}
void COptionDlg::OnRecordsetEdit()
{
// TODO: Add your control notification handler code here
if(!bIsSelected)
{
MessageBox("您还没有选择预编记得记录!\r\n请在右侧的列表框中双击选择记录!","SORRY!",MB_ICONINFORMATION|MB_OK);
}
else
{
UpdateData(TRUE);
CAlarmDlg* m_pwnd = (CAlarmDlg*)this->GetOwner();
CDaoRecordset rs(&m_pwnd->db);
rs.Open(AFX_DAO_USE_DEFAULT_TYPE,
"SELECT * FROM plan", 0);
//滚动到指定的记录
rs.MoveFirst();
rs.Move(m_nRecordIndex);
rs.Edit();
rs.SetFieldValue("事件",(LPCTSTR )m_strPlan);
rs.SetFieldValue("时间",(LPCTSTR )m_tPlanTime.Format("%H:%M:%S"));
rs.SetFieldValue("日期",(LPCTSTR )m_tPlanDate.Format("%Y年%m月%d日"));
CString strTemp;
strTemp.Format("%d",m_nPri);
rs.SetFieldValue("级别",(LPCTSTR )strTemp);
strTemp.Format("%d",m_nMode);
rs.SetFieldValue("提示模式",(LPCTSTR )strTemp);
rs.Update();
CDialog::OnOK();
}
}
void COptionDlg::OnRecordsetDel()
{
// TODO: Add your control notification handler code here
CAlarmDlg* m_pwnd = (CAlarmDlg*)this->GetOwner();
CDaoRecordset rs(&m_pwnd->db);
rs.Open(dbOpenTable,"plan");
POSITION nPos = m_ctlListBox.GetFirstSelectedItemPosition();
int n = m_ctlListBox.GetNextSelectedItem(nPos);
CString strTemp = m_ctlListBox.GetItemText(n,0);
int nRecordNumber = atoi(strTemp);
rs.Move(n);
rs.Delete();
rs.Close();
m_ctlListBox.DeleteAllItems();
m_pwnd->message.m_strPlanArray.RemoveAll();
m_pwnd->message.m_TimeList.RemoveAll();
m_pwnd->message.m_nModeList.RemoveAll();
m_pwnd->ReadPlanFromDataBase();
m_pwnd->ReadTimeInfoFromDataBase();
m_pwnd->ReadModeInfoFromDB();
ReadPlanFromDB();
}
void COptionDlg::OnKillfocusEditPlan()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
if(m_strPlan.Compare("关机") == 0)
{
m_nMode = 0;
}
UpdateData(FALSE);
}
void COptionDlg::OnNMDblclkListPlan(NMHDR *pNMHDR, LRESULT *pResult)
{
//将列表框中选定的项目复制到左边的窗体上以供编辑,同时给标志变量值位
POSITION pos = m_ctlListBox.GetFirstSelectedItemPosition();
int nIndex = m_ctlListBox.GetNextSelectedItem(pos);
m_nRecordIndex = nIndex;
CMyStringTime myStringToTime;
CString strTempInfo = m_ctlListBox.GetItemText(nIndex,1);
m_strPlan = strTempInfo;
strTempInfo = m_ctlListBox.GetItemText(nIndex,2);
CTime t = myStringToTime.CStringToTime(strTempInfo);
m_tPlanTime = t;
strTempInfo = m_ctlListBox.GetItemText(nIndex,3);
t = myStringToTime.CStringToDate(strTempInfo);
m_tPlanDate = t;
int nPri = atoi(m_ctlListBox.GetItemText(nIndex,4));
m_nPri = nPri;
strTempInfo = m_ctlListBox.GetItemText(nIndex,5);
int nMode = 0;
int nCount = m_ctlComboMode.GetCount();
for(int i = 0; i < nCount; i ++)
{
CString strTemp;
m_ctlComboMode.GetLBText(i,strTemp);
if(strTemp.Compare(strTempInfo) == 0)
{
nMode = i;
}
}
m_nMode = nMode;
bIsSelected = TRUE;
UpdateData(FALSE);
*pResult = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -