SetLoginBan.cpp 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. // SetLoginBan.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ylgl.h"
  5. #include "SetLoginBan.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // SetLoginBan dialog
  13. SetLoginBan::SetLoginBan(CWnd* pParent /*=NULL*/)
  14. : CDialog(SetLoginBan::IDD, pParent)
  15. {
  16. //{{AFX_DATA_INIT(SetLoginBan)
  17. // NOTE: the ClassWizard will add member initialization here
  18. //}}AFX_DATA_INIT
  19. m_pos=0;
  20. }
  21. void SetLoginBan::DoDataExchange(CDataExchange* pDX)
  22. {
  23. CDialog::DoDataExchange(pDX);
  24. //{{AFX_DATA_MAP(SetLoginBan)
  25. DDX_Control(pDX, IDC_LIST1, m_List1);
  26. //}}AFX_DATA_MAP
  27. }
  28. BEGIN_MESSAGE_MAP(SetLoginBan, CDialog)
  29. //{{AFX_MSG_MAP(SetLoginBan)
  30. ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
  31. ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
  32. ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
  33. ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
  34. //}}AFX_MSG_MAP
  35. END_MESSAGE_MAP()
  36. /////////////////////////////////////////////////////////////////////////////
  37. // SetLoginBan message handlers
  38. BOOL SetLoginBan::OnInitDialog()
  39. {
  40. CDialog::OnInitDialog();
  41. // TODO: Add extra initialization here
  42. g_sendhead.bsql=0;
  43. g_sendhead.code[0]=97;
  44. g_sendhead.tabcount=1;
  45. g_pMainWnd->ProcessChatMessageRequest2(2);if(g_bSendOK==0)return false;
  46. DataToArray(&g_List1array);
  47. m_List1.InitStyle();
  48. m_List1.InsertColumn(0,_T("姓名"),LVCFMT_LEFT,100);
  49. m_List1.InsertColumn(1,_T("星期日"),LVCFMT_LEFT,100);
  50. m_List1.InsertColumn(2,_T("星期一"),LVCFMT_LEFT,100);
  51. m_List1.InsertColumn(3,_T("星期二"),LVCFMT_LEFT,100);
  52. m_List1.InsertColumn(4,_T("星期三"),LVCFMT_LEFT,100);
  53. m_List1.InsertColumn(5,_T("星期四"),LVCFMT_LEFT,100);
  54. m_List1.InsertColumn(6,_T("星期五"),LVCFMT_LEFT,100);
  55. m_List1.InsertColumn(7,_T("星期六"),LVCFMT_LEFT,100);
  56. GetTimeRange();
  57. CenterWindow();
  58. return TRUE; // return TRUE unless you set the focus to a control
  59. // EXCEPTION: OCX Property Pages should return FALSE
  60. }
  61. void SetLoginBan::GetTimeRange()
  62. {
  63. CTime tm(atoi(g_date.Mid (0,4)),atoi(g_date.Mid (5,2)),atoi(g_date.Mid (8,2)),0,0,0);//=CTime::GetCurrentTime ();
  64. if(m_pos)
  65. {
  66. CTimeSpan sp(abs(m_pos)*7, 0, 0, 0);
  67. if(m_pos>0)
  68. tm+=sp;
  69. else
  70. tm-=sp;
  71. }
  72. int nDayWeek = tm.GetDayOfWeek()-1;
  73. int days1=nDayWeek;
  74. int days2=6-nDayWeek;
  75. CTime tm2,tm3;
  76. CTimeSpan sp(days1, 0, 0, 0);
  77. tm2=tm-sp;
  78. CTimeSpan sp2(days2, 0, 0, 0);
  79. tm3=tm+sp2;
  80. CString str;
  81. str.Format ("时间段:%04d-%02d-%02d 至 %04d-%02d-%02d", tm2.GetYear (), tm2.GetMonth (), tm2.GetDay (), tm3.GetYear (), tm3.GetMonth (), tm3.GetDay () );
  82. SetDlgItemText(IDC_STATIC1, str);
  83. m_scurdate.Format ("%04d-%02d-%02d", tm2.GetYear (), tm2.GetMonth (), tm2.GetDay () );
  84. ShowLoginData();
  85. }
  86. void SetLoginBan::OnButton1()
  87. {
  88. // TODO: Add your control notification handler code here
  89. m_pos--;
  90. GetTimeRange();
  91. }
  92. void SetLoginBan::OnButton2()
  93. {
  94. // TODO: Add your control notification handler code here
  95. m_pos++;
  96. GetTimeRange();
  97. }
  98. void SetLoginBan::ShowLoginData()
  99. {//m_scurdate
  100. CString filter="weekname='"+m_scurdate+"'";
  101. g_sendhead.code[0]=107;
  102. g_sendhead.tabcount=1;
  103. g_sendhead.bsql=0;
  104. g_pMainWnd->ProcessChatMessageRequest2(filter);if(g_bSendOK==0)return;
  105. CArray<CStringArray, CStringArray>List1array;
  106. DataToArray(&List1array);
  107. m_List1.DeleteAllItems ();
  108. for(int i=0; i<List1array.GetSize (); i++)
  109. {
  110. m_List1.InsertItem(i, List1array.ElementAt (i).ElementAt (0));
  111. m_List1.SetItemText(i, 1, List1array.ElementAt (i).ElementAt (1));
  112. m_List1.SetItemText(i, 2, List1array.ElementAt (i).ElementAt (2));
  113. m_List1.SetItemText(i, 3, List1array.ElementAt (i).ElementAt (3));
  114. m_List1.SetItemText(i, 4, List1array.ElementAt (i).ElementAt (4));
  115. m_List1.SetItemText(i, 5, List1array.ElementAt (i).ElementAt (5));
  116. m_List1.SetItemText(i, 6, List1array.ElementAt (i).ElementAt (6));
  117. m_List1.SetItemText(i, 7, List1array.ElementAt (i).ElementAt (7));
  118. }
  119. }
  120. void SetLoginBan::OnOK()
  121. {
  122. // TODO: Add extra validation here
  123. CStringArray array;
  124. array.Add (m_scurdate);
  125. for(int i=0; i<m_List1.GetItemCount (); i++)
  126. {
  127. array.Add (m_List1.GetItemText (i, 0));
  128. array.Add (m_List1.GetItemText (i, 1));
  129. array.Add (m_List1.GetItemText (i, 2));
  130. array.Add (m_List1.GetItemText (i, 3));
  131. array.Add (m_List1.GetItemText (i, 4));
  132. array.Add (m_List1.GetItemText (i, 5));
  133. array.Add (m_List1.GetItemText (i, 6));
  134. array.Add (m_List1.GetItemText (i, 7));
  135. }
  136. CMemFile memfile;
  137. CArchive ar(&memfile, CArchive::store);
  138. array.Serialize (ar);
  139. ar.Close();
  140. int length=memfile.GetLength ();
  141. BYTE *pData = memfile.Detach();
  142. g_nSendCode=23;
  143. g_pMainWnd->ProcessChatMessageRequest2(pData, length);
  144. g_nSendCode=0;
  145. delete []pData;
  146. if(g_bSendOK==0)return;
  147. AfxMessageBox("保存成功!", MB_ICONINFORMATION);
  148. }
  149. void SetLoginBan::OnButton3()
  150. {
  151. // TODO: Add your control notification handler code here
  152. CFileDialog fdlg(false, NULL,"ban1", OFN_ALLOWMULTISELECT,"排班文件(*.ban)|*.ban||");
  153. if(fdlg.DoModal ()!=IDOK)return;
  154. CStringArray array;
  155. for(int i=0; i<m_List1.GetItemCount (); i++)
  156. {
  157. array.Add (m_List1.GetItemText (i, 0));
  158. array.Add (m_List1.GetItemText (i, 1));
  159. array.Add (m_List1.GetItemText (i, 2));
  160. array.Add (m_List1.GetItemText (i, 3));
  161. array.Add (m_List1.GetItemText (i, 4));
  162. array.Add (m_List1.GetItemText (i, 5));
  163. array.Add (m_List1.GetItemText (i, 6));
  164. array.Add (m_List1.GetItemText (i, 7));
  165. }
  166. CMemFile memfile;
  167. CArchive ar(&memfile, CArchive::store);
  168. array.Serialize (ar);
  169. ar.Close();
  170. int length=memfile.GetLength ();
  171. BYTE *pData = memfile.Detach();
  172. CString path=fdlg.GetPathName ();
  173. path+=".ban";
  174. CFile fp;
  175. fp.Open (path, CFile::modeCreate|CFile::modeWrite);
  176. fp.Write (pData, length);
  177. fp.Close ();
  178. delete []pData;
  179. AfxMessageBox("保存成功!", MB_ICONINFORMATION);
  180. }
  181. void SetLoginBan::OnButton4()
  182. {
  183. // TODO: Add your control notification handler code here
  184. CFileDialog fdlg(true, NULL,"", OFN_ALLOWMULTISELECT,"排班文件(*.ban)|*.ban||");
  185. if(fdlg.DoModal ()!=IDOK)return;
  186. CString path=fdlg.GetPathName ();
  187. CFile fp;
  188. fp.Open (path, CFile::modeRead);
  189. DWORD count=fp.GetLength ();
  190. BYTE *pData=new BYTE [count];
  191. fp.Read (pData, count);
  192. fp.Close ();
  193. CStringArray array;
  194. CMemFile memfile;
  195. memfile.Attach (pData, count);
  196. CArchive ar(&memfile, CArchive::load);
  197. array.Serialize (ar);
  198. ar.Close();
  199. memfile.Detach ();
  200. delete []pData;
  201. CString name;
  202. for(int i=0; i<m_List1.GetItemCount (); i++)
  203. {
  204. name=m_List1.GetItemText (i, 0);
  205. for(int j=0; j<array.GetSize (); j+=8)
  206. {
  207. if(name==array.ElementAt (j))
  208. {
  209. m_List1.SetItemText (i, 1, array.ElementAt (j+1));
  210. m_List1.SetItemText (i, 2, array.ElementAt (j+2));
  211. m_List1.SetItemText (i, 3, array.ElementAt (j+3));
  212. m_List1.SetItemText (i, 4, array.ElementAt (j+4));
  213. m_List1.SetItemText (i, 5, array.ElementAt (j+5));
  214. m_List1.SetItemText (i, 6, array.ElementAt (j+6));
  215. m_List1.SetItemText (i, 7, array.ElementAt (j+7));
  216. array.RemoveAt (j);
  217. array.RemoveAt (j);
  218. array.RemoveAt (j);
  219. array.RemoveAt (j);
  220. array.RemoveAt (j);
  221. array.RemoveAt (j);
  222. array.RemoveAt (j);
  223. array.RemoveAt (j);
  224. break;
  225. }
  226. }
  227. }
  228. }