| | |
| | | LogHelper.WriteLog(ex); |
| | | throw ex; |
| | | } |
| | | finally |
| | | { |
| | | conn.Dispose(); |
| | | conn.Close(); |
| | | } |
| | | |
| | | } |
| | | return list; |
| | |
| | | LogHelper.WriteLog(ex); |
| | | throw ex; |
| | | } |
| | | finally |
| | | { |
| | | conn.Dispose(); |
| | | conn.Close(); |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | |
| | | LogHelper.WriteLog(ex); |
| | | throw ex; |
| | | } |
| | | finally |
| | | { |
| | | conn.Dispose(); |
| | | conn.Close(); |
| | | } |
| | | } |
| | | return t; |
| | | } |
| | |
| | | /// <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 * |
| | |
| | | |
| | | using (IDbConnection conn = sqlConnection()) |
| | | { |
| | | try |
| | | { |
| | | using (var reader = conn.QueryMultiple(sb.ToString(), parm)) |
| | | { |
| | | total = reader.ReadFirst<int>(); |
| | | return reader.Read<T>(); |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | |
| | | LogHelper.WriteLog(ex); |
| | | throw ex; |
| | | } |
| | | finally |
| | | { |
| | | conn.Dispose(); |
| | | conn.Close(); |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | 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) |
| | | { |
| | |
| | | LogHelper.WriteLog(ex); |
| | | throw ex; |
| | | } |
| | | |
| | | finally |
| | | { |
| | | conn.Dispose(); |
| | | conn.Close(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | 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) |
| | | { |
| | |
| | | LogHelper.WriteLog(ex); |
| | | throw ex; |
| | | } |
| | | |
| | | finally |
| | | { |
| | | conn.Dispose(); |
| | | conn.Close(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | 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); |
| | |
| | | table.Load(res); |
| | | return table; |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | //创建日志记录组件实例 |
| | | LogHelper.WriteLog(ex); |
| | | throw ex; |
| | | } |
| | | finally |
| | | { |
| | | conn.Dispose(); |
| | | conn.Close(); |
| | | } |
| | | } |
| | | |
| | | } |
| | |
| | | { |
| | | //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; |
| | | } |
| | | } |
| | | |
| | |
| | | { |
| | | //sql语句 |
| | | int result = 0; |
| | | try |
| | | { |
| | | using (IDbConnection conn = sqlConnection()) |
| | | { |
| | | try |
| | | { |
| | | result = conn.Execute(sql, parametere); |
| | | } |
| | | return result; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | |
| | | LogHelper.WriteLog(ex); |
| | | throw ex; |
| | | } |
| | | finally |
| | | { |
| | | conn.Dispose(); |
| | | conn.Close(); |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | tranction.Rollback(); |
| | | throw ex; |
| | | } |
| | | finally |
| | | { |
| | | conn.Dispose(); |
| | | conn.Close(); |
| | | } |
| | | return result; |
| | | } |
| | | } |
| | |
| | | { |
| | | |
| | | int result = 0; |
| | | try |
| | | { |
| | | using (IDbConnection conn = sqlConnection()) |
| | | { |
| | | try |
| | | { |
| | | result = conn.Execute(sql, parameter); |
| | | if (result != 0) |
| | |
| | | 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; |
| | | } |
| | | } |
| | | } |