DlgDatePlan.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. // DlgUserManager.cpp : 实现文件
  2. //
  3. #include "stdafx.h"
  4. #include "IDE.h"
  5. #include "DBConnection.h"
  6. #include ".\dlgdateplan.h"
  7. // CDlgDatePlan 对话框
  8. IMPLEMENT_DYNAMIC(CDlgDatePlan, CDialog)
  9. CDlgDatePlan::CDlgDatePlan(CWnd* pParent /*=NULL*/)
  10. : CDialog(CDlgDatePlan::IDD, pParent)
  11. {
  12. m_nPlanType = -1;
  13. m_strUid = "";
  14. m_nVarID = 0;
  15. m_strUserID = "";
  16. }
  17. CDlgDatePlan::~CDlgDatePlan()
  18. {
  19. }
  20. void CDlgDatePlan::DoDataExchange(CDataExchange* pDX)
  21. {
  22. CDialog::DoDataExchange(pDX);
  23. DDX_Control(pDX, IDC_HOURSSELECTOR, m_ocxHourSelector);
  24. }
  25. BEGIN_MESSAGE_MAP(CDlgDatePlan, CDialog)
  26. ON_BN_CLICKED(IDOK, OnBnClickedOk)
  27. ON_BN_CLICKED(IDCANCEL, OnBnClickedCancel)
  28. END_MESSAGE_MAP()
  29. // CDlgDatePlan 消息处理程序
  30. BOOL CDlgDatePlan::OnInitDialog()
  31. {
  32. CDialog::OnInitDialog();
  33. // TODO: 在此添加额外的初始化
  34. m_ocxHourSelector.SetFocus();
  35. COleSafeArray l_osaHours;
  36. DWORD numElements[] = {168};
  37. l_osaHours.Create(VT_UI1, 1, numElements);
  38. unsigned char szArray[7][24];
  39. long nPoint[1]={0};
  40. memset(szArray, 0, sizeof(szArray) );
  41. int nRet;
  42. if( m_nPlanType == PLAN_TYPE_USER )
  43. {
  44. nRet = CDBInterface::GetInstancePtr()->GetDatePlan( m_nPlanType, (char *)(LPCTSTR)m_strUserID.Trim(), szArray );
  45. if( nRet > 0 )
  46. {
  47. for( int x=0; x<7; x++)
  48. {
  49. for(int y=0; y<24; y++)
  50. {
  51. l_osaHours.PutElement(nPoint, &szArray[x][y]);
  52. nPoint[0]++;
  53. }
  54. }
  55. }
  56. }
  57. else if( m_nPlanType == PLAN_TYPE_EQUIP )
  58. {
  59. nRet = CDBInterface::GetInstancePtr()->GetDatePlan( m_nPlanType, (char *)(LPCTSTR)m_strUid, m_nVarID, szArray );
  60. if( nRet > 0 )
  61. {
  62. for( int x=0; x<7; x++)
  63. {
  64. for(int y=0; y<24; y++)
  65. {
  66. l_osaHours.PutElement(nPoint, &szArray[x][y]);
  67. nPoint[0]++;
  68. }
  69. }
  70. }
  71. else
  72. {
  73. for( int x=0; x<7; x++)
  74. {
  75. for(int y=0; y<24; y++)
  76. {
  77. int nTemp = 15;
  78. l_osaHours.PutElement(nPoint, &nTemp);
  79. nPoint[0]++;
  80. }
  81. }
  82. }
  83. }
  84. m_ocxHourSelector.SetHoursArray(l_osaHours);
  85. return TRUE; // return TRUE unless you set the focus to a control
  86. // 异常: OCX 属性页应返回 FALSE
  87. }
  88. void CDlgDatePlan::DealArray(unsigned char nBuf[7][24])
  89. {
  90. CString s,sTemp,str;
  91. CString sReport[500];
  92. int nReportIndex = 0;
  93. for( int y=0; y<7; y++)
  94. {
  95. for(int x=0; x<24; x++)
  96. {
  97. if(nBuf[y][x] == 15)
  98. {
  99. sTemp.Format("%02d%02d",y,x);
  100. sReport[nReportIndex] = sTemp;
  101. for(int x1 = x+1; x1<24; x1++)
  102. {
  103. if(nBuf[y][x1] == 15)
  104. {
  105. sTemp.Format("%02d%02d",y,x1);
  106. sReport[nReportIndex] += sTemp;
  107. }
  108. else
  109. {
  110. x = x1;
  111. break;
  112. }
  113. if(nBuf[y][x1] == 15 && x1 == 23)
  114. {
  115. x = x1;
  116. break;
  117. }
  118. }
  119. s.Format("%s",sReport[nReportIndex]);
  120. //AfxMessageBox(s);
  121. nReportIndex++;
  122. str+=s;
  123. str+="\n";
  124. }
  125. }
  126. }
  127. int nResultIndex = 0;
  128. int iSign = 0;
  129. CString sResult[500];
  130. bool bFlag[500];
  131. int i = 0,j = 0;
  132. for( i=0;i<500;i++ )
  133. bFlag[i] = true;
  134. for( i=0;i<nReportIndex;i++ )
  135. {
  136. iSign = 1;
  137. if(bFlag[i])
  138. {
  139. sResult[nResultIndex] = sReport[i];
  140. }
  141. for( j=i+1;j<nReportIndex;j++ )
  142. {
  143. if( sReport[i].GetLength() == sReport[j].GetLength() && bFlag[i] && bFlag[j])
  144. {
  145. if( CompareStr(sReport[i],sReport[j],iSign) )
  146. {
  147. sResult[nResultIndex] += sReport[j];
  148. bFlag[j] = false;
  149. iSign++;
  150. }
  151. }
  152. }
  153. if(bFlag[i])
  154. {
  155. bFlag[i] = false;
  156. nResultIndex++;
  157. }
  158. }
  159. ///////////////////////////////////////////////////////////////////////////
  160. CString sWeek1,sWeek2,sHour1,sHour2;
  161. if( m_nPlanType == PLAN_TYPE_USER )
  162. {
  163. CDBInterface::GetInstancePtr()->DeleteDatePlan( m_nPlanType, (char *)(LPCTSTR)m_strUserID );
  164. }
  165. else if( m_nPlanType == PLAN_TYPE_EQUIP )
  166. {
  167. CDBInterface::GetInstancePtr()->DeleteDatePlan( m_nPlanType, m_strUid, m_nVarID );
  168. }
  169. for( int x=0; x<nResultIndex; x++ )
  170. {
  171. sHour1 = sResult[x].Mid(2,2);
  172. sWeek1 = sResult[x].Mid(0,2);
  173. sHour2 = sResult[x].Mid(sResult[x].GetLength()-2,2);
  174. sWeek2 = sResult[x].Mid(sResult[x].GetLength()-4,2);
  175. if( m_nPlanType == PLAN_TYPE_USER )
  176. {
  177. CDBInterface::GetInstancePtr()->InsertDatePlan( m_nPlanType, (char *)(LPCTSTR)m_strUserID, atoi(sHour1), atoi(sHour2),
  178. atoi(sWeek1), atoi(sWeek2) );
  179. }
  180. else if( m_nPlanType == PLAN_TYPE_EQUIP )
  181. {
  182. CDBInterface::GetInstancePtr()->InsertDatePlan( m_nPlanType, m_strUid, m_nVarID, atoi(sHour1), atoi(sHour2),
  183. atoi(sWeek1), atoi(sWeek2) );
  184. }
  185. }
  186. }
  187. bool CDlgDatePlan::CompareStr(CString str1, CString str2,int nSign)
  188. {
  189. bool bResult = false;
  190. if( atoi(str1.Mid(0,2)) == atoi(str2.Mid(0,2)) && atoi(str1.Mid(2,2))+nSign == atoi(str2.Mid(2,2)) )
  191. bResult = true;
  192. if( atoi(str1.Mid(0,2))+nSign == atoi(str2.Mid(0,2)) && atoi(str1.Mid(2,2)) == atoi(str2.Mid(2,2)) )
  193. bResult = true;
  194. return bResult;
  195. }
  196. void CDlgDatePlan::OnBnClickedOk()
  197. {
  198. // TODO: 在此添加控件通知处理程序代码
  199. COleSafeArray l_osaHours;
  200. unsigned char szArray[7][24];
  201. l_osaHours = m_ocxHourSelector.GetHoursArray();
  202. unsigned char cBits;
  203. long m = 0;
  204. // Load the Information from the Grid to an Array
  205. for( int x=0; x<7; x++)
  206. {
  207. for(int y=0; y<24; y++)
  208. {
  209. m = long(x*24+y);
  210. l_osaHours.GetElement(&m, &cBits);
  211. szArray[x][y]= cBits;
  212. }
  213. }
  214. DealArray(szArray);
  215. OnOK();
  216. }
  217. void CDlgDatePlan::OnBnClickedCancel()
  218. {
  219. // TODO: 在此添加控件通知处理程序代码
  220. OnCancel();
  221. }