Beispiel #1
0
        /// <summary>
        /// 控件绑定模型配置
        /// </summary>
        /// <param name="page"></param>
        /// <param name="modelName">实现IPFConfigMapper的类中定义</param>
        /// <param name="list"></param>
        public static void BindModel(string modelName, List <ModelBindConfig> list)
        {
            var modelConfig = PFDataHelper.GetMultiModelConfig(modelName);

            foreach (var i in list)
            {
                PFModelConfig config = null;
                if (modelConfig != null)
                {
                    config = modelConfig[i.GetPropertyName()];
                }
                if (i.GetComponent() is System.Web.UI.WebControls.Label)
                {
                    System.Web.UI.WebControls.Label tmpControl = (System.Web.UI.WebControls.Label)i.GetComponent();
                    LabelBind(tmpControl, config);
                }
                else if (i.GetComponent() is System.Web.UI.WebControls.TextBox)
                {
                    System.Web.UI.WebControls.TextBox tmpControl = (System.Web.UI.WebControls.TextBox)i.GetComponent();
                    BindValidator(tmpControl, config, i.GetValidator());
                    LabelBind(i.GetLabel(), config);
                    TextBoxBind(tmpControl, config);
                }
                else if (i.GetComponent() is System.Web.UI.WebControls.DropDownList)
                {
                    System.Web.UI.WebControls.DropDownList tmpControl = (System.Web.UI.WebControls.DropDownList)i.GetComponent();
                    BindValidator(tmpControl, config, i.GetValidator());
                    LabelBind(i.GetLabel(), config);
                }
            }
        }
Beispiel #2
0
        private void LoadField()
        {
            var fieldNode = FieldSetsHelper.FindField(_fieldSetsXml, lbDataSet.Text, _fieldName);

            if (fieldNode != null)
            {
                var config = new PFModelConfig(fieldNode, lbDataSet.Text);
                tbName.Text = config.FieldName;
                tbText.Text = config.FieldText;
                if (config.FieldType != null)
                {
                    cbType.SelectedItem = PFDataHelper.GetStringByType(config.FieldType);
                }
                cbVisible.Checked = config.Visible;
                if (config.FieldSqlLength != null)
                {
                    nudSqlLength.Value    = config.FieldSqlLength.Value;
                    nudSqlLength.ReadOnly = !(cbHaveSqlLength.Checked = true);
                }
                else
                {
                    nudSqlLength.ReadOnly = !(cbHaveSqlLength.Checked = false);
                }
                if (config.FieldWidth != null)
                {
                    nudWidth.Value    = decimal.Parse(config.FieldWidth.Replace("px", ""));
                    nudWidth.ReadOnly = !(cbHaveWidth.Checked = true);
                }
                else
                {
                    nudWidth.ReadOnly = !(cbHaveWidth.Checked = false);
                }
                //_pfModelConfig = config;
            }
        }
        protected override void SetByModelPropertyConfig(PFModelConfig config)
        {
            //base.SetByModelPropertyConfig(config);

            if (config != null)
            {
                if (config.Required)
                {
                    SetRequired();
                }
                if (!string.IsNullOrWhiteSpace(config.FieldWidth))
                {
                    var width = int.Parse(config.FieldWidth.Replace("px", "")) + 10;//number类型控件后有个上下健头,所以要宽一点
                    SetStyle("width:" + width + "px");
                }

                if (config.FieldType == typeof(decimal))
                {
                    SetHtmlAttribute("onfocus", "this.oldvalue = this.value; ");
                    if (config.Precision.HasValue)
                    {
                        SetHtmlAttribute("onchange", "if(!$pf.isDecimal(this.value," + config.Precision + ")){this.value=this.oldvalue;}");
                    }
                    else
                    {
                        SetHtmlAttribute("onchange", "if(!$pf.isDecimal(this.value)){this.value=this.oldvalue;}");
                    }
                }
                else if (config.FieldType == typeof(int))
                {
                    SetHtmlAttribute("onfocus", "this.oldvalue = this.value; ");
                    SetHtmlAttribute("onchange", "if(!$pf.isInt(this.value)){this.value=this.oldvalue;}");
                }
            }
        }
