Ejemplo n.º 1
0
        public bool UpdateEntity(Model.CommodityModel entity)
        {
            string sql = string.Format("update Commodity set Name='{0}',Type='{1}',Manufacturer='{2}',Inventory={3},UnitPrice={4},Unit='{5}' where ID={6}",
                                       entity.Name, entity.Type, entity.Manufacturer, entity.Inventory, entity.UnitPrice, entity.Unit, entity.ID);

            return(MSSqlHelper.ExecuteNonQuery(MSSqlHelper.ConStr, CommandType.Text, sql, null) > 0);
        }
Ejemplo n.º 2
0
        public List <Model.CommodityModel> GetEntities(string sqlWhere)
        {
            string sql = string.Format("select * from View_Commodity where 1=1 {0}", sqlWhere);
            List <Model.CommodityModel> listCommodities = new List <Model.CommodityModel>();

            //Using 限定对象使用的范围在花括号里面,出了花括号后释放资源
            using (SqlDataReader odr = MSSqlHelper.ExecuteReader(MSSqlHelper.ConStr, CommandType.Text, sql, null))
            {
                while (odr.Read())
                {
                    Model.CommodityModel commodity = new Model.CommodityModel();
                    commodity.ID           = odr.GetInt32(0);
                    commodity.Name         = odr.IsDBNull(1) ? "" : odr.GetString(1);
                    commodity.Type         = odr.IsDBNull(3) ? "" : odr.GetString(3);
                    commodity.Manufacturer = odr.IsDBNull(5) ? "" : odr.GetString(5);
                    commodity.Person       = odr.IsDBNull(6) ? "" : odr.GetString(6);
                    commodity.Telphone     = odr.IsDBNull(7) ? "" : odr.GetString(7);
                    commodity.Address      = odr.IsDBNull(8) ? "" : odr.GetString(8);
                    commodity.UnitPrice    = odr.IsDBNull(10) ? 0 : odr.GetDecimal(10);
                    commodity.Unit         = odr.IsDBNull(12) ? "" : odr.GetString(12);
                    listCommodities.Add(commodity);
                }
            }
            return(listCommodities);
        }
Ejemplo n.º 3
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));
        }
Ejemplo n.º 4
0
 public Model.CommodityModel AddCommodity(Model.CommodityModel oneCommodity)
 {
     if (string.IsNullOrWhiteSpace(oneCommodity.Name))
     {
         Exception oe = new Exception();
         throw new FaultException <Exception>(oe, "商品名称不能为空");
     }
     //return new OracleDAL.CommodityService().AddEntity(oneCommodity);
     return(dataFactory.CommdityDal.AddEntity(oneCommodity));
 }
Ejemplo n.º 5
0
        //先重新生成BLLService,再运行一下commodityBLLService,在浏览器查看然,确保已经创建服务后,再Ui更新服务(这样才能发现服务器端新增的方法)。
        private void buttonSave_Click(object sender, EventArgs e)
        {
            int     inventory = 0;
            decimal unitPrice = 0.0M;

            try
            {
                inventory = int.Parse(textBoxInventory.Text);
                unitPrice = decimal.Parse(textBoxUnitPrice.Text);
            }
            catch
            {
                MessageBox.Show("单价或者库存有误!");
            }
            Model.CommodityModel oneCommodity = new Model.CommodityModel();
            oneCommodity.Name         = textBoxName.Text;
            oneCommodity.Type         = textBoxType.Text;
            oneCommodity.Manufacturer = textBoxManufacturer.Text;
            oneCommodity.Unit         = textBoxUnit.Text;
            oneCommodity.Inventory    = inventory;
            oneCommodity.UnitPrice    = unitPrice;
            //整个应用程序使用一个对象
            BLLCommodity.CommodityManagerServiceClient client = WCFServiceBLL.GetCommodityService();
            try
            {
                if (isUpdate)
                {
                    //获取要更新数据的ID
                    oneCommodity.ID = SID;
                    if (!client.UpdateCommodity(oneCommodity))
                    {
                        MessageBox.Show("更新失败");
                        this.DialogResult = DialogResult.None;
                        return;
                    }
                }
                else
                {
                    if (client.AddCommodity(oneCommodity) == null)
                    {
                        MessageBox.Show("保存失败");
                        this.DialogResult = DialogResult.None;
                    }
                }
            }
            catch (FaultException <Exception> ex)
            {
                MessageBox.Show(ex.Message);
                this.DialogResult = DialogResult.None;
                //后面还会执行吗
            }
        }
