/// <summary> /// 转仓 /// </summary> /// <param name="warehouse_id1"></param> /// <param name="warehouse_id2"></param> /// <param name="list"></param> /// <param name="goods_amount"></param> public bool Transfer(int warehouse_id1, int warehouse_id2, List <string> list, int goods_amount) { double price; foreach (string item in list) { im = id.FindId(Int32.Parse(item))[0]; //根据ID准确查询 if (im.Goods_amount < goods_amount) //判断用户输入数量是否超出仓库所有数量 { return(false); } price = id.GetPrice(Int32.Parse(item)); //通过ID获取单价 Update(Int32.Parse(item), goods_amount, goods_amount * price); //把第一个仓库的数据减少 listi = id.FindId(im.Goods_id, warehouse_id2, im.Client_id); //根据查询出来的结果查询第二个仓库 if (listi.Count > 0) //如果第二个仓库有和第一个仓库一样的物品并且是一个客户 { im = listi[0]; id.Update(im, goods_amount, goods_amount * price); //把数据添加到第二个仓库 } else { im.Warehouse_id = warehouse_id2; //把第二个仓库的ID给im im.Goods_amount = goods_amount; //物品数量给IM im.Goods_total = goods_amount * price; //物品总价给im id.Insert(im); //添加到数据库 } } return(true); }
/// <summary> /// 修改库存 /// </summary> /// <param name="im"></param> /// <param name="Goods_amount"></param> /// <param name="Goods_total"></param> public void Update(InventoryMOD im, int Goods_amount, double Goods_total) { sql = "UPDATE Inventory SET goods_amount=goods_amount+@Goods_amount ,goods_total=goods_total+@Goods_total where id=@id"; SqlParameter[] sp = { new SqlParameter("@id", im.Id), new SqlParameter("@Goods_amount", Goods_amount), new SqlParameter("@Goods_total", Goods_total), }; DBHelper.ExecuteNonQuery(sql, sp); }
/// <summary> /// 插入库存 /// </summary> /// <param name="im"></param> public void Insert(InventoryMOD im) { sql = "INSERT INTO Inventory VALUES(@Warehouse_id,@Goods_id,@Client_id,@Goods_amount,@Goods_total)"; SqlParameter[] sp = { new SqlParameter("@Warehouse_id", im.Warehouse_id), new SqlParameter("@Goods_id", im.Goods_id), new SqlParameter("@Client_id", im.Client_id), new SqlParameter("@Goods_amount", im.Goods_amount), new SqlParameter("@Goods_total", im.Goods_total), }; DBHelper.ExecuteNonQuery(sql, sp); }
/// <summary> /// 获取list集合 /// </summary> /// <param name="sql"></param> /// <param name="sp"></param> /// <returns></returns> private List <InventoryMOD> GetList(string sql, params SqlParameter[] sp) //Dataset赋值给实体类集合 { ds = DBHelper.GetDataset(sql, sp); list.Clear(); foreach (DataRow rows in ds.Tables[0].Rows) { InventoryMOD im = new InventoryMOD(); im.Id = Int32.Parse(rows[0].ToString()); im.Warehouse_id = Int32.Parse(rows[1].ToString()); im.Goods_id = Int32.Parse(rows[2].ToString()); im.Client_id = Int32.Parse(rows[3].ToString()); im.Goods_amount = Int32.Parse(rows[4].ToString()); im.Goods_total = double.Parse(rows[5].ToString()); list.Add(im); } return(list); }
/// <summary> /// 修改库存 /// </summary> /// <param name="im"></param> /// <param name="Goods_amount"></param> /// <param name="Goods_total"></param> public void Update(InventoryMOD im, int Goods_amount, double Goods_total) { id.Update(im, Goods_amount, Goods_total); }
/// <summary> /// 插入库存 /// </summary> /// <param name="im"></param> public void Insert(InventoryMOD im) { id.Insert(im); }