Beispiel #1
0
 protected void Setup_MainForm()
 {
     _formHost = UIDesigner_Service.IDesignerHost_FromComponent(this);
     _formName = UIDesigner_Form.Form_Main(this);
     if (_formName == null)
     {
         return;                     // If we do not know what the form name is -> we cannot go past this point.
     }
     try
     {
         if (_formHost != null)
         {
             // Basic setup of the form
             _formControls = UIDesigner_Tools.Host_Controls_All(_formHost);
             Setup_();
         }
     }
     catch (Exception)
     {
         _Form_Startup = false;
         throw;
     }
     _Form_Startup = false;
 }
Beispiel #2
0
        /// <summary>Generates the controls on the designer panels.</summary>
        /// <param name="designer">The designer</param>
        /// <param name="classType">The class type</param>
        /// <param name="classAttribute">The class attributeuteibute</param>
        /// <param name="panel1">The panel1</param>
        /// <param name="panel2">The panel to setting. Default value = null.</param>
        /// <param name="panel3">The panel3 setting. Default value = null.</param>
        /// <param name="onValueChange">The on valueue change setting. Default value = null.</param>
        /// <returns>The height of the form should be</returns>
        public int Generate_Controls(IDesignerHost designer, Type classType, BlueprintData_TableAttribute classAttribute, Panel panel1, Panel panel2 = null, Panel panel3 = null, EventHandler <onInputControl_EventArgs> onValueChange = null)
        {
            Panel panel = null;

            if (panel1 == null)
            {
                "Error! Cannot generate controls if Panel_1 is unknown.".zOk();
                return(0);
            }

            // Find decorated properties for the class that is to be generated
            bool class_GenerateAllFields = (classAttribute == null) ? true : classAttribute.GenerateAllFields;

            // For class type, get all fields that was marked with BlueprintData_FieldAttribute
            Input_Control input = null;
            IList <Tuple <FieldInfo, BlueprintData_FieldAttribute> > fields = LamedalCore_.Instance.Types.Class.ClassAttributes.Find_Fields(classType, new BlueprintData_FieldAttribute());
            // List<Tuple<FieldInfo, Attribute>> fields = _dotNet.ClassAttribute.Field_FindAttributes(classType, typeof(BlueprintData_FieldAttribute), class_GenerateAllFields);
            dynamic defaultO = UIDesigner_Form.Create(classType);

            foreach (Tuple <FieldInfo, BlueprintData_FieldAttribute> field in fields)
            {
                // ===================================
                // Read all the definition information
                // ===================================
                FieldInfo fieldInfo  = field.Item1;
                object    value      = fieldInfo.GetValue(defaultO);
                string    fieldValue = value.zObject().AsStr();
                string    fieldName  = fieldInfo.Name;

                var fieldDefinition = field.Item2 as BlueprintData_FieldAttribute;
                if (fieldDefinition == null)
                {
                    if (class_GenerateAllFields)
                    {
                        fieldDefinition = new BlueprintData_FieldAttribute();
                    }
                    else
                    {
                        "Error! Field '{0}' does not have attribute BlueprintData_FieldAttribute.".zFormat(fieldName).zOk();
                        continue;  // <========================================================================================
                    }
                }
                if (fieldDefinition.IsVisible == false)
                {
                    continue;                                      // <=================================================
                }
                string fieldCaption = fieldDefinition.Caption;
                if (fieldCaption == "")
                {
                    fieldCaption = fieldName;
                }
                Type   fieldType        = fieldInfo.FieldType;
                string fieldDescription = fieldDefinition.Description;
                bool   fieldIsPassword  = fieldDefinition.IsPassword;
                bool   fieldIsRequired  = fieldDefinition.IsRequired;
                int    fieldValueMax    = fieldDefinition.ValueMax;
                int    fieldValueMin    = fieldDefinition.ValueMin;
                int    fieldLengthMax   = fieldDefinition.LengthMax;
                int    fieldLengthMin   = fieldDefinition.LengthMin;

                // Create the form for capturing values
                if (panel == null)
                {
                    panel = panel1;
                }
                input = UIDesigner_Generate.Create_Input(designer, panel, fieldName, fieldCaption, fieldType, fieldValue, onValueChange);
                // Set the panel
                if (panel == panel3)
                {
                    panel = panel1;
                }
                else if (panel == panel2)
                {
                    if (panel3 == null)
                    {
                        panel = panel1;
                    }
                    else
                    {
                        panel = panel3;
                    }
                }
                else if (panel == panel1)
                {
                    if (panel2 != null)
                    {
                        panel = panel2;
                    }
                }


                if (input != null)
                {
                    input.Field_Description = fieldDescription;
                }
            }

            if (input != null)
            {
                return(input.Top + input.Height + 80);
            }
            return(0);
        }