コード例 #1
0
        private static void Create_Event(IDesignerHost host, Input_Control input, string eventName, string eventMethodName)
        {
            IEventBindingService      eventBindingService = UIDesigner_Service.IEventBindingService_FromHost(host);
            EventDescriptorCollection eventColl           = TypeDescriptor.GetEvents(input, new Attribute[0]);

            if (eventColl != null)
            {
                var eventDescriptor = eventColl[eventName] as EventDescriptor;
                if (eventDescriptor != null)
                {
                    PropertyDescriptor propertyDescriptor = eventBindingService.GetEventProperty(eventDescriptor);
                    propertyDescriptor.SetValue(input, eventMethodName);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Converts the generated form to object.
        /// </summary>
        /// <param name="e">The input event arguments control</param>
        /// <param name="Object">The object</param>
        public void Form_ToObject(onInputControl_EventArgs e, IObjectModel Object)
        {
            // Value on the form has changed -> update the object
            Input_Control input      = e.Control_;
            string        fieldName  = input.Field_Name;
            string        fieldValue = input.Field_Value;
            FieldInfo     fieldInfo  = Object.GetType().GetField(fieldName);
            Type          fieldType  = fieldInfo.FieldType;

            object value;

            if (fieldValue.zIsNullOrEmpty())
            {
                value = LamedalCore_.Instance.Types.Object.DefaultValue(fieldType);
            }
            else
            {
                value = LamedalCore_.Instance.Types.Object.CastTo(fieldValue, fieldType);
            }
            fieldInfo.SetValue(Object, value);
        }
コード例 #3
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);
        }