private void ExcelMappingActionOnExecute(object sender, SingleChoiceActionExecuteEventArgs e)
        {
            if ((string)e.SelectedChoiceActionItem.Data == "Reset")
            {
                ObjectSpace.Delete(ExcelImport.ExcelColumnMaps);
                ObjectSpace.CommitChanges();
                MapAction.DoExecute(MapAction.FindItemByIdPath("Map"));
            }
            else
            {
                if (!ExcelImport.ExcelColumnMaps.Any())
                {
                    Map();
                }
                ObjectSpace.CommitChanges();
                var parameters = e.ShowViewParameters;



                var dialogController = new DialogController();
                parameters.Controllers.Add(dialogController);
                parameters.CreatedView  = Application.CreateDashboardView(Application.CreateObjectSpace(), "ExcelColumnMapMasterDetail", true);
                parameters.TargetWindow = TargetWindow.NewModalWindow;
                ShowMapConfigView(parameters);
                dialogController.AcceptAction.Executed += AcceptActionOnExecuted;
            }
        }
Exemplo n.º 2
0
        private void ResetPortal()
        {
            var objSpace  = (XPObjectSpace)ObjectSpace;
            var classInfo = objSpace.Session.GetClassInfo <ActionPortal>();

            #region repopulate actions

            var softPortal = new ActionPortalLogic();
            var hardPortal = new ActionPortalHardLogic(softPortal);

            var intlObjs = ObjectSpace.GetObjects <ActionPortal>(
                CriteriaOperator.Parse("ActionPortalType = ?", ActionPortalType.Internal));
            ObjectSpace.Delete(intlObjs);

            foreach (var portalItem in hardPortal.ActionPortalList)
            {
                var portalObj = ObjectSpace.CreateObject <ActionPortal>();
                portalObj.ActionPortalType  = ActionPortalType.Internal;
                portalObj.ActionName        = portalItem.ActionName;
                portalObj.ActionDescription = portalItem.ActionDescription;
            }

            ObjectSpace.CommitChanges();

            #endregion
        }
Exemplo n.º 3
0
        void LoadDefaultUsersAndRolesData()
        {
            Employee adminUser = ObjectSpace.FindObject <Employee>(new BinaryOperator("UserName", "Admin"));

            if (adminUser == null)
            {
                adminUser          = ObjectSpace.CreateObject <Employee>();
                adminUser.UserName = "******";
                adminUser.SetPassword("");
            }

            Role adminRole = ObjectSpace.FindObject <Role>(new BinaryOperator("Name", "Administrator"));

            if (adminRole == null)
            {
                adminRole      = ObjectSpace.CreateObject <Role>();
                adminRole.Name = "Administrator";
            }

            while (adminRole.PersistentPermissions.Count > 0)
            {
                ObjectSpace.Delete(adminRole.PersistentPermissions[0]);
            }

            adminRole.AddPermission(new ObjectAccessPermission(typeof(object), ObjectAccess.AllAccess));

            adminRole.Save();
            adminUser.Roles.Add(adminRole);
            adminUser.Save();
        }
Exemplo n.º 4
0
        public void CombineAndSave(List <ModelDifferenceObject> selectedModelAspectObjects)
        {
            var selectedObjects = View.SelectedObjects.OfType <ModelDifferenceObject>().ToList();

            CheckIfMixingApplications(selectedObjects);
            foreach (var differenceObject in selectedModelAspectObjects)
            {
                var masterModel = new ModelLoader(differenceObject.PersistentApplication.ExecutableName).GetMasterModel(true);
                var model       = differenceObject.GetModel(masterModel);
                foreach (var selectedModelAspectObject in selectedObjects)
                {
                    foreach (var aspectObject in selectedModelAspectObject.AspectObjects)
                    {
                        var xml = aspectObject.Xml;
                        if (!(string.IsNullOrEmpty(xml)))
                        {
                            var aspectName = differenceObject.GetAspectName(aspectObject);
                            if (aspectName != "" && !(model.HasAspect(aspectName)))
                            {
                                model.AddAspect(aspectName);
                            }
                            new ModelXmlReader().ReadFromString(model, aspectName, xml);
                        }
                    }
                }
                ObjectSpace.Delete(differenceObject.AspectObjects);
                differenceObject.CreateAspects(model);
            }
            ObjectSpace.CommitChanges();
        }
        public override void UpdateDatabaseAfterUpdateSchema()
        {
            base.UpdateDatabaseAfterUpdateSchema();
            ObjectSpace.Delete(ObjectSpace.GetObjects <Note>());
            ObjectSpace.Delete(ObjectSpace.GetObjects <TaskType>());
            ObjectSpace.CommitChanges();

            for (int i = 0; i < 1000; i++)
            {
                Note note = ObjectSpace.CreateObject <Note>();
                note.Name = "note " + i;
            }
            TaskType taskType = ObjectSpace.CreateObject <TaskType>();

            taskType.Name = "2";

            XpoWorkflowDefinition wfDefinition = ObjectSpace.FindObject <XpoWorkflowDefinition>(new BinaryOperator("Name", "Simple performance test"));

            if (wfDefinition == null)
            {
                wfDefinition          = ObjectSpace.CreateObject <XpoWorkflowDefinition>();
                wfDefinition.Name     = "Simple performance test";
                wfDefinition.Criteria = "[IsProcessed] = False";
                Version ver = typeof(XafApplication).Assembly.GetName().Version;
                wfDefinition.Xaml             = string.Format(Xaml1, ver.Major, ver.Minor);
                wfDefinition.TargetObjectType = typeof(Note);
                wfDefinition.AutoStartWhenObjectFitsCriteria = true;
                wfDefinition.AutoStartWhenObjectIsCreated    = false;
                wfDefinition.IsActive = true;
            }

            ObjectSpace.CommitChanges();
        }
