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

📄 kaoqinset.cpp

📁 这是采用mfc编写的工资管理系统
💻 CPP
字号:
// KaoqinSet.cpp : implementation file
//

#include "stdafx.h"
#include "salarymanagement.h"
#include "KaoqinSet.h"

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

/////////////////////////////////////////////////////////////////////////////
// CKaoqinSet dialog


CKaoqinSet::CKaoqinSet(CWnd* pParent /*=NULL*/)
	: CDialog(CKaoqinSet::IDD, pParent)
{
	//{{AFX_DATA_INIT(CKaoqinSet)
	m_remark = _T("");
	m_name = _T("");
	m_timeBegin = 0;
	m_timeEnd = 0;
	//}}AFX_DATA_INIT

	//初始化数据库操作对象
	m_ado.OnInitADOConn();
}

CKaoqinSet::~CKaoqinSet()
{
	//关闭数据库操作对象连接
	m_ado.ExitConnect();
}

void CKaoqinSet::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CKaoqinSet)
	DDX_Control(pDX, IDC_LIST1, m_list);
	DDX_Control(pDX, IDC_COMBO22, m_dayTo);
	DDX_Control(pDX, IDC_COMBO11, m_monthFrom);
	DDX_Control(pDX, IDC_COMBO12, m_dayFrom);
	DDX_Control(pDX, IDC_COMBO21, m_monthTo);
	DDX_Text(pDX, IDC_REMARK, m_remark);
	DDX_Text(pDX, IDC_NAME, m_name);
	DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER1, m_timeBegin);
	DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER2, m_timeEnd);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CKaoqinSet, CDialog)
	//{{AFX_MSG_MAP(CKaoqinSet)
	ON_BN_CLICKED(IDC_BUTTON1, OnAddVacation)
	ON_CBN_SELCHANGE(IDC_COMBO11, OnSelchangeCombo11)
	ON_CBN_SELCHANGE(IDC_COMBO21, OnSelchangeCombo21)
	ON_BN_CLICKED(IDC_DELETE, OnDelete)
	ON_BN_CLICKED(IDC_SAVE, OnSave)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CKaoqinSet message handlers

BOOL CKaoqinSet::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	m_list.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
	m_list.InsertColumn(0,"节日名称",LVCFMT_CENTER,80);
	m_list.InsertColumn(1,"开始日期",LVCFMT_CENTER,100);
	m_list.InsertColumn(2,"结束日期",LVCFMT_CENTER,100);
	m_list.InsertColumn(3,"备注",LVCFMT_CENTER,100);

	LoadData();

	CString str;
	for(int i=1;i<=12;i++)
	{
		str.Format("%d",i);
		m_monthFrom.AddString(str);	
		m_monthTo.AddString(str);
	}
	m_monthFrom.SetCurSel(0);
	m_monthTo.SetCurSel(0);

	for(i=1;i<=31;i++)
	{
		str.Format("%d",i);
		m_dayFrom.AddString(str);
		m_dayTo.AddString(str);
	}
	m_dayFrom.SetCurSel(0);
	m_dayTo.SetCurSel(0);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CKaoqinSet::OnAddVacation() 
{
	UpdateData();

	if(m_name=="")
	{
		MessageBox("节日名称不能为空!","工资管理系统");
		return;
	}

	CString month1,month2,day1,day2;
	m_monthFrom.GetWindowText(month1);
	m_dayFrom.GetWindowText(day1);
	m_monthTo.GetWindowText(month2);
	m_dayTo.GetWindowText(day2);
	month1+="月"+day1+"日";
	month2+="月"+day2+"日";
	
	try{
		CString sql;
		sql.Format("Select * From Holiday Where 节日名称='%s'",m_name);
		_RecordsetPtr recordset=m_ado.GetRecordSet(sql);
		
		if(!recordset->adoEOF)
		{
			if(IDYES==AfxMessageBox("该节日已经存在,是否进行修改?",MB_YESNO))
			{
				recordset->PutCollect("开始日期",(_variant_t)month1);
				recordset->PutCollect("结束日期",(_variant_t)month2);
				recordset->PutCollect("备注",(_variant_t)m_remark);
			}
			else
				return;
		}
		else
		{
			recordset->AddNew();
			recordset->PutCollect("节日名称",(_variant_t)m_name);
			recordset->PutCollect("开始日期",(_variant_t)month1);
			recordset->PutCollect("结束日期",(_variant_t)month2);
			recordset->PutCollect("备注",(_variant_t)m_remark);
		}
		recordset->Update();
	}
	catch(_com_error e)
	{
		AfxMessageBox(e.Description());
	}

	LoadData();
}

