コード例 #1
0
        public static void ToEntity(this Control controls, object obj)
        {
            string ObjectName  = obj.GetType().Name;
            string bindingname = "";

            foreach (Control ctrl in controls.Controls)
            {
                if (ctrl is AutoTextBox)
                {
                    AutoTextBox textbox = ctrl as AutoTextBox;
                    if (textbox.BindingFor != ObjectName)
                    {
                        continue;
                    }
                    if (string.IsNullOrWhiteSpace(textbox.BindingName))
                    {
                        continue;
                    }
                    bindingname = textbox.BindingName;
                    SetProperty(bindingname, obj, textbox.Text);
                    continue;
                }
                if (ctrl is AutoRichTextBox)
                {
                    AutoRichTextBox textbox = ctrl as AutoRichTextBox;
                    if (textbox.BindingFor != ObjectName)
                    {
                        continue;
                    }
                    if (string.IsNullOrWhiteSpace(textbox.BindingName))
                    {
                        continue;
                    }
                    bindingname = textbox.BindingName;
                    SetProperty(bindingname, obj, textbox.Text);
                    continue;
                }
                if (ctrl is AutoMetroTextBox)
                {
                    AutoMetroTextBox textbox = ctrl as AutoMetroTextBox;
                    if (textbox.BindingFor != ObjectName)
                    {
                        continue;
                    }
                    if (string.IsNullOrWhiteSpace(textbox.BindingName))
                    {
                        continue;
                    }
                    bindingname = textbox.BindingName;
                    SetProperty(bindingname, obj, textbox.Text);
                    continue;
                }
                if (ctrl is AutoSearchCombobox)
                {
                    AutoSearchCombobox combobox = ctrl as AutoSearchCombobox;
                    if (combobox.BindingFor != ObjectName)
                    {
                        continue;
                    }
                    if (string.IsNullOrWhiteSpace(combobox.BindingName))
                    {
                        continue;
                    }
                    bindingname = combobox.BindingName;
                    if (combobox.GetSelectedText == true)
                    {
                        SetProperty(bindingname, obj, combobox.Text);
                    }
                    else
                    {
                        SetProperty(bindingname, obj, combobox.SelectedValue);
                    }
                    continue;
                }
                if (ctrl is AutoDatetime)
                {
                    AutoDatetime dtp = ctrl as AutoDatetime;
                    if (dtp.BindingFor != ObjectName)
                    {
                        continue;
                    }
                    if (string.IsNullOrWhiteSpace(dtp.BindingName))
                    {
                        continue;
                    }
                    bindingname = dtp.BindingName;
                    SetProperty(bindingname, obj, dtp.Value);
                    continue;
                }

                if (ctrl is AutoMetroCheckBox)
                {
                    AutoMetroCheckBox cb = ctrl as AutoMetroCheckBox;
                    if (cb.BindingFor != ObjectName)
                    {
                        continue;
                    }
                    if (string.IsNullOrWhiteSpace(cb.BindingName))
                    {
                        continue;
                    }
                    bindingname = cb.BindingName;
                    SetProperty(bindingname, obj, cb.Checked);
                    continue;
                }
                if (ctrl is AutoMetroRadio)
                {
                    AutoMetroRadio rd = ctrl as AutoMetroRadio;
                    if (rd.BindingFor != ObjectName)
                    {
                        continue;
                    }
                    if (string.IsNullOrWhiteSpace(rd.BindingName))
                    {
                        continue;
                    }
                    bindingname = rd.BindingName;
                    if (rd.Checked)
                    {
                        SetProperty(bindingname, obj, rd.ValueToCheck);
                    }
                    continue;
                }
                if (ctrl.Controls.Count > 0)
                {
                    ToEntity(ctrl, obj);
                }
            }
        }