Exemplo n.º 6
0
        private void ExcelMappingActionOnExecute(object sender, SingleChoiceActionExecuteEventArgs e)
        {
            if ((string)e.SelectedChoiceActionItem.Data == "Reset")
            {
                ObjectSpace.Delete(ExcelImport.ExcelColumnMaps);
                ObjectSpace.CommitChanges();
                MapAction.DoExecute(MapAction.FindItemByIdPath("Map"));
            }
            else
            {
                if (!ExcelImport.ExcelColumnMaps.Any())
                {
                    Map();
                }
                ObjectSpace.CommitChanges();
                var parameters = e.ShowViewParameters;
                MasterDetailService.MasterDetailDashboardViewItems
                .FirstAsync()
                .Select(tuple => {
                    var listView         = ((ListView)tuple.listViewItem.InnerView);
                    var criteriaOperator = listView.ObjectSpace.GetCriteriaOperator <ExcelColumnMap>(map => map.ExcelImport.Oid == ExcelImport.Oid);
                    listView.CollectionSource.Criteria[GetType().Name] = criteriaOperator;
                    return(Unit.Default);
                })
                .Subscribe();


                var dialogController = new DialogController();
                parameters.Controllers.Add(dialogController);
                parameters.CreatedView  = Application.CreateDashboardView(Application.CreateObjectSpace(), "ExcelColumnMapMasterDetail", true);
                parameters.TargetWindow = TargetWindow.NewModalWindow;
                ShowMapConfigView(parameters);
                dialogController.AcceptAction.Executed += AcceptActionOnExecuted;
            }
        }
        private void GenerateGraphActionOnExecute(object sender, SimpleActionExecuteEventArgs simpleActionExecuteEventArgs)
        {
            var serializationConfiguration = ((ISerializationConfiguration)View.CurrentObject);

            ObjectSpace.Delete(serializationConfiguration.SerializationGraph);
            new ClassInfoGraphNodeBuilder().Generate(serializationConfiguration);
            ObjectSpace.CommitChanges();
        }
Exemplo n.º 8
0
 private void OnExecute(object sender, ActionBaseEventArgs actionBaseEventArgs)
 {
     actionBaseEventArgs.Action.Controller.Frame.GetController <ChooseDBObjectsController>(chooseDBObjectsController => {
         chooseDBObjectsController.View.ObjectSpace.CommitChanges();
         var dbLogonObject          = ((DBLogonObject)chooseDBObjectsController.View.CurrentObject);
         var persistentAssemblyInfo = ((IPersistentAssemblyInfo)View.CurrentObject);
         ObjectSpace.Delete(persistentAssemblyInfo.PersistentClassInfos);
         ObjectSpace.Delete(persistentAssemblyInfo.Attributes.OfType <IPersistentAssemblyDataStoreAttribute>().FirstOrDefault());
         var assemblyGenerator = new AssemblyGenerator.AssemblyGenerator(dbLogonObject.ConnectionString, dbLogonObject.NavigationPath, persistentAssemblyInfo, chooseDBObjectsController.GetSelectedDBObjects());
         assemblyGenerator.Create();
     });
 }
Exemplo n.º 9
0
        public ActionResult Delete(Guid key)
        {
            Employee existing = ObjectSpace.GetObjectByKey <Employee>(key);

            if (existing != null)
            {
                ObjectSpace.Delete(existing);
                ObjectSpace.CommitChanges();
                return(NoContent());
            }
            return(NotFound());
        }
