Ejemplo n.º 1
0
        public ActionResult EnterWarehouse(EnterWarehouseBillViewModel model)
        {
            if (ModelState.IsValid)
            {
                //创建数据
                EnterWarehouseBill bill = new EnterWarehouseBill();
                bill.Id = model.Id;
                bill.BillNo = model.BillNo;
                bill.PlanId = model.PlanId;
                bill.CustomerId = model.CustomerId;
                bill.CustomerName = model.CustomerName;
                bill.DeliveryNo = model.DeliveryNo;
                bill.EnterType = model.EnterType;
                bill.IsConsigning = model.IsConsigning;
                bill.Warehouse = model.Warehouse;
                bill.UnloadingForceFeePrice = model.UnloadingForceFeePrice;
                bill.ForceFee = model.ForceFee;
                bill.StorageFeePrice = model.StorageFeePrice;
                bill.HasDrayage = model.HasDrayage;
                bill.Remark = model.Remark;
                bill.CreateTime = DateTime.Parse(model.CreateTime);

                List<EnterWarehouseBillGoods> listGoods = new List<EnterWarehouseBillGoods>();
                foreach (EnterWarehouseBillGoodsViewModel m in model.Goods)
                {
                    EnterWarehouseBillGoods g = new EnterWarehouseBillGoods();
                    g.Id = m.Id;
                    g.CustomerId = model.CustomerId;
                    g.CustomerName = model.CustomerName;
                    g.GoodsId = m.GoodsId;
                    g.GoodsNo = m.GoodsNo;
                    g.GoodsName = m.GoodsName;
                    g.Brand = m.Brand;
                    g.SpecModel = m.SpecModel;
                    g.GWeight = m.GWeight;
                    g.Grade = m.Grade;
                    g.BatchNo = m.BatchNo;
                    g.Packing = m.Packing;
                    g.Warehouse = model.Warehouse;
                    g.Location = m.Location;
                    g.Packages = m.Packages;
                    g.PieceWeight = m.PieceWeight;
                    g.Tunnages = m.Tunnages;
                    g.Piles = m.Piles;
                    g.TenThousands = m.TenThousands;
                    g.ProductionDate = m.ProductionDate;
                    g.ShipmentBillGoodsIds = m.ShipmentBillGoodsIds;
                    g.EnterWarehouseBillId = m.EnterWarehouseBillId;
                    g.DeliveryNo = model.DeliveryNo;
                    g.CreateTime = DateTime.Parse(model.CreateTime);
                    listGoods.Add(g);
                }

                //保存数据
                string strErrText;
                StockSystem stock = new StockSystem();
                if (bill.Id == 0)
                {
                    long nEnterWarehouseBillId = stock.InsertEnterWarehouseBill(bill, listGoods, LoginAccountId, LoginStaffName, out strErrText);
                    if (nEnterWarehouseBillId > 0)
                    {
                        //读取入库单号
                        bill = stock.LoadEnterWarehouseBill(nEnterWarehouseBillId, LoginAccountId, LoginStaffName, out strErrText);
                        if (bill == null)
                        {
                            var ret = new
                            {
                                EnterWarehouseBillNo = string.Empty,
                                ErrorText = strErrText
                            };
                            return Json(ret);
                        }
                        else
                        {
                            var ret = new
                            {
                                EnterWarehouseBillNo = bill.BillNo,
                                ErrorText = string.Empty
                            };
                            return Json(ret);
                        }
                    }
                    else
                    {
                        var ret = new
                        {
                            EnterWarehouseBillNo = string.Empty,
                            ErrorText = strErrText
                        };
                        return Json(ret);
                    }
                }
                else
                {
                    if (stock.UpdateEnterWarehouseBill(bill, listGoods, LoginAccountId, LoginStaffName, out strErrText))
                    {
                        var ret = new
                        {
                            EnterWarehouseBillNo = bill.BillNo,
                            ErrorText = string.Empty
                        };
                        return Json(ret);
                    }
                    else
                    {
                        var ret = new
                        {
                            EnterWarehouseBillNo = string.Empty,
                            ErrorText = strErrText
                        };
                        return Json(ret);
                    }
                }
            }
            return View(model);
        }