Ejemplo n.º 1
0
        private void CreateSimpleType()
        {
            var nameSpace = ObjectSpace.FindObject <Namespace>(new BinaryOperator("FullName", "系统类型"));

            if (nameSpace == null)
            {
                nameSpace      = ObjectSpace.CreateObject <Namespace>();
                nameSpace.Name = "系统类型";
                var createIndex = ObjectSpace.GetObjectsCount(typeof(BusinessObject), null);

                var strType = AddSimpleObject(typeof(string), "string-字符串", nameSpace, "一串文本内容");

                var dec          = AddSimpleObject(typeof(decimal), "decimal-数字", nameSpace, "通常用于记录带小数点的数字,比如表示货币金额时");
                var intt         = AddSimpleObject(typeof(int), "int-整数", nameSpace, "没有小数的数字");
                var datetimeType = AddSimpleObject(typeof(DateTime), "datetime-日期时间", nameSpace, "用于表示日期时间");
                var boolType     = AddSimpleObject(typeof(bool), "bool-布尔", nameSpace, "用于表示是/否,真/假,等2种可选值的情况");
                var imageType    = AddSimpleObject(typeof(Image), "image-图片", nameSpace, "用于表示图像信息");
                var colorType    = AddSimpleObject(typeof(Color), "color-颜色", nameSpace, "用于表示颜色信息");
                AddSimpleObject(typeof(sbyte), "sbyte-整数(8位有符号)", nameSpace, "8位有符号整数");
                AddSimpleObject(typeof(long), "long-整数(64位有符号)", nameSpace, "");
                AddSimpleObject(typeof(byte), "byte-整数(8位无符号)", nameSpace, "");
                AddSimpleObject(typeof(ushort), "ushort-整数(16位无符号)", nameSpace, "");
                AddSimpleObject(typeof(uint), "uint-整数(32位无符号)", nameSpace, "");
                AddSimpleObject(typeof(ulong), "ulong-整数(64位无符号)", nameSpace, "");
                AddSimpleObject(typeof(float), "float-数字(单精度浮点)", nameSpace, "");
                AddSimpleObject(typeof(double), "double-数字(双精度浮点)", nameSpace, "");
                AddSimpleObject(typeof(TimeSpan), "timespan-时间段", nameSpace, "");
                AddSimpleObject(typeof(Guid), "Guid", nameSpace, "全球唯一标识");
            }
        }
Ejemplo n.º 2
0
        public override void UpdateDatabaseAfterUpdateSchema()
        {
            base.UpdateDatabaseAfterUpdateSchema();
            if (ObjectSpace.GetObjectsCount(typeof(A1), null) == 0 && ObjectSpace.GetObjectsCount(typeof(CD_Address), null) == 0)
            {
                //var demoA1Data = new Faker<A1>()
                //    .CustomInstantiator(a1 => new A1(((XPObjectSpace)ObjectSpace).Session))
                //    .RuleFor(o => o.myIndex, bogus => bogus.Random.Int())
                //    .RuleFor(o => o.traceTimeStamp, bogus => bogus.Date.Recent(20))
                //    .RuleFor(o => o.traceComment, bogus => bogus.Lorem.Text())
                //    .RuleFor(o => o.trace_Bool, bogus => bogus.Random.Bool())
                //    .RuleFor(o => o.trace_GUID, bogus => Guid.NewGuid());
                //var a1Data = demoA1Data.Generate(100);

                //var demoAddressData = new Faker<CD_Address>()
                //    .CustomInstantiator(a1 => new CD_Address(((XPObjectSpace)ObjectSpace).Session))
                //    .RuleFor(o => o.Name, bogus => bogus.Name.FirstName())
                //    .RuleFor(o => o.Address, bogus => bogus.Address.Direction())
                //    .RuleFor(o => o.Overflow, bogus => bogus.Lorem.Text())
                //    .RuleFor(o => o.City, bogus => bogus.Address.City())
                //    .RuleFor(o => o.State, bogus => bogus.Address.State());
                //var addressData = demoAddressData.Generate(100);

                ObjectSpace.CommitChanges();
            }

            //ObjectSpace.CommitChanges(); //Uncomment this line to persist created object(s).
        }
 bool TypeHasWorkflows()
 {
     try {
         return(ObjectSpace.GetObjectsCount(typeof(ObjectChangedWorkflow), CriteriaOperator.Parse("TargetObjectType=?", View.ObjectTypeInfo.Type)) > 0);
     } catch (Exception e) {
         Tracing.Tracer.LogError(e);
         return(false);
     }
 }
Ejemplo n.º 4
0
 public override void UpdateDatabaseAfterUpdateSchema()
 {
     base.UpdateDatabaseAfterUpdateSchema();
     if (ObjectSpace.GetObjectsCount(typeof(Person), null) == 0)
     {
         Person p = ObjectSpace.CreateObject <Person>();
         p.FirstName = "Test Person";
         ObjectSpace.CommitChanges();
     }
 }
Ejemplo n.º 5
0
 public override void UpdateDatabaseAfterUpdateSchema()
 {
     base.UpdateDatabaseAfterUpdateSchema();
     //Create the Singleton object
     if (ObjectSpace.GetObjectsCount(typeof(Singleton), null) == 0)
     {
         ObjectSpace.CreateObject <Singleton>();
     }
     ObjectSpace.CommitChanges();
 }
Ejemplo n.º 6
0
        public override void UpdateDatabaseBeforeUpdateSchema()
        {
            base.UpdateDatabaseBeforeUpdateSchema();
            if (ObjectSpace.GetObjectsCount(typeof(Setelan), null) == 0)
            {
                ObjectSpace.CreateObject <Setelan>();
            }

            //if(CurrentDBVersion < new Version("1.1.0.0") && CurrentDBVersion > new Version("0.0.0.0")) {
            //    RenameColumn("DomainObject1Table", "OldColumnName", "NewColumnName");
            //}
        }
 public override void UpdateDatabaseAfterUpdateSchema()
 {
     base.UpdateDatabaseAfterUpdateSchema();
     if (ObjectSpace.GetObjectsCount(typeof(Task), null) == 0)
     {
         for (int i = 1; i <= 100; i++)
         {
             var task = ObjectSpace.CreateObject <Task>();
             task.Subject  = string.Format("Task #{0:000}", i);
             task.Deadline = DateTime.Today.AddDays(i - 30);
         }
     }
 }
Ejemplo n.º 8
0
 private void InitData()
 {
     if (ObjectSpace.GetObjectsCount(typeof(Product), null) < 10000)
     {
         for (int i = 0; i < 10000; i++)
         {
             Product product = ObjectSpace.CreateObject <Product>();
             product.Name        = string.Format("Product{0}", i);
             product.Description = string.Format("Description{0}", i);
             product.Price       = i % 10;
         }
         ObjectSpace.CommitChanges();
     }
 }
 public override void UpdateDatabaseAfterUpdateSchema()
 {
     base.UpdateDatabaseAfterUpdateSchema();
     if (ObjectSpace.GetObjectsCount(typeof(Contact), null) == 0)
     {
         Contact mary = ObjectSpace.CreateObject <Contact>();
         mary.Name        = "Mary";
         mary.Email       = "*****@*****.**";
         mary.PhoneNumber = "(555)123-45-67";
         Contact john = ObjectSpace.CreateObject <Contact>();
         john.Name        = "John";
         john.Email       = "*****@*****.**";
         john.PhoneNumber = "(555)987-65-43";
     }
 }
Ejemplo n.º 10
0
 public override void UpdateDatabaseAfterUpdateSchema()
 {
     base.UpdateDatabaseAfterUpdateSchema();
     if (ObjectSpace.GetObjectsCount(typeof(Contact), null) == 0)
     {
         for (int i = 0; i < 10; i++)
         {
             DatabaseHelper.CreateContact(ObjectSpace);
             DatabaseHelper.CreateAddress(ObjectSpace);
             DatabaseHelper.CreateDocument(ObjectSpace);
             this.UpdateStatus("Creating test data", "", string.Format("Batch #{0} was created", i));
         }
     }
     ObjectSpace.CommitChanges();
 }
