예제 #1
0
        /// <summary>
        /// 创建Stim控件基类,用于设计界面
        /// </summary>
        /// <param name="control"></param>
        /// <param name="objAttribute"></param>
        /// <returns></returns>
        private StimControl CreateStimBasic(Control control, Object objAttribute, Object objValue)
        {
            StimControl stimControl = null;

            //根据XML生成控件
            if (objAttribute.GetType().Name.Equals("XElement"))
            {
                XElement xElement = (XElement)objAttribute;
                //解决数据源
                List <TxtValObject> TempDataSource = null;
                string datasource = getXElementAttributeValue(xElement.Element("DataRule"), "DataSource", "");
                if (!string.IsNullOrEmpty(datasource))
                {
                    var json = new JavaScriptSerializer();
                    TempDataSource = json.Deserialize <List <TxtValObject> >(datasource) as List <TxtValObject>;
                }
                //解决窗体数据源
                PropertyGrid.Select.ValueObject TempDataObject = null;
                string TempDataObjectStr = getXElementAttributeValue(xElement.Element("FrmData"), "object", "");
                if (!string.IsNullOrEmpty(TempDataObjectStr))
                {
                    var json = new JavaScriptSerializer();
                    TempDataObject = json.Deserialize <PropertyGrid.Select.ValueObject>(TempDataObjectStr) as PropertyGrid.Select.ValueObject;
                }
                //解决验证规则
                PropertyGrid.CheckValueObject TempRegular = null;
                string RegularStr = getXElementAttributeValue(xElement.Element("DataRule"), "Regular", "");
                if (!string.IsNullOrEmpty(RegularStr))
                {
                    var json = new JavaScriptSerializer();
                    TempRegular = json.Deserialize <PropertyGrid.CheckValueObject>(RegularStr) as PropertyGrid.CheckValueObject;
                }
                //解决默认值
                PropertyGrid.ValueObject TempValueDialog = null;
                string valueDialogStr = getXElementAttributeValue(xElement.Element("DataControl"), "Value", "");
                if (!string.IsNullOrEmpty(valueDialogStr))
                {
                    var json = new JavaScriptSerializer();
                    TempValueDialog = json.Deserialize <PropertyGrid.ValueObject>(valueDialogStr) as PropertyGrid.ValueObject;
                }
                stimControl = new StimControl(control)
                {
                    objValue = objValue,
                    Name     = getXElementAttributeValue(xElement, "Column_Name", ""),
                    Location = new Point(int.Parse(getXElementAttributeValue(xElement, "X", "0")), int.Parse(getXElementAttributeValue(xElement, "Y", "0"))),
                    Width    = int.Parse(getXElementAttributeValue(xElement, "W", "250")),
                    Height   = int.Parse(getXElementAttributeValue(xElement, "H", "29")),
                    //Visible = (bool)xElement.Attribute("Visible"),
                    //Enabled = (bool)xElement.Attribute("Enabled"),
                    //TLP={CellBorderStyle=TableLayoutPanelCellBorderStyle.None},
                    property =
                    {
                        Name              = getXElementAttributeValue(xElement,                                                                                  "Column_Name",       ""),
                        Text              = xElement.Element("Lable").Value != "" ? xElement.Element("Lable").Value : (string)xElement.Attribute("Column_Name"),
                        ColumnWidth       = int.Parse(getXElementAttributeValue(xElement,                                                                        "CW",                "80")),
                        TabIndex          = int.Parse(getXElementAttributeValue(xElement,                                                                        "TabIndex",          "0")),
                        ControlType       = int.Parse(getXElementAttributeValue(xElement,                                                                        "ControlType",       "0")),
                        ControlVisible    = getXElementAttributeValue(xElement,                                                                                  "Visible",           "True").Equals("True")?1:0,
                        ControlEnable     = getXElementAttributeValue(xElement,                                                                                  "Enabled",           "True").Equals("True")?1:0,
                        ControlRequired   = getXElementAttributeValue(xElement,                                                                                  "Required",          "True").Equals("True") ? 1 : 0,
                        ListConditionFlag = getXElementAttributeValue(xElement,                                                                                  "ListConditionFlag", "True").Equals("True") ? 1 : 0,
                        ListShowFlag      = getXElementAttributeValue(xElement,                                                                                  "ListShowFlag",      "True").Equals("True") ? 1 : 0,
                        ControlDataSource = TempDataSource,
                        FrmDataObject     = TempDataObject,
                        Value             = TempValueDialog,
                        CheckRegular      = TempRegular
                    },
                    lblFile =
                    {
                        Text = xElement.Element("Lable").Value != "" ? xElement.Element("Lable").Value : getXElementAttributeValue(xElement, "Column_Name", ""),
                    },
                    DataFile =
                    {
                        Enabled = getXElementAttributeValue(xElement.Element("DataControl"), "Enabled", "True").Equals("True"),
                        Visible = getXElementAttributeValue(xElement.Element("DataControl"), "Visible", "True").Equals("True")
                    }
                };
            }
            //根据DataRow生成控件
            if (objAttribute.GetType().Name.Equals("DataRow"))
            {
                DataRow row = (DataRow)objAttribute;
                stimControl = new StimControl(control)
                {
                    Name     = (string)row["Column_Name"],
                    property =
                    {
                        Text = (string)row["Column_Name"],
                    },
                    //TLP={CellBorderStyle=TableLayoutPanelCellBorderStyle.None},
                    lblFile  = { Text = (string)row["Column_Name"] },// row["COMMENTS"] + ":";
                    DataFile =
                    {
                        Width  = 150,
                        Height = 21
                    }
                };
            }
            //为空时默认返回TextBox
            return(stimControl ?? new StimControl(new TextBox()));
        }
