Ejemplo n.º 1
0
 public dynamic TransferDepotDrug(dynamic data)
 {
     if (data == null)
     {
         return(new { f = 0 });
     }
     else
     {
         //midify
         int outId    = data.outId;
         int transNum = data.transNum;
         int inId     = data.inId;
         //转出:原来的num减去转出的num
         models.tb_DepotDrug depotdrug1 = depotDrugBLL.SingleContextGetList(en => en.Id == outId).FirstOrDefault();
         depotdrug1.Num = depotdrug1.Num - transNum;
         //转入:原来的num加上转入的num
         models.tb_DepotDrug depotdrug2 = depotDrugBLL.SingleContextGetList(en => en.Id == inId).FirstOrDefault();
         depotdrug2.Num = depotdrug2.Num + transNum;
         //保存修改
         depotDrugBLL.SingleContextModify(depotdrug1);
         depotDrugBLL.SingleContextModify(depotdrug2);
         //修改成功返回data
         return(new { items = data, f = 1 });
     }
 }
Ejemplo n.º 2
0
 public dynamic ModifyDepotDrug(dynamic data)
 {
     ///修改规则
     ///单修改仓库药品
     ///修改失败f=0,成功f=1;
     if (data == null)
     {
         return(new { f = 0 });
     }
     else
     {
         int id = data.id;
         //depotinId
         int                 depotId   = data.depotId;
         int                 drugId    = data.drugId;
         int                 num       = data.num;
         DateTime            proDate   = data.proDate;
         models.tb_DepotDrug depotdrug = depotDrugBLL.SingleContextGetList(en => en.Id == id).FirstOrDefault();
         //depotdrug.Id = id;
         depotdrug.DepotId        = depotId;
         depotdrug.DrugId         = drugId;
         depotdrug.Num            = num;
         depotdrug.ProductionDate = proDate;
         depotDrugBLL.SingleContextModify(depotdrug);
         //修改成功返回data
         return(new { items = data, f = 1 });
     }
 }