Exemplo n.º 10
0
        private void ResetColumns()
        {
            ImportApPmtDistnColumn obj = null;
            var objs = ObjectSpace.GetObjects <ImportApPmtDistnColumn>();

            ObjectSpace.Delete(objs);

            obj = CreateImportColumn(ObjectSpace, 1, "Payment Date", "DateTime");
            obj = CreateImportColumn(ObjectSpace, 2, "Invoice Due Date", "DateTime");
            obj = CreateImportColumn(ObjectSpace, 3, "Source", "string");
            obj = CreateImportColumn(ObjectSpace, 4, "Capex Opex", "string");
            obj = CreateImportColumn(ObjectSpace, 5, "Org Name", "string");
            obj = CreateImportColumn(ObjectSpace, 6, "Bank Account Name", "string");
            obj = CreateImportColumn(ObjectSpace, 7, "Pay Group", "string");
            obj = CreateImportColumn(ObjectSpace, 8, "Inv Source", "string");
            obj = CreateImportColumn(ObjectSpace, 9, "Vendor Name", "string");
            obj = CreateImportColumn(ObjectSpace, 10, "Company", "string");
            obj = CreateImportColumn(ObjectSpace, 11, "Account", "string");
            obj = CreateImportColumn(ObjectSpace, 12, "Cost Centre", "string");
            obj = CreateImportColumn(ObjectSpace, 13, "Product", "string");
            obj = CreateImportColumn(ObjectSpace, 14, "Sales Channel", "string");
            obj = CreateImportColumn(ObjectSpace, 15, "Country", "string");
            obj = CreateImportColumn(ObjectSpace, 16, "Intercompany", "string");
            obj = CreateImportColumn(ObjectSpace, 17, "Project", "string");
            obj = CreateImportColumn(ObjectSpace, 18, "Location", "string");
            obj = CreateImportColumn(ObjectSpace, 19, "Po Num", "string");
            obj = CreateImportColumn(ObjectSpace, 20, "Invoice Num", "string");
            obj = CreateImportColumn(ObjectSpace, 21, "Invoice Creation Date", "DateTime");
            obj = CreateImportColumn(ObjectSpace, 22, "Distribution Line Number", "int");
            obj = CreateImportColumn(ObjectSpace, 23, "Payment Amount Fx", "double");
            obj = CreateImportColumn(ObjectSpace, 24, "Payment Amount Aud", "double");
            obj = CreateImportColumn(ObjectSpace, 25, "Payment Number", "int");
            obj = CreateImportColumn(ObjectSpace, 26, "Payment Batch Name", "string");
            obj = CreateImportColumn(ObjectSpace, 27, "Payment Method", "string");
            obj = CreateImportColumn(ObjectSpace, 28, "Invoice Currency", "string");
            obj = CreateImportColumn(ObjectSpace, 29, "Payment Creation Date", "DateTime");
            obj = CreateImportColumn(ObjectSpace, 30, "Line Type Lookup Code", "string");
            obj = CreateImportColumn(ObjectSpace, 31, "Invoice Line Desc", "string");
            obj = CreateImportColumn(ObjectSpace, 32, "Tax Code", "string");
            obj = CreateImportColumn(ObjectSpace, 33, "Payment Currency", "string");
            obj = CreateImportColumn(ObjectSpace, 34, "Invoice Date", "DateTime");
            obj = CreateImportColumn(ObjectSpace, 35, "Capex Number", "string");
            obj = CreateImportColumn(ObjectSpace, 36, "Invoice Id", "int");
            obj = CreateImportColumn(ObjectSpace, 37, "Expenditure Type", "string");
            obj = CreateImportColumn(ObjectSpace, 38, "Project Number", "string");
            obj = CreateImportColumn(ObjectSpace, 39, "Vendor Number", "string");
        }
Exemplo n.º 11
0
        /// <summary>
        /// Atualiza a base após um update do programa
        /// </summary>
        public override void UpdateDatabaseAfterUpdateSchema()
        {
            String userName = ADResources.AdminUser;
            String fullName = ADResources.AdminName;
            String passWord = ADResources.AdminPass;

            // If a user doesn't exist in the database, create this user

            User admin = ObjectSpace.FindObject <User>(new BinaryOperator("UserName", userName));

            if (admin == null)
            {
                admin           = ObjectSpace.CreateObject <User>();
                admin.UserName  = userName;
                admin.FirstName = fullName;
                // Set a password if the standard authentication type is used
                admin.SetPassword(passWord);
            }

            // If a role with the Administrators name doesn't exist in the database, create this role
            Role adminRole = ObjectSpace.FindObject <Role>(new BinaryOperator("Name", "Administradores"));

            if (adminRole == null)
            {
                adminRole      = ObjectSpace.CreateObject <Role>();
                adminRole.Name = "Administradores";
            }
            // Delete all permissions assigned to the Administrators and Users roles
            while (adminRole.PersistentPermissions.Count > 0)
            {
                ObjectSpace.Delete(adminRole.PersistentPermissions[0]);
            }
            // Allow full access to all objects to the Administrators role
            adminRole.AddPermission(new ObjectAccessPermission(typeof(object), ObjectAccess.AllAccess));
            // Allow editing the Application Model to the Administrators role
            adminRole.AddPermission(new EditModelPermission(ModelAccessModifier.Allow));
            // Save the Administrators role to the database
            adminRole.Save();
            // Add the Administrators role to the user1
            admin.Roles.Add(adminRole);
            // Save the users to the database
            admin.Save();

            ObjectSpace.CommitChanges();

            base.UpdateDatabaseAfterUpdateSchema();
        }
