CREATE PROCEDURE change_product @result varchar(50) output, @product_no varchar(50), @color varchar(50), @product_size varchar(50), @oldcolor varchar(50), @oldproduct_size varchar(50), @stockid int, @oldstockid int, @number int, @users varchar(50), @orderno varchar(50), @memo_product_inout_record text AS declare @stockname varchar(50) declare @oldstockname varchar(50) declare @color2 varchar(50) begin TRANSACTION declare @nror int set @nror=0 if @stockid>0 and @oldstockid>0 begin select @stockname=stockname from tbl_stockid where stockid=@stockid select top 1 @color2=color2 from tbl_productstore where product_no=@product_no and color=@color select @oldstockname=stockname from tbl_stockid where stockid=@oldstockid /*如果原订单库存为自备货*/ if @oldstockid=1 or @oldstockid=2 or @oldstockid=3 begin /*如果新订单库存为自备货*/ if @stockid=1 or @stockid=2 or @stockid=3 begin update tbl_productstore set number=number+@number,lock_number=lock_number-@number where product_no=@product_no and color=@oldcolor and product_size=@oldproduct_size and stockid=@oldstockid set @nror=@nror+@@error insert into tbl_product_inout_record (product_no,color,product_size,number2,stock,users,operation_type,operation,memo) values (@product_no,@oldcolor,@oldproduct_size,@number,@oldstockname,@orderno+'|'+@users,'入库','修改订单',@memo_product_inout_record) set @nror=@nror+@@error update tbl_productstore set number=number-@number,lock_number=lock_number+@number where product_no=@product_no and color=@color and product_size=@product_size and stockid=@stockid set @nror=@nror+@@error insert into tbl_product_inout_record (product_no,color,product_size,number2,stock,users,operation_type,operation,memo) values (@product_no,@color,@product_size,0-@number,@stockname,@orderno+'|'+@users,'出库','修改订单',@memo_product_inout_record) set @nror=@nror+@@error update tbl_trade set stockid=@stockid,color=@color,product_size=@product_size,color2=@color2 where orderno=@orderno set @nror=@nror+@@error end /*如果新订单库存为全国货或都银泰仓库*/ else if @stockid=4 or @stockid=5 begin update tbl_productstore set number=number+@number,lock_number=lock_number-@number where product_no=@product_no and color=@oldcolor and product_size=@oldproduct_size and stockid=@oldstockid set @nror=@nror+@@error insert into tbl_product_inout_record (product_no,color,product_size,number2,stock,users,operation_type,operation,memo) values (@product_no,@oldcolor,@oldproduct_size,@number,@oldstockname,@orderno+'|'+@users,'入库','修改订单',@memo_product_inout_record) set @nror=@nror+@@error update tbl_productstore set number=number-@number,lock_number=lock_number+@number where product_no=@product_no and color=@color and product_size=@product_size and stockid=@stockid set @nror=@nror+@@error update tbl_trade set stockid=@stockid,color=@color,product_size=@product_size,color2=@color2 where orderno=@orderno set @nror=@nror+@@error end end /*如果原来的库存标识为全国货或者银泰的*/ if @oldstockid=4 or @oldstockid=5 begin /*如果新的订单库存标识为自备货*/ if @stockid=1 or @stockid=2 or @stockid=3 begin update tbl_productstore set number=number+@number,lock_number=lock_number-@number where product_no=@product_no and color=@oldcolor and product_size=@oldproduct_size and stockid=@oldstockid set @nror=@nror+@@error update tbl_productstore set number=number-@number,lock_number=lock_number+@number where product_no=@product_no and color=@color and product_size=@product_size and stockid=@stockid set @nror=@nror+@@error insert into tbl_product_inout_record (product_no,color,product_size,number2,stock,users,operation_type,operation,memo) values (@product_no,@color,@product_size,0-@number,@stockname,@orderno+'|'+@users,'出库','修改订单',@memo_product_inout_record) set @nror=@nror+@@error update tbl_trade set stockid=@stockid,color=@color,product_size=@product_size,color2=@color2 where orderno=@orderno set @nror=@nror+@@error end /*如果新的订单库存标识为全国货*/ else if @stockid=4 or @stockid=5 begin update tbl_productstore set number=number+@number,lock_number=lock_number-@number where product_no=@product_no and color=@oldcolor and product_size=@oldproduct_size and stockid=@oldstockid set @nror=@nror+@@error update tbl_productstore set number=number-@number,lock_number=lock_number+@number where product_no=@product_no and color=@color and product_size=@product_size and stockid=@stockid set @nror=@nror+@@error update tbl_trade set stockid=@stockid,color=@color,product_size=@product_size,color2=@color2 where orderno=@orderno set @nror=@nror+@@error end end end if @nror<>0 begin set @result='失败' rollback transaction end else begin set @result='成功' commit transaction end GO
public string chang_product(string product_no,string color,string product_size,string oldcolor,string oldproduct_size,int stockid,int oldstockid,int number,string users,string orderno,string memo_product_inout_record) { con = new SqlConnection(shopcon); con.Open(); com = new SqlCommand("change_product", con); com.CommandType = CommandType.StoredProcedure; com.Parameters.Add("@product_no",product_no ); com.Parameters.Add("@color",color ); com.Parameters.Add("@product_size",product_size); com.Parameters.Add("@oldcolor", oldcolor); com.Parameters.Add("@oldproduct_size",oldproduct_size); com.Parameters.Add("@stockid",stockid ); com.Parameters.Add("@oldstockid",oldstockid ); com.Parameters.Add("@number",number ); com.Parameters.Add("@users",users ); com.Parameters.Add("@orderno",orderno ); com.Parameters.Add("@memo_product_inout_record",memo_product_inout_record); com.Parameters.Add(new SqlParameter("@result", SqlDbType.NVarChar, 30)); com.Parameters["@result"].Direction = ParameterDirection.Output; com.ExecuteNonQuery(); string result = com.Parameters["@result"].Value.ToString(); con.Close(); com.Dispose(); return result; }