コード例 #2
0
        public static void ToForm(this Control controls, object obj)
        {
            if (obj == null)
            {
                return;
            }
            string ObjectName  = obj.GetType().Name;
            string bindingname = "";
            object val         = null;

            foreach (Control ctrl in controls.Controls)
            {
                if (ctrl is AutoTextBox)
                {
                    AutoTextBox textbox = ctrl as AutoTextBox;
                    if (textbox.BindingFor != ObjectName)
                    {
                        continue;
                    }
                    if (string.IsNullOrWhiteSpace(textbox.BindingName))
                    {
                        continue;
                    }
                    bindingname  = textbox.BindingName;
                    val          = GetPropertyValue(bindingname, obj);
                    textbox.Text = val != null?val.ToString() : "";

                    continue;
                }
                if (ctrl is AutoRichTextBox)
                {
                    AutoRichTextBox textbox = ctrl as AutoRichTextBox;
                    if (textbox.BindingFor != ObjectName)
                    {
                        continue;
                    }
                    if (string.IsNullOrWhiteSpace(textbox.BindingName))
                    {
                        continue;
                    }
                    bindingname  = textbox.BindingName;
                    val          = GetPropertyValue(bindingname, obj);
                    textbox.Text = val != null?val.ToString() : "";

                    continue;
                }
                if (ctrl is AutoMetroTextBox)
                {
                    AutoMetroTextBox textbox = ctrl as AutoMetroTextBox;
                    if (textbox.BindingFor != ObjectName)
                    {
                        continue;
                    }
                    if (string.IsNullOrWhiteSpace(textbox.BindingName))
                    {
                        continue;
                    }
                    bindingname  = textbox.BindingName;
                    val          = GetPropertyValue(bindingname, obj);
                    textbox.Text = val != null?val.ToString() : "";

                    continue;
                }
                if (ctrl is AutoDatetime)
                {
                    AutoDatetime dtp = ctrl as AutoDatetime;
                    if (dtp.BindingFor != ObjectName)
                    {
                        continue;
                    }
                    if (string.IsNullOrWhiteSpace(dtp.BindingName))
                    {
                        continue;
                    }
                    bindingname = dtp.BindingName;
                    val         = GetPropertyValue(bindingname, obj);
                    dtp.Value   = val != null?Convert.ToDateTime(val) : DateTime.Today.AddDays(-10);

                    continue;
                }
                if (ctrl is AutoSearchCombobox)
                {
                    AutoSearchCombobox cbb = ctrl as AutoSearchCombobox;
                    if (cbb.BindingFor != ObjectName)
                    {
                        continue;
                    }
                    if (string.IsNullOrWhiteSpace(cbb.BindingName))
                    {
                        continue;
                    }
                    bindingname = cbb.BindingName;
                    val         = GetPropertyValue(bindingname, obj);
                    if (cbb.GetSelectedText == true)
                    {
                        cbb.Text = val != null?val.ToString() : "";
                    }
                    else
                    {
                        cbb.SelectedValue = val != null?Convert.ToInt32(val) : 0;
                    }
                    continue;
                }
                if (ctrl is AutoMetroCheckBox)
                {
                    AutoMetroCheckBox cb = ctrl as AutoMetroCheckBox;
                    if (cb.BindingFor != ObjectName)
                    {
                        continue;
                    }
                    if (string.IsNullOrWhiteSpace(cb.BindingName))
                    {
                        continue;
                    }
                    bindingname = cb.BindingName;
                    val         = GetPropertyValue(bindingname, obj);
                    cb.Checked  = val == null ? false : Convert.ToBoolean(val);
                    continue;
                }
                if (ctrl is AutoMetroRadio)
                {
                    AutoMetroRadio rd = ctrl as AutoMetroRadio;
                    if (rd.BindingFor != ObjectName)
                    {
                        continue;
                    }
                    if (string.IsNullOrWhiteSpace(rd.BindingName))
                    {
                        continue;
                    }
                    bindingname = rd.BindingName;
                    val         = GetPropertyValue(bindingname, obj);
                    rd.Checked  = (Convert.ToInt32((int)val) == rd.ValueToCheck) ? true : false;
                    continue;
                }
                if (ctrl.Controls.Count > 0)
                {
                    ToForm(ctrl, obj);
                }
            }
        }