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.

441 lines
16 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using Swift.web.Component.Grid;
  4. using Swift.web.Component.Grid.gridHelper;
  5. using Swift.web.Library;
  6. using Swift.DAL.BL.Remit.BranchRating;
  7. using System.Data;
  8. using System.Web.UI.WebControls;
  9. using System.Text;
  10. using Swift.DAL.SwiftDAL;
  11. using System.Web;
  12. using System.Web.UI;
  13. using System.Text.RegularExpressions;
  14. namespace Swift.web.Remit.RiskBaseAnalysis.BranchRatingNEW
  15. {
  16. public partial class print : System.Web.UI.Page
  17. {
  18. protected const string GridName = "grid_branchRatingNEW";
  19. private string ViewFunctionId = "20191600,40241200";
  20. private string AddEditFunctionId = "20191610";
  21. private readonly SwiftGrid _grid = new SwiftGrid();
  22. private readonly RemittanceLibrary _sl = new RemittanceLibrary();
  23. private readonly BranchRatingNEWDao obj = new BranchRatingNEWDao();
  24. string type = "";
  25. bool ctrlEnable;
  26. protected void Page_Load(object sender, EventArgs e)
  27. {
  28. _sl.CheckSession();
  29. type = GetStatic.ReadQueryString("type", "").ToLower();
  30. if (!IsPostBack)
  31. {
  32. Authenticate();
  33. printRatingDetails();
  34. trratingDetails.Visible = true;
  35. trRatingComment.Visible = true;
  36. trReviewercomment.Visible = true;
  37. trApproverComment.Visible = true;
  38. loadgrid(type);
  39. }
  40. if (type == "rating" || type == "review" || type == "approve" || type == "print")
  41. loadgrid(type, true);
  42. }
  43. void printRatingDetails()
  44. {
  45. Branch.Text = GetStatic.ReadQueryString("bName", "");
  46. ReviewPeriod.Text = GetStatic.ReadQueryString("rPeriod", "");
  47. Reviewedon.Text = GetStatic.ReadQueryString("ron", "");
  48. Reviewer.Text = GetStatic.ReadQueryString("r", "");
  49. ratedby.Text = GetStatic.ReadQueryString("ratedby", "");
  50. ratedOn.Text = GetStatic.ReadQueryString("ratedon", "");
  51. approvedBy.Text = GetStatic.ReadQueryString("appby", "");
  52. approvedOn.Text = GetStatic.ReadQueryString("appon", "");
  53. }
  54. private void Authenticate()
  55. {
  56. _sl.CheckAuthentication(ViewFunctionId + "," + AddEditFunctionId);
  57. }
  58. void loadgrid(string actionType, bool isPagePostBack = false)
  59. {
  60. DataSet ds = null;
  61. var brDetaildId = GetStatic.ReadQueryString("brId", "");
  62. var branchId = GetStatic.ReadQueryString("bId", "");
  63. ds = obj.ratingCriteria(GetStatic.GetUser(), branchId, brDetaildId);
  64. ctrlEnable = (!isPagePostBack) ? true : ctrlEnable;
  65. if (null != ds)
  66. {
  67. if (ds.Tables.Count > 2)
  68. {
  69. DataTable scoringCriteria = ds.Tables[2];
  70. for (int i = 0; i < scoringCriteria.Rows.Count; i++)
  71. {
  72. hdnscoringCriteria.Value += scoringCriteria.Rows[i]["scoreTo"].ToString() + ":" + scoringCriteria.Rows[i]["rating"].ToString() + ":";
  73. }
  74. }
  75. if (!isPagePostBack)
  76. {
  77. string expression = "type = 'C'";
  78. DataRow[] drows;
  79. drows = ds.Tables[0].Select(expression);
  80. if (drows[0]["ratingDate"].ToString() != "")
  81. {
  82. ratingComment.InnerText = drows[0]["ratingComment"].ToString();
  83. trRatingComment.Visible = true;
  84. ctrlEnable = false;
  85. }
  86. }
  87. WriteRow(ds, ctrlEnable);
  88. PrintSummaryTable(ds);
  89. }
  90. if (actionType == "riskhistory" || actionType == "approve" || actionType == "print")
  91. {
  92. string expression = "type = 'C'";
  93. DataRow[] drows;
  94. drows = ds.Tables[0].Select(expression);
  95. if (drows[0]["reviewedDate"].ToString() != "")
  96. {
  97. trReviewercomment.Visible = true;
  98. reviewersComment.InnerText = drows[0]["reviewerComment"].ToString();
  99. }
  100. if (drows[0]["approvedDate"].ToString() != "")
  101. {
  102. trApproverComment.Visible = true;
  103. approversComment.InnerText = drows[0]["approverComment"].ToString();
  104. }
  105. }
  106. }
  107. void WriteRow(DataSet ds, bool ctrlEnable)
  108. {
  109. bool isControlReadOnly = true; //ctrlEnable; //(actionType == "rating") ? true : false;
  110. myData.CssClass = "TBL";
  111. myData.Rows.Clear();
  112. // Header
  113. var tr = new TableRow();
  114. tr.Style.Add("background-color", "#cccccc");
  115. var td = new TableCell();
  116. td.ColumnSpan = 2;
  117. td.Text = "Risk Category";
  118. td.Style.Add(HtmlTextWriterStyle.TextAlign, "center");
  119. tr.Cells.Add(td);
  120. td = new TableCell();
  121. td.ColumnSpan = 2;
  122. td.Text = "Scoring";
  123. td.Style.Add(HtmlTextWriterStyle.TextAlign, "center");
  124. tr.Cells.Add(td);
  125. myData.Rows.Add(tr);
  126. tr = new TableRow();
  127. tr.Style.Add("background-color", "#333333");
  128. td = new TableCell();
  129. td.ColumnSpan = 2;
  130. td.Text = "";
  131. tr.Cells.Add(td);
  132. td = new TableCell();
  133. td.Text = "Marks (1-5)";
  134. td.Style.Add(HtmlTextWriterStyle.TextAlign, "center");
  135. td.Style.Add(HtmlTextWriterStyle.Color, "white");
  136. tr.Cells.Add(td);
  137. td = new TableCell();
  138. td.Text = "Remarks";
  139. td.Style.Add(HtmlTextWriterStyle.TextAlign, "center");
  140. td.Style.Add(HtmlTextWriterStyle.Color, "white");
  141. tr.Cells.Add(td);
  142. myData.Rows.Add(tr);
  143. int index = 0;
  144. int subCatIndex = 0;
  145. var Category = "";
  146. foreach (DataRow item in ds.Tables[0].Rows)
  147. {
  148. index++;
  149. tr = new TableRow();
  150. if (item["type"].ToString() == "A")
  151. {
  152. td = new TableCell();
  153. td.ColumnSpan = 4;
  154. td.Text = item["description"].ToString();
  155. Category = item["summaryDescription"].ToString();
  156. tr.Style.Add("background-color", "Red");
  157. td.Style.Add(HtmlTextWriterStyle.TextAlign, "center");
  158. td.Style.Add(HtmlTextWriterStyle.Color, "white");
  159. td.Style.Add(HtmlTextWriterStyle.FontWeight, "bold");
  160. tr.Cells.Add(td);
  161. subCatIndex = 0;
  162. }
  163. else if (item["type"].ToString() == "B")
  164. {
  165. subCatIndex++;
  166. string expression = "ParentId = '" + item["ParentId"] + "' and type = 'C'";
  167. DataRow[] foundRows;
  168. foundRows = ds.Tables[0].Select(expression); // Use the Select method to find all rows matching the filter.
  169. td = new TableCell();
  170. td.RowSpan = foundRows.Length + 1;
  171. td.Text = subCatIndex.IntToLetter();
  172. td.CssClass = "tdSubCatIndex";
  173. tr.Cells.Add(td);
  174. td = new TableCell();
  175. td.CssClass = "tdContent";
  176. td.Text = item["description"].ToString();
  177. td.Style.Add("font-weight", "bold");
  178. td.Width = 400;
  179. tr.Cells.Add(td);
  180. td = new TableCell();
  181. td.Text = "";
  182. td.ColumnSpan = 2;
  183. td.Width = 200;
  184. tr.Cells.Add(td);
  185. }
  186. else if (item["type"].ToString() == "C")
  187. {
  188. td = new TableCell();
  189. td.CssClass = "tdContent";
  190. HiddenField hdnId = new HiddenField();
  191. hdnId.Value = item["rowId"].ToString();
  192. hdnId.ID = "hdn_" + index.ToString();
  193. td.Controls.Add(hdnId);
  194. System.Web.UI.HtmlControls.HtmlGenericControl dvContent =
  195. new System.Web.UI.HtmlControls.HtmlGenericControl("DIV");
  196. dvContent.Style.Add(HtmlTextWriterStyle.Width, "500px");
  197. dvContent.Attributes.Add("class", "tdContent");
  198. dvContent.InnerHtml = "<i>(" + Convert.ToInt32(item["displayOrder"].ToString()).ToRomanNumeral() + ") " + item["description"].ToString() + "</i>";
  199. td.Controls.Add(dvContent);
  200. tr.Cells.Add(td);
  201. td = new TableCell();
  202. td.CssClass = "tdddl";
  203. var ddl = new DropDownList();
  204. ddl.ID = "ddl_" + index.ToString();
  205. //ddl.Width = 100;
  206. ddl.CssClass = "ddl";
  207. ddl.Items.Insert(0, new ListItem("Select", ""));
  208. for (int i = 0; i <= 5; i++)
  209. {
  210. ddl.Items.Insert(i + 1, new ListItem((i).ToString("0.00") + " - " + ((i == 0 || i == 1) ? "Low" : (i == 2 || i == 3) ? "Medium" : "High"), (i).ToString("0.00")));
  211. }
  212. ddl.SelectedValue = item["score"].ToString();
  213. ddl.Enabled = false;
  214. td.Controls.Add(ddl);
  215. tr.Cells.Add(td);
  216. td = new TableCell();
  217. var txt = new System.Web.UI.HtmlControls.HtmlGenericControl("DIV"); //new TextBox();
  218. txt.ID = "txt_" + index.ToString();
  219. //txt.Width = 300;
  220. //txt.CssClass = "RemarksTextBox";
  221. //txt.TextMode = TextBoxMode.MultiLine;
  222. //txt.Rows = 3;
  223. txt.InnerText = item["remarks"].ToString();
  224. td.Controls.Add(txt);
  225. tr.Cells.Add(td);
  226. }
  227. myData.Rows.Add(tr);
  228. }
  229. hdnRowsCount.Value = index.ToString();
  230. }
  231. void PrintSummaryTable(DataSet ds)
  232. {
  233. Dictionary<string, decimal> CatTotalList = new Dictionary<string, decimal>();
  234. //string[,] weight = new string[,] { {"","","","" }, { } };
  235. var catWeightList = new ItemList<string, decimal>();
  236. //ItemList<string, decimal> subCatTotalList;
  237. var maxScore = 5;
  238. var totalMaxScore = 0; // maxScore*itemCount
  239. decimal totalScore = 0;
  240. decimal Score = 0;
  241. string strTable = @" <table runat='server' id='tblSummary' width='300px'>
  242. <tr>
  243. <th width='200px' style='text-align: left;'>
  244. Risk Category
  245. </th>
  246. <th width='50px' style='text-align: left;'>
  247. Score
  248. </th>
  249. <th width='50px' style='text-align: left;'>
  250. Rating
  251. </th>
  252. </tr>";
  253. if (ds.Tables.Count > 1 && ds.Tables[1].Rows.Count > 1)
  254. {
  255. DataTable dtSummary = ds.Tables[1];
  256. if (dtSummary.Rows.Count > 1)
  257. {
  258. for (int i = 0; i < dtSummary.Rows.Count; i++)
  259. {
  260. decimal score;
  261. decimal ratingScore = 0;
  262. if (decimal.TryParse(dtSummary.Rows[i]["score"].ToString(), out score))
  263. ratingScore = score;
  264. strTable += "<tr class='" + rating(ratingScore).ToLower() + "'><td>";
  265. strTable += dtSummary.Rows[i]["riskCategory"].ToString() + "</td><td>";
  266. strTable += ratingScore.ToString("0.00") + "</td><td>" + rating(ratingScore) + "</td></tr>";
  267. }
  268. }
  269. }
  270. else
  271. {
  272. string expression = "type = 'A'";
  273. DataRow[] Category;
  274. Category = ds.Tables[0].Select(expression);
  275. int index = 0;
  276. foreach (var item in Category)
  277. {
  278. index++;
  279. strTable += "<tr><td>";
  280. strTable += item["summaryDescription"].ToString() + "</td><td>";
  281. catWeightList.Add(item["summaryDescription"].ToString(), Convert.ToDecimal(item["weight"].ToString()));
  282. string expression1 = "ParentId Like '" + index.ToString() + ".%' and type = 'B'";
  283. DataRow[] SubCategory;
  284. SubCategory = ds.Tables[0].Select(expression1);
  285. decimal subCatWeight = Convert.ToDecimal(item["weight"].ToString()) / SubCategory.Length;
  286. int subCatIndex = 0;
  287. //subCatTotalList = new ItemList<string, decimal>();
  288. Dictionary<string, decimal> subCatTotalList = new Dictionary<string, decimal>();
  289. foreach (var subCat in SubCategory)
  290. {
  291. subCatIndex++;
  292. expression = "ParentId Like '" + index.ToString() + "." + subCatIndex.ToString() + "' and type = 'C'";
  293. DataRow[] foundRows;
  294. foundRows = ds.Tables[0].Select(expression);
  295. var itemCount = foundRows.Length;
  296. totalMaxScore = maxScore * itemCount;
  297. decimal subTotal = 0;
  298. foreach (var row in foundRows)
  299. {
  300. if (decimal.TryParse(row["score"].ToString(), out Score))
  301. subTotal += Score;
  302. }
  303. subCatTotalList.Add(subCatIndex.IntToLetter(), (subTotal / totalMaxScore) * subCatWeight);
  304. }
  305. decimal subCatTotal = 0;
  306. foreach (KeyValuePair<string, decimal> kvp in subCatTotalList)
  307. {
  308. subCatTotal += kvp.Value;
  309. }
  310. var score = (subCatTotal / Convert.ToDecimal(item["weight"].ToString())) * maxScore;
  311. strTable += (score).ToString("0.00") + "</td><td>" + rating(score) + "</td></tr>";
  312. totalScore += score * Convert.ToDecimal(item["weight"].ToString()) / 100;
  313. }
  314. strTable += "<tr><td>";
  315. strTable += "Overall " + "</td><td>";
  316. strTable += (totalScore).ToString("0.00") + "</td><td>" + rating(totalScore) + "</td></tr>";
  317. }
  318. strTable += "</table>";
  319. divSummary.InnerHtml = strTable;
  320. }
  321. string rating(decimal score)
  322. {
  323. string result = "";
  324. string[] scoringCriteria = hdnscoringCriteria.Value.Split(':');
  325. if (scoringCriteria.Length >= 3)
  326. {
  327. if (score <= Convert.ToDecimal(scoringCriteria[0]))
  328. result = scoringCriteria[1];
  329. else if (score <= Convert.ToDecimal(scoringCriteria[2]))
  330. result = scoringCriteria[3];
  331. else if (score > Convert.ToDecimal(scoringCriteria[2]))
  332. result = scoringCriteria[5];
  333. }
  334. return result;
  335. }
  336. }
  337. }