public void ChangeLanguage(CultureInfo cultureInfo)
        {
            // Must Delete All Entity Configuration, bacause it demande with language
            ConfigEntity x = ConfigEntity.CreateConfigEntity(typeof(User));

            x.Dispose();

            // Change Gwin CultureInfo Instance
            GwinApp.Instance.CultureInfo = cultureInfo;

            if (cultureInfo.TwoLetterISOLanguageName == "ar")
            {
                GwinApp.Instance.user.Language = GwinApp.Languages.ar;
            }
            if (cultureInfo.TwoLetterISOLanguageName == "fr")
            {
                GwinApp.Instance.user.Language = GwinApp.Languages.fr;
            }



            // Change Thread CultureInfo Instance
            Thread.CurrentThread.CurrentCulture   = cultureInfo;
            Thread.CurrentThread.CurrentUICulture = cultureInfo;

            this.Reload();
            // ReLoad Applicaton Interface
            //instance.FormApplication.Reload();

            //[Role] Restart must be after Language change, for Set Application Name Title after
            // Initialize Form
            GwinApp.Restart();
        }
        public void ManyToOneField_CreateInstanceTest()
        {
            // 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 TaskProjectsPropertyInfo = typeof(Group).GetProperty(nameof(Group.TaskProjects));
                ConfigEntity configEntity             = ConfigEntity.CreateConfigEntity(typeof(Group));
                Trainee      trainee = new Trainee();



                ManyToManyField ManyToManyField = new ManyToManyField(
                    TaskProjectsPropertyInfo,
                    Orientation.Vertical,
                    SizeLabel,
                    SizeControl,
                    configEntity,
                    Container,
                    GroupeBLO);

                // Selected the first speciality
                // selectedindex = 1 , index 0 for EmptyData
                ManyToManyField
                .SelectionFilterManager
                .ListeComboBox[typeof(Project).Name]
                .SelectedIndex = 1;
            }
        }
Exemplo n.º 3
0
 public void GwinAppStart()
 {
     GwinApp.Start(typeof(ModelContext), typeof(BaseBLO <>), new FormApplication(), null);
     configEntity        = ConfigEntity.CreateConfigEntity(typeof(TaskProject));
     Entity              = new TaskProject();
     entityMiniConfigBLO = GwinBaseBLO <BaseEntity> .CreateBLO_Instance(typeof(TaskProject), typeof(BaseBLO <>));
 }
Exemplo n.º 4
0
        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];
                    }
                }
            }
        }
        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;
            }
        }
