yzh
2021-09-30 1a81b518e0edd87a310a5b477773657e23d49cbd
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
<%@ WebHandler Language="C#" Class="GwProductHandler" %>
 
using Common;
using Dao;
using Model;
using Newtonsoft.Json;
using System;
using System.Web;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
 
public class GwProductHandler : PageHandler<SysUser>
{
    private GwProductDao _Dao = new GwProductDao();
    private SysXhDao sysXhDao = new SysXhDao();
    private List<GwOp> _OpList;
    private List<GwOpGroup> _GwOpGroupList;
    private List<SysXh> _SysXhList;
    private List<GwProduct> _GwProductClassList;    //产品分类列表
 
    private List<GwOp> OpList
    {
        get
        {
            if (this._OpList == null)
            {
                using (GwOpDao gwOpDao = new GwOpDao())
                    this._OpList = gwOpDao.LoadInfoList();
            }
            return this._OpList;
        }
    }
 
    //获取产品分类列表
    private List<GwProduct> GwProductClassList
    {
        get
        {
            if (this._GwProductClassList == null)
            {
                using (GwProductDao gwProductDao = new GwProductDao())
                    this._GwProductClassList = gwProductDao.getGwProductClassList();
            }
            return this._GwProductClassList;
        }
    }
 
    //获取通道组列表
    private List<GwOpGroup> GwOpGroupList
    {
        get
        {
            if (this._GwOpGroupList == null)
            {
                using (GwOpGroupDao gwOpGroupDao = new GwOpGroupDao())
                    this._GwOpGroupList = gwOpGroupDao.GetGroupList();
            }
            return this._GwOpGroupList;
        }
    }
 
    //获取序号规则列表
    private List<SysXh> SysXhList
    {
        get
        {
            if (this._SysXhList == null)
            {
                using (SysXhDao sysXhDao = new SysXhDao())
                    this._SysXhList = sysXhDao.GetSysXhList();
            }
            return this._SysXhList;
        }
    }
 
 
    public override JsonPageResult ProcessRequestInternal(PageContext<SysUser> context)
    {
        string @string = context.GetString("action");
        switch (@string)
        {
 
            case "LoadGwProductPageList":
                return this.LoadGwProductPageList(context);
            case "getGwProduct":
                return this.GetGwProduct(context);
            case "delete":
                return this.Delete(context);
            case "add":
                return this.Add(context);
            case "update":
                return this.Update(context);
            case "updateIs_enable":
                return this.UpdateIs_enable(context);
 
            case "getGwspDetailed":
                return this.GetGwspDetailed(context);
            default:
                throw new Exception("Invalid Action=" + @string);
        }
    }
 
 
    private JsonPageResult GetGwspDetailed(PageContext<SysUser> context)
    {
        string @string = context.GetString("spID");
        if (string.IsNullOrEmpty(@string))
            throw new ArgumentException("获取SPID错误");
        using (GwSpDao gwSpDao = new GwSpDao())
        {
            GwSp gwSp = gwSpDao.Get(@string);
            string[] strArray = gwSp.McExpression.Split(new char[1]
            {
        ';'
            }, StringSplitOptions.RemoveEmptyEntries);
            string str = (Convert.ToInt32(strArray[0]) != 0 ? strArray[0] + "条/1分钟;" : "") + (Convert.ToInt32(strArray[1]) != 0 ? strArray[1] + "条/5分钟;" : "") + (Convert.ToInt32(strArray[2]) != 0 ? strArray[2] + "条/10分钟;" : "") + (Convert.ToInt32(strArray[3]) != 0 ? strArray[3] + "条/半小时;" : "") + (Convert.ToInt32(strArray[4]) != 0 ? strArray[4] + "条/1小时;" : "") + (Convert.ToInt32(strArray[5]) != 0 ? strArray[5] + "条/4小时;" : "") + (Convert.ToInt32(strArray[6]) != 0 ? strArray[6] + "条/6小时;" : "") + (Convert.ToInt32(strArray[7]) != 0 ? strArray[7] + "条/12小时;" : "") + (Convert.ToInt32(strArray[8]) != 0 ? strArray[8] + "条/24小时;" : "");
            return new JsonPageResult(true, (object)new
            {
                Get = gwSp,
                McExpression = str
            });
        }
    }
 
