using Newtonsoft.Json; using Newtonsoft.Json.Converters; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Web; /// /// Common 的摘要说明 /// public class Common { public Common() { // // TODO: 在此处添加构造函数逻辑 // } public static string DataTableToJSON(DataTable dt) { try { string rowsjson = JsonConvert.SerializeObject(dt, new DataTableConverter()); string json = @"{""Rows"":" + rowsjson + @",""Total"":""" + dt.Rows.Count.ToString() + @"""}"; return json; } catch (Exception err) { return "{Rows:[],Total:0}"; } } public static string DataTableToJSON(DataTable dt,Int64 HRows) { try { string rowsjson = JsonConvert.SerializeObject(dt, new DataTableConverter()); string json = @"{""Rows"":" + rowsjson + @",""Total"":""" + HRows.ToString() + @"""}"; return json; } catch (Exception err) { return "{Rows:[],Total:0}"; } } public static Int64 GetRowTotal(string ViewName,string sWhere,ref string sErr) { SQLHelper.ClsCN oCn = new SQLHelper.ClsCN(); DataSet dsTotal; try { Int64 RowTotal = 0; dsTotal = oCn.RunProcReturn("select count(1) HRows from " + ViewName + " " + sWhere + " ", "gy_czygl"); if (dsTotal == null || dsTotal.Tables[0].Rows.Count == 0) { RowTotal = 0; } else { RowTotal = DBUtility.ClsPub.isLong(dsTotal.Tables[0].Rows[0][0]); } return RowTotal; } catch (Exception err) { sErr = err.Message; return 0; } } /// /// SQL字符转换 去掉 特殊字符 /// /// public static bool SQLtoChange(string OldSQL,ref string ViewSQL,ref string ProcSQL) { try { ViewSQL = OldSQL.Replace("^^", "'"); ViewSQL = ViewSQL.Replace("^*", "%"); /////////////////////////// ProcSQL = OldSQL.Replace("^^", "''"); ProcSQL = ProcSQL.Replace("^*", "%"); return true; } catch (Exception e) { return false; } } public static string GetSession() { try { string s = System.Web.HttpContext.Current.Session["HUserName"].ToString(); return s; } catch (Exception e) { return e.Message; } } public static bool HasSession() { try { string s = System.Web.HttpContext.Current.Session["HUserName"].ToString(); if (s.Trim().Length == 0) { return false; } else { return true; } } catch (Exception e) { return false; } } }