예제 #1
0
        public Model.CommodityModel[] GetCommodities(string name, string type, string manufacturer, string priceLow, string priceHigh)
        {
            string sqlWhere = "";

            if (!string.IsNullOrWhiteSpace(name))
            {
                sqlWhere += string.Format(" and Name like '%{0}%'", name);
            }
            if (!string.IsNullOrWhiteSpace(type))
            {
                sqlWhere += string.Format(" and Type like '%{0}%'", type);
            }
            if (!string.IsNullOrWhiteSpace(manufacturer))
            {
                sqlWhere += string.Format(" and Manufacturer like '%{0}%'", manufacturer);
            }
            if (!string.IsNullOrWhiteSpace(priceLow))
            {
                try
                {
                    decimal dPriceLow = decimal.Parse(priceLow);//调试一下,是否需要赋值
                    sqlWhere += string.Format(" and UnitPrice>={0}", dPriceLow);
                }
                catch
                {
                    Exception e = new Exception();
                    throw new FaultException <Exception>(e, "单价下限有误!");
                }
            }
            if (!string.IsNullOrWhiteSpace(priceHigh))
            {
                try
                {
                    decimal dPriceHigh = decimal.Parse(priceHigh);
                    sqlWhere += string.Format(" and UnitPrice<={0}", dPriceHigh);
                }
                catch
                {
                    Exception e = new Exception();
                    throw new FaultException <Exception>(e, "单价上限有误会!");
                }
            }
            ICommodityService commodityService = new OracleDAL.CommodityService();

            return(commodityService.GetCommodities(sqlWhere).ToArray());
        }
예제 #2
0
        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 OracleDAL.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.UpdateCommodity(oneCommodity);
            }
            oneOrder.Status = "已出库";
            IDAL.ISalesOrdersService salesOrderService = new OracleDAL.SalesOrderService();
            return(salesOrderService.UpdateSalesOrder(oneOrder));
        }