//private void Filtre_ComboBox_SelectedValueChanged(object sender, EventArgs e) //{ // foreach (var item in this.groupBoxFiltrage.Controls.OfType<TextBox>()) // { // item.Text = ""; // } // onRefreshEvent(sender, e); //} #endregion #region Read & Write /// <summary> /// Get Filter value /// </summary> /// <returns></returns> public Dictionary <string, object> GetFilterValues() { // Filter value Dictionary <string, object> FilterValues = new Dictionary <string, object>(); // List of Property shwon in Filter var PropertyListFilter = from i in BLO.TypeEntity.GetProperties() where i.GetCustomAttribute(typeof(FilterAttribute)) != null orderby((FilterAttribute)i.GetCustomAttribute(typeof(FilterAttribute))).Ordre select i; // Read Values from Fields foreach (PropertyInfo propertyInfo in PropertyListFilter) { ConfigProperty configProperty = new ConfigProperty(propertyInfo, this.ConfigEntity); IFieldTraitements fieldTraiement = BaseFieldTraitement.CreateInstance(configProperty); object value = fieldTraiement.GetFieldValue_From_Filter(FilterContainer, configProperty); if (value != null) { FilterValues[propertyInfo.Name] = value; } } return(FilterValues); }
public void TestAllEntities() { // Test All EntryForm using (ModelContext db = new ModelContext()) { foreach (var TypeEntity in new GwinEntitiesManager().GetAll_Entities_Type()) { var EntityInstance = Activator.CreateInstance(TypeEntity); ConfigEntity configEntity = ConfigEntity.CreateConfigEntity(TypeEntity); Dictionary <string, object> TestValyes = new Dictionary <string, object>(); // Set Values foreach (var prorpertyInfo in TypeEntity.GetProperties()) { ConfigProperty configProperty = new ConfigProperty(prorpertyInfo, configEntity); IFieldTraitements fieldTraitement = BaseFieldTraitement.CreateInstance(configProperty); var value = fieldTraitement.GetTestValue(prorpertyInfo); TestValyes[prorpertyInfo.Name] = value; prorpertyInfo.SetValue(EntityInstance, value); } // GetValues foreach (var prorpertyInfo in TypeEntity.GetProperties()) { ConfigProperty configProperty = new ConfigProperty(prorpertyInfo, configEntity); IFieldTraitements fieldTraitement = BaseFieldTraitement.CreateInstance(configProperty); var value = prorpertyInfo.GetValue(EntityInstance); var Exptected = TestValyes[prorpertyInfo.Name]; } } } }
/// <summary> /// Show the Entitu in EntyForm /// With default value of objet /// and Defailt value of filter /// </summary> public virtual void ShowEntity(Dictionary <string, object> CritereRechercheFiltre, EntityActions EntityAction) { // Generate the the form if is note generated CreateFieldIfNotGenerated(); // set SetpInitalize to true to not execute EventsChange isStepInitializingValues = true; BaseEntity entity = this.Entity; Type typeEntity = this.EntityBLO.TypeEntity; foreach (PropertyInfo item in ListeChampsFormulaire()) { ConfigProperty configProperty = new ConfigProperty(item, this.ConfigEntity); // Param WriteEntity_To_EntryForm_Param param = new WriteEntity_To_EntryForm_Param(); param.Entity = this.Entity; param.ConfigProperty = configProperty; param.CritereRechercheFiltre = CritereRechercheFiltre; param.FromContainer = ConteneurFormulaire; param.EntityAction = EntityAction; // Get FieldTraitement Type IFieldTraitements fieldTraitement = BaseFieldTraitement.CreateInstance(configProperty); // Invok Create Field Method fieldTraitement.ShowEntity_To_EntryForm(param); } // Fin de la phase d'initialisaiton this.isStepInitializingValues = false; }
public void Show_and_Read_Entity_In_EntryFormTest() { BaseEntryForm baseEntryForm = new BaseEntryForm(this.TaskProjectBLO); TaskProject taskProject = new TaskProjectBLO().CreateTestInstance(); // Set Default Values // Set Values foreach (var prorpertyInfo in taskProject.GetType().GetProperties()) { ConfigProperty configProperty = new ConfigProperty(prorpertyInfo, configEntity); IFieldTraitements fieldTraitement = BaseFieldTraitement.CreateInstance(configProperty); var value = fieldTraitement.GetTestValue(prorpertyInfo); // Set Value prorpertyInfo.SetValue(taskProject, value); } baseEntryForm.Entity = taskProject; // Show Entity to View baseEntryForm.ShowEntity(); // Read Entity from View baseEntryForm.ReadEntity(); }
/// <summary> /// Create Instance with Test Data /// </summary> /// <returns>Instance of TaskProject with TestData</returns> public TaskProject CreateTestInstance() { TaskProject instance = new TaskProject(); foreach (var item in instance.GetType().GetProperties()) { ConfigProperty configProperty = new ConfigProperty(item, this.ConfigEntity); IFieldTraitements fieldTraitement = BaseFieldTraitement.CreateInstance(configProperty); item.SetValue(instance, fieldTraitement.GetTestValue(item)); } return(instance); }
/// <summary> /// Initialisation de filtre /// </summary> protected void CreatFiltre() { // Default Size and Positions int width_label = 100; int height_label = 25; int width_control = 100; int height_control = 25; // List of Properties must be shown in filter var propertyListFilter = from i in BLO.TypeEntity.GetProperties() where i.GetCustomAttribute(typeof(FilterAttribute)) != null orderby((FilterAttribute)i.GetCustomAttribute(typeof(FilterAttribute))).Ordre select i; // Create Field in filter foreach (PropertyInfo propertyInfo in propertyListFilter) { // Config Property Instance ConfigProperty configProperty = new ConfigProperty(propertyInfo, this.ConfigEntity); // WidthControl int item_width_control = width_control; if (configProperty.Filter?.WidthControl != 0) { item_width_control = configProperty.Filter.WidthControl; } // Params to Create Fields CreateField_In_Filter_Params param = new CreateField_In_Filter_Params(); param.ConfigProperty = configProperty; param.SizeLabel = new Size(width_label, height_label); param.SizeControl = new Size(item_width_control, height_control); param.TabIndex = ++TabIndex; param.FilterContainer = FilterContainer; param.DefaultFilterValues = DefaultFilterValues; param.EntityBLO = BLO; // Create FieldTraitement Instance IFieldTraitements fieldTraitement = BaseFieldTraitement.CreateInstance(configProperty); BaseField baseField = null; // Invok Create Field in filter Method baseField = fieldTraitement.CreateField_In_Filter(param); baseField.ValueChanged += Filtre_SelectedValueChanged; } // End For }
/// <summary> /// Insert Column in DataGrid /// </summary> private void _Insert_Column_In_DataGrid() { int index_colonne = 0; // Create Properties Columns foreach (PropertyInfo propertyInfo in this.ShownEntityProperties) { ConfigProperty configProperty = new ConfigProperty(propertyInfo, this.EntityBLO.ConfigEntity); //Insert Column according to its Type DataGridViewColumn colonne = new DataGridViewTextBoxColumn();; index_colonne++; // Params to Creat Fields CreateFieldColumns_In_EntityDataGrid param = new CreateFieldColumns_In_EntityDataGrid(); param.Column = colonne; param.ConfigProperty = configProperty; // Create FieldTraitement Instance IFieldTraitements fieldTraitement = BaseFieldTraitement.CreateInstance(configProperty); // Invok Create Column fieldTraitement.ConfigFieldColumn_In_EntityDataGrid(param); // Insert Column in DataGriView this.dataGridView.Columns.Insert(index_colonne, param.Column); } // Create SelectedAction Columns in Last of columns if (this.EntityBLO.ConfigEntity.ListDataGridSelectedAction != null) { foreach (DataGridSelectedActionAttribute item in this.EntityBLO.ConfigEntity.ListDataGridSelectedAction) { index_colonne++; DataGridViewButtonColumn colonne = new DataGridViewButtonColumn(); colonne.HeaderText = item.Title; colonne.Text = item.Title; colonne.Name = item.TypeOfForm.FullName; colonne.Tag = item; colonne.ToolTipText = item.Description; colonne.UseColumnTextForButtonValue = true; // Insert Column in DataGriView this.dataGridView.Columns.Insert(index_colonne, colonne); } } }
/// <summary> /// Set Values to Entity /// </summary> public virtual void ReadEntity() { foreach (PropertyInfo item in ListeChampsFormulaire()) { ConfigProperty ConfigProperty = new ConfigProperty(item, this.ConfigEntity); // Find Field BaseField baseField = null; if (ConfigProperty.EntryForm?.TabPage == true) { //Control[] recherche = this.tabControlForm.Controls.Find(item.Name, true); //if (recherche.Count() > 0) // baseField = (BaseField)recherche.First(); //else // throw new FieldNotExistInFormException(); } else { Control[] recherche = this.ConteneurFormulaire.Controls.Find(item.Name, true); if (recherche.Count() > 0) { baseField = (BaseField)recherche.First(); } else { throw new FieldNotExistInFormException(); } } // Params BaseFieldTraitementParam param = new BaseFieldTraitementParam(); param.ConfigProperty = ConfigProperty; param.Entity = this.Entity; param.BaseField = baseField; param.EntityBLO = this.EntityBLO; // Get FieldTraitement Type IFieldTraitements fieldTraitement = BaseFieldTraitement.CreateInstance(param.ConfigProperty); object value = fieldTraitement.ConvertValue(param); param.Entity.GetType().GetProperty(param.ConfigProperty.PropertyInfo.Name).SetValue(param.Entity, value); } }
/// <summary> /// Field Creation /// </summary> private void CreateFieldIfNotGenerated() { // Create Field if not yet Created if (!this.AutoGenerateField || this.isGeneratedForm) { return; } this.isGeneratedForm = true; // Execute Befor Init Methode this.FormBeforInit(); // // Container // // Create FlowLayout : it containe All Filed or GroupBox of Fileds this.flowLayoutPanelForm = new FlowLayoutPanel(); this.flowLayoutPanelForm.AutoScroll = true; this.flowLayoutPanelForm.Dock = DockStyle.Fill; this.FlowLayoutContainer.Controls.Add(this.flowLayoutPanelForm); if (GwinApp.isRightToLeft) { this.flowLayoutPanelForm.FlowDirection = FlowDirection.RightToLeft; this.FlowLayoutContainer.RightToLeft = RightToLeft.Yes; } else { this.FlowLayoutContainer.RightToLeft = RightToLeft.No; this.flowLayoutPanelForm.FlowDirection = FlowDirection.LeftToRight; } // set flowLayoutPanelForm as Conteneurs du formulaire this.ConteneurFormulaire = this.flowLayoutPanelForm; #region Default Positions and Size int y_field = 0; int x_field = 0; int width_label = 100; int height_label = 10; int width_control = 200; int height_control = 25; int width_groueBox = 100; int height_groueBox = 200; // il ne sera pas utilisé Orientation orientation = Orientation.Vertical; #endregion // Init interface with TabControl this.InitTabPageInterface(); // Create GroupBoxes Dictionary <string, Control> GroupesBoxMainContainers = new Dictionary <string, Control>(); this.CreateGroupesBoxes(GroupesBoxMainContainers, width_groueBox, height_groueBox); // L'index de la touche Entrer int TabIndex = 0; // Get Properties to show in Entry Form var listeProprite = from i in this.EntityBLO.TypeEntity.GetProperties() where i.GetCustomAttribute(typeof(EntryFormAttribute)) != null orderby((EntryFormAttribute)i.GetCustomAttribute(typeof(EntryFormAttribute))).Ordre select i; // Create Field per Properites foreach (PropertyInfo item in listeProprite) { ConfigProperty configProperty = new ConfigProperty(item, this.ConfigEntity); // Field Size int width_control_config = width_control; int height_control_config = height_control; if (configProperty.EntryForm?.WidthControl != 0) { width_control_config = configProperty.EntryForm.WidthControl; } if (configProperty.EntryForm?.HeightControl != 0) { height_control_config = configProperty.EntryForm.WidthControl; } // Orientation Orientation orientation_config = orientation; if (configProperty.EntryForm?.UseOrientationField == true) { orientation_config = configProperty.EntryForm.OrientationField; } // FieldContainner Control FieldContainner = this.ConteneurFormulaire; if (configProperty.EntryForm?.GroupeBox != null && configProperty.EntryForm?.GroupeBox != string.Empty) { FieldContainner = GroupesBoxMainContainers[configProperty.EntryForm?.GroupeBox]; } BaseField baseField = null; // Params to Create Fields CreateFieldParams param = new CreateFieldParams(); param.PropertyInfo = item; param.Location = new System.Drawing.Point(x_field, y_field); param.OrientationField = orientation_config; param.SizeLabel = new Size(width_label, height_label); param.SizeControl = new Size(width_control_config, height_control_config); param.ConfigProperty = configProperty; param.TabIndex = ++TabIndex; param.EntityBLO = this.EntityBLO; // used per ManyToOne Field // param.TabControlForm = this.tabControlForm; // used per ManyToMany Field param.Entity = this.Entity; param.ConteneurFormulaire = FieldContainner; param.errorProvider = errorProvider; // Create FieldTraitement Instance IFieldTraitements fieldTraitement = BaseFieldTraitement.CreateInstance(configProperty); // Invok Create Field Method baseField = fieldTraitement.CreateField_In_EntryForm(param); // Create Value Changed to Apply Business Role if (configProperty.BusinesRole != null) { baseField.ValueChanged += ControlPropriete_ValueChanged; } // API Event if (this.EntityPLO != null) { baseField.ValueChanged += Presentation_ValueChanged; baseField.ValidatingField += Presentation_ValidatingField; } // [Bug] Validation per FieldNature if (configProperty.EntryForm?.isRequired == true) { baseField.ValidatingField += textBoxString_Validating; GwinApp.Instance.Theme.RequiredField(baseField); } // Add Field to List this.Fields.Add(baseField.Name, baseField); // Execute After Init methode }// Fin de for // TabControl for Save and Cancel button this.btEnregistrer.TabIndex = ++TabIndex; this.btAnnuler.TabIndex = ++TabIndex; // GroupeBox Style foreach (GroupBox item in this.ConteneurFormulaire.Controls.Cast <Control>().Where(c => c.GetType() == typeof(GroupBox))) { // item.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold); item.Font = new System.Drawing.Font("Microsoft Sans Serif", 14F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel, ((byte)(0))); } foreach (FlowLayoutPanel item in GroupesBoxMainContainers.Values) { item.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel, ((byte)(0))); } this.FormAfterInit(); }