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.

393 lines
15 KiB

  1. using System.Data;
  2. using Swift.DAL.SwiftDAL;
  3. namespace Swift.DAL.BL.System.Notification
  4. {
  5. public class ChangeApprovalDao : SwiftDao
  6. {
  7. public DataRow SelectById(string functionId)
  8. {
  9. string sql = "SELECT * FROM changesApprovalSettings WITH(NOLOCK) WHERE functionId = " +
  10. FilterString(functionId);
  11. DataSet ds = ExecuteDataset(sql);
  12. if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
  13. return null;
  14. return ds.Tables[0].Rows[0];
  15. }
  16. public DataRow SelectLogHeadById(string functionId, string id)
  17. {
  18. DataRow dr = SelectById(functionId);
  19. if (dr == null)
  20. return null;
  21. string mainTable = dr["mainTable"].ToString();
  22. string modTable = dr["modTable"].ToString();
  23. string pkField = dr["pkField"].ToString();
  24. string sql =
  25. @"SELECT
  26. createdBy = ISNULL(MAX(mode.createdBy), MAX(main.createdBy))
  27. ,createdDate = ISNULL(MAX(mode.createdDate), MAX(main.createdDate))
  28. FROM " +
  29. mainTable + @" main WITH(NOLOCK)
  30. FULL JOIN " + modTable +
  31. @" mode WITH(NOLOCK) ON main." + pkField + " = mode." + pkField +
  32. @"
  33. WHERE main." + pkField + " = " + FilterString(id) + @" OR mode." + pkField +
  34. " = " + FilterString(id);
  35. DataSet ds = ExecuteDataset(sql);
  36. if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
  37. return null;
  38. return ds.Tables[0].Rows[0];
  39. }
  40. public DataRow SelectLogHeadByIdUR(string functionId, string id)
  41. {
  42. string sql =
  43. @"SELECT
  44. createdBy = ISNULL(MAX(mode.createdBy), MAX(main.createdBy))
  45. ,createdDate = ISNULL(MAX(mode.createdDate), MAX(main.createdDate))
  46. FROM applicationUserRoles main WITH(NOLOCK)
  47. FULL JOIN applicationUserRolesMod mode WITH(NOLOCK) ON main.userId = mode.userId
  48. AND main.userId = " +
  49. FilterString(id) + @" AND mode.userId = " + FilterString(id);
  50. DataSet ds = ExecuteDataset(sql);
  51. if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
  52. return null;
  53. return ds.Tables[0].Rows[0];
  54. }
  55. public DataRow SelectLogHeadByIdUF(string functionId, string id)
  56. {
  57. string sql =
  58. @"SELECT
  59. createdBy = ISNULL(MAX(mode.createdBy), MAX(main.createdBy))
  60. ,createdDate = ISNULL(MAX(mode.createdDate), MAX(main.createdDate))
  61. FROM applicationUserFunctions main WITH(NOLOCK)
  62. FULL JOIN applicationUserFunctionsMod mode WITH(NOLOCK) ON main.userId = mode.userId
  63. AND main.userId = " +
  64. FilterString(id) + @" AND mode.userId = " + FilterString(id);
  65. DataSet ds = ExecuteDataset(sql);
  66. if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
  67. return null;
  68. return ds.Tables[0].Rows[0];
  69. }
  70. public DataRow SelectLogHeadByIdRC(string functionId, string id)
  71. {
  72. string sql =
  73. @"SELECT
  74. createdBy = ISNULL(MAX(mode.createdBy), MAX(main.createdBy))
  75. ,createdDate = ISNULL(MAX(mode.createdDate), MAX(main.createdDate))
  76. FROM csCriteria main WITH(NOLOCK)
  77. LEFT JOIN csCriteriaHistory mode WITH(NOLOCK) ON main.csdetailId = mode.csdetailId
  78. AND main.csdetailId = " +
  79. FilterString(id) + @" AND mode.csdetailId = " + FilterString(id) +
  80. @"
  81. AND mode.approvedBy IS NULL";
  82. DataSet ds = ExecuteDataset(sql);
  83. if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
  84. return null;
  85. return ds.Tables[0].Rows[0];
  86. }
  87. public DbResult Approve(string user, string functionId, string id)
  88. {
  89. DataRow dr = SelectById(functionId);
  90. if (dr == null)
  91. return (new DbResult());
  92. string spName = dr["spName"].ToString();
  93. string pkField = dr["pkField"].ToString();
  94. string sql = spName + " @flag = 'approve', @user=" + FilterString(user) + ", @" + pkField + " = " +
  95. FilterString(id);
  96. if (functionId == "20131030" ||
  97. functionId == "20131130" ||
  98. functionId == "20131230" ||
  99. functionId == "20131330" ||
  100. functionId == "20601030" ||
  101. functionId == "20601130")
  102. sql = spName + " @flag = 'approveAll', @user=" + FilterString(user) + ", @" + pkField + " = " +
  103. FilterString(id);
  104. return ParseDbResult(ExecuteDataset(sql).Tables[0]);
  105. }
  106. public DbResult Reject(string user, string functionId, string id)
  107. {
  108. DataRow dr = SelectById(functionId);
  109. if (dr == null)
  110. return (new DbResult());
  111. string spName = dr["spName"].ToString();
  112. string pkField = dr["pkField"].ToString();
  113. string sql = spName + " @flag = 'reject', @user=" + FilterString(user) + ", @" + pkField + " = " +
  114. FilterString(id);
  115. if (functionId == "20141030" ||
  116. functionId == "20141130" ||
  117. functionId == "20131030" ||
  118. functionId == "20131130" ||
  119. functionId == "20131230" ||
  120. functionId == "20131330" ||
  121. functionId == "20601030")
  122. sql = spName + " @flag = 'rejectAll', @user=" + FilterString(user) + ", @" + pkField + " = " +
  123. FilterString(id);
  124. return ParseDbResult(ExecuteDataset(sql).Tables[0]);
  125. }
  126. public DbResult RejectUR(string user, string functionId, string id)
  127. {
  128. string sql =
  129. "[proc_applicationRoleFunction] @flag = 'reject', @roleIds = '1', @functionIds = NULL, @user = " +
  130. FilterString(user) + ", @userId = " + FilterString(id);
  131. return ParseDbResult(ExecuteDataset(sql).Tables[0]);
  132. }
  133. public DbResult RejectUF(string user, string functionId, string id)
  134. {
  135. string sql =
  136. "[proc_applicationRoleFunction] @flag = 'reject', @roleIds = NULL, @functionIds = '1', @user = " +
  137. FilterString(user) + ", @userId = " + FilterString(id);
  138. return ParseDbResult(ExecuteDataset(sql).Tables[0]);
  139. }
  140. public string[] GetChangeList(string functionId, string id)
  141. {
  142. DataRow dr = SelectById(functionId);
  143. if (dr == null)
  144. return new[] {"", ""};
  145. string mainTable = dr["mainTable"].ToString();
  146. string modTable = dr["modTable"].ToString();
  147. string pkField = dr["pkField"].ToString();
  148. string pageName = dr["pageName"].ToString();
  149. string changeType = "";
  150. string sql = "SELECT 'x' FROM " + mainTable + " WHERE approvedBy IS NULL AND " + pkField + " = " +
  151. FilterString(id);
  152. string res = GetSingleResult(sql);
  153. if (res == "x")
  154. {
  155. changeType = "Insert";
  156. }
  157. sql = "SELECT modType FROM " + modTable + " WHERE " + pkField + " = " + FilterString(id);
  158. if ((mainTable + "History").ToUpper() == modTable.ToUpper())
  159. {
  160. sql = sql + " AND approvedBy IS NULL ";
  161. }
  162. res = GetSingleResult(sql);
  163. if (res.ToUpper() == "U")
  164. {
  165. changeType = "Update";
  166. }
  167. else if (res.ToUpper() == "D")
  168. {
  169. changeType = "Delete";
  170. }
  171. string oldValue = "";
  172. string newValue = "";
  173. if (changeType == "Insert")
  174. {
  175. sql = "EXEC [proc_GetColumnToRow] @returnTable = 'Y'";
  176. sql += ",@tableName = " + FilterString(mainTable);
  177. sql += ",@fieldName = " + FilterString(pkField);
  178. sql += ",@dataId = " + FilterString(id);
  179. newValue = GetSingleResult(sql);
  180. }
  181. if (changeType == "Update")
  182. {
  183. sql = "EXEC [proc_GetColumnToRow] @returnTable = 'Y'";
  184. sql += ",@tableName = " + FilterString(modTable);
  185. sql += ",@fieldName = " + FilterString(pkField);
  186. sql += ",@dataId = " + FilterString(id);
  187. newValue = GetSingleResult(sql);
  188. }
  189. if (changeType == "Update" || changeType == "Delete")
  190. {
  191. sql = "EXEC [proc_GetColumnToRow] @returnTable = 'Y'";
  192. sql += ",@tableName = " + FilterString(mainTable);
  193. sql += ",@fieldName = " + FilterString(pkField);
  194. sql += ",@dataId = " + FilterString(id);
  195. oldValue = GetSingleResult(sql);
  196. }
  197. return new[] {oldValue, newValue, pageName, changeType};
  198. }
  199. public string[] GetChangeListUR(string functionId, string id)
  200. {
  201. string mainTable = "applicationUserRoles";
  202. string modTable = "applicationUserRolesMod";
  203. string pkField = "userId";
  204. string pageName = "User Roles";
  205. string changeType = "";
  206. string sql = "SELECT modType FROM " + modTable + " WHERE " + pkField + " = " + FilterString(id);
  207. string res = GetSingleResult(sql);
  208. if (res.ToUpper() == "U")
  209. {
  210. changeType = "Update";
  211. }
  212. string oldValue = "";
  213. string newValue = "";
  214. if (changeType == "Update")
  215. {
  216. sql = "EXEC [proc_GetColumnToRow] @returnTable = 'Y'";
  217. sql += ",@tableName = " + FilterString(modTable);
  218. sql += ",@fieldName = " + FilterString(pkField);
  219. sql += ",@dataId = " + FilterString(id);
  220. newValue = GetSingleResult(sql);
  221. sql = "EXEC [proc_GetColumnToRow] @returnTable = 'Y'";
  222. sql += ",@tableName = " + FilterString(mainTable);
  223. sql += ",@fieldName = " + FilterString(pkField);
  224. sql += ",@dataId = " + FilterString(id);
  225. oldValue = GetSingleResult(sql);
  226. }
  227. return new[] {oldValue, newValue, pageName, changeType};
  228. }
  229. public string[] GetChangeListUF(string functionId, string id)
  230. {
  231. string mainTable = "applicationUserFunctions";
  232. string modTable = "applicationUserFunctionsMod";
  233. string pkField = "userId";
  234. string pageName = "User Functions";
  235. string changeType = "";
  236. string sql = "SELECT modType FROM " + modTable + " WHERE " + pkField + " = " + FilterString(id);
  237. string res = GetSingleResult(sql);
  238. if (res.ToUpper() == "U")
  239. {
  240. changeType = "Update";
  241. }
  242. string oldValue = "";
  243. string newValue = "";
  244. if (changeType == "Update")
  245. {
  246. sql = "EXEC [proc_GetColumnToRow] @returnTable = 'Y'";
  247. sql += ",@tableName = " + FilterString(modTable);
  248. sql += ",@fieldName = " + FilterString(pkField);
  249. sql += ",@dataId = " + FilterString(id);
  250. newValue = GetSingleResult(sql);
  251. sql = "EXEC [proc_GetColumnToRow] @returnTable = 'Y'";
  252. sql += ",@tableName = " + FilterString(mainTable);
  253. sql += ",@fieldName = " + FilterString(pkField);
  254. sql += ",@dataId = " + FilterString(id);
  255. oldValue = GetSingleResult(sql);
  256. }
  257. return new[] {oldValue, newValue, pageName, changeType};
  258. }
  259. public string[] GetChangeListRC(string functionId, string id)
  260. {
  261. string mainTable = "";
  262. string modTable = "";
  263. string pkField = "";
  264. string pageName = "";
  265. string changeType = "";
  266. switch (functionId)
  267. {
  268. case "20601035":
  269. mainTable = "csCriteria";
  270. modTable = "csCriteriaHistory";
  271. pkField = "csDetailId";
  272. pageName = "Rule Criteria";
  273. break;
  274. case "20601135":
  275. mainTable = "cisCriteria";
  276. modTable = "cisCriteriaHistory";
  277. pkField = "cisDetailId";
  278. pageName = "ID Criteria";
  279. break;
  280. }
  281. string sql = "SELECT modType FROM " + modTable + " WHERE " + pkField + " = " + FilterString(id) +
  282. " AND approvedBy IS NULL";
  283. string res = GetSingleResult(sql);
  284. if (res.ToUpper() == "U")
  285. {
  286. changeType = "Update";
  287. }
  288. string oldValue = "";
  289. string newValue = "";
  290. if (changeType == "Update")
  291. {
  292. sql = "EXEC [proc_GetColumnToRow] @returnTable = 'Y'";
  293. sql += ",@tableName = " + FilterString(modTable);
  294. sql += ",@fieldName = " + FilterString(pkField);
  295. sql += ",@dataId = " + FilterString(id);
  296. newValue = GetSingleResult(sql);
  297. sql = "EXEC [proc_GetColumnToRow] @returnTable = 'Y'";
  298. sql += ",@tableName = " + FilterString(mainTable);
  299. sql += ",@fieldName = " + FilterString(pkField);
  300. sql += ",@dataId = " + FilterString(id);
  301. oldValue = GetSingleResult(sql);
  302. }
  303. return new[] {oldValue, newValue, pageName, changeType};
  304. }
  305. public DataRow CheckApprovalApi(string user, string functionId, string id)
  306. {
  307. string sql = "EXEC [proc_errPaidTranAPI] @flag = 'c'";
  308. sql += ",@user = " + FilterString(user);
  309. sql += ",@functionId = " + FilterString(functionId);
  310. sql += ",@id = " + FilterString(id);
  311. var ds = ExecuteDataset(sql);
  312. if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
  313. return null;
  314. return ds.Tables[0].Rows[0];
  315. }
  316. }
  317. }