Example #1
0
 private Control GetRequiredCombobox(string propertyQuery, DataComboBox dataComboBox)
 {
     DBConnection.QueryConnection.Open();
     using (var cmd = new MySqlCommand(propertyQuery, DBConnection.QueryConnection))
     {
         using (var rd = cmd.ExecuteReader())
         {
             while (rd.Read())
             {
                 if (!rd.HasRows)
                 {
                     continue;
                 }
                 dataComboBox.Items.Add(rd[1]);
                 dataComboBox.RealValues.Add(rd[0].ToString());
             }
         }
     }
     DBConnection.QueryConnection.Close();
     if (dataComboBox.Items.Count != 0)
     {
         dataComboBox.SelectedIndex = 0;
     }
     return(dataComboBox);
 }
Example #2
0
        void CreateFields()
        {
            panelPropArea.Controls.Clear();
            _valueControls = new Dictionary <string, Control>();
            var objType = _selectedObject.GetType();
            var props = objType.GetProperties();
            int x = 80, y = 5;
            var difference = 30;

            //var tableQuery = GetPropValue(DBConnection.DbCon, objType.Name).ToString(); //  verilen tabloyu almak için query'i veriyor

            foreach (var prop in props)
            {
                var extraArea = false;
                var attribute = prop.GetCustomAttribute <PropertyMVC>();
                if (attribute == null)
                {
                    continue;
                }
                Control requiredControl = null;
                switch (attribute.DesiredControl)
                {
                case ControlEnum.MultilineTextBox:
                    requiredControl = new TextBox {
                        Multiline = true
                    };
                    extraArea = true;
                    break;

                case ControlEnum.MultipleAdder:

                    break;

                case ControlEnum.Entity:     // Entity id veya class ataması yapılacak
                    var propQuery = GetPropValue(DBConnection.DbCon, prop.PropertyType.Name);

                    //var fieldNames = TakeFieldNames(propQuery);
                    var cbx = new DataComboBox();
                    #region Düzenleme için bilgi getirme kodu
                    DBConnection.QueryConnection.Open();
                    using (var cmd = new MySqlCommand(propQuery.ToString(), DBConnection.QueryConnection))
                    {
                        using (var rd = cmd.ExecuteReader())
                        {
                            while (rd.Read())
                            {
                                if (!rd.HasRows)
                                {
                                    continue;
                                }
                                cbx.Items.Add(rd[1]);
                                cbx.RealValues.Add(rd[0].ToString());
                            }
                        }
                    }
                    DBConnection.QueryConnection.Close();
                    if (cbx.Items.Count != 0)
                    {
                        cbx.SelectedIndex = 0;
                    }
                    requiredControl = cbx;
                    #endregion
                    break;

                default:

                    requiredControl = GetControl(attribute.DesiredControl, attribute.Source);

                    break;
                }
                if (requiredControl != null)
                {
                    //prop.SetValue(SelectedObject, "Test");
                    var propValue = prop.GetValue(_selectedObject);
                    var lbl       = new System.Windows.Forms.Label
                    {
                        Text     = attribute.DisplayName,
                        Location = new Point(0, y),
                        AutoSize = true
                    };
                    requiredControl.Size     = new Size(150, 25);
                    requiredControl.Location = new Point(x, y);
                    if (propValue != null)
                    {
                        requiredControl.Text = propValue.ToString();
                    }
                    y        += extraArea ? difference + 5 : difference;
                    extraArea = false;
                    panelPropArea.Controls.Add(lbl);
                    panelPropArea.Controls.Add(requiredControl);
                    _valueControls.Add(prop.Name, requiredControl);
                }
            }
        }
Example #3
0
        private void CreateFields()
        {
            panelPropArea.Controls.Clear();
            _valueControls = new Dictionary <string, Control>();
            var objType = _selectedObject.GetType();
            var props   = objType.GetProperties();

            x          = 80; y = 5;
            difference = 30;
            foreach (var prop in props)
            {
                var extraArea = false;
                var attr      = prop.GetCustomAttribute <PropertyMVC>();
                if (attr == null)
                {
                    continue;
                }
                Control requiredControl = null;
                var     attribute       = attr;
                switch (attribute.DesiredControl)
                {
                case ControlEnum.MultilineTextBox:
                    requiredControl = new TextBox {
                        Multiline = true
                    };
                    extraArea = true;
                    break;

                case ControlEnum.MultipleAdder:

                    break;

                case ControlEnum.Entity:
                    var propQuery = GetPropValue(DBConnection.DbCon, prop.PropertyType.Name).ToString();
                    var cbx       = new DataComboBox();
                    requiredControl = GetRequiredCombobox(propQuery, cbx);
                    break;

                default:
                    requiredControl = GetControl(attribute.DesiredControl, attribute.Source);
                    break;
                }
                if (requiredControl == null)
                {
                    continue;
                }
                var propValue = prop.GetValue(_selectedObject);
                var lbl       = new Label
                {
                    Text     = attribute.DisplayName,
                    Location = new Point(2, y),
                    AutoSize = true
                };
                requiredControl.Size     = new Size(150, 25);
                requiredControl.Location = new Point(x, y);
                if (propValue != null)
                {
                    requiredControl.Text = propValue.ToString();
                }
                y        += extraArea ? difference + 5 : difference;
                extraArea = false;
                panelPropArea.Controls.Add(lbl);
                panelPropArea.Controls.Add(requiredControl);
                _valueControls.Add(prop.Name, requiredControl);
            }
        }