Пример #1
0
        /// <summary>
        /// 根据XML生成控件,添加,编辑页面用
        /// </summary>
        /// <param name="xElement"></param>
        /// <param name="objValue"></param>
        /// <param name="Flag">add、modify</param>
        ///
        public CreateStimControl(XElement xElement, Object objValue, string Flag)
        {
            TextBox txt = new TextBox();

            AutoStimControl = CreateStimBasic(txt, xElement, objValue, Flag);
            //string type = (string)xElement.Attribute("ControlType");
            //AutoStimControl.property_TypeChangeHandler(type);
        }
Пример #2
0
        /// <summary>
        /// 根据XML生成控件,设计界面用
        /// </summary>
        /// <param name="xElement"></param>
        /// <param name="objValue"></param>
        public CreateStimControl(XElement xElement, Object objValue)
        {
            TextBox txt = new TextBox();

            AutoStimControl = CreateStimBasic(txt, xElement, objValue);
            //string type = (string)xElement.Attribute("ControlType");
            //AutoStimControl.CreateControlAndSetValue(type, objValue);
        }
Пример #3
0
        /// <summary>
        /// 根据DataRow生成控件
        /// </summary>
        /// <param name="row"></param>
        /// <param name="objValue"></param>
        /// <param name="draggable"></param>
        public CreateStimControl(DataRow row, Object objValue = null)
        {
            string dataType = row["DATA_TYPE"].ToString();

            switch (dataType)
            {
            case "DATE":
                DateTimePicker dateTimePicker = new DateTimePicker();
                AutoStimControl = CreateStimBasic(dateTimePicker, row, objValue);
                break;

            case "NUMBER":
                NumericUpDown numericUpDown = new NumericUpDown();
                AutoStimControl = CreateStimBasic(numericUpDown, row, objValue);
                break;

            default:
                TextBox txt = new TextBox();
                AutoStimControl = CreateStimBasic(txt, row, objValue);
                break;
            }
        }
Пример #4
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()));
        }
Пример #5
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()));
        }
Пример #6
0
        /// <summary>
        /// 使用 LINQ to XML 的方式创建XML
        /// </summary>
        /// <param name="tableName">数据库表名</param>
        /// <param name="controls">控件集合</param>
        /// <returns></returns>
        public string MakeXmlLinq(string tableName, Control.ControlCollection controls)
        {
            XDocument xDoc = new XDocument(
                new XDeclaration("1.0", "utf-8", "yes"),
                new XElement("Table",
                             new XAttribute("TableName", tableName)
                             )
                );

            int VerticalScroll   = this.tabPageDetail.VerticalScroll.Value;
            int HorizontalScroll = this.tabPageDetail.HorizontalScroll.Value;

            foreach (Control control in controls)
            {
                if (control is StimControl)
                {
                    StimControl temp = control as StimControl;
                    //解决shujuy
                    string datasource = string.Empty;
                    if (temp.property.ControlDataSource != null)
                    {
                        var json = new JavaScriptSerializer();
                        datasource = json.Serialize(temp.property.ControlDataSource);
                    }
                    //解决弹窗选择数据
                    string frmDataObject = string.Empty;
                    if (temp.property.FrmDataObject != null)
                    {
                        var json = new JavaScriptSerializer();
                        frmDataObject = json.Serialize(temp.property.FrmDataObject);
                    }
                    //解决规则
                    string Regular = string.Empty;
                    if (temp.property.CheckRegular != null)
                    {
                        var json = new JavaScriptSerializer();
                        Regular = json.Serialize(temp.property.CheckRegular);
                    }
                    //解决默认值
                    string valueObjectStr = string.Empty;
                    if (temp.property.Value != null)
                    {
                        var json = new JavaScriptSerializer();
                        valueObjectStr = json.Serialize(temp.property.Value);
                    }
                    XElement xEle = new XElement("Column",
                                                 new XAttribute("Column_Name", temp.Name),
                                                 new XAttribute("ControlType", temp.property.ControlType),
                                                 new XAttribute("ControlName", control.Controls["TLP"].Controls["dataFile"].GetType().Name),
                                                 new XAttribute("Visible", temp.property.ControlVisible == 1 ? "True" : "False"),
                                                 new XAttribute("Enabled", temp.property.ControlEnable == 1 ? "True" : "False"),
                                                 new XAttribute("Required", temp.property.ControlRequired == 1 ? "True" : "False"),
                                                 new XAttribute("ListConditionFlag", temp.property.ListConditionFlag == 1 ? "True" : "False"),
                                                 new XAttribute("ListShowFlag", temp.property.ListShowFlag == 1 ? "True" : "False"),
                                                 new XAttribute("X", (temp.property.ControlLeft + HorizontalScroll).ToString()),
                                                 new XAttribute("Y", (temp.property.ControlTop + VerticalScroll).ToString()),
                                                 new XAttribute("W", temp.property.ControlWidth.ToString()),
                                                 new XAttribute("H", temp.property.ControlHeight.ToString()),
                                                 new XAttribute("CW", temp.property.ColumnWidth.ToString()),
                                                 new XAttribute("TabIndex", temp.property.TabIndex.ToString()),
                                                 new XElement("Lable", temp.property.Text,
                                                              new XAttribute("W", 100),
                                                              new XAttribute("H", 25)
                                                              ),
                                                 new XElement("DataControl",
                                                              new XAttribute("Visible", temp.property.ControlVisible == 1 ? "True" : "False"),
                                                              new XAttribute("Enabled", temp.property.ControlEnable == 1 ? "True" : "False"),
                                                              new XAttribute("Value", valueObjectStr)
                                                              ),
                                                 new XElement("DataRule",
                                                              //new XAttribute("Nullable", DtStruct.Select("COLUMN_NAME='" + control.Name + "'")[0]["NULLABLE"].ToString()),
                                                              new XAttribute("DataSource", datasource),
                                                              new XAttribute("Regular", Regular)
                                                              ),
                                                 new XElement("FrmData",
                                                              new XAttribute("object", frmDataObject)
                                                              )
                                                 );
                    xDoc.Root.Add(xEle);
                }
            }

            //xDoc.Save(Application.StartupPath + "\\DetailForm.xml");

            return(xDoc.Declaration + xDoc.ToString(SaveOptions.DisableFormatting));
        }
Пример #7
0
        /// <summary>
        /// propertyGrid控件属性切换
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void stimControl_Click(object sender, EventArgs e)
        {
            StimControl stimControl = (StimControl)sender;

            propertyGrid1.SelectedObject = stimControl.property;
        }