sync.dic.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  1. using BizCom;
  2. using Newtonsoft.Json;
  3. using Newtonsoft.Json.Linq;
  4. using NHibernate.Linq;
  5. using NHibernate.Mapping;
  6. using NPOI.SS.Formula.Functions;
  7. using SiteCore.Redis;
  8. using SQLData;
  9. using System;
  10. using System.Collections;
  11. using System.Collections.Generic;
  12. using System.Data;
  13. using System.Linq;
  14. using System.Runtime.Remoting.Metadata.W3cXsd2001;
  15. namespace SiteCore.Handler
  16. {
  17. public partial class sync
  18. {
  19. #region dic
  20. private string getDicClassName(string pType)
  21. {
  22. //转成大小写
  23. switch (pType)
  24. {
  25. case "modular":
  26. {
  27. return "XModular";
  28. }
  29. }
  30. return pType;
  31. }
  32. public void get_dic_item()
  33. {
  34. if (UrlParmsCheck("class,mId"))
  35. {
  36. string c = GetString("class");
  37. string mId = GetString("mId");
  38. DicSysBase sysBase = GetReflectionObject(c) as DicSysBase;
  39. DataTable dt = sysBase.GetDataTable("ID=" + mId);
  40. if (dt != null && dt.Rows.Count > 0)
  41. {
  42. returnSuccess(Utils.Serialization.JsonString.DataTable2AjaxJson(dt));
  43. }
  44. }
  45. }
  46. public void del_dic_item()
  47. {
  48. if (UrlParmsCheck("class,mId"))
  49. {
  50. string c = GetString("class");
  51. string mId = GetString("mId");
  52. switch (c)
  53. {
  54. case "CeErpOrganization":
  55. string sql = "select count(0) from view_erpuser where orgid=" + mId;
  56. object res = CeErpOrganization.ExecuteScalar(sql);
  57. if (res != null && Convert.ToInt32(res) > 0)
  58. {
  59. returnErrorMsg("该组织已存在人员不允许删除!");
  60. return;
  61. }
  62. break;
  63. }
  64. DicSysBase sysBase = GetReflectionObject(c) as DicSysBase;
  65. DicSysBase entity = sysBase.GetEntity(mId) as DicSysBase;
  66. if (entity != null)
  67. {
  68. entity.DelChild(entity.ID);
  69. entity.Delete();
  70. returnSuccessMsg(entity.ParentID + "|删除成功!");
  71. }
  72. }
  73. }
  74. public void build_dic_item()
  75. {
  76. if (UrlParmsCheck("mId"))
  77. {
  78. string mId = GetString("mId");
  79. CeErpModular.BuilderOperate(mId);
  80. returnSuccessMsg(mId + "|生成成功!");
  81. }
  82. }
  83. public void transfer_dic_item()
  84. {
  85. if (UrlParmsCheck("mId,pId,sort"))
  86. {
  87. string mId = GetString("mId");
  88. int pId = GetInt("pId");
  89. int sort = GetInt("sort");
  90. string c = GetString("class");
  91. DicSysBase sysBase = GetReflectionObject(getDicClassName(c)) as DicSysBase;
  92. sysBase.TransModular(mId, pId, sort, sysBase.tableName);
  93. returnSuccessMsg(mId + "|转移成功!");
  94. }
  95. }
  96. public void line_dic_item()
  97. {
  98. if (UrlParmsCheck("mId,st,et"))
  99. {
  100. string mId = GetString("mId");
  101. string prev = GetString("prev");
  102. int st = GetInt("st");
  103. int et = GetInt("et");
  104. string c = GetString("class");
  105. DicSysBase sysBase = GetReflectionObject(getDicClassName(c)) as DicSysBase;
  106. sysBase.SaveLine(mId, prev, st, et, sysBase.tableName);
  107. returnSuccessMsg(mId + "|生成成功!");
  108. }
  109. }
  110. public void save_dic_item()
  111. {
  112. if (UrlParmsCheck("id,pid,name,class"))
  113. {
  114. string c = GetString("class");
  115. int id = GetInt("id");
  116. int pid = GetInt("pid");
  117. string name = GetString("name");
  118. string code = GetString("code");
  119. string selPemShop = GetString("selPemShop");
  120. int sort = GetInt("sort");
  121. int del = GetInt("del");
  122. string memo = GetString("memo");
  123. string url = GetString("url");
  124. string tag = GetString("tag");
  125. string icon = GetString("icon");
  126. int operate = GetInt("operate");
  127. int oldOrder = GetInt("oldOrder");
  128. string cName = c;// getDicClassName(c);
  129. if (cName == "")
  130. {
  131. return;
  132. }
  133. DicSysBase sysBase = GetReflectionObject(cName) as DicSysBase;
  134. DicSysBase entity = null;
  135. if (id > 0)
  136. {
  137. entity = sysBase.GetEntity(id) as DicSysBase;
  138. }
  139. else
  140. {
  141. entity = sysBase;
  142. }
  143. entity.ParentID = pid;
  144. entity.Name = name;
  145. entity.Code = code;
  146. entity.Sort = sort;
  147. entity.IsDel = (del == 1 ? true : false);
  148. entity.Memo = memo;
  149. switch (c)
  150. {
  151. case "CeErpModular":
  152. case "XModular":
  153. {
  154. entity.Url = url;
  155. entity.Tag = tag;
  156. entity.Icon = icon;
  157. entity.isOperate = (operate == 1 ? true : false);
  158. break;
  159. }
  160. case "CeErpOrganization":
  161. {
  162. entity.pemShop = selPemShop;
  163. entity.OldOrder = (oldOrder == 1 ? true : false);
  164. break;
  165. }
  166. case "hoststation":
  167. {
  168. entity.HostFieldName = GetString("hostfield");
  169. entity.HostName = GetString("hostname");
  170. entity.MaxStock = GetDouble("maxstock");
  171. entity.WarningStock = GetDouble("warningstock");
  172. break;
  173. }
  174. }
  175. if (id == 0)
  176. entity.Create();
  177. if (entity.ParentID > 0)
  178. {
  179. DataRow dr = sysBase.GetParentFields("Path,Code", entity.ParentID);
  180. string parentPath = dr["Path"].ToString();
  181. entity.Path = parentPath == "" ? "|" + entity.ParentID + "|" : parentPath + entity.ParentID + "|";
  182. if (c == "opt")
  183. {
  184. entity.PCode = dr["Code"].ToString();
  185. }
  186. }
  187. entity.Update();
  188. switch (c)
  189. {
  190. case "SErpModular":
  191. {
  192. erpRedis.RedisHelper.clearFilterKeys("pms_*");
  193. break;
  194. }
  195. case "CeErpModular":
  196. case "XModular":
  197. {
  198. //去除己保存的所有权限
  199. WebUser.ClearPermissionCache();
  200. break;
  201. }
  202. }
  203. returnSuccessMsg(entity.ID + "|保存成功");
  204. }
  205. }
  206. #endregion
  207. #region category
  208. private string getCTable(string t)
  209. {
  210. switch (t)
  211. {
  212. case "utype":
  213. {
  214. return "ce_erpunittype";
  215. }
  216. case "cartype":
  217. {
  218. return "ce_erpcartype";
  219. }
  220. case "paymenttype":
  221. {
  222. return "ce_erppaymenttype";
  223. }
  224. case "transgrade":
  225. {
  226. return "ce_erptransgrade";
  227. }
  228. }
  229. return "";
  230. }
  231. public void get_category()
  232. {
  233. string cate = GetPostString("cate");
  234. if (cate != "")
  235. {
  236. DataTable dt = null;
  237. dt = CategoryService.GetCategory(getCTable(cate), "");
  238. writeGridJson(dt.Rows.Count, Utils.Serialization.JsonString.DataTable2AjaxJson(dt));
  239. }
  240. }
  241. public void del_category()
  242. {
  243. if (UrlParmsCheck("sId,cate"))
  244. {
  245. int sId = GetInt("sId");
  246. string cate = GetString("cate");
  247. CategoryService.DelCategory(getCTable(cate), sId);
  248. returnSuccessMsg("己删除");
  249. }
  250. }
  251. public void save_category()
  252. {
  253. if (UrlParmsCheck("name,cate"))
  254. {
  255. int sId = GetInt("sId");
  256. string name = GetString("name");
  257. string cate = GetString("cate");
  258. CategoryService.SaveCategory(getCTable(cate), name, sId);
  259. returnSuccessMsg("保存成功!");
  260. }
  261. }
  262. #endregion
  263. public void perms_dic_item()
  264. {
  265. if (UrlParmsCheck("mId"))
  266. {
  267. string mId = GetString("mId");
  268. CeErpModular.AddPermission(mId);
  269. WebUser.ClearPermissionCache();
  270. returnSuccessMsg(mId + "|加入成功!");
  271. }
  272. }
  273. public void get_design_info()
  274. {
  275. if (UrlPostParmsCheck("type"))
  276. {
  277. int tarId = GetPostInt("tarId");
  278. int type = GetPostInt("type");
  279. if (tarId == 0)
  280. {
  281. returnSuccess("[]");
  282. return;
  283. }
  284. string sql = "select * from Ce_ErpDesignInfo where type = " + type + " and tarId = " + tarId;
  285. DataTable dt = null;
  286. try
  287. {
  288. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  289. }
  290. catch (Exception e)
  291. {
  292. dt = new DataTable();
  293. }
  294. if (dt != null && dt.Rows.Count > 0)
  295. {
  296. returnSuccess(Utils.Serialization.JsonString.DataTable2AjaxJson(dt));
  297. return;
  298. }
  299. returnSuccess("[]");
  300. }
  301. }
  302. public void save_design_info()
  303. {
  304. if (UrlPostParmsCheck("type"))
  305. {
  306. int tarId = GetPostInt("tarId");
  307. if (tarId == 0)
  308. {
  309. returnSuccessMsg("当前组织无法设置");
  310. return;
  311. }
  312. int shopId = GetPostInt("shopId");
  313. if (shopId == 0)
  314. {
  315. returnSuccessMsg("当前店铺无法设置");
  316. return;
  317. }
  318. string data = GetPostString("data");
  319. if (data == "")
  320. {
  321. returnSuccessMsg("数据不全无法设置");
  322. return;
  323. }
  324. int type = GetPostInt("type");
  325. string sql = "select * from Ce_ErpDesignInfo where type = " + type + " and tarId = " + tarId + " and shopId = " + shopId;
  326. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  327. List<CeErpDesignInfo> CeErpDesignInfos = new List<CeErpDesignInfo>();
  328. JArray jo = JsonConvert.DeserializeObject<JArray>(data);
  329. int shopIndex = 0;
  330. foreach (JObject item in jo)
  331. {
  332. CeErpDesignInfo shop = new CeErpDesignInfo();
  333. string[] ids = item["designIds"].ToString() == "" ? null : item["designIds"].ToString().Split(',');
  334. shop.tarId = tarId;
  335. shop.type = type;
  336. shop.designId = 0;
  337. shop.shopId = shopId;
  338. shop.orders = Convert.ToInt32(item["orders"]);
  339. CeErpDesignInfos.Add(shop);
  340. if (ids != null)
  341. {
  342. int designIndex = 0;
  343. for (int i = 0; i < ids.Length; i++)
  344. {
  345. CeErpDesignInfo design = new CeErpDesignInfo();
  346. design.tarId = tarId;
  347. design.type = type;
  348. design.designId = Convert.ToInt32(ids[i]);
  349. design.shopId = shopId;
  350. design.orders = designIndex;
  351. CeErpDesignInfos.Add(design);
  352. designIndex++;
  353. }
  354. }
  355. shopIndex++;
  356. }
  357. List<string> delIds = new List<string>();
  358. List<string> upList = new List<string>();
  359. foreach (CeErpDesignInfo item in CeErpDesignInfos)
  360. {
  361. if (dt.Rows.Count > 0)
  362. {
  363. foreach (DataRow dr in dt.Rows)
  364. {
  365. if (Convert.ToInt32(dr["shopId"]) == item.shopId && Convert.ToInt32(dr["designId"]) == item.designId)
  366. {
  367. item.ID = Convert.ToInt32(dr["id"]);
  368. if (Convert.ToInt32(dr["orders"]) != item.orders)
  369. {
  370. upList.Add(string.Format("update Ce_ErpDesignInfo set orders = {0} where ID = {1}", item.orders, item.ID));
  371. }
  372. delIds.Add(dr["id"].ToString());
  373. }
  374. }
  375. }
  376. }
  377. string delsql = "delete from Ce_ErpDesignInfo where type = " + type + " and tarId = " + tarId;
  378. if (delIds.Count > 0)
  379. {
  380. delsql += "and id not in (" + string.Join(",", delIds) + ")";
  381. }
  382. CeErpDesignInfo.ExecuteNonQuery(delsql);
  383. if (upList.Count > 0)
  384. {
  385. CeErpDesignInfo.ExecuteNonQuery(string.Join(";", upList));
  386. }
  387. List<string> inList = new List<string>();
  388. foreach (CeErpDesignInfo item in CeErpDesignInfos)
  389. {
  390. if (item.ID == 0)
  391. {
  392. 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));
  393. }
  394. }
  395. if (inList.Count > 0)
  396. {
  397. CeErpDesignInfo.ExecuteNonQuery(string.Join(";", inList));
  398. }
  399. returnSuccessMsg("添加成功!");
  400. }
  401. }
  402. public void save_shop_info()
  403. {
  404. if (UrlPostParmsCheck("type"))
  405. {
  406. int tarId = GetPostInt("tarId");
  407. if (tarId == 0)
  408. {
  409. returnSuccessMsg("当前组织无法设置");
  410. return;
  411. }
  412. string shopIds = GetPostString("shopIds");
  413. int type = GetPostInt("type");
  414. if (!string.IsNullOrWhiteSpace(shopIds))
  415. {
  416. string delsql = "delete from Ce_ErpDesignInfo where type =" + type + " and tarId = " + tarId + " and shopId not in (" + shopIds + ")";
  417. CeErpDesignInfo.ExecuteNonQuery(delsql);
  418. }
  419. else
  420. {
  421. string delsql = "delete from Ce_ErpDesignInfo where type =" + type + " and tarId = " + tarId;
  422. CeErpDesignInfo.ExecuteNonQuery(delsql);
  423. }
  424. returnSuccessMsg("添加成功!");
  425. }
  426. }
  427. public void save_dic_info()
  428. {
  429. if (UrlPostParmsCheck("type"))
  430. {
  431. int tarId = GetPostInt("tarId");
  432. if (tarId == 0)
  433. {
  434. returnSuccessMsg("当前组织/用户无法设置");
  435. return;
  436. }
  437. string data = GetPostString("data");
  438. if (data == "")
  439. {
  440. returnSuccessMsg("数据不全无法设置");
  441. return;
  442. }
  443. int type = GetPostInt("type");
  444. string sql = "select * from Ce_ErpDesignInfo where type = " + type + " and tarId = " + tarId;
  445. int shopId = GetPostInt("shopId");
  446. bool isShop = false;
  447. if (shopId > 0)
  448. {
  449. sql += " and shopId = " + shopId;
  450. isShop = true;
  451. }
  452. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  453. List<CeErpDesignInfo> CeErpDesignInfos = new List<CeErpDesignInfo>();
  454. JArray jo = JsonConvert.DeserializeObject<JArray>(data);
  455. int shopIndex = 0;
  456. foreach (JObject item in jo)
  457. {
  458. CeErpDesignInfo shop = new CeErpDesignInfo();
  459. string[] ids = item["designIds"].ToString() == "" ? null : item["designIds"].ToString().Split(',');
  460. shopId = Convert.ToInt32(item["shopId"]);
  461. shop.tarId = tarId;
  462. shop.type = type;
  463. shop.designId = 0;
  464. shop.shopId = shopId;
  465. shop.orders = Convert.ToInt32(item["orders"]);
  466. CeErpDesignInfos.Add(shop);
  467. if (ids != null)
  468. {
  469. int designIndex = 0;
  470. for (int i = 0; i < ids.Length; i++)
  471. {
  472. CeErpDesignInfo design = new CeErpDesignInfo();
  473. design.tarId = tarId;
  474. design.type = type;
  475. design.designId = Convert.ToInt32(ids[i]);
  476. design.shopId = shopId;
  477. design.orders = designIndex;
  478. CeErpDesignInfos.Add(design);
  479. designIndex++;
  480. }
  481. }
  482. shopIndex++;
  483. }
  484. List<string> delIds = new List<string>();
  485. List<string> upList = new List<string>();
  486. foreach (CeErpDesignInfo item in CeErpDesignInfos)
  487. {
  488. if (dt.Rows.Count > 0)
  489. {
  490. foreach (DataRow dr in dt.Rows)
  491. {
  492. if (Convert.ToInt32(dr["shopId"]) == item.shopId && Convert.ToInt32(dr["designId"]) == item.designId)
  493. {
  494. item.ID = Convert.ToInt32(dr["id"]);
  495. if (Convert.ToInt32(dr["orders"]) != item.orders)
  496. {
  497. upList.Add(string.Format("update Ce_ErpDesignInfo set orders = {0} where ID = {1}", item.orders, item.ID));
  498. }
  499. delIds.Add(dr["id"].ToString());
  500. }
  501. }
  502. }
  503. }
  504. string delsql = "delete from Ce_ErpDesignInfo where type = " + type + " and tarId = " + tarId;
  505. if (delIds.Count > 0)
  506. {
  507. delsql += "and id not in (" + string.Join(",", delIds) + ")";
  508. }
  509. if (isShop)
  510. {
  511. delsql += " and shopId = " + shopId;
  512. }
  513. CeErpDesignInfo.ExecuteNonQuery(delsql);
  514. if (upList.Count > 0)
  515. {
  516. CeErpDesignInfo.ExecuteNonQuery(string.Join(";", upList));
  517. }
  518. List<string> inList = new List<string>();
  519. foreach (CeErpDesignInfo item in CeErpDesignInfos)
  520. {
  521. if (item.ID == 0)
  522. {
  523. 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));
  524. }
  525. }
  526. if (inList.Count > 0)
  527. {
  528. CeErpDesignInfo.ExecuteNonQuery(string.Join(";", inList));
  529. }
  530. }
  531. returnSuccessMsg("添加成功!");
  532. }
  533. public void get_shop_list()
  534. {
  535. string sql = "select id,shopname as name from ce_erpshop";
  536. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  537. if (dt != null && dt.Rows.Count > 0)
  538. {
  539. returnSuccess(Utils.Serialization.JsonString.DataTable2AjaxJson(dt));
  540. return;
  541. }
  542. }
  543. public void get_product_list()
  544. {
  545. string sql = "select id,ptype as name from ce_erpproduct ";
  546. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  547. if (dt != null && dt.Rows.Count > 0)
  548. {
  549. returnSuccess(Utils.Serialization.JsonString.DataTable2AjaxJson(dt));
  550. return;
  551. }
  552. }
  553. }
  554. }