Пример #1
0
        private void buttonGet_Click(object sender, EventArgs e)
        {
            uint dwCommand = 0;

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

            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 (comboBoxDeviceType.SelectedIndex)
            {
            case 0:
            case 1:
                if (comboBoxDeviceType.SelectedIndex == 0)
                {
                    dwCommand = (uint)CHCNetSDK.NET_DVR_GET_DOOR_STATUS_HOLIDAY_PLAN;
                }
                else
                {
                    dwCommand = (uint)CHCNetSDK.NET_DVR_GET_VERIFY_HOLIDAY_PLAN;
                }

                int holidayPlanNumberIndex;
                int.TryParse(textBoxHolidayPlanNumber.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[comboBoxDeviceType.SelectedIndex], CHCNetSDK.NET_DVR_GetLastError());
                    MessageBox.Show(strTemp);
                    return;
                }
                else
                {
                    strTemp = string.Format("{0}", strCommand[comboBoxDeviceType.SelectedIndex]);
                    g_formList.AddLog(m_lUserID, AcsDemoPublic.OPERATION_SUCC_T, strTemp);
                }

                break;

            case 2:
                dwCommand = (uint)CHCNetSDK.NET_DVR_GET_CARD_RIGHT_HOLIDAY_PLAN_V50;
                uint dwConSize = (uint)Marshal.SizeOf(m_struPlanCond);
                m_struPlanCond.dwSize = dwConSize;
                IntPtr ptrPlanCon = Marshal.AllocHGlobal((int)dwConSize);
                Marshal.StructureToPtr(m_struPlanCond, ptrPlanCon, false);
                IntPtr ptrDwReturned = Marshal.AllocHGlobal(4);

                // limited input data guarantee parse success
                uint.TryParse(textBoxHolidayPlanNumber.Text, out m_struPlanCond.dwHolidayPlanNumber);
                ushort.TryParse(textBoxLocalControllerID.Text, out m_struPlanCond.wLocalControllerID);


                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[comboBoxDeviceType.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}", strCommand[comboBoxDeviceType.SelectedIndex]);
                    g_formList.AddLog(m_lUserID, AcsDemoPublic.OPERATION_SUCC_T, 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)
            {
                checkBoxEnablePlan.Checked = true;
            }
            else
            {
                checkBoxEnablePlan.Checked = false;
            }

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

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

            Marshal.FreeHGlobal(ptrPlanCfgH);
        }