Beispiel #4
0
        private static void TextBoxBind(TextBox textBox, PFModelConfig modelConfig)
        {
            if (modelConfig != null)
            {
                if (modelConfig.FieldType == typeof(decimal))
                {
                    textBox.Attributes.Add("onfocus", "this.oldvalue = this.value; ");
                    if (modelConfig.Precision.HasValue)
                    {
                        textBox.Attributes.Add("onchange", "if(!$pf.isDecimal(this.value," + modelConfig.Precision + ")){this.value=this.oldvalue;}");
                    }
                    else
                    {
                        textBox.Attributes.Add("onchange", "if(!$pf.isDecimal(this.value)){this.value=this.oldvalue;}");
                    }
                }
                else if (modelConfig.FieldType == typeof(int))
                {
                    textBox.Attributes.Add("onfocus", "this.oldvalue = this.value; ");
                    textBox.Attributes.Add("onchange", "if(!$pf.isInt(this.value)){this.value=this.oldvalue;}");
                }

                if (textBox.Width != null && textBox.Width.IsEmpty &&
                    (!PFDataHelper.StringIsNullOrWhiteSpace(modelConfig.FieldWidth)))
                {
                    textBox.Width = new Unit(modelConfig.FieldWidth);
                }
            }
        }
Beispiel #5
0
 public virtual void SetPropertyFor <TModel, TProperty>(HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > expression)
 {
     _modelConfig = GetModelPropertyConfig(htmlHelper, expression);
     if (_modelConfig != null)
     {
         SetByModelPropertyConfig(_modelConfig);
     }
 }
Beispiel #6
0
 public virtual void SetPropertyFor <TModel, TProperty>(HtmlHelper htmlHelper, Expression <Func <TModel, TProperty> > expression)
 {
     _modelConfig = GetModelPropertyConfig(htmlHelper, expression);
     if (_modelConfig != null)
     {
         _required = _modelConfig.Required;
     }
 }
Beispiel #7
0
 public virtual void SetPropertyFor(HtmlHelper htmlHelper, string expression)
 {
     _modelConfig = GetModelPropertyConfig(htmlHelper, expression);
     if (_modelConfig != null)
     {
         _required = _modelConfig.Required;
     }
 }
Beispiel #8
0
 public virtual void SetPropertyFor(HtmlHelper htmlHelper, string expression)
 {
     _modelConfig = GetModelPropertyConfig(htmlHelper, expression);
     if (_modelConfig != null)
     {
         SetByModelPropertyConfig(_modelConfig);
     }
 }
Beispiel #9
0
        private void AddFieldRow(PFModelConfig config)
        {
            var i = dgvFieldSet.Rows.Add();

            dgvFieldSet.Rows[i].Cells["FieldName"].Value   = config.FieldName;
            dgvFieldSet.Rows[i].Cells["FieldText"].Value   = config.FieldText;
            dgvFieldSet.Rows[i].Cells["hideDataSet"].Value = config.DataSet;
        }
Beispiel #10
0
        protected override void SetByModelPropertyConfig(PFModelConfig config)
        {
            base.SetByModelPropertyConfig(config);

            if (config != null)
            {
                if (!string.IsNullOrWhiteSpace(config.FieldWidth))
                {
                    var width = int.Parse(config.FieldWidth.Replace("px", "")) + 20;//下拉控件后有个下健头,所以要宽一点
                    SetStyle("width:" + width + "px");
                }
            }
        }
Beispiel #11
0
 private string GetHtmlByModelConfig(string html, PFModelConfig config)
 {
     if (config != null)
     {
         var ex = "";
         if (_required)
         {
             ex += "<span style='color:red'>*</span>";
         }
         ex += ":";
         return(AppendToLast(html, ex));
     }
     return(html);
 }
Beispiel #12
0
 protected virtual void SetByModelPropertyConfig(PFModelConfig config)
 {
     if (config != null)
     {
         if (config.Required)
         {
             SetRequired();
         }
         //if (!string.IsNullOrWhiteSpace(config.FieldWidth)) { SetStyle("width:"+ config.FieldWidth+"pt"); }
         if (!string.IsNullOrWhiteSpace(config.FieldWidth))
         {
             SetStyle("width:" + config.FieldWidth);
         }
     }
 }
Beispiel #13
0
 /// <summary>
 /// 绑定label
 /// </summary>
 /// <typeparam name="TComponent">支持textbox</typeparam>
 /// <param name="component"></param>
 /// <param name="modelConfig"></param>
 /// <param name="label"></param>
 private static void LabelBind(Label label, PFModelConfig modelConfig)
 {
     if (modelConfig != null)
     {
         if (PFDataHelper.StringIsNullOrWhiteSpace(label.Text) || label.Text == modelConfig.FieldName ||
             label.Text == "Label"   //Label控件的默认Text是Label
             )
         {
             label.Text = modelConfig.FieldText;
         }
         if (modelConfig.Required)
         {
             label.Text += "<span style='color:red'>*</span>";
         }
         label.Text += ":";
     }
 }
