// WorkerReport.cpp : implementation file // #include "stdafx.h" #include "ylgl.h" #include "WorkerReport.h" #include "MyMdi.H" #include "SelBrunDevice.h" #include "GetClientInfo.h" #include "ShowRemark.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // WorkerReport IMPLEMENT_DYNCREATE(WorkerReport, MyFormView) WorkerReport::WorkerReport() : MyFormView(WorkerReport::IDD) { //{{AFX_DATA_INIT(WorkerReport) m_filter = _T(""); m_clerk = _T(""); m_worker = g_user.name; m_addr = _T(""); m_date1 = ::GetTmFromStr(g_date); m_date2 = ::GetTmFromStr(g_date); m_remark = _T(""); m_check1 = FALSE; m_remark2 = _T(""); m_days = 0; m_remark3 = _T(""); //}}AFX_DATA_INIT } WorkerReport::~WorkerReport() { } void WorkerReport::DoDataExchange(CDataExchange* pDX) { MyFormView::DoDataExchange(pDX); //{{AFX_DATA_MAP(WorkerReport) DDX_Control(pDX, IDC_COMBOclerk, m_comboclerk); DDX_Control(pDX, IDC_COMBO1, m_combo1); DDX_Control(pDX, IDC_LIST2, m_List1); DDX_Control(pDX, IDC_STATIC1, m_static1); DDX_CBString(pDX, IDC_COMBO1, m_filter); DDX_CBString(pDX, IDC_COMBOclerk, m_clerk); DDX_Text(pDX, IDC_EDITworker, m_worker); DDX_Text(pDX, IDC_EDITaddr, m_addr); DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER1, m_date1); DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER2, m_date2); DDX_Text(pDX, IDC_EDITremark, m_remark); DDX_Check(pDX, IDC_CHECK1, m_check1); DDX_Text(pDX, IDC_EDITremark2, m_remark2); DDX_Text(pDX, IDC_EDITremark3, m_remark3); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(WorkerReport, MyFormView) //{{AFX_MSG_MAP(WorkerReport) ON_BN_CLICKED(IDC_BUTclose, OnBUTclose) ON_BN_CLICKED(IDC_BUTTON1, OnButton1) ON_BN_CLICKED(IDC_BUTTON2, OnButton2) ON_BN_CLICKED(IDC_BUTTON3, OnButton3) ON_NOTIFY(NM_CLICK, IDC_LIST2, OnClickList2) ON_BN_CLICKED(IDC_BUTTON4, OnButton4) ON_BN_CLICKED(IDC_BUTTON5, OnButton5) ON_BN_CLICKED(IDC_CHECK1, OnCheck1) ON_CBN_CLOSEUP(IDC_COMBOclerk, OnCloseupCOMBOclerk) ON_CBN_CLOSEUP(IDC_COMBO1, OnCloseupCombo1) ON_WM_TIMER() ON_BN_CLICKED(IDC_BUTTON10, OnButton10) ON_BN_CLICKED(IDC_BUTTON11, OnButton11) ON_BN_CLICKED(IDC_BUTTON32, OnButton32) ON_BN_CLICKED(IDC_BUTTON14, OnButton14) ON_BN_CLICKED(IDC_BUTTON9, OnButton9) ON_BN_CLICKED(IDC_BUTTON16, OnButton16) ON_BN_CLICKED(IDC_BUTTON12, OnButton12) //}}AFX_MSG_MAP END_MESSAGE_MAP() // ON_NOTIFY(NM_CUSTOMDRAW, IDC_LIST2, OnCustomdrawList) ///////////////////////////////////////////////////////////////////////////// // WorkerReport diagnostics #ifdef _DEBUG void WorkerReport::AssertValid() const { MyFormView::AssertValid(); } void WorkerReport::Dump(CDumpContext& dc) const { MyFormView::Dump(dc); } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // WorkerReport message handlers void WorkerReport::OnInitialUpdate() { MyFormView::OnInitialUpdate(); // TODO: Add your specialized code here and/or call the base class CMyMdi Mdi; Mdi.SetSubView((CWnd*)GetParent(), (CWnd*)this); GetDlgItem(IDC_BUTTON2)->EnableWindow(IsHasRights2new(49)); GetDlgItem(IDC_BUTTON14)->EnableWindow(IsHasRights2new(53)); // 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_static1.SetFont(&g_titlefont); m_List1.SetHeadings("id,0;人员,100;客户全称,180;日期,110;填写日期,110;工作内容,180;明日计划,180;领导评定,180;状态,50"); // m_List1.LoadColumnInfo (201); GetData(); m_combo1.GetWindowRect(rc2); ScreenToClient(rc2); rc2.bottom += 200; m_combo1.MoveWindow(rc2); GetDlgItem(IDC_BUTclose)->GetWindowRect(rc2); SetComboHei(&m_combo1, rc2.Height()); m_combo1.AddString("广东"); m_combo1.AddString("广西"); m_combo1.AddString("河南"); m_combo1.AddString("河北"); m_combo1.AddString("山东"); m_combo1.AddString("山西"); m_combo1.AddString("湖南"); m_combo1.AddString("湖北"); m_combo1.AddString("云南"); m_combo1.AddString("黑龙江"); m_combo1.AddString("吉林"); m_combo1.AddString("甘肃"); m_combo1.AddString("陕西"); m_combo1.AddString("四川"); m_combo1.AddString("重庆"); m_combo1.AddString("北京"); m_combo1.AddString("天津"); m_combo1.AddString("内蒙"); m_combo1.AddString("新疆"); m_combo1.AddString("辽宁"); m_combo1.AddString("青海"); m_combo1.AddString("江苏"); m_combo1.AddString("江西"); m_combo1.AddString("浙江"); m_combo1.AddString("福建"); m_combo1.AddString("海南"); m_combo1.AddString("贵州"); m_combo1.AddString("安徽"); m_combo1.AddString("上海"); m_combo1.AddString("西藏"); m_combo1.AddString("宁夏"); m_combo1.AddString("香港"); m_combo1.AddString("澳门"); m_combo1.AddString("台湾"); m_comboclerk.RefDroppedWidth(); } void WorkerReport::FillGrid() { m_List1.DeleteAllItems2(); int ii = 0; m_List1.m_arLabels.SetSize(m_List1array.GetSize(), 1); int count = 0; if (m_days) { CTime tm = ::GetTmFromStr(g_date); CTimeSpan dt = CTimeSpan(m_days, 0, 0, 0); CTime begintm = tm - dt; CString begindate = begintm.Format("%Y-%m-%d"); CStringArray existarray; for (ii = 0; ii < m_List1.m_arLabels.GetSize(); ii++) { if (::FindArray(&existarray, m_List1array.ElementAt(ii).ElementAt(1)) != -1)continue; if (m_List1array.ElementAt(ii).ElementAt(3) <= begindate) { m_List1.m_arLabels.ElementAt(count++).Copy(m_List1array.ElementAt(ii)); } //else existarray.Add(m_List1array.ElementAt(ii).ElementAt(1)); } m_days = 0; } else if (m_clerk != "") { for (ii = 0; ii < m_List1.m_arLabels.GetSize(); ii++) { if (m_List1array.ElementAt(ii).ElementAt(1) == m_clerk) { m_List1.m_arLabels.ElementAt(count++).Copy(m_List1array.ElementAt(ii)); } } } else if (m_filter.IsEmpty()) { for (ii = 0; ii < m_List1.m_arLabels.GetSize(); ii++) { m_List1.m_arLabels.ElementAt(count++).Copy(m_List1array.ElementAt(ii)); } } else { for (ii = 0; ii < m_List1.m_arLabels.GetSize(); ii++) { if (m_List1array.ElementAt(ii).ElementAt(0).Find(m_filter) != -1 || \ m_List1array.ElementAt(ii).ElementAt(1).Find(m_filter) != -1 || \ m_List1array.ElementAt(ii).ElementAt(2).Find(m_filter) != -1 || \ m_List1array.ElementAt(ii).ElementAt(3).Find(m_filter) != -1 || \ m_List1array.ElementAt(ii).ElementAt(4).Find(m_filter) != -1) { 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); } void WorkerReport::OnBUTclose() { // TODO: Add your control notification handler code here GetParent()->SendMessage(WM_CLOSE); } BOOL WorkerReport::PreTranslateMessage(MSG* pMsg) { // TODO: Add your specialized code here and/or call the base class try { if (pMsg->message == WM_KEYDOWN) { switch (pMsg->wParam) { case VK_RETURN: OnButton1(); return 1; case 0x43: // copy if ((GetKeyState(VK_CONTROL) & 0x80)) { GetFocus()->SendMessage(WM_COPY); return TRUE; } break; case 0x56: //Ctrl + V: if ((GetKeyState(VK_CONTROL) & 0x80)) { GetFocus()->SendMessage(WM_PASTE); return TRUE; } break; case 0x58: // cut if ((GetKeyState(VK_CONTROL) & 0x80)) { GetFocus()->SendMessage(WM_CUT); return TRUE; } break; case 0x5A: //undo case 0x59: //redo if ((GetKeyState(VK_CONTROL) & 0x80)) { GetFocus()->SendMessage(WM_UNDO); return TRUE; } break; } } return MyFormView::PreTranslateMessage(pMsg); } catch (...) { } return TRUE; } void WorkerReport::OnButton1() { // TODO: Add your control notification handler code here UpdateData(); m_filter.TrimLeft(); m_filter.TrimRight(); FillGrid(); } void WorkerReport::OnButton3() { UpdateData(); m_addr.TrimLeft(); m_addr.TrimRight(); m_remark.TrimLeft(); m_remark.TrimRight(); if (m_remark == "" || m_remark3 == "" || m_addr == "") { AfxMessageBox("资料不全!", MB_ICONINFORMATION); return; } if (m_date2 > m_date1) { CTimeSpan dt = m_date2 - m_date1; if (dt.GetDays() > 6) { AfxMessageBox("只能签到近一星期!", MB_ICONINFORMATION); return; } } else { CTimeSpan dt = m_date1 - m_date2; if (dt.GetDays() > 2) { AfxMessageBox("请不要玩穿越!", MB_ICONINFORMATION); return; } } CString date1 = m_date1.Format("%Y-%m-%d"); CString date2 = m_date2.Format("%Y-%m-%d"); CString sql; if (m_id == "") sql.Format("insert into [workerreport] ([worker],[addr],[date1],[date2],[remark],[remark3])values( '%s','%s','%s','%s','%s','%s')", m_worker, m_addr, date1, date2, m_remark, m_remark3); else sql.Format("update [workerreport] set [addr]='%s',[date1]='%s',[date2]='%s',[remark]='%s',[remark3]='%s' where id=%s", m_addr, date1, date2, m_remark, m_remark3, m_id); g_sendhead.bsql = 1; g_pMainWnd->ProcessChatMessageRequest2(sql); if (g_bSendOK == 0)return; AfxMessageBox("保存成功!", MB_ICONINFORMATION); GetData(); } void WorkerReport::GetData() { UpdateData(); g_sendhead.bsql = 0; g_sendhead.code[0] = 212; g_sendhead.tabcount = 1; if (m_check1) g_pMainWnd->ProcessChatMessageRequest2(3); else { CString filter; CTime tm = ::GetTmFromStr(g_date); CTimeSpan dt = CTimeSpan(30, 0, 0, 0); CTime begintm = tm - dt; CString begindate = begintm.Format("%Y-%m-%d"); CString enddate = tm.Format("%Y-%m-%d"); filter.Format("date2>='%s' and date2<='%s'", begindate, enddate); g_pMainWnd->ProcessChatMessageRequest2(filter); } if (g_bSendOK == 0) { return; } DataToArray(&m_List1array); int size = m_List1array.GetSize(); int i = 0; CStringArray array; for ( i = 0; i < g_userarray.GetSize(); i++) { CString worker = g_userarray.ElementAt(i).ElementAt(1); BOOL bFind = 0; for (int j = 0; j < size; j++) { if (m_List1array.ElementAt(j).ElementAt(1) == worker) { bFind = 1; break; } } if (bFind == 0)array.Add(worker); } m_List1array.SetSize(size + array.GetSize(), 1); for (i = 0; i < array.GetSize(); i++) { m_List1array.ElementAt(size + i).Add(""); m_List1array.ElementAt(size + i).Add(array.ElementAt(i)); m_List1array.ElementAt(size + i).Add(""); m_List1array.ElementAt(size + i).Add(""); m_List1array.ElementAt(size + i).Add(""); m_List1array.ElementAt(size + i).Add(""); m_List1array.ElementAt(size + i).Add(""); m_List1array.ElementAt(size + i).Add(""); m_List1array.ElementAt(size + i).Add(""); } m_List1arrayBak.SetSize(m_List1array.GetSize()); for (i = 0; i < m_List1array.GetSize(); i++) { m_List1arrayBak.ElementAt(i).Copy(m_List1array.ElementAt(i)); if (m_List1array.ElementAt(i).ElementAt(5).GetLength()>100) m_List1array.ElementAt(i).SetAt(5, m_List1array.ElementAt(i).ElementAt(5).Left(100) + ".."); if (m_List1array.ElementAt(i).ElementAt(6).GetLength()>100) m_List1array.ElementAt(i).SetAt(6, m_List1array.ElementAt(i).ElementAt(6).Left(100) + ".."); if (m_List1array.ElementAt(i).ElementAt(7).GetLength() > 100) m_List1array.ElementAt(i).SetAt(7, m_List1array.ElementAt(i).ElementAt(7).Left(100) + ".."); if (m_List1array.ElementAt(i).ElementAt(7) != "") { if (0 == atoi(m_List1array.ElementAt(i).ElementAt(8))) m_List1array.ElementAt(i).SetAt(8, "未读"); else m_List1array.ElementAt(i).SetAt(8, "已读"); } } FillGrid(); BOOL bFind = 0; for (i = 0; i < m_List1arrayBak.GetSize(); i++) { if (0 == atoi(m_List1arrayBak.ElementAt(i).ElementAt(8)) && m_List1arrayBak.ElementAt(i).ElementAt(7) != "" && m_List1arrayBak.ElementAt(i).ElementAt(1) == g_user.name) { ShowRemark dlg; dlg.m_remark = m_List1arrayBak.ElementAt(i).ElementAt(7); dlg.DoModal(); CString sql; sql.Format("update [workerreport] set [read]='1' where id=%s", m_List1arrayBak.ElementAt(i).ElementAt(0)); g_sendhead.bsql = 1; g_pMainWnd->ProcessChatMessageRequest2(sql); bFind = 1; } } if (bFind)GetData(); } void WorkerReport::OnClickList2(NMHDR* pNMHDR, LRESULT* pResult) { // TODO: Add your control notification handler code here POSITION pos; pos = m_List1.GetFirstSelectedItemPosition(); if (pos == NULL) { OnButton4(); return; } int iItem = m_List1.GetNextSelectedItem(pos); m_id = m_List1.GetItemText(iItem, 0); if (m_id == "") { OnButton4(); return; } for (int i = 0; i < m_List1arrayBak.GetSize(); i++) { if (m_id == m_List1arrayBak.ElementAt(i).ElementAt(0)) { m_worker = m_List1arrayBak.ElementAt(i).ElementAt(1); m_addr = m_List1arrayBak.ElementAt(i).ElementAt(2); m_date1 = ::GetTmFromStr(m_List1arrayBak.ElementAt(i).ElementAt(3)); m_date2 = ::GetTmFromStr(m_List1arrayBak.ElementAt(i).ElementAt(4)); m_remark = m_List1arrayBak.ElementAt(i).ElementAt(5); m_remark3 = m_List1arrayBak.ElementAt(i).ElementAt(6); m_remark2 = m_List1arrayBak.ElementAt(i).ElementAt(7); UpdateData(0); GetDlgItem(IDC_BUTTON3)->SetWindowText("保存更改"); if (g_user.name != m_worker || m_List1arrayBak.ElementAt(i).ElementAt(4) != g_date || m_List1arrayBak.ElementAt(i).ElementAt(7) != "") GetDlgItem(IDC_BUTTON3)->EnableWindow(0); else GetDlgItem(IDC_BUTTON3)->EnableWindow(1); break; } } *pResult = 0; } void WorkerReport::OnButton4() { // TODO: Add your control notification handler code here m_id = ""; m_worker = g_user.name; m_addr = _T(""); m_date1 = ::GetTmFromStr(g_date); m_date2 = ::GetTmFromStr(g_date); m_remark = _T(""); m_remark2 = _T(""); m_remark3 = _T(""); UpdateData(0); GetDlgItem(IDC_BUTTON3)->SetWindowText("保存"); GetDlgItem(IDC_BUTTON3)->EnableWindow(1); } void WorkerReport::OnButton2() { // 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 id = m_List1.GetItemText(iItem, 0); CString sql; sql.Format("delete from [workerreport] where [id]=%s", id); g_sendhead.bsql = 1; g_pMainWnd->ProcessChatMessageRequest2(sql); if (g_bSendOK == 0)return; GetData(); } void WorkerReport::OnButton5() { // TODO: Add your control notification handler code here UpdateData(); GetClientInfo dlg; if (dlg.DoModal() == IDOK) { m_addr = dlg.m_name2; UpdateData(0); } } void WorkerReport::OnCheck1() { // TODO: Add your control notification handler code here GetData(); } void WorkerReport::OnCloseupCOMBOclerk() { // TODO: Add your control notification handler code here int pos = m_comboclerk.GetCurSel(); if (pos == -1)return; m_comboclerk.GetLBText(pos, m_clerk); FillGrid(); } void WorkerReport::OnCloseupCombo1() { // TODO: Add your control notification handler code here SetTimer(1, 100, NULL); } void WorkerReport::OnTimer(UINT nIDEvent) { // TODO: Add your message handler code here and/or call default KillTimer(1); UpdateData(); FillGrid(); MyFormView::OnTimer(nIDEvent); } void WorkerReport::OnCustomdrawList(NMHDR* pNMHDR, LRESULT* pResult) { NMLVCUSTOMDRAW* pLVCD = reinterpret_cast(pNMHDR); // Take the default processing unless we set this to something else below. *pResult = 0; // First thing - check the draw stage. If it's the control's prepaint // stage, then tell Windows we want messages for every item. if (CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage) { *pResult = CDRF_NOTIFYITEMDRAW; } else if (CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage) { // This is the prepaint stage for an item. Here's where we set the // item's text color. Our return value will tell Windows to draw the // item itself, but it will use the new color we set here. // We'll cycle the colors through red, green, and light blue. if (m_List1.m_arLabels.ElementAt(pLVCD->nmcd.dwItemSpec).ElementAt(8) != "0") pLVCD->clrText = RGB(220, 0, 0); else pLVCD->clrText = RGB(20, 133, 20); if (pLVCD->nmcd.dwItemSpec % 2) pLVCD->clrTextBk = g_gridcol1; else pLVCD->clrTextBk = g_gridcol2; // Store the color back in the NMLVCUSTOMDRAW struct. // Tell Windows to paint the control itself. *pResult = CDRF_DODEFAULT; } } void WorkerReport::OnButton10() { // TODO: Add your control notification handler code here m_days = 2; FillGrid(); } void WorkerReport::OnButton11() { // TODO: Add your control notification handler code here m_days = 3; FillGrid(); } void WorkerReport::OnButton32() { // TODO: Add your control notification handler code here m_days = 5; FillGrid(); } void WorkerReport::OnButton14() { // TODO: Add your control notification handler code here POSITION pos; pos = m_List1.GetFirstSelectedItemPosition(); if (pos == NULL) { AfxMessageBox("请先选中项目!", MB_ICONINFORMATION); return; } int iItem = m_List1.GetNextSelectedItem(pos); CString id = m_List1.GetItemText(iItem, 0); ShowRemark dlg; dlg.m_remark = m_remark2; if (dlg.DoModal() == IDOK) { CString right = g_user.name + "示"; if (dlg.m_remark.GetLength() >= right.GetLength()) { if (dlg.m_remark.Right(right.GetLength()) != right) dlg.m_remark += " " + right; } else dlg.m_remark += " " + right; CString m_remark2 = dlg.m_remark; CString sql; sql.Format("update [workerreport] set [remark2]='%s',[read]='0' where id=%s", m_remark2, id); g_sendhead.bsql = 1; g_pMainWnd->ProcessChatMessageRequest2(sql); if (g_bSendOK == 0)return; AfxMessageBox("保存成功!", MB_ICONINFORMATION); GetData(); } } void WorkerReport::OnButton9() { // TODO: Add your control notification handler code here UpdateData(); ShowRemark dlg; dlg.m_remark = m_remark; if (dlg.DoModal() == IDOK) { m_remark = dlg.m_remark; UpdateData(0); } } void WorkerReport::OnButton16() { // TODO: Add your control notification handler code here UpdateData(); ShowRemark dlg; dlg.m_remark = m_remark2; if (dlg.DoModal() == IDOK) { } } void WorkerReport::OnButton12() { // TODO: Add your control notification handler code here UpdateData(); ShowRemark dlg; dlg.m_remark = m_remark3; if (dlg.DoModal() == IDOK) { m_remark3 = dlg.m_remark; UpdateData(0); } }