DlgDatePlan.cpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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. else if( m_nPlanType == PLAN_TYPE_KG )
  85. {
  86. if( m_sDoSetPlanTime=="" )
  87. {
  88. for( int x=0; x<7; x++)
  89. {
  90. for(int y=0; y<24; y++)
  91. {
  92. int nTemp = 15;
  93. l_osaHours.PutElement(nPoint, &nTemp);
  94. nPoint[0]++;
  95. }
  96. }
  97. }
  98. else
  99. {
  100. for( int i=0; i<m_sDoSetPlanTime.GetLength(); i++)
  101. {
  102. int x = i/24;
  103. int y = i%24;
  104. int nData=0;
  105. if( m_sDoSetPlanTime[i]=='1' )
  106. nData = 15;
  107. l_osaHours.PutElement(nPoint, &nData);
  108. nPoint[0]++;
  109. }
  110. }
  111. }
  112. m_ocxHourSelector.SetHoursArray(l_osaHours);
  113. return TRUE; // return TRUE unless you set the focus to a control
  114. // 异常: OCX 属性页应返回 FALSE
  115. }
  116. void CDlgDatePlan::DealArray(unsigned char nBuf[7][24])
  117. {
  118. CString s,sTemp,str;
  119. CString sReport[500];
  120. int nReportIndex = 0;
  121. for( int y=0; y<7; y++)
  122. {
  123. for(int x=0; x<24; x++)
  124. {
  125. if(nBuf[y][x] == 15)
  126. {
  127. sTemp.Format("%02d%02d",y,x);
  128. sReport[nReportIndex] = sTemp;
  129. for(int x1 = x+1; x1<24; x1++)
  130. {
  131. if(nBuf[y][x1] == 15)
  132. {
  133. sTemp.Format("%02d%02d",y,x1);
  134. sReport[nReportIndex] += sTemp;
  135. }
  136. else
  137. {
  138. x = x1;
  139. break;
  140. }
  141. if(nBuf[y][x1] == 15 && x1 == 23)
  142. {
  143. x = x1;
  144. break;
  145. }
  146. }
  147. s.Format("%s",sReport[nReportIndex]);
  148. //AfxMessageBox(s);
  149. nReportIndex++;
  150. str+=s;
  151. str+="\n";
  152. }
  153. }
  154. }
  155. int nResultIndex = 0;
  156. int iSign = 0;
  157. CString sResult[500];
  158. bool bFlag[500];
  159. int i = 0,j = 0;
  160. for( i=0;i<500;i++ )
  161. bFlag[i] = true;
  162. for( i=0;i<nReportIndex;i++ )
  163. {
  164. iSign = 1;
  165. if(bFlag[i])
  166. {
  167. sResult[nResultIndex] = sReport[i];
  168. }
  169. for( j=i+1;j<nReportIndex;j++ )
  170. {
  171. if( sReport[i].GetLength() == sReport[j].GetLength() && bFlag[i] && bFlag[j])
  172. {
  173. if( CompareStr(sReport[i],sReport[j],iSign) )
  174. {
  175. sResult[nResultIndex] += sReport[j];
  176. bFlag[j] = false;
  177. iSign++;
  178. }
  179. }
  180. }
  181. if(bFlag[i])
  182. {
  183. bFlag[i] = false;
  184. nResultIndex++;
  185. }
  186. }
  187. ///////////////////////////////////////////////////////////////////////////
  188. CString sWeek1,sWeek2,sHour1,sHour2;
  189. if( m_nPlanType == PLAN_TYPE_USER )
  190. {
  191. CDBInterface::GetInstancePtr()->DeleteDatePlan( m_nPlanType, (char *)(LPCTSTR)m_strUserID );
  192. }
  193. else if( m_nPlanType == PLAN_TYPE_EQUIP )
  194. {
  195. CDBInterface::GetInstancePtr()->DeleteDatePlan( m_nPlanType, m_strUid, m_nVarID );
  196. }
  197. for( int x=0; x<nResultIndex; x++ )
  198. {
  199. sHour1 = sResult[x].Mid(2,2);
  200. sWeek1 = sResult[x].Mid(0,2);
  201. sHour2 = sResult[x].Mid(sResult[x].GetLength()-2,2);
  202. sWeek2 = sResult[x].Mid(sResult[x].GetLength()-4,2);
  203. if( m_nPlanType == PLAN_TYPE_USER )
  204. {
  205. CDBInterface::GetInstancePtr()->InsertDatePlan( m_nPlanType, (char *)(LPCTSTR)m_strUserID, atoi(sHour1), atoi(sHour2),
  206. atoi(sWeek1), atoi(sWeek2) );
  207. }
  208. else if( m_nPlanType == PLAN_TYPE_EQUIP )
  209. {
  210. CDBInterface::GetInstancePtr()->InsertDatePlan( m_nPlanType, m_strUid, m_nVarID, atoi(sHour1), atoi(sHour2),
  211. atoi(sWeek1), atoi(sWeek2) );
  212. }
  213. }
  214. }
  215. bool CDlgDatePlan::CompareStr(CString str1, CString str2,int nSign)
  216. {
  217. bool bResult = false;
  218. if( atoi(str1.Mid(0,2)) == atoi(str2.Mid(0,2)) && atoi(str1.Mid(2,2))+nSign == atoi(str2.Mid(2,2)) )
  219. bResult = true;
  220. if( atoi(str1.Mid(0,2))+nSign == atoi(str2.Mid(0,2)) && atoi(str1.Mid(2,2)) == atoi(str2.Mid(2,2)) )
  221. bResult = true;
  222. return bResult;
  223. }
  224. void CDlgDatePlan::OnBnClickedOk()
  225. {
  226. // TODO: 在此添加控件通知处理程序代码
  227. if( m_nPlanType == PLAN_TYPE_KG )
  228. {
  229. CString s;
  230. m_sDoSetPlanTime = "";
  231. COleSafeArray l_osaHours;
  232. l_osaHours = m_ocxHourSelector.GetHoursArray();
  233. unsigned char cBits;
  234. long m = 0;
  235. // Load the Information from the Grid to an Array
  236. for( int x=0; x<7; x++)
  237. {
  238. for(int y=0; y<24; y++)
  239. {
  240. m = long(x*24+y);
  241. l_osaHours.GetElement(&m, &cBits);
  242. s.Format( "%d",cBits==0?0:1 );
  243. m_sDoSetPlanTime += s;
  244. }
  245. }
  246. }
  247. else
  248. {
  249. COleSafeArray l_osaHours;
  250. unsigned char szArray[7][24];
  251. l_osaHours = m_ocxHourSelector.GetHoursArray();
  252. unsigned char cBits;
  253. long m = 0;
  254. // Load the Information from the Grid to an Array
  255. for( int x=0; x<7; x++)
  256. {
  257. for(int y=0; y<24; y++)
  258. {
  259. m = long(x*24+y);
  260. l_osaHours.GetElement(&m, &cBits);
  261. szArray[x][y]= cBits;
  262. }
  263. }
  264. DealArray(szArray);
  265. }
  266. OnOK();
  267. }
  268. void CDlgDatePlan::OnBnClickedCancel()
  269. {
  270. // TODO: 在此添加控件通知处理程序代码
  271. OnCancel();
  272. }