Exemplo n.º 12
0
        void CreateInterfaces(CollectionSourceBase collectionSourceBase)
        {
            var interfaceInfo = ((IInterfaceInfo)ObjectSpace.CreateObject(View.ObjectTypeInfo.Type));

            ObjectSpace.Delete(interfaceInfo);
            string assemblyName = interfaceInfo.GetPropertyInfo(x => x.Assembly).Name;
            string name         = interfaceInfo.GetPropertyInfo(x => x.Name).Name;

            foreach (Type type in GetInterfaces())
            {
                if (ObjectSpace.FindObject(View.ObjectTypeInfo.Type, CriteriaOperator.Parse(string.Format("{0}=? AND {1}=?", assemblyName, name),
                                                                                            new AssemblyName(type.Assembly.FullName + "").Name, type.FullName)) == null)
                {
                    createInterfaceInfo(type, collectionSourceBase);
                }
            }
            ObjectSpace.CommitChanges();
        }
Exemplo n.º 13
0
        private void GeneratePricesAction_Execute(object sender, SimpleActionExecuteEventArgs e)
        {
            ArrayList list        = new ArrayList();
            PriceList currentList = (PriceList)View.CurrentObject;

            foreach (Price price in currentList.Prices)
            {
                list.Add(price);
            }

            ObjectSpace.Delete(list);

            IList items = ObjectSpace.GetObjects(typeof(Item), CriteriaOperator.Parse("Sold=true"));

            foreach (Item item in items)
            {
                Price price = ObjectSpace.CreateObject <Price>();
                price.Item      = ObjectSpace.GetObjectByKey <Item>(item.ItemNumber);
                price.ListPrice = item.Cost;

                currentList.Prices.Add(price);
            }
        }
