コード例 #1
0
        public void BindData(bool bReset)
        {
            if (Function.IsEmpty(strSysIniFile) || Function.IsEmpty(strUserIniFile))
            {
                return;
            }
            int    itemCount;
            string strValueTemp;
            string strDefValue;
            int    pos;

            string[]  valueTemp;        //配置值的集合
            string[]  valueList;        //最大、最小或下拉选项
            ConfigMsg configMsg;        //TreeList第一层节点
            ConfigMsg configMsgItem;    //TreeList第二层节点

            configMsgs.Clear();

            foreach (string nodeName in nodeNames)
            {
                configMsg             = new ConfigMsg();
                configMsg.ConfigName  = nodeName;
                configMsg.ConfigDesc  = Function.ProfileString(strSysIniFile, nodeName, "desc", "");
                configMsg.ConfigValue = Function.ProfileString(strSysIniFile, nodeName, "count", "");
                configMsg.ConfigType  = "G";            //把类型设置为“G”

                try
                {
                    itemCount = int.Parse(configMsg.ConfigValue.ToString());
                }
                catch { itemCount = 0; }
                configMsg.ConfigValue = itemCount.ToString() + "项";

                //添加配置项
                for (int j = 1; j <= itemCount; j++)
                {
                    strDefValue  = "";
                    strValueTemp = Function.ProfileString(strSysIniFile, nodeName, j.ToString(), "");
                    valueTemp    = strValueTemp.Split(new char[] { ',' });
                    if (valueTemp.Length < 2)
                    {
                        continue;
                    }

                    configMsgItem            = new ConfigMsg();
                    configMsgItem.ConfigDesc = valueTemp[0];
                    configMsgItem.ConfigName = valueTemp[0];

                    pos = valueTemp[1].IndexOf('(');
                    if (pos > 0)
                    {
                        configMsgItem.ConfigType = valueTemp[1].Substring(0, pos);
                        strDefValue = valueTemp[1].Substring(pos + 1, valueTemp[1].Length - 3);
                    }
                    else
                    {
                        configMsgItem.ConfigType = valueTemp[1];    //配置值类型
                    }

                    if (!bReset && Function.ProfileString(strUserIniFile, nodeName, configMsgItem.ConfigName, "") != "")
                    {
                        configMsgItem.ConfigValue = Function.ProfileString(strUserIniFile, nodeName, configMsgItem.ConfigName, "");
                    }
                    else
                    {
                        configMsgItem.ConfigValue = strDefValue;
                    }
                    //新标注
                    //处理Type为N(数字最大值、最小值)、L(下拉项)的项
                    if (valueTemp.Length > 2 && (configMsgItem.ConfigType == "N" || configMsgItem.ConfigType == "L" || configMsgItem.ConfigType == "C"))
                    {
                        valueList = new string[valueTemp.Length - 2];
                        for (int k = 0; k < valueList.Length; k++)
                        {
                            valueList[k] = valueTemp[2 + k];
                        }
                        configMsgItem.ConfigValueList = valueList;
                    }

                    if (configMsgItem.ConfigType == "R")
                    {
                        try
                        {
                            configMsgItem.ConfigValue = Convert.ToBoolean(configMsgItem.ConfigValue);
                        }
                        catch { configMsgItem.ConfigValue = false; }
                    }

                    if (configMsgItem.ConfigType == "C")
                    {
                        configMsgItem.ConfigValue = (configMsgItem.ConfigValue as string).Replace(";", ",");
                    }

                    configMsg.ConfigMsgs.Add(configMsgItem);
                }

                configMsgs.Add(configMsg);
            }
            this.treeList1.Nodes.Clear();
            if (configMsgs.Count == 1)
            {
                this.treeList1.DataSource = configMsgs[0].ConfigMsgs;
            }
            else
            {
                this.treeList1.DataSource = configMsgs;
            }
            this.treeList1.RefreshDataSource();
        }
コード例 #2
0
        private void treeList1_GetCustomNodeCellEdit(object sender, GetCustomNodeCellEditEventArgs e)
        {
            if (e.Column.FieldName != "ConfigValue")
            {
                return;
            }
            ConfigMsg configItem = treeList1.GetDataRecordByNode(e.Node) as ConfigMsg;

            if (configItem == null)
            {
                return;
            }

            switch (configItem.ConfigType)
            {
            case "R":
                e.RepositoryItem = this.repositoryItemCheckEdit1;
                break;

            case "G":
                e.RepositoryItem = this.repositoryItemTextEdit1;
                break;

            case "C":
                e.RepositoryItem = this.repositoryItemColorEdit1;
                break;

            case "D":
                e.RepositoryItem = this.repositoryItemDateEdit1;
                break;

            case "L":
                this.repositoryItemComboBox1 = new RepositoryItemComboBox();
                this.repositoryItemComboBox1.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;
                this.repositoryItemComboBox1.Items.AddRange(configItem.ConfigValueList);
                e.RepositoryItem = this.repositoryItemComboBox1;
                break;

            case "N":
                this.repositoryItemSpinEdit1 = new RepositoryItemSpinEdit();
                this.repositoryItemSpinEdit1.IsFloatValue = false;
                if (configItem.ConfigValueList.Length >= 1)     //长度为1有最小值项
                {
                    if (!Function.IsEmpty(configItem.ConfigValueList[0]) && Function.IsNumber(configItem.ConfigValueList[0]))
                    {
                        this.repositoryItemSpinEdit1.MinValue = decimal.Parse(configItem.ConfigValueList[0]);
                    }
                    else
                    {
                        this.repositoryItemSpinEdit1.MinValue = decimal.MinValue;
                    }
                }
                if (configItem.ConfigValueList.Length == 2)
                {
                    if (!Function.IsEmpty(configItem.ConfigValueList[1]) && Function.IsNumber(configItem.ConfigValueList[1]))
                    {
                        this.repositoryItemSpinEdit1.MaxValue = decimal.Parse(configItem.ConfigValueList[1]);
                    }
                    else
                    {
                        this.repositoryItemSpinEdit1.MaxValue = decimal.MaxValue;
                    }
                }
                e.RepositoryItem = this.repositoryItemSpinEdit1;
                break;
            }
        }