0

我正在尝试编写代码进行付款并更新状态。在下面的代码中,我已经完成了提交付款的逻辑,它工作正常,但我无法更新状态。状态是Item_Order表中的一列,付款后必须更新

我的代码是:

 delegate void PaymentDone();

    public void paySave()
    {
        SqlConnection conn1 = new SqlConnection();
        try
        {

            conn1.ConnectionString = " 
            server=.\\ms2k5;database=Info_Connect;Trusted_Connection=true";
            conn1.Open();

            SqlCommand insertPayment = new SqlCommand("Delegate_SP", conn1);
            insertPayment.CommandType = CommandType.StoredProcedure;



            string currentDate = DateTime.Today.ToString();

            if (Convert.ToDateTime(payDate.Text) >= Convert.ToDateTime(currentDate))
            {

                insertPayment.Parameters.Add("@reciptId", SqlDbType.VarChar);
                insertPayment.Parameters["@reciptId"].Value = fullfill.Text;

                insertPayment.Parameters.Add("@payDate", SqlDbType.DateTime);
                insertPayment.Parameters["@payDate"].Value =   
                Convert.ToDateTime(payDate.Text);

                insertPayment.Parameters.Add("@balPay", SqlDbType.Float);
                insertPayment.Parameters["@balPay"].Value = Convert.ToDouble(balace.Text) - Convert.ToDouble(amnt1.Text);

                insertPayment.Parameters.Add("@payDone", SqlDbType.Float);
                insertPayment.Parameters["@payDone"].Value =    
                Convert.ToDouble(amnt1.Text);

                insertPayment.Parameters.Add("@fullfillID_FK", SqlDbType.VarChar);
                insertPayment.Parameters["@fullfillID_FK"].Value = fullfill.Text;

                insertPayment.Parameters.Add("@clintID_FK", SqlDbType.Int);
                insertPayment.Parameters["@clintID_FK"].Value = 
                (clintId_FK.Text).ToString();

                insertPayment.Parameters.Add("@operation", SqlDbType.VarChar);
                insertPayment.Parameters["@operation"].Value = 3;

                insertPayment.ExecuteNonQuery();

            }
            else
            {
                MessageBox.Show("Payment Date Should be later than Full Order Date");
            }
        }
    }

    public void payUpdate()
    {
        SqlConnection conn1 = new SqlConnection();
        try
        {
            conn1.ConnectionString = " 
            server=.\\ms2k5;database=Info_Connect;Trusted_Connection=true";
            conn1.Open();

            SqlCommand insertStaus = new SqlCommand("Delegate_SP", conn1);
            insertStaus.CommandType = CommandType.StoredProcedure;

            insertStaus.Parameters.Add("@status", SqlDbType.VarChar);
            insertStaus.Parameters["@status"].Value = "RUNING";

           if (balace.Text.Equals("0"))
            {

            insertStaus.Parameters.Add("@status", SqlDbType.VarChar);
            insertStaus.Parameters["@status"].Value = "CLOSE";
            }
            else
            {
              insertStaus.Parameters.Add("@status", SqlDbType.VarChar);
             insertStaus.Parameters["@status"].Value = "RUNING";
            }

            MessageBox.Show("3");

            insertStaus.Parameters.Add("@operation", SqlDbType.VarChar);
            insertStaus.Parameters["@operation"].Value = 2;


            insertStaus.ExecuteNonQuery();
        }
    }

我的存储过程是

ALTER PROCEDURE [dbo].[Delegate_SP]
@reciptId varchar(50)=null,
@balPay float,
@payDone float=null,
@payDate datetime=null, 
@fullfillId_FK varchar(50)=null,
@clintId_FK int=null,
@status varchar(50)=null,
@operation int,
@fullfillId varchar(50)=null


 AS

BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

if @operation=3

BEGIN
UPDATE Recipt set balPay=@balPay where reciptId=@reciptId
 if @@rowcount=0

insert into Recipt(reciptId,balPay,payDone,payDate,fullfillId_FK,clintId_FK)values
               (@reciptId,@balPay,@payDone,@payDate,@fullfillId_FK,@clintId_FK)

 update Item_Full set totCost=(select balPay from Recipt) where fullfillId=@reciptId

 END
if @operation=2

 BEGIN
  UPDATE Item_Order set status=@status where orderId=@reciptId
END
END

问题是我tdsparser在方法中遇到异常payUpdate......该paySave方法工作正常

4

0 回答 0