C#执行事务

public   int  Add()
        
{
            
int intReturn = -1;
            
if (this.GetPhsInfo(this.Terminal_No) == null)
            
{
                intReturn 
= -1;
            }

            
else
            
{
                SMS.Agent.AgentPhsNoInfo agent 
= this.GetPhsInfo(this.Terminal_No);
                
this.Agent_Code_One = agent.AgentCodeOne;
                
this.Agent_Code_Two = agent.AgentCodeTwo;
                
//更新终端号码的值
                if (agent.PhsNo == null)
                
{
                    
this.Terminal_Phs_No = "";
                }

                
else
                
{
                    
this.Terminal_Phs_No=agent.PhsNo;
                }

            }

            OracleConnection connection 
= new OracleConnection(SMS.DBUtility.OracleHelper.ConnectionString);
            connection.Open();
            OracleTransaction transaction 
= connection.BeginTransaction(IsolationLevel.ReadCommitted);
            OracleCommand oraCmd 
= new OracleCommand();
            
try
            
{

                
string strSqlAddDeduct = "Insert Into ter_phs_deduct_list(Agent_Key,Agent_Code_One,Agent_Code_Two,Terminal_Phs_No,Phs_No," +
                    
"Account_Money,Account_Date,Status,Send_Status,Memo,FormNo,Terminal_No) Values('" + this.Agent_Key + "'," +
                    
"'" + this.Agent_Code_One + "','" + this.Agent_Code_Two + "','" + this.Terminal_Phs_No + "'," +
                    
"'" + this.Phs_No + "','" + this.Account_Money + "',to_date('" + this.Account_Date.ToString() + "','yyyy-mm-dd hh24:mi:ss')," +
                    
"'" + this.Status + "','" + this.Send_Status + "','" + this.Memo + "','" + this.FormNo + "','" + this.Terminal_No + "')";

                
//对用户终端的可用金额 Account_Money 字段进行更新 
                string strUpdateMoney = "Update agent_phs_No Set Account_Money=Account_Money - " + this.Account_Money + " Where Terminal_No='" + this.Terminal_No + "'";

                oraCmd.Connection 
= connection;
                oraCmd.Transaction 
= transaction;

                oraCmd.CommandText 
= strSqlAddDeduct;
                oraCmd.ExecuteNonQuery();

                oraCmd.CommandText 
= strUpdateMoney;
                oraCmd.ExecuteNonQuery();

                transaction.Commit();

                intReturn 
= 1;
            }

            
catch(Exception ex)
            
{
                transaction.Rollback();
                connection.Close();
                connection.Dispose();
            }

            
finally
            
{
                transaction.Dispose();
                connection.Close();
                connection.Dispose();
            }


            
return intReturn;
        }
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值