Esempio n. 1
0
        /// <summary>
        /// 依据容器控件中的对应映射控件,向远程设备请求对应的已配置参数;
        /// </summary>
        /// <param name="ownerPage">容器控件;</param>
        /// <param name="channelNum">参数所属通道号;</param>
        /// <param name="paraList">请求参数列表;</param>
        public void GetQueryParaList(Control ownerPage, int channelNum, IntPtr paraList)
        {
            //遍历容器控件,通过控件名与设备参数间的映射关系,生成向远程设备请求配置参数值的参数列表;
            foreach (Control control in ownerPage.Controls)
            {
                //控件不使能则不需要请求参数(包括其下所有子控件)
                if ((control.Enabled == false))
                {
                    continue;
                }

                //控件为非叶节点控件,则使用递归继续向下遍历;
                if (control.Controls.Count != 0)
                {
                    GetQueryParaList(control, channelNum, paraList);
                }

                //使用control.AccessibleName来标识参与映射的控件;
                //可依据需求修改为其他标识;
                if (control.AccessibleName != null)
                {
                    bool isFind;

                    DevControl.PARA_TYPES paraType = DevControl.PARA_TYPES.END_OF_PARA_TYPES;
                    isFind = this._propertyParaMap.FindParaByProperty(control.AccessibleName, ref paraType);
                    if (isFind == true)
                    {
                        DevControl.paralist_addnode(paraList, channelNum, paraType);
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 从容器控件中读取已加入映射表的子控件的输入值;
        /// </summary>
        /// <param name="ownerPage">容器控件;</param>
        /// <param name="channelNum">参数所属通道号;</param>
        /// <param name="paraList">IntPtr(paralist);</param>
        /// <returns>DevControl.tagErrorCode</returns>
        private DevControl.tagErrorCode GetParameterFromProperty(Control ownerPage, int channelNum, IntPtr paraList)
        {
            IntPtr setParaList = paraList;

            DevControl.tagErrorCode eCode = DevControl.tagErrorCode.DM_ERR_OK;

            Debug.Assert(ownerPage != null);
            Debug.Assert(paraList != IntPtr.Zero);

            //遍历容器控件,通过控件名与设备参数间的映射关系,从配置界面的控件中读取配置设备的参数;
            foreach (Control control in ownerPage.Controls)
            {
                //控件不使能则不需要填充数值(包括其下所有子控件)
                if ((control.Enabled == false))
                {
                    continue;
                }

                //控件为非叶节点控件,则使用递归继续向下遍历;
                if (control.Controls.Count != 0)
                {
                    eCode = GetParameterFromProperty(control, channelNum, paraList);
                    if (eCode != DevControl.tagErrorCode.DM_ERR_OK)
                    {
                        break;
                    }
                }

                //使用control.AccessibleName来标识参与映射的控件;
                //可依据需求修改为其他标识;
                if (control.AccessibleName != null)
                {
                    bool isFind;

                    //查找控件映射的PARA_TYPES
                    DevControl.PARA_TYPES paraType = DevControl.PARA_TYPES.END_OF_PARA_TYPES;
                    isFind = this._propertyParaMap.FindParaByProperty(control.AccessibleName, ref paraType);
                    if (isFind == true)
                    {
                        //依据控件类型,从控件中读取输入参数值,按字符串格式读取;
                        StringBuilder bufferString = new StringBuilder();

                        Type controlType = control.GetType();
                        if (controlType == typeof(System.Windows.Forms.TextBox))
                        {
                            if (((System.Windows.Forms.TextBox)control).ReadOnly == true)
                            {
                                continue;
                            }

                            bufferString.Append(((System.Windows.Forms.TextBox)control).Text.Trim());
                        }
                        else if (controlType == typeof(System.Windows.Forms.CheckBox))
                        {
                            if (((System.Windows.Forms.CheckBox)control).Checked)
                            {
                                bufferString.Append('1');
                            }
                            else
                            {
                                bufferString.Append('0');
                            }
                        }
                        else if (controlType == typeof(System.Windows.Forms.ComboBox))
                        {
                            bufferString.Append(((System.Windows.Forms.ComboBox)control).SelectedIndex.ToString());
                        }
                        else if (controlType == typeof(System.Windows.Forms.NumericUpDown))
                        {
                            bufferString.Append(((System.Windows.Forms.NumericUpDown)control).Value.ToString());
                        }
                        else
                        {
                            Debug.Fail("must support new controlType!");
                            continue;
                        }

                        //将读取的字符串格式输入参数值转换为操作接口输入类型,然后检查输入参数的合法性,合法则加入参数列表;
                        byte[] valueBuf = new byte[100];
                        int    valueLen = valueBuf.Length;
                        eCode = DevControl.DM_String2Value(paraType, bufferString, bufferString.Length, valueBuf, ref valueLen);
                        if (eCode == DevControl.tagErrorCode.DM_ERR_OK)
                        {
                            eCode = DevControl.DM_CheckPara(this._devHandle, channelNum, paraType, valueLen, valueBuf);
                            if (eCode == DevControl.tagErrorCode.DM_ERR_OK)
                            {
                                DevControl.paralist_addnode(setParaList, channelNum, paraType, valueLen, valueBuf);
                            }
                            else
                            {
                                break;
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }

            return(eCode);
        }