Esempio n. 1
0
        private void buttonGetHG_Click(object sender, EventArgs e)
        {
            uint dwCommand = 0;

            string[] strCommand = { "NET_DVR_GET_DOOR_STATUS_HOLIDAY_GROUP", "NET_DVR_GET_VERIFY_HOLIDAY_GROUP", "NET_DVR_GET_CARD_RIGHT_HOLIDAY_GROUP_V50" };

            uint   dwReturned = 0;
            string strTemp    = null;
            uint   dwSize     = (uint)Marshal.SizeOf(m_struGroupCfg);
            IntPtr ptrPlanCfg = Marshal.AllocHGlobal((int)dwSize);

            Marshal.StructureToPtr(m_struGroupCfg, ptrPlanCfg, false);

            switch (comboBoxDeviceTypeHG.SelectedIndex)
            {
            case 0:
            case 1:
                if (comboBoxDeviceTypeHG.SelectedIndex == 0)
                {
                    dwCommand = (uint)CHCNetSDK.NET_DVR_GET_DOOR_STATUS_HOLIDAY_GROUP;
                }
                else
                {
                    dwCommand = (uint)CHCNetSDK.NET_DVR_GET_VERIFY_HOLIDAY_GROUP;
                }

                int holidayGroupNumberHGIndex;
                int.TryParse(textBoxHolidayGroupNumberHG.Text, out holidayGroupNumberHGIndex);

                if (!CHCNetSDK.NET_DVR_GetDVRConfig(m_lUserID, dwCommand, holidayGroupNumberHGIndex, ptrPlanCfg, dwSize, ref dwReturned))
                {
                    Marshal.FreeHGlobal(ptrPlanCfg);
                    strTemp = string.Format("{0} FAIL, ERROR CODE {1}", strCommand[comboBoxDeviceTypeHG.SelectedIndex], CHCNetSDK.NET_DVR_GetLastError());
                    MessageBox.Show(strTemp);
                    return;
                }
                else
                {
                    strTemp = string.Format("{0}", strCommand[comboBoxDeviceTypeHG.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_struGroupCond);
                m_struGroupCond.dwSize = dwConSize;
                IntPtr ptrPlanCon = Marshal.AllocHGlobal((int)dwConSize);
                Marshal.StructureToPtr(m_struGroupCond, ptrPlanCon, false);
                IntPtr ptrDwReturned = Marshal.AllocHGlobal(4);

                // limited input data guarantee parse success
                uint.TryParse(textBoxHolidayGroupNumberHG.Text, out m_struGroupCond.dwHolidayGroupNumber);
                ushort.TryParse(textBoxLocalControllerID.Text, out m_struGroupCond.wLocalControllerID);


                if (!CHCNetSDK.NET_DVR_GetDeviceConfig(m_lUserID, dwCommand, 1, ptrPlanCon, dwConSize, ptrDwReturned, ptrPlanCfg, dwSize))
                {
                    Marshal.FreeHGlobal(ptrPlanCfg);
                    Marshal.FreeHGlobal(ptrPlanCon);
                    Marshal.FreeHGlobal(ptrDwReturned);
                    strTemp = string.Format("{0} FAIL, ERROR CODE {1}", strCommand[comboBoxDeviceTypeHG.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[comboBoxDeviceTypeHG.SelectedIndex]);
                    g_formList.AddLog(m_lUserID, AcsDemoPublic.OPERATION_SUCC_T, strTemp);
                }

                break;

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

            m_struGroupCfg = (CHCNetSDK.NET_DVR_HOLIDAY_GROUP_CFG)Marshal.PtrToStructure(ptrPlanCfg, typeof(CHCNetSDK.NET_DVR_HOLIDAY_GROUP_CFG));

            if (1 == m_struGroupCfg.byEnable)
            {
                checkBoxEnableHG.Checked = true;
            }
            else
            {
                checkBoxEnableHG.Checked = false;
            }

            textBoxHolidayGroupNameHG.Text = System.Text.Encoding.UTF8.GetString(m_struGroupCfg.byGroupName);

            UpdateLstGroupNo();

            Marshal.FreeHGlobal(ptrPlanCfg);
        }
Esempio n. 2
0
        private void btnGetTemplate_Click(object sender, EventArgs e)
        {
            uint dwCommand = 0;

            string[] strCommand = { "NET_DVR_GET_CARD_RIGHT_HOLIDAY_GROUP_V50", "NET_DVR_GET_VERIFY_HOLIDAY_GROUP", "NET_DVR_GET_DOOR_STATUS_HOLIDAY_GROUP" };

            uint   dwReturned = 0;
            string strTemp    = null;
            uint   dwSize     = (uint)Marshal.SizeOf(m_struGroupCfg);
            IntPtr ptrPlanCfg = Marshal.AllocHGlobal((int)dwSize);

            Marshal.StructureToPtr(m_struGroupCfg, ptrPlanCfg, false);

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

                int holidayGroupNumberHGIndex;
                int.TryParse(textBoxHGNumber.Text, out holidayGroupNumberHGIndex);

                if (!CHCNetSDK.NET_DVR_GetDVRConfig(m_lUserID, dwCommand, holidayGroupNumberHGIndex, ptrPlanCfg, dwSize, ref dwReturned))
                {
                    Marshal.FreeHGlobal(ptrPlanCfg);
                    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_GROUP_V50;
                uint dwConSize = (uint)Marshal.SizeOf(m_struGroupCond);
                m_struGroupCond.dwSize = dwConSize;
                // limited input data guarantee parse success
                uint.TryParse(textBoxHGNumber.Text, out m_struGroupCond.dwHolidayGroupNumber);
                ushort.TryParse(textBoxLocalControllerID.Text, out m_struGroupCond.wLocalControllerID);

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

                if (!CHCNetSDK.NET_DVR_GetDeviceConfig(m_lUserID, dwCommand, 1, ptrPlanCon, dwConSize, ptrDwReturned, ptrPlanCfg, dwSize))
                {
                    Marshal.FreeHGlobal(ptrPlanCfg);
                    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(ptrPlanCfg);
                MessageBox.Show("unknown command");
                return;
            }

            m_struGroupCfg = (CHCNetSDK.NET_DVR_HOLIDAY_GROUP_CFG)Marshal.PtrToStructure(ptrPlanCfg, typeof(CHCNetSDK.NET_DVR_HOLIDAY_GROUP_CFG));

            if (1 == m_struGroupCfg.byEnable)
            {
                checkBoxEnableHG.Checked = true;
            }
            else
            {
                checkBoxEnableHG.Checked = false;
            }

            Encoding ec = System.Text.Encoding.GetEncoding("gb2312");

            //textBoxHolidayGroupNameHG.Text
            //var byteToString4 = System.Text.Encoding.ASCII.GetString(m_struGroupCfg.byGroupName);
            textBoxHGName.Text = ec.GetString(m_struGroupCfg.byGroupName);
            // Console.WriteLine(byteToString4);

            UpdateListGroupNo();

            Marshal.FreeHGlobal(ptrPlanCfg);
        }