void CKaoqinSet::OnSelchangeCombo11() 
{
	int index=m_monthFrom.GetCurSel()+1;
	SetDayToMonth(index,m_dayFrom);
}

void CKaoqinSet::OnSelchangeCombo21() 
{
	int index=m_monthTo.GetCurSel()+1;
	SetDayToMonth(index,m_dayTo);
}


void CKaoqinSet::SetDayToMonth(int index,CComboBox &combo)
{
	//根据不同月份的选择,更新日期组合框中可选的日期
	int dayCount=0;
	switch(index)
	{
	case 1:
	case 3:
	case 5:
	case 7:
	case 8:
	case 10:
	case 12:dayCount=31;
		break;
	case 2:dayCount=29;
		break;
	default:dayCount=30;
	}
	CString str;
	combo.ResetContent();
	for(int i=1;i<=dayCount;i++)
	{
		str.Format("%d",i);
		combo.AddString(str);
	}
	combo.SetCurSel(0);
}

void CKaoqinSet::LoadData()
{
	try{
		_RecordsetPtr recordset=m_ado.GetRecordSet("select * From Holiday");
		int nItem=0;
		m_list.DeleteAllItems();
		
		//将数据库中的节日信息显示在列表控件中
		while(!recordset->adoEOF)
		{
			_variant_t vName=recordset->GetCollect("节日名称");
			_variant_t vTime1=recordset->GetCollect("开始日期");
			_variant_t vTime2=recordset->GetCollect("结束日期");
			_variant_t vRemark=recordset->GetCollect("备注");
			
			if(vName.vt!=VT_NULL)
				m_list.InsertItem(nItem,(_bstr_t)vName);
			if(vTime1.vt!=VT_NULL)
				m_list.SetItem(nItem,1,1,(_bstr_t)vTime1,NULL,0,0,0);
			if(vTime2.vt!=VT_NULL)
				m_list.SetItem(nItem,2,1,(_bstr_t)vTime2,NULL,0,0,0);
			if(vRemark.vt!=VT_NULL)
				m_list.SetItem(nItem,3,1,(_bstr_t)vRemark,NULL,0,0,0);
			
			recordset->MoveNext();
			nItem++;
		}
	}
	catch(_com_error e)
	{
		AfxMessageBox(e.Description());
	}
}

void CKaoqinSet::OnDelete() 
{
	POSITION pos = m_list.GetFirstSelectedItemPosition();

	try{
		if (pos == NULL)
			TRACE0("No items were selected!\n");
		else
		{
			while (pos)
			{
				int nItem = m_list.GetNextSelectedItem(pos);
				
				CString name=m_list.GetItemText(nItem,0);
				CString sql;
				
				sql.Format("Delete From Holiday Where 节日名称='%s'",name);
				
				m_ado.ExecuteSQL(sql);//在数据库中删除该部门信息
				
				m_list.DeleteItem(nItem);//在列表控件中删除该部门
			}
		}
	}
	catch(_com_error e)
	{
		AfxMessageBox(e.Description());
	}
	LoadData();
}

void CKaoqinSet::OnSave() 
{	
	UpdateData();

	//根据用户选择得到上下班对应的时间的小时、分钟和秒数
	int hourBegin=m_timeBegin.GetHour();
	int minuteBegin=m_timeBegin.GetMinute();
	int secondBegin=m_timeBegin.GetSecond();

	int hourEnd=m_timeEnd.GetHour();
	int minuteEnd=m_timeEnd.GetMinute();
	int secondEnd=m_timeEnd.GetSecond();

	//获取配置文件路径
	char ProfileName[256];
	GetModuleFileName(NULL,ProfileName,256);
	
	ProfileName[strlen(ProfileName)-3]='\0';
	strcat(ProfileName,"ini");

	//将得到的时、分、秒写入配置文件
	CString temp;
	temp.Format("%d",hourBegin);
	WritePrivateProfileString("Time","hourAm",temp,ProfileName);
	temp.Format("%d",minuteBegin);
	WritePrivateProfileString("Time","minuteAm",temp,ProfileName);
	temp.Format("%d",secondBegin);
	WritePrivateProfileString("Time","secondAm",temp,ProfileName);
	temp.Format("%d",hourEnd);
	WritePrivateProfileString("Time","hourPm",temp,ProfileName);
	temp.Format("%d",minuteEnd);
	WritePrivateProfileString("Time","minutePm",temp,ProfileName);
	temp.Format("%d",secondEnd);
	WritePrivateProfileString("Time","secondPm",temp,ProfileName);
}

⌨️ 快捷键说明

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