Exemplo n.º 14
0
        public override void UpdateDatabaseAfterUpdateSchema()
        {
            base.UpdateDatabaseAfterUpdateSchema();
            // If a user named 'Sam' doesn't exist in the database, create this user
            Employee user1 = ObjectSpace.FindObject <Employee>(new BinaryOperator("UserName", "Sam"));

            if (user1 == null)
            {
                user1           = ObjectSpace.CreateObject <Employee>();
                user1.Color     = Color.Red;
                user1.UserName  = "******";
                user1.FirstName = "Sam";
                user1.Caption   = user1.UserName;
                // Set a password if the standard authentication type is used
                user1.SetPassword(null);
            }
            // If a user named 'John' doesn't exist in the database, create this user
            Employee user2 = ObjectSpace.FindObject <Employee>(new BinaryOperator("UserName", "John"));

            if (user2 == null)
            {
                user2           = ObjectSpace.CreateObject <Employee>();
                user2.Color     = Color.Green;
                user2.UserName  = "******";
                user2.FirstName = "John";
                user2.Caption   = user2.UserName;
                // Set a password if the standard authentication type is used
                user2.SetPassword(null);
            }
            // If a role with the Administrators name doesn't exist in the database, create this role
            Group adminRole = ObjectSpace.FindObject <Group>(new BinaryOperator("Name", Group.DefaultAdministratorsGroupName));

            if (adminRole == null)
            {
                adminRole      = ObjectSpace.CreateObject <Group>();
                adminRole.Name = Group.DefaultAdministratorsGroupName;
            }
            // If a role with the Users name doesn't exist in the database, create this role
            Group userRole = ObjectSpace.FindObject <Group>(new BinaryOperator("Name", Group.DefaultUsersGroupName));

            if (userRole == null)
            {
                userRole      = ObjectSpace.CreateObject <Group>();
                userRole.Name = Group.DefaultUsersGroupName;
            }
            // Delete all permissions assigned to the Administrators and Users roles
            while (adminRole.PersistentPermissions.Count > 0)
            {
                ObjectSpace.Delete(adminRole.PersistentPermissions[0]);
            }
            while (userRole.PersistentPermissions.Count > 0)
            {
                ObjectSpace.Delete(userRole.PersistentPermissions[0]);
            }
            // Allow full access to all objects to the Administrators role
            adminRole.AddPermission(new ObjectAccessPermission(typeof(object), ObjectAccess.AllAccess));
            // Allow editing the application model to the Administrators role
            adminRole.AddPermission(new EditModelPermission(ModelAccessModifier.Allow));
            // Save the Administrators role to the database
            adminRole.Save();
            // Allow full access to all objects to the Users role
            userRole.AddPermission(new ObjectAccessPermission(typeof(object), ObjectAccess.AllAccess));
            // Deny full access to the User type objects to the Users role
            userRole.AddPermission(new ObjectAccessPermission(typeof(Employee),
                                                              ObjectAccess.ChangeAccess, ObjectAccessModifier.Deny));
            userRole.AddPermission(new ObjectAccessPermission(typeof(Group),
                                                              ObjectAccess.AllAccess, ObjectAccessModifier.Deny));
            // Deny editing the application model to the Users role
            userRole.AddPermission(new EditModelPermission(ModelAccessModifier.Deny));
            // Save the Users role to the database
            userRole.Save();
            // Add the Administrators role to the user1
            user1.Groups.Add(adminRole);
            // Add the Users role to the user2
            user2.Groups.Add(userRole);
            // Save the users to the database
            user1.Save();
            user2.Save();
        }
        public override void UpdateDatabaseAfterUpdateSchema()
        {
            base.UpdateDatabaseAfterUpdateSchema();

            #region Create Users for the Complex Security Strategy
            // If a user named 'Sam' doesn't exist in the database, create this user
            User user1 = ObjectSpace.FindObject <User>(new BinaryOperator("UserName", "Sam"));
            if (user1 == null)
            {
                user1           = ObjectSpace.CreateObject <User>();
                user1.UserName  = "******";
                user1.FirstName = "Sam";
                // Set a password if the standard authentication type is used
                user1.SetPassword("");
            }
            // If a user named 'John' doesn't exist in the database, create this user
            User user2 = ObjectSpace.FindObject <User>(new BinaryOperator("UserName", "John"));
            if (user2 == null)
            {
                user2           = ObjectSpace.CreateObject <User>();
                user2.UserName  = "******";
                user2.FirstName = "John";
                // Set a password if the standard authentication type is used
                user2.SetPassword("");
            }
            // If a role with the Administrators name doesn't exist in the database, create this role
            Role adminRole = ObjectSpace.FindObject <Role>(new BinaryOperator("Name", "Administrators"));
            if (adminRole == null)
            {
                adminRole      = ObjectSpace.CreateObject <Role>();
                adminRole.Name = "Administrators";
            }
            // If a role with the Users name doesn't exist in the database, create this role
            Role userRole = ObjectSpace.FindObject <Role>(new BinaryOperator("Name", "Users"));
            if (userRole == null)
            {
                userRole      = ObjectSpace.CreateObject <Role>();
                userRole.Name = "Users";
            }
            // Delete all permissions assigned to the Administrators and Users roles
            while (adminRole.PersistentPermissions.Count > 0)
            {
                ObjectSpace.Delete(adminRole.PersistentPermissions[0]);
            }
            while (userRole.PersistentPermissions.Count > 0)
            {
                ObjectSpace.Delete(userRole.PersistentPermissions[0]);
            }
            // Allow full access to all objects to the Administrators role
            adminRole.AddPermission(new ObjectAccessPermission(typeof(object), ObjectAccess.AllAccess));
            // Deny editing access to the AuditDataItemPersistent type objects to the Administrators role
            adminRole.AddPermission(new ObjectAccessPermission(typeof(AuditDataItemPersistent), ObjectAccess.ChangeAccess, ObjectAccessModifier.Deny));
            // Allow editing the application model to the Administrators role
            adminRole.AddPermission(new EditModelPermission(ModelAccessModifier.Allow));
            // Save the Administrators role to the database
            adminRole.Save();
            // Allow full access to all objects to the Users role
            userRole.AddPermission(new ObjectAccessPermission(typeof(object), ObjectAccess.AllAccess));
            // Deny editing access to the User type objects to the Users role
            userRole.AddPermission(new ObjectAccessPermission(typeof(User), ObjectAccess.ChangeAccess, ObjectAccessModifier.Deny));
            // Deny full access to the Role type objects to the Users role
            userRole.AddPermission(new ObjectAccessPermission(typeof(Role), ObjectAccess.AllAccess, ObjectAccessModifier.Deny));
            // Deny editing the application model to the Users role
            userRole.AddPermission(new EditModelPermission(ModelAccessModifier.Deny));
            // Save the Users role to the database
            userRole.Save();
            // Add the Administrators role to the user1
            user1.Roles.Add(adminRole);
            // Add the Users role to the user2
            user2.Roles.Add(userRole);
            // Save the users to the database
            user1.Save();
            user2.Save();
            ObjectSpace.CommitChanges();
            #endregion
        }
        public override void UpdateDatabaseAfterUpdateSchema()
        {
            base.UpdateDatabaseAfterUpdateSchema();

            User user1 = ObjectSpace.FindObject <User>(new BinaryOperator("UserName", "Sam"));

            if (user1 == null)
            {
                user1           = ObjectSpace.CreateObject <User>();
                user1.UserName  = "******";
                user1.FirstName = "Sam";
                // Set a password if the standard authentication type is used
                user1.SetPassword("");
            }
            // If a user named 'John' doesn't exist in the database, create this user
            User user2 = ObjectSpace.FindObject <User>(new BinaryOperator("UserName", "John"));

            if (user2 == null)
            {
                user2           = ObjectSpace.CreateObject <User>();
                user2.UserName  = "******";
                user2.FirstName = "John";
                // Set a password if the standard authentication type is used
                user2.SetPassword("");
            }

            BasicUser adminUser = ObjectSpace.FindObject <BasicUser>(new BinaryOperator("UserName", "Sam"));

            if (adminUser == null)
            {
                adminUser          = ObjectSpace.CreateObject <BasicUser>();
                adminUser.UserName = "******";
                adminUser.FullName = "Sam";
            }
            // Make the user an administrator
            adminUser.IsAdministrator = true;
            // Set a password if the standard authentication type is used
            adminUser.SetPassword("");
            // Save the user to the database
            adminUser.Save();


            // If a role with the Administrators name doesn't exist in the database, create this role
            Role adminRole = ObjectSpace.FindObject <Role>(new BinaryOperator("Name", "Administrators"));

            if (adminRole == null)
            {
                adminRole      = ObjectSpace.CreateObject <Role>();
                adminRole.Name = "Administrators";
            }
            // If a role with the Users name doesn't exist in the database, create this role
            Role userRole = ObjectSpace.FindObject <Role>(new BinaryOperator("Name", "Users"));

            if (userRole == null)
            {
                userRole      = ObjectSpace.CreateObject <Role>();
                userRole.Name = "Users";
            }
            // Delete all permissions assigned to the Administrators and Users roles
            while (adminRole.PersistentPermissions.Count > 0)
            {
                ObjectSpace.Delete(adminRole.PersistentPermissions[0]);
            }
            while (userRole.PersistentPermissions.Count > 0)
            {
                ObjectSpace.Delete(userRole.PersistentPermissions[0]);
            }
            // Allow full access to all objects to the Administrators role
            adminRole.AddPermission(new ObjectAccessPermission(typeof(object), ObjectAccess.AllAccess));
            // Allow editing the application model to the Administrators role
            adminRole.AddPermission(new EditModelPermission(ModelAccessModifier.Allow));
            // Save the Administrators role to the database
            adminRole.Save();
            // Allow full access to all objects to the Users role
            userRole.AddPermission(new ObjectAccessPermission(typeof(object), ObjectAccess.AllAccess));
            //// Deny full access to the User type objects to the Users role
            //userRole.AddPermission(new ObjectAccessPermission(typeof(UserDetail), ObjectAccess.AllAccess, ObjectAccessModifier.Deny));
            // Deny full access to the Role type objects to the Users role
            userRole.AddPermission(new ObjectAccessPermission(typeof(Role), ObjectAccess.AllAccess, ObjectAccessModifier.Deny));
            //userRole.AddPermission(new ObjectAccessPermission(typeof(), ObjectAccess.Read, ObjectAccessModifier.Deny));
            // Deny editing the application model to the Users role
            userRole.AddPermission(new EditModelPermission(ModelAccessModifier.Deny));
            // Save the Users role to the database
            userRole.Save();
            // Add the Administrators role to the user1
            user1.Roles.Add(adminRole);
            // Add the Users role to the user2
            user2.Roles.Add(userRole);
            // Save the users to the database
            user1.Save();
            user2.Save();
        }
