VueWebApi/Tools/DapperHelper.cs
@@ -52,6 +52,11 @@
                    LogHelper.WriteLog(ex);
                    throw ex;
                }
                finally
                {
                    conn.Dispose();
                    conn.Close();
                }
                
            }
            return list;
@@ -81,6 +86,11 @@
                    LogHelper.WriteLog(ex);
                    throw ex;
                }
                finally
                {
                    conn.Dispose();
                    conn.Close();
                }
            }
            return result;
        }
@@ -108,6 +118,11 @@
                    LogHelper.WriteLog(ex);
                    throw ex;
                }
                finally
                {
                    conn.Dispose();
                    conn.Close();
                }
            }
            return t;
        }
@@ -124,14 +139,11 @@
        /// <returns></returns>
        public static IEnumerable<T> GetPageList<T>(string sql,Object parm, string orderBy,string sort, int pageIndex, int pageSize, out int total)
        {
            try
            {
                //int skip = 1;
                //if (pageIndex > 0)
                //{
                //    skip = (pageIndex - 1) * pageSize + 1;
                //}
                StringBuilder sb = new StringBuilder();
                sb.AppendFormat("SELECT COUNT(1) FROM ({0}) AS Result;", sql);
                sb.AppendFormat(@"SELECT *
@@ -142,11 +154,12 @@
                using (IDbConnection conn = sqlConnection())
                {
                try
                {
                    using (var reader = conn.QueryMultiple(sb.ToString(), parm))
                    {
                        total = reader.ReadFirst<int>();
                        return reader.Read<T>();
                    }
                }
            }
            catch (Exception ex)
@@ -155,7 +168,13 @@
                LogHelper.WriteLog(ex);
                throw ex;
            }
                finally
                {
                    conn.Dispose();
                    conn.Close();
                }
           
            }
        }
        /// <summary>
@@ -167,15 +186,14 @@
        public static DataTable selectdata(string sql, Object parm)
        {
            //sql语句
            try
            {
                using (IDbConnection conn = sqlConnection())
            {
                try
                {
                    DataTable table = new DataTable();
                    var data = conn.ExecuteReader(sql, parm);
                    table.Load(data);
                    return table;
                }
            }
            catch (Exception ex)
            {
@@ -183,7 +201,12 @@
                LogHelper.WriteLog(ex);
                throw ex;
            }
                finally
                {
                    conn.Dispose();
                    conn.Close();
                }
            }
        }
        /// <summary>
@@ -194,15 +217,14 @@
        public static DataTable selecttable(string sql)
        {
            //sql语句
            try
            {
                using (IDbConnection conn = sqlConnection())
            {
                try
                {
                    DataTable table = new DataTable();
                    var data = conn.ExecuteReader(sql);
                    table.Load(data);
                    return table;
                }
            }
            catch (Exception ex)
            {
@@ -210,7 +232,12 @@
                LogHelper.WriteLog(ex);
                throw ex;
            }
                finally
                {
                    conn.Dispose();
                    conn.Close();
                }
            }
        }
        /// <summary>
@@ -222,9 +249,9 @@
        public static DataTable selectProcedure(string sql, Object parm)
        {
            //sql语句
            try
            {
                using (IDbConnection conn = sqlConnection())
            {
                try
                {
                    DataTable table = new DataTable();
                    //var data = conn.ExecuteReader(sql, parm);
@@ -232,12 +259,17 @@
                    table.Load(res);
                    return table;
                }
            }
            catch (Exception ex)
            {
                //创建日志记录组件实例
                LogHelper.WriteLog(ex);
                throw ex;
                }
                finally
                {
                    conn.Dispose();
                    conn.Close();
                }
            }
        }
@@ -252,19 +284,24 @@
        {
            //sql语句
            int result = 0;
            try
            {
                using (IDbConnection conn = sqlConnection())
                {
                try
                {
                    result = conn.Query(sql, parm).Count();
                }
                return result;
            }
            catch (Exception ex)
            {
                //创建日志记录组件实例
                LogHelper.WriteLog(ex);
                throw ex;
                }
                finally
                {
                    conn.Dispose();
                    conn.Close();
                }
                return result;
            }
        }
@@ -278,13 +315,11 @@
        {
            //sql语句
            int result = 0;
            try
            {
                using (IDbConnection conn = sqlConnection())
                {
                try
                {
                    result = conn.Execute(sql, parametere);
                }
                return result;
            }
            catch (Exception ex)
            {
@@ -292,6 +327,13 @@
                LogHelper.WriteLog(ex);
                throw ex;
            }   
                finally
                {
                    conn.Dispose();
                    conn.Close();
                }
            }
            return result;
        }
        /// <summary>
@@ -323,6 +365,11 @@
                    tranction.Rollback();
                    throw ex;
                }
                finally
                {
                    conn.Dispose();
                    conn.Close();
                }
                return result;
            }
        }
@@ -339,9 +386,9 @@
        {
            int result = 0;
            try
            {
                using (IDbConnection conn = sqlConnection())
            {
                try
                {
                    result = conn.Execute(sql, parameter);
                    if (result != 0)
@@ -349,14 +396,19 @@
                        result = conn.Query<int>("select ident_current(@table)", new { table = tableName }).Single<int>();
                    }
                }
                return result;
            }
            catch (Exception ex)
            { 
                //创建日志记录组件实例
                LogHelper.WriteLog(ex);
                throw ex;
            }
                finally
                {
                    conn.Dispose();
                    conn.Close();
                }
            }
            return result;
        }
    }
}