Ejemplo n.º 1
0
        public static XPBaseObject GetXpObjectByKeyValue(ObjectSpace oSpace, string value, Type type) {
            if (string.IsNullOrEmpty(value))
                return null;

            if (!type.IsSubclassOf(typeof(XPBaseObject)))
                return null;

            var keyPropertyName = oSpace.Session.GetClassInfo(type).
                        PersistentProperties.
                        OfType<XPMemberInfo>().
                        Where(p => p.HasAttribute(typeof(KeyPropertyAttribute))).
                        Select(p => p.Name).
                        FirstOrDefault() ??

                    oSpace.Session.GetClassInfo(type).
                        PersistentProperties.
                        OfType<XPMemberInfo>().
                        Where(p => p.Name == "Name" || p.Name == "Code")
                        .Select(p => p.Name)
                        .FirstOrDefault() ??
                    "Oid";

            var item = (XPBaseObject)oSpace.FindObject(
                                type,
                                new BinaryOperator(keyPropertyName, value),
                                true);
            if (item != null)
                return item;

            var nestedObjectSpace = oSpace.CreateNestedObjectSpace();
            item = (XPBaseObject)nestedObjectSpace.CreateObject(type);
            item.ClassInfo.PersistentProperties.
                OfType<XPMemberInfo>().
                Where(p => p.Name == keyPropertyName).
                FirstOrDefault().
                SetValue(item, value);

            item.Save();
            nestedObjectSpace.CommitChanges();

            return oSpace.GetObject(item);

        }
Ejemplo n.º 2
0
        public override void UpdateDatabaseAfterUpdateSchema()
        {
            base.UpdateDatabaseAfterUpdateSchema();
            if (ObjectSpace.FindObject <Customer>(null) == null)
            {
                var customer = ObjectSpace.CreateObject <Customer>();
                customer.Name = "Apostolis Bekiaris";
                var order = ObjectSpace.CreateObject <Order>();
                order.Quantity = 2;
                customer.Orders.Add(order);

                order          = ObjectSpace.CreateObject <Order>();
                order.Quantity = 3;
                customer.Orders.Add(order);

                order          = ObjectSpace.CreateObject <Order>();
                order.Quantity = 4;
                customer.Orders.Add(order);
                ObjectSpace.CommitChanges();
            }
        }
Ejemplo n.º 3
0
        void BindMember(IMemberInfo memberInfo)
        {
            var           pivotedPropertyAttribute = memberInfo.FindAttribute <PivotedPropertyAttribute>();
            IAnalysisInfo analysisInfo;

            if (string.IsNullOrEmpty(pivotedPropertyAttribute.AnalysisCriteria))
            {
                analysisInfo = (IAnalysisInfo)ObjectSpace.CreateObject(memberInfo.MemberType);
                var pivotedType = View.ObjectTypeInfo.FindMember(pivotedPropertyAttribute.CollectionName).ListElementType;
                ((XPObjectSpace)ObjectSpace).Session.GetClassInfo(analysisInfo).GetMember(analysisInfo.GetPropertyName(x => x.DataType)).SetValue(analysisInfo, pivotedType);
            }
            else
            {
                analysisInfo = ObjectSpace.FindObject(memberInfo.MemberType, CriteriaOperator.Parse(pivotedPropertyAttribute.AnalysisCriteria)) as IAnalysisInfo;
                if (analysisInfo == null)
                {
                    throw new UserFriendlyException(new Exception("Could not find a " + memberInfo.MemberType.Name + " object that can fit " + pivotedPropertyAttribute.AnalysisCriteria));
                }
            }
            memberInfo.SetValue(View.CurrentObject, analysisInfo);
        }
Ejemplo n.º 4
0
        private void Duyet_Execute(object sender, SimpleActionExecuteEventArgs e)
        {
            LanTangCa lanTangCa = (LanTangCa)View.CurrentObject;

            lanTangCa.ngayDuyet  = DateTime.Today;
            lanTangCa.nguoiDuyet = lanTangCa.Session.GetObjectByKey <NguoiDung>(SecuritySystem.CurrentUserId);

            CriteriaOperator criteriaOperator = CriteriaOperator.And(CriteriaOperator.Parse("[nguoiChamCong] = ?", lanTangCa.nguoiTangCa), CriteriaOperator.Parse("[ngay.ngayChamCong] = ?", lanTangCa.ngayTangCa));
            GioCong          gio = ObjectSpace.FindObject <GioCong>(criteriaOperator);

            if (!Equals(gio, null))
            {
                gio.soGioTangCa   = lanTangCa.thoiGianTangCa;
                gio.ngayDuyet     = lanTangCa.ngayDuyet;
                lanTangCa.gioCong = gio;
            }

            ObjectSpace.CommitChanges();
            ObjectSpace.Refresh();
            View.Refresh();
        }
Ejemplo n.º 5
0
        private PermissionPolicyRole CreateDefaultRole()
        {
            PermissionPolicyRole defaultRole = ObjectSpace.FindObject <PermissionPolicyRole>(new BinaryOperator("Name", "Default"));

            if (defaultRole == null)
            {
                defaultRole      = ObjectSpace.CreateObject <PermissionPolicyRole>();
                defaultRole.Name = "Default";

                defaultRole.AddObjectPermission <PermissionPolicyUser>(SecurityOperations.Read, "[Oid] = CurrentUserId()", SecurityPermissionState.Allow);
                defaultRole.AddNavigationPermission(@"Application/NavigationItems/Items/Default/Items/MyDetails", SecurityPermissionState.Allow);
                defaultRole.AddMemberPermission <PermissionPolicyUser>(SecurityOperations.Write, "ChangePasswordOnFirstLogon", "[Oid] = CurrentUserId()", SecurityPermissionState.Allow);
                defaultRole.AddMemberPermission <PermissionPolicyUser>(SecurityOperations.Write, "StoredPassword", "[Oid] = CurrentUserId()", SecurityPermissionState.Allow);
                defaultRole.AddTypePermissionsRecursively <PermissionPolicyRole>(SecurityOperations.Read, SecurityPermissionState.Deny);
                defaultRole.AddTypePermissionsRecursively <ModelDifference>(SecurityOperations.ReadWriteAccess, SecurityPermissionState.Allow);
                defaultRole.AddTypePermissionsRecursively <ModelDifferenceAspect>(SecurityOperations.ReadWriteAccess, SecurityPermissionState.Allow);
                defaultRole.AddTypePermissionsRecursively <ModelDifference>(SecurityOperations.Create, SecurityPermissionState.Allow);
                defaultRole.AddTypePermissionsRecursively <ModelDifferenceAspect>(SecurityOperations.Create, SecurityPermissionState.Allow);
            }
            return(defaultRole);
        }
