Exemplo n.º 1
0
        public ActionResult ListCollage(List <PW_Collage> listCollage, List <SYS_CollageDetai> listCollageDetai)//保存领料主页面
        {
            ArrayList list = new ArrayList();

            try
            {
                try
                {
                    var Auditor       = Session["UserName"].ToString().Trim(); //审核人
                    var Operator      = Session["UserName"].ToString().Trim(); //操作人
                    var CollageStates = "已领料".Trim();
                    var AuditDate     = DateTime.Now;                          //审核时间
                    list.Add(Auditor);
                    list.Add(Operator);
                    list.Add(AuditDate.ToString());
                    list.Add(CollageStates);
                    listCollage[0].Auditor   = Auditor;
                    listCollage[0].Operator  = Operator;
                    listCollage[0].AuditDate = AuditDate;
                    listCollage[0].ToAudit   = true;
                }
                catch (Exception)
                {
                    return(Redirect("/Home/Login"));
                }
                var CollageState = "已领料".Trim();
                if (listCollage[0].CollageID == 0)
                {
                    myModels.PW_Collage.Add(listCollage[0]);
                }
                else
                {
                    myModels.Entry(listCollage[0]).State = System.Data.Entity.EntityState.Modified;
                }
                if (myModels.SaveChanges() > 0)
                {
                    var CollageID = listCollage[0].CollageID;
                    if (listCollageDetai != null)
                    {
                        List <int> oldID        = new List <int>(); //原来ID
                        List <int> newID        = new List <int>(); //新ID
                        List <int> listdelectID = new List <int>(); //需要删除的ID集合
                        var        lists        = myModels.SYS_CollageDetai.Where(m => m.CollageID == CollageID).Select(m => new { m.CollageDetaiID }).ToList();
                        foreach (var item in lists)
                        {
                            oldID.Add(item.CollageDetaiID);
                        }
                        for (int i = 0; i < listCollageDetai.Count; i++)
                        {
                            listCollageDetai[i].CollageID = CollageID;
                            var CollageDetaiID    = listCollageDetai[i].CollageDetaiID;
                            var FittingsCode      = listCollageDetai[i].FittingsCode.Trim();                                                                             //配件编码
                            var VehicleType       = listCollageDetai[i].VehicleType.Trim();                                                                              //车型
                            var InvenQuan         = listCollageDetai[i].Quantity;                                                                                        //数量
                            var WarehouseID       = listCollageDetai[i].WarehouseID;                                                                                     //仓库ID
                            var listInventory     = myModels.SYS_Inventory.Where(m => m.FittingsCode == FittingsCode && m.WarehouseID == WarehouseID).SingleOrDefault(); //库存表
                            var listInventorys    = myModels.SYS_Inventory.Where(m => m.FittingsCode == FittingsCode).ToList();                                          //库存表
                            var listFittingsInfos = (from tbFittingsInfo in myModels.SYS_FittingsInfo where tbFittingsInfo.FittingsCode == FittingsCode select tbFittingsInfo).SingleOrDefault();
                            var listFittingsInfo  = (from tbFittingsInfo in myModels.SYS_FittingsInfo
                                                     join tbFittingsType in myModels.SYS_FittingsType on tbFittingsInfo.FittingsTypeID equals tbFittingsType.FittingsTypeID
                                                     join tbVehicleType in myModels.SYS_VehicleType on tbFittingsInfo.VehicleTypeID equals tbVehicleType.VehicleTypeID
                                                     join tbSystemUnit in myModels.SYS_SystemUnit on tbFittingsInfo.SystemUnitID equals tbSystemUnit.SystemUnitID
                                                     where tbFittingsInfo.FittingsCode == FittingsCode
                                                     select new FittingsInfoVo
                            {
                                FittingsCode = tbFittingsInfo.FittingsCode.Trim(),
                                FittingsName = tbFittingsInfo.FittingsName.Trim(),
                                Intake = tbFittingsInfo.Intake,
                                SalesPrice = tbFittingsInfo.SalesPrice,
                                WholesalePrice = tbFittingsInfo.WholesalePrice,
                                FittingsTypeName = tbFittingsType.FittingsTypeName.Trim(),
                                VehicleType = tbVehicleType.VehicleType.Trim(),
                                SystemUnit = tbSystemUnit.SystemUnit.Trim(),
                            }).SingleOrDefault();

                            if (CollageDetaiID == 0)
                            {
                                myModels.SYS_CollageDetai.Add(listCollageDetai[i]);//新增
                            }
                            else
                            {
                                newID.Add(listCollageDetai[i].CollageDetaiID);
                                myModels.Entry(listCollageDetai[i]).State = System.Data.Entity.EntityState.Modified;//修改
                            }
                            if (listFittingsInfos != null)
                            {
                                var lis = myModels.SYS_CollageDetai.Where(m => m.CollageDetaiID == CollageDetaiID).Select(m => new { m.FittingsCode, m.WarehouseID, m.Quantity }).SingleOrDefault();//查询原来明细信息
                                if (lis != null)
                                {
                                    var Quantity = lis.Quantity;
                                    listFittingsInfos.InvenQuan = listFittingsInfos.InvenQuan + (Quantity - InvenQuan);//修改配件表数量
                                }
                                else
                                {
                                    var liInvenQuan = listFittingsInfos.InvenQuan != null? listFittingsInfos.InvenQuan:0;
                                    listFittingsInfos.InvenQuan = liInvenQuan - InvenQuan;//修改配件表数量
                                }
                                myModels.Entry(listFittingsInfos).State = System.Data.Entity.EntityState.Modified;
                            }
                            if (listInventory != null)//修改库存信息
                            {
                                if (CollageDetaiID != 0)
                                {
                                    var lis = myModels.SYS_CollageDetai.Where(m => m.CollageDetaiID == CollageDetaiID).Select(m => new { m.FittingsCode, m.WarehouseID, m.Quantity }).SingleOrDefault(); //查询原来明细信息
                                    if (lis.WarehouseID != WarehouseID)
                                    {
                                        var liWarehouseID  = lis.WarehouseID;
                                        var liFittingsCode = lis.FittingsCode;
                                        var oldInvenQuan   = myModels.SYS_Inventory.Where(m => m.WarehouseID == liWarehouseID && m.FittingsCode == liFittingsCode).SingleOrDefault(); //旧库存表
                                        oldInvenQuan.InvenQuan             = oldInvenQuan.InvenQuan + InvenQuan;
                                        myModels.Entry(oldInvenQuan).State = System.Data.Entity.EntityState.Modified;                                                                 //修改
                                        listInventory.InvenQuan            = listInventory.InvenQuan - InvenQuan;
                                    }
                                    else
                                    {
                                        var Quantity = lis.Quantity;
                                        listInventory.InvenQuan = listInventory.InvenQuan + (Quantity - InvenQuan);
                                    }
                                }
                                else
                                {
                                    listInventory.InvenQuan = listInventory.InvenQuan - InvenQuan;
                                }
                                myModels.Entry(listInventory).State = System.Data.Entity.EntityState.Modified;//修改
                            }
                            else//新增库存信息
                            {
                                SYS_Inventory sys_Inventory = new SYS_Inventory();
                                sys_Inventory.Position    = listCollageDetai[i].Position;
                                sys_Inventory.WarehouseID = listCollageDetai[i].WarehouseID;
                                if (listFittingsInfo != null)
                                {
                                    sys_Inventory.FittingsType = listFittingsInfo.FittingsTypeName;
                                    sys_Inventory.FittingsCode = listFittingsInfo.FittingsCode;
                                    sys_Inventory.FittingsName = listFittingsInfo.FittingsName;
                                    sys_Inventory.VehicleType  = listFittingsInfo.VehicleType;
                                    sys_Inventory.SystemUnit   = listFittingsInfo.SystemUnit;
                                    sys_Inventory.InvenQuan    = -InvenQuan;
                                    sys_Inventory.NewIntake    = listFittingsInfo.Intake;
                                    sys_Inventory.SalePrice    = listFittingsInfo.SalesPrice;
                                    sys_Inventory.WholePrice   = listFittingsInfo.WholesalePrice;
                                    myModels.SYS_Inventory.Add(sys_Inventory);//新增
                                }
                                else
                                {
                                    sys_Inventory.NewIntake    = 0;
                                    sys_Inventory.WholePrice   = 0;
                                    sys_Inventory.FittingsCode = listCollageDetai[i].FittingsCode;
                                    sys_Inventory.FittingsName = listCollageDetai[i].FittingsName;
                                    sys_Inventory.VehicleType  = listCollageDetai[i].VehicleType;
                                    sys_Inventory.SystemUnit   = listCollageDetai[i].SystemUnit;
                                    sys_Inventory.InvenQuan    = -listCollageDetai[i].Quantity;
                                    sys_Inventory.SalePrice    = listCollageDetai[i].UnitPrice;
                                    sys_Inventory.Position     = listCollageDetai[i].Position;
                                    myModels.SYS_Inventory.Add(sys_Inventory);//新增
                                }
                            }
                            myModels.SaveChanges();
                        }
                        var ReceptionID   = listCollage[0].ReceptionID;
                        var listReception = (from tbReception in myModels.PW_Reception where tbReception.ReceptionID == ReceptionID select tbReception).Single();
                        listReception.CollageState          = CollageState;
                        myModels.Entry(listReception).State = System.Data.Entity.EntityState.Modified;
                        myModels.SaveChanges();
                        listdelectID = oldID.Except(newID).ToList();//从某集合中删除其与另一个集合中相同的项;其实这个说简单点就是某集合中独有的元素(差集)
                        foreach (var item in listdelectID)
                        {
                            var listQuantity = myModels.SYS_CollageDetai.Where(m => m.CollageDetaiID == item).Select(m => new { m.Quantity, m.FittingsCode, m.WarehouseID }).SingleOrDefault();

                            var FittingsCode      = listQuantity.FittingsCode;
                            var WarehouseID       = listQuantity.WarehouseID;
                            var Quantity          = listQuantity.Quantity;
                            var listInventory     = myModels.SYS_Inventory.Where(m => m.FittingsCode == FittingsCode && m.WarehouseID == WarehouseID).SingleOrDefault();                          //库存表
                            var listFittingsInfos = (from tbFittingsInfo in myModels.SYS_FittingsInfo where tbFittingsInfo.FittingsCode == FittingsCode select tbFittingsInfo).SingleOrDefault(); //配件表
                            listInventory.InvenQuan                 = listInventory.InvenQuan + Quantity;
                            listFittingsInfos.InvenQuan             = listFittingsInfos.InvenQuan + Quantity;
                            myModels.Entry(listInventory).State     = System.Data.Entity.EntityState.Modified;        //修改库存数量
                            myModels.Entry(listFittingsInfos).State = System.Data.Entity.EntityState.Modified;        //修改配件数量
                            var listdelect = myModels.SYS_CollageDetai.Where(m => m.CollageDetaiID == item).Single(); //删除
                            myModels.SYS_CollageDetai.Remove(listdelect);
                        }
                    }
                    else
                    {
                        var listdelect = myModels.SYS_CollageDetai.Where(m => m.CollageID == CollageID).ToList();//删除全部
                        myModels.SYS_CollageDetai.RemoveRange(listdelect);
                    }
                    myModels.SaveChanges();
                }
            }
            catch (Exception e)
            {
                return(Json(false, JsonRequestBehavior.AllowGet));
            }
            return(Json(list, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 2
0
        public ActionResult ToAuditIncome(int IncomingID, int NewWarehouseID, string IndentNumber) //审核入库单
        {
            var WarehousingDetail = Session["WarehousingDetail"] as List <SYS_WarehousingDetail>;  //入库明细

            try
            {
                var list = myModels.PW_Incoming.Where(m => m.IncomingID == IncomingID).Single();
                list.IncomingID            = list.IncomingID;
                list.ToAudit               = true;
                list.Auditor               = Session["UserName"].ToString();
                list.AuditDate             = DateTime.Now;
                myModels.Entry(list).State = System.Data.Entity.EntityState.Modified;
                if (myModels.SaveChanges() > 0)
                {
                    if (!string.IsNullOrEmpty(IndentNumber))
                    {
                        var Proc = myModels.PW_Procurement.Where(m => m.IndentNumber == IndentNumber).SingleOrDefault();
                        Proc.Documents             = "已进完货";
                        myModels.Entry(Proc).State = System.Data.Entity.EntityState.Modified;
                    }
                    foreach (var item in WarehousingDetail)                 //遍历明细
                    {
                        var WarehousingDetailID = item.WarehousingDetailID; //明细ID
                        var FittingsInfoID      = item.FittingsInfoID;      //配件ID
                        var Quantity            = item.Quantity;            //数量
                        var listFittings        = (from tbFittingsInfo in myModels.SYS_FittingsInfo
                                                   join tbFittingsType in myModels.SYS_FittingsType on tbFittingsInfo.FittingsTypeID equals tbFittingsType.FittingsTypeID
                                                   join tbVehicleType in myModels.SYS_VehicleType on tbFittingsInfo.VehicleTypeID equals tbVehicleType.VehicleTypeID
                                                   join tbSystemUnit in myModels.SYS_SystemUnit on tbFittingsInfo.SystemUnitID equals tbSystemUnit.SystemUnitID
                                                   where tbFittingsInfo.FittingsInfoID == FittingsInfoID
                                                   select new FittingsInfoVo
                        {
                            FittingsCode = tbFittingsInfo.FittingsCode.Trim(),
                            FittingsName = tbFittingsInfo.FittingsName.Trim(),
                            VehicleType = tbVehicleType.VehicleType.Trim(),
                            FittingsTypeName = tbFittingsType.FittingsTypeName.Trim(),
                            SystemUnit = tbSystemUnit.SystemUnit.Trim()
                        }).SingleOrDefault();
                        var FittingsCode   = listFittings.FittingsCode;                                                                                              //配件编码
                        var listInventorys = myModels.SYS_Inventory.Where(m => m.WarehouseID == NewWarehouseID && m.FittingsCode == FittingsCode).SingleOrDefault(); //修改后仓库
                        if (listInventorys != null)                                                                                                                  //修改库存(库存量)
                        {
                            listInventorys.InvenQuan             = listInventorys.InvenQuan + Quantity;
                            myModels.Entry(listInventorys).State = System.Data.Entity.EntityState.Modified;
                        }
                        else
                        {//新增库存
                            SYS_Inventory sys_Inventory = new SYS_Inventory();
                            sys_Inventory.FittingsCode = listFittings.FittingsCode;
                            sys_Inventory.FittingsName = listFittings.FittingsName;
                            sys_Inventory.FittingsType = listFittings.FittingsTypeName;
                            sys_Inventory.VehicleType  = listFittings.VehicleType;
                            sys_Inventory.SystemUnit   = listFittings.SystemUnit;
                            sys_Inventory.WarehouseID  = NewWarehouseID;
                            sys_Inventory.InvenQuan    = Quantity;
                            sys_Inventory.SalePrice    = item.UnitPrice;
                            myModels.SYS_Inventory.Add(sys_Inventory);
                        }
                        //修改配件信息表库存量
                        var listFit = myModels.SYS_FittingsInfo.Where(m => m.FittingsInfoID == FittingsInfoID).SingleOrDefault();
                        listFit.InvenQuan             = listFit.InvenQuan + Quantity;
                        myModels.Entry(listFit).State = System.Data.Entity.EntityState.Modified;
                    }
                }
                myModels.SaveChanges();
            }
            catch (Exception)
            {
                return(Json(false, JsonRequestBehavior.AllowGet));
            }
            return(Json(true, JsonRequestBehavior.AllowGet));
        }