DlgDatePlan.cpp 4.7 KB

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