SalaryDlg.cpp
上传用户:tyjx315
上传日期:2015-01-18
资源大小:1685k
文件大小:3k
- // SalaryDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "SuperMarket.h"
- #include "SalaryDlg.h"
- #include "afxdb.h"
- #include "HintDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CSalaryDlg dialog
- CSalaryDlg::CSalaryDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CSalaryDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CSalaryDlg)
- m_number = _T("");
- m_name = _T("");
- m_salary = _T("");
- //}}AFX_DATA_INIT
- }
- void CSalaryDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CSalaryDlg)
- DDX_Text(pDX, IDC_EDIT2, m_number);
- DDX_Text(pDX, IDC_EDIT1, m_name);
- DDX_Text(pDX, IDC_EDIT3, m_salary);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CSalaryDlg, CDialog)
- //{{AFX_MSG_MAP(CSalaryDlg)
- ON_BN_CLICKED(IDC_NAME_SEARCH, OnNameSearch)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CSalaryDlg message handlers
- void CSalaryDlg::OnNameSearch() //查找
- {
- // TODO: Add your control notification handler code here
- CString strSQL;
- UpdateData();
- CDatabase dbTemp; //打开数据库
- dbTemp.OpenEx("Driver={Microsoft Access Driver (*.mdb)};DBQ=超市管理数据库.mdb;");
- CRecordset rs( &dbTemp);
- rs.Open(AFX_DB_USE_DEFAULT_TYPE,"select * From 工资表 where number = '"+m_number+"' " );
-
- if(m_number.GetAt(0) != 'Y' || m_number.GetLength() != 4 )
- {
- MessageBox ("员工编号不正确!n正确的编号如Y001");
- return;
- }
- if(rs.IsEOF())
- {
- MessageBox("无此员工的工资信息!");
- return;
- }
- else
- {
- rs.GetFieldValue((short)1,m_name);
- rs.GetFieldValue((short)2,m_salary);
- UpdateData(false);
- }
-
- rs.Close();
- dbTemp.Close();
- }
- void CSalaryDlg::OnOK() //录入
- {
- // TODO: Add extra validation here
- CString strSQL,temp_salary;
- float salary;
- UpdateData();
- CDatabase dbTemp; //打开数据库
-
- dbTemp.OpenEx("Driver={Microsoft Access Driver (*.mdb)};DBQ=超市管理数据库.mdb;");
- CRecordset rs( &dbTemp);
- rs.Open(AFX_DB_USE_DEFAULT_TYPE,"select * From 工资表 where number = '"+m_number+"' " );
-
- salary = atof(m_salary);
- if( m_number.GetAt(0) != 'Y' || m_number.GetLength() != 4)
- {
- MessageBox ("员工编号不正确!n正确的编号如Y001");
- return;
- }
-
- if(m_name == "")
- {
- MessageBox ("员工姓名不能为空!");
- return;
- }
-
- if(salary < 1000)
- {
- MessageBox("员工工资输入错误!n员工工资不能低于1000!");
- return;
- }
-
- if(rs.IsEOF())
- {
- strSQL = "insert into 工资表 values('"+m_number+"','"+m_name+"','"+m_salary+"')";
- dbTemp.ExecuteSQL(strSQL);
- MessageBox("工资录入成功!");
- m_number = "";
- m_name = "";
- m_salary="";
- UpdateData(false);
- }
- else
- {
- rs.GetFieldValue((short)2,temp_salary);
- UpdateData();
- CHintDlg H_Dlg;
- H_Dlg.m_salary = temp_salary;
- if(H_Dlg.DoModal()==IDOK)
- {
- strSQL = "Update 工资表 set salary = '"+m_salary+"' where number = '"+m_number+"'";
- dbTemp.ExecuteSQL(strSQL);
- MessageBox("更新成功!");
- m_number = "";
- m_name = "";
- m_salary="";
- UpdateData(false);
- }
- else
- {
- m_number = "";
- m_name = "";
- m_salary="";
- MessageBox("员工工资不变!");
- UpdateData(false);
- }
-
- }
-
- rs.Close();
- dbTemp.Close();
-
- // CDialog::OnOK();
- }