You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

832 lines
35 KiB

  1. using CounsellorBL.Common;
  2. using CounsellorBL.ConstDefinition;
  3. using CounsellorBL.Helper;
  4. using MonumentDefine;
  5. using OT.COM.ArsenalDB;
  6. using OT.COM.ArsenalDB.SQL;
  7. using OT.COM.LogisticsUtil;
  8. using OT.COM.SignalerMessage;
  9. using SoldierData.EnterprizeV4;
  10. using System;
  11. using System.Collections.Concurrent;
  12. using System.Collections.Generic;
  13. using System.Data;
  14. using System.Globalization;
  15. using System.Linq;
  16. using System.Net;
  17. using System.Net.Http;
  18. using System.Reflection;
  19. using System.Text;
  20. using System.Threading.Tasks;
  21. namespace CounsellorBL
  22. {
  23. public partial class TestService : DBService
  24. {
  25. public override string MainTable => GetMainTableName(typeof(tb_sys_translation));
  26. public TestService()
  27. {
  28. }
  29. public void TestInsert()
  30. {
  31. tb_sys_org o = new tb_sys_org()
  32. {
  33. uid = "2",
  34. name = "ssss",
  35. };
  36. Command cInsert = Command.SetupInsertCmd(o);
  37. ArsenalInterface ai = ArsenalDBMgr.GetInst(cInsert, GetDefaultSystemColumnInfo());
  38. ai.RunEditSingleCmd(cInsert);
  39. }
  40. public static ConcurrentDictionary<string, string> GetSetting()
  41. {
  42. return CustomizeDBMgr.SettingData;
  43. }
  44. #region Test Aync
  45. public static async Task<string> GetURL(Uri i_url)
  46. {
  47. using System.Net.Http.HttpClient client = new System.Net.Http.HttpClient();
  48. // GetStringAsync returns a Task<string>. That means that when you await the
  49. // task you'll get a string (urlContents).
  50. Task<string> getStringTask = client.GetStringAsync(i_url);
  51. string urlContents = await getStringTask.ConfigureAwait(false);
  52. // The return statement specifies an integer result.
  53. // Any methods that are awaiting AccessTheWebAsync retrieve the length value.
  54. return urlContents;
  55. }
  56. public static List<string> GetURLAync(string[] i_url)
  57. {
  58. List<string> lRes = new List<string>();
  59. if (i_url != null)
  60. {
  61. List<Task<string>> lts = new List<Task<string>>();
  62. foreach (string sUrl in i_url)
  63. {
  64. using HttpClient hc = new HttpClient();
  65. // GetStringAsync returns a Task<string>. That means that when you await the
  66. // task you'll get a string (urlContents).
  67. lts.Add(hc.GetStringAsync(new Uri(sUrl)));
  68. }
  69. Task.WaitAll(lts.ToArray());
  70. foreach (Task<string> ts in lts)
  71. {
  72. string s = ts.Result;
  73. lRes.Add(s);
  74. }
  75. // The return statement specifies an integer result.
  76. // Any methods that are awaiting AccessTheWebAsync retrieve the length value.
  77. }
  78. return lRes;
  79. }
  80. public static List<string> GetURLOrigin(string[] i_url)
  81. {
  82. List<string> lRes = new List<string>();
  83. if (i_url != null)
  84. {
  85. foreach (string sUrl in i_url)
  86. {
  87. using WebClient wc = new WebClient();
  88. lRes.Add(wc.DownloadString(sUrl));
  89. }
  90. }
  91. return lRes;
  92. }
  93. #endregion
  94. public void FillTrans()
  95. {
  96. List<Command> lCmdMaster = new List<Command>();
  97. for (int i = 100; i < 200; i++)
  98. {
  99. lCmdMaster.Add(Command.SetupInsertCmd(
  100. new tb_sys_translation()
  101. {
  102. create_org_uid = "001",
  103. update_org_uid = "001",
  104. create_user_uid = "3CE873C2-33AB-41E6-B6FE-4C528DEF5AF8",
  105. update_user_uid = "3CE873C2-33AB-41E6-B6FE-4C528DEF5AF8",
  106. name = $"Test{i}",
  107. language = "zh-Hant",
  108. trans = $"測試{i}"
  109. }));
  110. }
  111. ArsenalInterface ai = ArsenalDBMgr.GetInst(lCmdMaster[0], GetDefaultSystemColumnInfo());
  112. ai.RunEditCmds(lCmdMaster);
  113. }
  114. public static void FindSelfFK()
  115. {
  116. string codeBase = Assembly.GetExecutingAssembly().GetName().CodeBase;
  117. codeBase = codeBase.Substring(0, codeBase.LastIndexOf("/", StringComparison.OrdinalIgnoreCase));
  118. Assembly[] assemblyArray = (from f in AppDomain.CurrentDomain.GetAssemblies()
  119. where !f.IsDynamic
  120. && f.FullName.IndexOf("SoldierData", StringComparison.OrdinalIgnoreCase) != -1
  121. && f.CodeBase != null
  122. && f.CodeBase.StartsWith(codeBase, StringComparison.OrdinalIgnoreCase)
  123. select f).ToArray<Assembly>();
  124. List<Type> ltAll = new List<Type>();
  125. foreach (Assembly aCur in assemblyArray)
  126. {
  127. ltAll.AddRange(aCur.GetTypes().Where(f => f.BaseType == typeof(EntityBase)));
  128. }
  129. foreach (Type tCur in ltAll)
  130. {
  131. TableMiscAttribute tm = EntityUtil.GetClassAttribute<TableMiscAttribute>(tCur);
  132. List<KeyValuePair<string, ForeignRelation>> lkv = tm.Data.ForeignRelations.Where(f => f.Value.ForeignTable == tCur.Name).ToList();
  133. if (lkv.Count != 0)
  134. {
  135. foreach (KeyValuePair<string, ForeignRelation> kv in lkv)
  136. {
  137. int nMatchCount = 0;
  138. foreach (string sKey in kv.Value.Pars.Keys)
  139. {
  140. if (sKey == kv.Value.Pars[sKey])
  141. {
  142. nMatchCount++;
  143. }
  144. }
  145. if (kv.Value.Pars.Keys.Count == nMatchCount)
  146. {
  147. System.Diagnostics.Debug.WriteLine(kv.Key);
  148. }
  149. }
  150. }
  151. }
  152. }
  153. public void DeleteCascadeData(string i_sTable, Dictionary<string, object> i_dicCond)
  154. {
  155. string codeBase = Assembly.GetExecutingAssembly().GetName().CodeBase;
  156. codeBase = codeBase.Substring(0, codeBase.LastIndexOf("/", StringComparison.OrdinalIgnoreCase));
  157. Assembly[] assemblyArray = (from f in AppDomain.CurrentDomain.GetAssemblies()
  158. where !f.IsDynamic
  159. && f.FullName.IndexOf("SoldierData", StringComparison.OrdinalIgnoreCase) != -1
  160. && f.CodeBase != null
  161. && f.CodeBase.StartsWith(codeBase, StringComparison.OrdinalIgnoreCase)
  162. select f).ToArray<Assembly>();
  163. List<Type> ltAll = new List<Type>();
  164. foreach (Assembly aCur in assemblyArray)
  165. {
  166. ltAll.AddRange(aCur.GetTypes().Where(f => f.BaseType == typeof(EntityBase)));
  167. }
  168. List<Tuple<Type, Dictionary<string, object>>> lt = GetTypeFKFromRecursive(ltAll, i_sTable, i_dicCond);
  169. lt.Reverse();
  170. List<Command> lCmds = new List<Command>();
  171. foreach (Tuple<Type, Dictionary<string, object>> ttd in lt)
  172. {
  173. EntityBase ebCond = ClassHelper.GetInstByType(ttd.Item1) as EntityBase;
  174. ebCond.FillData(ttd.Item2);
  175. lCmds.Add(Command.SetupDeleteCmd(ebCond));
  176. }
  177. if (lCmds.Count > 0)
  178. {
  179. ArsenalInterface ai = ArsenalDBMgr.GetInst(lCmds[0], GetDefaultSystemColumnInfo());
  180. ai.RunEditCmds(lCmds);
  181. }
  182. }
  183. public List<Tuple<Type, Dictionary<string, object>>> GetTypeFKFromRecursive(List<Type> ltAll, string i_sTable, Dictionary<string, object> i_dicCond, int i_nLevel = 0)
  184. {
  185. List<Tuple<Type, Dictionary<string, object>>> lRes = new List<Tuple<Type, Dictionary<string, object>>>();
  186. List<Tuple<Type, Dictionary<string, object>>> lTemp = GetTypeFKFromRecursiveItem(ltAll, i_sTable, i_dicCond);
  187. if (lTemp.Count != 0)
  188. {
  189. lRes.AddRange(lTemp);
  190. foreach (Tuple<Type, Dictionary<string, object>> ttd in lTemp)
  191. {
  192. lRes.AddRange(GetTypeFKFromRecursive(ltAll, ttd.Item1.Name, ttd.Item2, i_nLevel + 1));
  193. }
  194. }
  195. return lRes;
  196. }
  197. public static List<Tuple<Type, Dictionary<string, object>>> GetTypeFKFromRecursiveItem(List<Type> ltAll, string i_sTable, Dictionary<string, object> i_dicCond)
  198. {
  199. List<Tuple<Type, Dictionary<string, object>>> ltRes = new List<Tuple<Type, Dictionary<string, object>>>();
  200. if (ltAll != null && i_dicCond != null)
  201. {
  202. foreach (Type tCur in ltAll)
  203. {
  204. TableMiscAttribute tm = EntityUtil.GetClassAttribute<TableMiscAttribute>(tCur);
  205. List<KeyValuePair<string, ForeignRelation>> lkv = tm.Data.ForeignRelations.Where(f => f.Value.ForeignTable == i_sTable).ToList();
  206. if (lkv.Count != 0)
  207. {
  208. EntityBase oDisply = ClassHelper.GetInstByType(tCur) as EntityBase;
  209. oDisply.SetFullDirty();
  210. foreach (KeyValuePair<string, ForeignRelation> kvp in lkv)
  211. {
  212. if (kvp.Value.Pars.Keys.Count != i_dicCond.Count)
  213. {
  214. continue;
  215. }
  216. bool bNotMatch = false;
  217. List<WhereNode> wnCond = new List<WhereNode>();
  218. foreach (string sKey in kvp.Value.Pars.Keys)
  219. {
  220. string sTargetColumn = kvp.Value.Pars[sKey];
  221. if (!i_dicCond.ContainsKey(sTargetColumn))
  222. {
  223. bNotMatch = true;
  224. }
  225. else
  226. {
  227. wnCond.Add(new WhereNode(sKey, WhereNode.EColumnOperation.EOT_EQ, tCur, i_dicCond[sTargetColumn].ToString()));
  228. }
  229. }
  230. if (bNotMatch)
  231. {
  232. continue;
  233. }
  234. Command cSelect = Command.SetupSelectCmd(oDisply, new WhereNode(WhereNode.ENodeOperation.ENO_AND, wnCond.ToArray()));
  235. ArsenalInterface ai = ArsenalDBMgr.GetInst(cSelect);
  236. QueryDataSet qds = ai.RunQueryDataSet(cSelect);
  237. if (qds.Total > 0)
  238. {
  239. foreach (DataRow dr in qds.DATA.Tables[0].Rows)
  240. {
  241. Dictionary<string, object> dicRow = new Dictionary<string, object>
  242. {
  243. { BLWording.UID, dr[BLWording.UID] }
  244. };
  245. ltRes.Add(Tuple.Create<Type, Dictionary<string, object>>(tCur, dicRow));
  246. }
  247. }
  248. }
  249. }
  250. }
  251. }
  252. return ltRes;
  253. }
  254. [Auth(false)]
  255. public static CResponseMessage Action(CRequestMessage i_crm)
  256. {
  257. CResponseMessage crm = new CSuccessResponseMessage("Reach." + DateTime.Now, i_crm);
  258. return crm;
  259. }
  260. public string Fix()
  261. {
  262. string sMsg = null;
  263. //
  264. do
  265. {
  266. QueryJsonElementCollection lBlocks = new QueryJsonElementCollection();
  267. QueryJsonElement qjeA = lBlocks.GetInst();
  268. qjeA.table = tb_rpt_apicolumn.TABLENAME;
  269. qjeA.displaycols = new List<string>() { tb_rpt_apicolumn.CN_API_UID, tb_rpt_apicolumn.CN_NAME };
  270. lBlocks.Add(qjeA);
  271. sMsg = MakeSelectJoinByBlocks(lBlocks, out Command cSelect);
  272. ArsenalInterface ai = ArsenalDBMgr.GetInst(cSelect, GetDefaultSystemColumnInfo());
  273. List<tb_rpt_apicolumn> la = ai.RunQueryList<tb_rpt_apicolumn>(cSelect);
  274. if (!cSelect.IsSuccess)
  275. {
  276. sMsg = cSelect.LastErrorCode;
  277. break;
  278. }
  279. Dictionary<string, bool> dicColumnReserveColumn = new Dictionary<string, bool>();
  280. string sSpecialColumnName = "reserve_space";
  281. la.ForEach(f =>
  282. {
  283. if (!dicColumnReserveColumn.ContainsKey(f.api_uid))
  284. {
  285. dicColumnReserveColumn.Add(f.api_uid, false);
  286. }
  287. if (f.name == sSpecialColumnName)
  288. {
  289. dicColumnReserveColumn[f.api_uid] = true;
  290. }
  291. });
  292. List<Command> lcCmds = new List<Command>();
  293. foreach (KeyValuePair<string, bool> kvp in dicColumnReserveColumn)
  294. {
  295. if (!kvp.Value)
  296. {
  297. lcCmds.Add(Command.SetupInsertCmd(new tb_rpt_apicolumn()
  298. {
  299. api_uid = kvp.Key,
  300. name = sSpecialColumnName,
  301. column_type = "nvarchar(100)",
  302. remark = "Space",
  303. trans_default = "備註"
  304. }));
  305. }
  306. }
  307. DateTime dtNow = DateTime.Now.Date;
  308. // NAME VALUE STATUS_FLAG SYSTEM_FLAG
  309. List<Tuple<string, string, int, int>> ltNewSetting = new List<Tuple<string, string, int, int>>()
  310. {
  311. new Tuple<string, string, int, int>(BLWording.SYSTEMSETTING_SYSTEMERRORMAIL, "", BLWording.STATUS_FLAG_ON , BLWording.SYSTEM_FLAG_OFF),
  312. new Tuple<string, string, int, int>(BLWording.REPORTLOG_MAILLIST, "", BLWording.STATUS_FLAG_ON , BLWording.SYSTEM_FLAG_OFF),
  313. new Tuple<string, string, int, int>(BLWording.REPORTLOG_ACTIVETIME, "8:10", BLWording.STATUS_FLAG_ON , BLWording.SYSTEM_FLAG_OFF),
  314. new Tuple<string, string, int, int>(BLWording.ADINTELOG_MAILLIST, "", BLWording.STATUS_FLAG_ON , BLWording.SYSTEM_FLAG_OFF),
  315. new Tuple<string, string, int, int>(BLWording.ADINTELOG_ACTIVETIME, "8:20", BLWording.STATUS_FLAG_ON , BLWording.SYSTEM_FLAG_OFF),
  316. new Tuple<string, string, int, int>(BLWording.RPTLOGMAIL_LASTTIME, dtNow.AddDays(-1).ToString(CultureInfo.CurrentCulture), BLWording.STATUS_FLAG_ON , BLWording.SYSTEM_FLAG_RUNTIME),
  317. new Tuple<string, string, int, int>(BLWording.ADINTEMAIL_LASTTIME, dtNow.AddDays(-1).ToString(CultureInfo.CurrentCulture), BLWording.STATUS_FLAG_ON , BLWording.SYSTEM_FLAG_RUNTIME),
  318. new Tuple<string, string, int, int>(BLWording.SYSTEM_LAUNCH, DateTime.Now.ToString(CultureInfo.CurrentCulture), BLWording.STATUS_FLAG_ON , BLWording.SYSTEM_FLAG_RUNTIME),
  319. new Tuple<string, string, int, int>(BLWording.LOG_RANGE, "14", BLWording.STATUS_FLAG_ON , BLWording.SYSTEM_FLAG_ON),
  320. new Tuple<string, string, int, int>(BLWording.REPORT_FLAG_GROUP, BLWording.STATUS_FLAG_OFF.ToString(CultureInfo.CurrentCulture), BLWording.STATUS_FLAG_ON , BLWording.SYSTEM_FLAG_ON)
  321. };
  322. if (CheckAndInserSetting(ltNewSetting, out List<Command> o_lcCmdsSetting) == null && o_lcCmdsSetting.Any())
  323. {
  324. lcCmds.AddRange(o_lcCmdsSetting);
  325. }
  326. lcCmds.Add(Command.SetupUpdateCmd(
  327. new tb_sys_system_setting() { key_value = DateTime.Now.ToString(CultureInfo.CurrentCulture) },
  328. new tb_sys_system_setting() { name = BLWording.SYSTEM_LAUNCH }));
  329. List<Tuple<string, string, string>> ltNewTrans = new List<Tuple<string, string, string>>() {
  330. new Tuple<string, string, string>("zh-Hant","common.emptyname","空白名稱"),
  331. new Tuple<string, string, string>("zh-Hant","common.duplicate","重複"),
  332. new Tuple<string, string, string>("zh-Hant","common.sendmail.success","郵件發送成功"),
  333. new Tuple<string, string, string>("zh-Hant","common.timerange_day","一天"),
  334. new Tuple<string, string, string>("zh-Hant","common.timerange_week","一週"),
  335. new Tuple<string, string, string>("zh-Hant","common.timerange_month","一月"),
  336. new Tuple<string, string, string>("zh-Hant","common.timerange_customize","自選"),
  337. new Tuple<string, string, string>("zh-Hant","common.timerange","時間區間"),
  338. new Tuple<string, string, string>("zh-Hant","system_flag.nonsystem","客製值"),
  339. new Tuple<string, string, string>("zh-Hant","system_flag.system","系統值"),
  340. new Tuple<string, string, string>("zh-Hant","system_flag.runtime","執行變數"),
  341. new Tuple<string, string, string>("zh-Hant","common.download","下載"),
  342. new Tuple<string, string, string>("zh-Hant","common.entercode","密碼"),
  343. new Tuple<string, string, string>("zh-Hant","common.date_start","開始時間"),
  344. new Tuple<string, string, string>("zh-Hant","common.date_end","結束時間"),
  345. new Tuple<string, string, string>("zh-Hant","menu.articlemanage2.maintain","發文列表2"),
  346. new Tuple<string, string, string>("zh-Hant","grp.article_id","文章ID"),
  347. new Tuple<string, string, string>("zh-Hant","grp.article.message","貼文訊息"),
  348. new Tuple<string, string, string>("zh-Hant","grp.article_media","貼文媒體檔"),
  349. new Tuple<string, string, string>("zh-Hant","prd.product.maintain","品項維護"),
  350. new Tuple<string, string, string>("zh-Hant","prd.wholesale_price","批價"),
  351. new Tuple<string, string, string>("zh-Hant","prd.price","單價"),
  352. new Tuple<string, string, string>("zh-Hant","common.invalid_file","失效檔案"),
  353. new Tuple<string, string, string>("zh-Hant","common.no_file","無檔案"),
  354. new Tuple<string, string, string>("zh-Hant","common.upload_file","檔案上傳"),
  355. new Tuple<string, string, string>("zh-Hant","common.no_media_fle","無媒體檔案"),
  356. new Tuple<string, string, string>("zh-Hant","grp.no_product","無產品"),
  357. new Tuple<string, string, string>("zh-Hant","grp.post_now","立即貼文"),
  358. new Tuple<string, string, string>("zh-Hant","grp.post_success","貼文成功"),
  359. new Tuple<string, string, string>("zh-Hant","grp.addproduct","新增品項"),
  360. new Tuple<string, string, string>("zh-Hant","prd.copyallspec","複製所有規格"),
  361. new Tuple<string, string, string>("zh-Hant","prd.removeallspec","清除規格"),
  362. new Tuple<string, string, string>("zh-Hant","grp.manully_import","手動匯入留言"),
  363. new Tuple<string, string, string>("zh-Hant","article.remark","備註"),
  364. };
  365. if (CheckAndInserTrans(ltNewTrans, out List<Command> o_lcCmdsTrans) == null && o_lcCmdsTrans.Any())
  366. {
  367. lcCmds.AddRange(o_lcCmdsTrans);
  368. }
  369. if (TruncParam(new List<string>() { "system_flag" }, out List<Command> o_lcTrunPara) == null)
  370. {
  371. lcCmds.AddRange(o_lcTrunPara);
  372. }
  373. List<Tuple<string, string, string, int>> ltNewParam = new List<Tuple<string, string, string, int>>() {
  374. new Tuple<string, string, string, int>("success_flag","success_flag.fail","0", 0),
  375. new Tuple<string, string, string, int>("common.timerange","common.timerange_day","day", 0),
  376. new Tuple<string, string, string, int>("common.timerange","common.timerange_week","week", 1),
  377. new Tuple<string, string, string, int>("common.timerange","common.timerange_month","month", 2),
  378. new Tuple<string, string, string, int>("common.timerange","common.timerange_customize","customize", 3),
  379. new Tuple<string, string, string, int>("system_flag","system_flag.nonsystem","0", 0),
  380. new Tuple<string, string, string, int>("system_flag","system_flag.system","1", 0),
  381. new Tuple<string, string, string, int>("system_flag","system_flag.runtime","2", 0),
  382. };
  383. if (CheckAndInserParam(ltNewParam, out List<Command> o_lcCmdsPara) == null && o_lcCmdsPara.Any())
  384. {
  385. lcCmds.AddRange(o_lcCmdsPara);
  386. }
  387. if (lcCmds.Any())
  388. {
  389. ai.RunEditCmds(lcCmds);
  390. }
  391. // 搜尋系統參數中REPORT_STATUS
  392. tb_sys_system_setting tReport = new tb_sys_system_setting();
  393. tb_sys_system_setting tReportWhere = new tb_sys_system_setting() { name = BLWording.REPORT_FLAG_GROUP };
  394. tReport.SetDirty(tb_sys_system_setting.CN_KEY_VALUE);
  395. Command csSelect = Command.SetupSelectCmd(tReport, tReportWhere);
  396. ai = ArsenalDBMgr.GetInst(csSelect, GetDefaultSystemColumnInfo());
  397. tb_sys_system_setting cSetting = ai.RunQuerySingleORM<tb_sys_system_setting>(csSelect);
  398. // 判斷REPORT_STATUS是否為true 及得到需更改的資料
  399. string sFlag = BLWording.STATUS_FLAG_ON.ToString(CultureInfo.CurrentCulture);
  400. if (cSetting.key_value != sFlag && CheckAndUpdateReport(out List<Command> o_lcAuth) == null)
  401. {
  402. tb_sys_system_setting tSettingWhere = new tb_sys_system_setting() { name = BLWording.REPORT_FLAG_GROUP };
  403. tb_sys_system_setting tSettingUpdate = new tb_sys_system_setting() { key_value = sFlag };
  404. Command cUpdae = Command.SetupUpdateCmd(tSettingUpdate, tSettingWhere);
  405. o_lcAuth.Add(cUpdae);
  406. ai.RunEditCmds(o_lcAuth);
  407. }
  408. }
  409. while (false);
  410. return sMsg;
  411. }
  412. public string CheckAndInserSetting(List<Tuple<string, string, int, int>> ltChecks, out List<Command> o_lcCmds)
  413. {
  414. string sMsg = null;
  415. List<Command> lcCmds = null;
  416. do
  417. {
  418. tb_sys_system_setting tDisplay = new tb_sys_system_setting();
  419. tDisplay.SetDirty(tb_sys_system_setting.CN_NAME);
  420. Command cSelect = Command.SetupSelectCmd(tDisplay);
  421. ArsenalInterface ai = ArsenalDBMgr.GetInst(cSelect, GetDefaultSystemColumnInfo());
  422. List<tb_sys_system_setting> ltAll = ai.RunQueryList<tb_sys_system_setting>(cSelect);
  423. List<Command> lcCmdsTemp = new List<Command>();
  424. if (ltChecks != null)
  425. {
  426. foreach (Tuple<string, string, int, int> t in ltChecks)
  427. {
  428. if (ltAll.FirstOrDefault(f => f.name == t.Item1) == null)
  429. {
  430. tb_sys_system_setting tsInsert = new tb_sys_system_setting()
  431. {
  432. name = t.Item1,
  433. key_value = t.Item2,
  434. status_flag = t.Item3,
  435. system_flag = t.Item4
  436. };
  437. lcCmdsTemp.Add(Command.SetupInsertCmd(tsInsert));
  438. }
  439. }
  440. }
  441. lcCmds = lcCmdsTemp;
  442. }
  443. while (false);
  444. o_lcCmds = lcCmds;
  445. return sMsg;
  446. }
  447. public string TruncParam(List<string> ltChecks, out List<Command> o_lcCmds)
  448. {
  449. string sMsg = null;
  450. List<Command> lcCmds = null;
  451. do
  452. {
  453. tb_sys_paramcatalog tDisplay = new tb_sys_paramcatalog();
  454. tDisplay.SetDirty(tb_sys_paramcatalog.CN_NAME, tb_sys_paramcatalog.CN_UID);
  455. Command cSelect = Command.SetupSelectCmd(tDisplay);
  456. ArsenalInterface ai = ArsenalDBMgr.GetInst(cSelect, GetDefaultSystemColumnInfo());
  457. List<tb_sys_paramcatalog> lpcAll = ai.RunQueryList<tb_sys_paramcatalog>(cSelect);
  458. List<Command> lcCmdsTemp = new List<Command>();
  459. if (ltChecks != null)
  460. {
  461. foreach (string t in ltChecks)
  462. {
  463. tb_sys_paramcatalog pc = lpcAll.FirstOrDefault(f => f.name == t);
  464. if (pc != null)
  465. {
  466. lcCmdsTemp.Add(Command.SetupDeleteCmd(new tb_sys_param() { paramcatalog = pc.uid }));
  467. }
  468. }
  469. }
  470. lcCmds = lcCmdsTemp;
  471. }
  472. while (false);
  473. o_lcCmds = lcCmds;
  474. return sMsg;
  475. }
  476. public string CheckAndInserParam(List<Tuple<string, string, string, int>> ltChecks, out List<Command> o_lcCmds)
  477. {
  478. string sMsg = null;
  479. List<Command> lcCmds = null;
  480. do
  481. {
  482. tb_sys_param tpDisplay = new tb_sys_param();
  483. tpDisplay.SetDirty(tb_sys_param.CN_NAME, tb_sys_param.CN_UID);
  484. Command cSelectParam = Command.SetupSelectCmd(tpDisplay);
  485. ArsenalInterface ai = ArsenalDBMgr.GetInst(cSelectParam, GetDefaultSystemColumnInfo());
  486. List<tb_sys_param> lpAll = ai.RunQueryList<tb_sys_param>(cSelectParam);
  487. tb_sys_paramcatalog tDisplay = new tb_sys_paramcatalog();
  488. tDisplay.SetDirty(tb_sys_paramcatalog.CN_NAME, tb_sys_paramcatalog.CN_UID);
  489. Command cSelect = Command.SetupSelectCmd(tDisplay);
  490. List<tb_sys_paramcatalog> lpcAll = ai.RunQueryList<tb_sys_paramcatalog>(cSelect);
  491. List<Command> lcCmdsTemp = new List<Command>();
  492. Dictionary<string, string> dicCateGoryName2Uid = new Dictionary<string, string>();
  493. if (ltChecks != null)
  494. {
  495. foreach (Tuple<string, string, string, int> t in ltChecks)
  496. {
  497. if (!dicCateGoryName2Uid.ContainsKey(t.Item1))
  498. {
  499. tb_sys_paramcatalog pc = lpcAll.FirstOrDefault(f => f.name == t.Item1);
  500. if (pc == null)
  501. {
  502. string sUID = Guid.NewGuid().ToString();
  503. tb_sys_paramcatalog pcInsert = new tb_sys_paramcatalog()
  504. {
  505. uid = sUID,
  506. name = t.Item1,
  507. status_flag = BLWording.STATUS_FLAG_ON,
  508. system_flag = BLWording.STATUS_FLAG_OFF,
  509. };
  510. dicCateGoryName2Uid.Add(t.Item1, sUID);
  511. lcCmdsTemp.Add(Command.SetupInsertCmd(pcInsert));
  512. }
  513. else
  514. {
  515. dicCateGoryName2Uid.Add(pc.name, pc.uid);
  516. }
  517. }
  518. tb_sys_param p = lpAll.FirstOrDefault(f => f.name == t.Item2 && f.paramcatalog == dicCateGoryName2Uid[t.Item1]);
  519. if (p == null)
  520. {
  521. lcCmdsTemp.Add(Command.SetupDeleteCmd(new tb_sys_param()
  522. {
  523. name = t.Item2,
  524. paramcatalog = dicCateGoryName2Uid[t.Item1],
  525. }));
  526. tb_sys_param pInsert = new tb_sys_param()
  527. {
  528. name = t.Item2,
  529. paramcatalog = dicCateGoryName2Uid[t.Item1],
  530. param_value = t.Item3,
  531. status_flag = BLWording.STATUS_FLAG_ON,
  532. system_flag = BLWording.STATUS_FLAG_OFF,
  533. seq = t.Item4
  534. };
  535. lcCmdsTemp.Add(Command.SetupInsertCmd(pInsert));
  536. }
  537. }
  538. }
  539. lcCmds = lcCmdsTemp;
  540. }
  541. while (false);
  542. o_lcCmds = lcCmds;
  543. return sMsg;
  544. }
  545. public string CheckAndInserTrans(List<Tuple<string, string, string>> ltChecks, out List<Command> o_lcCmds)
  546. {
  547. string sMsg = null;
  548. List<Command> lcCmds = null;
  549. do
  550. {
  551. if (ltChecks == null)
  552. {
  553. sMsg = MessageWording.PARAM_NOT_EXPECTED;
  554. break;
  555. }
  556. tb_sys_translation tDisplay = new tb_sys_translation();
  557. tDisplay.SetDirty(tb_sys_translation.CN_NAME, tb_sys_translation.CN_LANGUAGE);
  558. Command cSelect = Command.SetupSelectCmd(tDisplay);
  559. ArsenalInterface ai = ArsenalDBMgr.GetInst(cSelect, GetDefaultSystemColumnInfo());
  560. List<tb_sys_translation> ltAll = ai.RunQueryList<tb_sys_translation>(cSelect);
  561. List<Command> lcCmdsTemp = new List<Command>();
  562. foreach (Tuple<string, string, string> t in ltChecks)
  563. {
  564. if (ltAll.FirstOrDefault(f => f.language == t.Item1 && f.name == t.Item2) == null)
  565. {
  566. tb_sys_translation tsInsert = new tb_sys_translation()
  567. {
  568. language = t.Item1,
  569. name = t.Item2,
  570. trans = t.Item3
  571. };
  572. lcCmdsTemp.Add(Command.SetupInsertCmd(tsInsert));
  573. }
  574. }
  575. lcCmds = lcCmdsTemp;
  576. }
  577. while (false);
  578. o_lcCmds = lcCmds;
  579. return sMsg;
  580. }
  581. /// <summary>
  582. /// 將原本SWFIT在handle_item的資料搬到group_item
  583. /// </summary>
  584. /// <param name="o_lcCmds"></param>
  585. /// <returns></returns>
  586. public string CheckAndUpdateReport(out List<Command> o_lcCmds)
  587. {
  588. string sMsg = null;
  589. List<Command> lcCmds;
  590. do
  591. {
  592. // 先搜尋authreport的資料
  593. tb_rpt_authreport rDisplay = new tb_rpt_authreport();
  594. rDisplay.SetDirty(tb_rpt_authreport.CN_UID, tb_rpt_authreport.CN_REPORT_TYPE, tb_rpt_authreport.CN_DEPARTMENT_ITEM);
  595. tb_rpt_authreport rWhere = new tb_rpt_authreport() { report_type = BseMessageWording.GROUP };
  596. Command cSelect = Command.SetupSelectCmd(rDisplay, rWhere);
  597. ArsenalInterface ai = ArsenalDBMgr.GetInst(cSelect, GetDefaultSystemColumnInfo());
  598. List<tb_rpt_authreport> ltAll = ai.RunQueryList<tb_rpt_authreport>(cSelect);
  599. List<Command> lcCmdsTemp = new List<Command>();
  600. if (ltAll.Any())
  601. {
  602. foreach (var t in ltAll)
  603. {
  604. if (t.department_item != null)
  605. {
  606. // 更新tb_rpt_authreport資料
  607. tb_rpt_authreport uAuth = new tb_rpt_authreport() { uid = t.uid };
  608. tb_rpt_authreport uData = new tb_rpt_authreport()
  609. {
  610. department_item = null,
  611. group_items = t.department_item
  612. };
  613. lcCmdsTemp.Add(Command.SetupUpdateCmd(uData, uAuth));
  614. // 更新tb_rpt_authreport_schedule資料
  615. tb_rpt_authreport_schedule uScheduleAuth = new tb_rpt_authreport_schedule() { authreport_uid = t.uid };
  616. tb_rpt_authreport_schedule uScheduleData = new tb_rpt_authreport_schedule()
  617. {
  618. department_item = null,
  619. group_items = t.department_item
  620. };
  621. lcCmdsTemp.Add(Command.SetupUpdateCmd(uScheduleData, uScheduleAuth));
  622. }
  623. }
  624. }
  625. lcCmds = lcCmdsTemp;
  626. }
  627. while (false);
  628. o_lcCmds = lcCmds;
  629. return sMsg;
  630. }
  631. public int LogTest()
  632. {
  633. return LogHelper.DBLog("NNNNNNNNNN");
  634. }
  635. public Command TestSQLLib()
  636. {
  637. SQLLib mb = new SQLLib(new MSSQLDirectSQLHelper());
  638. mb.GetArticleProduct("aaa", out Command cRes);
  639. return cRes;
  640. }
  641. }
  642. class SQLLib : DirectSQLLibBase
  643. {
  644. public SQLLib(ADirectSQLHelper i_sqlLibBase) : base(i_sqlLibBase) { }
  645. public virtual string GetArticleProduct(string i_sArticleUid, out Command o_cResult)
  646. {
  647. ADirectCmdParameter cp = GetParamter();
  648. string sSQL = $@"SELECT a.{tb_prd_product.CN_UID}
  649. , a.{tb_prd_product.CN_NAME}
  650. , a.{tb_prd_product.CN_MEMO}
  651. FROM {GetFormalTableName<tb_prd_product>()} a
  652. LEFT JOIN {GetFormalTableName<tb_prd_article2product>()} b
  653. on a.{tb_prd_product.CN_UID} = b.{tb_prd_article2product.CN_PRD_UID}
  654. where b.{tb_prd_article2product.CN_ARTICLE_UID} = {cp.Add(i_sArticleUid)}";
  655. return GenerateCommand<tb_prd_product>(sSQL, cp, out o_cResult);
  656. }
  657. }
  658. }