Esempio n. 1
0
        public void TestShopSaleReadProperly()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <CompanyDbContext>();

            using (var context = new CompanyDbContext(options, new FakeGetClaimsProvider("accessKey*")))
            {
                context.Database.EnsureCreated();
                var company   = Company.AddTenantToDatabaseWithSaveChanges("TestCompany", PaidForModules.None, context);
                var shop      = RetailOutlet.AddTenantToDatabaseWithSaveChanges("TestShop", company, context);
                var shopStock = new ShopStock {
                    Name = "dress", RetailPrice = 12, NumInStock = 2, Shop = shop
                };
                context.Add(shopStock);
                context.SaveChanges();

                //ATTEMPT
                var status = ShopSale.CreateSellAndUpdateStock(1, shopStock.ShopStockId, context);
                status.IsValid.ShouldBeTrue(status.GetAllErrors());
                context.Add(status.Result);
                context.SaveChanges();

                //VERIFY
                var salesNotFiltered = context.ShopSales.IgnoreQueryFilters()
                                       .Include(x => x.StockItem).ThenInclude(x => x.Shop)
                                       .ToList();

                salesNotFiltered.Count.ShouldEqual(1);
                salesNotFiltered.First().StockItem.ShouldNotBeNull();
                salesNotFiltered.First().StockItem.Shop.ShouldNotBeNull();
            }
        }
        public ShopStock Delete(ShopStock shopStocks)
        {
            var result = _context.Remove(shopStocks);

            _context.SaveChanges();
            return(result.Entity);
        }
Esempio n. 3
0
        public void TestDataKeyNotSetIfProvidedKeyIsNull()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <CompanyDbContext>();

            using (var context = new CompanyDbContext(options, new FakeGetClaimsProvider(null)))
            {
                context.Database.EnsureCreated();
                var company = Company.AddTenantToDatabaseWithSaveChanges("TestCompany", PaidForModules.None, context);
                var shop    = RetailOutlet.AddTenantToDatabaseWithSaveChanges("TestShop", company, context);
                var stock   = new ShopStock {
                    Name = "dress", Shop = shop
                };
                stock.SetShopLevelDataKey("accessKey*");
                context.Add(stock);
                context.SaveChanges();
            }
            using (var context = new CompanyDbContext(options, new FakeGetClaimsProvider("accessKey*")))
            {
                //ATTEMPT
                var stocksFiltered = context.ShopStocks.ToList();

                //VERIFY
                stocksFiltered.Count.ShouldEqual(1);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 获取药店所有药品库存
        /// </summary>
        /// <param name="ShopCode">药店编码</param>
        /// <param name="LsRepType">处方类型</param>
        /// <returns></returns>
        public static ShopStock GetAllShopStocks(string ShopCode, int LsRepType)
        {
            SetFlagValue(LsRepType);
            string         shop_code = ShopCode;
            HttpWebRequest request   = (System.Net.HttpWebRequest)WebRequest.Create(strURL);
            //参数
            IDictionary <string, string> parameters = new Dictionary <string, string>();
            string timestamp, token;

            SetBaseInterfcaeParameters(out timestamp, out token);
            parameters.Add("method", nameof(ShopStocks));
            parameters.Add("flag", flag);
            parameters.Add("model", ShopStocks);
            DataMain data_main = new DataMain()
            {
                shop_code  = shop_code,
                goods_code = "",
                timestamp  = timestamp,
                token      = token
            };
            string    Data_Json = SetParametersJson(parameters, data_main);
            string    jsonString = HttpRequestHelper.PostPage(strURL, Data_Json);
            ShopStock returnData = jsSerializer.Deserialize <ShopStock>(jsonString);

            return(returnData);
        }
        public ShopStock Create(ShopStock shopStocks)
        {
            var result = _context.Add <ShopStock>(shopStocks);

            _context.SaveChanges();
            return(result.Entity);
        }
        public static void AddStockToShops(this CompanyDbContext context, string [] lines)
        {
            foreach (var line in lines)
            {
                var colonIndex = line.IndexOf(':');
                var shopName   = line.Substring(0, colonIndex);
                var shop       = context.Tenants.IgnoreQueryFilters().OfType <RetailOutlet>()
                                 .SingleOrDefault(x => x.Name == shopName);
                if (shop == null)
                {
                    throw new ApplicationException($"Could not find a shop of name '{shopName}'");
                }

                var eachStock = from stockAndPrice in line.Substring(colonIndex + 1).Split(',')
                                let parts = stockAndPrice.Split('|').Select(x => x.Trim()).ToArray()
                                            select new { Name = parts[0], Price = decimal.Parse(parts[1]) };
                foreach (var stock in eachStock)
                {
                    var newStock = new ShopStock {
                        Name = stock.Name, NumInStock = 5, RetailPrice = stock.Price, Shop = shop
                    };
                    newStock.SetShopLevelDataKey(shop.DataKey);
                    context.Add(newStock);
                }
            }
        }
        public void TestQueryFilterWorksOnShopStock()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <CompanyDbContext>();

            using (var context = new CompanyDbContext(options, new FakeGetClaimsProvider("accessKey*")))
            {
                context.Database.EnsureCreated();
                var company = Company.AddTenantToDatabaseWithSaveChanges("TestCompany", PaidForModules.None, context);
                var shop    = RetailOutlet.AddTenantToDatabaseWithSaveChanges("TestShop", company, context);
                var stock   = new ShopStock {
                    Name = "dress", NumInStock = 5, Shop = shop
                };
                context.Add(stock);
                context.SaveChanges();

                var utData  = context.SetupSingleDtoAndEntities <SellItemDto>();
                var service = new CrudServices(context, utData.ConfigAndMapper);

                //ATTEMPT
                var dto = new SellItemDto
                {
                    TenantItemId = shop.TenantItemId,
                    ShopStockId  = stock.ShopStockId,
                    NumBought    = 1
                };
                var shopSale = service.CreateAndSave(dto);

                //VERIFY
                service.IsValid.ShouldBeTrue(service.GetAllErrors());
                context.ShopSales.Count().ShouldEqual(1);
                context.ShopStocks.Single().NumInStock.ShouldEqual(4);
            }
        }
