EmployerInfoLookup.cpp
上传用户:sunh8215
上传日期:2010-02-13
资源大小:1616k
文件大小:3k
- // EmployerInfoLookup.cpp : implementation file
- //
- #include "stdafx.h"
- #include "qq.h"
- #include "EmployerInfoLookup.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CEmployerInfoLookup dialog
- CString CEmployerInfoLookup::STRINGS[100]={""};
- CEmployerInfoLookup::CEmployerInfoLookup(CWnd* pParent /*=NULL*/)
- : CDialog(CEmployerInfoLookup::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CEmployerInfoLookup)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- EmployerCode = _T("");
- Name = _T("");
- Depart = _T("");
- bSuccess=false;
- }
- void CEmployerInfoLookup::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CEmployerInfoLookup)
- DDX_Control(pDX, IDC_COMBO1, m_InfoLookup_EmployerCode);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CEmployerInfoLookup, CDialog)
- //{{AFX_MSG_MAP(CEmployerInfoLookup)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CEmployerInfoLookup message handlers
- BOOL CEmployerInfoLookup::OnInitDialog()
- {
- CDialog::OnInitDialog();
- HICON m_hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME2);
- this->SetIcon(m_hIcon,true);//设置对话框图标
- // TODO: Add extra initialization here
- m_acCombo.Init(GetDlgItem(IDC_COMBO1));
- if(!m_EmployerInfoSet.Open(AFX_DB_USE_DEFAULT_TYPE))
- {
- MessageBox("打开数据库失败!","数据库错误",MB_OK);
- return false;
- }
- InitDate();//初始化数组成员
- m_EmployerInfoSet.MoveFirst();//move to the first record
- int i=0;
- while(!m_EmployerInfoSet.IsEOF())
- {
- STRINGS[i]=m_EmployerInfoSet.m_EmployerCode.GetBuffer(m_EmployerInfoSet.m_EmployerCode.GetLength());
- m_EmployerInfoSet.MoveNext();
- i++;
- }
- m_EmployerInfoSet.Close();//关闭数据库
- for (int j=0;(!STRINGS[j].IsEmpty()); j++)
- {
- m_acCombo.GetStringList().Add(STRINGS[j].GetBuffer(STRINGS[j].GetLength()));
- }
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- void CEmployerInfoLookup::OnOK()
- {
- // TODO: Add extra validation here
- CString str;
- m_InfoLookup_EmployerCode.GetWindowText(str);
- if(str=="")
- {
- MessageBox("请输入职员代号!","数据为空错误",MB_OK);
- return ;
- }
- if(!m_EmployerInfoSet.Open(AFX_DB_USE_DEFAULT_TYPE))
- {
- AfxMessageBox("查询数据库失败或者数据库没有连接!");
- bSuccess=false;
- return ;
- }
- bool bInSQL=false;//是否存在这个数据记录
- m_EmployerInfoSet.MoveFirst();
- while(!m_EmployerInfoSet.IsEOF())
- {
- if(m_EmployerInfoSet.m_EmployerCode==str)
- {
- bInSQL=true;
- break;
- }
- else bInSQL=false;
- m_EmployerInfoSet.MoveNext();
- }
- ///////////////////////////////////////////////////////////
- // 查询成功的话保存得到的数据
- if(bInSQL)
- {
- Depart=m_EmployerInfoSet.m_Depart;
- EmployerCode=m_EmployerInfoSet.m_EmployerCode;
- Name=m_EmployerInfoSet.m_Name;
- bSuccess=true;
- }
- else
- {
- MessageBox("该记录不存在!","记录错误",MB_OK);
- bSuccess=false;
- m_EmployerInfoSet.Close();//关闭数据库返回
- return ;
- }
- ////保存数据完成关闭数据库
- m_EmployerInfoSet.Close();
- CDialog::OnOK();
- }
- void CEmployerInfoLookup::OnCancel()
- {
- // TODO: Add extra cleanup here
- CDialog::OnCancel();
- }
- void CEmployerInfoLookup::InitDate()
- {
- for(int i=0;i<100;i++)
- {
- STRINGS[i]="";
- }
- }