Ejemplo n.º 6
0
        private void CreateDataToBeAnalysed()
        {
            Analysis taskAnalysis1 = ObjectSpace.FindObject <Analysis>(CriteriaOperator.Parse("Name='Completed tasks'"));

            if (taskAnalysis1 == null)
            {
                taskAnalysis1                = ObjectSpace.CreateObject <Analysis>();
                taskAnalysis1.Name           = "Completed tasks";
                taskAnalysis1.ObjectTypeName = typeof(DemoTask).FullName;
                /*taskAnalysis1.Criteria = "[Status] = 'Completed'";*/
                taskAnalysis1.Criteria = "[Status_Int] = " + ((Int32)TaskStatus.Completed).ToString();
            }
            Analysis taskAnalysis2 = ObjectSpace.FindObject <Analysis>(CriteriaOperator.Parse("Name='Estimated and actual work comparison'"));

            if (taskAnalysis2 == null)
            {
                taskAnalysis2                = ObjectSpace.CreateObject <Analysis>();
                taskAnalysis2.Name           = "Estimated and actual work comparison";
                taskAnalysis2.ObjectTypeName = typeof(DemoTask).FullName;
            }
        }
Ejemplo n.º 7
0
        //private Permissao ConsultarTarefa()
        //{
        //    Permissao consultarT = ObjectSpace.FindObject<Permissao>(new BinaryOperator("Name", "ConsultarTarefa"));
        //    if (consultarT == null)
        //    {
        //        consultarT = ObjectSpace.CreateObject<Permissao>();
        //        consultarT.Name = "ConsultarTarefa";
        //    }
        //    consultarT.PermissionPolicy = SecurityPermissionPolicy.DenyAllByDefault;
        //    consultarT.Save();
        //    return consultarT;
        //}

        private Permissao DefinirResponsavel()
        {
            Permissao DefResp = ObjectSpace.FindObject <Permissao>(new BinaryOperator("Name", "DefinirResponsavel"));

            if (DefResp == null)
            {
                DefResp      = ObjectSpace.CreateObject <Permissao>();
                DefResp.Name = "DefinirResponsavel";
            }
            DefResp.PermissionPolicy = SecurityPermissionPolicy.DenyAllByDefault;
            DefResp.AddTypePermissionsRecursively <Tarefa>("Write;Read", SecurityPermissionState.Allow);
            DefResp.AddTypePermissionsRecursively <SubTarefa>("Write;Read", SecurityPermissionState.Allow);
            DefResp.AddTypePermissionsRecursively <Usuario>("Read", SecurityPermissionState.Allow);
            DefResp.AddTypePermissionsRecursively <Versao>("Read", SecurityPermissionState.Allow);
            DefResp.AddTypePermissionsRecursively <Projeto>("Read", SecurityPermissionState.Allow);


            DefResp.AddNavigationPermission(@"Application/NavigationItems/Items/Tarefas/Items/ConsultarTarefa_ListView", SecurityPermissionState.Allow);
            DefResp.Save();
            return(DefResp);
        }
Ejemplo n.º 8
0
        private Permissao CadastrarTarefa()
        {
            Permissao CadTarefa = ObjectSpace.FindObject <Permissao>(new BinaryOperator("Name", "CadastrarTarefa"));

            if (CadTarefa == null)
            {
                CadTarefa      = ObjectSpace.CreateObject <Permissao>();
                CadTarefa.Name = "CadastrarTarefa";
            }
            CadTarefa.PermissionPolicy = SecurityPermissionPolicy.DenyAllByDefault;
            CadTarefa.AddTypePermissionsRecursively <Tarefa>("Create;Write;Read;Delete", SecurityPermissionState.Allow);
            CadTarefa.AddTypePermissionsRecursively <SubTarefa>("Create;Write;Read;Delete", SecurityPermissionState.Allow);
            CadTarefa.AddTypePermissionsRecursively <Versao>("Read", SecurityPermissionState.Allow);
            CadTarefa.AddTypePermissionsRecursively <Usuario>("Read", SecurityPermissionState.Allow);

            CadTarefa.AddNavigationPermission(@"Application/NavigationItems/Items/Tarefas/Items/ConsultarTarefa_ListView", SecurityPermissionState.Allow);
            CadTarefa.AddNavigationPermission(@"Application/NavigationItems/Items/Tarefas/Items/CriarTarefa_DetailView", SecurityPermissionState.Allow);
            CadTarefa.AddNavigationPermission(@"Application/NavigationItems/Items/Tarefas/Items/Criar SubTarefa", SecurityPermissionState.Allow);
            CadTarefa.Save();
            return(CadTarefa);
        }
Ejemplo n.º 9
0
        private void InitialDataEntryController_Activated(object sender, EventArgs e)
        {
            //เริ่มสร้าง
            OpenSendScore oss = ObjectSpace.FindObject <OpenSendScore>(CriteriaOperator.Parse("Open = ?", true));

            if (oss != null)
            {
                if (oss.ERound != null)
                {
                    Employee owner  = ObjectSpace.GetObjectByKey <Employee>(SecuritySystem.CurrentUserId);
                    Score    oscore = ObjectSpace.FindObject <Score>(CriteriaOperator.Parse("ERound = ? AND Office=?", oss.ERound, 995));
                    if (oscore == null)
                    {
                        CreateAll(oss, owner);
                    }
                    else
                    {
                        MessageOptions options = new MessageOptions();
                        options.Duration     = 2000;
                        options.Message      = string.Format("{0} มีการสร้างตารางข้อมูลแล้ว!!!", oss.ERound.Title);
                        options.Type         = InformationType.Error;
                        options.Web.Position = InformationPosition.Top;
                        options.Win.Caption  = "Error";
                        options.Win.Type     = WinMessageType.Flyout;
                        Application.ShowViewStrategy.ShowMessage(options);
                    }
                }
            }
            else
            {
                MessageOptions options = new MessageOptions();
                options.Duration     = 2000;
                options.Message      = string.Format("ยังไม่เปิดให้บันทึกข้อมูล หรือ ไม่มีรอบประเมินที่เปิด!!!");
                options.Type         = InformationType.Error;
                options.Web.Position = InformationPosition.Top;
                options.Win.Caption  = "Error";
                options.Win.Type     = WinMessageType.Flyout;
                Application.ShowViewStrategy.ShowMessage(options);
            }
        }
