Using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
namespace DBUtility
{
public enum EffentNextType
{
/// <summary>
/// 对其他语句无任何影响
/// </summary>
None,
/// <summary>
/// 当前语句必须为"select count(1) from .."格式,如果存在则继续执行,不存在回滚事务
/// </summary>
WhenHaveContine,
/// <summary>
/// 当前语句必须为"select count(1) from .."格式,如果不存在则继续执行,存在回滚事务
/// </summary>
WhenNoHaveContine,
/// <summary>
/// 当前语句影响到的行数必须大于0,否则回滚事务
/// </summary>
ExcuteEffectRows,
/// <summary>
/// 引发事件-当前语句必须为"select count(1) from .."格式,如果不存在则继续执行,存在回滚事务
/// </summary>
SolicitationEvent
}
public class CommandInfo
{
public object ShareObject = null;
public object OriginalData = null;
event EventHandler _solicitationEvent;
public event EventHandler SolicitationEvent
{
add
{
_solicitationEvent += value;
}
remove
{
_solicitationEvent -= value;
}
}
public void OnSolicitationEvent()
{
if (_solicitationEvent != null)
{
_solicitationEvent(this,new EventArgs());
}
}
public string CommandText;
public System.Data.Common.DbParameter[] Parameters;
public EffentNextType EffentNextType = EffentNextType.None;
public CommandInfo()
{
}
public CommandInfo(string sqlText, SqlParameter[] para)
{
this.CommandText = sqlText;
this.Parameters = para;
}
public CommandInfo(string sqlText, SqlParameter[] para, EffentNextType type)
{
this.CommandText = sqlText;
this.Parameters = para;
this.EffentNextType = type;
}
}
}
---------------------------------------------------------------------------------
调用:
List<CommandInfo> list = new List<CommandInfo>();
CommandInfo cmd = new CommandInfo();
string strSql = "insert into PPC_Man_400Tels (ManGuid,BizCode,SubCode,ManID,Status,Type) values (@ManGuid,@BizCode,@SubCode,@ManID," + status + "," + type + ")";
SqlParameter[] ps = new SqlParameter[]{
new SqlParameter("@ManID",SqlDbType.Int),
new SqlParameter("@ManGuid",SqlDbType.VarChar),
new SqlParameter("@BizCode",SqlDbType.VarChar,50),
new SqlParameter("@SubCode",SqlDbType.VarChar,50)};
ps[0].Value = mid;
ps[1].Value = ManID;
ps[2].Value = bizCode;
ps[3].Value = subCode;
string strSql1 = "update sys_V4007Code set Status=@Status where (BizCode=@BizCode and Code=@SubCode)";
SqlParameter[] paras1 = new SqlParameter[] {
new SqlParameter("@BizCode",SqlDbType.VarChar),
new SqlParameter("@SubCode",SqlDbType.VarChar),
new SqlParameter("@Status",SqlDbType.SmallInt)};
paras1[0].Value = bizCode;
paras1[1].Value = subCode;
paras1[2].Value = 0;
cmd = new CommandInfo(strSql1.ToString(), paras1);
list.Add(cmd);
cmd = new CommandInfo(strSql.ToString(), ps);
list.Add(cmd);
DbHelperSQL.ExecuteSqlTran(list);