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.

297 lines
12 KiB

  1. using Swift.DAL.BL.Remit.AgentRiskProfiling;
  2. using Swift.DAL.SwiftDAL;
  3. using Swift.web.Component.Grid;
  4. using Swift.web.Library;
  5. using System;
  6. using System.Data;
  7. using System.Text;
  8. using System.Web.UI.WebControls;
  9. namespace Swift.web.Remit.AgentRiskProfiling
  10. {
  11. public partial class Manage : System.Web.UI.Page
  12. {
  13. protected const string GridName = "grid_agentRisk";
  14. private string ViewFunctionId = "20191000";
  15. private string AddEditFunctionId = "20191010";
  16. private readonly SwiftGrid _grid = new SwiftGrid();
  17. private readonly RemittanceLibrary _sl = new RemittanceLibrary();
  18. private readonly agentRiskProfilingDao obj = new agentRiskProfilingDao();
  19. private string type = "";
  20. protected void Page_Load(object sender, EventArgs e)
  21. {
  22. if (!IsPostBack)
  23. {
  24. Authenticate();
  25. type = GetStatic.ReadQueryString("type", "");
  26. Session["riskProfiling"] = null;
  27. if (type.ToLower() == "risk")
  28. {
  29. trNew.Visible = false;
  30. trRiskProfiling.Visible = true;
  31. trReviewercomment.Visible = false;
  32. trReviewerdetails.Visible = false;
  33. btnSaveRiskProfiling.Visible = true;
  34. btnSaveReview.Visible = false;
  35. reviewDetails.InnerHtml = "";
  36. loadgrid();
  37. }
  38. else if (type.ToLower() == "review")
  39. {
  40. trNew.Visible = false;
  41. trRiskProfiling.Visible = true;
  42. trReviewercomment.Visible = true;
  43. btnSaveReview.Visible = true;
  44. trReviewerdetails.Visible = false;
  45. btnSaveRiskProfiling.Visible = false;
  46. reviewDetails.InnerHtml = "";
  47. loadgrid();
  48. makeDatagridReadOnly();
  49. }
  50. else if (type.ToLower() == "riskhistory")
  51. {
  52. trNew.Visible = false;
  53. trRiskProfiling.Visible = true;
  54. trReviewercomment.Visible = true;
  55. btnSaveReview.Visible = false;
  56. trReviewerdetails.Visible = true;
  57. btnSaveRiskProfiling.Visible = false;
  58. //reviewDetails.InnerHtml = "";
  59. reviewersComment.Attributes.Add("readOnly", "true");
  60. loadgrid();
  61. makeDatagridReadOnly();
  62. }
  63. else
  64. {
  65. trNew.Visible = true;
  66. trRiskProfiling.Visible = false;
  67. }
  68. }
  69. }
  70. private void makeDatagridReadOnly()
  71. {
  72. for (int i = 0; i < riskProfiling.Items.Count; i++)
  73. {
  74. txtScore = (TextBox)riskProfiling.Items[i].FindControl("txtScore");
  75. txtRemarks = (TextBox)riskProfiling.Items[i].FindControl("txtRemarks");
  76. txtScore.Attributes.Add("readOnly", "true");
  77. txtScore.Attributes.Remove("onblur");
  78. txtRemarks.Attributes.Add("readOnly", "true");
  79. }
  80. }
  81. private void Authenticate()
  82. {
  83. _sl.CheckAuthentication(ViewFunctionId);
  84. }
  85. private void loadgrid()
  86. {
  87. DataSet ds = null;
  88. var assessementId = GetStatic.ReadQueryString("aId", "");
  89. var agentId = GetStatic.ReadQueryString("agentId", "");
  90. ds = obj.profilingCriteria(GetStatic.GetUser(), agentId, assessementId);
  91. if (null != ds)
  92. {
  93. Session["riskProfiling"] = ds.Tables[0];
  94. if (ds.Tables.Count > 1)
  95. {
  96. DataTable scoringCriteria = ds.Tables[1];
  97. for (int i = 0; i < scoringCriteria.Rows.Count; i++)
  98. {
  99. hdnscoringCriteria.Value += scoringCriteria.Rows[i]["scoreTo"].ToString() + ":" + scoringCriteria.Rows[i]["rating"].ToString() + ":";
  100. }
  101. }
  102. riskProfiling.DataSource = ds.Tables[0];
  103. riskProfiling.DataBind();
  104. try
  105. {
  106. DataRow dr = ds.Tables[0].Rows[0];
  107. if (null != dr["reviewerComment"])
  108. {
  109. reviewersComment.Text = dr["reviewerComment"].ToString();
  110. }
  111. if (null != dr["reviewedDate"])
  112. {
  113. var reviewDate = dr["reviewedDate"].ToString();
  114. if (!string.IsNullOrEmpty(reviewDate))
  115. {
  116. makeDatagridReadOnly();
  117. }
  118. }
  119. if (type.ToLower() == "riskhistory")
  120. {
  121. if (null != dr["createdBy"] && null != dr["createdDate"] && null != dr["reviewdBy"] && null != dr["reviewedDate"])
  122. {
  123. reviewDetails.InnerHtml = "<br /><b>Created By</b>: " + dr["createdBy"].ToString() + " &nbsp;&nbsp;<b>Created Date</b>: " + dr["createdDate"] + " &nbsp;&nbsp;<b>Review By</b>: " + dr["reviewdBy"] + " &nbsp;&nbsp;<b>Reviewed Date</b>: " + dr["reviewedDate"] + "";
  124. }
  125. }
  126. }
  127. catch (Exception ex)
  128. { }
  129. }
  130. }
  131. private Label lblCriteria;
  132. private TextBox txtMinScore;
  133. private TextBox txtMaxScore;
  134. private TextBox txtScore;
  135. private TextBox txtRemarks;
  136. private TextBox txtScoreTotal;
  137. private TextBox txtRiskCategory;
  138. private decimal totalScore = 0;
  139. protected void riskProfiling_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
  140. {
  141. if (e.Item.ItemType == ListItemType.Item | e.Item.ItemType == ListItemType.AlternatingItem)
  142. {
  143. lblCriteria = (Label)e.Item.FindControl("lblCriteria");
  144. txtMinScore = (TextBox)e.Item.FindControl("txtMinScore");
  145. txtMaxScore = (TextBox)e.Item.FindControl("txtMaxScore");
  146. txtScore = (TextBox)e.Item.FindControl("txtScore");
  147. txtRemarks = (TextBox)e.Item.FindControl("txtRemarks");
  148. txtScore.Attributes.Add("onfocus", "resetInput(this, '0', 1, true);");
  149. txtScore.Attributes.Add("onblur", "resetInput(this, '0', 2, true, 'true');CalculateScore();");
  150. txtScore.Attributes.Add("onkeydown", "return numericOnly(this, (event?event:evt), true,'true');");
  151. txtScore.Attributes.Add("onpaste", "return manageOnPaste(this);");
  152. txtScore.Attributes.Add("class", "form-control");
  153. txtRemarks.Attributes.Add("class", "form-control");
  154. // Misc.MakeNumericTextbox(ref txtScore);
  155. txtRemarks = (TextBox)e.Item.FindControl("txtRemarks");
  156. DataTable dt = new DataTable();
  157. dt = (DataTable)Session["riskProfiling"];
  158. if (dt != null)
  159. {
  160. lblCriteria.Text = dt.Rows[e.Item.ItemIndex]["topic"].ToString();
  161. txtMinScore.Text = dt.Rows[e.Item.ItemIndex]["minimumScore"].ToString();
  162. txtMaxScore.Text = dt.Rows[e.Item.ItemIndex]["maximumScore"].ToString();
  163. txtScore.Text = dt.Rows[e.Item.ItemIndex]["score"].ToString();
  164. txtRemarks.Text = dt.Rows[e.Item.ItemIndex]["remarks"].ToString();
  165. totalScore += (txtScore.Text.Trim() != "") ? Convert.ToDecimal(txtScore.Text) : 0;
  166. }
  167. }
  168. if (e.Item.ItemType == ListItemType.Footer)
  169. {
  170. txtScoreTotal = (TextBox)e.Item.FindControl("txtScoreTotal");
  171. Misc.MakeDisabledTextbox(ref txtScoreTotal);
  172. txtScoreTotal.Text = (totalScore > 0) ? totalScore.ToString() : "";
  173. txtScoreTotal.Attributes.Add("class", "form-control");
  174. txtRiskCategory = (TextBox)e.Item.FindControl("txtRiskCategory");
  175. txtRiskCategory.Attributes.Add("readOnly", "true");
  176. string[] scoringCriteria = hdnscoringCriteria.Value.Split(':');
  177. var scCriteria = "";
  178. var scColor = "";
  179. if (totalScore <= Convert.ToDecimal(scoringCriteria[0]))
  180. {
  181. scCriteria = scoringCriteria[1];
  182. scColor = "#87a96b";
  183. }
  184. else if (totalScore <= Convert.ToDecimal(scoringCriteria[2]))
  185. {
  186. scCriteria = scoringCriteria[3];
  187. scColor = "#a1caf1";
  188. }
  189. else if (totalScore > Convert.ToDecimal(scoringCriteria[2]))
  190. {
  191. scCriteria = scoringCriteria[5];
  192. scColor = "#fd5e53";
  193. }
  194. txtRiskCategory.Text = scCriteria;
  195. txtRiskCategory.Style.Add("background-color", scColor);
  196. //Misc.MakeDisabledTextbox(ref txtRiskCategory);
  197. }
  198. }
  199. protected void btnSaveAgent_Click(object sender, EventArgs e)
  200. {
  201. Page.Validate();
  202. if (Page.IsValid)
  203. {
  204. var dbResult = obj.SaveRiskProfilingAgent(GetStatic.GetUser(), hddAgentId.Value, assessementdate.Text);
  205. //if (dbResult.ErrorCode.Equals("0"))
  206. //GetStatic.AlertMessage(Page, dbResult.Msg);
  207. ManageMessage(dbResult);
  208. }
  209. }
  210. protected void btnSaveRiskProfiling_Click(object sender, EventArgs e)
  211. {
  212. var sb = new StringBuilder("<root>");
  213. var assessementId = GetStatic.ReadQueryString("aId", "");
  214. decimal totalScore = 0;
  215. var rating = "";
  216. for (int i = 0; i < riskProfiling.Items.Count; i++)
  217. {
  218. var criteriaId = riskProfiling.DataKeys[i].ToString();
  219. txtScore = (TextBox)riskProfiling.Items[i].FindControl("txtScore");
  220. txtRemarks = (TextBox)riskProfiling.Items[i].FindControl("txtRemarks");
  221. //txtRiskCategory=(TextBox)riskProfiling.Items[i].FindControl("txtRiskCategory");
  222. sb.Append("<row assessementId=\"" + assessementId + "\" ");
  223. sb.Append(" criteriaId=\"" + criteriaId + "\" ");
  224. sb.Append(" score=\"" + txtScore.Text + "\" ");
  225. sb.Append(" remarks=\"" + obj.FilterStringForXml(txtRemarks.Text.Trim()) + "\" />");
  226. totalScore += Convert.ToDecimal((txtScore.Text.Trim() == "") ? "0" : txtScore.Text.Trim());
  227. }
  228. Table tbl = (Table)riskProfiling.Controls[0];
  229. DataGridItem footer = (DataGridItem)tbl.Controls[tbl.Controls.Count - 1]; //header would be tbl.Controls[0]
  230. txtRiskCategory = (TextBox)footer.FindControl("txtRiskCategory");
  231. rating = txtRiskCategory.Text.Trim();
  232. sb.Append("</root>");
  233. var dbResult = obj.SaveRiskProfiling(GetStatic.GetUser(), sb, assessementId, rating, totalScore);
  234. //GetStatic.AlertMessage(this, dbResult.Msg);
  235. loadgrid();
  236. ManageMessage(dbResult);
  237. }
  238. protected void btnSaveReview_Click(object sender, EventArgs e)
  239. {
  240. if (GetStatic.ReadQueryString("type", "") == "review")
  241. {
  242. var assessementId = GetStatic.ReadQueryString("aId", "");
  243. var agentId = GetStatic.ReadQueryString("agentId", "");
  244. var dbResult = obj.SaveReview(GetStatic.GetUser(), agentId, assessementId, reviewersComment.Text);
  245. ManageMessage(dbResult);
  246. }
  247. }
  248. private void ManageMessage(DbResult dbResult)
  249. {
  250. var url = "List.aspx";
  251. GetStatic.CallJSFunction(this, string.Format("CallBackSave('{0}','{1}", dbResult.ErrorCode, dbResult.Msg.Replace("'", "") + "','" + url + "')"));
  252. }
  253. }
  254. }