Esempio n. 1
0
        private void TestProductSaleByDayNSAdd()
        {
            var addEntity = new ProductSaleByDayNSEntity()
            {
                DataSource      = "测试来源",
                ProductID       = Guid.NewGuid().ToString(),
                ShopID          = Guid.NewGuid().ToString(),
                ProductName     = "测试商品添加",
                OutProductID    = Guid.NewGuid().ToString(),
                ImportGroupId   = Guid.NewGuid().ToString(),
                StatisticalDate = DateTime.Now//分库分表字段是必须的
            };
            var repository = GetRepository();

            //如果新增主键是自增列会自动赋值自增列值到主键
            repository.Add(addEntity);
            var entity = repository.Get(new ProductSaleByDayNSEntity {
                SysNo = addEntity.SysNo
            });

            Assert.True(addEntity.SysNo > 0);
            Assert.NotNull(entity);
            Assert.AreEqual(addEntity.SysNo, entity.SysNo);
            Assert.AreEqual(addEntity.ProductName, entity.ProductName);
        }
Esempio n. 2
0
        public bool Delete()
        {
            var deleteEntity = new ProductSaleByDayNSEntity()
            {
                SysNo = Guid.Parse("650BC09C-2B9C-467B-A457-8B4853CC1F0F")
            };
            var repository = GetRepository();

            return(repository.Delete(deleteEntity));
        }
Esempio n. 3
0
 public string Index()
 {
     if (isRuning == true)
     {
         return("正在运行中");
     }
     lock (lockObj)
     {
         isRuning = true;
         try
         {
             var importGroupId       = Guid.NewGuid();
             var random              = new Random();
             var repositoryFactory   = RepositoryFactory.Create <ProductSaleByDayEntity>();
             var repositoryNSFactory = RepositoryFactory.Create <ProductSaleByDayNSEntity>();
             repositoryNSFactory.Delete(QueryFactory.Create <ProductSaleByDayNSEntity>());
             var tempDate = new DateTime(2018, 1, 1);
             while (tempDate <= DateTime.Now.Date)
             {
                 if (tempDate.Day == 1)
                 {
                     var query = QueryFactory.Create <ProductSaleByDayEntity>();
                     query.DBModel.DBModel_ShuffledTempDate = tempDate;
                     repositoryFactory.Delete(query);
                 }
                 foreach (var p in dicProduct)
                 {
                     var temp   = new ProductSaleByDayEntity();
                     var tempNS = new ProductSaleByDayNSEntity();
                     tempNS.SysNo           = temp.SysNo = Guid.NewGuid();
                     tempNS.DataSource      = temp.DataSource = lstDataSource[random.Next(lstDataSource.Count)];
                     tempNS.ShopID          = temp.ShopID = dicShop.Keys.ToList()[random.Next(dicShop.Count)];
                     tempNS.ShopName        = temp.ShopName = dicShop[temp.ShopID];
                     tempNS.ProductID       = temp.ProductID = p.Key;
                     tempNS.OutProductID    = temp.OutProductID = p.Value;
                     tempNS.ProductName     = temp.ProductName = p.Value;
                     tempNS.Sales           = temp.Sales = random.Next(100000);
                     tempNS.StatisticalDate = temp.StatisticalDate = tempDate;
                     tempNS.UpdateDate      = temp.UpdateDate = temp.CreateDate = DateTime.Now;
                     tempNS.UpdateUserID    = temp.UpdateUserID = temp.CreateUserID = Guid.NewGuid();
                     tempNS.ImportGroupId   = temp.ImportGroupId = importGroupId;
                     repositoryFactory.Add(temp);
                     repositoryNSFactory.Add(tempNS);
                 }
                 tempDate = tempDate.AddDays(1);
             }
         }
         finally
         {
             isRuning = false;
         }
         return("初始化成功");
     }
 }
Esempio n. 4
0
        public int UpdateWhere()
        {
            var updateEntity = new ProductSaleByDayNSEntity()
            {
                DataSource = "测试来源修改",
            };
            var repository = GetRepository();

            var where = QueryFactory.Create <ProductSaleByDayNSEntity>(m => m.DataSource == "新增测试来源" && m.StatisticalDate > new DateTime(2019, 01, 03));//where是更新条件

            return(repository.Update(updateEntity, where));
        }
Esempio n. 5
0
        public bool Update()
        {
            var updateEntity = new ProductSaleByDayNSEntity()
            {
                SysNo           = Guid.Parse("650BC09C-2B9C-467B-A457-8B4853CC1F0F"),
                DataSource      = "测试来源修改",
                StatisticalDate = new DateTime(2019, 01, 05),
            };
            var repository = GetRepository();

            //根据主键更新其他字段
            return(repository.Update(updateEntity));
        }
