Пример #1
0
        private void listViewTimeSegment_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
        {
            iItemIndex = e.ItemIndex;
            if (iItemIndex < 0)
            {
                return;
            }
            int iDate = cbDate.SelectedIndex;
            int i     = iDate * CHCNetSDK.MAX_TIMESEGMENT_V30 + iItemIndex;

            if (1 == m_struPlanCfg.struPlanCfg[i].byEnable)
            {
                checkBoxEnableTime.Checked = true;
            }
            else
            {
                checkBoxEnableTime.Checked = false;
            }
            cbVerifyMode.SelectedIndex    = (int)m_struPlanCfg.struPlanCfg[i].byVerifyMode;
            cbDoorStateMode.SelectedIndex = (int)m_struPlanCfg.struPlanCfg[i].byDoorStatus;
            CHCNetSDK.NET_DVR_SIMPLE_DAYTIME struTime = new CHCNetSDK.NET_DVR_SIMPLE_DAYTIME();
            if (AcsDemoPublic.CheckDate(m_struPlanCfg.struPlanCfg[i].struTimeSegment.struBeginTime))
            {
                struTime = m_struPlanCfg.struPlanCfg[i].struTimeSegment.struBeginTime;
                if (struTime.byHour == 24 && struTime.byMinute == 0 && struTime.bySecond == 0)
                {
                    struTime.byHour   = 23;
                    struTime.byMinute = 59;
                    struTime.bySecond = 59;
                }
                dTPStartTime.Value = new System.DateTime(dTPStartTime.Value.Year,
                                                         dTPStartTime.Value.Month, dTPStartTime.Value.Day, struTime.byHour,
                                                         struTime.byMinute, struTime.bySecond);
            }
            if (AcsDemoPublic.CheckDate(m_struPlanCfg.struPlanCfg[i].struTimeSegment.struEndTime))
            {
                struTime = m_struPlanCfg.struPlanCfg[i].struTimeSegment.struEndTime;
                if (struTime.byHour == 24 && struTime.byMinute == 0 && struTime.bySecond == 0)
                {
                    struTime.byHour   = 23;
                    struTime.byMinute = 59;
                    struTime.bySecond = 59;
                }
                dTPEndTime.Value = new System.DateTime(dTPEndTime.Value.Year,
                                                       dTPEndTime.Value.Month, dTPEndTime.Value.Day, struTime.byHour,
                                                       struTime.byMinute, struTime.bySecond);
            }
        }