    /// <summary>
    /// 加载产品页面列表
    /// </summary>
    /// <param name="context"></param>
    /// <returns></returns>
    private JsonPageResult LoadGwProductPageList(PageContext<SysUser> context)
    {
        string name = context.GetString("name");
        string classes = context.GetString("classes");
        string is_default = context.GetString("is_default");
        string op_group_id = context.GetString("op_group_id")=="0" ? "": context.GetString("op_group_id");
        int recordCount = 0;
        int pageSize = context.GetInt("pageSize", 20);
        int pageIndex = context.GetInt("pageIndex", 1);
 
        GwProductDao gwProductDao = new GwProductDao();
 
        //加载产品列表信息
        List<GwProduct> list = gwProductDao.LoadInfoList(name, classes, is_default, op_group_id, pageIndex, pageSize, out recordCount);
        string str1 = "";
        if (list != null && list.Count > 0)
        {
            foreach (GwProduct gwProduct in list)
            {
                str1 = str1 + "<tr><td  rowspan=\"1\" ><input type=\"checkbox\"name=\"checkbox\" value=\"" + gwProduct.id + "\"/></td><td rowspan=\"1\">" + gwProduct.name ;
                str1 += "</td>";
                str1 = str1 + "<td>" + "<img src=\'" + gwProduct.icon + "' />" ;
                str1 += "</td>";
                str1 = str1 + "<td>" + gwProduct.instructions ;
                str1 += "</td>";
                str1 = str1 + "<td>" + classesToName(gwProduct.classes) ;
                str1 += "</td>";
                str1 = str1 + "<td>" + this.gwProductClassToName(gwProduct.parent_id) ;
                str1 += "</td>";
                //str1 = str1 + "<td>" + gwProduct.path ;
                //str1 += "</td>";
                str1 = str1 + "<td>" + isDefaultToName(gwProduct.is_default) ;
                str1 += "</td>";
                //str1 = str1 + "<td>" + isEnableToName(gwProduct.is_enable) ;
                str1 = str1 + "<td>" + GetStatusText(gwProduct.is_enable, gwProduct.id) ;
                str1 += "</td>";
                str1 = str1 + "<td>" + gwProduct.sort ;
                str1 += "</td>";
                str1 = str1 + "<td>" + this.opGroupIdToName(gwProduct.op_group_id) ;
                str1 += "</td>";
                str1 = str1 + "<td>" + this.apiSpXhIdToName(gwProduct.api_sp_xh_id) ;
                str1 += "</td>";
                str1 = str1 + "<td>" + gwProduct.giving_num ;
                str1 += "</td>";
                str1 = str1 + "<td>" + gwProduct.remark ;
                str1 += "</td>";
                str1 += "<td rowspan=\"1\" class=\"text-right\">";
                if (context.HasRight("3023"))
                    str1 += string.Format(" <a class=\"btn-block btn btn-primary btn-xs action-modal-edit\" data-id=\"{0}\"><i class=\"fa fa-edit\"></i>  编辑</a>", (object)gwProduct.id);
                if (context.HasRight("3024"))
                    str1 += string.Format(" <a class=\"btn-block btn btn-xs btn-default action-delete\"  data-id=\"{0}\"><i class=\"fa fa-trash\"></i> 删除</a>", (object)gwProduct.id);
                str1 += "</td>";
                str1 += "</tr>";
            }
        }
        else
            str1 += "<tr><td colspan=\"14\" style=\"padding-left:5px; text-align: center;\">暂无信息</td></tr>";
        return new JsonPageResult(true, (object)new
        {
            Table = str1.ToString(),
            TotalCount = recordCount
        });
    }
 
    //根据产品ID获取产品信息
    private JsonPageResult GetGwProduct(PageContext<SysUser> context)
    {
        return new JsonPageResult(true, this._Dao.find(context.GetString("id")));
    }
 
    //产品类别转换名称
    private string classesToName(int classes)
    {
        string str = "";
        switch (classes)
        {
            case 0:
                str = "产品分类";
                break;
            case 1:
                str = "产品";
                break;
        }
        return str;
    }
 
    //产品ID转换名称
    public string gwProductClassToName(string gwProductId)
    {
 
        if (this.GwProductClassList == null)
            return string.Empty;
        GwProduct newGwProduct = this.GwProductClassList.Find((Predicate<GwProduct>)(gwProduct => gwProduct.id == gwProductId));
        if (newGwProduct != null)
            return string.Format("{0}<div class=\"text-muted\">{1}</div>", (object)newGwProduct.id, (object)newGwProduct.name);
 
        return string.Format("{0}", (object)gwProductId);
 
    }
 
    //是否默认转换名称
    private string isDefaultToName(int isDefault)
    {
        string str = "";
        switch (isDefault)
        {
            case 0:
                str = "否";
                break;
            case 1:
                str = "是";
                break;
        }
        return str;
    }
 