Ejemplo n.º 10
0
        private PermissionPolicyRole GetAccountantRole()
        {
            PermissionPolicyRole role = ObjectSpace.FindObject <PermissionPolicyRole>(new BinaryOperator("Name", "Accountants"));

            if (role == null)
            {
                role      = ObjectSpace.CreateObject <PermissionPolicyRole>();
                role.Name = "Accountants";

                role.AddNavigationPermission("Application/NavigationItems/Items/Default/Items/MyDetails", SecurityPermissionState.Allow);
                role.AddNavigationPermission("Application/NavigationItems/Items/Default/Items/Department_ListView", SecurityPermissionState.Allow);
                role.AddNavigationPermission("Application/NavigationItems/Items/Default/Items/Employee_ListView", SecurityPermissionState.Allow);

                role.AddNavigationPermission("Application/NavigationItems/Items/Default/Items/Customer_ListView", SecurityPermissionState.Allow);
                role.AddNavigationPermission("Application/NavigationItems/Items/Default/Items/Invoice_ListView", SecurityPermissionState.Allow);


                role.AddObjectPermission <Department>(SecurityOperations.Read, "Employees[Oid=CurrentUserId()]", SecurityPermissionState.Allow);

                role.SetTypePermission <Employee>(SecurityOperations.Create, SecurityPermissionState.Allow);
                role.AddObjectPermission <Employee>(SecurityOperations.FullObjectAccess, "IsNull(Department) || Department.Employees[Oid=CurrentUserId()]", SecurityPermissionState.Allow);

                role.SetTypePermission <EmployeeTask>(SecurityOperations.Create, SecurityPermissionState.Allow);
                role.AddObjectPermission <EmployeeTask>(SecurityOperations.FullObjectAccess,
                                                        "IsNull(AssignedTo) || IsNull(AssignedTo.Department) || AssignedTo.Department.Employees[Oid=CurrentUserId()]", SecurityPermissionState.Allow);

                role.SetTypePermission <PermissionPolicyRole>(SecurityOperations.Read, SecurityPermissionState.Allow);

                role.SetTypePermission <Department>(SecurityOperations.Read, SecurityPermissionState.Allow);
                //  role.SetTypePermission<Invoice>(SecurityOperations.Create, SecurityPermissionState.Allow);
                role.SetTypePermission <InvoiceItem>(SecurityOperations.FullObjectAccess, SecurityPermissionState.Allow);
                role.SetTypePermission <Product>(SecurityOperations.Read, SecurityPermissionState.Allow);

                role.SetTypePermission <Customer>(SecurityOperations.Read, SecurityPermissionState.Allow);
                role.AddObjectPermission <Invoice>(SecurityOperations.FullObjectAccess, "[Klient] Is Null Or [Klient.Consultant] Is Null Or [Klient.Consultant.Department.Employees][[Oid] = CurrentUserId()]", SecurityPermissionState.Allow);
                role.AddObjectPermission <Customer>(SecurityOperations.FullObjectAccess, "[Consultant] Is Null Or [Consultant.Department.Employees][[Oid] = CurrentUserId()]", SecurityPermissionState.Allow);
                //    role.AddObjectPermission<Empl>(SecurityOperations.FullObjectAccess, "[Consultant] Is Null Or [Consultant.Department.Employees][[Oid] = CurrentUserId()]", SecurityPermissionState.Allow);
            }
            return(role);
        }
Ejemplo n.º 11
0
        private IDCRole GetDefaultRole()
        {
            IDCRole defaultRole = ObjectSpace.FindObject <IDCRole>(new BinaryOperator("Name", "Default"));

            if (defaultRole == null)
            {
                defaultRole      = ObjectSpace.CreateObject <IDCRole>();
                defaultRole.Name = "Default";

                IDCTypePermissions securityDemoUserPermissions = ObjectSpace.CreateObject <IDCTypePermissions>();
                securityDemoUserPermissions.TargetType = typeof(IDCUser);
                defaultRole.TypePermissions.Add(securityDemoUserPermissions);

                IDCObjectPermissions myDetailsPermission = ObjectSpace.CreateObject <IDCObjectPermissions>();
                myDetailsPermission.Criteria      = "[Oid] = CurrentUserId()";
                myDetailsPermission.AllowNavigate = true;
                myDetailsPermission.AllowRead     = true;
                securityDemoUserPermissions.ObjectPermissions.Add(myDetailsPermission);

                IDCTypePermissions userPermissions = ObjectSpace.CreateObject <IDCTypePermissions>();
                userPermissions.TargetType = typeof(IDCUser);
                defaultRole.TypePermissions.Add(userPermissions);

                IDCMemberPermissions ownPasswordPermission = ObjectSpace.CreateObject <IDCMemberPermissions>();
                ownPasswordPermission.Members    = "ChangePasswordOnFirstLogon; StoredPassword";
                ownPasswordPermission.AllowWrite = true;
                userPermissions.MemberPermissions.Add(ownPasswordPermission);

                IDCTypePermissions securityRolePermissions = ObjectSpace.CreateObject <IDCTypePermissions>();
                securityRolePermissions.TargetType = typeof(IDCRole);
                defaultRole.TypePermissions.Add(userPermissions);

                IDCObjectPermissions defaultRolePermission = ObjectSpace.CreateObject <IDCObjectPermissions>();
                defaultRolePermission.Criteria      = "[Name] = 'Default'";
                defaultRolePermission.AllowNavigate = true;
                defaultRolePermission.AllowRead     = true;
                securityRolePermissions.ObjectPermissions.Add(defaultRolePermission);
            }
            return(defaultRole);
        }
 public override void UpdateDatabaseAfterUpdateSchema()
 {
     base.UpdateDatabaseAfterUpdateSchema();
     if (ObjectSpace.FindObject <BusinessObject>(null) == null)
     {
         var obj = ObjectSpace.CreateObject <BusinessObject>();
         obj.FieldA = "aaa";
         obj.FieldB = "bbb";
         obj.FieldC = "ccc";
         obj.FieldD = "ddd";
         obj.FieldE = "eee";
         obj.FieldF = "fff";
         obj.FieldG = "ggg";
         obj.FieldH = "hhh";
         obj.FieldI = "iii";
         obj.FieldJ = "jjj";
         obj.FieldK = "kkk";
         obj.FieldL = "lll";
         obj.FieldM = "mmm";
         obj.FieldN = "nnn";
     }
 }
Ejemplo n.º 13
0
        public override void UpdateDatabaseAfterUpdateSchema()
        {
            base.UpdateDatabaseAfterUpdateSchema();

            if (ObjectSpace.FindObject <HierarchicalResource>(null) == null)
            {
                List <HierarchicalResource> list = new List <HierarchicalResource>();
                int    num = 12;
                Random rnd = new Random();
                for (int i = 0; i < num; i++)
                {
                    HierarchicalResource r = ObjectSpace.CreateObject <HierarchicalResource>();
                    r.Name  = string.Format("Resource{0}", i);
                    r.Color = GetColor(rnd.NextDouble(), rnd.NextDouble(), rnd.NextDouble());
                    if (list.Count > 0)
                    {
                        r.Parent = list[rnd.Next(list.Count)];
                    }
                    list.Add(r);
                }
            }
        }
