zrg
2025-04-02 235ddcabc45bab8a8434c92e537f5c6183b7efb7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
 
/// <summary>
/// Common 的摘要说明
/// </summary>
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;
        }
    }
 
    /// <summary>
    /// SQL字符转换 去掉 特殊字符
    /// </summary>
    /// <returns></returns>
    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;
        }
    }
}