Exemplo n.º 17
0
        public static XPCollection<WeekReportData> CreateClassroomTimetableData(ObjectSpace objectSpace, string classroomCode, string semesterName)
        {
            ConstrainstParameter cp = objectSpace.FindObject<ConstrainstParameter>(
               new BinaryOperator("Code", "AFTERNOONPERIODCOUNT"));
            int afternoonPeriodCount = Convert.ToInt32(cp.Value);

            cp = objectSpace.FindObject<ConstrainstParameter>(
               new BinaryOperator("Code", "MORNINGPERIODCOUNT"));
            int morningPeriodCount = Convert.ToInt32(cp.Value);

            try
            {
                using (XPCollection<WeekReportData> xpw = new XPCollection<WeekReportData>(objectSpace.Session,
                           new ContainsOperator("Classrooms", new BinaryOperator("ClassroomCode", classroomCode))))
                {

                    objectSpace.Delete(xpw);
                    objectSpace.CommitChanges();
                    using (XPCollection<TkbSemester> xpctkbSemester = new XPCollection<TkbSemester>(objectSpace.Session,
                        new GroupOperator(GroupOperatorType.And, new BinaryOperator("Lesson.Semester.SemesterName",
                            semesterName), new BinaryOperator("Classroom.ClassroomCode", classroomCode))))
                    {

                        Dictionary<string, WeekReportData> dicTimePeriodforWeekData = new Dictionary<string, WeekReportData>();
                        WeekReportData currentWeekData;

                        foreach (TkbSemester tkbSem in xpctkbSemester)
                        {
                            string[] strperiod = tkbSem.Period.Split(',');
                            List<string> periodTimeList = new List<string>();
                            foreach (string s in strperiod)
                            {
                                if (Convert.ToInt32(s) >= 1 && Convert.ToInt32(s) <= morningPeriodCount)
                                    if (!periodTimeList.Contains("Sáng"))
                                        periodTimeList.Add("Sáng");
                                if (Convert.ToInt32(s) > morningPeriodCount && Convert.ToInt32(s) <= (morningPeriodCount + afternoonPeriodCount))
                                    if (!periodTimeList.Contains("Chiều"))
                                        periodTimeList.Add("Chiều");
                                if (Convert.ToInt32(s) > (morningPeriodCount + afternoonPeriodCount))
                                    if (!periodTimeList.Contains("Tối"))
                                        periodTimeList.Add("Tối");
                            }

                            foreach (String period in periodTimeList)
                            {
                                if (!dicTimePeriodforWeekData.ContainsKey(period))
                                {
                                    currentWeekData = objectSpace.CreateObject<WeekReportData>();
                                    currentWeekData.Semester = objectSpace.FindObject<Semester>(
                                        CriteriaOperator.Parse("SemesterName = ?", semesterName));
                                    currentWeekData.Classrooms.Add(objectSpace.FindObject<Classroom>(
                                        CriteriaOperator.Parse("ClassroomCode=?", classroomCode)));
                                    currentWeekData.PeriodTime = period;
                                    dicTimePeriodforWeekData.Add(period, currentWeekData);
                                }

                                dicTimePeriodforWeekData[period][tkbSem.Day] += string.Format("Lớp:{0}\r\n Môn:{1}-{2}\r\nTiết:{3}\r\nTuần:{4}\r\n\r\n",
                                        tkbSem.Lesson.ClassIDs, tkbSem.Lesson.Subject.SubjectCode, tkbSem.Lesson.Subject.SubjectName,
                                        Utils.ShortStringPeriod(tkbSem.Period), Utils.ShortStringWeek(tkbSem.StringWeeks));
                            }

                        }
                        objectSpace.CommitChanges();
                    }

                }
            }

            catch (Exception ex)
            {
                throw new UserFriendlyException("Lỗi thực hiện: " + ex.Message);
            }

            return new XPCollection<WeekReportData>(objectSpace.Session,
                           new GroupOperator(GroupOperatorType.And, new BinaryOperator("Semester.SemesterName",
                            semesterName), new ContainsOperator("Classrooms", new BinaryOperator("ClassroomCode", classroomCode))));
        }