Esempio n. 6
0
        private void TestTranUpdateWhere(bool isCommit)
        {
            var repository = GetRepository();

            var where = QueryFactory.Create <ProductSaleByDayNSEntity>(m => !m.ProductName.Contains("批量修改Where") && m.ProductName.Contains("修改"));//where是更新条件

            var count        = repository.Count(where);
            var updateEntity = new ProductSaleByDayNSEntity()
            {
                DataSource  = "测试来源批量修改",
                ProductName = "商品批量修改Where"
            };

            using (var tran = DBTool.BeginTransaction())
            {
                Assert.AreEqual(tran.TransactionIndex, 1);
                using (var tran2 = DBTool.BeginTransaction())
                {
                    Assert.AreEqual(tran2.TransactionIndex, 2);
                    //注意如果是更新用的是实体类的DBModel_ShuffledTempDate Query中的无效
                    int updateCount = repository.Update(updateEntity, where);

                    Assert.AreEqual(updateCount, count);
                    Assert.AreNotEqual(updateCount, 0);
                    if (isCommit)
                    {
                        tran.Complete();
                    }
                }
            }
            using (var tran = DBTool.BeginTransaction())
            {
                Assert.AreEqual(tran.TransactionIndex, 1);
            }
            if (isCommit)
            {
                var newcount = repository.Count(where);
                Assert.AreNotEqual(count, newcount);
            }
            else
            {
                var newcount = repository.Count(where);
                Assert.AreEqual(count, newcount);
            }
            using (var tran = DBTool.BeginTransaction())
            {
                Assert.AreEqual(tran.TransactionIndex, 1);
            }
        }
Esempio n. 7
0
        public void Add()
        {
            var addEntity = new ProductSaleByDayNSEntity()
            {
                SysNo           = Guid.NewGuid(),
                DataSource      = "新增测试来源",
                ProductID       = Guid.NewGuid(),
                ShopID          = Guid.NewGuid(),
                ProductName     = "测试商品",
                OutProductID    = Guid.NewGuid().ToString(),
                ImportGroupId   = Guid.NewGuid(),
                StatisticalDate = DateTime.Now
            };
            var repository = GetRepository();

            //如果新增主键是自增列会自动赋值自增列值到主键
            repository.Add(addEntity);
        }
Esempio n. 8
0
        public void TestProductSaleByDayNSUpdateWhere()
        {
            var repository = GetRepository();
            var queryCount = QueryFactory.Create <ProductSaleByDayNSEntity>(m => !m.ProductName.Contains("没有") && m.ProductName.Contains("修改"));


            var count        = repository.Count(queryCount);
            var updateEntity = new ProductSaleByDayNSEntity()
            {
                DataSource  = "测试来源批量修改",
                ProductName = "商品修改Where"
            };

            var where = QueryFactory.Create <ProductSaleByDayNSEntity>(m => !m.ProductName.Contains("没有") && m.ProductName.Contains("修改"));//where是更新条件
            //注意如果是更新用的是实体类的DBModel_ShuffledTempDate Query中的无效
            int updateCount = repository.Update(updateEntity, where);

            Assert.AreEqual(updateCount, count);
            Assert.AreNotEqual(updateCount, 0);
        }
Esempio n. 9
0
        public string Index()
        {
            if (isRuning == true)
            {
                return("正在运行中");
            }
            lock (lockObj)
            {
                isRuning = true;
                try
                {
                    var repositoryNSFactory = RepositoryFactory.Create <ProductSaleByDayNSEntity>();
                    if (repositoryNSFactory.GetList(m => m.CreateDate > DateTime.Now.Date).Count > 100)
                    {
                        return("");
                    }
                    var shopRepository = RepositoryFactory.Create <ShopEntity>();
                    shopRepository.Delete(QueryFactory.Create <ShopEntity>());
                    for (int i = 0; i < 10; i++)
                    {
                        var shop = new ShopEntity
                        {
                            SysNo    = Guid.NewGuid().ToString(),
                            ShopCode = "00" + i,
                            ShopName = "测试店铺" + i,
                            ShopType = i % 3,
                            IsDelete = false,
                        };
                        shopRepository.Add(shop);
                    }
                    lstShop = shopRepository.GetList(QueryFactory.Create <ShopEntity>());
                    var importGroupId = Guid.NewGuid();
                    var random        = new Random();

                    repositoryNSFactory.Delete(QueryFactory.Create <ProductSaleByDayNSEntity>());
                    var tempDate = new DateTime(2018, 1, 1);
                    while (tempDate <= DateTime.Now)
                    {
                        foreach (var p in dicProduct)
                        {
                            var tempNS = new ProductSaleByDayNSEntity();

                            tempNS.DataSource = lstDataSource[random.Next(lstDataSource.Count)];
                            var shop = lstShop[random.Next(lstShop.Count)];
                            tempNS.ShopID = shop.SysNo;

                            tempNS.ProductID       = p.Key.ToString();
                            tempNS.OutProductID    = p.Value;
                            tempNS.ProductName     = p.Value;
                            tempNS.Sales           = random.Next(100000);
                            tempNS.StatisticalDate = tempDate;
                            tempNS.CreateDate      = DateTime.Now;
                            tempNS.CreateUserID    = Guid.NewGuid().ToString();
                            tempNS.ImportGroupId   = importGroupId.ToString();

                            repositoryNSFactory.Add(tempNS);
                        }
                        tempDate = tempDate.AddDays(1);
                    }
                }
                finally
                {
                    isRuning = false;
                }
                return("初始化成功");
            }
        }