    //是否启用转换名称
    private string isEnableToName(int isDefault)
    {
        string str = "";
        switch (isDefault)
        {
            case 0:
                str = "停用";
                break;
            case 1:
                str = "启用";
                break;
        }
        return str;
    }
 
    //通道组转换名称
    public string opGroupIdToName(int opGroupId)
    {
 
        if (this.GwOpGroupList == null)
            return string.Empty;
        GwOpGroup newGwOpGroup = this.GwOpGroupList.Find((Predicate<GwOpGroup>)(gwGroup => gwGroup.GroupID == opGroupId));
        if (newGwOpGroup != null)
            return string.Format("{0}<div class=\"text-muted\">{1}</div>", (object)newGwOpGroup.GroupID, (object)newGwOpGroup.GroupName);
 
        return string.Format("{0}", (object)opGroupId);
 
    }
 
    //序号规则ID转换名称
    public string apiSpXhIdToName(string api_sp_xh_id)
    {
 
        if (this.SysXhList == null)
            return string.Empty;
        SysXh newSysXh = this.SysXhList.Find((Predicate<SysXh>)(sysXh => sysXh.xhId == api_sp_xh_id));
        if (newSysXh != null)
            return string.Format("{0}<div class=\"text-muted\">{1}</div>", (object)newSysXh.xhId, (object)newSysXh.xhName);
 
        return string.Format("{0}", (object)api_sp_xh_id);
 
        foreach (SysXh sysXh in this.SysXhList)
        {
            if (api_sp_xh_id == sysXh.xhId)
                return sysXh.xhName;
            else
                continue;
        }
 
        return "序号规则未定义";
 
    }
 
    //产品是否启用
    private string GetStatusText(int is_enable, string productId)
    {
        if (is_enable == 0)
            return string.Format("<span class=\"action-updateStatus btn btn-xs btn-default\" data-is_enable=\"1\" data-id=\"{0}\">已停用</span>", (object)productId);
        return string.Format("<span class=\"action-updateStatus btn btn-xs  btn-success \" data-is_enable=\"0\" data-id=\"{0}\">已启用</span>", (object)productId);
    }
 
 
 
 
    //根据父级产品ID获取产品路径
    public string getProductPath(string parent_id, string productId)
    {
        string path = "";
        if (string.IsNullOrEmpty(parent_id) || parent_id == "0" || this.GwProductClassList == null)
        {
            path += "0" + "," + productId;
            return path;
        }
 
        GwProduct newGwProduct = this.GwProductClassList.Find((Predicate<GwProduct>)(gwProduct => gwProduct.id == parent_id));
        if (newGwProduct == null)
        {
            path += "0" + "," + productId;
            return path;
        }
        else if (newGwProduct != null)
        {
            path += (object)newGwProduct.path + "," + productId;
            return path;
        }
 
        return productId;
 
    }
 
 
    public bool IsInt(string input)
    {
        for (int index = 0; index < input.Length; ++index)
        {
            if (!char.IsNumber(input, index))
                return false;
        }
        return true;
    }
 
 
    private string FormatIpHtml(string p)
    {
        if (string.IsNullOrEmpty(p))
            return string.Empty;
        return p.Replace("|", "<br/>");
    }
 
 
    //保存更新后的账号信息
    private JsonPageResult Update(PageContext<SysUser> context)
    {
        GwProduct o = new GwProduct();
        o.id = context.GetString("id");
        o.name = context.GetString("name");
        //o.icon = context.GetString("icon");
        o.instructions = context.GetString("instructions");
        o.classes = context.GetInt("classes", 0);
        o.parent_id = context.GetString("parent_id");
        //o.path = context.GetString("path");
        o.path = getProductPath(o.parent_id, o.id);
        o.is_default = context.GetInt("is_default", 0);
        o.is_enable = context.GetInt("is_enable", 0);
        o.sort = context.GetInt("sort", 0);
        o.op_group_id = context.GetInt("op_group_id", 0);
        o.api_sp_xh_id = context.GetString("api_sp_xh_id");
        o.giving_num = context.GetInt("giving_num", 0);
        o.remark = context.GetString("remark");
 
        if (string.IsNullOrEmpty(o.name))
            throw new Exception("请输入产品名称!");
        if (!string.IsNullOrEmpty(context.GetString("sort")) && !Regex.IsMatch(context.GetString("sort"), "^[0-9]*$"))
            throw new Exception("序号必须为数字");
        
        //上传保存文件
        HttpFileCollection _file = HttpContext.Current.Request.Files;
        if (_file.Count > 0)
        {
            long size = _file[0].ContentLength; //文件大小
            string type = _file[0].ContentType; //文件类型
            string name = _file[0].FileName; //文件名
            string _tp = Path.GetExtension(name);//文件扩展名
            if (_tp.ToLower() == ".jpg" || _tp.ToLower() == ".jpeg" || _tp.ToLower() == ".gif" || _tp.ToLower() == ".png")
            {
                Stream stream = _file[0].InputStream;//获取文件流
                string savaName = o.id + "-" + DateTime.Now.ToString("yyyyMMddHHssmm") + _tp; //保存文件。文件名
                string filepath = "\\static\\images\\productIcon\\" + savaName;
                string path = AppDomain.CurrentDomain.BaseDirectory + filepath;//图片路径
                _file[0].SaveAs(path);
 
                o.icon = filepath;
            }
            else
            {
                throw new Exception("非图片文件,请重新选择!");
            }
 
        }else
        {
                if(o.classes==0)
            {
                    o.icon = "";
            }else { 
                o.icon = context.GetString("icon");
            }
        }
 
        this._Dao.Update(o);
        return new JsonPageResult(true, (object)("产品" + o.name + "修改成功!"));
    }
 