Esempio n. 8
0
        public ShopStock Post(ShopStockDTO value)
        {
            ShopStock model = new ShopStock()
            {
                ComponentId = value.ComponentId,
                ShopId      = value.ShopId
            };

            return(IShopStockRepository.Create(model));
        }
Esempio n. 9
0
        public ActionResult ShopRiceStockEdit(int id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ShopStock shop = db.ShopStock.Find(id);

            if (shop == null)
            {
                return(HttpNotFound());
            }
            return(View(shop));
        }
Esempio n. 10
0
        public ShopStock Put(int id, ShopStockDTO value)
        {
            ShopStock model = IShopStockRepository.Get(id);

            if (value.ComponentId != 0)
            {
                model.ComponentId = value.ComponentId;
            }
            if (value.ComponentId != 0)
            {
                model.ComponentId = value.ComponentId;
            }
            return(IShopStockRepository.Update(model));
        }
Esempio n. 11
0
        public ActionResult ShopRiceStock(FormCollection form, ShopStock worth)
        {
            string idd = Convert.ToString(Session["UserId"]);

            var RiceName = Convert.ToString(form["RiceName"]);

            worth.srsc_title = RiceName;

            worth.Qty          = Convert.ToInt32(form["BAgs"]);
            worth.packing_type = Convert.ToInt32(form["packing"]);
            worth.PerBagPrice  = Convert.ToDecimal(form["Price"]);
            db.ShopStock.Add(worth);
            db.SaveChanges();

            return(RedirectToAction("ShopStock"));
        }
Esempio n. 12
0
        public ActionResult ShopRiceStockEdit(FormCollection form, ShopStock worth)
        {
            worth.ShopStockId = Convert.ToInt32(form["ShopStockId"]);
            ShopStock shop = db.ShopStock.Find(worth.ShopStockId);

            string idd = Convert.ToString(Session["UserId"]);

            var RiceName = Convert.ToString(form["RiceName"]);

            shop.srsc_title = RiceName;

            shop.Qty             = Convert.ToInt32(form["BAgs"]);
            shop.packing_type    = Convert.ToInt32(form["packing"]);
            shop.PerBagPrice     = Convert.ToDecimal(form["Price"]);
            db.Entry(shop).State = EntityState.Modified;
            db.SaveChanges();

            return(RedirectToAction("ShopStock"));
        }
