// Account.cpp : implementation file // #include "stdafx.h" #include "ylgl.h" #include "Account.h" #include "MyMdi.H" #include "SetLeftBar.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // Account IDC_EDIT2 //extern void WriteClientLog(CString str); // Jeff写客户端日志; IMPLEMENT_DYNCREATE(Account, MyFormView) Account::Account() : MyFormView(Account::IDD) { //{{AFX_DATA_INIT(Account) m_account = _T(""); m_psw = _T(""); m_psw2 = _T(""); m_discount = "9.0"; m_bAddNew=1; m_discount2 = _T("9.0"); //}}AFX_DATA_INIT } Account::~Account() { } void Account::DoDataExchange(CDataExchange* pDX) { MyFormView::DoDataExchange(pDX); //{{AFX_DATA_MAP(Account) DDX_Control(pDX, IDC_SPIN1, m_spin1); DDX_Control(pDX, IDC_COMBOname, m_comboname); DDX_Control(pDX, IDC_LIST2, m_List1); DDX_Control(pDX, IDC_STATIC1, m_static1); DDX_Text(pDX, IDC_EDITaccount, m_account); DDX_Text(pDX, IDC_EDITpsw, m_psw); DDX_Text(pDX, IDC_EDITpsw2, m_psw2); DDX_Text(pDX, IDC_EDIT2, m_discount); DDX_Text(pDX, IDC_EDIT3, m_discount2); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(Account, MyFormView) //{{AFX_MSG_MAP(Account) ON_BN_CLICKED(IDC_BUTsave, OnBUTsave) ON_BN_CLICKED(IDC_BUTdel, OnBUTdel) ON_BN_CLICKED(IDC_BUTclose, OnBUTclose) ON_NOTIFY(NM_CLICK, IDC_LIST2, OnClickList2) ON_BN_CLICKED(IDC_BUTadd, OnBUTadd) ON_BN_CLICKED(IDC_BUTbm1, OnBUTbm1) ON_BN_CLICKED(IDC_BUTbm6, OnBUTbm6) ON_BN_CLICKED(IDC_BUTbm2, OnBUTbm2) ON_BN_CLICKED(IDC_BUTbm3, OnBUTbm3) ON_BN_CLICKED(IDC_BUTbm4, OnBUTbm4) ON_BN_CLICKED(IDC_BUTbm5, OnBUTbm5) ON_BN_CLICKED(IDC_BUTleftbar, OnBUTleftbar) ON_BN_CLICKED(IDC_CHECK27, OnCheck27) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // Account diagnostics #ifdef _DEBUG void Account::AssertValid() const { MyFormView::AssertValid(); } void Account::Dump(CDumpContext& dc) const { MyFormView::Dump(dc); } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // Account message handlers void Account::OnInitialUpdate() { //AfxMessageBox("用户管理"); MyFormView::OnInitialUpdate(); // TODO: Add your specialized code here and/or call the base class CMyMdi Mdi; Mdi.SetSubView((CWnd*)GetParent(), (CWnd*)this); #ifdef LKAY_VERSION GetDlgItem(IDC_CHECK54)->ShowWindow(SW_SHOW); #endif #ifdef LYFZ_VERSION GetDlgItem(IDC_CHECK54)->SetWindowText("明日安排"); GetDlgItem(IDC_CHECK54)->ShowWindow(SW_SHOW); #endif #ifdef BASIC_VERSION GetDlgItem(IDC_BUTleftbar)->ShowWindow(0); #ifdef BASIC_ADDDRESS GetDlgItem(IDC_STATIC2)->ShowWindow(1); GetDlgItem(IDC_CHECK40)->ShowWindow(1); GetDlgItem(IDC_CHECK41)->ShowWindow(1); GetDlgItem(IDC_CHECK42)->ShowWindow(1); GetDlgItem(IDC_CHECK43)->ShowWindow(1); GetDlgItem(IDC_CHECK44)->ShowWindow(1); #endif #endif #ifdef ENTERPRISE_VERSION GetDlgItem(IDC_CHECK29)->ShowWindow(1); #endif // Here we create the outbar control using the splitter as its parent // and setting its id to the first pane. CRect rc2; GetWindowRect(rc2); ::MoveWindow(m_hWnd,g_rc.left,g_rc.top,g_rc.Width(),g_rc.Height(),TRUE); EnumChildWindows(m_hWnd,(WNDENUMPROC)EnumChildProc,0); m_comboname.GetWindowRect (rc2); ScreenToClient(rc2); rc2.bottom +=200; m_comboname.MoveWindow (rc2); m_spin1.SetRange (0, 10); m_static1.SetFont (&g_titlefont); m_List1.SetHeadings( "账号, 60;姓名, 60;部门,60" ); m_List1.LoadColumnInfo (112); // Jeff初始化,向服务器获取用户信息; g_sendhead.bsql=0; g_sendhead.code[0]=23; g_sendhead.tabcount=1; g_pMainWnd->ProcessChatMessageRequest2(5); if(g_bSendOK==0) return; DataToArray(&m_List1array); int i = 0; m_List1arrayBak.SetSize(m_List1array.GetSize ()); for(i=0; iSendMessage(WM_CLOSE); } void Account::ClearCtrl() { m_account = _T(""); m_psw = _T(""); m_psw2 = _T(""); m_comboname.SetCurSel (-1); UpdateData(false); for(int i=0; i<60; i++) { ((CButton*)GetDlgItem(IDC_CHECK1+i))->SetCheck(0); } } void Account::OnClickList2(NMHDR* pNMHDR, LRESULT* pResult) { // TODO: Add your control notification handler code here ListSelChange(); *pResult = 0; } void Account::ListSelChange() { #if 1 // Jeff 在选择列表时,启用删除按钮; GetDlgItem(IDC_BUTdel)->EnableWindow(); #endif POSITION pos; pos=m_List1.GetFirstSelectedItemPosition(); if(pos==NULL) { OnBUTadd(); return; } GetDlgItem(IDC_BUTleftbar)->EnableWindow(1); m_bAddNew=0; GetDlgItem(IDC_EDITaccount)->EnableWindow(0); GetDlgItem(IDC_COMBOname)->EnableWindow(0); GetDlgItem(IDC_EDITpsw)->EnableWindow(0); GetDlgItem(IDC_EDITpsw2)->EnableWindow(0); int iItem=m_List1.GetNextSelectedItem(pos); CString account=m_List1.GetItemText (iItem, 0); for(int ii=0; iiEnableWindow(1); GetDlgItem(IDC_COMBOname)->EnableWindow(1); GetDlgItem(IDC_EDITpsw)->EnableWindow(1); GetDlgItem(IDC_EDITpsw2)->EnableWindow(1); ClearCtrl(); GetDlgItem(IDC_BUTleftbar)->EnableWindow(0); #if 1 // Jeff添加时禁用删除按钮; GetDlgItem(IDC_BUTdel)->EnableWindow(0); #endif } void Account::OnBUTsave() // 保存按钮; { // TODO: Add your control notification handler code here UpdateData(); CString name; CString rights=GetRights(); CString sql; if(m_bAddNew) { if(m_account.IsEmpty ()) { AfxMessageBox("资料不全!", MB_ICONINFORMATION);return; } int pos=m_comboname.GetCurSel (); if(pos==-1) { AfxMessageBox("资料不全!", MB_ICONINFORMATION);return; } m_comboname.GetLBText (pos, name); if(m_psw!=m_psw2) { AfxMessageBox("密码不一至!", MB_ICONINFORMATION);return; } if(IsExist(m_account,name)) { AfxMessageBox("已有此账号或姓名,请重新输入!", MB_ICONINFORMATION); return; } sql.Format ("insert into [user](account,name,psw,rights,discount,discount2) values('%s','%s','%s','%s','%0.1f','%0.1f')", m_account,name,m_psw,rights,atof(m_discount),atof(m_discount2)); sql+=USER_REF; g_sendhead.bsql=1; g_pMainWnd->ProcessChatMessageRequest2(sql); if(g_bSendOK==0) return; #if 1 // Jeff添加成功后,要删除m_strNameArray里的存根; for (int i(0); i < m_strNameArray.GetSize(); i++) { if ( name == m_strNameArray.ElementAt(i)) { //AfxMessageBox("ssssss"); m_strNameArray.RemoveAt(i); break; } } ClearCtrl(); CommboboxReLoad(); #endif GetData(); } else//修改 { sql.Format ("update [user] set [rights]='%s',[discount]='%0.1f',[discount2]='%0.1f' where [account]='%s' ", rights, atof(m_discount), atof(m_discount2), m_account); sql+=USER_REF; g_sendhead.bsql=1; g_pMainWnd->ProcessChatMessageRequest2(sql);if(g_bSendOK==0)return; GetData(); } } void Account::OnBUTdel() // 删除按钮; { // TODO: Add your control notification handler code here POSITION pos; pos=m_List1.GetFirstSelectedItemPosition(); if(pos==NULL) { return; } if(AfxMessageBox("确认删除吗?", MB_YESNO|MB_ICONINFORMATION)!=IDYES)return; int iItem=m_List1.GetNextSelectedItem(pos); CString account=m_List1.GetItemText (iItem, 0); if(account=="admin") { AfxMessageBox("管理员不能删除"); return; } CString sql; sql.Format ("delete from [user] where [account]='%s' ", account); sql+=USER_REF; g_sendhead.bsql=1; g_pMainWnd->ProcessChatMessageRequest2(sql); if(g_bSendOK==0) return; #if 1 // Jeff 删除时要清空文本框; CString strName = m_List1.GetItemText(iItem,1); //BOOL bNameInArray = FALSE; ClearCtrl(); //for ( int i(0); i < m_strNameArray.GetSize(); i++) //{ // if ( name == m_strNameArray.ElementAt(i)) // { // bNameInArray = TRUE; // break; // } // } //if ( !bNameInArray ) // { m_strNameArray.Add(strName); //} CommboboxReLoad(); #endif GetData(); } void Account::GetData() { g_sendhead.bsql=0; g_sendhead.code[0]=23; g_sendhead.tabcount=1; g_pMainWnd->ProcessChatMessageRequest2(23); DataToArray(&m_List1array); // Jeff add:在getdata里处理; m_List1arrayBak.RemoveAll(); m_List1arrayBak.SetSize(m_List1array.GetSize ()); for(int i=0; iGetCheck()); ret+=temp; } return ret; } void Account::SetRights(CString rights) { int i = 0; for( i=0; i=60)break; ((CButton*)GetDlgItem(IDC_CHECK1+i))->SetCheck(rights.GetAt (i)=='1'); } for(i=rights.GetLength (); i<60; i++) { ((CButton*)GetDlgItem(IDC_CHECK1+i))->SetCheck(0); } } void Account::OnBUTbm6() { // TODO: Add your control notification handler code here POSITION pos; pos=m_List1.GetFirstSelectedItemPosition(); if(pos) { int iItem=m_List1.GetNextSelectedItem(pos); CString account=m_List1.GetItemText (iItem, 0); if(account=="admin") { SetRights("000000000000000000000000000000000000000000000000010000000000"); return; } } SetRights("000000000000000000000000000000000000000000000000000000000000"); } void Account::OnBUTbm1() { // TODO: Add your control notification handler code here ((CButton*)GetDlgItem(IDC_CHECK1+0))->SetCheck(1); ((CButton*)GetDlgItem(IDC_CHECK1+15))->SetCheck(1); } void Account::OnBUTbm2() { // TODO: Add your control notification handler code here ((CButton*)GetDlgItem(IDC_CHECK1+4))->SetCheck(1); ((CButton*)GetDlgItem(IDC_CHECK1+5))->SetCheck(1); ((CButton*)GetDlgItem(IDC_CHECK1+8))->SetCheck(1); ((CButton*)GetDlgItem(IDC_CHECK1+15))->SetCheck(1); } void Account::OnBUTbm3() { // TODO: Add your control notification handler code here ((CButton*)GetDlgItem(IDC_CHECK1+5))->SetCheck(1); ((CButton*)GetDlgItem(IDC_CHECK1+6))->SetCheck(1); ((CButton*)GetDlgItem(IDC_CHECK1+7))->SetCheck(1); ((CButton*)GetDlgItem(IDC_CHECK1+8))->SetCheck(1); ((CButton*)GetDlgItem(IDC_CHECK1+9))->SetCheck(1); ((CButton*)GetDlgItem(IDC_CHECK1+10))->SetCheck(1); ((CButton*)GetDlgItem(IDC_CHECK1+11))->SetCheck(1); ((CButton*)GetDlgItem(IDC_CHECK1+12))->SetCheck(1); } void Account::OnBUTbm4() { // TODO: Add your control notification handler code here ((CButton*)GetDlgItem(IDC_CHECK1+16))->SetCheck(1); ((CButton*)GetDlgItem(IDC_CHECK1+17))->SetCheck(1); ((CButton*)GetDlgItem(IDC_CHECK1+18))->SetCheck(1); ((CButton*)GetDlgItem(IDC_CHECK1+19))->SetCheck(1); ((CButton*)GetDlgItem(IDC_CHECK1+20))->SetCheck(1); ((CButton*)GetDlgItem(IDC_CHECK1+21))->SetCheck(1); ((CButton*)GetDlgItem(IDC_CHECK1+22))->SetCheck(1); } void Account::OnBUTbm5() { // TODO: Add your control notification handler code here SetRights("111111111111111111111111111111111111111111111111111111111111"); } void Account::OnBUTleftbar() // 界面设置 { // TODO: Add your control notification handler code here SetLeftBar dlg; dlg.m_account=m_account; dlg.DoModal(); } void Account::OnCheck27() { // TODO: Add your control notification handler code here // if(((CButton*)GetDlgItem(IDC_CHECK27))->GetCheck()) // { // } }