Ejemplo n.º 11
0
        private void CreateTQBFDemoObjects()
        {
            var             rnd      = new Random(8573);
            IList <Product> products = null;

            if (ObjectSpace.GetObjectsCount(typeof(Product), null) == 0)
            {
                products = new List <Product>();
                for (var i = 0; i < productNames.Length; i++)
                {
                    var product = ObjectSpace.CreateObject <Product>();
                    product.Name  = productNames[i];
                    product.Price = (80 + rnd.Next(2000)) * 0.01m;
                    products.Add(product);
                }
            }
            if (ObjectSpace.GetObjectsCount(typeof(Order), null) == 0)
            {
                if (products == null)
                {
                    products = ObjectSpace.GetObjects <Product>();
                }
                var now = DateTime.Now;
                for (var i = 0; i < 1000; i++)
                {
                    now = now.AddMinutes(-(1 + rnd.Next(20)));
                    var order = ObjectSpace.CreateObject <Order>();
                    order.Date = now;
                    var dnum = 1 + rnd.Next(21);
                    for (var j = 0; j < dnum; j++)
                    {
                        var product = products[rnd.Next(products.Count)];
                        var detail  = order.Details.FirstOrDefault(d => d.Product == product);
                        if (detail == null)
                        {
                            detail         = ObjectSpace.CreateObject <OrderLine>();
                            detail.Product = product;
                            order.Details.Add(detail);
                        }
                        detail.Quantity++;
                    }
                    order.Address = string.Format("{0} W {1} St", (1 + rnd.Next(15)) * 100 + 1 + rnd.Next(30), rnd.Next(100));
                    order.Total   = order.Details.Sum(d => d.Quantity * d.Product.Price);
                    order.Status  = CalcStatus(now, rnd);
                }
            }
        }
        public override void UpdateDatabaseAfterUpdateSchema()
        {
            base.UpdateDatabaseAfterUpdateSchema();

            if (ObjectSpace.GetObjectsCount(typeof(ExampleObject), null) == 0)
            {
                for (int i = 0; i < 5; i++)
                {
                    ReferencedObject refObject = ObjectSpace.CreateObject <ReferencedObject>();
                    refObject.Name = string.Format("Owner Object {0:d}", i + 1);
                    ExampleObject exampleObj = ObjectSpace.CreateObject <ExampleObject>();
                    exampleObj.Name = string.Format("Example object {0:d}", i + 1);
                    exampleObj.LookupReferencedObject = refObject;
                }
                ObjectSpace.CommitChanges();
            }
        }
