| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 | using SqlSugar;using System;using System.Configuration;using System.Data.SqlClient;using System.Runtime.InteropServices;namespace WCS_Client{    public class SugarClient    {        internal static string _connectionString = ConfigurationManager.ConnectionStrings["OracleDatabase"].ConnectionString;        //创建sqlserver连接对象          public static SqlConnection GetConnection()        {            var connection = new SqlConnection(_connectionString);            connection.Open();            return connection;        }        public static SqlSugarClient GetInstance()        {            var db = new SqlSugarClient(new ConnectionConfig()            {                ConnectionString = _connectionString,                DbType = SqlSugar.DbType.SqlServer,                IsAutoCloseConnection = true,//开启自动释放模式和EF原理一样我就不多解释了                //InitKey默认SystemTable            });            db.Aop.OnLogExecuting = (sql, pars) =>            {                string result = sql + "\r\n";// + db.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value));                LogHelper.Sys_Log.WriteLog(result);            };            return db;        }        #region 分页适用sqlserver数据库        //public static PageData GetPageData<T>(List<string> WhereStringList, string orderText, int PageIndex, int PageSize)        //{        //    var sb = new StringBuilder();        //    string tableName = typeof(T).Name;        //    sb.Append(string.Format("select * from {0} where 1=1 ", tableName));        //    if (WhereStringList != null && WhereStringList.Count > 0)        //    {        //        sb.Append(" and ");        //        sb.Append(WhereStringList[0]);        //    }        //    return QueryPageSql(sb.ToString(), orderText, PageIndex, PageSize);        //}        //public static PageData GetPageData(string _SQLText, string orderText, List<string> WhereStringList, int PageIndex, int PageSize)        //{        //    var sb = new StringBuilder();        //    sb.Append(_SQLText);        //    if (WhereStringList != null && WhereStringList.Count > 0)        //    {        //        sb.Append(" and ");        //        sb.Append(WhereStringList[0]);        //    }        //    return QueryPageSql(sb.ToString(), orderText, PageIndex, PageSize);        //}        //private static PageData QueryPageSql(string SQLText, string OrderText, int PageIndex, int PageSize)        //{        //    if (PageSize <= 0) PageSize = 2000;        //    int startRecord = (PageIndex - 1) * PageSize + 1;        //    int endRecord = startRecord + PageSize - 1;        //    string sql = string.Format("select * from (select ROW_NUMBER() Over (Order By {0}) as RN,a.* from ({1}) a) b where  b.RN between {2} and {3}", OrderText, SQLText, startRecord, endRecord);        //    string CountStr = string.Format("Select Count(1) From ({0})  t", SQLText);        //    SqlSugarClient db = null;        //    try        //    {        //        db = GetInstance();        //        //WriteDebugFormat("查询sql:" + sql, "");                        //        DataTable dt = db.Ado.GetDataTable(sql);                        //        //WriteInfoFormat(dt.Rows[0]["Task_AddDateTime"].ToString(),string.Empty);        //        int count = Convert.ToInt32(db.Ado.GetScalar(CountStr));        //        int PageCount = count / PageSize;        //        if (count % PageSize > 0)        //            PageCount += 1;        //        if (dt != null && dt.Rows.Count > 0)        //        {        //            PageData PageDataItem = new PageData();        //            PageDataItem.PageIndex = PageIndex;        //            PageDataItem.PageSize = PageSize;        //            PageDataItem.PageCount = PageCount;        //            PageDataItem.RowsCount = count;        //            dt.TableName = "table";        //            PageDataItem.Dt = dt;        //            return PageDataItem;        //        }        //    }        //    catch (Exception ex)        //    {        //        MessageUtil.ShowError(ex.ToString());        //    }        //    finally        //    {        //        if (db != null) ((IDisposable)db).Dispose();        //    }        //    return null;        //}        #endregion;    }    public class CommHelper    {        #region 内存回收        [DllImport("kernel32.dll", EntryPoint = "SetProcessWorkingSetSize")]        public static extern int SetProcessWorkingSetSize(IntPtr process, int minSize, int maxSize);        /// <summary>        /// 释放内存        /// </summary>        public static void ClearMemory()        {            GC.Collect();            GC.WaitForPendingFinalizers();            if (Environment.OSVersion.Platform == PlatformID.Win32NT)            {                SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1);            }        }        #endregion    }    //public class PageData    //{    //    int _PageIndex = 0;    //    /// <summary>    //    /// 页码    //    /// </summary>    //    public int PageIndex    //    {    //        get    //        {    //            return _PageIndex;    //        }    //        set    //        {    //            _PageIndex = value;    //        }    //    }    //    int _PageSize = 0;    //    /// <summary>    //    /// 分页尺寸    //    /// </summary>    //    public int PageSize    //    {    //        get    //        {    //            return _PageSize;    //        }    //        set    //        {    //            _PageSize = value;    //        }    //    }    //    int _PageCount = 0;    //    /// <summary>    //    /// 总页数    //    /// </summary>    //    public int PageCount    //    {    //        get    //        {    //            return _PageCount;    //        }    //        set    //        {    //            _PageCount = value;    //        }    //    }    //    int _RowsCount = 0;    //    /// <summary>    //    /// 总记录数    //    /// </summary>    //    public int RowsCount    //    {    //        get    //        {    //            return _RowsCount;    //        }    //        set    //        {    //            _RowsCount = value;    //        }    //    }    //    string _DisplayText = "";    //    /// <summary>    //    /// 其他汇总数据文本    //    /// </summary>    //    public string DisplayText    //    {    //        get    //        {    //            return _DisplayText;    //        }    //        set    //        {    //            _DisplayText = value;    //        }    //    }    //    DataTable _Dt = null;    //    /// <summary>    //    /// 分页数据    //    /// </summary>    //    public DataTable Dt    //    {    //        get    //        {    //            return _Dt;    //        }    //        set    //        {    //            _Dt = value;    //        }    //    }    //}}
 |