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.

238 lines
9.5 KiB

  1. using EasyBL.WebApi.Message;
  2. using Entity.Sugar;
  3. using Entity.ViewModels;
  4. using SqlSugar;
  5. using SqlSugar.Base;
  6. using System;
  7. using System.Collections.Generic;
  8. namespace EasyBL.WEBAPP.ShowEasy
  9. {
  10. public class OrganizerMaintain_QryService : ServiceBase
  11. {
  12. #region 主辦值(分頁資料)
  13. /// <summary>
  14. /// 主辦值(分頁資料)
  15. /// </summary>
  16. /// <param name="i_crm">todo: describe i_crm parameter on QueryPage</param>
  17. /// <returns></returns>
  18. public ResponseMessage QueryPage(RequestMessage i_crm)
  19. {
  20. ResponseMessage rm = null;
  21. string sMsg = null;
  22. var db = SugarBase.DB;
  23. try
  24. {
  25. do
  26. {
  27. var pml = new PageModel
  28. {
  29. PageIndex = _fetchInt(i_crm, @"pageIndex"),
  30. PageSize = _fetchInt(i_crm, @"pageSize")
  31. };
  32. var iPageCount = 0;
  33. var sSortField = _fetchString(i_crm, @"sortField");
  34. var sSortOrder = _fetchString(i_crm, @"sortOrder");
  35. var sOrganizerName = _fetchString(i_crm, @"OrganizerName");
  36. var sEffective = _fetchString(i_crm, @"Effective");
  37. var bExcel = _fetchBool(i_crm, @"Excel");
  38. pml.DataList = db.Queryable<SETB_ORG_Organizer, SETB_UTL_City>
  39. ((t1, t2) =>
  40. new object[] {
  41. JoinType.Left, t1.OrgID == t2.OrgID && t1.CityID == t2.CityID
  42. }
  43. )
  44. .Where((t1, t2) => t1.OrgID == i_crm.ORIGID)//&& t1.OrganizerName.Contains(sOrganizerName) && sEffective.Contains(t1.Effective)
  45. .WhereIF(!string.IsNullOrEmpty(sOrganizerName), (t1, t2) => t1.OrganizerName.Contains(sOrganizerName))
  46. .WhereIF(!string.IsNullOrEmpty(sEffective), (t1, t2) => sEffective.Contains(t1.Effective))
  47. .Select((t1, t2) => new View_ORG_Organizer
  48. {
  49. OrgID=t1.OrgID,
  50. OrganizerID=t1.OrganizerID,
  51. OrganizerName=t1.OrganizerName,
  52. CityName = t2.CityName,
  53. Telephone=t1.Telephone,
  54. Email=t1.Email,
  55. WebSite=t1.WebSite,
  56. Effective=t1.Effective
  57. })
  58. //.MergeTable()
  59. .OrderBy(sSortField, sSortOrder)
  60. .ToPageList(pml.PageIndex, bExcel ? 100000 : pml.PageSize, ref iPageCount);
  61. pml.Total = iPageCount;
  62. rm = new SuccessResponseMessage(null, i_crm);
  63. if (bExcel)
  64. {
  65. const string sFileName = "主辦單位";
  66. var oHeader = new Dictionary<string, string>
  67. {
  68. { "RowIndex", "項次" },
  69. { "OrganizerName", "主辦單位名稱" },
  70. { "CityName", "城市名稱" },
  71. { "Telephone", "聯絡電話" },
  72. { "Email", "Email" },
  73. { "WebSite", "網址" },
  74. { "Effective", "狀態(Y:有效;N:無效)" }
  75. };
  76. var dicAlain = ExcelService.GetExportAlain(oHeader, "Effective");
  77. var saArguments = pml.DataList as List<View_ORG_Organizer>;
  78. var bOk = new ExcelService().CreateExcelByList(saArguments, out string sPath, oHeader, dicAlain, sFileName);
  79. rm.DATA.Add(BLWording.REL, sPath);
  80. }
  81. else
  82. {
  83. rm.DATA.Add(BLWording.REL, pml);
  84. }
  85. } while (false);
  86. }
  87. catch (Exception ex)
  88. {
  89. sMsg = Util.GetLastExceptionMsg(ex);
  90. LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(OrganizerMaintain_QryService), @"主辦值", @"QueryPage(主辦值(分頁資料))", @"", @"", @"");
  91. }
  92. finally
  93. {
  94. if (null != sMsg)
  95. {
  96. rm = new ErrorResponseMessage(sMsg, i_crm);
  97. }
  98. }
  99. return rm;
  100. }
  101. #endregion 主辦值(分頁資料)
  102. #region 洲別列表(多筆)
  103. /// <summary>
  104. /// 洲別列表(多筆)
  105. /// </summary>
  106. /// <param name="i_crm"></param>
  107. /// <returns></returns>
  108. public ResponseMessage QueryList(RequestMessage i_crm)
  109. {
  110. ResponseMessage rm = null;
  111. string sMsg = null;
  112. var db = SugarBase.GetIntance();
  113. try
  114. {
  115. do
  116. {
  117. var saArgumentClass = db.Queryable<OTB_SYS_Arguments>()
  118. .Where(x => x.OrgID == i_crm.ORIGID && x.Effective == "Y" && x.DelStatus == "N" && x.ArgumentClassID== "Area" && x.LevelOfArgument==0)
  119. .OrderBy(x => x.OrderByValue)
  120. .ToList();
  121. rm = new SuccessResponseMessage(null, i_crm);
  122. rm.DATA.Add(BLWording.REL, saArgumentClass);
  123. } while (false);
  124. }
  125. catch (Exception ex)
  126. {
  127. sMsg = Util.GetLastExceptionMsg(ex);
  128. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(OrganizerMaintain_QryService), "", "QueryList(洲別列表(多筆))", "", "", "");
  129. }
  130. finally
  131. {
  132. if (null != sMsg)
  133. {
  134. rm = new ErrorResponseMessage(sMsg, i_crm);
  135. }
  136. }
  137. return rm;
  138. }
  139. #endregion 參數類別(多筆)
  140. #region 國家列表(多筆)
  141. /// <summary>
  142. /// 國家列表(多筆)
  143. /// </summary>
  144. /// <param name="i_crm"></param>
  145. /// <returns></returns>
  146. public ResponseMessage QueryCountryList(RequestMessage i_crm)
  147. {
  148. ResponseMessage rm = null;
  149. string sMsg = null;
  150. var db = SugarBase.GetIntance();
  151. try
  152. {
  153. do
  154. {
  155. var sRegionID = _fetchString(i_crm, @"RegionID");
  156. var saArgumentClass = db.Queryable<OTB_SYS_Arguments>()
  157. .Where(x => x.OrgID == i_crm.ORIGID && x.Effective == "Y" && x.DelStatus == "N" && x.ArgumentClassID == "Area"&& x.ParentArgument== sRegionID)
  158. .OrderBy(x => x.OrderByValue)
  159. .ToList();
  160. rm = new SuccessResponseMessage(null, i_crm);
  161. rm.DATA.Add(BLWording.REL, saArgumentClass);
  162. } while (false);
  163. }
  164. catch (Exception ex)
  165. {
  166. sMsg = Util.GetLastExceptionMsg(ex);
  167. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(OrganizerMaintain_QryService), "", "QueryCountryList(國家列表(多筆))", "", "", "");
  168. }
  169. finally
  170. {
  171. if (null != sMsg)
  172. {
  173. rm = new ErrorResponseMessage(sMsg, i_crm);
  174. }
  175. }
  176. return rm;
  177. }
  178. #endregion 參數類別(多筆)
  179. #region 城市列表(多筆)
  180. /// <summary>
  181. /// 國家列表(多筆)
  182. /// </summary>
  183. /// <param name="i_crm"></param>
  184. /// <returns></returns>
  185. public ResponseMessage QueryCityList(RequestMessage i_crm)
  186. {
  187. ResponseMessage rm = null;
  188. string sMsg = null;
  189. var db = SugarBase.GetIntance();
  190. try
  191. {
  192. do
  193. {
  194. var sCountryID = _fetchString(i_crm, @"CountryID");
  195. var saArgumentClass = db.Queryable<SETB_UTL_City>()
  196. .Where(x => x.OrgID == i_crm.ORIGID && x.Effective == "Y" && x.CountryID == sCountryID)//&& x.DelStatus == "N"
  197. //.OrderBy(x => x.OrderByValue)
  198. .ToList();
  199. rm = new SuccessResponseMessage(null, i_crm);
  200. rm.DATA.Add(BLWording.REL, saArgumentClass);
  201. } while (false);
  202. }
  203. catch (Exception ex)
  204. {
  205. sMsg = Util.GetLastExceptionMsg(ex);
  206. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(OrganizerMaintain_QryService), "", "QueryCountryList(國家列表(多筆))", "", "", "");
  207. }
  208. finally
  209. {
  210. if (null != sMsg)
  211. {
  212. rm = new ErrorResponseMessage(sMsg, i_crm);
  213. }
  214. }
  215. return rm;
  216. }
  217. #endregion 參數類別(多筆)
  218. }
  219. }