Ejemplo n.º 6
0
        public Model.CommodityModel AddEntity(Model.CommodityModel entity)
        {
            entity.ID = GetNewID();
            string sql = string.Format(@"insert into Commodity(ID,Name,Type,Manufacturer,Inventory,UnitPrice,Unit) 
                                                    values({0},'{1}','{2}','{3}',{4},{5},'{6}')", entity.ID, entity.Name, entity.Type, entity.Manufacturer, entity.Inventory, entity.UnitPrice, entity.UnitPrice);

            if (MSSqlHelper.ExecuteNonQuery(MSSqlHelper.ConStr, CommandType.Text, sql, null) > 0)
            {
                return(entity);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 7
0
 private void AddCommodity_Load(object sender, EventArgs e)
 {
     if (isUpdate)
     {
         ICommodityManagerService client         = WCFServiceBLL.GetCommodityService();
         Model.CommodityModel     commodityModel = client.GetOneCommodity(SID);
         textBoxInventory.Text    = commodityModel.Inventory.ToString();
         textBoxManufacturer.Text = commodityModel.Manufacturer;
         textBoxName.Text         = commodityModel.Name;
         textBoxType.Text         = commodityModel.Type;
         textBoxUnit.Text         = commodityModel.Unit;
         textBoxUnitPrice.Text    = commodityModel.UnitPrice.ToString();
         buttonSave.Text          = "更新";
         this.Text = "修改产品";
     }
 }
Ejemplo n.º 8
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 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));
        }
Ejemplo n.º 9
0
        public List <Model.CommodityModel> GetEntities(string sqlWhere)
        {
            string sql = string.Format("select * from commodity where 1=1 {0}", sqlWhere);
            List <Model.CommodityModel> listCommodities = new List <Model.CommodityModel>();

            //Using 限定对象使用的范围在花括号里面,出了花括号后释放资源
            using (OracleDataReader odr = OracleHelper.ExecuteReader(OracleHelper.ConnectionString, CommandType.Text, sql, null))
            {
                while (odr.Read())
                {
                    Model.CommodityModel commodity = new Model.CommodityModel();
                    commodity.ID           = odr.GetInt32(0);
                    commodity.Name         = odr.IsDBNull(1) ? "" : odr.GetString(1);
                    commodity.Type         = odr.IsDBNull(2) ? "" : odr.GetString(2);
                    commodity.Manufacturer = odr.IsDBNull(3) ? "" : odr.GetString(3);
                    commodity.Inventory    = odr.IsDBNull(4) ? 0 : odr.GetInt32(4);
                    commodity.UnitPrice    = odr.IsDBNull(5) ? 0 : odr.GetDecimal(5);
                    commodity.Unit         = odr.IsDBNull(6) ? "" : odr.GetString(6);
                    listCommodities.Add(commodity);
                }
            }
            return(listCommodities);
        }
Ejemplo n.º 10
0
        private void buttonEditName_Click(object sender, EventArgs e)
        {
            SelectCommodity selectCommodityForm = new SelectCommodity();

            if (selectCommodityForm.ShowDialog() == DialogResult.OK)
            {
                SalesCommodityID = selectCommodityForm.SelectedCommodityID;
                if (SalesCommodityID < 1)
                {
                    MessageBox.Show("未选中商品!");
                    return;
                }
                BLLCommodity.CommodityManagerServiceClient client = WCFServiceBLL.GetCommodityService();
                Model.CommodityModel oneCommodity = client.GetOneCommodity(SalesCommodityID);
                textBoxName.Text       = oneCommodity.Name;
                textBoxPrice.Text      = oneCommodity.UnitPrice.ToString();
                labelManufacturer.Text = "[" + oneCommodity.Manufacturer + "]";
                labelPerson.Text       = "[" + oneCommodity.Person + "||" + oneCommodity.Telphone + "]";
                labelAddress.Text      = "[" + oneCommodity.Address;
                labelType.Text         = "[" + oneCommodity.Type + "]";
                labelUnit.Text         = "[" + oneCommodity.Unit + "]";
            }
        }