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

📄 timerecorddlg.cpp

📁 信息提醒小秘书软件的源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//版权有所:李巧平    2003年1月份  电子邮件:liqiaoping@163.com  个人主页:http://mengyuworkroom.y365.com   QQ:5542376
// timerecordDlg.cpp : implementation file
//

#include "stdafx.h"
#include "timerecord.h"
#include "timerecordDlg.h"
#include "ShowMsg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
extern	CTimerecordApp	theApp;

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

	bool	m_showabout;
	int		maxtime;

// 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)
	virtual void OnOK();
	virtual BOOL OnInitDialog();
	afx_msg void OnTimer(UINT nIDEvent);
	//}}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)
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTimerecordDlg dialog

CTimerecordDlg::CTimerecordDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CTimerecordDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CTimerecordDlg)
	m_date = 0;
	m_time = 0;
	m_use = FALSE;
	m_radio = -1;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CTimerecordDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTimerecordDlg)
	DDX_Control(pDX, IDC_LIST, m_list);
	DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER_DATE, m_date);
	DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER_TIME, m_time);
	DDX_Check(pDX, IDC_CHECK_USE, m_use);
	DDX_Radio(pDX, IDC_RADIO1, m_radio);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CTimerecordDlg, CDialog)
	//{{AFX_MSG_MAP(CTimerecordDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON_ADD_EDIT, OnButtonAddEdit)
	ON_NOTIFY(NM_DBLCLK, IDC_LIST, OnDblclkList)
	ON_NOTIFY(NM_RCLICK, IDC_LIST, OnRclickList)
	ON_COMMAND(ID_MENUITEM_DELRECORD, OnMenuitemDelrecord)
	ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
	ON_WM_TIMER()
	ON_WM_SIZE()
	ON_MESSAGE(WM_SHOWTASK,onShowTask)
	ON_COMMAND(ID_MENUITEM_ABOUT, OnMenuitemAbout)
	ON_BN_CLICKED(IDC_RADIO2, OnRadio1)
	ON_BN_CLICKED(IDC_RADIO3, OnRadio1)
	ON_BN_CLICKED(IDC_RADIO4, OnRadio1)
	ON_MESSAGE(WM_MAX_XC,running)
	ON_COMMAND(ID_MENUITEM_SHOWFRAME, OnMenuitemShowframe)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTimerecordDlg message handlers

BOOL CTimerecordDlg::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
	CTime	nowtime = CTime::GetCurrentTime();
	m_time = nowtime;
	m_date = nowtime;
	m_use=false;
	m_radio=0;
	UpdateData(false);

	fields.Add("titile");
	fields.Add("text");
	fields.Add("date");
	fields.Add("time");
	fields.Add("use");
	fields.Add("insertdatatime");

	m_fields.Add("titile");
	m_fields.Add("text");
	m_fields.Add("date");
	m_fields.Add("time");
	m_fields.Add("use");
	m_fields.Add("insertdatatime");
	m_fields.Add("id");


	DWORD dwStyle;
	RECT rect;
	LV_COLUMN lvc;
	dwStyle = m_list.GetStyle();
	dwStyle |= LVS_EX_GRIDLINES |LVS_EX_FULLROWSELECT|LVS_SHOWSELALWAYS ;
	m_list.SetExtendedStyle(dwStyle);
	m_list.SetBkColor(RGB(240,247,233));
	m_list.SetTextBkColor(RGB(240,247,233));
	m_list.GetClientRect(&rect);
	lvc.mask = LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH |LVCF_FMT;
	lvc.fmt=LVCFMT_CENTER;
	lvc.iSubItem = 0;
	lvc.pszText = _T("标题");
	lvc.cx = 60;
	m_list.InsertColumn(1,&lvc);
	lvc.iSubItem = 1;
	lvc.pszText = _T("内容");
	lvc.cx = 140;
	m_list.InsertColumn(2,&lvc);
	lvc.iSubItem = 2;
	lvc.pszText = _T("日期");
	lvc.cx = 60;
	m_list.InsertColumn(3,&lvc);
	lvc.iSubItem = 3;
	lvc.pszText = _T("时间");
	lvc.cx = 60;
	m_list.InsertColumn(4,&lvc);
	lvc.iSubItem = 4;
	lvc.pszText = _T("是否生效");
	lvc.cx = 40;
	m_list.InsertColumn(5,&lvc);
	lvc.iSubItem = 5;
	lvc.pszText = _T("记录时间");
	lvc.cx = 120;
	m_list.InsertColumn(6,&lvc);
	lvc.iSubItem = 6;
	lvc.pszText = _T("ID");
	lvc.cx = 0;
	m_list.InsertColumn(7,&lvc);
	
	showWideToListCtrl("",1);

	id.RemoveAll();

	showmsg=false;

	SetTimer(1,1,NULL);
	SetTimer(2,500,NULL);
	SetTimer(3,500,NULL);

	// 初始化系统托盘图标
	nid.cbSize=(DWORD)sizeof(NOTIFYICONDATA);
	nid.hWnd=this->m_hWnd;
	nid.uID=IDR_MAINFRAME;
	nid.uFlags=NIF_ICON|NIF_MESSAGE|NIF_TIP ;
	nid.uCallbackMessage=WM_SHOWTASK;//自定义的消息名称
	nid.hIcon=LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDR_MAINFRAME));
	strcpy(nid.szTip,"信息提醒小秘书");//信息提示条为“计划任务提醒”
	Shell_NotifyIcon(NIM_ADD,&nid);//在托盘区添加图标


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

void CTimerecordDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.m_showabout=false;
		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 CTimerecordDlg::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 CTimerecordDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CTimerecordDlg::OnOK() 
{
	// TODO: Add extra validation here
	if(AfxMessageBox("真的要退出吗?",MB_YESNO)==IDYES)
		m_xc_date.run=false;
	//CDialog::OnOK();
}

void CTimerecordDlg::OnCancel() 
{
	// TODO: Add extra cleanup here
	if(AfxMessageBox("真的要退出吗?",MB_YESNO)==IDYES)
		m_xc_date.run=false;}

void CTimerecordDlg::OnButtonAddEdit() 
{
	// TODO: Add your control notification handler code here
	CString temp;
	CStringArray	values;
	UpdateData(true);
	GetDlgItemText(IDC_EDIT_TITILE,temp);
	if(temp=="")
	{
		AfxMessageBox("请输入主题!");
		return;
	}
	values.Add(temp);
	GetDlgItemText(IDC_EDIT_TEXT,temp);
	if(temp=="")
	{
		AfxMessageBox("请输入内容!");
		return;
	}
	values.Add(temp);
	temp = m_date.Format(_T("%Y-%m-%d"));
	values.Add(temp);
	temp = m_time.Format(_T("%H:%M:%S"));
	values.Add(temp);
	m_use?temp="1":temp="0";
	values.Add(temp);
	CTime	nowtime = CTime::GetCurrentTime();
	temp = nowtime.Format(_T("%Y-%m-%d %H:%M:%S"));
	values.Add(temp);

	char	msg[255];
	GetDlgItemText(IDC_BUTTON_ADD_EDIT,temp);
	if(temp =="添  加")
	{
		if(theApp.m_pingdatabase->_insertDataToDatabase("recordmsg",&fields,&values,1,msg) !=1)
		{
			temp.Format("%s",msg);
			AfxMessageBox(temp);
			return;
		}
		AfxMessageBox("成功记录一条信息");

		OnRadio1();
	}
	else if(temp =="修  改")
	{
		GetDlgItemText(IDC_EDIT_ID,temp);
		sprintf(msg,"where id=%s",temp);
		if(theApp.m_pingdatabase->_updateRecord("recordmsg",msg,&fields,&values,1,msg) !=1)
		{
			if(strcmp(msg,temp)!=0)
				temp.Format("%s",msg);
			else
				temp.Format("没有此条记录!");
			AfxMessageBox(temp);
			return;
		}
		AfxMessageBox("成功修改一条信息");
		SetDlgItemText(IDC_BUTTON_ADD_EDIT,"添  加");

		OnRadio1();
	}
	initADDorEDIT();
}

void CTimerecordDlg::showWideToListCtrl(CString sql,int flag)
{
	m_list.DeleteAllItems();
	char msg[255];
	strcpy(msg,sql);
	CString temp;
	int counts=theApp.m_pingdatabase->_selectCountsFromDatabase("recordmsg",msg,msg);
	if(counts<0)
	{
		temp.Format("%s",msg);
		AfxMessageBox(temp);
		return;
	}
	if(counts==0)
	{
		if(flag!=1)
			AfxMessageBox("没有记录");
		return;
	}
	CStringArray	*values;
	values=new CStringArray[counts];
	strcpy(msg,sql);
	if(theApp.m_pingdatabase->_selectDataFromDatabase("recordmsg",msg,&m_fields,values,counts,msg)!=counts)
	{
		if(flag!=1)
			AfxMessageBox("取出的数据数目不对");
		return;
	}
	//创建行
	LV_ITEM lvitem;
	lvitem.pszText="";

⌨️ 快捷键说明

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