Beispiel #14
0
 /// <param name="validator">动态生成RequiredFieldValidator的方法不能实现</param>
 private static void BindValidator <TComponent>(TComponent component, PFModelConfig modelConfig, BaseValidator validator)
     where TComponent : WebControl
 {
     if (modelConfig != null && modelConfig.Required)
     {
         component.Attributes.Add("required", "required");
     }
     if (validator != null)
     {
         validator.ControlToValidate = component.ID;
         validator.Text    = "必填";
         validator.Display = ValidatorDisplay.Dynamic;
         if (modelConfig != null)
         {
             validator.Enabled = modelConfig.Required;
         }
     }
 }
Beispiel #15
0
        /// <summary>
        /// 控件绑定模型配置
        /// </summary>
        /// <param name="page"></param>
        /// <param name="modelName">实现IPFConfigMapper的类中定义</param>
        /// <param name="list"></param>
        public static void GridBindModel(DataGrid grid, string modelName)
        {
            var modelConfig = PFDataHelper.GetMultiModelConfig(modelName);

            if (modelConfig != null)
            {
                if (grid.Columns != null)
                {
                    foreach (DataGridColumn c in grid.Columns)
                    {
                        if (c is BoundColumn)
                        {
                            BoundColumn   tc     = c as BoundColumn;
                            PFModelConfig config = null;
                            if (modelConfig != null)
                            {
                                config = modelConfig[tc.DataField];
                            }
                            if (config != null && (PFDataHelper.StringIsNullOrWhiteSpace(tc.HeaderText) || tc.HeaderText == config.FieldName))
                            {
                                tc.HeaderText = config.FieldText;
                            }
                        }
                        else if (c is TemplateColumn)
                        {
                            TemplateColumn tc     = c as TemplateColumn;
                            PFModelConfig  config = null;
                            if (modelConfig != null)
                            {
                                config = modelConfig[tc.HeaderText];
                            }
                            if (config != null && (PFDataHelper.StringIsNullOrWhiteSpace(tc.HeaderText) || tc.HeaderText == config.FieldName))
                            {
                                tc.HeaderText = config.FieldText;
                            }
                        }
                    }
                }
            }
        }
Beispiel #16
0
 private void UpdateFieldNodeByModel(ref XmlNode xmlNode, ref PFModelConfig model)
 {
 }
Beispiel #17
0
 private void UpdateModelByForm(ref PFModelConfig model)
 {
 }
Beispiel #18
0
        private void RefreshGrid()
        {
            _xmlPath      = cbSys.SelectedValue.ToString();
            _fieldSetsXml = new XmlDocument();
            _fieldSetsXml.Load(_xmlPath);

            _dataSets = _fieldSetsXml.ChildNodes[1];

            List <string> fields = (tbField.Text ?? "").Replace(" ", "").Split(new char[] { ',', '"' }, StringSplitOptions.RemoveEmptyEntries).ToList();

            fields = fields.Select(a => (a ?? "").ToLower()).ToList();
            var list = new List <PFModelConfig>();

            foreach (XmlNode dataSet in _dataSets.ChildNodes)
            {
                var fieldsNode = dataSet.SelectSingleNode("Fields");//demo节点也读出来了,是null的
                if (fieldsNode != null)
                {
                    foreach (XmlNode i in dataSet.SelectSingleNode("Fields").ChildNodes)
                    {
                        //foreach (string field in fields)
                        //{
                        var config = new PFModelConfig(i, dataSet.Attributes["name"].Value);
                        //if (fields.Any(a => (a??"").ToLower() == config.LowerFieldName))
                        if (fields.Any(a => a == config.LowerFieldName))
                        {
                            list.Add(config);
                        }
                        //}
                    }
                }
            }
            var groups = list.GroupBy(a => a.DataSet).OrderByDescending(a => a.Count());

            var tmpFields = new List <string>(fields.ToArray());
            var result    = new List <string>();

            dgvFieldSet.Rows.Clear();
            foreach (var group in groups)
            {
                bool haveAny = false;
                AddDataSetRow(group.Key);
                foreach (PFModelConfig item in group)
                {
                    AddFieldRow(item);
                    if (tmpFields.Contains(item.LowerFieldName))
                    {
                        tmpFields.Remove(item.LowerFieldName);
                        haveAny = true;
                    }
                    //if (tmpFields.Contains(item.FieldName))
                    //{
                    //    tmpFields.Remove(item.FieldName);
                    //    haveAny = true;
                    //}
                }
                if (haveAny)
                {
                    result.Add(group.Key);
                }
            }
            tbResult.Text = string.Join(",", result);
            tbLose.Text   = string.Join(",", tmpFields);
        }