저장 프로세스 (스크롤 +if 문장 + 되돌아오는 매개 변수 + 클래스 수신 매개 변수) 실례

7880 단어 저장 프로세스

  
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;
 
    }

좋은 웹페이지 즐겨찾기