Ejemplo n.º 14
0
        public override void UpdateDatabaseAfterUpdateSchema()
        {
            base.UpdateDatabaseAfterUpdateSchema();
            string    name      = "Test1";
            DemoClass theObject = ObjectSpace.FindObject <DemoClass>(CriteriaOperator.Parse("Name=?", name));

            if (theObject == null)
            {
                theObject      = ObjectSpace.CreateObject <DemoClass>();
                theObject.Name = name;
                CreateParameters();
                theObject.Parameter = ObjectSpace.FindObject <DemoParameter>(CriteriaOperator.Parse("Name=?", "Param 102"));
            }
            name      = "Test2";
            theObject = ObjectSpace.FindObject <DemoClass>(CriteriaOperator.Parse("Name=?", name));
            if (theObject == null)
            {
                theObject           = ObjectSpace.CreateObject <DemoClass>();
                theObject.Name      = name;
                theObject.Parameter = ObjectSpace.FindObject <DemoParameter>(CriteriaOperator.Parse("Name=?", "Param 202"));
            }
        }
Ejemplo n.º 15
0
        //-------------------------//
        #region Permissões de Acesso ao Sistema

        private Permissao CadastrarProjeto()
        {
            Permissao CadProjRole = ObjectSpace.FindObject <Permissao>(new BinaryOperator("Name", "CadastrarProjeto"));

            if (CadProjRole == null)
            {
                CadProjRole      = ObjectSpace.CreateObject <Permissao>();
                CadProjRole.Name = "CadastrarProjeto";
                CadProjRole.AddObjectPermission <PermissionPolicyUser>(SecurityOperations.Read, "[Oid] = CurrentUserId()", SecurityPermissionState.Allow);
            }
            CadProjRole.PermissionPolicy = SecurityPermissionPolicy.DenyAllByDefault;
            CadProjRole.AddTypePermissionsRecursively <Projeto>("Create;Write;Read", SecurityPermissionState.Allow);
            CadProjRole.AddTypePermissionsRecursively <Tarefa>("Read", SecurityPermissionState.Allow);
            CadProjRole.AddTypePermissionsRecursively <SubTarefa>("Read", SecurityPermissionState.Allow);
            CadProjRole.AddTypePermissionsRecursively <Versao>("Read", SecurityPermissionState.Allow);
            CadProjRole.AddTypePermissionsRecursively <Usuario>("Read", SecurityPermissionState.Allow);

            CadProjRole.AddNavigationPermission(@"Application/NavigationItems/Items/Projetos/Items/Projeto_ListView", SecurityPermissionState.Allow);
            CadProjRole.AddNavigationPermission(@"Application/NavigationItems/Items/Projetos/Items/CriarProjeto_DetailView", SecurityPermissionState.Allow);
            CadProjRole.Save();
            return(CadProjRole);
        }
Ejemplo n.º 16
0
 public override void UpdateDatabaseAfterUpdateSchema()
 {
     base.UpdateDatabaseAfterUpdateSchema();
     if (ObjectSpace.FindObject <Contact>(CriteriaOperator.Parse(
                                              "FirstName == 'Mary' && LastName == 'Tellitson'")) == null)
     {
         Contact contact = ObjectSpace.CreateObject <Contact>();
         contact.FirstName = "Mary";
         contact.LastName  = "Tellitson";
         contact.Email     = "*****@*****.**";
         contact.Save();
     }
     if (ObjectSpace.FindObject <Contact>(CriteriaOperator.Parse(
                                              "FirstName == 'Andrew' && LastName == 'Fuller'")) == null)
     {
         Contact contact = ObjectSpace.CreateObject <Contact>();
         contact.FirstName = "Andrew";
         contact.LastName  = "Fuller";
         contact.Email     = "*****@*****.**";
         contact.Save();
     }
 }
Ejemplo n.º 17
0
        public override void UpdateDatabaseAfterUpdateSchema()
        {
            base.UpdateDatabaseAfterUpdateSchema();
            Version currentModuleVersion = typeof(WorkflowModule).Assembly.GetName().Version;
            var     workflowModuleInfo   = ObjectSpace.FindObject <ModuleInfo>(new BinaryOperator("Name", "WorkflowModule"));

            if (workflowModuleInfo != null)
            {
                var dbModuleVersion = new Version(workflowModuleInfo.Version);
                if (dbModuleVersion < currentModuleVersion)
                {
                    if (dbModuleVersion.Major != currentModuleVersion.Major ||
                        dbModuleVersion.Minor != currentModuleVersion.Minor)
                    {
                        UpdateVersionInXaml(XafTypesInfo.Instance.FindTypeInfo(typeof(ScheduledWorkflow)),
                                            dbModuleVersion, currentModuleVersion);
                        UpdateVersionInXaml(XafTypesInfo.Instance.FindTypeInfo(typeof(ObjectChangedWorkflow)),
                                            dbModuleVersion, currentModuleVersion);
                    }
                }
            }
        }
Ejemplo n.º 18
0
        public override void UpdateDatabaseAfterUpdateSchema()
        {
            base.UpdateDatabaseAfterUpdateSchema();
            SimpleUser sam = ObjectSpace.FindObject <SimpleUser>(new BinaryOperator("UserName", "Sam"));

            if (sam == null)
            {
                sam                 = ObjectSpace.CreateObject <SimpleUser>();
                sam.UserName        = "******";
                sam.IsAdministrator = true;
                sam.Save();
            }
            SimpleUser john = ObjectSpace.FindObject <SimpleUser>(new BinaryOperator("UserName", "John"));

            if (john == null)
            {
                john                 = ObjectSpace.CreateObject <SimpleUser>();
                john.UserName        = "******";
                john.IsAdministrator = true;
                john.Save();
            }
        }
        public override void UpdateDatabaseAfterUpdateSchema()
        {
            base.UpdateDatabaseAfterUpdateSchema();
            Contact contactJane = ObjectSpace.FindObject <Contact>(
                new BinaryOperator("Name", "Jane Smith"));

            if (contactJane == null)
            {
                contactJane       = ObjectSpace.CreateObject <Contact>();
                contactJane.Name  = "Jane Smith";
                contactJane.Email = "*****@*****.**";
            }
            Contact contactJohn = ObjectSpace.FindObject <Contact>(
                new BinaryOperator("Name", "John Smith"));

            if (contactJohn == null)
            {
                contactJohn       = ObjectSpace.CreateObject <Contact>();
                contactJohn.Name  = "John Smith";
                contactJohn.Email = "*****@*****.**";
            }
        }
