<%@ 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")));
|
}
|
}
|