1、教师工资系统VF程序源代码及其说明程序源代码及其说明1、 登陆界面实现代码及截图1.1核心代码void CLogInDlg:OnOK() / TODO: Add extra validation here UpdateData(TRUE); if(m_usrName = ) AfxMessageBox(用户账号不能为空!); return; if(m_usrPasswd = ) AfxMessageBox(用户密码不能为空!); return; CDatabase db; CString sql; db.Open(NULL,FALSE,FALSE,ODBC;DSN=salaryDB;UID=z
2、hang,PWD=NULL); ClogInSet* pset = new ClogInSet(&db); sql.Format(select * fromlogin where ID=%s and passwd=%s,m_usrName,m_usrPasswd); pset-Open(AFX_DB_USE_DEFAULT_TYPE,sql); if(m_usrName != pset-m_ID | m_usrPasswd != pset-m_passwd) AfxMessageBox(用户账号或密码错误!); return; CDialog:OnOK();1.2 登陆界面2、 工资查询实现代
3、码及截图2.1 核心代码void CpaySearch:OnQuery() / TODO: Add your control notification handler code here CDatabase db; CString sql; db.Open(NULL,FALSE,FALSE,ODBC;DSN=salaryDB;UID=zhang,PWD=NULL); Csalaryset* pset = new Csalaryset(&db); int i=0; CString str; CString ty,tm,td; m_years.GetWindowText(ty); m_months
4、.GetWindowText(tm); m_departments.GetWindowText(td);/ str.Format(%d,m_years.GetCurSel();/ AfxMessageBox(str); if(radioSel = 0) if(m_years.GetCurSel() = 0) if(m_months.GetCurSel() = 0 & m_departments.GetCurSel() != 0) sql.Format(select * from searchSalary where dept=%s,td); else if(m_months.GetCurSel
5、() != 0 & m_departments.GetCurSel() = 0) sql.Format(select * from searchSalary where month=%s,tm); else if(m_months.GetCurSel() != 0 & m_departments.GetCurSel() != 0) sql.Format(select * from searchSalary where dept=%s and month=%s,td,tm); else sql.Format(select * from searchSalary); else/ if(m_year
6、s.GetCurSel() != 0) if(m_months.GetCurSel() = 0 & m_departments.GetCurSel() != 0) sql.Format(select * from searchSalary where dept=%s and year=%s,td,ty); else if(m_months.GetCurSel() != 0 & m_departments.GetCurSel() = 0) sql.Format(select * from searchSalary where month=%s and year=%s,tm,ty); else i
7、f(m_months.GetCurSel() != 0 & m_departments.GetCurSel() != 0) sql.Format( select * from searchSalary where year=%s and month=%s and dept=%s, ty,tm,td ); else sql.Format(select * from searchSalary where year=%s,ty); else UpdateData(TRUE); if(m_years.GetCurSel() = 0) if(m_months.GetCurSel() = 0 & m_de
8、partments.GetCurSel() != 0) sql.Format(select * from searchSalary where ID=%s and dept=%s,m_ID,td); else if(m_months.GetCurSel() != 0 & m_departments.GetCurSel() = 0) sql.Format(select * from searchSalary where ID=%s and month=%s,m_ID,tm); else if(m_months.GetCurSel() != 0 & m_departments.GetCurSel(
9、) != 0) sql.Format(select * from searchSalary where ID=%s and dept=%s and month=%s,m_ID,td,tm); else sql.Format(select * from searchSalary where ID=%s,m_ID); else/ if(m_years.GetCurSel() != 0) if(m_months.GetCurSel() = 0 & m_departments.GetCurSel() != 0) sql.Format(select * from searchSalary where I
10、D=%s and dept=%s and year=%s,m_ID,td,ty); else if(m_months.GetCurSel() != 0 & m_departments.GetCurSel() = 0) sql.Format(select * from searchSalary where ID=%s and month=%s and year=%s,m_ID,tm,ty); else if(m_months.GetCurSel() != 0 & m_departments.GetCurSel() != 0) sql.Format( select * from searchSal
11、ary where ID=%s and year=%s and month=%s and dept=%s, m_ID,ty,tm,td ); else sql.Format(select * from searchSalary where ID=%s and year=%s,m_ID,ty); UpdateData(FALSE); / sql.Format(select * from searchSalary); AfxMessageBox(sql); m_printList.DeleteAllItems(); pset-Open(AFX_DB_USE_DEFAULT_TYPE,sql); i
12、f(pset-GetRecordCount() = 0) delete pset; return; while(!pset-IsEOF() str.Format(%s,pset-m_ID); m_printList.InsertItem(i,str); str.Format(%s,pset-m_name); m_printList.SetItemText(i,name,str); str.Format(%s,pset-m_dept); m_printList.SetItemText(i,department,str); str.Format(%s,pset-m_position); m_pri
13、ntList.SetItemText(i,position,str); str.Format(%.2f,pset-m_allowance); m_printList.SetItemText(i,allowance,str); str.Format(%.2f,pset-m_salary); m_printList.SetItemText(i,salary,str); str.Format(%.2f,pset-m_reward); m_printList.SetItemText(i,reward,str); str.Format(%d,pset-m_year); m_printList.SetIt
14、emText(i,year,str); str.Format(%d,pset-m_month); m_printList.SetItemText(i,month,str); i+; pset-MoveNext(); db.Close(); delete pset;2.2 查询界面3、教职工基本信息添加实现代码及截图3.1核心代码void CWorkersInfo:OnModify() / TODO: Add your control notification handler code here int count = m_wkrsInfo.GetItemCount(); try CDataba
15、se db; CString sql; db.Open(NULL,FALSE,FALSE,ODBC;DSN=salaryDB;UID=zhang,PWD=NULL); CsysSet *sset = new CsysSet(&db); double al = 0; double sal = 0; / CcheckOnSet *cset = new CcheckOnSet(&db); CTime times = CTime:GetCurrentTime(); int year=times.GetYear(); int month=times.GetMonth();/* sql.Format(%d
16、,count); AfxMessageBox(sql); sql.Format(%d-%d,year,month); AfxMessageBox(sql);*/ CString ID,Name,Pos,Title,Dept,Phone; for(int i = 0;i Open(AFX_DB_USE_DEFAULT_TYPE,sql); sal = sset-m_salary; al = sset-m_pAllowance; sql.Format(%.2f,sal); /* AfxMessageBox(sql); / Print the sql statement for check. */
17、sset-Close(); /Close is needed. sql.Format(insert into searchSalary (ID,name,dept,position,allowance,salary,reward,year,month) values (%s,%s,%s,%s,%.2f,%.2f,0,%d,%d), ID,Name,Dept,Pos,al,sal,year,month); db.ExecuteSQL(sql); db.Close(); catch(CDBException e) CString err; err.Format(数据库操作错误!); AfxMess
18、ageBox(err); 3.2 教职工信息查询界面4、 系统设置实现代码和截图4.1确定修改系统设置实现代码void CSystemSetting:OnConfirm() / TODO: Add your control notification handler code here CDatabase db; CString sql,sql1,sql2,sql3,sql4,sql5; sql.Format(select * from sysSet); db.Open(NULL,FALSE,FALSE,ODBC;DSN=salaryDB;UID=zhang,PWD=NULL); CsysSet
19、 *pset = new CsysSet(&db); pset-Open(AFX_DB_USE_DEFAULT_TYPE,sql); m_1_1 = pset-m_salary; m_1_2 = pset-m_aAllowance; m_1_3 = pset-m_pAllowance; m_1_4 = pset-m_tAllowance; pset-MoveNext(); m_2_1 = pset-m_salary; m_2_2 = pset-m_aAllowance; m_2_3 = pset-m_pAllowance; m_2_4 = pset-m_tAllowance; pset-Mov
20、eNext(); m_3_1 = pset-m_salary; m_3_2 = pset-m_aAllowance; m_3_3 = pset-m_pAllowance; m_3_4 = pset-m_tAllowance; pset-MoveNext(); m_4_1 = pset-m_salary; m_4_2 = pset-m_aAllowance; m_4_3 = pset-m_pAllowance; m_4_4 = pset-m_tAllowance; pset-MoveNext(); m_5_1 = pset-m_salary; m_5_2 = pset-m_aAllowance;
21、 m_5_3 = pset-m_pAllowance; m_5_4 = pset-m_tAllowance; pset-MoveFirst(); UpdateData(TRUE); sql1.Format(update sysSet set salary=%.1f,aAllowance=%.1f,pAllowance=%.1f,tAllowance=%.1f where SID=0001, m_1_1,m_1_2,m_1_3,m_1_4); sql2.Format(update sysSet set salary=%.1f,aAllowance=%.1f,pAllowance=%.1f,tAl
22、lowance=%.1f where SID=0002, m_2_1,m_2_2,m_2_3,m_2_4); sql3.Format(update sysSet set salary=%.1f,aAllowance=%.1f,pAllowance=%.1f,tAllowance=%.1f where SID=0003, m_3_1,m_3_2,m_3_3,m_3_4); sql4.Format(update sysSet set salary=%.1f,aAllowance=%.1f,pAllowance=%.1f,tAllowance=%.1f where SID=0004, m_4_1,m
23、_4_2,m_4_3,m_4_4); sql5.Format(update sysSet set salary=%.1f,aAllowance=%.1f,pAllowance=%.1f,tAllowance=%.1f where SID=0005, m_5_1,m_5_2,m_5_3,m_5_4); db.ExecuteSQL(sql1); db.ExecuteSQL(sql2); db.ExecuteSQL(sql3); db.ExecuteSQL(sql4); db.ExecuteSQL(sql5); db.Close();4.2删除教职工信息功能实现代码void CSystemSetti
24、ng:OnDelete() / TODO: Add your control notification handler code here UpdateData(TRUE); if(m_delete=) AfxMessageBox(请输入教职工编号!); return; Calert *dlg = new Calert(); if(dlg-DoModal()=IDOK) CString sql; CDatabase db; sql.Format(delete from baseInfo where ID=%s,m_delete); db.Open(NULL,FALSE,FALSE,ODBC;DSN=salaryDB;UID=zhang,PWD=NULL); db.ExecuteSQL(sql); db.Close();