Ejemplo n.º 20
0
        private void Update()
        {
            Settings result = ObjectSpace.FindObject <Settings>(null);

            if (result != null)
            {
                if (ObjectSpace.FindObject <SettingsPrefix>(new BinaryOperator("Prefix", "S")) == null)
                {
                    SettingsPrefix settingsPrefix = ObjectSpace.CreateObject <SettingsPrefix>();
                    settingsPrefix.DataType        = typeof(Sale);
                    settingsPrefix.Prefix          = "S";
                    settingsPrefix.SystemGenerated = true;
                    result.SystemPrefixes.Add(settingsPrefix);

                    SettingsTerms settingsTerms = ObjectSpace.CreateObject <SettingsTerms>();
                    settingsTerms.DataType        = typeof(Sale);
                    settingsTerms.SystemGenerated = true;
                    settingsTerms.Terms           = "These are the default Sale Terms. Please replace them with your terms in settings";
                    result.SystemTerms.Add(settingsTerms);
                }
            }
        }
Ejemplo n.º 21
0
        void ShowSerializationView(SingleChoiceActionExecuteEventArgs singleChoiceActionExecuteEventArgs)
        {
            var groupObjectType    = XafTypesInfo.Instance.FindBussinessObjectType <ISerializationConfigurationGroup>();
            var showViewParameters = singleChoiceActionExecuteEventArgs.ShowViewParameters;

            showViewParameters.TargetWindow = TargetWindow.NewModalWindow;
            View view;

            if (ObjectSpace.FindObject(groupObjectType, null) == null)
            {
                IObjectSpace objectSpace         = Application.CreateObjectSpace(XafTypesInfo.Instance.FindBussinessObjectType <ISerializationConfigurationGroup>());
                var          objectFromInterface = objectSpace.CreateObjectFromInterface <ISerializationConfigurationGroup>();
                view = Application.CreateDetailView(objectSpace, objectFromInterface);
            }
            else
            {
                IObjectSpace objectSpace = Application.CreateObjectSpace(groupObjectType);
                view = Application.CreateListView(objectSpace, groupObjectType, true);
            }
            showViewParameters.CreatedView = view;
            AddDialogController(showViewParameters);
        }
Ejemplo n.º 22
0
        public override void UpdateDatabaseAfterUpdateSchema()
        {
            base.UpdateDatabaseAfterUpdateSchema();
            OAuthUser sampleUser = ObjectSpace.FindObject <OAuthUser>(new BinaryOperator("UserName", "User"));

            if (sampleUser == null)
            {
                sampleUser          = ObjectSpace.CreateObject <OAuthUser>();
                sampleUser.UserName = "******";
                sampleUser.EnableStandardAuthentication = true;
                sampleUser.SetPassword("");
            }
            PermissionPolicyRole defaultRole = CreateDefaultRole();

            sampleUser.Roles.Add(defaultRole);

            OAuthUser userAdmin = ObjectSpace.FindObject <OAuthUser>(new BinaryOperator("UserName", "Admin"));

            if (userAdmin == null)
            {
                userAdmin          = ObjectSpace.CreateObject <OAuthUser>();
                userAdmin.UserName = "******";
                userAdmin.EnableStandardAuthentication = true;
                // Set a password if the standard Authentication type is used
                userAdmin.SetPassword("");
            }
            // If a role with the Administrators name doesn't exist in the database, create this role
            PermissionPolicyRole adminRole = ObjectSpace.FindObject <PermissionPolicyRole>(new BinaryOperator("Name", "Administrators"));

            if (adminRole == null)
            {
                adminRole      = ObjectSpace.CreateObject <PermissionPolicyRole>();
                adminRole.Name = "Administrators";
            }
            adminRole.IsAdministrative = true;
            userAdmin.Roles.Add(adminRole);
            ObjectSpace.CommitChanges(); //This line persists created object(s).
        }
Ejemplo n.º 23
0
        public override void UpdateDatabaseAfterUpdateSchema()
        {
            base.UpdateDatabaseAfterUpdateSchema();
            SecuritySystemRole adminRole = ObjectSpace.FindObject <SecuritySystemRole>(new BinaryOperator("Name", "Administrators"));

            if (adminRole == null)
            {
                adminRole                  = ObjectSpace.CreateObject <SecuritySystemRole>();
                adminRole.Name             = "Administrators";
                adminRole.IsAdministrative = true;
            }
            SecuritySystemRole userRole = ObjectSpace.FindObject <SecuritySystemRole>(new BinaryOperator("Name", "Users"));

            if (userRole == null)
            {
                userRole      = ObjectSpace.CreateObject <SecuritySystemRole>();
                userRole.Name = "Users";
                userRole.SetTypePermissionsRecursively <object>(SecurityOperations.FullAccess, SecuritySystemModifier.Allow);
            }
            MyUser user1 = ObjectSpace.FindObject <MyUser>(new BinaryOperator("UserName", "Admin"));

            if (user1 == null)
            {
                user1          = ObjectSpace.CreateObject <MyUser>();
                user1.UserName = "******";
                user1.SetPassword("");
                user1.Roles.Add(adminRole);
            }
            MyUser user2 = ObjectSpace.FindObject <MyUser>(new BinaryOperator("UserName", "User"));

            if (user2 == null)
            {
                user2          = ObjectSpace.CreateObject <MyUser>();
                user2.UserName = "******";
                user2.SetPassword("");
                user2.Roles.Add(userRole);
            }
        }
Ejemplo n.º 24
0
        public override void UpdateDatabaseAfterUpdateSchema()
        {
            base.UpdateDatabaseAfterUpdateSchema();

            var sampleUser = ObjectSpace.FindObject <PermissionPolicyUser>(new BinaryOperator("UserName", "User"));

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

            var defaultRole = CreateDefaultRole();

            sampleUser.Roles.Add(defaultRole);

            var userAdmin = ObjectSpace.FindObject <PermissionPolicyUser>(new BinaryOperator("UserName", "Admin"));

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

            var adminRole = ObjectSpace.FindObject <PermissionPolicyRole>(new BinaryOperator("Name", "Administrators"));

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

            adminRole.IsAdministrative = true;
            userAdmin.Roles.Add(adminRole);
            ObjectSpace.CommitChanges();
        }