Exemplo n.º 6
0
        public void CreateConfigEntityTest()
        {
            List <Type> ls = new ModelConfiguration().GetAll_Entities_Type();

            foreach (Type item in ls)
            {
                ConfigEntity configEntity = ConfigEntity.CreateConfigEntity(item);
            }
        }
        public void ConfigProperty_of_AllField_Test()
        {
            ConfigEntity ConfigEntity = ConfigEntity.CreateConfigEntity(typeof(TaskProject));

            foreach (PropertyInfo PropertyInfoName in typeof(TaskProject).GetProperties())
            {
                ConfigProperty ConfigProperty = new ConfigProperty(PropertyInfoName, ConfigEntity);
                Assert.IsNotNull(ConfigProperty.DisplayProperty.Title);
                Assert.AreNotEqual(ConfigProperty.DisplayProperty.Title, String.Empty);
            }
        }
        /// <summary>
        /// Create Entry form instance
        /// </summary>
        /// <param name="EtityBLO"></param>
        /// <param name="entity"></param>
        /// <param name="critereRechercheFiltre"></param>
        /// <param name="AutoGenerateField"></param>
        public BaseEntryForm(
            IGwinBaseBLO EtityBLO,
            BaseEntity entity,
            Dictionary <string, object> critereRechercheFiltre,
            bool AutoGenerateField)
        {
            InitializeComponent();
            errorProvider.RightToLeft = GwinApp.isRightToLeft;

            if (System.ComponentModel.LicenseManager.UsageMode != System.ComponentModel.LicenseUsageMode.Designtime)
            {
                CheckPramIsNull.CheckParam_is_NotNull(EtityBLO, this, nameof(EtityBLO));

                // Init Variables
                this.EntityBLO         = EtityBLO;
                this.Entity            = entity;
                this.FilterValues      = critereRechercheFiltre;
                this.AutoGenerateField = AutoGenerateField;
                this.ConfigEntity      = ConfigEntity.CreateConfigEntity(this.EntityBLO.TypeEntity);

                // Default values
                this.ConteneurFormulaire      = FlowLayoutContainer;
                this.isStepInitializingValues = false;
                this.MessageValidation        = new MessageValidation(errorProvider);
                this.Fields      = new Dictionary <string, BaseField>();
                this.GroupsBoxes = new Dictionary <string, GroupBox>();

                // Create PLO Instance if PLO exist
                if (this.EntityPLO == null && this.ConfigEntity.PresentationLogic != null)
                {
                    this.EntityPLO = (IGwinPLO)Activator.CreateInstance(this.ConfigEntity.PresentationLogic.TypePLO);
                }


                // Create or Config Entity Instance
                if (this.EntityBLO != null && this.Entity == null)
                {
                    this.Entity = (BaseEntity)EtityBLO.CreateEntityInstance();
                }
                if ((this.Entity == null || this.Entity.Id == 0) && this.FilterValues != null)
                {
                    this.InitialisationEntityParCritereRechercheFiltre();
                }

                // Create Field in Form
                this.CreateFieldIfNotGenerated();
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Edit the collection ManyToMany_Creation
        /// Create Instead Manager form of ManyToMany_Creation collection
        /// </summary>
        private void DataGridControl_ManyToMany_Creation(object sender, EventArgs e)
        {
            // Init Params
            BaseEntity   obj          = this.DataGridControl_Instance.SelectedEntity;
            PropertyInfo propertyInfo = this.DataGridControl_Instance.SelectedProperty;

            // Selected the Tab id allready in edition
            if (tabControl_MainManager.TabPages.ContainsKey(obj + propertyInfo.Name))
            {
                tabControl_MainManager.SelectedTab = tabControl_MainManager.TabPages[obj + propertyInfo.Name];
                return;
            }

            // Create Business object of the collection
            Type         type_objet_of_collection    = propertyInfo.PropertyType.GetGenericArguments()[0];
            IGwinBaseBLO service_objet_of_collection = this.BLO_Instance.CreateServiceBLOInstanceByTypeEntity(type_objet_of_collection);

            // Default filter values
            Dictionary <string, object> ValeursFiltre = new Dictionary <string, object>();

            ValeursFiltre[propertyInfo.DeclaringType.Name] = obj.Id;

            // Create ManagerFormControl Instance
            ManagerFormControl form = new ManagerFormControl(service_objet_of_collection, ValeursFiltre, this.FrmParent);



            ConfigEntity configEntity = ConfigEntity.CreateConfigEntity(propertyInfo.DeclaringType);

            string formTitle = Glossary.Update + " : ";

            formTitle += new ConfigProperty(propertyInfo, configEntity).DisplayProperty.Title; // Entity
            formTitle += " " + Glossary.For + " ";
            formTitle += obj;
            form.ChangeTabGridTitle(formTitle);
            // Not Show In RunTume Mode
            //if (!Debugger.IsAttached)
            form.ShowFilter(false);


            // Insertion de la gestion à l'interface
            this.AddMenyToMeny_Creation_to_TabPage(form, propertyInfo, obj);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Généric ToString
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            string Titre      = "";
            Type   EntityType = ObjectContext.GetObjectType(this.GetType());

            ConfigEntity configEntity = ConfigEntity.CreateConfigEntity(EntityType);

            // Test if the object has the memeber AffichageClasse.DisplayMember
            if (this.GetType().GetProperty(configEntity.GwinEntity.DisplayMember) == null)
            {
                throw new GwinException("The Entity " + this.GetType() + "does not have the membe  : " + configEntity.GwinEntity.DisplayMember);
            }

            object value = this.GetType().GetProperty(configEntity.GwinEntity.DisplayMember).GetValue(this);

            if (value != null)
            {
                Titre = value.ToString();
            }
            if (Titre == string.Empty)
            {
                if (configEntity.GwinEntity.SingularName != null)
                {
                    return(configEntity.GwinEntity.SingularName);
                }
                else
                {
                    string msg = String.Format("Property {0} of the classe {1} must not be null", nameof(GwinEntityAttribute.SingularName), nameof(GwinEntityAttribute));
                    throw new GwinException(msg);
                }
            }



            else
            {
                return(Titre);
            }
        }
        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;
            }
        }
Exemplo n.º 12
0
        public void DisposeTest()
        {
            ConfigEntity configEntity = ConfigEntity.CreateConfigEntity(typeof(Role));

            Assert.AreEqual(configEntity.Dispose(), true);
        }