    private JsonPageResult Add(PageContext<SysUser> context)
    {
        GwProduct o = new GwProduct();
        //o.id = context.GetString("id");
        o.id = sysXhDao.getXh("GW_PRODUCT");
        o.name = context.GetString("name");
        //o.icon = context.GetString("icon");
        o.instructions = context.GetString("instructions");
        o.classes = context.GetInt("classes", 0);
        o.parent_id = context.GetString("parent_id");
        //o.path = context.GetString("path");
        o.path = getProductPath(o.parent_id, o.id);
        o.is_default = context.GetInt("is_default", 0);
        o.is_enable = context.GetInt("is_enable", 0);
        o.sort = context.GetInt("sort", 0);
        o.op_group_id = context.GetInt("op_group_id", 0);
        o.api_sp_xh_id = context.GetString("api_sp_xh_id");
        o.giving_num = context.GetInt("giving_num", 0);
        o.remark = context.GetString("remark");
 
        if (string.IsNullOrEmpty(o.name))
            throw new Exception("请输入产品名称!");
        if (!string.IsNullOrEmpty(context.GetString("sort")) && !Regex.IsMatch(context.GetString("sort"), "^[0-9]*$"))
            throw new Exception("序号必须为数字");
 
        if (this._Dao.IsNameExists(o.name))
            throw new Exception("产品名称已经存在,请重新填写!");
 
        //上传保存文件
        HttpFileCollection _file = HttpContext.Current.Request.Files;
        if (_file.Count > 0)
        {
            long size = _file[0].ContentLength; //文件大小
            string type = _file[0].ContentType; //文件类型
            string name = _file[0].FileName; //文件名
            string _tp = Path.GetExtension(name);//文件扩展名
            if (_tp.ToLower() == ".jpg" || _tp.ToLower() == ".jpeg" || _tp.ToLower() == ".gif" || _tp.ToLower() == ".png")
            {
                Stream stream = _file[0].InputStream;//获取文件流
                string savaName = o.id + "-" + DateTime.Now.ToString("yyyyMMddHHssmm") + _tp; //保存文件。文件名
                string filepath = "\\static\\images\\productIcon\\" + savaName;
                string path = AppDomain.CurrentDomain.BaseDirectory + filepath;//图片路径
                _file[0].SaveAs(path);
 
                o.icon = filepath;
            }
            else
            {
                throw new Exception("非图片文件,请重新选择!");
            }
        }
 
        this._Dao.Add(o);
        return new JsonPageResult(true, (object)("产品" + o.name + "添加成功!"));
    }
 
    //更新产品启停状态
    private JsonPageResult UpdateIs_enable(PageContext<SysUser> context)
    {
        string productId = context.GetString("productId");
        int is_enable = context.GetInt("is_enable");
        if (string.IsNullOrEmpty(productId))
            throw new ArgumentException("获取产品状态参数失败");
        if (!this._Dao.UpdateIs_enable(productId, is_enable))
            throw new ArgumentNullException("修改产品状态失败!");
 
        return new JsonPageResult(true, (object)"更改产品状态成功!");
    }
 
    private JsonPageResult Delete(PageContext<SysUser> context)
    {
        string productId = context.GetString("productId");
        if (string.IsNullOrEmpty(productId))
            throw new ArgumentException("产品ID为空!");
        this._Dao.Delete(productId);
        return new JsonPageResult(true, (object)("产品" + productId + "删除成功!"));
    }
 
    private JsonPageResult GetPrePattern(PageContext<SysUser> context)
    {
        return new JsonPageResult(true, (object)new GwSpPrePatternDao().Get(context.GetString("patternID")));
    }
}