Ejemplo n.º 25
0
        protected override void OnActivated()
        {
            base.OnActivated();
            CriteriaOperator criteria         = CriteriaOperator.And(CriteriaOperator.Parse("[thangChamCong] Is Null"));
            CriteriaOperator criteriaOperator = new BinaryOperator("Id", new JoinOperand("ThangChamCong", null, Aggregate.Max, new OperandProperty("Id")));
            var thangChamCong = (ThangChamCong)ObjectSpace.FindObject <ThangChamCong>(criteriaOperator);

            if ((Equals(thangChamCong, null)) || thangChamCong.thangChamCong.Month < DateTime.Today.Month)
            {
                ThangChamCong thang     = ObjectSpace.CreateObject <ThangChamCong>();
                DateTime      thangCham = DateTime.Today;
                thang.ngayCapNhat   = DateTime.Now;
                thang.thangChamCong = thangCham;
            }
            else
            {
                IList <NgayTinhCong> ngayTinhCongs = ObjectSpace.GetObjects <NgayTinhCong>(criteria);
                if (!Equals(ngayTinhCongs, null))
                {
                    IList <ThangChamCong> thangChamCongs = ObjectSpace.GetObjects <ThangChamCong>();
                    foreach (NgayTinhCong ngayTinhCong in ngayTinhCongs)
                    {
                        foreach (ThangChamCong thang in thangChamCongs)
                        {
                            if ((ngayTinhCong.ngayChamCong.Month == thang.thangChamCong.Month) && (ngayTinhCong.ngayChamCong.Year == thang.thangChamCong.Year))
                            {
                                ngayTinhCong.thangChamCong = thang;
                                thang.ngayCapNhat          = DateTime.Now;
                            }
                        }
                    }
                }
            }
            ObjectSpace.CommitChanges();
            ObjectSpace.Refresh();
            View.Refresh();
            // Perform various tasks depending on the target View.
        }
Ejemplo n.º 26
0
        private PermissionPolicyRole CreateDefaultRole()
        {
            var defaultRole = ObjectSpace.FindObject <Role>(new BinaryOperator("Name", "Операторы"));

            if (defaultRole == null)
            {
                defaultRole                  = ObjectSpace.CreateObject <Role>();
                defaultRole.Name             = "Операторы";
                defaultRole.CanEditModel     = false;
                defaultRole.IsAdministrative = false;
                defaultRole.PermissionPolicy = SecurityPermissionPolicy.DenyAllByDefault;

                defaultRole.AddObjectPermission <User>(SecurityOperations.Read, "[Oid] = CurrentUserId()", SecurityPermissionState.Allow);
                defaultRole.AddNavigationPermission(@"Application/NavigationItems/Items/Security/Items/MyDetails", SecurityPermissionState.Allow);
                defaultRole.AddMemberPermission <User>(SecurityOperations.Write, "ChangePasswordOnFirstLogon", "[Oid] = CurrentUserId()", SecurityPermissionState.Allow);
                defaultRole.AddMemberPermission <User>(SecurityOperations.Write, "StoredPassword", "[Oid] = CurrentUserId()", SecurityPermissionState.Allow);

                defaultRole.AddTypePermissionsRecursively <Role>(SecurityOperations.Read, SecurityPermissionState.Deny);
                defaultRole.AddTypePermissionsRecursively <ModelDifference>(SecurityOperations.ReadOnlyAccess, SecurityPermissionState.Allow);
                defaultRole.AddTypePermissionsRecursively <ModelDifferenceAspect>(SecurityOperations.ReadOnlyAccess, SecurityPermissionState.Allow);

                defaultRole.AddTypePermissionsRecursively <Order>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow);
                defaultRole.AddTypePermissionsRecursively <OrderRow>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow);
                defaultRole.AddTypePermissionsRecursively <ProductGroup>(SecurityOperations.ReadOnlyAccess, SecurityPermissionState.Allow);
                defaultRole.AddTypePermissionsRecursively <Product>(SecurityOperations.ReadOnlyAccess, SecurityPermissionState.Allow);
                defaultRole.AddTypePermissionsRecursively <PriceList>(SecurityOperations.ReadOnlyAccess, SecurityPermissionState.Allow);
                defaultRole.AddTypePermissionsRecursively <Price>(SecurityOperations.ReadOnlyAccess, SecurityPermissionState.Allow);


                defaultRole.AddNavigationPermission(@"Application/NavigationItems/Items/Default/Items/Orders", SecurityPermissionState.Allow);
                defaultRole.AddNavigationPermission(@"Application/NavigationItems/Items/Default/Items/Catalog", SecurityPermissionState.Deny);
                defaultRole.AddNavigationPermission(@"Application/NavigationItems/Items/Default/Items/PriceLists", SecurityPermissionState.Deny);
                defaultRole.AddNavigationPermission(@"Application/NavigationItems/Items/Reports", SecurityPermissionState.Deny);
                defaultRole.AddNavigationPermission(@"Application/NavigationItems/Items/Security/Items/PermissionPolicyUser_ListView", SecurityPermissionState.Deny);
                defaultRole.AddNavigationPermission(@"Application/NavigationItems/Items/Security/Items/PermissionPolicyRole_ListView", SecurityPermissionState.Deny);
            }
            return(defaultRole);
        }
Ejemplo n.º 27
0
        public override void UpdateDatabaseAfterUpdateSchema()
        {
            base.UpdateDatabaseAfterUpdateSchema();
            if (ObjectSpace.FindObject <Country>(null) == null)
            {
                var country = ObjectSpace.CreateObject <Country>();
                country.Name = "USA";
                var customer = ObjectSpace.CreateObject <Customer>();
                customer.Name    = "DevExpress";
                customer.Country = country;
                customer         = ObjectSpace.CreateObject <Customer>();
                customer.Name    = "Ray";
                customer.Country = country;

                country          = ObjectSpace.CreateObject <Country>();
                country.Name     = "Netherlands";
                country.EUMember = true;
                customer         = ObjectSpace.CreateObject <Customer>();
                customer.Name    = "Impactive";
                customer.Country = country;
                customer         = ObjectSpace.CreateObject <Customer>();
                customer.Name    = "Tolis";
                customer.Country = country;

                var securitySystemRole = (SecuritySystemRole)ObjectSpace.GetRole("Admin");
                securitySystemRole.IsAdministrative = true;
                var user = (SecuritySystemUser)ObjectSpace.GetUser("Admin");
                user.Roles.Add(securitySystemRole);

                securitySystemRole = (SecuritySystemRole)ObjectSpace.GetRole("User");
                securitySystemRole.SetTypePermissions(typeof(Customer), SecurityOperations.FullAccess, SecuritySystemModifier.Allow);
                securitySystemRole.SetTypePermissions(typeof(Country), SecurityOperations.FullAccess, SecuritySystemModifier.Allow);
                user = ObjectSpace.CreateObject <SecuritySystemUser>();
                user.Roles.Add(securitySystemRole);

                ObjectSpace.CommitChanges();
            }
        }
