示例#1
0
        public static Form AddForm(BaseObject obj, int controlWidth, int controlHeight)
        {
            Form form = new Form
            {
                ClientSize = new Size(controlWidth * 2, (obj.GetType().GetProperties().Count() * controlHeight * 2) +
                                      (obj.GetType().GetFields().Count() * controlHeight * 2) + (controlHeight * 2))
            };

            return(form);
        }
示例#2
0
文件: Object.cs 项目: Vakenrovec/CRUD
 private void GetProperties(Form form, BaseObject obj, ref int y, ApplicationDataContext applicationDataContext)
 {
     foreach (PropertyInfo property in obj.GetType().GetProperties())
     {
         LabelAttribute attribute = property.GetCustomAttributes(true).OfType <LabelAttribute>().First();
         Controls.AddLabel(form, y, 0, ControlWidth, ControlHeight, attribute.LabelText);
         if (property.PropertyType.IsGenericType)
         {
             IList list = (IList)property.GetValue(obj);
             Controls.AddComboBox(form, y, ControlWidth, ControlWidth, ControlHeight, list.Cast <object>().ToArray(), "");
         }
         else
         if (property.PropertyType.IsEnum)
         {
             Controls.AddComboBox(form, y, ControlWidth, ControlWidth, ControlHeight, property.PropertyType.GetEnumNames(), property.GetValue(obj).ToString());
         }
         else
         if (property.PropertyType == typeof(int) || property.PropertyType == typeof(string))
         {
             Controls.AddTextBox(form, y, ControlWidth, ControlWidth, ControlHeight, property.GetValue(obj)?.ToString());
         }
         else
         if (property.PropertyType.GetCustomAttributes(true).OfType <CommunicationTypeAttribute>().First().CommunicationType == "Композиция")
         {
             Button createObjectButton = Controls.AddButton(form, y, ControlWidth, ControlWidth, ControlHeight, "Посмотреть объект");
             createObjectButton.Click += (sender, e) =>
             {
                 BaseObject newObj = (BaseObject)property.GetValue(obj);
                 newObj.Update(applicationDataContext, false);
             };
         }
         else
         {
             List <BaseObject> list = new List <BaseObject>();
             foreach (BaseObject element in applicationDataContext.Objects)
             {
                 if (element.GetType() == property.PropertyType && element != property.GetValue(this))
                 {
                     list.Add(element);
                 }
             }
             Controls.AddComboBox(form, y, ControlWidth, ControlWidth, ControlHeight, list.Cast <object>().ToArray(), property.GetValue(this));
         }
         y += ControlHeight * 2;
     }
 }