예제 #2
0
        /// <summary>
        /// 用于添加、编辑页面生成控件
        /// </summary>
        /// <param name="control"></param>
        /// <param name="objAttribute"></param>
        /// <param name="objValue"></param>
        /// <param name="Flag">是添加、还是修改</param>
        /// <returns></returns>
        private StimControl CreateStimBasic(TextBox control, Object objAttribute, Object objValue, string Flag)
        {
            StimControl stimControl = null;

            //根据XML生成控件
            if (objAttribute.GetType().Name.Equals("XElement"))
            {
                XElement xElement = (XElement)objAttribute;
                //解决数据源
                List <TxtValObject> TempDataSource = null;
                string datasource = getXElementAttributeValue(xElement.Element("DataRule"), "DataSource", "");
                if (!string.IsNullOrEmpty(datasource))
                {
                    var json = new JavaScriptSerializer();
                    TempDataSource = json.Deserialize <List <TxtValObject> >(datasource) as List <TxtValObject>;
                }
                //解决窗体数据源
                PropertyGrid.Select.ValueObject TempDataObject = null;
                string TempDataObjectStr = getXElementAttributeValue(xElement.Element("FrmData"), "object", "");
                if (!string.IsNullOrEmpty(TempDataObjectStr))
                {
                    var json = new JavaScriptSerializer();
                    TempDataObject = json.Deserialize <PropertyGrid.Select.ValueObject>(TempDataObjectStr) as PropertyGrid.Select.ValueObject;
                }
                //解决验证规则
                PropertyGrid.CheckValueObject TempRegular = null;
                string RegularStr = getXElementAttributeValue(xElement.Element("DataRule"), "Regular", "");
                if (!string.IsNullOrEmpty(RegularStr))
                {
                    var json = new JavaScriptSerializer();
                    TempRegular = json.Deserialize <PropertyGrid.CheckValueObject>(RegularStr) as PropertyGrid.CheckValueObject;
                }
                //解决默认值
                PropertyGrid.ValueObject TempValueDialog = null;
                string valueDialogStr = getXElementAttributeValue(xElement.Element("DataControl"), "Value", "");
                if (!string.IsNullOrEmpty(valueDialogStr))
                {
                    var json = new JavaScriptSerializer();
                    TempValueDialog = json.Deserialize <PropertyGrid.ValueObject>(valueDialogStr) as PropertyGrid.ValueObject;
                    if (Flag.ToLower().Equals("add"))
                    {
                        //0,文本;1,系统变量;2,sql语句
                        switch (TempValueDialog.ValueType)
                        {
                        case "0": objValue = TempValueDialog.ValueStr; break;

                        case "1": objValue = (new PropertyGrid.Item.SysValue()).GetValue(TempValueDialog.ValueApp); break;

                        case "2": objValue = (new BLL.STIM_CONFIG()).getSqlDefaultValue(TempValueDialog.ValueSql); break;
                        }
                    }
                }
                stimControl = new StimControl(control)
                {
                    objValue = objValue,
                    Name     = getXElementAttributeValue(xElement, "Column_Name", ""),
                    Location = new Point(int.Parse(getXElementAttributeValue(xElement, "X", "0")), int.Parse(getXElementAttributeValue(xElement, "Y", "0"))),
                    Width    = int.Parse(getXElementAttributeValue(xElement, "W", "250")),
                    Height   = int.Parse(getXElementAttributeValue(xElement, "H", "29")),
                    Visible  = (getXElementAttributeValue(xElement, "Visible", "True")).Equals("True"),
                    //Enabled = (bool)xElement.Attribute("Enabled"),
                    TLP      = { CellBorderStyle = TableLayoutPanelCellBorderStyle.None },
                    property =
                    {
                        Name              = getXElementAttributeValue(xElement,                                                                                  "Column_Name",       ""),
                        Text              = xElement.Element("Lable").Value != "" ? xElement.Element("Lable").Value : (string)xElement.Attribute("Column_Name"),
                        ColumnWidth       = int.Parse(getXElementAttributeValue(xElement,                                                                        "CW",                "80")),
                        TabIndex          = int.Parse(getXElementAttributeValue(xElement,                                                                        "TabIndex",          "0")),
                        ControlType       = int.Parse(getXElementAttributeValue(xElement,                                                                        "ControlType",       "0")),
                        ControlVisible    = getXElementAttributeValue(xElement,                                                                                  "Visible",           "True").Equals("True") ? 1 : 0,
                        ControlEnable     = getXElementAttributeValue(xElement,                                                                                  "Enabled",           "True").Equals("True") ? 1 : 0,
                        ControlRequired   = getXElementAttributeValue(xElement,                                                                                  "Required",          "True").Equals("True") ? 1 : 0,
                        ListConditionFlag = getXElementAttributeValue(xElement,                                                                                  "ListConditionFlag", "True").Equals("True") ? 1 : 0,
                        ListShowFlag      = getXElementAttributeValue(xElement,                                                                                  "ListShowFlag",      "True").Equals("True") ? 1 : 0,
                        FrmDataObject     = TempDataObject,
                        ControlDataSource = TempDataSource,
                        Value             = TempValueDialog,
                        CheckRegular      = TempRegular
                    },
                    lblFile =
                    {
                        Text = xElement.Element("Lable").Value != "" ? xElement.Element("Lable").Value : (string)xElement.Attribute("Column_Name"),
                    },
                    DataFile =
                    {
                        Enabled = getXElementAttributeValue(xElement.Element("DataControl"), "Enabled", "True").Equals("True"),
                        Visible = getXElementAttributeValue(xElement.Element("DataControl"), "Visible", "True").Equals("True")
                    }
                };
            }

            //为空时默认返回TextBox
            return(stimControl ?? new StimControl(new TextBox()));
        }