123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541 |
- // 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);
- m_List1arrayBak.SetSize(m_List1array.GetSize ());
- for(int i=0; i<m_List1array.GetSize (); i++)
- {
- m_List1arrayBak.ElementAt (i).Add (m_List1array.ElementAt (i).ElementAt (0)); // Jeff.账号;
- m_List1arrayBak.ElementAt (i).Add (m_List1array.ElementAt (i).ElementAt (1)); // Jeff.性名;
- m_List1arrayBak.ElementAt (i).Add (m_List1array.ElementAt (i).ElementAt (8)); // Jeff.部门;
- }
- // Jeff:这里需要做个小处理,不添加已有账号的性名到下拉框中;
- #if 0// OldEdition;
- for( i=0; i<g_userarray.GetSize(); i++)
- m_comboname.AddString (g_userarray.ElementAt (i).ElementAt (1));
- #else
- for(i=0; i<g_userarray.GetSize(); i++)
- m_strNameArray.Add(g_userarray.ElementAt(i).ElementAt(1));
-
- for ( i=0; i < m_List1array.GetSize(); i++)
- {
- for (int j = 0; j < m_strNameArray.GetSize();j++)
- if ( m_List1array.ElementAt(i).ElementAt(1) == m_strNameArray.ElementAt(j) )
- {
- m_strNameArray.RemoveAt(j);
- }
- }
- CommboboxReLoad();
- #endif
- FillGrid();
- }
- void Account::CommboboxReLoad()
- {
- m_comboname.ResetContent();
- for(int i=0; i<m_strNameArray.GetSize(); i++)
- m_comboname.AddString (m_strNameArray.ElementAt (i));
- }
- void Account::FillGrid()
- {
- m_List1.DeleteAllItems2();
- int ii=0;
- //m_List1.m_arLabels.SetSize( m_List1arrayBak.GetSize (), 1 ); // Jeff:old
- m_List1.m_arLabels.SetSize(m_List1array.GetSize(),1);
- int count=0;
- for(ii=0; ii<m_List1.m_arLabels.GetSize (); ii++)
- {
- m_List1.m_arLabels.ElementAt(count++).Copy(m_List1arrayBak.ElementAt(ii));
- //m_List1.m_arLabels.ElementAt(count++).Copy(m_List1array.ElementAt(ii));
- }
- m_List1.m_arLabels.SetSize(count, 1);
- ii=count;
- m_List1.m_LabelCount=ii;
- m_List1.SetItemCountEx (ii);
- UpdateData();
- //Invalidate();
- }
- void Account::OnBUTclose()
- {
- // TODO: Add your control notification handler code here
- GetParent()->SendMessage(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; ii<m_List1array.GetSize (); ii++)
- {
- if(m_List1array.ElementAt (ii).ElementAt (0)==account)
- {
- CString name,rights;
- m_account = m_List1array.ElementAt (ii).ElementAt (0);
- name = m_List1array.ElementAt (ii).ElementAt (1);
- m_psw=m_psw2= m_List1array.ElementAt (ii).ElementAt (2);
- rights = m_List1array.ElementAt (ii).ElementAt (3);
- m_discount.Format("%0.1f" , atof(m_List1array.ElementAt (ii).ElementAt (5) ));
- m_discount2.Format("%0.1f" , atof(m_List1array.ElementAt (ii).ElementAt (6) ));
- UpdateData(false);
- //int nIndex =0 ;
- int pos=m_comboname.FindString (0, name);
- if(pos!=-1)
- m_comboname.SetCurSel (pos);
- else
- {
- m_comboname.InsertString (0, name);
- m_comboname.SetCurSel (0);
- }
- SetRights(rights);
- return;
- }
- }
- }
- void Account::OnBUTadd() // 添加新账号按钮; 添加时禁用删除按钮;
- {
- // TODO: Add your control notification handler code here
- CommboboxReLoad();
- m_bAddNew=1;
- GetDlgItem(IDC_EDITaccount)->EnableWindow(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; i<m_List1array.GetSize (); i++)
- {
- m_List1arrayBak.ElementAt (i).Add (m_List1array.ElementAt (i).ElementAt (0));
- m_List1arrayBak.ElementAt (i).Add (m_List1array.ElementAt (i).ElementAt (1));
- m_List1arrayBak.ElementAt (i).Add (m_List1array.ElementAt (i).ElementAt (8));
- }
- //
- FillGrid();
- }
- BOOL Account::IsExist(CString account,CString name)
- {
- for(int i=0; i<m_List1array.GetSize (); i++)
- {
- if(account==m_List1array.ElementAt (i).ElementAt (0))return 1;
- if(name==m_List1array.ElementAt (i).ElementAt (1))return 1;
- }
- return 0;
- }
- CString Account::GetRights()//50
- {
- CString ret,temp;
- for(int i=0; i<60; i++)
- {
- temp.Format ("%d",((CButton*)GetDlgItem(IDC_CHECK1+i))->GetCheck());
- ret+=temp;
- }
- return ret;
- }
- void Account::SetRights(CString rights)
- {
- for(int i=0; i<rights.GetLength (); i++)
- {
- if(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())
- // {
- // }
- }
|