Esempio n. 13
0
        public void Update_sales(FormCollection form)
        {
            var js = new JavaScriptSerializer();


            int shopid = Convert.ToInt16(form["ShopStockId"]);
            var obj    = js.DeserializeObject(form["ProducedRiceSales_ch"].ToString());
            List <ShopStock> ProducedRiceSales_ch = js.Deserialize <ShopStock[]>(form["ProducedRiceSales_ch"].ToString()).ToList();

            foreach (var item in ProducedRiceSales_ch)
            {
                var rsc = db.ShopStock.Find(item.ShopStockId);
                if (rsc == null)
                {
                    rsc = new ShopStock();
                }
                rsc.Rice_Production_id = item.Rice_Production_id;
                rsc.PerBagPrice        = item.PerBagPrice;
                rsc.Qty              = item.Qty;
                rsc.TotalWeight_KG   = item.TotalWeight_KG;
                rsc.TotalWeight_Mann = item.TotalWeight_Mann;
                rsc.SumWeight_KG     = item.SumWeight_KG;
                rsc.SumWeight_Mann   = item.SumWeight_Mann;
                rsc.Total_Amount     = item.Total_Amount;
                rsc.packing_type     = item.packing_type;
                rsc.NetTotal         = item.NetTotal;
                rsc.PerBagPrice      = item.packing_type;


                rsc.Status = true;
                if (item.ShopStockId == 0)
                {
                    db.ShopStock.Add(rsc);
                    db.SaveChanges();


                    var Rice_Produce_Bags = db.Rice_Produce_Bags.Where(m => m.Rice_Production_id == item.Rice_Production_id).ToList();

                    decimal qty = item.Qty;

                    foreach (var obj1 in Rice_Produce_Bags)
                    {
                        decimal diff = obj1.Rice_Produce_TotalBagsProduce - obj1.Rice_Produce_BagsSold;
                        if (diff > qty && qty > 0)
                        {
                            obj1.Rice_Produce_BagsSold     += Convert.ToInt32(qty);
                            obj1.Rice_Produce_RemainingBags = obj1.Rice_Produce_TotalBagsProduce - obj1.Rice_Produce_BagsSold;
                            db.Entry(obj1).State            = System.Data.Entity.EntityState.Modified;
                            db.SaveChanges();
                            qty = 0;
                        }
                        else if (diff <= qty && qty > 0 && diff != 0)
                        {
                            obj1.Rice_Produce_BagsSold     += Convert.ToInt32(diff);
                            obj1.Rice_Produce_RemainingBags = obj1.Rice_Produce_TotalBagsProduce - obj1.Rice_Produce_BagsSold;
                            db.Entry(obj1).State            = System.Data.Entity.EntityState.Modified;
                            db.SaveChanges();
                            qty -= diff;
                        }
                    }
                }
                else
                {
                    int prsc_qty = 0;
                    using (var newdb = new ApplicationDbContext())
                    {
                        prsc_qty = newdb.ShopStock.Where(m => m.ShopStockId == item.ShopStockId).First().Qty;
                    }
                    var Rice_Produce_Bags = db.Rice_Produce_Bags.Where(m => m.Rice_Production_id == item.Rice_Production_id).OrderByDescending(m => m.Rice_Produce_Bag_Date).ToList();

                    foreach (var obj_new in Rice_Produce_Bags)
                    {
                        if (prsc_qty >= obj_new.Rice_Produce_BagsSold && prsc_qty > 0)
                        {
                            decimal diff1 = prsc_qty - obj_new.Rice_Produce_BagsSold;
                            obj_new.Rice_Produce_BagsSold     -= Convert.ToInt32(obj_new.Rice_Produce_BagsSold);
                            obj_new.Rice_Produce_RemainingBags = obj_new.Rice_Produce_TotalBagsProduce - obj_new.Rice_Produce_BagsSold;
                            db.Entry(obj_new).State            = System.Data.Entity.EntityState.Modified;
                            db.SaveChanges();
                            prsc_qty = (int)diff1;
                        }
                        else if (prsc_qty < obj_new.Rice_Produce_BagsSold && prsc_qty > 0)
                        {
                            decimal diff1 = prsc_qty - obj_new.Rice_Produce_BagsSold;
                            obj_new.Rice_Produce_BagsSold     -= Convert.ToInt32(prsc_qty);
                            obj_new.Rice_Produce_RemainingBags = obj_new.Rice_Produce_TotalBagsProduce - obj_new.Rice_Produce_BagsSold;
                            db.Entry(obj_new).State            = System.Data.Entity.EntityState.Modified;
                            db.SaveChanges();
                            prsc_qty = (int)diff1;
                        }
                    }
                    db.Entry(rsc).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();



                    Rice_Produce_Bags = db.Rice_Produce_Bags.Where(m => m.Rice_Production_id == item.Rice_Production_id).ToList();

                    decimal qty = item.Qty;
                    foreach (var obj1 in Rice_Produce_Bags)
                    {
                        decimal diff = obj1.Rice_Produce_TotalBagsProduce - obj1.Rice_Produce_BagsSold;
                        if (diff > qty && qty > 0)
                        {
                            obj1.Rice_Produce_BagsSold     += Convert.ToInt32(qty);
                            obj1.Rice_Produce_RemainingBags = obj1.Rice_Produce_TotalBagsProduce - obj1.Rice_Produce_BagsSold;
                            db.Entry(obj1).State            = System.Data.Entity.EntityState.Modified;
                            db.SaveChanges();
                            qty = 0;
                        }
                        else if (diff <= qty && qty > 0 && diff != 0)
                        {
                            obj1.Rice_Produce_BagsSold     += Convert.ToInt32(diff);
                            obj1.Rice_Produce_RemainingBags = obj1.Rice_Produce_TotalBagsProduce - obj1.Rice_Produce_BagsSold;
                            db.Entry(obj1).State            = System.Data.Entity.EntityState.Modified;
                            db.SaveChanges();
                            qty -= diff;
                        }
                    }
                }
            }
        }
