1
yhj
2024-07-24 5e5d945e91568b973faa27d8ab0bcef99fc4a6c5
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#region
 
using System;
using System.Data;
using CSFrameworkV5.Common;
using CSFrameworkV5.Core;
using CSFrameworkV5.Core.CodeGenerator;
using CSFrameworkV5.Interfaces;
using CSFrameworkV5.WCFContract;
 
#endregion
 
namespace CSFrameworkV5.WebRef
{
    public class WCF_DataDict : WCF_Base<IDataDictService>, IBridge_DataDict
    {
        private string _DBID;
        private Type _ORM;
        private string _TableName;
 
        public WCF_DataDict()
        {
            _DBID = Loginer.CurrentUser.DBID;
        }
 
        public WCF_DataDict(Type ORM)
            : this()
        {
            _ORM = ORM;
            _TableName = ORM_Tools.GetTableName(ORM);
            _DBID = Loginer.CurrentUser.DBID;
        }
 
        public WCF_DataDict(string tableName)
            : this()
        {
            _TableName = tableName;
            _DBID = Loginer.CurrentUser.DBID;
        }
 
        public WCF_DataDict(string tableName, string DBID)
            : this()
        {
            _TableName = tableName;
            _DBID = DBID;
        }
 
        private void AssertORM()
        {
            if (_ORM == null) throw new Exception("WCF_DATA_DICT:没有指定ORM模型!");
        }
 
        #region IBridge_DataDict Members
 
        public Type ORM
        {
            get => _ORM;
            set => _ORM = value;
        }
 
        public string TableName
        {
            get => _TableName;
            set => _TableName = value;
        }
 
        public string LastGeneratedKey { get; set; }
 
        public DataTable GetDataDictByTableName(string tableName)
        {
            return Excute(client =>
            {
                var loginTicket =
                    WebServiceSecurity.EncryptLoginer(Loginer.CurrentUser);
                var receivedData =
                    client.GetDataDictByDBTableName(loginTicket, tableName,
                        _DBID);
                return ZipTools.DecompressionDataSet(receivedData).Tables[0];
            });
        }
 
        public DataTable GetEmptyTable(string DBName, string tableName)
        {
            return Excute(client =>
            {
                var loginTicket =
                    WebServiceSecurity.EncryptLoginer(Loginer.CurrentUser);
                var receivedData =
                    client.GetEmptyTable(loginTicket, DBName, tableName);
                return ZipTools.DecompressionDataSet(receivedData).Tables[0];
            });
        }
 
        public DataTable GetDataByKey(string key)
        {
            AssertORM();
 
            return Excute(client =>
            {
                var loginTicket =
                    WebServiceSecurity.EncryptLoginer(Loginer.CurrentUser);
                var receivedData =
                    client.GetDataByKey(loginTicket, _ORM.FullName, key);
                return ZipTools.DecompressionDataSet(receivedData).Tables[0];
            });
        }
 
        public DataTable GetSummaryData()
        {
            return Excute(client =>
            {
                var loginTicket =
                    WebServiceSecurity.EncryptLoginer(Loginer.CurrentUser);
                byte[] receivedData;
                if (_ORM != null)
                    receivedData =
                        client.GetSummaryData(loginTicket, _ORM.FullName);
                else if (!string.IsNullOrEmpty(_TableName))
                    receivedData =
                        client.GetDataDictByDBTableName(loginTicket, _TableName,
                            _DBID);
                else
                    throw new Exception("WCF_DATA_DICT:没有指定ORM模型或资料表名!");
 
                return ZipTools.DecompressionDataSet(receivedData).Tables[0];
            });
        }
 
        public bool Update(DataSet data)
        {
            AssertORM();
 
            return Excute(client =>
            {
                var loginTicket =
                    WebServiceSecurity.EncryptLoginer(Loginer.CurrentUser);
                var bs = ZipTools.CompressionDataSet(data);
                return client.Update(loginTicket, bs, _ORM.FullName);
            });
        }
 
        public SaveResultEx UpdateEx(DataSet data)
        {
            AssertORM();
 
            return Excute(client =>
            {
                var loginTicket =
                    WebServiceSecurity.EncryptLoginer(Loginer.CurrentUser);
                var bs = ZipTools.CompressionDataSet(data);
                var rt = client.UpdateEx(loginTicket, bs, _ORM.FullName);
                return (SaveResultEx)ZipTools.DecompressionObject(rt);
            });
        }
 
        public bool Delete(string keyValue)
        {
            AssertORM();
 
            return Excute(client =>
            {
                var loginTicket =
                    WebServiceSecurity.EncryptLoginer(Loginer.CurrentUser);
                return client.Delete(loginTicket, keyValue, _ORM.FullName);
            });
        }
 
        public bool CheckNoExists(string keyValue)
        {
            AssertORM();
 
            return Excute(client =>
            {
                var loginTicket =
                    WebServiceSecurity.EncryptLoginer(Loginer.CurrentUser);
                return client.CheckNoExists(loginTicket, keyValue,
                    _ORM.FullName);
            });
        }
 
        public bool CheckNoExists(string keyFieldName, string keyValue)
        {
            AssertORM();
 
            return Excute(client =>
            {
                var loginTicket =
                    WebServiceSecurity.EncryptLoginer(Loginer.CurrentUser);
                return client.CheckNoExistsEx(loginTicket, keyFieldName,
                    keyValue, _ORM.FullName);
            });
        }
 
        public virtual DateTime GetServerTime()
        {
            return Excute<DateTime, ICommonService>(svc =>
            {
                var loginTicket = WebServiceSecurity.GetLoginTicket();
                return svc.GetServerTime(loginTicket);
            });
        }
 
        public DataTable GetLookupData()
        {
            return Excute(client =>
            {
                var loginTicket =
                    WebServiceSecurity.EncryptLoginer(Loginer.CurrentUser);
                byte[] receivedData;
 
                if (_ORM != null)
                    receivedData =
                        client.GetLookupDataByTableName(loginTicket,
                            _TableName);
                else if (!string.IsNullOrEmpty(_TableName))
                    receivedData =
                        client.GetLookupDataByDBTableName(loginTicket,
                            _TableName, _DBID);
                else
                    throw new Exception("WCF_DATA_DICT:没有指定ORM模型或资料表名!");
 
                return ZipTools.DecompressionDataSet(receivedData).Tables[0];
            });
        }
 
        public DataTable GetDataDictBySql(string SQL)
        {
            throw new NotImplementedException();
        }
 
        #endregion
    }
}