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

📄 holidaymandlg.cpp

📁 visual c++与sql Server数据库开发考勤管理系统
💻 CPP
字号:
// HolidayManDlg.cpp : implementation file
//

#include "stdafx.h"
#include "CheckManage.h"
#include "HolidayManDlg.h"
#include "HolidayEditDlg.h"
#include "HolidaySet.h"
#include "COMDEF.H"
#include "Columns.h"
#include "Column.h"
#include "_Recordset.h"

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

/////////////////////////////////////////////////////////////////////////////
// CHolidayManDlg dialog


CHolidayManDlg::CHolidayManDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CHolidayManDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CHolidayManDlg)
	//}}AFX_DATA_INIT
}


void CHolidayManDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CHolidayManDlg)
	DDX_Control(pDX, IDC_ADODC1, m_Adodc);
	DDX_Control(pDX, IDC_DATAGRID1, m_Datagrid);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CHolidayManDlg, CDialog)
	//{{AFX_MSG_MAP(CHolidayManDlg)
	ON_BN_CLICKED(IDC_ADD_BUTTON, OnAddButton)
	ON_BN_CLICKED(IDC_MODI_BUTTON, OnModiButton)
	ON_BN_CLICKED(IDC_DEL_BUTTON, OnDelButton)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CHolidayManDlg message handlers

// 初始化
BOOL CHolidayManDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	RefreshData();
	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}

// 更新数据
void CHolidayManDlg::RefreshData()
{
	UpdateData(TRUE);
	
	// 设置Select语句
	CString cSource = "SELECT Id, HolidayDate AS 节假日, HolidayName AS 名称"
		      " FROM HolidaySet";
	
	//刷新ADO Data控件的记录源
	m_Adodc.SetRecordSource(cSource);
	m_Adodc.Refresh();
	
	//设置列宽度
	_variant_t vIndex;
	vIndex = long(0);
	m_Datagrid.GetColumns().GetItem(vIndex).SetWidth(0);
	vIndex = long(1);
	m_Datagrid.GetColumns().GetItem(vIndex).SetWidth(130);
	vIndex = long(2);
	m_Datagrid.GetColumns().GetItem(vIndex).SetWidth(130);
}

// 添加按钮
void CHolidayManDlg::OnAddButton() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	
	// 初始化HolidayEditDlg对话框中的变量
	CHolidayEditDlg dlg;
	dlg.cId = "";
	dlg.cTime = "";
	dlg.m_name = "";
	dlg.m_time = CTime::GetCurrentTime();
	
	// 打开HolidayEditDlg对话框
	if (dlg.DoModal() == IDOK)
		RefreshData();
}

// 修改按钮
void CHolidayManDlg::OnModiButton() 
{
	// TODO: Add your control notification handler code here
	if (m_Adodc.GetRecordset().GetEof()) 
	{
		MessageBox("请选择要修改的记录");
		return;
	}
	
	// 设置HolidayEditDlg对话框中的变量
	CHolidayEditDlg dlg;
	dlg.cId = m_Datagrid.GetItem(0);
	dlg.cTime = m_Datagrid.GetItem(1);
	CString cYear = dlg.cTime.Left(4);
	CString cMonth = dlg.cTime.Mid(5,2);
	CString cDay = dlg.cTime.Right(2);
	dlg.m_time = CTime::CTime(atoi(cYear), atoi(cMonth), atoi(cDay), 0, 0, 0);
	dlg.m_name = m_Datagrid.GetItem(2);
	
	// 打开HolidayEditDlg对话框
	if (dlg.DoModal() == IDOK)
		RefreshData();
	
}

// 删除按钮
void CHolidayManDlg::OnDelButton() 
{
	// TODO: Add your control notification handler code here
	if (m_Adodc.GetRecordset().GetEof())
	{
		MessageBox("请选择要删除的记录!");
		return;
	}
	
	if (MessageBox("是否删除当前记录?","请确认", MB_YESNO + MB_ICONQUESTION) == IDYES)
	{
		// 删除
		CHolidaySet cur;
		cur.SqlDelete(m_Datagrid.GetItem(0));
		RefreshData();
	}
}

⌨️ 快捷键说明

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