Exemplo n.º 13
0
        public ConfigProperty(PropertyInfo propertyInfo, ConfigEntity configEntity)
        {
            this.PropertyInfo = propertyInfo;


            this.ConfigEntity = configEntity;
            //Fill RessouceManager
            this.RessoucesManagers = this.ConfigEntity.RessourcesManagers;


            // Culture Info
            this.CultureInfo = GwinApp.Instance.CultureInfo;

            // Localizable
            this.TypeOfEntity = propertyInfo.ReflectedType;
            this.Localizable  = this.ConfigEntity.GwinEntity.Localizable;



            //
            // Relationship
            //
            Attribute Relationship = propertyInfo.GetCustomAttribute(typeof(RelationshipAttribute));

            this.Relationship = Relationship as RelationshipAttribute;
            if (this.Relationship != null)
            {
                // Check if Type of Memeber is valide Generic List
                if (
                    (this.Relationship.Relation == RelationshipAttribute.Relations.ManyToMany_Creation ||
                     this.Relationship.Relation == RelationshipAttribute.Relations.ManyToMany_Selection ||
                     this.Relationship.Relation == RelationshipAttribute.Relations.OneToMany)
                    &&
                    this.PropertyInfo.PropertyType.GetGenericArguments().Count() == 0)
                {
                    string msg_exception = "The Type :" + this.PropertyInfo.PropertyType.Name;
                    msg_exception += " of member " + this.PropertyInfo.Name;
                    msg_exception += " in Entity " + this.PropertyInfo.DeclaringType.Name;
                    msg_exception += " is not a valid generic List";
                    throw new GwinException(msg_exception);
                }
            }

            //
            // DisplayProperty
            //
            #region DisplayProperty
            // Load DisplayProperty
            Attribute DisplayProperty = propertyInfo.GetCustomAttribute(typeof(DisplayPropertyAttribute));
            this.DisplayProperty = DisplayProperty as DisplayPropertyAttribute;
            // If DisplayProperty not exist
            if (this.DisplayProperty == null)
            {
                if (this.Localizable == false)
                {
                    string message = String.Format("The Attribute : {0} not exist", nameof(DisplayPropertyAttribute));
                    message += " with Property :" + propertyInfo.ToString();
                    message += " in Entity " + propertyInfo.ReflectedType.Name;
                    message += " \n Bacause the Entity is not configured as Localazible";
                    throw new AnnotationNotExistException(message);
                }

                this.DisplayProperty = new DisplayPropertyAttribute();
            }
            if (this.DisplayProperty.isInGlossary)
            {
                string          GlossaryRessouceFullName = "App.Gwin.Entities.Resources.Glossary.Glossary";
                ResourceManager GlossaryResourceManager  = null;
                GlossaryResourceManager = new ResourceManager(GlossaryRessouceFullName, typeof(Glossary).Assembly);
                string title = GlossaryResourceManager.GetString(propertyInfo.Name, this.CultureInfo);
                if (title == null)
                {
                    this.DisplayProperty.Title = this.CultureInfo.Name + "_Glossary_" + propertyInfo.Name;
                }
                else
                {
                    this.DisplayProperty.Title = title;
                }
            }
            else
            {
                //
                // Title
                //
                if (this.DisplayProperty.Title == null)
                {
                    if (this.PropertyInfo.PropertyType.IsSubclassOf(typeof(BaseEntity)))
                    {
                        this.DisplayProperty.Title = ConfigEntity.CreateConfigEntity(this.PropertyInfo.PropertyType).GwinEntity.SingularName;
                    }
                    else
                    {
                        this.DisplayProperty.Title = GetStringFromRessource(propertyInfo.Name);
                    }
                }
                else
                {
                    this.DisplayProperty.Title = GetStringFromRessource(propertyInfo.Name);
                }
            }
            #endregion

            //
            // EntryForm
            //
            Attribute EntryForm = propertyInfo.GetCustomAttribute(typeof(EntryFormAttribute));
            this.EntryForm = EntryForm as EntryFormAttribute;



            //
            // DataGrid
            //
            Attribute DataGrid = propertyInfo.GetCustomAttribute(typeof(DataGridAttribute));
            this.DataGrid = DataGrid as DataGridAttribute;
            // Order
            if (this.EntryForm != null && this.EntryForm.Ordre > 0 &&
                this.DataGrid != null && this.DataGrid.Ordre == 0)
            {
                this.DataGrid.Ordre = this.EntryForm.Ordre;
            }

            //
            // Filter
            //
            Attribute Filter = propertyInfo.GetCustomAttribute(typeof(FilterAttribute));
            this.Filter = Filter as FilterAttribute;

            //
            // DataSource
            //
            Attribute dataSource = propertyInfo.GetCustomAttribute(typeof(ReferencesDataSourceAttribute));
            this.DataSource = dataSource as ReferencesDataSourceAttribute;

            //
            // Criteria
            //
            Attribute SelectionCriteria_Attribute = propertyInfo.GetCustomAttribute(typeof(SelectionCriteriaAttribute));
            this.SelectionCriteria = SelectionCriteria_Attribute as SelectionCriteriaAttribute;

            //
            //BusinesRoleAttribute
            //

            Attribute aBusinesRole = propertyInfo.GetCustomAttribute(typeof(BusinesRoleAttribute));
            this.BusinesRole = aBusinesRole as BusinesRoleAttribute;


            // Determine FieldNautre
            this.FieldNature = BaseFieldTraitement.DetermineFieldNature(this);
        }
        /// <summary>
        /// Calculate MenuItmes from DataBase and Model Config
        /// </summary>
        private void CalculateMenuItems()
        {
            // Create Parent groups Menu from ManuItemApplication Table
            foreach (MenuItemApplication menuItemApplication in this.MenuItemApplicationService.GetAll())
            {
                //Continue if user don't have a role required by menuItemApplication roles
                if (menuItemApplication.Roles != null && menuItemApplication.Roles.Count > 0)
                {
                    if (!GwinApp.Instance.user.HasOneOfRoles(menuItemApplication.Roles))
                    {
                        continue;
                    }
                }

                // Create Parent Menu Item
                Structures.MenuItem menuItem = new Structures.MenuItem(true);

                menuItem.ToolStripMenuItem.Name = "toolStripMenuItem" + menuItemApplication.Code;
                menuItem.ToolStripMenuItem.Size = new System.Drawing.Size(82, 20);
                // Title
                menuItem.ToolStripMenuItem.Text = (menuItemApplication.Title.Current != string.Empty)
                    ? menuItemApplication.Title.Current
                    : menuItem.ToolStripMenuItem.Text = menuItemApplication.Code;

                MenuStruct.ParentMenuItems.Add(menuItem);
            }


            // Create SubMenu MenuItems from ModelCondiguration Entities
            Dictionary <Type, MenuAttribute> MenuAttributes_And_Types = new GwinEntitiesManager().Get_All_Type_And_MenuAttributes();

            foreach (var menuAttributes_And_Types in MenuAttributes_And_Types)
            {
                Type   EntityType = null;
                string Title      = null;
                string Group      = null;

                // Determine Category of Type : Entity or Form
                if (menuAttributes_And_Types.Key.IsSubclassOf(typeof(Form)))
                {
                    if (menuAttributes_And_Types.Value.EntityType == null)
                    {
                        throw new GwinException(String.Format("The property EntityType of MenuAttribute of the Form {0} is null \n it can not be null we use it to check security permission", menuAttributes_And_Types.Key));
                    }
                    EntityType = menuAttributes_And_Types.Value.EntityType;
                    ConfigEntity configEntity = ConfigEntity.CreateConfigEntity(EntityType);
                    Group = menuAttributes_And_Types.Value.Group;
                    if (menuAttributes_And_Types.Value.Title != null)
                    {
                        Title = configEntity.Translate(menuAttributes_And_Types.Value.Title);
                    }
                }
                else
                {
                    if (menuAttributes_And_Types.Key.IsSubclassOf(typeof(BaseEntity)))
                    {
                        EntityType = menuAttributes_And_Types.Key;
                        ConfigEntity configEntity = ConfigEntity.CreateConfigEntity(EntityType);
                        Group = configEntity.Menu.Group;
                        Title = configEntity.Menu.Title;
                    }
                    else
                    {
                        throw new GwinException(String.Format("The Type {0} does not inherit from BaseEntity or Form ", menuAttributes_And_Types.Key));
                    }
                }



                // Security : Continue if User dont have persmission
                if (!GwinApp.Instance.user.HasAccess(EntityType))
                {
                    continue;
                }



                // Create MenuItem and Save to Dictionary MenyItem
                Structures.MenuItem SubMenuItem = new Structures.MenuItem(false);

                SubMenuItem.ToolStripMenuItem.Name   = menuAttributes_And_Types.Key.FullName;
                SubMenuItem.ToolStripMenuItem.Size   = new System.Drawing.Size(82, 20);
                SubMenuItem.ToolStripMenuItem.Text   = Title;
                SubMenuItem.ToolStripMenuItem.Click += ToolStripMenuItem_Click;
                SubMenuItem.TypeOfEntity             = menuAttributes_And_Types.Key;

                // Find Parent if Exist
                Structures.MenuItem ParentMenuItem = null;
                if (Group != null)
                {
                    string toolStripMenuItem_key = "toolStripMenuItem" + Group;
                    ParentMenuItem = MenuStruct.ParentMenuItems.Where(m => m.ToolStripMenuItem.Name == toolStripMenuItem_key).SingleOrDefault();

                    // If parrent exist
                    if (ParentMenuItem != null)
                    {
                        ParentMenuItem.Add(SubMenuItem);
                    }
                    else
                    {
                        // throw new GwinException(String.Format("the Parent {0} of {1} not exist ", configEntity.Menu.Group, toolStripMenuItem_key));
                        // Patent not exist bevause user not have permission required by Parent Menu
                    }
                }
                else
                {
                    this.MenuStruct.ParentMenuItems.Add(SubMenuItem);
                }
            }
        }