123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- // DlgUserManager.cpp : 实现文件
- //
- #include "stdafx.h"
- #include "IDE.h"
- #include ".\dlgdateplan.h"
- // CDlgDatePlan 对话框
- IMPLEMENT_DYNAMIC(CDlgDatePlan, CDialog)
- CDlgDatePlan::CDlgDatePlan(CWnd* pParent /*=NULL*/)
- : CDialog(CDlgDatePlan::IDD, pParent)
- {
- m_nPlanType = -1;
- m_strUid = "";
- m_nVarID = 0;
- m_strUserID = "";
- }
- CDlgDatePlan::~CDlgDatePlan()
- {
- }
- void CDlgDatePlan::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- DDX_Control(pDX, IDC_HOURSSELECTOR, m_ocxHourSelector);
- }
- BEGIN_MESSAGE_MAP(CDlgDatePlan, CDialog)
- ON_BN_CLICKED(IDOK, OnBnClickedOk)
- ON_BN_CLICKED(IDCANCEL, OnBnClickedCancel)
- END_MESSAGE_MAP()
- // CDlgDatePlan 消息处理程序
- BOOL CDlgDatePlan::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // TODO: 在此添加额外的初始化
- m_ocxHourSelector.SetFocus();
- COleSafeArray l_osaHours;
- DWORD numElements[] = {168};
- l_osaHours.Create(VT_UI1, 1, numElements);
- unsigned char szArray[7][24];
- long nPoint[1]={0};
- memset(szArray, 0, sizeof(szArray) );
- int nRet;
- return TRUE; // return TRUE unless you set the focus to a control
- // 异常: OCX 属性页应返回 FALSE
- }
- void CDlgDatePlan::DealArray(unsigned char nBuf[7][24])
- {
- CString s,sTemp,str;
- CString sReport[500];
- int nReportIndex = 0;
- for( int y=0; y<7; y++)
- {
- for(int x=0; x<24; x++)
- {
- if(nBuf[y][x] == 15)
- {
- sTemp.Format("%02d%02d",y,x);
- sReport[nReportIndex] = sTemp;
- for(int x1 = x+1; x1<24; x1++)
- {
- if(nBuf[y][x1] == 15)
- {
- sTemp.Format("%02d%02d",y,x1);
- sReport[nReportIndex] += sTemp;
- }
- else
- {
- x = x1;
- break;
- }
- if(nBuf[y][x1] == 15 && x1 == 23)
- {
- x = x1;
- break;
- }
- }
- s.Format("%s",sReport[nReportIndex]);
- //AfxMessageBox(s);
- nReportIndex++;
- str+=s;
- str+="\n";
- }
- }
- }
- int nResultIndex = 0;
- int iSign = 0;
- CString sResult[500];
- bool bFlag[500];
- int i = 0,j = 0;
- for( i=0;i<500;i++ )
- bFlag[i] = true;
- for( i=0;i<nReportIndex;i++ )
- {
- iSign = 1;
- if(bFlag[i])
- {
- sResult[nResultIndex] = sReport[i];
- }
-
- for( j=i+1;j<nReportIndex;j++ )
- {
- if( sReport[i].GetLength() == sReport[j].GetLength() && bFlag[i] && bFlag[j])
- {
- if( CompareStr(sReport[i],sReport[j],iSign) )
- {
- sResult[nResultIndex] += sReport[j];
- bFlag[j] = false;
- iSign++;
- }
- }
- }
- if(bFlag[i])
- {
- bFlag[i] = false;
- nResultIndex++;
- }
- }
- ///////////////////////////////////////////////////////////////////////////
- CString sWeek1,sWeek2,sHour1,sHour2;
- if( m_nPlanType == PLAN_TYPE_USER )
- {
- //CDBInterface::GetInstancePtr()->DeleteDatePlan( m_nPlanType, (char *)(LPCTSTR)m_strUserID );
- }
- else if( m_nPlanType == PLAN_TYPE_EQUIP )
- {
- //CDBInterface::GetInstancePtr()->DeleteDatePlan( m_nPlanType, m_strUid, m_nVarID );
- }
- for( int x=0; x<nResultIndex; x++ )
- {
- sHour1 = sResult[x].Mid(2,2);
- sWeek1 = sResult[x].Mid(0,2);
- sHour2 = sResult[x].Mid(sResult[x].GetLength()-2,2);
- sWeek2 = sResult[x].Mid(sResult[x].GetLength()-4,2);
- if( m_nPlanType == PLAN_TYPE_USER )
- {
- // CDBInterface::GetInstancePtr()->InsertDatePlan( m_nPlanType, (char *)(LPCTSTR)m_strUserID, atoi(sHour1), atoi(sHour2),
- // atoi(sWeek1), atoi(sWeek2) );
- }
- else if( m_nPlanType == PLAN_TYPE_EQUIP )
- {
- // CDBInterface::GetInstancePtr()->InsertDatePlan( m_nPlanType, m_strUid, m_nVarID, atoi(sHour1), atoi(sHour2),
- // atoi(sWeek1), atoi(sWeek2) );
- }
- }
- }
- bool CDlgDatePlan::CompareStr(CString str1, CString str2,int nSign)
- {
- bool bResult = false;
-
- if( atoi(str1.Mid(0,2)) == atoi(str2.Mid(0,2)) && atoi(str1.Mid(2,2))+nSign == atoi(str2.Mid(2,2)) )
- bResult = true;
- if( atoi(str1.Mid(0,2))+nSign == atoi(str2.Mid(0,2)) && atoi(str1.Mid(2,2)) == atoi(str2.Mid(2,2)) )
- bResult = true;
- return bResult;
- }
- void CDlgDatePlan::OnBnClickedOk()
- {
- // TODO: 在此添加控件通知处理程序代码
- if( m_nPlanType == PLAN_TYPE_KG )
- {
- CString s;
- m_sDoSetPlanTime = "";
- COleSafeArray l_osaHours;
- l_osaHours = m_ocxHourSelector.GetHoursArray();
-
- unsigned char cBits;
- long m = 0;
- // Load the Information from the Grid to an Array
- for( int x=0; x<7; x++)
- {
- for(int y=0; y<24; y++)
- {
- m = long(x*24+y);
- l_osaHours.GetElement(&m, &cBits);
-
- s.Format( "%d",cBits==0?0:1 );
- m_sDoSetPlanTime += s;
- }
- }
- }
- else
- {
- COleSafeArray l_osaHours;
- unsigned char szArray[7][24];
- l_osaHours = m_ocxHourSelector.GetHoursArray();
-
- unsigned char cBits;
- long m = 0;
- // Load the Information from the Grid to an Array
- for( int x=0; x<7; x++)
- {
- for(int y=0; y<24; y++)
- {
- m = long(x*24+y);
- l_osaHours.GetElement(&m, &cBits);
- szArray[x][y]= cBits;
- }
- }
- DealArray(szArray);
- }
- OnOK();
- }
- void CDlgDatePlan::OnBnClickedCancel()
- {
- // TODO: 在此添加控件通知处理程序代码
- OnCancel();
- }
|