• 【数据操作】同一数据库内事务操作的封装


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


  • 相关阅读:
    Hibernate总结(二)---hibernate中的各种映射
    调度子系统7_负载均衡(四)
    (网络层: 二 ) 网络层提供的服务(基于无连接的服务)
    我的2013——一名计算机教师的高开低走
    文艺小青年
    图解RabbitMQ
    解决Mac下idea运行速度慢
    较主流的消息队列的比较与选型
    Ubuntu下RabbitMQ安装
    linux守护进程与&的区别
  • 原文地址:https://www.cnblogs.com/a311300/p/1527441.html
Copyright © 2020-2023  润新知