Exemplo n.º 18
0
        public static XPCollection<AccountTransactionTracking> CreateStudentClassTransactionTrackingData(ObjectSpace objectSpace, string classCode, string semesterName)
        {
            try
            {
                using (XPCollection<AccountTransactionTracking> xpw = new XPCollection<AccountTransactionTracking>(objectSpace.Session,
                               new BinaryOperator("Student.StudentClass.ClassCode", classCode)))
                {
                    objectSpace.Delete(xpw);
                    objectSpace.CommitChanges();

                    StudentClass studentClass = objectSpace.FindObject<StudentClass>(
                        new BinaryOperator("ClassCode", classCode));
                    Semester semester = objectSpace.FindObject<Semester>(
                        new BinaryOperator("SemesterName", semesterName));
                    DateTime semesterLastDate = semester.StartDate.AddDays(semester.NumberOfWeek * 7);

                    decimal beforedebtvalue=0;
                    decimal requestvalue= 0;
                    decimal paidvalue = 0;

                    if (studentClass != null && semester != null)
                    {
                        foreach (Student student in studentClass.Students)
                        {
                            beforedebtvalue = 0;
                            requestvalue = 0;
                            paidvalue = 0;
                            foreach (AccountTransaction accTrans in student.AccountTransactions)
                            {
                                if ((accTrans.Semester != null &&
                                    Convert.ToInt32(accTrans.Semester.SemesterName)<Convert.ToInt32(semester.SemesterName)))
                                //||accTrans.TransactingDate< semester.StartDate)
                                    beforedebtvalue += accTrans.MoneyAmount;
                                else if (//accTrans.TransactingDate <= semesterLastDate ||
                                    (accTrans.Semester!=null && accTrans.Semester.SemesterName ==semester.SemesterName))
                                {
                                    if (accTrans.MoneyAmount < 0) //money has to paid
                                    {
                                        requestvalue += (-accTrans.MoneyAmount);
                                    }
                                    else //money has paid
                                    {
                                        paidvalue += accTrans.MoneyAmount;
                                    }
                                }
                            }

                            AccountTransactionTracking accTracking = objectSpace.CreateObject<AccountTransactionTracking>();
                            accTracking.Student = student;
                            accTracking.Semester = semester;
                            accTracking.BeforeDebtValue = -beforedebtvalue;
                            accTracking.PaidValue= paidvalue;
                            accTracking.RequestValue = requestvalue;
                            accTracking.Save();
                        }
                        objectSpace.CommitChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                throw new UserFriendlyException("Lỗi thực hiện: " + ex.Message);
            }
            return new XPCollection<AccountTransactionTracking>(objectSpace.Session,
                       new BinaryOperator("Student.StudentClass.ClassCode", classCode));
        }
Exemplo n.º 19
0
        private void GenerateModuleAssembly()
        {
            #region GetVersion

            Version ver = BusinessBuilder.GetVersion(AdmiralEnvironment.DomainComponentDefineFile);

            if (ver != null)
            {
                ver = new Version(ver.Major + 1, ver.Minor, ver.Build, ver.Revision);
            }
            else
            {
                ver = new Version(1, 0, 0, 0);
            }

            #endregion

            var assemblyName = "AdmiralDynamicDC";
            var newFileName  = assemblyName + ver + ".dll";

            #region 定义程序集

            var asmName = new AssemblyName(assemblyName)
            {
                Version = ver
            };
            //[assembly: AssemblyFileVersionAttribute("1.0.0.12")]
            var assembly = AppDomain.CurrentDomain.DefineDynamicAssembly(asmName, AssemblyBuilderAccess.Save, AdmiralEnvironment.DomainComponentDefineDirectory.FullName);

            #region 定义模块

            var module = assembly.DefineDynamicModule(assemblyName, newFileName);

            #endregion

            #endregion

            #region 设置文件版本

            var asmFileVerCtor = typeof(AssemblyFileVersionAttribute).GetConstructor(new[] { typeof(string) });

            var asmFileVer = new CustomAttributeBuilder(asmFileVerCtor, new object[] { ver.ToString() });

            assembly.SetCustomAttribute(asmFileVer);

            #endregion

            #region XafModule

            var xafModule = module.DefineType("RuntimeModule", TypeAttributes.Public | TypeAttributes.Class, typeof(RuntimeModuleBase));
            var ctor      = xafModule.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard | CallingConventions.HasThis, Type.EmptyTypes);
            var baseCtor  = typeof(RuntimeModuleBase).GetConstructor(Type.EmptyTypes);

            var il = ctor.GetILGenerator();

            //.maxstack 8
            //L_0000: ldarg.0
            //L_0001: call instance void Admiral.ERP.Module.RuntimeModuleBase::.ctor()
            //L_0006: ret
            il.Emit(OpCodes.Ldarg_0);
            il.Emit(OpCodes.Call, baseCtor);
            il.Emit(OpCodes.Ret);
            xafModule.CreateType();

            #endregion

            #region 创建业务对象

            var bos = ObjectSpace.GetObjects <IBusinessObject>(new BinaryOperator("IsRuntimeDefine", true)).OrderBy(x => x.CreateIndex).ToArray();

            var types = new Dictionary <IBusinessObjectBase, TypeBuilder>();

            foreach (var bo in bos)
            {
                var type = module.DefineType("BusinessObject." + bo.BusinessObjectName, TypeAttributes.Interface | TypeAttributes.Public | TypeAttributes.Abstract);


                AddDomainAttribute(type, bo.RegisterType);

                if (!bo.IsPersistent)
                {
                    AddNonPersistentDc(type);
                }

                if (bo.DefaultProperty != null)
                {
                    AddDefaultProperty(type, bo.DefaultProperty);
                }
                if (bo.NavigationGroup != null)
                {
                    AddNavigationItem(type, bo.NavigationGroup.Name);
                }

                if (!string.IsNullOrEmpty(bo.Caption))
                {
                    type.ModelDefault("Caption", bo.Caption);
                }

                if (bo.Icon != null)
                {
                    type.ModelDefault("ImageName", bo.Icon.ImageName);
                }
                else
                {
                    type.ModelDefault("ImageName", "BO_Unknown");
                }

                if (bo.IsCloneable.HasValue)
                {
                    type.ModelDefault("IsCloneable", bo.IsCloneable.Value.ToString().ToLower());
                }
                if (bo.IsCreatableItem.HasValue)
                {
                    type.ModelDefault("IsCreatableItem", bo.IsCreatableItem.Value.ToString().ToLower());
                }
                if (bo.IsVisibileInReports.HasValue)
                {
                    type.VisibileInReport(bo.IsVisibileInReports.Value);
                }
                types.Add(bo, type);
            }

            foreach (var bo in bos)
            {
                var type = types[bo];

                #region 处理基类

                foreach (var bi in bo.Bases)
                {
                    type.AddInterfaceImplementation(ImportTypeReference(bi, types));
                }

                #endregion

                #region 填加属性

                foreach (var p in bo.Properties)
                {
                    p.BuildProperty(type, types);
                }

                #endregion

                try
                {
                    type.CreateType();
                }
                catch (Exception ex)
                {
                    throw new Exception("创建类" + type.Name + "时出错:" + ex.Message);
                }
            }

            #endregion

            #region 保存生成的程序集

            assembly.Save(newFileName);
            File.WriteAllText(AdmiralEnvironment.DomainComponentDefineConfig.FullName, AdmiralEnvironment.DomainComponentDefineDirectory.FullName + "\\" + newFileName);

            #endregion

            #region  除模块信息

            var moduleInfo = ObjectSpace.FindObject <ModuleInfo>(new BinaryOperator("Name", "ERPModule"));
            if (moduleInfo != null)
            {
                ObjectSpace.Delete(moduleInfo);
                ObjectSpace.CommitChanges();
            }

            #endregion
        }
 public void Capture(ObjectSpace objectSpace) {
     var objectType = XafTypesInfo.Instance.FindBussinessObjectType<ISequenceReleasedObject>();
     var objectByKey = objectSpace.GetObjectByKey(objectType, _sequenceReleasedObjectKey);
     if (objectByKey != null)
         objectSpace.Delete(objectByKey);
 }
 private void GenerateGraph(ISerializationConfiguration serializationConfiguration)
 {
     ObjectSpace.Delete(serializationConfiguration.SerializationGraph);
     new ClassInfoGraphNodeBuilder().Generate(serializationConfiguration);
 }