public dynamic ModifyInstock(dynamic data)
 {
     if (data == null)
     {
         return(new { f = 0 });
     }
     else
     {
         int               id      = data.id;
         int               depotId = data.depotId;
         int               drugId  = data.drugId;
         int               supId   = data.supId;
         int               num     = data.num;
         DateTime          inDate  = data.inDate;
         DateTime          proDate = data.proDate;
         models.tb_DepotIn depotin = depotInBLL.SingleContextGetList(en => en.Id == id).FirstOrDefault();
         //depotdrug.Id = id;
         depotin.DepotId        = depotId;
         depotin.DrugId         = drugId;
         depotin.SupId          = supId;
         depotin.Num            = num;
         depotin.InDate         = inDate;
         depotin.ProductionDate = proDate;
         depotInBLL.SingleContextModify(depotin);
         //修改成功返回data
         return(new { items = data, f = 1 });
     }
 }
示例#2
0
        public dynamic PostBuildPurchaseDrug(dynamic data)
        {
            List <models.tb_DepotIn> depotInList = new List <models.tb_DepotIn>();
            List <int> pids = new List <int>();

            if (data != null)
            {
                foreach (var d in data)
                {
                    int pid = d;
                    pids.Add(pid);
                }
            }
            else
            {
                return(null);
            }
            var purchaseList = purchaseBLL.GetList(en => pids.Contains(en.Id));

            if (purchaseList != null)
            {
                foreach (var purchase in purchaseList)
                {
                    purchase.CloseDate = DateTime.Now;
                    purchase.Finish    = true;
                    foreach (var drug in purchase.tb_PurchaseDrugs)
                    {
                        models.tb_DepotIn depotin = new models.tb_DepotIn()
                        {
                            DepotId        = drug.DepotId,
                            DrugId         = drug.DrugId,
                            InDate         = DateTime.Now,
                            Num            = drug.Num,
                            ProductionDate = DateTime.Now,
                            SupId          = drug.SupId
                        };
                        models.tb_DepotDrug depotDrug = new models.tb_DepotDrug()
                        {
                            DepotId        = drug.DepotId,
                            DrugId         = drug.DrugId,
                            ProductionDate = DateTime.Now,
                            Num            = drug.Num
                        };
                        depotin.tb_DepotDrug.Add(depotDrug);
                        depotInList.Add(depotin);
                    }
                }
                depotInBLL.AddRange(depotInList);
                purchaseBLL.Modify(purchaseList);
            }
            else
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Conflict));
            }

            return(true);
        }
        public dynamic AddDepotDrug(dynamic data)
        {//用来接收ajax传来的数据
            //获取数据写入数据库
            if (data.result != null)
            {
                try
                {
                    List <models.tb_DepotIn> depotInList = new List <models.tb_DepotIn>();
                    var drugList = drugBLL.GetList(en => true);

                    foreach (var d in data.result)
                    {
                        //初始化对象
                        models.tb_DepotIn   tb_depotin   = new models.tb_DepotIn();
                        models.tb_DepotDrug tb_depotdrug = new models.tb_DepotDrug();
                        models.tb_Warning   warn         = new models.tb_Warning();
                        int      depotId = d.depotId;
                        int      drugId  = d.drugId;
                        int      supId   = d.supId;
                        int      num     = d.num;
                        DateTime inDate  = d.inDate;
                        DateTime proDate = d.proDate;
                        //为每一条仓库药品对象赋值
                        tb_depotdrug.DepotId        = depotId;
                        tb_depotdrug.DrugId         = drugId;
                        tb_depotdrug.Num            = num;
                        tb_depotdrug.ProductionDate = proDate;
                        tb_depotin.tb_DepotDrug.Add(tb_depotdrug);
                        //添加预警信息
                        double days = drugList.FirstOrDefault(en => en.Id == depotId).Shelf * 0.8;
                        warn.WarningDays = proDate.AddDays(days);
                        tb_depotdrug.tb_Warning.Add(warn);
                        //为每一条入库记录对象赋值
                        tb_depotin.DepotId        = depotId;
                        tb_depotin.DrugId         = drugId;
                        tb_depotin.SupId          = supId;
                        tb_depotin.Num            = num;
                        tb_depotin.InDate         = inDate;
                        tb_depotin.ProductionDate = proDate;
                        depotInList.Add(tb_depotin);
                    }
                    depotInBLL.AddRange(depotInList);
                }
                catch (Exception e)
                {
                    return(e.ToString());
                }
            }
            return(new{ });
        }