Пример #2
0
        private void btnGet_Click(object sender, EventArgs e)
        {
            uint dwCommand = 0;

            string[] strCommand = { "NET_DVR_GET_CARD_RIGHT_HOLIDAY_PLAN_V50", "NET_DVR_GET_VERIFY_HOLIDAY_PLAN", "NET_DVR_GET_DOOR_STATUS_HOLIDAY_PLAN" };

            uint   dwReturned = 0;
            string strTemp    = null;
            uint   dwSize     = (uint)Marshal.SizeOf(m_struPlanCfgH);

            m_struPlanCfgH.dwSize = dwSize;
            IntPtr ptrPlanCfgH = Marshal.AllocHGlobal((int)dwSize);

            Marshal.StructureToPtr(m_struPlanCfgH, ptrPlanCfgH, false);

            switch (cbDeviceType.SelectedIndex)
            {
            case 1:
            case 2:
                if (cbDeviceType.SelectedIndex == 2)
                {
                    dwCommand = (uint)CHCNetSDK.NET_DVR_GET_DOOR_STATUS_HOLIDAY_PLAN;
                }
                else
                {
                    dwCommand = (uint)CHCNetSDK.NET_DVR_GET_VERIFY_HOLIDAY_PLAN;
                }

                int holidayPlanNumberIndex;
                int.TryParse(textBoxHPNumber.Text, out holidayPlanNumberIndex);

                if (!CHCNetSDK.NET_DVR_GetDVRConfig(m_lUserID, dwCommand, holidayPlanNumberIndex, ptrPlanCfgH, dwSize, ref dwReturned))
                {
                    Marshal.FreeHGlobal(ptrPlanCfgH);
                    strTemp = string.Format("{0} FAIL, ERROR CODE {1}", strCommand[cbDeviceType.SelectedIndex], CHCNetSDK.NET_DVR_GetLastError());
                    MessageBox.Show(strTemp);
                    return;
                }
                else
                {
                    strTemp = string.Format("{0} Succ", strCommand[cbDeviceType.SelectedIndex]);
                    MessageBox.Show(strTemp);
                }

                break;

            case 0:
                dwCommand = (uint)CHCNetSDK.NET_DVR_GET_CARD_RIGHT_HOLIDAY_PLAN_V50;
                uint dwConSize = (uint)Marshal.SizeOf(m_struPlanCond);
                m_struPlanCond.dwSize = dwConSize;
                // limited input data guarantee parse success
                uint.TryParse(textBoxHPNumber.Text, out m_struPlanCond.dwHolidayPlanNumber);
                ushort.TryParse(textBoxLCID.Text, out m_struPlanCond.wLocalControllerID);

                IntPtr ptrPlanCon = Marshal.AllocHGlobal((int)dwConSize);
                Marshal.StructureToPtr(m_struPlanCond, ptrPlanCon, false);
                IntPtr ptrDwReturned = Marshal.AllocHGlobal(4);

                if (!CHCNetSDK.NET_DVR_GetDeviceConfig(m_lUserID, dwCommand, 1, ptrPlanCon, dwConSize, ptrDwReturned, ptrPlanCfgH, dwSize))
                {
                    Marshal.FreeHGlobal(ptrPlanCfgH);
                    Marshal.FreeHGlobal(ptrPlanCon);
                    Marshal.FreeHGlobal(ptrDwReturned);
                    strTemp = string.Format("{0} FAIL, ERROR CODE {1}", strCommand[cbDeviceType.SelectedIndex], CHCNetSDK.NET_DVR_GetLastError());
                    MessageBox.Show(strTemp);
                    return;
                }
                else
                {
                    dwReturned = (uint)Marshal.ReadInt32(ptrDwReturned);
                    Marshal.FreeHGlobal(ptrDwReturned);
                    Marshal.FreeHGlobal(ptrPlanCon);
                    strTemp = string.Format("{0} Succ", strCommand[cbDeviceType.SelectedIndex]);
                    MessageBox.Show(strTemp);
                }

                break;

            default:
                Marshal.FreeHGlobal(ptrPlanCfgH);
                MessageBox.Show("unknown command");
                return;
            }

            m_struPlanCfgH = (CHCNetSDK.NET_DVR_HOLIDAY_PLAN_CFG)Marshal.PtrToStructure(ptrPlanCfgH, typeof(CHCNetSDK.NET_DVR_HOLIDAY_PLAN_CFG));

            UpdateList();

            if (1 == m_struPlanCfgH.byEnable)
            {
                checkBoxEnableHP.Checked = true;
            }
            else
            {
                checkBoxEnableHP.Checked = false;
            }

            if (!AcsDemoPublic.CheckState(m_struPlanCfgH.struBeginDate) || !AcsDemoPublic.CheckState(m_struPlanCfgH.struEndDate))
            {
                Marshal.FreeHGlobal(ptrPlanCfgH);
                return;
            }

            // set the date
            dTPStartTime.Value = new System.DateTime(m_struPlanCfgH.struBeginDate.wYear, m_struPlanCfgH.struBeginDate.byMonth, m_struPlanCfgH.struBeginDate.byDay);
            dTPEndTime.Value   = new System.DateTime(m_struPlanCfgH.struEndDate.wYear, m_struPlanCfgH.struEndDate.byMonth, m_struPlanCfgH.struEndDate.byDay);

            Marshal.FreeHGlobal(ptrPlanCfgH);
        }