// BuMenDlg.cpp : implementation file // #include "stdafx.h" #include "ylgl.h" #include "BuMenDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // BuMenDlg dialog BuMenDlg::BuMenDlg(CWnd* pParent /*=NULL*/) : CDialog(BuMenDlg::IDD, pParent) { //{{AFX_DATA_INIT(BuMenDlg) m_edit1 = _T(""); //}}AFX_DATA_INIT } void BuMenDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(BuMenDlg) DDX_Control(pDX, IDC_LIST1, m_List1); DDX_Text(pDX, IDC_EDIT1, m_edit1); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(BuMenDlg, CDialog) //{{AFX_MSG_MAP(BuMenDlg) ON_BN_CLICKED(IDC_BUTadd, OnBUTadd) ON_BN_CLICKED(IDC_BUTdel, OnBUTdel) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // BuMenDlg message handlers BOOL BuMenDlg::OnInitDialog() { CDialog::OnInitDialog(); // TODO: Add extra initialization here CRect rc; m_List1.GetClientRect(rc); CString strHeadings; strHeadings.Format("部门名称,%d", rc.Width() - 18); m_List1.SetHeadings(strHeadings); FillGrid(); this->CenterWindow(g_pMainWnd); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void BuMenDlg::FillGrid() { g_sendhead.bsql = 0; g_sendhead.code[0] = 3; g_sendhead.tabcount = 1; g_pMainWnd->ProcessChatMessageRequest2(3); if (g_bSendOK == 0)return; DataToArray(&m_List1array); m_List1.DeleteAllItems2(); int ii = 0; { m_List1.m_arLabels.SetSize(m_List1array.GetSize(), 1); for (ii = 0; ii < m_List1.m_arLabels.GetSize(); ii++) m_List1.m_arLabels.ElementAt(ii).Copy(m_List1array.ElementAt(ii)); } m_List1.m_LabelCount = ii; m_List1.SetItemCountEx(ii); } void BuMenDlg::OnBUTadd() { // TODO: Add your control notification handler code here UpdateData(); m_edit1.TrimLeft(); m_edit1.TrimRight(); if (m_edit1.IsEmpty()) { AfxMessageBox("部门不能为空!", MB_ICONINFORMATION); this->GetDlgItem(IDC_EDIT1)->SetFocus(); return; } CString sql; sql.Format("insert into bumen (name)values('%s')", m_edit1); g_sendhead.bsql = 1; g_sendhead.bsql = 1; g_pMainWnd->ProcessChatMessageRequest2(sql); if (g_bSendOK == 0)return; FillGrid(); } void BuMenDlg::OnBUTdel() { // TODO: Add your control notification handler code here POSITION pos; pos = m_List1.GetFirstSelectedItemPosition(); if (pos == NULL) { AfxMessageBox("请选中您要删除的部门!", MB_ICONINFORMATION); return; } if (AfxMessageBox("确认删除吗?", MB_YESNO | MB_ICONINFORMATION) != IDYES)return; int iItem = m_List1.GetNextSelectedItem(pos); CString name = m_List1.GetItemText(iItem, 0); CString sql; sql.Format("delete from bumen where name='%s'", name); g_sendhead.bsql = 1; g_pMainWnd->ProcessChatMessageRequest2(sql); if (g_bSendOK == 0)return; FillGrid(); }