Esempio n. 14
0
 public void Update(ShopStock shopstock)
 {
     _shopstockrepository.Update(shopstock);
     _unitofwork.Commit();
 }
Esempio n. 15
0
        public ShopStock Delete(int id)
        {
            ShopStock shopStock = IShopStockRepository.Get(id);

            return(IShopStockRepository.Delete(shopStock));
        }
 public ShopStock Update(ShopStock shopStocks)
 {
     _context.Entry(shopStocks).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
     _context.SaveChanges();
     return(shopStocks);
 }
Esempio n. 17
0
        /// <summary>
        /// 根据单个商品编码和药店编码查询库存是否足够
        /// </summary>
        /// <param name="LsRepType">处方类型</param>
        /// <param name="code">编码</param>
        /// <param name="RecipeDtlTotality">数量</param>
        /// <param name="ShopCode">药店编码</param>
        /// <returns></returns>
        public static bool ShopStocksSingle(int LsRepType, string code, double RecipeDtlTotality, string ShopCode)
        {
            if (Service.DBClientService.GetModelByID <BsHospital>(UserProfiles.HospitalID).IsInterface)
            {
                flag = "5400";
                string shop_code = ShopCode;
                if (LsRepType == (int)EnumRecipeType.生鲜)//生鲜项目
                {
                    flag = "5602";
                    code = code.Substring(2);
                }
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(strURL);
                //参数
                IDictionary <string, string> parameters = new Dictionary <string, string>();
                string timestamp, token;
                SetBaseInterfcaeParameters(out timestamp, out token);
                parameters.Add("method", nameof(ShopStocks));
                parameters.Add("flag", flag);
                parameters.Add("model", ShopStocks);
                DataMain data_main = new DataMain()
                {
                    shop_code  = shop_code,
                    goods_code = code,
                    timestamp  = timestamp,
                    token      = token
                };
                string    Data_Json = SetParametersJson(parameters, data_main);
                string    jsonString = HttpRequestHelper.PostPage(strURL, Data_Json);
                ShopStock returnData = jsSerializer.Deserialize <ShopStock>(jsonString);

                double stocks = 0;
                if (returnData.data == null)
                {
                    //Orm.Client.Base.FrmMessageRemind.Show("没有查询到该项目库存,请更换药品或者手动删除项目");
                    return(false);
                }
                else if (returnData.data.Count > 0)
                {
                    stocks = double.Parse(returnData.data[0].stocks);
                    if (RecipeDtlTotality > stocks)
                    {
                        if (LsRepType == (int)EnumOuRecipeLsRepType.中药)
                        {
                            //Orm.Client.Base.FrmMessageBox.ShowDialog(string.Format("【{0}】处方总数【{1}】库存剩余数【{2}】,该项目库存不足,请更换药品或者手动更改数量", returnData.data[0].name, RecipeDtlTotality * 10, stocks * 10), "系统提示");
                        }
                        else
                        {
                            //Client.Base.FrmMessageBox.ShowDialog(string.Format("【{0}】处方总数【{1}】库存剩余数【{2}】,该项目库存不足,请更换药品或者手动更改数量", returnData.data[0].name, RecipeDtlTotality, stocks), "系统提示");
                        }
                        return(false);
                    }
                    else
                    {
                        return(true);
                    }
                }
                else
                {
                    //Orm.Client.Base.FrmMessageBox.ShowDialog(string.Format("没有查询到该项目库存,请更换药品或者手动删除项目"), "系统提示");
                    return(false);
                }
            }
            else
            {
                return(true);
            }
        }
Esempio n. 18
0
 public void Create(ShopStock shopstock)
 {
     _shopstockrepository.Add(shopstock);
     _unitofwork.Commit();
 }