| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600 |
- 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<CeErpDesignInfo> CeErpDesignInfos = new List<CeErpDesignInfo>();
- JArray jo = JsonConvert.DeserializeObject<JArray>(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<string> delIds = new List<string>();
- List<string> upList = new List<string>();
- 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<string> inList = new List<string>();
- 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");
- if (shopIds == "")
- {
- returnSuccessMsg("数据不全无法设置");
- return;
- }
- 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);
- }
- 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<CeErpDesignInfo> CeErpDesignInfos = new List<CeErpDesignInfo>();
- JArray jo = JsonConvert.DeserializeObject<JArray>(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<string> delIds = new List<string>();
- List<string> upList = new List<string>();
- 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<string> inList = new List<string>();
- 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;
- }
- }
- }
- }
|