public void ValueChanged(BaseEntryForm EntryForm, object sender) { BaseField field = sender as BaseField; switch (field.Name) { case nameof(LeaveAsk.leaveCategory): { //ComboBoxField leavecatfield = field as ComboBoxField; //ManyToOneField Stafffield = EntryForm.Fields[nameof(LeaveAsk.staff)] as ManyToOneField; //Staff staff = Stafffield.SelectedItem as Staff; //Int32Filed nbdays = EntryForm.Fields[nameof(LeaveAsk.nbDaysWanted)] as Int32Filed; ManyToOneField leavecatfield = EntryForm.Fields[nameof(LeaveAsk.leaveCategory)] as ManyToOneField; LeaveCategory leavecategory = leavecatfield.SelectedItem as LeaveCategory; ManyToOneField stafffield = EntryForm.Fields[nameof(LeaveAsk.staff)] as ManyToOneField; Staff staff = stafffield.SelectedItem as Staff; Int32Filed nbdays = EntryForm.Fields[nameof(LeaveAsk.nbDaysWanted)] as Int32Filed; if (leavecategory.Reference == "Administrativeleave") { staff.nbTotalDaysAdmin = staff.nbTotalDaysAdmin - nbdays; } } break; } }
public void ManyToOneField_WithOutFilter() { // Model Data : Trainee, Groupe, Speciality using (ModelContext db = new ModelContext()) { Panel Container = new Panel(); Size SizeLabel = new Size(100, 20); Size SizeControl = new Size(100, 20); IGwinBaseBLO GroupeBLO = new GwinBaseBLO <Group>(db); PropertyInfo SpecialtyPropertyInfo = typeof(Group).GetProperty(nameof(Group.Specialty)); ConfigEntity configEntity = ConfigEntity.CreateConfigEntity(typeof(Group)); Group trainee = new Group(); Specialty Specialty = db.Specialtys.Where(s => s.Reference == "TDI").SingleOrDefault(); ManyToOneField manyToOneField = new ManyToOneField( GroupeBLO, SpecialtyPropertyInfo, Container, Orientation.Vertical, SizeLabel, SizeControl, Specialty.Id, configEntity, trainee); // Selected the first Groupe manyToOneField.SelectedIndex = 0; } }
/// <summary> /// Affichage des données dans les ComboBox /// </summary> protected void ViewingData() { // Affichage des données du premiere comboBox // les autres comboBox sont afficher par l'événement ValueChange du ComboBox if (ListeComboBox.Values.Count() <= 0) { return; } ManyToOneField comboBox = ListeComboBox.Values.ElementAt(0); string key = ListeComboBox.Keys.ElementAt(0); IGwinBaseBLO service = this.Service .CreateServiceBLOInstanceByTypeEntity(LsiteTypeObjetCritere[key]); IList ls_source = service.GetAll(); // Add Black Value if requorid if (this.ConfigProperty?.EntryForm?.isDefaultIsEmpty == true || this.ConfigProperty?.Filter?.isDefaultIsEmpty == true) { ls_source.Insert(0, new EmptyEntity()); } // Initalisation avec la valeur par défaux s'il existe if (this.ListeValeursInitiaux != null && this.ListeValeursInitiaux.Keys.Contains(key)) { this.StopEventSelectedIndexChange = true; comboBox.DataSource = ls_source; this.StopEventSelectedIndexChange = false; comboBox.SelectedValue = this.ListeValeursInitiaux[key]; } else { comboBox.DataSource = ls_source; } }
public BaseField CreateField_In_Filter(CreateField_In_Filter_Params param) { // Default Value Int64 default_value = 0; if (param.DefaultFilterValues != null && param.DefaultFilterValues.Keys.Contains(param.ConfigProperty.PropertyInfo.PropertyType.Name)) { default_value = (Int64)param.DefaultFilterValues[param.ConfigProperty.PropertyInfo.PropertyType.Name]; } ManyToOneField manyToOneField = new ManyToOneField(param.EntityBLO, param.ConfigProperty.PropertyInfo, param.FilterContainer, Orientation.Horizontal, param.SizeLabel, param.SizeControl, default_value, param.ConfigProperty.ConfigEntity, param.Entity ); manyToOneField.Name = param.ConfigProperty.PropertyInfo.Name; manyToOneField.TabIndex = param.TabIndex; manyToOneField.Text_Label = param.ConfigProperty.DisplayProperty.Title; param.FilterContainer.Controls.Add(manyToOneField); return(manyToOneField); }
/// <summary> /// Affichage des données dans les ComboBox /// </summary> protected void ViewingData() { // Affichage des données du premiere comboBox // les autres comboBox sont afficher par l'événement ValueChange du ComboBox if (ListeComboBox.Values.Count() <= 0) { return; } ManyToOneField comboBox = ListeComboBox.Values.ElementAt(0); string key = ListeComboBox.Keys.ElementAt(0); IBaseRepository service = this.Service .CreateInstance_Of_Service_From_TypeEntity(LsiteTypeObjetCritere[key]); // Initalisation avec la valeur par défaux s'il existe if (this.ListeValeursInitiaux != null && this.ListeValeursInitiaux.Keys.Contains(key)) { this.StopEventSelectedIndexChange = true; comboBox.DataSource = service.GetAll(); this.StopEventSelectedIndexChange = false; comboBox.SelectedValue = this.ListeValeursInitiaux[key]; } else { comboBox.DataSource = service.GetAll(); } }
public void ShowCars(MeansTransportCategories meansTransportCategories, Staff staff, BaseEntryForm EntryForm) { if (staff == null || meansTransportCategories == MeansTransportCategories.Public) { EntryForm.Fields[nameof(MissionOrder.Car)].Hide(); } else if (staff != null && meansTransportCategories == MeansTransportCategories.Public) { EntryForm.Fields[nameof(MissionOrder.Car)].Hide(); } else if (staff == null && meansTransportCategories == MeansTransportCategories.Voiture_de_Service) { EntryForm.Fields[nameof(MissionOrder.Car)].Show(); ManyToOneField CarField = EntryForm.Fields[nameof(MissionOrder.Car)] as ManyToOneField; List <Car> ls = new ModelContext().Cars.Where(r => r.PersonelCar == false).ToList <Car>(); CarField.DataSource = ls; if (ls.Count < 1) { CarField.TextCombobox = ""; } } else if (staff != null && meansTransportCategories == MeansTransportCategories.Voiture_de_Service) { EntryForm.Fields[nameof(MissionOrder.Car)].Show(); ManyToOneField CarField = EntryForm.Fields[nameof(MissionOrder.Car)] as ManyToOneField; List <Car> ls = new ModelContext().Cars.Where(r => r.PersonelCar == false).ToList <Car>(); CarField.DataSource = ls; if (ls.Count < 1) { CarField.TextCombobox = ""; } } else if (staff == null && meansTransportCategories == MeansTransportCategories.Voiture_Personnel) { EntryForm.Fields[nameof(MissionOrder.Car)].Show(); } else if (staff != null && meansTransportCategories == MeansTransportCategories.Voiture_Personnel) { ManyToOneField CarField = EntryForm.Fields[nameof(MissionOrder.Car)] as ManyToOneField; List <Car> ls = new ModelContext().Cars.Where(r => r.Staff.Id == staff.Id).ToList <Car>(); CarField.DataSource = ls; EntryForm.Fields[nameof(MissionOrder.Car)].Show(); if (ls.Count < 1) { CarField.TextCombobox = ""; } } }
public object GetFieldValue_From_Filter(Control FilterContainer, ConfigProperty ConfigProperty) { ManyToOneField ComboBoxEntity = (ManyToOneField)FilterContainer.Controls.Find(ConfigProperty.PropertyInfo.Name, true).First(); BaseEntity obj = (BaseEntity)ComboBoxEntity.SelectedItem; if (obj != null && Convert.ToInt32(obj.Id) != 0) { return(ComboBoxEntity.Value); } else { return(null); } }
/// <summary> /// Affichage du filtre dans l'interface /// Remplissage de ListeComboBox /// </summary> private void InitInterface() { this.DisplayMember = ""; this.ValueMember = "Id"; int index = 10; // Si un objet du critère de selection exite dans la classe // Nous cherchons sa valeur pour l'utiliser foreach (Type item in this.ConfigProperty.SelectionCriteria.CriteriasTypes) { // Meta information d'affichage du de Critère GwinEntityAttribute DisplayEntityAttributeCritere = (GwinEntityAttribute)item.GetCustomAttribute(typeof(GwinEntityAttribute)); // Size Filter Item Size SizeControlFilter = new Size(this.SizeControl.Width, 25); ManyToOneField manyToOneFilter = new ManyToOneField(this.Service, item, null, null, this.OrientationFiled, this.SizeLabel, SizeControlFilter, 0, this.ConfigProperty.ConfigEntity, this.ValueEntity ); manyToOneFilter.Name = item.Name; //manyToOneFilter.Size = new System.Drawing.Size(this.widthField, this.HeightField); manyToOneFilter.TabIndex = ++index; manyToOneFilter.Text_Label = item.Name; manyToOneFilter.ValueMember = "Id"; manyToOneFilter.DisplayMember = DisplayEntityAttributeCritere.DisplayMember; // pour le chargement de comboBox Suivant manyToOneFilter.ValueChanged += Value_SelectedIndexChanged; manyToOneFilter.Visible = true; // [bug] Le contôle ne s'affiche pas dans le formilaire ?? //Form f = new Form(); //f.Controls.Add(manyToOneFilter); //f.Show(); this.MainContainner.Controls.Add(manyToOneFilter); ListeComboBox.Add(item.Name, manyToOneFilter); LsiteTypeObjetCritere.Add(item.Name, item); } }
public void ValueChanged(BaseEntryForm EntryForm, object sender) { //// In //if ((bool)EntryForm.Fields[nameof(MaterialInOut.InStock)].Value == true) //{ // EntryForm.Fields[nameof(MaterialInOut.InDate)].Show(); // EntryForm.Fields[nameof(MaterialInOut.InReason)].Show(); //} //else //{ // EntryForm.Fields[nameof(MaterialInOut.InDate)].Hide(); // EntryForm.Fields[nameof(MaterialInOut.InReason)].Hide(); //} // Location BaseField field = sender as BaseField; switch (field.Name) { // Location case nameof(MaterialInOut.Service): { ManyToOneField servicefield = field as ManyToOneField; Service service = servicefield.SelectedItem as Service; if (service != null && new LocationBLO(db).LocationsByService(service).Count > 0) { EntryForm.Fields[nameof(MaterialInOut.Location)].Show(); ManyToOneField LocationField = EntryForm.Fields[nameof(MaterialInOut.Location)] as ManyToOneField; List <Location> lc = new LocationBLO(db).LocationsByService(service); LocationField.DataSource = lc; } else { EntryForm.Fields[nameof(MaterialInOut.Location)].Hide(); } } break; } }
/// <summary> /// CreateField in EntryForm /// /// </summary> /// <param name="param"> /// param.PropertyInfo /// param.Location /// param.OrientationField /// param.SizeLabel /// param.SizeControl /// param.ConfigProperty /// param.TabIndex /// param.Service /// param.ConfigEntity /// param.TabControlForm /// param.Entity /// param.ConteneurFormulaire /// </param> /// <returns>the created field</returns> public BaseField CreateField_In_EntryForm(CreateFieldParams param) { Int64 InitValue = 0; ManyToOneField manyToOneField = new ManyToOneField(param.EntityBLO, param.PropertyInfo, param.ConteneurFormulaire, param.OrientationField, param.SizeLabel, param.SizeControl, InitValue, param.ConfigProperty.ConfigEntity, param.Entity ); manyToOneField.Location = param.Location; manyToOneField.Name = param.PropertyInfo.Name; manyToOneField.TabIndex = param.TabIndex; manyToOneField.Text_Label = param.ConfigProperty.DisplayProperty.Title; // Inert in to Interface param.ConteneurFormulaire.Controls.Add(manyToOneField); return(manyToOneField); }
public void ValueChanged(BaseEntryForm EntryForm, object sender) { BaseField field = sender as BaseField; switch (field.Name) { case nameof(AdvancementGrade.gradecategory): { ManyToOneField gradecatfield = field as ManyToOneField; GradeCategory gradecategory = gradecatfield.SelectedItem as GradeCategory; if (gradecategory != null) { EntryForm.Fields[nameof(AdvancementGrade.grade)].Show(); ManyToOneField gradefield = EntryForm.Fields[nameof(AdvancementGrade.grade)] as ManyToOneField; List <StaffGrade> ls = gradecategory.grades; gradefield.DataSource = ls; } } break; } }
public void ManyToOneField_WithFilter() { // Model Data : Trainee, Groupe, Speciality using (ModelContext db = new ModelContext()) { Panel Container = new Panel(); Size SizeLabel = new Size(100, 20); Size SizeControl = new Size(100, 20); IGwinBaseBLO TraineeBLO = new GwinBaseBLO <Trainee>(db); PropertyInfo groupePropertyInfo = typeof(Trainee).GetProperty(nameof(Trainee.Group)); ConfigEntity configEntity = ConfigEntity.CreateConfigEntity(typeof(Trainee)); Trainee trainee = new Trainee(); ManyToOneField manyToOneField = new ManyToOneField( TraineeBLO, groupePropertyInfo, Container, Orientation.Vertical, SizeLabel, SizeControl, 0, configEntity, trainee); // Selected the first speciality // selectedindex = 1 , index 0 for EmptyData manyToOneField .SelectionFilterManager .ListeComboBox[typeof(Specialty).Name] .SelectedIndex = 1; // Selected the first Groupe manyToOneField.SelectedIndex = 0; } }
/// <summary> /// Création et Initalisation des contrôles du formulaire /// </summary> private void GenerateFormIfNotGenerated() { // Generate if not generated if (!this.AutoGenerateField || this.isGeneratedForm) { return; } this.isGeneratedForm = true; #region Taille par défaut // Positions et Tailles par défaut 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 par défaut Orientation orientation = Orientation.Vertical; #endregion #region Préparation de l'interface par Panel et GroupeBox // Initalisation de l'interface avec TabControl this.InitTabPageInterface(); // Création des groupBox s'il existe Dictionary <string, Control> GroupesBoxMainContainers = new Dictionary <string, Control>(); this.CreateGroupesBoxes(GroupesBoxMainContainers, width_groueBox, height_groueBox); #endregion // L'index de la touche Entrer int TabIndex = 0; var listeProprite = from i in this.Service.TypeEntity.GetProperties() where i.GetCustomAttribute(typeof(EntryFormAttribute)) != null orderby((EntryFormAttribute)i.GetCustomAttribute(typeof(EntryFormAttribute))).Ordre select i; // Affichage des champs par leurs type foreach (PropertyInfo item in listeProprite) { #region Recalcule des valeurs pardéfaut selon l'annotation de chauqe champs // l'annotation ConfigProperty configProperty = new ConfigProperty(item, this.ConfigEntity); // Taile du Field int width_control_config = width_control; if (configProperty.EntryForm?.WidthControl != 0) { width_control_config = configProperty.EntryForm.WidthControl; } // Orientation Orientation orientation_config = orientation; if (configProperty.EntryForm?.UseOrientationField == true) { orientation_config = configProperty.EntryForm.OrientationField; } #endregion Control field_control = null; Control FiledContainner = this.ConteneurFormulaire; if (configProperty.EntryForm?.GroupeBox != null && configProperty.EntryForm?.GroupeBox != string.Empty) { FiledContainner = GroupesBoxMainContainers[configProperty.EntryForm?.GroupeBox]; } switch (item.PropertyType.Name) { #region Champs String case "String": StringField stringFiled = new StringField( item, orientation_config, new Size(width_label, height_label), new Size(width_control_config, height_control), this.ConfigEntity); stringFiled.Location = new System.Drawing.Point(x_field, y_field); stringFiled.Name = item.Name; stringFiled.TabIndex = ++TabIndex; stringFiled.Text_Label = configProperty.DisplayProperty.Titre; stringFiled.FieldChanged += ControlPropriete_ValueChanged; if (configProperty.EntryForm?.isOblegatoir == true) { stringFiled.ValidatingFiled += textBoxString_Validating; } // Insertion à l'interface this.ConteneurFormulaire.Controls.Add(stringFiled); field_control = stringFiled; break; #endregion #region Champs Int32 case "Int32": Int32Filed int32Filed = new Int32Filed( item, orientation_config, new Size(width_label, height_label), new Size(width_control_config, height_control), this.ConfigEntity); int32Filed.Location = new System.Drawing.Point(x_field, y_field); int32Filed.Name = item.Name; int32Filed.TabIndex = ++TabIndex; int32Filed.Text_Label = configProperty.DisplayProperty.Titre; int32Filed.FieldChanged += ControlPropriete_ValueChanged; if (configProperty.EntryForm?.isOblegatoir == true) { int32Filed.ValidatingFiled += TextBoxInt32_Validating; } // Insertion à l'interface this.ConteneurFormulaire.Controls.Add(int32Filed); field_control = int32Filed; break; #endregion #region Champs DateTime case "DateTime": DateTimeField dateTimeField = new DateTimeField( item, orientation_config, new Size(width_label, height_label), new Size(width_control_config, height_control), this.ConfigEntity); dateTimeField.Location = new System.Drawing.Point(x_field, y_field); dateTimeField.Name = item.Name; dateTimeField.TabIndex = ++TabIndex; dateTimeField.Text_Label = configProperty.DisplayProperty.Titre; dateTimeField.FieldChanged += ControlPropriete_ValueChanged; if (configProperty.EntryForm?.isOblegatoir == true) { dateTimeField.ValidatingFiled += DateTimePicker_Validating; } // Insertion à l'interface this.ConteneurFormulaire.Controls.Add(dateTimeField); field_control = dateTimeField; break; #endregion default: { #region Champs : ManyToOne if (configProperty.Relationship?.Relation == RelationshipAttribute.Relations.ManyToOne) { // Déterminer le contenue du Field ManyToOne : GroupeBox ou Panel Control ConteneurManyToMany = this.ConteneurFormulaire; if (configProperty.EntryForm?.GroupeBox != null && configProperty.EntryForm?.GroupeBox != string.Empty) { ConteneurManyToMany = GroupesBoxMainContainers[configProperty.EntryForm?.GroupeBox]; } // Création de champs ManyToOneField Int64 InitValue = 0; //if (ValeursFiltre != null && ValeursFiltre.Keys.Contains(properperty.DisplayProperty.TitretyInfo.Name)) // default_value = (Int64)ValeursFiltre[propertyInfo.Name]; ManyToOneField manyToOneField = new ManyToOneField(this.Service, item, ConteneurManyToMany, orientation_config, new Size(width_label, height_label), new Size(width_control_config, height_control), InitValue, this.ConfigEntity ); manyToOneField.Location = new System.Drawing.Point(x_field, y_field); manyToOneField.Name = item.Name; manyToOneField.TabIndex = ++TabIndex; manyToOneField.Text_Label = configProperty.DisplayProperty.Titre; manyToOneField.FieldChanged += ControlPropriete_ValueChanged; if (configProperty.EntryForm?.isOblegatoir == true) { manyToOneField.Validating += ComboBox_Validating; } this.ConteneurFormulaire.Controls.Add(manyToOneField); field_control = manyToOneField; } #endregion #region Champs ManyToMany if (configProperty.Relationship?.Relation == RelationshipAttribute.Relations.ManyToMany) { if (configProperty.EntryForm?.TabPage == true) { TabPage tabPage = new TabPage(); tabPage.Name = "tabPage" + item.Name; tabPage.Text = configProperty.DisplayProperty.Titre; tabControlForm.TabPages.Add(tabPage); FiledContainner = tabPage; } //Trouver les Valeurs par défaut List <BaseEntity> ls_default_value = null; if (this.Entity != null) { IList ls_obj = item.GetValue(this.Entity) as IList; if (ls_obj != null) { ls_default_value = ls_obj.Cast <BaseEntity>().ToList(); } } ManyToManyField manyToManyField = new ManyToManyField(item, orientation_config, new Size(width_label, height_label), new Size(width_control_config, height_control), this.ConfigEntity, FiledContainner, this.Service); manyToManyField.Name = item.Name; manyToManyField.FieldChanged += ControlPropriete_ValueChanged; if (configProperty.EntryForm?.TabPage == true) { manyToManyField.Dock = DockStyle.Fill; } field_control = manyToManyField; } #endregion } break; } // Fin de suitch FiledContainner.Controls.Add(field_control); // Insertion du Champs dans sa GroupeBox si il existe // [Bug] il n'est pas supprimé de l'inrface, car il est déja ajouté }// Fin de for // TabControl sur Enregistrer et Annuler this.btEnregistrer.TabIndex = ++TabIndex; this.btAnnuler.TabIndex = ++TabIndex; 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))); } }
public void ValueChanged(BaseEntryForm EntryForm, object sender) { BaseField field = sender as BaseField; switch (field.Name) { case nameof(MissionOrder.MissionConvocation): { ManyToOneField missionField = field as ManyToOneField; MissionConvocation MissionConvocation = missionField.SelectedItem as MissionConvocation; if (MissionConvocation != null) { EntryForm.Fields[nameof(MissionOrder.Staff)].Show(); ManyToOneField StaffField = EntryForm.Fields[nameof(MissionOrder.Staff)] as ManyToOneField; List <Staff> ls = MissionConvocation.Staffs; // ls.Insert(0, new Staff()); throw Datetime2 exception StaffField.DataSource = ls; } } break; case nameof(MissionOrder.MeansTransportCategory): { ComboBoxField missioncarfieled = field as ComboBoxField; meanscatG = (MeansTransportCategories)missioncarfieled.Value; this.ShowCars(meanscatG, staffG, EntryForm); } break; case nameof(MissionOrder.Validation): { BooleanField missionValiditionfield = field as BooleanField; bool validation = (bool)missionValiditionfield.Value; if (validation) { EntryForm.Fields[nameof(MissionOrder.ValidationDate)].Show(); BooleanField validitionfield = EntryForm.Fields[nameof(MissionOrder.ValidationDate)] as BooleanField; } else { EntryForm.Fields[nameof(MissionOrder.ValidationDate)].Hide(); BooleanField validitionfield = EntryForm.Fields[nameof(MissionOrder.ValidationDate)] as BooleanField; } } break; case nameof(MissionOrder.Staff): { ManyToOneField missionStaffield = field as ManyToOneField; staffG = missionStaffield.SelectedItem as Staff; this.ShowCars(meanscatG, staffG, EntryForm); } break; } }
/// <summary> /// Initialisation de filtre /// </summary> protected void initFiltre() { // Postion et Taille par défaut int width_label = 100; int height_label = 25; int width_control = 100; int height_control = 20; int TabIndex = 0; var propertyListFilter = from i in Service.TypeEntity.GetProperties() where i.GetCustomAttribute(typeof(FilterAttribute)) != null orderby((FilterAttribute)i.GetCustomAttribute(typeof(FilterAttribute))).Ordre select i; // Insertion des critère de recherche par Type foreach (PropertyInfo propertyInfo in propertyListFilter) { ConfigProperty attributesOfProperty = new ConfigProperty(propertyInfo, this.ConfigEntity); // Utiliser le Largeur de la configuration s'il existe int item_width_control = width_control; if (attributesOfProperty.Filter?.WidthControl != 0) { item_width_control = attributesOfProperty.Filter.WidthControl; } if (propertyInfo.PropertyType.Name == "String") { StringField stringFiled = new StringField( propertyInfo, Orientation.Horizontal, new Size(width_label, height_label), new Size(item_width_control, height_control) , this.ConfigEntity); stringFiled.Name = propertyInfo.Name; stringFiled.TabIndex = TabIndex++; stringFiled.Text_Label = attributesOfProperty.DisplayProperty.Titre; stringFiled.FieldChanged += Filtre_TextBox_SelectedValueChanged; MainContainer.Controls.Add(stringFiled); } if (propertyInfo.PropertyType.Name == "Int32") { Int32Filed int32Filed = new Int32Filed(propertyInfo, Orientation.Vertical, new Size(width_label, height_label), new Size(item_width_control, height_control), this.ConfigEntity ); int32Filed.Name = propertyInfo.Name; int32Filed.TabIndex = TabIndex++; int32Filed.Text_Label = attributesOfProperty.DisplayProperty.Titre; int32Filed.FieldChanged += Filtre_TextBox_SelectedValueChanged; MainContainer.Controls.Add(int32Filed); } if (propertyInfo.PropertyType.Name == "DateTime") { DateTimeField dateTimeField = new DateTimeField(propertyInfo, Orientation.Vertical, new Size(width_label, height_label), new Size(item_width_control, height_control), this.ConfigEntity ); dateTimeField.Name = propertyInfo.Name; dateTimeField.TabIndex = TabIndex++; dateTimeField.Text_Label = attributesOfProperty.DisplayProperty.Titre; dateTimeField.FieldChanged += Filtre_TextBox_SelectedValueChanged; MainContainer.Controls.Add(dateTimeField); } // // Relation ManyToOne // if (attributesOfProperty.Relationship?.Relation != RelationshipAttribute.Relations.Empty && attributesOfProperty.Relationship?.Relation == RelationshipAttribute.Relations.ManyToOne) { // La valeurs pardéfaut Int64 default_value = 0; if (ValeursFiltre != null && ValeursFiltre.Keys.Contains(propertyInfo.PropertyType.Name)) { default_value = (Int64)ValeursFiltre[propertyInfo.PropertyType.Name]; } ManyToOneField manyToOneField = new ManyToOneField(this.Service, propertyInfo, this.MainContainer, Orientation.Horizontal, new Size(width_label, height_label), new Size(item_width_control, height_control), default_value, ConfigEntity ); manyToOneField.Name = propertyInfo.Name; manyToOneField.TabIndex = TabIndex++; manyToOneField.Text_Label = attributesOfProperty.DisplayProperty.Titre; manyToOneField.FieldChanged += Filtre_ComboBox_SelectedValueChanged; MainContainer.Controls.Add(manyToOneField); // // Remplissage de ComboBox // //Type ServicesEntityEnRelationType = typeof(BaseRepository<>).MakeGenericType(propertyInfo.PropertyType); //IBaseRepository ServicesEntity = (IBaseRepository)Activator.CreateInstance(ServicesEntityEnRelationType); //List<object> ls = ServicesEntity.GetAllDetached(); //manyToOneField.ValueMember = "Id"; //manyToOneField.DisplayMember = AffichagePropriete.DisplayMember; //manyToOneField.DataSource = ls; //if (AffichagePropriete.isValeurFiltreVide) manyToOneField.SelectedIndex = -1; //// Affectation de valeur initial //if (this.ValeursFiltre != null && this.ValeursFiltre.ContainsKey(propertyInfo.Name)) //{ // manyToOneField.CreateControl(); // manyToOneField.Value = Convert.ToInt64(this.ValeursFiltre[propertyInfo.Name]); //} } //if (MainContainer.Controls.Count > 0) //{ // int max_h = this.MainContainer.Controls.Cast<Control>().Max(c => c.Size.Height); // this.MainContainer.Size = new Size(this.MainContainer.Size.Width, max_h); //} } // End For }
/// <summary> /// Obtient les valeurs du filtre /// </summary> /// <returns></returns> public Dictionary <string, object> CritereRechercheFiltre() { // Application de filtre Dictionary <string, object> RechercheInfos = new Dictionary <string, object>(); var PropertyListFilter = from i in Service.TypeEntity.GetProperties() where i.GetCustomAttribute(typeof(FilterAttribute)) != null orderby((FilterAttribute)i.GetCustomAttribute(typeof(FilterAttribute))).Ordre select i; foreach (PropertyInfo propertyInfo in PropertyListFilter) { switch (propertyInfo.PropertyType.Name) { case "String": { StringField stringFiled = (StringField)this.groupBoxFiltrage.Controls.Find(propertyInfo.Name, true).First(); if (stringFiled.Value != String.Empty) { RechercheInfos[propertyInfo.Name] = stringFiled.Value; } } break; case "Int32": { Int32Filed int32Filed = (Int32Filed)this.groupBoxFiltrage.Controls.Find(propertyInfo.Name, true).First(); if ((int)int32Filed.Value != 0) { RechercheInfos[propertyInfo.Name] = int32Filed.Value; } } break; case "DateTime": { DateTimeField dateTimeField = (DateTimeField)this.groupBoxFiltrage.Controls.Find(propertyInfo.Name, true).First(); if ((DateTime)dateTimeField.Value != DateTime.MinValue) { RechercheInfos[propertyInfo.Name] = dateTimeField.Value; } } break; default: // Dans le cas d'un objet de type BaseEntity { ConfigProperty ConfigProperty = new ConfigProperty(propertyInfo, this.ConfigEntity); if (ConfigProperty.Relationship.Relation == RelationshipAttribute.Relations.ManyToOne) { // [bug] groupBoxFiltrage doit être MainContainner ManyToOneField ComboBoxEntity = (ManyToOneField)this.groupBoxFiltrage.Controls.Find(propertyInfo.Name, true).First(); BaseEntity obj = (BaseEntity)ComboBoxEntity.SelectedItem; if (obj != null && Convert.ToInt32(obj.Id) != 0) { RechercheInfos[propertyInfo.Name] = obj.Id; } } } break; } } return(RechercheInfos); }
/// <summary> /// Initialisation de filtre /// </summary> protected void initFiltre() { // Postion et Taille par défaut int width_label = 50; int height_label = 20; int width_control = 50; int height_control = 20; int TabIndex = 0; // Insertion des critère de recherche par Type foreach (PropertyInfo propertyInfo in PropertyListFilter()) { // Trouver l'objet AffichagePropriete depuis l'annotation Attribute getAffichagePropriete = propertyInfo.GetCustomAttribute(typeof(AffichageProprieteAttribute)); if (getAffichagePropriete == null) { continue; } AffichageProprieteAttribute AffichagePropriete = (AffichageProprieteAttribute)getAffichagePropriete; if (AffichagePropriete.Filtre == false) { continue; } // Utiliser le Largeur de la configuration s'il existe int item_width_control = width_control; if (AffichagePropriete.WidthColonne != 0) { item_width_control = AffichagePropriete.WidthColonne; } if (propertyInfo.PropertyType.Name == "String") { StringFiled stringFiled = new StringFiled(propertyInfo, Orientation.Horizontal, new Size(width_label, height_label), new Size(item_width_control, height_control)); stringFiled.Name = propertyInfo.Name; stringFiled.TabIndex = TabIndex++; stringFiled.Text_Label = AffichagePropriete.Titre; stringFiled.FieldChanged += Filtre_TextBox_SelectedValueChanged; MainContainer.Controls.Add(stringFiled); } if (propertyInfo.PropertyType.Name == "Int32") { Int32Filed int32Filed = new Int32Filed(propertyInfo, Orientation.Vertical, new Size(width_label, height_label), new Size(item_width_control, height_control) ); int32Filed.Name = propertyInfo.Name; int32Filed.TabIndex = TabIndex++; int32Filed.Text_Label = AffichagePropriete.Titre; int32Filed.FieldChanged += Filtre_TextBox_SelectedValueChanged; MainContainer.Controls.Add(int32Filed); } if (propertyInfo.PropertyType.Name == "DateTime") { DateTimeField dateTimeField = new DateTimeField(propertyInfo, Orientation.Vertical, new Size(width_label, height_label), new Size(item_width_control, height_control) ); dateTimeField.Name = propertyInfo.Name; dateTimeField.TabIndex = TabIndex++; dateTimeField.Text_Label = AffichagePropriete.Titre; dateTimeField.FieldChanged += Filtre_TextBox_SelectedValueChanged; MainContainer.Controls.Add(dateTimeField); } // // Relation ManyToOne // if (AffichagePropriete.Relation != String.Empty && AffichagePropriete.Relation == AffichageProprieteAttribute.RELATION_MANYTOONE) { // La valeurs pardéfaut Int64 default_value = 0; if (ValeursFiltre != null && ValeursFiltre.Keys.Contains(propertyInfo.Name)) { default_value = (Int64)ValeursFiltre[propertyInfo.Name]; } ManyToOneField manyToOneField = new ManyToOneField(this.Service, propertyInfo, this.MainContainer, Orientation.Horizontal, new Size(width_label, height_label), new Size(item_width_control, height_control), default_value ); manyToOneField.Name = propertyInfo.Name; manyToOneField.TabIndex = TabIndex++; manyToOneField.Text_Label = AffichagePropriete.Titre; manyToOneField.FieldChanged += Filtre_ComboBox_SelectedValueChanged; MainContainer.Controls.Add(manyToOneField); // // Remplissage de ComboBox // //Type ServicesEntityEnRelationType = typeof(BaseRepository<>).MakeGenericType(propertyInfo.PropertyType); //IBaseRepository ServicesEntity = (IBaseRepository)Activator.CreateInstance(ServicesEntityEnRelationType); //List<object> ls = ServicesEntity.GetAllDetached(); //manyToOneField.ValueMember = "Id"; //manyToOneField.DisplayMember = AffichagePropriete.DisplayMember; //manyToOneField.DataSource = ls; //if (AffichagePropriete.isValeurFiltreVide) manyToOneField.SelectedIndex = -1; //// Affectation de valeur initial //if (this.ValeursFiltre != null && this.ValeursFiltre.ContainsKey(propertyInfo.Name)) //{ // manyToOneField.CreateControl(); // manyToOneField.Value = Convert.ToInt64(this.ValeursFiltre[propertyInfo.Name]); //} } //if (MainContainer.Controls.Count > 0) //{ // int max_h = this.MainContainer.Controls.Cast<Control>().Max(c => c.Size.Height); // this.MainContainer.Size = new Size(this.MainContainer.Size.Width, max_h); //} } // End For }
/// <summary> /// Chargement des comboBox suivants /// il s'exécute aprés le changement du valeur de chaque comboBox /// à chaque changement d'un comboBox on charge les données de comboBox suivant /// </summary> private void Value_SelectedIndexChanged(object sender, EventArgs e) { // n'exécuter pas cette événement, si nous somme à l'étape d'initialisation // des chmpas de critères if (this.StopEventSelectedIndexChange) { return; } // Initialisation de ComboBox, Service, Entite qui a ête changé ManyToOneField comboBoxChanged = (ManyToOneField)sender; comboBoxChanged.CreateControl(); int indexComboBoxChanged = ListeComboBox.Values.ToList <ManyToOneField>().IndexOf(comboBoxChanged); string keyComboBoxCanged = ListeComboBox.Keys.ElementAt(indexComboBoxChanged); IBaseRepository serviceComboBoxActuel = this.Service .CreateInstance_Of_Service_From_TypeEntity(LsiteTypeObjetCritere[keyComboBoxCanged]); BaseEntity EntiteActuel = serviceComboBoxActuel.GetBaseEntityByID(Convert.ToInt64(comboBoxChanged.SelectedValue)); /// Actualisation de ComboBox suivant s'il existe /// Le ComboBox suivant prend les valeurs de l'Entite actuel de comboBox /// car l'entité actuel doit avoir une prorpiété de type type Collection de l'entityé suivant /// Le nom de cette propiété égale Nom d'entité suivant + "s" /// si cette propiété n'existe pas la méthode lance une exception if (comboBoxChanged.SelectedValue != null && (ListeComboBox.Values.Count() - 1) >= (indexComboBoxChanged + 1)) { // ComboBox suivant ManyToOneField nextComboBox = ListeComboBox.Values.ElementAt(indexComboBoxChanged + 1); string keyNexComboBox = ListeComboBox.Keys.ElementAt(indexComboBoxChanged + 1); PropertyInfo PropertyContenantValeursComboSuivant = EntiteActuel.GetType() .GetProperties() .Where(p => p.Name == keyNexComboBox + "s") .SingleOrDefault(); if (PropertyContenantValeursComboSuivant == null) { throw new PropertyNotExistInEntityException(keyNexComboBox + "s"); } // Affectation des valeurs au ComboBox suivant IList ls_source = null; if (PropertyContenantValeursComboSuivant != null) { ls_source = PropertyContenantValeursComboSuivant.GetValue(EntiteActuel) as IList; // Initalisation avec la valeur par défaux s'il existe if (this.ListeValeursInitiaux != null && this.ListeValeursInitiaux.Keys.Contains(keyNexComboBox)) { this.StopEventSelectedIndexChange = true; nextComboBox.DataSource = null; nextComboBox.DataSource = ls_source; this.StopEventSelectedIndexChange = false; nextComboBox.SelectedValue = this.ListeValeursInitiaux[keyNexComboBox]; } else { nextComboBox.DataSource = ls_source; } } // Si ce Combo n'a pas d'information alors vider les combBobx suivant if (ls_source == null || ls_source.Count == 0) { for (int i = (indexComboBoxChanged + 1); i < ListeComboBox.Values.Count(); i++) { ManyToOneField comboBox_suivant2 = ListeComboBox.Values.ElementAt(i); comboBox_suivant2.DataSource = null; comboBox_suivant2.TextCombobox = ""; } } } else { // si la selection de dernier ComboBox on lance l'événement ValueChanged onValueChaned(this, null); } }
/// <summary> /// Affichage du filtre dans l'interface /// Remplissage de ListeComboBox /// </summary> private void InitInterface() { this.DisplayMember = ""; this.ValueMember = "Id"; Attribute selectionCriteriaAttribute = this.PropertyInfo.PropertyType.GetGenericArguments()[0] .GetCustomAttribute(typeof(SelectionCriteriaAttribute)); if (selectionCriteriaAttribute == null) { return; } SelectionCriteriaAttribute MetaSelectionCriteria = (SelectionCriteriaAttribute)selectionCriteriaAttribute; if (MetaSelectionCriteria == null) { this.isHasFilter = false; } else { this.isHasFilter = true; } int index = 10; // Si un objet du critère de selection exite dans la classe // Nous cherchons sa valeur pour l'utiliser foreach (Type item in MetaSelectionCriteria.Criteria) { // Meta information d'affichage du de Critère DisplayEntityAttribute DisplayEntityAttributeCritere = (DisplayEntityAttribute)item.GetCustomAttribute(typeof(DisplayEntityAttribute)); ManyToOneField manyToOneFilter = new ManyToOneField(this.Service, item, null, null, this.OrientationFiled, this.SizeLabel, this.SizeControl, 0, this.ConfigEntity ); manyToOneFilter.Name = item.Name; //manyToOneFilter.Size = new System.Drawing.Size(this.widthField, this.HeightField); manyToOneFilter.TabIndex = ++index; manyToOneFilter.Text_Label = item.Name; manyToOneFilter.ValueMember = "Id"; manyToOneFilter.DisplayMember = DisplayEntityAttributeCritere.DisplayMember; // pour le chargement de comboBox Suivant manyToOneFilter.FieldChanged += Value_SelectedIndexChanged; manyToOneFilter.Visible = true; // [bug] Le contôle ne s'affiche pas dans le formilaire ?? //Form f = new Form(); //f.Controls.Add(manyToOneFilter); //f.Show(); this.MainContainner.Controls.Add(manyToOneFilter); ListeComboBox.Add(item.Name, manyToOneFilter); LsiteTypeObjetCritere.Add(item.Name, item); } }
/// <summary> /// Obtient les valeurs du filtre /// </summary> /// <returns></returns> public Dictionary <string, object> CritereRechercheFiltre() { // Application de filtre Dictionary <string, object> RechercheInfos = new Dictionary <string, object>(); foreach (PropertyInfo propertyInfo in PropertyListFilter()) { // Trouver l'objet AffichagePropriete depuis l'annotation avec Filtre = True Attribute getAffichagePropriete = propertyInfo.GetCustomAttribute(typeof(AffichageProprieteAttribute)); if (getAffichagePropriete == null) { continue; } AffichageProprieteAttribute AffichagePropriete = (AffichageProprieteAttribute)getAffichagePropriete; if (AffichagePropriete.Filtre == false) { continue; } switch (propertyInfo.PropertyType.Name) { case "String": { StringFiled stringFiled = (StringFiled)this.groupBoxFiltrage.Controls.Find(propertyInfo.Name, true).First(); if (stringFiled.Value != String.Empty) { RechercheInfos[propertyInfo.Name] = stringFiled.Value; } } break; case "Int32": { Int32Filed int32Filed = (Int32Filed)this.groupBoxFiltrage.Controls.Find(propertyInfo.Name, true).First(); if ((int)int32Filed.Value != 0) { RechercheInfos[propertyInfo.Name] = int32Filed.Value; } } break; case "DateTime": { DateTimeField dateTimeField = (DateTimeField)this.groupBoxFiltrage.Controls.Find(propertyInfo.Name, true).First(); if ((DateTime)dateTimeField.Value != DateTime.MinValue) { RechercheInfos[propertyInfo.Name] = dateTimeField.Value; } } break; default: // Dans le cas d'un objet de type BaseEntity { // [bug] groupBoxFiltrage doit être MainContainner ManyToOneField ComboBoxEntity = (ManyToOneField)this.groupBoxFiltrage.Controls.Find(propertyInfo.Name, true).First(); BaseEntity obj = (BaseEntity)ComboBoxEntity.SelectedItem; if (obj != null && Convert.ToInt32(obj.Id) != 0) { RechercheInfos[propertyInfo.Name] = obj.Id; } } break; } } return(RechercheInfos); }