Ejemplo n.º 3
0
 public dynamic OutStock(dynamic data)
 {//用来接收ajax传来的数据
     //获取数据写入数据库
     if (data.result != null)
     {
         try
         {
             foreach (var d in data.result)
             {
                 //取出值
                 int      depotdrugId = d.depotdrugId;
                 int      num         = d.num;
                 DateTime outDate     = d.outDate;
                 //初始化对象
                 models.tb_DepotDrug depotdrug = depotDrugBLL.SingleContextGetList(e => e.Id == depotdrugId).FirstOrDefault();
                 models.tb_DepotOut  depotout  = new models.tb_DepotOut();
                 //赋值
                 depotout.DepotId = depotdrug.DepotId;
                 depotout.DrugId  = depotdrug.DrugId;
                 depotout.SupId   = depotdrug.tb_DepotIn.SupId;
                 depotout.Num     = num;
                 depotout.OutDate = outDate;
                 //////出库
                 depotdrug.Num -= num;
                 depotdrug.tb_DepotOut.Add(depotout);
                 depotDrugBLL.SingleContextModify(depotdrug);
             }
         }
         catch (Exception e)
         {
             return(e.ToString());
         }
     }
     return(new { });
 }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        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{ });
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            DateTime time = new DateTime(2016, 5, 4);

            int[] months = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
            selectStock();
            //insertPur();
            //List<models.tb_SupplierInfo> slist = new List<models.tb_SupplierInfo>();
            //for (int i = 0; i < 7; i++)
            //{
            //    models.tb_SupplierInfo supp = new models.tb_SupplierInfo()
            //    {
            //        Name = Snames[i],
            //        CompanyPhone = "1234567891" + i,
            //        ContactName = "张三",
            //        Email = "*****@*****.**",
            //        Fax = "1234567-321",
            //        LegalPersons = "李四",
            //        OrganizationCode = "00000000-0",
            //        PostalCode = "300000",
            //        Address = "中国",
            //        ContactPhone = "1234567891" + 1

            //    };
            //    slist.Add(supp);
            //}
            //supplierBLL.AddRange(slist);
            //List<models.tb_DrugInfo> dlist = new List<models.tb_DrugInfo>();
            //int l = 0;
            //foreach (var s in drugNames)
            //{
            //    models.tb_DrugInfo drug = new models.tb_DrugInfo()
            //    {
            //        LicenseNumber = "国药准字Z1002021" + l,
            //        Name = s,
            //        spec = "盒",
            //        Shelf = 365,
            //        Uses = "感冒,上火"
            //    };
            //    l++;
            //    dlist.Add(drug);
            //}
            //drugBLL.AddRange(dlist);
            //List<models.tb_DepotInfo> ddlist = new List<models.tb_DepotInfo>();
            //for (int i = 0; i < 4; i++)
            //{
            //    models.tb_DepotInfo d = new models.tb_DepotInfo()
            //    {
            //        Address = "天津",
            //        Area = 400.5,
            //        Name = depotNames[i],
            //        Type = i
            //    };
            //    ddlist.Add(d);
            //}
            ////depotBLL.AddRange(ddlist);
            //List<models.tb_DepotIn> ilist = new List<models.tb_DepotIn>();
            //List<models.tb_DepotDrug> dddlist = new List<models.tb_DepotDrug>();
            //for (int i = 0; i < 100; i++)
            //{
            //    Random r = new Random(Guid.NewGuid().GetHashCode());
            //    models.tb_DepotIn din = new models.tb_DepotIn();
            //    din.DepotId = r.Next(1, 5);
            //    r = new Random(Guid.NewGuid().GetHashCode());
            //    din.DrugId = r.Next(1, 11);
            //    r = new Random(Guid.NewGuid().GetHashCode());
            //    din.Num = r.Next(2, 10) * 100;
            //    r = new Random(Guid.NewGuid().GetHashCode());
            //    din.SupId = r.Next(1, 8);
            //    r = new Random(Guid.NewGuid().GetHashCode());
            //    din.InDate = time.AddMonths(r.Next(0, 12)).AddDays(-r.Next(1, 30));
            //    r = new Random(Guid.NewGuid().GetHashCode());
            //    din.ProductionDate = time.AddMonths(-r.Next(1, 5));
            //    r = new Random(Guid.NewGuid().GetHashCode());
            //    ilist.Add(din);

            //    models.tb_DepotDrug dd = new models.tb_DepotDrug()
            //    {
            //        ProductionDate = din.ProductionDate,
            //        Num = din.Num,
            //        DepotId = din.DepotId,
            //        DrugId = din.DrugId,
            //        DepotInId = i + 1
            //    };
            //    dddlist.Add(dd);
            //}
            //depotInBLL.AddRange(ilist);
            //depotDrugBLL.AddRange(dddlist);
            //List<models.tb_DepotOut> dlist1 = new List<models.tb_DepotOut>();
            //List<models.tb_DepotDrug> ddlist2 = depotDrugBLL.SingleContextGetList(en => true, en => en.tb_DepotIn);
            models.tb_DepotDrug dd       = depotDrugBLL.SingleContextGetList(en => en.Id == 1).FirstOrDefault();
            models.tb_DepotOut  depotout = new models.tb_DepotOut()
            {
                Num = 100
            };

            dd.Num -= 100;
            dd.tb_DepotOut.Add(depotout);
            depotDrugBLL.SingleContextModify(dd);
            //for (int i = 0; i < 100; i++)
            //{
            //    Random r = new Random(Guid.NewGuid().GetHashCode());
            //    models.tb_DepotDrug dd = ddlist2[r.Next(0, ddlist2.Count)];
            //    var depotIn = depotInBLL.GetList(en => en.Id == dd.DepotInId).FirstOrDefault();
            //    int num = r.Next(2, 5) * 10;
            //    models.tb_DepotOut din = new models.tb_DepotOut();
            //    din.DepotId = dd.DepotId;
            //    din.DrugId = dd.DrugId;
            //    r = new Random(Guid.NewGuid().GetHashCode());
            //    dd.Num -= num;
            //    din.Num = num;
            //    din.SupId = 1;
            //    r = new Random(Guid.NewGuid().GetHashCode());
            //    var R = new Random(Guid.NewGuid().GetHashCode());
            //    din.OutDate = dd.tb_DepotIn.InDate.AddMonths(r.Next(0, 10)).AddDays(R.Next(1, 10));
            //    din.tb_DepotDrug.Add(dd);
            //    dlist1.Add(din);
            //}
            //depotOutBLL.SingleContextAddRange(dlist1);
            //int year = 2016;
            //DateTime time2 = new DateTime(year, 1, 1);
            //DateTime time3 = new DateTime(year + 1, 1, 1);
            //var outIds = depotOutBLL.GetList(de => de.OutDate >= time2 && de.OutDate <time3).Select(en => en.Id);
            //var l = depotDrugBLL.GetList(en => en.tb_DepotIn.InDate >= time2 && en.tb_DepotIn.InDate < time3 && en.DepotId==1 && en.DrugId==1, en => en.tb_DepotOut, en => en.tb_DepotIn, en => en.tb_DepotInfo, tb => tb.tb_DrugInfo);
            //var depotdrug = from s in l
            //                group s by new { s.DepotId, s.DrugId } into g
            //                select new
            //                {
            //                    depotId = g.Key.DepotId,
            //                    drugId = g.Key.DrugId,
            //                    sum = g.Sum(en => en.Num)
            //                };

            //var c = from m in months
            //        join s in l on m equals  s.tb_DepotIn.InDate.Month into monthDepot
            //        from md in monthDepot.DefaultIfEmpty()
            //        group md by new { md.tb_DrugInfo, md.tb_DepotInfo, month = m } into g
            //        select new
            //        {
            //            depotName ="东仓库",
            //            drugName = "复方感冒灵",
            //            outNum =g!=null?g.Sum(en => en.tb_DepotOut.Where(de => outIds.Contains(de.Id)).Sum(x => x.Num)):0,
            //            inNum =g!=null?g.Sum(en => en.tb_DepotIn.Num):0,
            //            Num = g!= null?g.Sum(en => en.tb_DepotIn.Num)-g.Sum(en => en.tb_DepotOut.Where(de => outIds.Contains(de.Id)).Sum(x => x.Num)):0,
            //            month = g.Key.month

            //        };
            //DefaultIfEmpty()能够为空序列提供一个默认的元素。DefaultIfEmpty使用到了泛型的default关键词,
            //对于引用类型将返回null,而对于值类型将返回0。对于结构体类型,则会根据其成员类型将他们对应的初始化为null或者0.
            //var z = from m in months
            //        join s in t
            //        on m equals s.month into os
            //        from x in os.DefaultIfEmpty()
            //        select new
            //        {
            //            depotName =(x==null)?null:x.depotName,
            //            drugName = (x == null) ? null : x.drugName,
            //            outNum = (x == null) ? 0 : x.outNum,
            //            inNum = (x == null) ? 0 : x.inNum,
            //            Num = (x == null) ? 0 : x.Num,
            //            month = m
            //        }
            //                ;
            //var l = depotDrugBLL.GetList(en => true, en => en.tb_DepotOut, en => en.tb_DepotIn, en => en.tb_DepotInfo, tb => tb.tb_DrugInfo);
            //var t = from s in l
            //        group s by new {s.tb_DrugInfo,s.tb_DepotInfo} into g
            //        orderby g.Key.tb_DepotInfo.Name
            //        select new
            //        {
            //            depotName=g.Key.tb_DepotInfo.Name,
            //            drugName=g.Key.tb_DrugInfo.Name,
            //            outNum=g.Sum(en=>en.tb_DepotOut.Sum(x=>x.Num)),
            //            inNum=g.Sum(en=>en.tb_DepotIn.Num)

            //        };
            //int a;
        }