Ejemplo n.º 13
0
        public override void UpdateDatabaseAfterUpdateSchema()
        {
            base.UpdateDatabaseAfterUpdateSchema();

            //string name = "MyName";
            //DomainObject1 theObject = ObjectSpace.FindObject<DomainObject1>(CriteriaOperator.Parse("Name=?", name));
            //if(theObject == null) {
            //    theObject = ObjectSpace.CreateObject<DomainObject1>();
            //    theObject.Name = name;
            //}
            if (ObjectSpace is DevExpress.ExpressApp.Xpo.XPObjectSpace)
            {
                PermissionPolicyUser sampleUser = ObjectSpace.FindObject <PermissionPolicyUser>(new BinaryOperator("UserName", "User"));
                if (sampleUser == null)
                {
                    sampleUser          = ObjectSpace.CreateObject <PermissionPolicyUser>();
                    sampleUser.UserName = "******";
                    sampleUser.SetPassword("");
                }
                PermissionPolicyRole defaultRole = CreateDefaultRole();
                sampleUser.Roles.Add(defaultRole);

                PermissionPolicyUser userAdmin = ObjectSpace.FindObject <PermissionPolicyUser>(new BinaryOperator("UserName", "Admin"));
                if (userAdmin == null)
                {
                    userAdmin          = ObjectSpace.CreateObject <PermissionPolicyUser>();
                    userAdmin.UserName = "******";
                    // 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);
                if (ObjectSpace.GetObjectsCount(typeof(AboutCompanySingleton), null) == 0)
                {
                    ObjectSpace.CreateObject <AboutCompanySingleton>();
                }
                ObjectSpace.CommitChanges(); //This line persists created object(s).
            }
        }
Ejemplo n.º 14
0
        public override void UpdateDatabaseAfterUpdateSchema()
        {
            base.UpdateDatabaseAfterUpdateSchema();

            ObjectSpace.EnsureSingletons();

            if (ObjectSpace.GetObjectsCount(typeof(TokenObjectsEditorDemoTokens), null) == 0)
            {
                var faker = new Faker <TokenObjectsEditorDemoTokens>()
                            .CustomInstantiator(f => ObjectSpace.CreateObject <TokenObjectsEditorDemoTokens>())
                            .RuleFor(r => r.Name, f => f.Name.FirstName());

                var tokens = faker.Generate(100);

                ObjectSpace.CommitChanges();
            }
        }
        private void RefreshAction_Executed(object sender, DevExpress.ExpressApp.Actions.ActionBaseEventArgs e)
        {
            Stopwatch.Stop();
            var cnt = ObjectSpace.GetObjectsCount(View.ObjectTypeInfo.Type, null);

            var member = View.ObjectTypeInfo.Type.GetProperties().FirstOrDefault(m => m.GetCustomAttribute <AssociationAttribute>() != null);

            var cnt2 = member == null
                ? 0
                : ObjectSpace.GetObjectsCount(member.PropertyType.GetGenericArguments()[0], null);

            var name = member == null
                ? string.Empty
                : member.PropertyType.GetGenericArguments()[0].Name;

            var mode = (View.Model as DevExpress.ExpressApp.Model.IModelListView).DataAccessMode;

            WinApplication.Messaging.Show("Elapsed", $"{View.Caption}{Environment.NewLine}DataAccessMode: {mode}{Environment.NewLine}{View.ObjectTypeInfo.Type.Name}: {cnt}{Environment.NewLine}{name}: {cnt2}{Environment.NewLine}{Stopwatch.Elapsed}");
        }
Ejemplo n.º 16
0
        public override void UpdateDatabaseAfterUpdateSchema()
        {
            base.UpdateDatabaseAfterUpdateSchema();

            if (ObjectSpace.GetObjectsCount(typeof(DomainObject1), null) == 0)
            {
                var userFaker = new Faker <DomainObject1>()
                                .CustomInstantiator(f => new DomainObject1(((XPObjectSpace)ObjectSpace).Session))
                                .RuleFor(o => o.Name, f => f.Name.FullName())
                                .RuleFor(o => o.Address, f => f.Address.FullAddress())
                                .RuleFor(o => o.Active, f => f.Random.Bool())
                                .RuleFor(o => o.Birthday, f => f.Date.Recent(100))
                                .RuleFor(o => o.Salary, f => f.Random.Decimal(50000, 100000));
                var users = userFaker.Generate(3000);



                ObjectSpace.CommitChanges();
            }
        }
 public override void UpdateDatabaseAfterUpdateSchema()
 {
     base.UpdateDatabaseAfterUpdateSchema();
     if (ObjectSpace.GetObjectsCount(typeof(Contact), null) == 0)
     {
         Contact mary = ObjectSpace.CreateObject <Contact>();
         mary.Name  = "Mary";
         mary.Email = "*****@*****.**";
         Contact john = ObjectSpace.CreateObject <Contact>();
         john.Name  = "John";
         john.Email = "*****@*****.**";
     }
     foreach (MyReportDataV2 reportData in ObjectSpace.GetObjects <MyReportDataV2>())
     {
         if ((reportData.IsPredefined) && string.IsNullOrEmpty(reportData.Category))
         {
             reportData.Category = "Predefined";
         }
     }
 }
Ejemplo n.º 18
0
        public override void UpdateDatabaseAfterUpdateSchema()
        {
            base.UpdateDatabaseAfterUpdateSchema();
            if (ObjectSpace.GetObjectsCount(typeof(About), null) == 0)
            {
                ObjectSpace.CreateObject <About>();
            }
            if (ObjectSpace.GetObjectsCount(typeof(Home), null) == 0)
            {
                ObjectSpace.CreateObject <Home>();
            }

            //var About = "About";
            //About theObject = ObjectSpace.FindObject<About>(CriteriaOperator.Parse("Code=?", About));
            //if (theObject == null)
            //{
            //    theObject = ObjectSpace.CreateObject<About>();
            //    theObject.Code = About;
            //}
            Contact Contact = ObjectSpace.FindObject <Contact>(CriteriaOperator.Parse("Code=?", "Contact"));

            if (Contact == null)
            {
                Contact      = ObjectSpace.CreateObject <Contact>();
                Contact.Code = "Contact";
            }
            ObjectSpace.CommitChanges();
            //string name = "MyName";
            //DomainObject1 theObject = ObjectSpace.FindObject<DomainObject1>(CriteriaOperator.Parse("Name=?", name));
            //if(theObject == null) {
            //    theObject = ObjectSpace.CreateObject<DomainObject1>();
            //    theObject.Name = name;
            //}

            //ObjectSpace.CommitChanges(); //Uncomment this line to persist created object(s).
        }
Ejemplo n.º 19
0
        //public 员工 CreateDefaultEmployee(系统用户 user)
        //{
        //    var emp = ObjectSpace.CreateObject<员工>();

        //    var company = ObjectSpace.CreateObject<往来单位>();
        //    emp.名称 = "管理员";
        //    emp.手机 = "13660088006";

        //    company.客户 = true;

        //    company.供应商 = true;

        //    company.名称 = "京东";

        //    company.联系人.Add(emp);
        //    user.员工 = emp;
        //    emp.系统用户 = user;

        //    var add = ObjectSpace.CreateObject<地址>();
        //    add.详细地址 = "上海市黄浦区";

        //    company.地址.Add(add);
        //    var tdch = new TestDataGeneratorHelper();
        //    var employees = tdch.GetRandomNames(30);
        //    foreach (var em in employees)
        //    {
        //        var e = ObjectSpace.CreateObject<员工>();
        //        e.名称 = em;
        //        e.手机 = "13866559988";
        //        company.联系人.Add(e);
        //    }
        //    return emp;
        //}

        public override void UpdateDatabaseAfterUpdateSchema()
        {
            base.UpdateDatabaseAfterUpdateSchema();

            //string name = "MyName";
            //DomainObject1 theObject = ObjectSpace.FindObject<DomainObject1>(CriteriaOperator.Parse("Name=?", name));
            //if(theObject == null) {
            //    theObject = ObjectSpace.CreateObject<DomainObject1>();
            //    theObject.Name = name;
            //}
            var sampleUser = ObjectSpace.FindObject <系统用户>(new BinaryOperator("UserName", "User"));

            if (sampleUser == null)
            {
                sampleUser          = ObjectSpace.CreateObject <系统用户>();
                sampleUser.UserName = "******";
                sampleUser.SetPassword("");
            }

            var defaultRole = CreateDefaultRole();

            sampleUser.Roles.Add(defaultRole);

            var userAdmin = ObjectSpace.FindObject <系统用户>(new BinaryOperator("UserName", "Admin"));

            if (userAdmin == null)
            {
                userAdmin          = ObjectSpace.CreateObject <系统用户>();
                userAdmin.UserName = "******";
                // Set a password if the standard authentication type is used
                userAdmin.SetPassword("");
                //CreateDefaultEmployee(userAdmin);
            }

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

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


            adminRole.IsAdministrative = true;
            userAdmin.Roles.Add(adminRole);



            //var inited = ObjectSpace.GetObjectsCount(typeof (产品), null) > 0;
            //var tdch = new TestDataGeneratorHelper();
            //if (!inited)
            //{
            //    var t = CreateUnit("台");

            //    var g = CreateUnit("个");

            //    CreateProduct("Surface 3 64G 2G", t, 2000, 2999);

            //    CreateProduct("Surface 3 128G 4G", t, 2000, 4888);

            //    CreateProduct("Surface Pro 3 I3 64G 4G", t, 3000, 4499);

            //    CreateProduct("Surface Pro 3 I5 128G 4G", t, 4500, 5699);

            //    CreateProduct("Surface Pro 3 I5 256G 8G", t, 6388, 6999);

            //    CreateProduct("Surface Pro 3 I7 256G 8G", t, 7000, 8888);

            //    CreateProduct("Surface Pro 3 I7 512G 8G", t, 8000, 9999);

            //    CreateProduct("Surface Pro 4 CoreM 128G 8G", t, 5688, 6688);

            //    CreateProduct("Surface Pro 4 I5 128G 8G", t, 6388, 7388);

            //    CreateProduct("Surface Pro 4 I5 256G 8G", t, 6388, 9688);

            //    CreateProduct("Surface Pro 4 I7 256G 16G", t, 6388, 13388);

            //    CreateProduct("Surface Notebook I5 128G 8G", t, 10000, 11088);

            //    CreateProduct("Surface Notebook I5 256G 16G", t, 10000, 14088);

            //    CreateProduct("Surface Notebook I7 256G 16G", t, 13000, 15588);

            //    CreateProduct("Surface Notebook I7 512G 16G", t, 15000, 20088);

            //    var microsoft = CreateCompany("Microsoft", "比尔.盖茨", "13800001111", "徐家汇", true, true);

            //    var google = CreateCompany("Google", "拉里·佩奇", "13988881111", "徐家汇", true, true);

            //    var baidu = CreateCompany("Baidu", "李彦宏", "13900001111", "陆家嘴", true, true);

            //    var tencent = CreateCompany("Tencent", "15912111211", "马化腾", "陆家嘴", true, true);

            //    var ali = CreateCompany("Alibaba", "15612121212", "马云", "陆家嘴", true, true);

            //    //500个客户


            //}

            //var area = ObjectSpace.FindObject<省份>(null);
            //if (area == null)
            //{
            //    var js = CreateSF("江苏");
            //    CreateCity(js, "苏州", "姑苏区,相城区,吴中区,虎丘区,工业园区,吴江区,张家港市,常熟市,太仓巿,昆山市");
            //    CreateCity(js, "南京", "鼓楼区,白下区,玄武区,秦淮区,建邺区,下关区,雨花台区,栖霞区,高淳县,溧水县,六合区,浦口区,江宁区");

            //    var tjs = CreateSF("天津");
            //    CreateCity(tjs, "天津", "和平区,河东区,河西区,南开区,河北区,红桥区,滨海新区,东丽区,西青区,津南区,北辰区,武清区,宝坻区,宁河区,静海区,蓟县");


            //    var cqs = CreateSF("重庆");
            //    CreateCity(cqs, "重庆",
            //        "渝中区,大渡口区,江北区,沙坪坝区,九龙坡区,南岸区,北碚区,渝北区,巴南区,涪陵区,綦江区,大足区,长寿区,江津区,合川区,永川区,南川区,璧山区,铜梁区,潼南区,荣昌区,万州区,梁平县,城口县,丰都县,垫江县,忠县,开县,云阳县,奉节县,巫山县,巫溪县,黔江区,武隆县,石柱土家族自治县,秀山土家族苗族自治县,酉阳土家族苗族自治县,彭水苗族土家族自治县");

            //    var zjs = CreateSF("浙江");
            //    CreateCity(zjs, "杭州", "市区,上城区,下城区,江干区,拱墅区,西湖区,滨江区,萧山区,余杭区,富阳区,桐庐县,淳安县,建德市,临安市");

            //    var scs = CreateSF("四川");
            //    CreateCity(scs, "成都", "武侯区,锦江区,青羊区,金牛区,成华区,龙泉驿区,温江区,新都区,青白江区,双流区,郫县,蒲江县,大邑县,金堂县,新津县,都江堰市,彭州市,邛崃市,崇州市");

            //    var gds = CreateSF("广东");
            //    CreateCity(gds, "广州", "越秀区,荔湾区,海珠区,天河区,白云区,黄埔区,番禺区,花都区,南沙区,增城区,从化区");

            //    var szs = CreateSF("深圳");
            //    CreateCity(szs, "深圳", "福田区,罗湖区,南山区,盐田区,宝安区,龙岗区");

            //    var shs = CreateSF("上海");
            //    CreateCity(shs, "上海", "黄浦区,浦东新区,徐汇区,长宁区,静安区,普陀区,虹口区,杨浦区,闵行区,宝山区,嘉定区,金山区,松江区,青浦区,奉贤区,崇明县");

            //    var bjs = CreateSF("北京");
            //    CreateCity(bjs, "北京", "东城区,西城区,海淀区,朝阳区,丰台区,石景山区,门头沟区,通州区,顺义区,房山区,大兴区,昌平区,怀柔区,平谷区,密云区,延庆区");
            //    ObjectSpace.CommitChanges();
            //    var s = ObjectSpace.GetObjects<销售区域>();

            //    var customers = tdch.GetRandomNames(500);
            //    var rnd = new Random();
            //    foreach (var customer in customers)
            //    {
            //        CreateCompany(customer, customer, "13900005555", "中国", false, true, s[rnd.Next(s.Count - 1)]);
            //    }
            //}


            //var dd = ObjectSpace.FindObject<日期维度>(null);
            //if (dd == null)
            //{
            //    for (var x = DateTime.Parse("2013-1-1"); x <= DateTime.Parse("2017-12-31"); x = x.AddDays(1))
            //    {
            //        var t = ObjectSpace.CreateObject<日期维度>();
            //        t.TheDate = x;
            //    }
            //}
            //var solutions = ObjectSpace.GetObjects<单据编号方案>();

            //var froms = XafTypesInfo.Instance.FindTypeInfo(typeof(单据)).Descendants.Where(x => x.IsPersistent);
            //foreach (var item in froms)
            //{
            //    //需要看看为啥为空
            //    var solution = solutions.FirstOrDefault(x => x.应用单据!=null && x.应用单据.FullName == item.FullName);
            //    if (solution == null)
            //    {
            //        solution = ObjectSpace.CreateObject<单据编号方案>();
            //        solution.应用单据 = item.Type;
            //        solution.名称 = item.Name + "编号方案";
            //        var item1 = ObjectSpace.CreateObject<单据编号当前日期规则>();
            //        item1.格式化字符串 = "yyyyMMddHHmmssfff";
            //        solution.编号规则.Add(item1);
            //    }

            //}

            var nameSpace = ObjectSpace.FindObject <NameSpace>(new BinaryOperator("FullName", "系统类型"));

            if (nameSpace == null)
            {
                nameSpace   = ObjectSpace.CreateObject <NameSpace>();
                nameSpace.称 = "系统类型";
                var createIndex = ObjectSpace.GetObjectsCount(typeof(BusinessObject), null);

                var strType = AddSimpleObject(typeof(string), "字符串", nameSpace, "一串文本内容");

                var dec          = AddSimpleObject(typeof(decimal), "数字(decimal)", nameSpace, "通常用于记录带小数点的数字,比如表示货币金额时");
                var intt         = AddSimpleObject(typeof(int), "整数(int)", nameSpace, "没有小数的数字");
                var datetimeType = AddSimpleObject(typeof(DateTime), "日期时间", nameSpace, "用于表示日期时间");
                var boolType     = AddSimpleObject(typeof(bool), "布尔", nameSpace, "用于表示是/否,真/假,等2种可选值的情况");
                var imageType    = AddSimpleObject(typeof(Image), "图片", nameSpace, "用于表示图像信息");
                var colorType    = AddSimpleObject(typeof(Color), "颜色", nameSpace, "用于表示颜色信息");
                AddSimpleObject(typeof(sbyte), "整数(sbyte 8位有符号)", nameSpace, "8位有符号整数");
                AddSimpleObject(typeof(long), "整数(long 64位有符号)", nameSpace, "");
                AddSimpleObject(typeof(byte), "整数(byte 8位无符号)", nameSpace, "");
                AddSimpleObject(typeof(ushort), "整数(ushort 16位无符号)", nameSpace, "");
                AddSimpleObject(typeof(uint), "整数(uint 32位无符号)", nameSpace, "");
                AddSimpleObject(typeof(ulong), "整数(ulong 64位无符号)", nameSpace, "");
                AddSimpleObject(typeof(float), "数字(float 单精度浮点)", nameSpace, "");
                AddSimpleObject(typeof(double), "数字(double 双精度浮点)", nameSpace, "");
                AddSimpleObject(typeof(TimeSpan), "时间段(TimeSpan)", nameSpace, "");
                AddSimpleObject(typeof(Guid), "Guid", nameSpace, "全球唯一标识");
            }

            ObjectSpace.CommitChanges(); //This line persists created object(s).
            ERPModule.IsNewVersion = true;
        }
Ejemplo n.º 20
0
        public override void UpdateDatabaseAfterUpdateSchema()
        {
            base.UpdateDatabaseAfterUpdateSchema();
            CreateUserAndRoles();
            CreateEditors();
            CreateRuleSources();

            #region user roles

            var icode = AddPreDefinedBusinessObject(typeof(ICode), "单据编号");

            if (icode.Properties.Count == 0)
            {
                icode.IsAbstract   = true;
                icode.IsPersistent = false;
                var code = ObjectSpace.CreateObject <IProperty>();
                code.Name         = "Code";
                code.Caption      = "编号";
                code.TypeCategory = PropertyTypeCategory.简单类型;
                code.PropertyType = code.PropertyTypes.FirstOrDefault(x => x.FullName == typeof(string).FullName);
                icode.Properties.Add(code);
            }

            #endregion

            #region 编辑器


            #endregion

            #region 菜单

            var pmsModule = CreateModule("采购管理");
            var smsModule = CreateModule("销售管理");
            var scmModule = CreateModule("库存管理");

            var pdsModule = CreateModule("生产管理");
            var fmsModule = CreateModule("财务管理");
            var qmsModule = CreateModule("质检管理");


            var baseForm = CreateModule("基础单据");
            var baseInfo = CreateModule("基础数据");

            var demoNav = CreateNaviationGroup("功能演示");
            #endregion

            #region 系统类型

            createIndex = ObjectSpace.GetObjectsCount(typeof(IBusinessObject), null);

            var strType = AddSimpleObject(typeof(string), typeof(IStringProperty), "字符串");

            var dec          = AddSimpleObject(typeof(decimal), typeof(INumberProperty), "数字(decimal)");
            var intt         = AddSimpleObject(typeof(int), typeof(INumberProperty), "整数(int)");
            var datetimeType = AddSimpleObject(typeof(DateTime), typeof(IDateTimeProperty), "日期时间");
            var boolType     = AddSimpleObject(typeof(bool), typeof(IBooleanProperty), "布尔");
            var imageType    = AddSimpleObject(typeof(Image), typeof(IImageProperty), "图片");
            var colorType    = AddSimpleObject(typeof(Color), typeof(IColorProperty), "颜色");

            AddSimpleObject(typeof(sbyte), typeof(INumberProperty), "整数(sbyte 8位有符号)");

            AddSimpleObject(typeof(long), typeof(INumberProperty), "整数(long 64位有符号)");
            AddSimpleObject(typeof(byte), typeof(INumberProperty), "整数(byte 8位无符号)");

            AddSimpleObject(typeof(ushort), typeof(INumberProperty), "整数(ushort 16位无符号)");
            AddSimpleObject(typeof(uint), typeof(INumberProperty), "整数(uint 32位无符号)");
            AddSimpleObject(typeof(ulong), typeof(INumberProperty), "整数(ulong 64位无符号)");
            AddSimpleObject(typeof(float), typeof(INumberProperty), "数字(float 单精度浮点)");
            AddSimpleObject(typeof(double), typeof(INumberProperty), "数字(double 双精度浮点)");
            AddSimpleObject(typeof(TimeSpan), typeof(IDateTimeProperty), "时间段(TimeSpan)");
            AddSimpleObject(typeof(Guid), null, "Guid");
            #endregion

            #region formatSolution

            CreateFormat("yyyy-MM-dd", "年月日", "2016-1-1 15:30", "2016-01-01", datetimeType, "");
            CreateFormat("yyyy-MMMM-dd", "年月(英文月)日", "2016-1-1 15:30", "2016-01-01", datetimeType, "");
            CreateFormat("yyyy年MM月dd日", "中文日期", "2016-12-31 15:30", "2016年12月31日", datetimeType, "");
            CreateFormat("yyyy年MM月", "短中文日期", "2016-12-31 15:30", "2016年12月", datetimeType, "");
            CreateFormat("MM月dd日", "月日", "2016-1-1 15:30", "16-01-01", datetimeType, "");
            CreateFormat("dddd", "星期", "2016-1-1 15:30", "星期三", datetimeType, "");
            CreateFormat("yyyy-MM-dd HH:mm:ss", "时间日期", "2016-1-1 15:30:21", "2016-01-01 15:30:21", datetimeType, "");
            CreateFormat("yyyy-MM-dd HH:mm:ss.fff", "时间日期", "2016-1-1 15:30:21.776", "2016-01-01 15:30:21.776", datetimeType, "");
            CreateFormat("yyyy-MM-dd hh:mm:ss", "时间(AM/PM)日期", "2016-1-1 15:30:21", "2016-01-01 03:30:21 PM", datetimeType, "");
            CreateFormat("HH:mm:ss", "时分秒", "2016-12-31 15:30:21", "15:30:21", datetimeType, "");
            CreateFormat("HH:mm", "时分", "2016-12-31 15:30:21", "15:30", datetimeType, "");
            CreateFormat("hh:mm", "时(AM/PM)分", "2016-12-31 15:30:21", "15:30 AM", datetimeType, "");
            CreateFormat("HH时mm分ss秒", "中文时分秒", "2016-12-31 15:30:21", "15时30分21秒", datetimeType, "");

            CreateFormat("C", "货币", "2.5", "¥2.50", dec, "");
            CreateFormat("D5", "十进制数", "25", "00025", dec, "");
            CreateFormat("E", "科学型", "25000", "2.500000E+005", dec, "");
            CreateFormat("F2", "固定点", "25", "25.00", dec, "");
            CreateFormat("G", "常规", "2.5", "2.5", dec, "");
            CreateFormat("N", "数字", "2500000", "2,500,000.00", dec, "");
            CreateFormat("X", "十六进制", "255", "FF", dec, "");


            ObjectSpace.CommitChanges();

            #endregion

            #region 验证规则


            #endregion

            #region TestObject

            var testObject = BusinessObjectBuilder.Exist(ObjectSpace, "TestObject");
            if (testObject == null)
            {
                var tb = new BusinessObjectBuilder(ObjectSpace, "TestObject", "测试对象", typeof(IReferenceProperty));
                tb.BusinessObject.NavigationGroup = demoNav;
                tb.CreateProperty <IStringProperty>("StringProperty", "字符串", strType);
                tb.CreateProperty <INumberProperty>("DecimalProperty", "数字小数", dec);
                tb.CreateProperty <INumberProperty>("IntProperty", "整数", intt);

                tb.CreateProperty <IDateTimeProperty>("DateTimeProperty", "日期时间", datetimeType);
                tb.CreateProperty <IBooleanProperty>("BoolProperty", "布尔型", boolType);
                tb.CreateProperty <IImageProperty>("ImageProperty", "图片", imageType);
                tb.CreateProperty <IColorProperty>("ColorProperty", "颜色", colorType);
                tb.CreateProperty <IReferenceProperty>("ReferenceProperty", "引用字段", tb.BusinessObject, PropertyTypeCategory.引用类型);
                //tb.CreateProperty<IListProperty>("ListProperty", "集合", tb.BusinessObject, PropertyTypeCategory.集合类型);
            }

            #endregion

            //var formbase = AddSystemBusinessObject(typeof (IFormBase), "表单");
            //var formItembase = AddSystemBusinessObject(typeof (IFormItemBase), "明细");
            //var form = new Tuple<IBusinessObject, IBusinessObject>(formbase, formItembase);

            //var productItemBase = AddBaseInfo("ProductItem", "产品");
            //if(!productItemBase.Properties.Any(x=>x.Name == "Product"))
            //{
            //    var pproduct = ObjectSpace.CreateObject<IReferenceProperty>();
            //    pproduct.PropertyType = product;
            //    pproduct.Name = "Product";
            //    pproduct.Caption = "产品";
            //    productItemBase.Properties.Add(pproduct);
            //}

            //var order = AddFormBase(baseForm,"Order", "订单", true, DomainComponetReisterType.SharePart, null, form);
            //var plan = AddFormBase(baseForm, "Plan", "计划单", true, DomainComponetReisterType.SharePart, null, form);
            //var request = AddFormBase(baseForm, "Request", "申请单", true, DomainComponetReisterType.SharePart, null, form);
            //var notice = AddFormBase(baseForm, "Notice", "通知单", true, DomainComponetReisterType.SharePart, null, form);
            //var quote = AddFormBase(baseForm, "Quote", "报价单", true, DomainComponetReisterType.SharePart, null, form);
            //var query = AddFormBase(baseForm, "Query", "询价单", true, DomainComponetReisterType.SharePart, null, form);
            //var contract = AddFormBase(baseForm, "Contract", "合同", true, DomainComponetReisterType.SharePart, null, form);
            //var stockIn = AddFormBase(baseForm, "StockIn", "入库单", true, DomainComponetReisterType.SharePart, null, form);
            //var stockOut = AddFormBase(baseForm, "StockOut", "出库单", true, DomainComponetReisterType.SharePart, null, form);

            //var returnx = AddFormBase(baseForm, "Return", "退货单", true, DomainComponetReisterType.SharePart, null, form, stockOut);

            //var stocktaking = AddFormBase(baseForm, "Stocktaking", "盘点单", true, DomainComponetReisterType.SharePart, null, form);

            //var pms = AddFormBase(pmsModule,"Pms", "采购", true, DomainComponetReisterType.SharePart);
            //var sms = AddFormBase(smsModule,"Sms", "销售", true, DomainComponetReisterType.SharePart);
            //var scm = AddFormBase(scmModule,"Scm", "库存", true, DomainComponetReisterType.SharePart);
            //var pds = AddFormBase(pdsModule,"Pds", "生产", true, DomainComponetReisterType.SharePart);
            //var fms = AddFormBase(fmsModule,"Fms", "财务", true, DomainComponetReisterType.SharePart);
            //var qms = AddFormBase(qmsModule,"Qms", "质检", true, DomainComponetReisterType.SharePart);

            //AddFormBase(pmsModule,"PmsPlan", "采购计划", false, DomainComponetReisterType.AutoRegisterDomainComponent, pmsNav, pms, plan);


            //AddFormBase(pmsModule,"PmsQuery", "采购询价", false, DomainComponetReisterType.AutoRegisterDomainComponent, pmsNav, pms, query);
            //AddFormBase(pmsModule, "PmsQuote", "采购报价", false, DomainComponetReisterType.AutoRegisterDomainComponent, pmsNav, pms, quote);
            //var pmsContract = AddFormBase(pmsModule,"PmsContract", "采购合同", false, DomainComponetReisterType.AutoRegisterDomainComponent, pmsNav, pms, contract);
            //pmsContract.Item2.Bases.Add(productItemBase);

            //AddFormBase(pmsModule, "PmsRequest", "采购申请", false, DomainComponetReisterType.AutoRegisterDomainComponent, pmsNav, pms, request);

            //AddFormBase(pmsModule, "PmsNotice", "采购通知", false, DomainComponetReisterType.AutoRegisterDomainComponent, pmsNav, pms, notice);

            //var pmsOrder = AddFormBase(pmsModule, "PmsOrder", "采购订单", false, DomainComponetReisterType.AutoRegisterDomainComponent, pmsNav, pms, order);
            //pmsOrder.Item2.Bases.Add(productItemBase);

            //AddFormBase(pmsModule, "PmsArriveNotice", "采购到货通知", false, DomainComponetReisterType.AutoRegisterDomainComponent, pmsNav, pms, notice);

            //AddFormBase(pmsModule, "PmsArriveQCRequest", "到货检质申请", false, DomainComponetReisterType.AutoRegisterDomainComponent, pmsNav, pms, notice);
            //AddFormBase(pmsModule, "PmsArriveQCReport", "到货检质报告", false, DomainComponetReisterType.AutoRegisterDomainComponent, pmsNav, pms, notice);
            //AddFormBase(pmsModule, "PmsStockIn", "采购入库", false, DomainComponetReisterType.AutoRegisterDomainComponent, pmsNav, pms, stockIn);
            //AddFormBase(pmsModule, "PmsReturnNotice", "采购退货通知", false, DomainComponetReisterType.AutoRegisterDomainComponent, pmsNav, pms, returnx, notice);
            //AddFormBase(pmsModule, "PmsReturn", "采购退货", false, DomainComponetReisterType.AutoRegisterDomainComponent, pmsNav, pms, returnx);

            ////打算怎么卖
            //AddFormBase(smsModule, "SmsPlan", "销售计划", false, DomainComponetReisterType.AutoRegisterDomainComponent, smsNav, sms, plan);

            //AddFormBase(smsModule, "SmsQuery", "销售询价", false, DomainComponetReisterType.AutoRegisterDomainComponent, smsNav, sms, query);
            //AddFormBase(smsModule, "SmsQuote", "销售报价", false, DomainComponetReisterType.AutoRegisterDomainComponent, smsNav, sms, quote);
            //AddFormBase(smsModule, "SmsContract", "销售合同", false, DomainComponetReisterType.AutoRegisterDomainComponent, smsNav, sms, contract);
            //AddFormBase(smsModule, "SmsOrder", "销售订单", false, DomainComponetReisterType.AutoRegisterDomainComponent, smsNav, sms, order);

            ////价格有超常规时,则需要申请,申请审批后可以转订单
            //AddFormBase(smsModule, "SmsRequest", "销售申请", false, DomainComponetReisterType.AutoRegisterDomainComponent, smsNav, sms, request);

            //AddFormBase(smsModule, "SmsNotice", "销售发货通知", false, DomainComponetReisterType.AutoRegisterDomainComponent, smsNav, sms, notice);

            //AddFormBase(smsModule, "SmsStockOutQCRequest", "销出质检申请", false, DomainComponetReisterType.AutoRegisterDomainComponent, smsNav, sms, stockOut);

            //AddFormBase(smsModule, "SmsStockOutQCReport", "销出质检报告", false, DomainComponetReisterType.AutoRegisterDomainComponent, smsNav, sms, stockOut);

            //AddFormBase(smsModule, "SmsStockOutQCNGProcess", "销出不良处理", false, DomainComponetReisterType.AutoRegisterDomainComponent, smsNav, sms, stockOut);

            //AddFormBase(smsModule, "SmsStockOut", "销售出库", false, DomainComponetReisterType.AutoRegisterDomainComponent, smsNav, sms, stockOut);


            //AddFormBase(smsModule, "SmsReturnNotice", "销售退货通知", false, DomainComponetReisterType.AutoRegisterDomainComponent, smsNav, sms, returnx, notice);
            //AddFormBase(smsModule, "SmsReturn", "销售退货", false, DomainComponetReisterType.AutoRegisterDomainComponent, smsNav, sms, returnx);

            //AddFormBase(smsModule, "SmsReturnQCRequest", "退货质检申请", false, DomainComponetReisterType.AutoRegisterDomainComponent, smsNav, sms, qms);
            //AddFormBase(smsModule, "SmsReturnQCReport", "退货质检报告", false, DomainComponetReisterType.AutoRegisterDomainComponent, smsNav, sms, qms);

            //AddFormBase(smsModule, "SmsReturnStockIn", "销售退货入库", false, DomainComponetReisterType.AutoRegisterDomainComponent, smsNav, sms, returnx, stockIn);
            ////销售退货不合格品处理
            //AddFormBase(smsModule, "SmsReturnProcess", "销退处理", false, DomainComponetReisterType.AutoRegisterDomainComponent, smsNav, sms, returnx);

            //AddFormBase(scmModule, "ScmStocktakingNotice", "盘点通知", false, DomainComponetReisterType.AutoRegisterDomainComponent, scmNav, scm, stocktaking, notice);
            //AddFormBase(scmModule, "ScmStocktaking", "库存盘点", false, DomainComponetReisterType.AutoRegisterDomainComponent, scmNav, scm, stocktaking);
            //AddFormBase(scmModule, "ScmStocktakingOut", "报损单", false, DomainComponetReisterType.AutoRegisterDomainComponent, scmNav, scm, stocktaking, stockOut);
            //AddFormBase(scmModule, "ScmStocktakingIn", "报溢单", false, DomainComponetReisterType.AutoRegisterDomainComponent, scmNav, scm, stocktaking, stockIn);
            //AddFormBase(scmModule, "ScmTransfer", "调拨单", false, DomainComponetReisterType.AutoRegisterDomainComponent, scmNav, scm);
            //AddFormBase(scmModule, "ScmTransferOut", "调拨出库", false, DomainComponetReisterType.AutoRegisterDomainComponent, scmNav, scm, stockOut);
            //AddFormBase(scmModule, "ScmTransferIn", "调拨入库", false, DomainComponetReisterType.AutoRegisterDomainComponent, scmNav, scm, stockIn);
            //ObjectSpace.CommitChanges();
        }
Ejemplo n.º 21
0
        public override void UpdateDatabaseAfterUpdateSchema()
        {
            base.UpdateDatabaseAfterUpdateSchema();
            //string name = "MyName";
            //DomainObject1 theObject = ObjectSpace.FindObject<DomainObject1>(CriteriaOperator.Parse("Name=?", name));
            //if(theObject == null) {
            //    theObject = ObjectSpace.CreateObject<DomainObject1>();
            //    theObject.Name = name;
            //}
            Employee sampleUser = ObjectSpace.FindObject <Employee>(new BinaryOperator("UserName", "Norman"));

            if (sampleUser == null)
            {
                sampleUser          = ObjectSpace.CreateObject <Employee>();
                sampleUser.UserName = "******";
                sampleUser.SetPassword("");
            }
            MarbidRole defaultRole = CreateDefaultRole();

            sampleUser.MarbidRoles.Add(defaultRole);

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

            if (userAdmin == null)
            {
                userAdmin          = ObjectSpace.CreateObject <Employee>();
                userAdmin.UserName = "******";
                // 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
            MarbidRole adminRole = ObjectSpace.FindObject <MarbidRole>(new BinaryOperator("Name", "Administrators"));

            if (adminRole == null)
            {
                adminRole      = ObjectSpace.CreateObject <MarbidRole>();
                adminRole.Name = "Administrators";
            }
            adminRole.IsAdministrative = true;
            userAdmin.MarbidRoles.Add(adminRole);

            MarbidRole carManagerRole = ObjectSpace.FindObject <MarbidRole>(new BinaryOperator("Name", "Car Manager"));

            if (carManagerRole == null)
            {
                carManagerRole                  = ObjectSpace.CreateObject <MarbidRole>();
                carManagerRole.Name             = "Car Manager";
                carManagerRole.IsAdministrative = false;
            }

            if (ObjectSpace.GetObjectsCount(typeof(SystemSetting), null) == 0)
            {
                SystemSetting ss = ObjectSpace.CreateObject <SystemSetting>();
                ss.MaximumOfficeLeaveDays = 3;
                ss.YearlyOfficeLeaveDays  = 14;
                ss.DriverManagerRole      = adminRole;
                ss.HRRole = adminRole;
            }

            ObjectSpace.CommitChanges(); //This line persists created object(s).
        }
Ejemplo n.º 22
0
        public override void UpdateDatabaseAfterUpdateSchema()
        {
            base.UpdateDatabaseAfterUpdateSchema();
            //string name = "MyName";
            //DomainObject1 theObject = ObjectSpace.FindObject<DomainObject1>(CriteriaOperator.Parse("Name=?", name));
            //if(theObject == null) {
            //    theObject = ObjectSpace.CreateObject<DomainObject1>();
            //    theObject.Name = name;
            //}
            Employee sampleUser = ObjectSpace.FindObject <Employee>(new BinaryOperator("UserName", "User"));

            if (sampleUser == null)
            {
                sampleUser           = ObjectSpace.CreateObject <Employee>();
                sampleUser.UserName  = "******";
                sampleUser.FirstName = "Sample";
                sampleUser.LastName  = "User";
                sampleUser.SetPassword("");
            }
            EmployeeRole defaultRole = CreateDefaultRole();

            sampleUser.EmployeeRoles.Add(defaultRole);

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

            if (userAdmin == null)
            {
                userAdmin           = ObjectSpace.CreateObject <Employee>();
                userAdmin.UserName  = "******";
                userAdmin.FirstName = "Super";
                userAdmin.LastName  = "Admin";
                // 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
            EmployeeRole adminRole = ObjectSpace.FindObject <EmployeeRole>(new BinaryOperator("Name", "Administrators"));

            if (adminRole == null)
            {
                adminRole      = ObjectSpace.CreateObject <EmployeeRole>();
                adminRole.Name = "Administrators";
            }
            adminRole.IsAdministrative = true;
            userAdmin.EmployeeRoles.Add(adminRole);
            ObjectSpace.CommitChanges(); //This line persists created object(s).


            XmlDocument glDocument = new XmlDocument();

            glDocument.LoadXml(GetInitialData("GLAccount.xml"));
            XmlElement  xelRoot  = glDocument.DocumentElement;
            XmlNodeList xnlNodes = xelRoot.SelectNodes("/data-set/record");

            foreach (XmlNode xndNode in xnlNodes)
            {
                GLAccount glAccount = ObjectSpace.FindObject <GLAccount>(new BinaryOperator("AccountNumber", xndNode["Account"].InnerText));
                if (glAccount == null)
                {
                    glAccount = ObjectSpace.CreateObject <GLAccount>();
                    glAccount.AccountNumber    = xndNode["Account"].InnerText;
                    glAccount.AccountName      = xndNode["Name"].InnerText;
                    glAccount.AccountType      = (GLACcountType)Convert.ToInt16(xndNode["Type"].InnerText);
                    glAccount.RetainedEarnings = Convert.ToBoolean(xndNode["RetainedEarnings"].InnerText);

                    glAccount.Save();
                }
            }

            glDocument.LoadXml(GetInitialData("Currency.xml"));
            xelRoot  = glDocument.DocumentElement;
            xnlNodes = xelRoot.SelectNodes("/data-set/record");
            foreach (XmlNode xndNode in xnlNodes)
            {
                Currency currency = ObjectSpace.FindObject <Currency>(new BinaryOperator("CurrencyCode", xndNode["CurrencyCode"].InnerText));
                if (currency == null)
                {
                    currency = ObjectSpace.CreateObject <Currency>();
                    currency.CurrencyCode       = xndNode["CurrencyCode"].InnerText;
                    currency.Name               = xndNode["Name"].InnerText;
                    currency.ExchangeRate       = Convert.ToDecimal(xndNode["ExchangeRate"].InnerText);
                    currency.AccountsPayable    = ObjectSpace.FindObject <GLAccount>(new BinaryOperator("AccountNumber", xndNode["AccountsPayable"].InnerText));
                    currency.APDiscounts        = ObjectSpace.FindObject <GLAccount>(new BinaryOperator("AccountNumber", xndNode["APDiscounts"].InnerText));
                    currency.AccountsReceivable = ObjectSpace.FindObject <GLAccount>(new BinaryOperator("AccountNumber", xndNode["AccountsReceivable"].InnerText));
                    currency.ARDiscounts        = ObjectSpace.FindObject <GLAccount>(new BinaryOperator("AccountNumber", xndNode["ARDiscounts"].InnerText));
                    currency.DefaultARWriteOffs = ObjectSpace.FindObject <GLAccount>(new BinaryOperator("AccountNumber", xndNode["DefaultARWriteOffs"].InnerText));
                    currency.GainLossOnExchange = ObjectSpace.FindObject <GLAccount>(new BinaryOperator("AccountNumber", xndNode["GainLossOnExchange"].InnerText));

                    currency.Save();
                }
            }

            glDocument.LoadXml(GetInitialData("Bank.xml"));
            xelRoot  = glDocument.DocumentElement;
            xnlNodes = xelRoot.SelectNodes("/data-set/record");
            foreach (XmlNode xndNode in xnlNodes)
            {
                Bank bank = ObjectSpace.FindObject <Bank>(new BinaryOperator("Name", xndNode["Name"].InnerText));
                if (bank == null)
                {
                    bank           = ObjectSpace.CreateObject <Bank>();
                    bank.Name      = xndNode["Name"].InnerText;
                    bank.GLAccount = ObjectSpace.FindObject <GLAccount>(new BinaryOperator("AccountNumber", xndNode["GLAccount"].InnerText));
                    bank.Currency  = ObjectSpace.FindObject <Currency>(new BinaryOperator("CurrencyCode", xndNode["CurrencyCode"].InnerText));

                    bank.Save();
                }
            }

            glDocument.LoadXml(GetInitialData("Warehouse.xml"));
            xelRoot  = glDocument.DocumentElement;
            xnlNodes = xelRoot.SelectNodes("/data-set/record");
            foreach (XmlNode xndNode in xnlNodes)
            {
                Warehouse warehouse = ObjectSpace.FindObject <Warehouse>(new BinaryOperator("Name", xndNode["Name"].InnerText));
                if (warehouse == null)
                {
                    warehouse      = ObjectSpace.CreateObject <Warehouse>();
                    warehouse.Name = xndNode["Name"].InnerText;

                    warehouse.Save();
                }
            }

            glDocument.LoadXml(GetInitialData("ItemType.xml"));
            xelRoot  = glDocument.DocumentElement;
            xnlNodes = xelRoot.SelectNodes("/data-set/record");
            foreach (XmlNode xndNode in xnlNodes)
            {
                ItemType itemType = ObjectSpace.FindObject <ItemType>(new BinaryOperator("Name", xndNode["Name"].InnerText));
                if (itemType == null)
                {
                    itemType               = ObjectSpace.CreateObject <ItemType>();
                    itemType.Name          = xndNode["Name"].InnerText;
                    itemType.Inventory     = Convert.ToBoolean(xndNode["Inventory"].InnerText);
                    itemType.CostingMethod = (CostingMethod)Convert.ToInt16(xndNode["CostingMethod"].InnerText);

                    itemType.Save();
                }
            }

            if (ObjectSpace.GetObjectsCount(typeof(SystemSetting), null) == 0)
            {
                SystemSetting systemSetting = ObjectSpace.CreateObject <SystemSetting>();
                systemSetting.CompanyName            = "Aturable Solution";
                systemSetting.SalesNumber            = 1001;
                systemSetting.PurchaseOrderNumber    = 1001;
                systemSetting.InvoiceNumber          = 1001;
                systemSetting.InventoryReceiptNumber = 1001;
                systemSetting.Sales           = ObjectSpace.FindObject <GLAccount>(new BinaryOperator("AccountNumber", "4000"));
                systemSetting.CostofGoodsSold = ObjectSpace.FindObject <GLAccount>(new BinaryOperator("AccountNumber", "5000"));
                systemSetting.Inventory       = ObjectSpace.FindObject <GLAccount>(new BinaryOperator("AccountNumber", "1200"));
                systemSetting.DefaultCurrency = ObjectSpace.FindObject <Currency>(new BinaryOperator("CurrencyCode", "IDR"));

                systemSetting.Save();
                ObjectSpace.CommitChanges();
            }

            glDocument.LoadXml(GetInitialData("Vendor.xml"));
            xelRoot  = glDocument.DocumentElement;
            xnlNodes = xelRoot.SelectNodes("/data-set/record");
            foreach (XmlNode xndNode in xnlNodes)
            {
                Vendor vendor = ObjectSpace.FindObject <Vendor>(new BinaryOperator("Name", xndNode["Name"].InnerText));
                if (vendor == null)
                {
                    vendor                    = ObjectSpace.CreateObject <Vendor>();
                    vendor.Name               = xndNode["Name"].InnerText;
                    vendor.DiscountPercent    = Convert.ToDecimal(xndNode["DiscountPercent"].InnerText);
                    vendor.DiscountDays       = Convert.ToInt16(xndNode["DiscountDays"].InnerText);
                    vendor.Currency           = ObjectSpace.GetObjectByKey <Currency>(xndNode["Currency"].InnerText);
                    vendor.DefaultDueDays     = Convert.ToInt16(xndNode["DefaultDueDays"].InnerText);
                    vendor.DefaultDescription = xndNode["DefaultDescription"].InnerText;

                    vendor.Save();
                }
            }

            glDocument.LoadXml(GetInitialData("Items.xml"));
            xelRoot  = glDocument.DocumentElement;
            xnlNodes = xelRoot.SelectNodes("/data-set/record");
            foreach (XmlNode xndNode in xnlNodes)
            {
                Item item = ObjectSpace.FindObject <Item>(new BinaryOperator("ItemNumber", xndNode["ItemNumber"].InnerText));
                if (item == null)
                {
                    item                 = ObjectSpace.CreateObject <Item>();
                    item.Name            = xndNode["Name"].InnerText;
                    item.ItemNumber      = xndNode["ItemNumber"].InnerText;
                    item.Sales           = ObjectSpace.FindObject <GLAccount>(new BinaryOperator("AccountNumber", xndNode["Sales"].InnerText));
                    item.CostofGoodsSold = ObjectSpace.FindObject <GLAccount>(new BinaryOperator("AccountNumber", xndNode["CostofGoodsSold"].InnerText));
                    item.Inventory       = ObjectSpace.FindObject <GLAccount>(new BinaryOperator("AccountNumber", xndNode["Inventory"].InnerText));
                    item.Sold            = Convert.ToBoolean(xndNode["Sold"].InnerText);
                    item.Purchased       = Convert.ToBoolean(xndNode["Purchased"].InnerText);
                    item.Type            = ObjectSpace.FindObject <ItemType>(new BinaryOperator("Name", xndNode["Type"].InnerText));
                    item.Save();
                }
            }
            ObjectSpace.CommitChanges();
            glDocument.LoadXml(GetInitialData("VendorItem.xml"));
            xelRoot  = glDocument.DocumentElement;
            xnlNodes = xelRoot.SelectNodes("/data-set/record");
            foreach (XmlNode xndNode in xnlNodes)
            {
                VendorItem item = ObjectSpace.FindObject <VendorItem>(new BinaryOperator("Description", xndNode["Description"].InnerText));
                if (item == null)
                {
                    item                    = ObjectSpace.CreateObject <VendorItem>();
                    item.Item               = ObjectSpace.GetObjectByKey <Item>(xndNode["ItemNumber"].InnerText);
                    item.Vendor             = ObjectSpace.FindObject <Vendor>(CriteriaOperator.Parse("Name=?", xndNode["Vendor"].InnerText));
                    item.VendorItemNumber   = xndNode["VendorItemNumber"].InnerText;
                    item.VendorItemQuantity = Convert.ToInt16(xndNode["VendorItemQuantity"].InnerText);
                    item.Description        = xndNode["Description"].InnerText;
                    item.Cost               = Convert.ToDecimal(xndNode["Cost"].InnerText);

                    item.Save();
                }
            }

            ObjectSpace.CommitChanges();
        }
Ejemplo n.º 23
0
        public override void UpdateDatabaseAfterUpdateSchema()
        {
            base.UpdateDatabaseAfterUpdateSchema();
            //string name = "MyName";
            //DomainObject1 theObject = ObjectSpace.FindObject<DomainObject1>(CriteriaOperator.Parse("Name=?", name));
            //if(theObject == null) {
            //    theObject = ObjectSpace.CreateObject<DomainObject1>();
            //    theObject.Name = name;
            //}
            PermissionPolicyUser sampleUser = ObjectSpace.FindObject <PermissionPolicyUser>(new BinaryOperator("UserName", "User"));

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

            sampleUser.Roles.Add(defaultRole);

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

            if (userAdmin == null)
            {
                userAdmin          = ObjectSpace.CreateObject <PermissionPolicyUser>();
                userAdmin.UserName = "******";
                // 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);
            if (ObjectSpace.GetObjectsCount(typeof(Employee), null) == 0)
            {
                Employee Employee1 = ObjectSpace.CreateObject <Employee>();
                Employee1.EmployeeID = "001";
                Employee Employee2 = ObjectSpace.CreateObject <Employee>();
                Employee2.EmployeeID = "002";
            }

            if (ObjectSpace.GetObjectsCount(typeof(Product), null) == 0)
            {
                Product product = ObjectSpace.CreateObject <Product>();
                product.Name        = "Chai";
                product.Description = "is a tea beverage made by boiling black tea in milk and water with a mixture of aromatic herbs and spices[2]. Originating in India,[3] the beverage has gained worldwide popularity, becoming a feature in many coffee and tea houses. Although traditionally prepared as a decoction of green cardamom pods, cinnamon sticks, ground cloves, ground ginger, and black peppercorn together with black tea leaves, retail versions include tea bags for infusion, instant powdered mixtures, and concentrates.";
                for (int i = 0; i < 10; i++)
                {
                    Order order = ObjectSpace.CreateObject <Order>();
                    if (i % 2 == 0)
                    {
                        order.EmployeeID = "001";
                    }
                    else
                    {
                        order.EmployeeID = "002";
                    }
                    order.Product     = product;
                    order.Description = "Order " + i.ToString();
                }
                Order ExtraOrder = ObjectSpace.CreateObject <Order>();
                ExtraOrder.EmployeeID = "001";
                ExtraOrder.Product    = product;
            }
            if (ObjectSpace.GetObjectsCount(typeof(Person), null) == 0)
            {
                Person person = ObjectSpace.CreateObject <Person>();
                person.FirstName = "Jose";
                person.LastName  = "Ojeda";

                PhoneNumber RussianPhone = ObjectSpace.CreateObject <PhoneNumber>();
                RussianPhone.Number = "+7986532147";


                PhoneNumber SalvadoreanPhone = ObjectSpace.CreateObject <PhoneNumber>();
                SalvadoreanPhone.Number = "+5036532147";

                person.PhoneNumbers.Add(SalvadoreanPhone);
                person.PhoneNumbers.Add(RussianPhone);
            }



            ObjectSpace.CommitChanges(); //This line persists created object(s).
        }