Beispiel #1
0
        //几个ID要分清楚
        public bool PostPurchaseOrder(int id)
        {
            Model.PurchaseOrdersModel oneOrder = GetOnePurchaseOrder(id);
            if (oneOrder.Status.Equals("已入库"))
            {
                Exception oe = new Exception();
                throw new FaultException <Exception>(oe, "订单已经提交,请务重复提交");
            }
            List <Model.PurchaseCommodityModel> purchaseCommoditiesList = GetPurchaseCommoditiesByID(id).ToList();

            IDAL.ICommodityService commodityService = new MSSQLDAL.CommodityService();
            foreach (Model.PurchaseCommodityModel onePurchaseCommodity in purchaseCommoditiesList)
            {
                Model.CommodityModel commodityModel = new Model.CommodityModel();
                commodityModel.ID           = onePurchaseCommodity.CommodityID;
                commodityModel.Manufacturer = onePurchaseCommodity.CommodityManufacturer;
                commodityModel.Name         = onePurchaseCommodity.CommodityName;
                commodityModel.Type         = onePurchaseCommodity.CommodityType;
                commodityModel.Unit         = onePurchaseCommodity.CommodityUnit;
                commodityModel.UnitPrice    = onePurchaseCommodity.CommodityUnitPrice;
                commodityModel.Inventory    = onePurchaseCommodity.CommodityInventory + onePurchaseCommodity.Count;
                //这儿不会出现异常了吧,否则要回滚
                commodityService.UpdateEntity(commodityModel);
            }
            oneOrder.Status = "已入库";
            return(new MSSQLDAL.PurchaseOrderService().UpdateEntity(oneOrder));
        }
        public bool PostSalesOrder(int id)
        {
            Model.SalesOrdersModel oneOrder = GetOneSalesOrder(id);
            if (oneOrder.Status.Equals("已出库"))
            {
                Exception oe = new Exception();
                throw new FaultException <Exception>(oe, "订单已出库");
            }
            List <Model.SalesCommodityModel> salesCommoditiesList = GetSalesCommoditiesByID(id).ToList();
            List <Model.SalesCommodityModel> errorList            = salesCommoditiesList.Where(u => u.CommodityInventory < u.Count).ToList();

            //简单处理回滚,因为一条不成功,所有记录操作所有被回滚
            //这儿确保安全无误后对库存进行更新
            if (errorList.Count > 0)
            {
                Exception oe      = new Exception();
                string    message = "提交失败!\r\n";
                foreach (Model.SalesCommodityModel oneErrorSalesCommodity in errorList)
                {
                    message += string.Format("{0}的当前库存({1})小于订单的数量({2})!\r\n", oneErrorSalesCommodity.CommodityName, oneErrorSalesCommodity.CommodityInventory, oneErrorSalesCommodity.Count);
                }
                throw new FaultException <Exception>(oe, message);
            }
            IDAL.ICommodityService commodityService = new MSSQLDAL.CommodityService();
            foreach (Model.SalesCommodityModel oneSalesCommodity in salesCommoditiesList)
            {
                Model.CommodityModel oneCommodity = new Model.CommodityModel();
                oneCommodity.ID           = oneSalesCommodity.CommodityID;
                oneCommodity.Name         = oneSalesCommodity.CommodityName;
                oneCommodity.Type         = oneSalesCommodity.CommodityType;
                oneCommodity.Manufacturer = oneSalesCommodity.CommodityManufacturer;
                oneCommodity.Unit         = oneSalesCommodity.CommodityUnit;
                oneCommodity.UnitPrice    = oneSalesCommodity.CommodityUnitPrice;
                oneCommodity.Inventory    = oneSalesCommodity.CommodityInventory - oneSalesCommodity.Count;

                commodityService.AddEntity(oneCommodity);
            }
            oneOrder.Status = "已出库";
            IDAL.ISalesOrdersService salesOrderService = new MSSQLDAL.SalesOrderService();
            //return salesOrderService.UpdateEntity(oneOrder);
            return(dataFactory.SalesOrderDal.UpdateEntity(oneOrder));
        }