Ejemplo n.º 28
0
        public override void UpdateDatabaseAfterUpdateSchema()
        {
            base.UpdateDatabaseAfterUpdateSchema();


            CreateClassLevelObjects();
            CreateMemberLevelObjects();
            CreateObjectLevelObjects();

            PermissionPolicyRole administratorRole = CreateAdministratorRole();

            PermissionPolicyUser userAdmin = ObjectSpace.FindObject <PermissionPolicyUser>(new BinaryOperator("UserName", "Sam"));

            if (userAdmin == null)
            {
                userAdmin          = ObjectSpace.CreateObject <PermissionPolicyUser>();
                userAdmin.UserName = "******";
                userAdmin.IsActive = true;
                userAdmin.SetPassword("");
                userAdmin.Roles.Add(administratorRole);
            }

            PermissionPolicyRole securityDemoRole = CreateSecurityDemoRole();

            PermissionPolicyUser userJohn = ObjectSpace.FindObject <PermissionPolicyUser>(new BinaryOperator("UserName", "John"));

            if (userJohn == null)
            {
                userJohn          = ObjectSpace.CreateObject <PermissionPolicyUser>();
                userJohn.UserName = "******";
                userJohn.IsActive = true;
                //userJohn.Roles.Add(defaultRole);
                userJohn.Roles.Add(securityDemoRole);
                userJohn.Save();
            }

            ObjectSpace.CommitChanges();
        }
Ejemplo n.º 29
0
        public void MapBankStmtActivityRegex()
        {
            var ccyAud = ObjectSpace.FindObject <Currency>(CriteriaOperator.Parse("Name = ?", "AUD"));

            var account1 = ObjectSpace.CreateObject <Account>();

            account1.Name     = "VHA ANZ 70086";
            account1.Currency = ccyAud;

            var activity1 = ObjectSpace.CreateObject <Activity>();

            activity1.Name = "Reversed AP Pymt";

            var bs1 = ObjectSpace.CreateObject <BankStmt>();

            bs1.TranDate        = new DateTime(2016, 06, 01);
            bs1.Account         = account1;
            bs1.Activity        = activity1;
            bs1.TranDescription = "252040416CMOAU30305823434";
            bs1.TranAmount      = 1000;

            var map = ObjectSpace.CreateObject <BankStmtMapping>();

            map.RowIndex           = 1;
            map.CriteriaExpression = @"Account.Name IN ('VHA ANZ EUR','VHA ANZ GBP','VHA ANZ NZD','VHA ANZ USD') AND dbo.REGEXP(TranDescription, '(\A\d{9,})([a-zA-Z]{0,6})(\d{9,})(.{0,4}\z)')=1 AND TranAmount > 0";
            map.Activity           = activity1;

            ObjectSpace.CommitChanges();

            var bss = ObjectSpace.GetObjects <BankStmt>();

            var mapper = new BankStmtMapper(ObjectSpace);

            mapper.Process(bss);

            bs1 = ObjectSpace.FindObject <BankStmt>(null);
            Assert.NotNull(bs1.Activity);
        }
Ejemplo n.º 30
0
        public override void UpdateDatabaseAfterUpdateSchema()
        {
            base.UpdateDatabaseAfterUpdateSchema();
            var defaultRole = (SecuritySystemRole)ObjectSpace.GetDefaultRole();

            var adminRole = ObjectSpace.GetAdminRole("Admin");
            var adminUser = adminRole.GetUser("Admin");

            var userRole = ObjectSpace.GetRole("User");

            userRole.CanEditModel = true;
            userRole.SetTypePermissionsRecursively <object>(SecurityOperations.FullAccess, SecuritySystemModifier.Allow);

            var user = (SecuritySystemUser)userRole.GetUser("user");

            user.Roles.Add(defaultRole);

            if (ObjectSpace.FindObject <Customer>(null) == null)
            {
                var customer = ObjectSpace.CreateObject <Customer>();
                customer.FirstName = "Apostolis";
                customer.LastName  = "Bekiaris";
                customer.User      = user;
                customer           = ObjectSpace.CreateObject <Customer>();
                customer.FirstName = "FilteredApostolis";
                customer.LastName  = "FilteredBekiaris";
                customer.User      = (SecuritySystemUser)adminUser;

                using (var stream = GetType().Assembly.GetManifestResourceStream(GetType(), "FilterDashboard.xml")){
                    var dashboardDefinition = ObjectSpace.CreateObject <DashboardDefinition>();
                    dashboardDefinition.Name = "Filtered from model";
                    Debug.Assert(stream != null, "stream != null");
                    dashboardDefinition.Xml = new StreamReader(stream).ReadToEnd();
                }
            }

            ObjectSpace.CommitChanges();
        }
Ejemplo n.º 31
0
        protected override void OnActivated()
        {
            base.OnActivated();
            string              condition    = CriteriaOperator.And(CriteriaOperator.Parse("[ngayDuyet] Is Null")).ToString();
            CriteriaOperator    criteria     = CriteriaOperator.Parse(condition);
            IList <LanXinDiTre> lanXinDiTres = ObjectSpace.GetObjects <LanXinDiTre>(criteria);

            foreach (LanXinDiTre lanXinDiTre in lanXinDiTres)
            {
                CriteriaOperator criteriaOperator = CriteriaOperator.And(CriteriaOperator.Parse("[nguoiChamCong] = ?", lanXinDiTre.nguoiTaoPhieu), CriteriaOperator.Parse("[ngay.ngayChamCong] = ?", lanXinDiTre.ngayXinPhep));
                GioCong          gio = ObjectSpace.FindObject <GioCong>(criteriaOperator);
                //if (!Equals(gio, null))
                //{
                //    //gio.soLanDiTre -= 1;
                //    //gio.soLanDiTre = gio.soLanDiTre - 1;
                //}

                lanXinDiTre.gioCong = gio;
            }
            ObjectSpace.CommitChanges();
            ObjectSpace.Refresh();
            View.Refresh();
        }
        private bool IsInDeptStudent(ObjectSpace objectSpace, Student student, out decimal deptAmount)
        {
            deptAmount = 0;
            try
            {
                ConstrainstParameter cp = objectSpace.FindObject<ConstrainstParameter>(
                   new BinaryOperator("Code", "MINDEPTCANENROLL"));

                deptAmount = -Convert.ToDecimal(student.AccountBalance.Value);
                if (deptAmount > Convert.ToDecimal(cp.Value))
                    return true;
            }
            catch { }
            finally { }
            return false;
        }
