using BizCom; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using NHibernate.Linq; using NHibernate.Mapping; using NPOI.SS.Formula.Functions; using SiteCore.Redis; using SQLData; using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Linq; using System.Runtime.Remoting.Metadata.W3cXsd2001; namespace SiteCore.Handler { public partial class sync { #region dic private string getDicClassName(string pType) { //转成大小写 switch (pType) { case "modular": { return "XModular"; } } return pType; } public void get_dic_item() { if (UrlParmsCheck("class,mId")) { string c = GetString("class"); string mId = GetString("mId"); DicSysBase sysBase = GetReflectionObject(c) as DicSysBase; DataTable dt = sysBase.GetDataTable("ID=" + mId); if (dt != null && dt.Rows.Count > 0) { returnSuccess(Utils.Serialization.JsonString.DataTable2AjaxJson(dt)); } } } public void del_dic_item() { if (UrlParmsCheck("class,mId")) { string c = GetString("class"); string mId = GetString("mId"); switch (c) { case "CeErpOrganization": string sql = "select count(0) from view_erpuser where orgid=" + mId; object res = CeErpOrganization.ExecuteScalar(sql); if (res != null && Convert.ToInt32(res) > 0) { returnErrorMsg("该组织已存在人员不允许删除!"); return; } break; } DicSysBase sysBase = GetReflectionObject(c) as DicSysBase; DicSysBase entity = sysBase.GetEntity(mId) as DicSysBase; if (entity != null) { entity.DelChild(entity.ID); entity.Delete(); returnSuccessMsg(entity.ParentID + "|删除成功!"); } } } public void build_dic_item() { if (UrlParmsCheck("mId")) { string mId = GetString("mId"); CeErpModular.BuilderOperate(mId); returnSuccessMsg(mId + "|生成成功!"); } } public void transfer_dic_item() { if (UrlParmsCheck("mId,pId,sort")) { string mId = GetString("mId"); int pId = GetInt("pId"); int sort = GetInt("sort"); string c = GetString("class"); DicSysBase sysBase = GetReflectionObject(getDicClassName(c)) as DicSysBase; sysBase.TransModular(mId, pId, sort, sysBase.tableName); returnSuccessMsg(mId + "|转移成功!"); } } public void line_dic_item() { if (UrlParmsCheck("mId,st,et")) { string mId = GetString("mId"); string prev = GetString("prev"); int st = GetInt("st"); int et = GetInt("et"); string c = GetString("class"); DicSysBase sysBase = GetReflectionObject(getDicClassName(c)) as DicSysBase; sysBase.SaveLine(mId, prev, st, et, sysBase.tableName); returnSuccessMsg(mId + "|生成成功!"); } } public void save_dic_item() { if (UrlParmsCheck("id,pid,name,class")) { string c = GetString("class"); int id = GetInt("id"); int pid = GetInt("pid"); string name = GetString("name"); string code = GetString("code"); string selPemShop = GetString("selPemShop"); int sort = GetInt("sort"); int del = GetInt("del"); string memo = GetString("memo"); string url = GetString("url"); string tag = GetString("tag"); string icon = GetString("icon"); int operate = GetInt("operate"); int oldOrder = GetInt("oldOrder"); string cName = c;// getDicClassName(c); if (cName == "") { return; } DicSysBase sysBase = GetReflectionObject(cName) as DicSysBase; DicSysBase entity = null; if (id > 0) { entity = sysBase.GetEntity(id) as DicSysBase; } else { entity = sysBase; } entity.ParentID = pid; entity.Name = name; entity.Code = code; entity.Sort = sort; entity.IsDel = (del == 1 ? true : false); entity.Memo = memo; switch (c) { case "CeErpModular": case "XModular": { entity.Url = url; entity.Tag = tag; entity.Icon = icon; entity.isOperate = (operate == 1 ? true : false); break; } case "CeErpOrganization": { entity.pemShop = selPemShop; entity.OldOrder = (oldOrder == 1 ? true : false); break; } case "hoststation": { entity.HostFieldName = GetString("hostfield"); entity.HostName = GetString("hostname"); entity.MaxStock = GetDouble("maxstock"); entity.WarningStock = GetDouble("warningstock"); break; } } if (id == 0) entity.Create(); if (entity.ParentID > 0) { DataRow dr = sysBase.GetParentFields("Path,Code", entity.ParentID); string parentPath = dr["Path"].ToString(); entity.Path = parentPath == "" ? "|" + entity.ParentID + "|" : parentPath + entity.ParentID + "|"; if (c == "opt") { entity.PCode = dr["Code"].ToString(); } } entity.Update(); switch (c) { case "SErpModular": { erpRedis.RedisHelper.clearFilterKeys("pms_*"); break; } case "CeErpModular": case "XModular": { //去除己保存的所有权限 WebUser.ClearPermissionCache(); break; } } returnSuccessMsg(entity.ID + "|保存成功"); } } #endregion #region category private string getCTable(string t) { switch (t) { case "utype": { return "ce_erpunittype"; } case "cartype": { return "ce_erpcartype"; } case "paymenttype": { return "ce_erppaymenttype"; } case "transgrade": { return "ce_erptransgrade"; } } return ""; } public void get_category() { string cate = GetPostString("cate"); if (cate != "") { DataTable dt = null; dt = CategoryService.GetCategory(getCTable(cate), ""); writeGridJson(dt.Rows.Count, Utils.Serialization.JsonString.DataTable2AjaxJson(dt)); } } public void del_category() { if (UrlParmsCheck("sId,cate")) { int sId = GetInt("sId"); string cate = GetString("cate"); CategoryService.DelCategory(getCTable(cate), sId); returnSuccessMsg("己删除"); } } public void save_category() { if (UrlParmsCheck("name,cate")) { int sId = GetInt("sId"); string name = GetString("name"); string cate = GetString("cate"); CategoryService.SaveCategory(getCTable(cate), name, sId); returnSuccessMsg("保存成功!"); } } #endregion public void perms_dic_item() { if (UrlParmsCheck("mId")) { string mId = GetString("mId"); CeErpModular.AddPermission(mId); WebUser.ClearPermissionCache(); returnSuccessMsg(mId + "|加入成功!"); } } public void get_design_info() { if (UrlPostParmsCheck("type")) { int tarId = GetPostInt("tarId"); int type = GetPostInt("type"); if (tarId == 0) { returnSuccess("[]"); return; } string sql = "select * from Ce_ErpDesignInfo where type = " + type + " and tarId = " + tarId; DataTable dt = null; try { dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0]; } catch (Exception e) { dt = new DataTable(); } if (dt != null && dt.Rows.Count > 0) { returnSuccess(Utils.Serialization.JsonString.DataTable2AjaxJson(dt)); return; } returnSuccess("[]"); } } public void save_design_info() { if (UrlPostParmsCheck("type")) { int tarId = GetPostInt("tarId"); if (tarId == 0) { returnSuccessMsg("当前组织无法设置"); return; } int shopId = GetPostInt("shopId"); if (shopId == 0) { returnSuccessMsg("当前店铺无法设置"); return; } string data = GetPostString("data"); if (data == "") { returnSuccessMsg("数据不全无法设置"); return; } int type = GetPostInt("type"); string sql = "select * from Ce_ErpDesignInfo where type = " + type + " and tarId = " + tarId + " and shopId = " + shopId; DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0]; List CeErpDesignInfos = new List(); JArray jo = JsonConvert.DeserializeObject(data); int shopIndex = 0; foreach (JObject item in jo) { CeErpDesignInfo shop = new CeErpDesignInfo(); string[] ids = item["designIds"].ToString() == "" ? null : item["designIds"].ToString().Split(','); shop.tarId = tarId; shop.type = type; shop.designId = 0; shop.shopId = shopId; shop.orders = Convert.ToInt32(item["orders"]); CeErpDesignInfos.Add(shop); if (ids != null) { int designIndex = 0; for (int i = 0; i < ids.Length; i++) { CeErpDesignInfo design = new CeErpDesignInfo(); design.tarId = tarId; design.type = type; design.designId = Convert.ToInt32(ids[i]); design.shopId = shopId; design.orders = designIndex; CeErpDesignInfos.Add(design); designIndex++; } } shopIndex++; } List delIds = new List(); List upList = new List(); foreach (CeErpDesignInfo item in CeErpDesignInfos) { if (dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { if (Convert.ToInt32(dr["shopId"]) == item.shopId && Convert.ToInt32(dr["designId"]) == item.designId) { item.ID = Convert.ToInt32(dr["id"]); if (Convert.ToInt32(dr["orders"]) != item.orders) { upList.Add(string.Format("update Ce_ErpDesignInfo set orders = {0} where ID = {1}", item.orders, item.ID)); } delIds.Add(dr["id"].ToString()); } } } } string delsql = "delete from Ce_ErpDesignInfo where type = " + type + " and tarId = " + tarId; if (delIds.Count > 0) { delsql += "and id not in (" + string.Join(",", delIds) + ")"; } CeErpDesignInfo.ExecuteNonQuery(delsql); if (upList.Count > 0) { CeErpDesignInfo.ExecuteNonQuery(string.Join(";", upList)); } List inList = new List(); foreach (CeErpDesignInfo item in CeErpDesignInfos) { if (item.ID == 0) { inList.Add(string.Format("INSERT INTO [dbo].[Ce_ErpDesignInfo]([type], [tarId], [shopId], [designId], [orders]) VALUES ( {0}, {1}, {2}, {3}, {4})", item.type, item.tarId, item.shopId, item.designId, item.orders)); } } if (inList.Count > 0) { CeErpDesignInfo.ExecuteNonQuery(string.Join(";", inList)); } returnSuccessMsg("添加成功!"); } } public void save_shop_info() { if (UrlPostParmsCheck("type")) { int tarId = GetPostInt("tarId"); if (tarId == 0) { returnSuccessMsg("当前组织无法设置"); return; } string shopIds = GetPostString("shopIds"); int type = GetPostInt("type"); if (!string.IsNullOrWhiteSpace(shopIds)) { string delsql = "delete from Ce_ErpDesignInfo where type =" + type + " and tarId = " + tarId + " and shopId not in (" + shopIds + ")"; CeErpDesignInfo.ExecuteNonQuery(delsql); } else { string delsql = "delete from Ce_ErpDesignInfo where type =" + type + " and tarId = " + tarId; CeErpDesignInfo.ExecuteNonQuery(delsql); } returnSuccessMsg("添加成功!"); } } public void save_dic_info() { if (UrlPostParmsCheck("type")) { int tarId = GetPostInt("tarId"); if (tarId == 0) { returnSuccessMsg("当前组织/用户无法设置"); return; } string data = GetPostString("data"); if (data == "") { returnSuccessMsg("数据不全无法设置"); return; } int type = GetPostInt("type"); string sql = "select * from Ce_ErpDesignInfo where type = " + type + " and tarId = " + tarId; int shopId = GetPostInt("shopId"); bool isShop = false; if (shopId > 0) { sql += " and shopId = " + shopId; isShop = true; } DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0]; List CeErpDesignInfos = new List(); JArray jo = JsonConvert.DeserializeObject(data); int shopIndex = 0; foreach (JObject item in jo) { CeErpDesignInfo shop = new CeErpDesignInfo(); string[] ids = item["designIds"].ToString() == "" ? null : item["designIds"].ToString().Split(','); shopId = Convert.ToInt32(item["shopId"]); shop.tarId = tarId; shop.type = type; shop.designId = 0; shop.shopId = shopId; shop.orders = Convert.ToInt32(item["orders"]); CeErpDesignInfos.Add(shop); if (ids != null) { int designIndex = 0; for (int i = 0; i < ids.Length; i++) { CeErpDesignInfo design = new CeErpDesignInfo(); design.tarId = tarId; design.type = type; design.designId = Convert.ToInt32(ids[i]); design.shopId = shopId; design.orders = designIndex; CeErpDesignInfos.Add(design); designIndex++; } } shopIndex++; } List delIds = new List(); List upList = new List(); foreach (CeErpDesignInfo item in CeErpDesignInfos) { if (dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { if (Convert.ToInt32(dr["shopId"]) == item.shopId && Convert.ToInt32(dr["designId"]) == item.designId) { item.ID = Convert.ToInt32(dr["id"]); if (Convert.ToInt32(dr["orders"]) != item.orders) { upList.Add(string.Format("update Ce_ErpDesignInfo set orders = {0} where ID = {1}", item.orders, item.ID)); } delIds.Add(dr["id"].ToString()); } } } } string delsql = "delete from Ce_ErpDesignInfo where type = " + type + " and tarId = " + tarId; if (delIds.Count > 0) { delsql += "and id not in (" + string.Join(",", delIds) + ")"; } if (isShop) { delsql += " and shopId = " + shopId; } CeErpDesignInfo.ExecuteNonQuery(delsql); if (upList.Count > 0) { CeErpDesignInfo.ExecuteNonQuery(string.Join(";", upList)); } List inList = new List(); foreach (CeErpDesignInfo item in CeErpDesignInfos) { if (item.ID == 0) { inList.Add(string.Format("INSERT INTO [dbo].[Ce_ErpDesignInfo]([type], [tarId], [shopId], [designId], [orders]) VALUES ( {0}, {1}, {2}, {3}, {4})", item.type, item.tarId, item.shopId, item.designId, item.orders)); } } if (inList.Count > 0) { CeErpDesignInfo.ExecuteNonQuery(string.Join(";", inList)); } } returnSuccessMsg("添加成功!"); } public void get_shop_list() { string sql = "select id,shopname as name from ce_erpshop"; DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0]; if (dt != null && dt.Rows.Count > 0) { returnSuccess(Utils.Serialization.JsonString.DataTable2AjaxJson(dt)); return; } } public void get_product_list() { string sql = "select id,ptype as name from ce_erpproduct "; DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0]; if (dt != null && dt.Rows.Count > 0) { returnSuccess(Utils.Serialization.JsonString.DataTable2AjaxJson(dt)); return; } } } }