Ejemplo n.º 33
0
        public void ProccesExcellRows(IEnumerable records, ObjectSpace objectSpace, DoWorkEventArgs e) {

            var i = 0;

            //for every row in excell sheet
            foreach (Row record in records) {
                ++i;
                if (i == 1) continue;
                if (_BgWorker.CancellationPending) { e.Cancel = true; break; }

                //var os = new ObjectSpace(objectSpace, XafTypesInfo.Instance);
                object newObj = null;

                //chech if row contains Oid

                //get key property name of the object type being imported
                var kp = objectSpace.GetKeyPropertyName(Type);
                //check if it exists in excel and is mapped ?
                var idMapping = ImportMap.Mappings.Where(p => p.MapedTo == kp).FirstOrDefault();
                if (idMapping != null && GetQString(record[idMapping.Column].Value) != string.Empty) {
                    try {
                        //find existing object
                        var val = record[idMapping.Column];
                        var gwid = new Guid(GetQString(val.Value));
                        newObj = objectSpace.FindObject(Type, new BinaryOperator(kp, gwid), true);
                    } catch {

                    }
                }
                if (newObj == null) //create a new instance
                    newObj = objectSpace.CreateObject(Type) as IXPSimpleObject;

                string message;
                if (newObj != null) {
                    var props = ((IXPSimpleObject)newObj).ClassInfo.PersistentProperties
                        .OfType<XPMemberInfo>();


                    foreach (var mapping in ImportMap.Mappings) {
                        if (_BgWorker.CancellationPending) { e.Cancel = true; break; }
                        Application.DoEvents();

                        var mapping1 = mapping;
                        var prop = props.Where(p => p.Name == mapping1.MapedTo).FirstOrDefault();

                        try {
                            var val = record[mapping.Column];
                            // continue;

                            if (val != null) {
                                //if simple property
                                if (prop.ReferenceType == null) {
                                    var isNullable = prop.MemberType.IsGenericType && prop.MemberType.GetGenericTypeDefinition() == typeof(Nullable<>);
                                    object convertedValue = null;

                                    if (prop.MemberType == null) return;

                                    if (isNullable) {
                                        if (prop.StorageType == typeof(int)) {
                                            int number;
                                            var rez = Int32.TryParse(val.Value, out number);
                                            if (rez) convertedValue = number;

                                        } else if (prop.StorageType == typeof(DateTime)) {
                                            if (val.Value != string.Empty) {
                                                //Include validate
                                                var dt = DateTime.FromOADate(Convert.ToDouble(val.Value));
                                                convertedValue = dt;
                                            }
                                        } else if (prop.StorageType == typeof(double)) {
                                            double number;
                                            var rez = Double.TryParse(val.Value, out number);
                                            if (rez) convertedValue = number;
                                        }
                                    } else {

                                        if (prop.MemberType == typeof(char))
                                            convertedValue = Convert.ChangeType(GetQString(val.Value), prop.MemberType);
                                        else if (prop.MemberType == typeof(Guid))
                                            convertedValue = new Guid(GetQString(val.Value));
                                        else if (prop.StorageType == typeof(DateTime)) {
                                            if (val.Value != string.Empty) {
                                                //Include validate
                                                var dt = DateTime.FromOADate(Convert.ToDouble(val.Value));
                                                convertedValue = dt;
                                            }
                                        } else if (prop.MemberType == typeof(double)) {
                                            double number;
                                            //  Application.CurrentCulture.NumberFormat.NumberDecimalSeparator = ".";
                                            var rez = Double.TryParse(val.Value, NumberStyles.Number, new NumberFormatInfo { NumberDecimalSeparator = "." }, out number);
                                            if (rez) convertedValue = number;
                                        } else if (prop.MemberType == typeof(bool)) {
                                            if (val.Value != string.Empty && (val.Value.Length == 1 || val.Value.ToLower() == "true" || val.Value.ToLower() == "false")) {
                                                bool truefalse;
                                                if (val.Value.ToLower() == "true" || val.Value.ToLower() == "false")
                                                    truefalse = Convert.ToBoolean(val.Value);
                                                else
                                                    truefalse = Convert.ToBoolean(Convert.ToInt32(val.Value));
                                                convertedValue = truefalse;
                                            }
                                        } else
                                            convertedValue = Convert.ChangeType(val.Value, prop.MemberType);
                                    }

                                    if (convertedValue != null) {
                                        if (convertedValue.GetType() == typeof(double))
                                            convertedValue = Math.Round((double)convertedValue, 2, MidpointRounding.ToEven);

                                        prop.SetValue(newObj, convertedValue);
                                    }
                                }
                                //if referenced property
                                if (prop.ReferenceType != null) {

                                    //if other referenced type
                                    if (prop.MemberType.IsSubclassOf(typeof(XPBaseObject))) {
                                        var text = val.Value;
                                        var typ = prop.MemberType;
                                        var mval = ImportWizard.Helper.GetXpObjectByKeyValue(objectSpace, text, typ);
                                        prop.SetValue(newObj, objectSpace.GetObject(mval));
                                    }
                                }

                            }

                        } catch (Exception E) {
                            message = string.Format("Error processing record {0}. {1}", i, E);
                            _BgWorker.ReportProgress(0, message);
                        }

                        if (CurrentCollectionSource != null)
                            AddNewObjectToCollectionSource(CurrentCollectionSource, newObj, ObjectSpace);
                        ObjectSpace.Session.Save(newObj);
                    }
                }

                objectSpace.CommitChanges();
                message = string.Format("Importing record {0} succesfull.", i);
                _BgWorker.ReportProgress(1, message);
                Application.DoEvents();
            }
        }
Ejemplo n.º 34
0
        public static XPCollection<ClassTransactionTracking> CreateStudentClassTrackingData(ObjectSpace objectSpace, string semesterName)
        {
            string strParse = "";
            try
            {
                using (XPCollection<StudentClass> xpw = new XPCollection<StudentClass>(objectSpace.Session))
                {

                    foreach (StudentClass studentClass in xpw)
                    {
                        ClassTransactionTracking ct = objectSpace.FindObject<ClassTransactionTracking>
                            (CriteriaOperator.Parse("StudentClass.ClassCode = ? and Semester.SemesterName = ?",
                            studentClass.ClassCode, semesterName));
                        if (ct == null)
                        {
                            ct = objectSpace.CreateObject< ClassTransactionTracking>();
                            ct.Semester = objectSpace.FindObject<Semester>(CriteriaOperator.Parse("SemesterName=?", semesterName));
                            ct.StudentClass = objectSpace.FindObject<StudentClass>(CriteriaOperator.Parse("ClassCode=?", studentClass.ClassCode));
                            ct.Save();
                        }

                        strParse += (strParse == "" ? string.Format("StudentClass.ClassCode='{0}'", studentClass.ClassCode) :
                            string.Format(" or StudentClass.ClassCode='{0}'", studentClass.ClassCode));
                    }
                    objectSpace.CommitChanges();
                    strParse = string.Format("({0}) and Semester.SemesterName= '{1}'", strParse, semesterName);
                }
            }
            catch (Exception ex)
            {
                throw new UserFriendlyException(string.Format("Lỗi thực hiện: {0}\r\n Strack trace:{1}", ex.Message, ex.StackTrace));
            }
            return new XPCollection<ClassTransactionTracking>(objectSpace.Session, CriteriaOperator.Parse(strParse));
        }
Ejemplo n.º 35
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));
        }
Ejemplo n.º 36
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))));
        }