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.

915 lines
34 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 Manage : System.Web.UI.Page
  17. {
  18. protected const string GridName = "grid_branchRatingNEW";
  19. private string ViewFunctionId = "20191600";
  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. if (type == "rating" || type == "review" || type == "approve")
  35. {
  36. trNew.Visible = false;
  37. trratingDetails.Visible = true;
  38. checkIsRatingOrReviewOrApprove(type);
  39. loadgrid(type, false);
  40. }
  41. else if (type == "riskhistory")
  42. {
  43. trNew.Visible = false;
  44. trratingDetails.Visible = true;
  45. trReviewercomment.Visible = true;
  46. trApproverComment.Visible = true;
  47. checkIsRatingOrReviewOrApprove(type);
  48. loadgrid(type);
  49. }
  50. else
  51. {
  52. trNew.Visible = true;
  53. trratingDetails.Visible = false;
  54. }
  55. }
  56. if (type == "rating" || type == "review" || type == "approve")
  57. loadgrid(type, true);
  58. }
  59. void checkIsRatingOrReviewOrApprove(string actionType)
  60. {
  61. if (actionType == "rating")
  62. {
  63. btnBranchRating.Visible = true;
  64. btnReview.Visible = false;
  65. trReviewercomment.Visible = false;
  66. trApproverComment.Visible = false;
  67. btnApprove.Visible = false;
  68. }
  69. else if (actionType == "review")
  70. {
  71. btnBranchRating.Visible = false;
  72. btnReview.Visible = true;
  73. trReviewercomment.Visible = true;
  74. trApproverComment.Visible = false;
  75. btnApprove.Visible = false;
  76. }
  77. else if (actionType == "approve")
  78. {
  79. btnReview.Visible = false;
  80. btnBranchRating.Visible = false;
  81. trReviewercomment.Visible = true;
  82. trApproverComment.Visible = true;
  83. btnApprove.Visible = true;
  84. }
  85. else if (actionType == "riskhistory")
  86. {
  87. btnReview.Visible = false;
  88. btnBranchRating.Visible = false;
  89. btnApprove.Visible = false;
  90. trReviewercomment.Visible = true;
  91. trApproverComment.Visible = true;
  92. reviewersComment.Enabled = false;
  93. approversComment.Enabled = false;
  94. }
  95. else
  96. {
  97. btnReview.Visible = false;
  98. trReviewercomment.Visible = false;
  99. btnBranchRating.Visible = false;
  100. trApproverComment.Visible = false;
  101. btnApprove.Visible = false;
  102. }
  103. }
  104. void printRatingDetails()
  105. {
  106. Branch.Text = GetStatic.ReadQueryString("bName", "");
  107. ReviewPeriod.Text = GetStatic.ReadQueryString("rPeriod", "");
  108. Reviewedon.Text = GetStatic.ReadQueryString("ron", "");
  109. Reviewer.Text = GetStatic.ReadQueryString("r", "");
  110. ratedby.Text = GetStatic.ReadQueryString("ratedby", "");
  111. ratedOn.Text = GetStatic.ReadQueryString("ratedon", "");
  112. approvedBy.Text = GetStatic.ReadQueryString("appby", "");
  113. approvedOn.Text = GetStatic.ReadQueryString("appon", "");
  114. string strPrintUrl = "print.aspx?type=print&brId=" + GetStatic.ReadQueryString("brId", "") +
  115. "&bId=" + GetStatic.ReadQueryString("bId", "") + "&bName=" + GetStatic.ReadQueryString("bName", "") +
  116. "&ratedby=" + GetStatic.ReadQueryString("ratedby", "") + "&ratedon=" + GetStatic.ReadQueryString("ratedon", "") +
  117. "&ron=" + GetStatic.ReadQueryString("ron", "") + "&r=" + GetStatic.ReadQueryString("r", "") +
  118. "&appby=" + GetStatic.ReadQueryString("appby", "") + "&appon=" + GetStatic.ReadQueryString("appon", "") + "&rPeriod=" + GetStatic.ReadQueryString("rPeriod", "") + "";
  119. printBtn.Attributes.Add("onClick", "openPrint('" + strPrintUrl + "');");
  120. }
  121. private void Authenticate()
  122. {
  123. _sl.CheckAuthentication(ViewFunctionId + "," + AddEditFunctionId);
  124. }
  125. void loadgrid(string actionType, bool isPagePostBack = false)
  126. {
  127. DataSet ds = null;
  128. var brDetaildId = GetStatic.ReadQueryString("brId", "");
  129. var branchId = GetStatic.ReadQueryString("bId", "");
  130. ds = obj.ratingCriteria(GetStatic.GetUser(), branchId, brDetaildId);
  131. ctrlEnable = (!isPagePostBack) ? true : ctrlEnable;
  132. if (null != ds)
  133. {
  134. if (ds.Tables.Count > 2)
  135. {
  136. DataTable scoringCriteria = ds.Tables[2];
  137. for (int i = 0; i < scoringCriteria.Rows.Count; i++)
  138. {
  139. hdnscoringCriteria.Value += scoringCriteria.Rows[i]["scoreTo"].ToString() + ":" + scoringCriteria.Rows[i]["rating"].ToString() + ":";
  140. }
  141. }
  142. if (!isPagePostBack)
  143. {
  144. string expression = "type = 'C'";
  145. DataRow[] drows;
  146. drows = ds.Tables[0].Select(expression);
  147. if (drows[0]["ratingDate"].ToString() != "")
  148. {
  149. trWarning.Visible = false;
  150. ddlRatingCompleted.SelectedValue = "Y";
  151. ratingComment.Text = drows[0]["ratingComment"].ToString();
  152. trRatingComment.Visible = true;
  153. //trRatersDetails.Visible = true;
  154. ctrlEnable = false;
  155. ddlRatingCompleted.Enabled = false;
  156. ratingComment.Enabled = false;
  157. //ratingDetails.InnerHtml = "<br /><b>Rating By</b>: " + drows[0]["ratingby"].ToString() + " &nbsp;&nbsp;<b>Rating Date</b>: " + drows[0]["ratingDate"].ToString() + "";
  158. }
  159. else
  160. {
  161. trWarning.Visible = true;
  162. ddlRatingCompleted.SelectedValue = "N";
  163. trRatingComment.Visible = false;
  164. //trRatersDetails.Visible = false;
  165. ctrlEnable = true;
  166. //ratingDetails.InnerHtml = "";
  167. ddlRatingCompleted.Enabled = true;
  168. ratingComment.Enabled = true;
  169. }
  170. }
  171. WriteRow(ds, ctrlEnable);
  172. PrintSummaryTable(ds);
  173. }
  174. if (actionType == "riskhistory" || actionType == "approve")
  175. {
  176. string expression = "type = 'C'";
  177. DataRow[] drows;
  178. drows = ds.Tables[0].Select(expression);
  179. //reviewersComment.Text = ds.Tables[0].Rows[0]["reviewerComment"].ToString();
  180. //approversComment.Text = ds.Tables[0].Rows[0]["approverComment"].ToString();
  181. if (drows[0]["reviewedDate"].ToString() != "")
  182. {
  183. trReviewercomment.Visible = true;
  184. //trReviewerdetails.Visible = true;
  185. reviewersComment.Text = drows[0]["reviewerComment"].ToString();
  186. reviewersComment.Enabled = false;
  187. //reviewDetails.InnerHtml = "<br /><b>Reviewed By</b>: " + drows[0]["reviewedBy"].ToString() + " &nbsp;&nbsp;<b>Reviewed Date</b>: " + drows[0]["reviewedDate"].ToString() + "";
  188. }
  189. else
  190. {
  191. trReviewercomment.Visible = false;
  192. //trReviewerdetails.Visible = false;
  193. //reviewDetails.InnerHtml = "";
  194. }
  195. if (actionType != "approve")
  196. {
  197. if (drows[0]["approvedDate"].ToString() != "")
  198. {
  199. trApproverComment.Visible = true;
  200. //trApproverdetails.Visible = true;
  201. approversComment.Text = drows[0]["approverComment"].ToString();
  202. //approveDetails.InnerHtml = "<br /><b>Approved By</b>: " + drows[0]["approvedBy"].ToString() + " &nbsp;&nbsp;<b>Approved Date</b>: " + drows[0]["approvedDate"].ToString() + ""; ;
  203. }
  204. else
  205. {
  206. trApproverComment.Visible = false;
  207. //trApproverdetails.Visible = false;
  208. //approveDetails.InnerHtml = "";
  209. }
  210. }
  211. else
  212. {
  213. trApproverComment.Visible = true;
  214. //trApproverdetails.Visible = true;
  215. }
  216. }
  217. }
  218. void WriteRow(DataSet ds, bool ctrlEnable)
  219. {
  220. bool isControlReadOnly = ctrlEnable; //(actionType == "rating") ? true : false;
  221. myData.CssClass = "TBL";
  222. myData.Rows.Clear();
  223. // Header
  224. var tr = new TableRow();
  225. tr.Style.Add("background-color", "#cccccc");
  226. var td = new TableCell();
  227. td.ColumnSpan = 2;
  228. td.Text = "Risk Category";
  229. td.Style.Add(HtmlTextWriterStyle.TextAlign, "center");
  230. tr.Cells.Add(td);
  231. td = new TableCell();
  232. td.ColumnSpan = 2;
  233. td.Text = "Scoring";
  234. td.Style.Add(HtmlTextWriterStyle.TextAlign, "center");
  235. tr.Cells.Add(td);
  236. myData.Rows.Add(tr);
  237. tr = new TableRow();
  238. tr.Style.Add("background-color", "#333333");
  239. td = new TableCell();
  240. td.ColumnSpan = 2;
  241. td.Text = "";
  242. tr.Cells.Add(td);
  243. td = new TableCell();
  244. td.Text = "Marks (1-5)";
  245. td.Style.Add(HtmlTextWriterStyle.TextAlign, "center");
  246. td.Style.Add(HtmlTextWriterStyle.Color, "white");
  247. tr.Cells.Add(td);
  248. td = new TableCell();
  249. td.Text = "Remarks";
  250. td.Style.Add(HtmlTextWriterStyle.TextAlign, "center");
  251. td.Style.Add(HtmlTextWriterStyle.Color, "white");
  252. tr.Cells.Add(td);
  253. myData.Rows.Add(tr);
  254. int index = 0;
  255. int subCatIndex = 0;
  256. var Category = "";
  257. foreach (DataRow item in ds.Tables[0].Rows)
  258. {
  259. index++;
  260. tr = new TableRow();
  261. if (item["type"].ToString() == "A")
  262. {
  263. td = new TableCell();
  264. td.ColumnSpan = 4;
  265. td.Text = item["description"].ToString();
  266. Category = item["summaryDescription"].ToString();
  267. tr.Style.Add("background-color", "Red");
  268. td.Style.Add(HtmlTextWriterStyle.TextAlign, "center");
  269. td.Style.Add(HtmlTextWriterStyle.Color, "white");
  270. td.Style.Add(HtmlTextWriterStyle.FontWeight, "bold");
  271. tr.Cells.Add(td);
  272. subCatIndex = 0;
  273. }
  274. else if (item["type"].ToString() == "B")
  275. {
  276. subCatIndex++;
  277. string expression = "ParentId = '" + item["ParentId"] + "' and type = 'C'";
  278. DataRow[] foundRows;
  279. foundRows = ds.Tables[0].Select(expression); // Use the Select method to find all rows matching the filter.
  280. td = new TableCell();
  281. td.RowSpan = foundRows.Length + 1;
  282. td.Text = subCatIndex.IntToLetter();
  283. td.CssClass = "tdSubCatIndex";
  284. tr.Cells.Add(td);
  285. td = new TableCell();
  286. td.CssClass = "tdContent";
  287. td.Text = item["description"].ToString();
  288. td.Style.Add("font-weight", "bold");
  289. td.Width = 400;
  290. tr.Cells.Add(td);
  291. td = new TableCell();
  292. td.Text = "";
  293. td.ColumnSpan = 2;
  294. td.Width = 200;
  295. tr.Cells.Add(td);
  296. }
  297. else if (item["type"].ToString() == "C")
  298. {
  299. td = new TableCell();
  300. td.CssClass = "tdContent";
  301. HiddenField hdnId = new HiddenField();
  302. hdnId.Value = item["rowId"].ToString();
  303. hdnId.ID = "hdn_" + index.ToString();
  304. td.Controls.Add(hdnId);
  305. System.Web.UI.HtmlControls.HtmlGenericControl dvContent =
  306. new System.Web.UI.HtmlControls.HtmlGenericControl("DIV");
  307. dvContent.Style.Add(HtmlTextWriterStyle.Width, "500px");
  308. dvContent.Attributes.Add("class", "tdContent");
  309. dvContent.InnerHtml = "<i>(" + Convert.ToInt32(item["displayOrder"].ToString()).ToRomanNumeral() + ") " + item["description"].ToString() + "</i>";
  310. td.Controls.Add(dvContent);
  311. tr.Cells.Add(td);
  312. td = new TableCell();
  313. td.CssClass = "tdddl";
  314. var ddl = new DropDownList();
  315. ddl.ID = "ddl_" + index.ToString();
  316. //ddl.Width = 100;
  317. ddl.CssClass = "ddl";
  318. ddl.Items.Insert(0, new ListItem("Select", ""));
  319. for (int i = 0; i <= 5; i++)
  320. {
  321. 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")));
  322. }
  323. ddl.SelectedValue = item["score"].ToString();
  324. ddl.Enabled = isControlReadOnly;
  325. td.Controls.Add(ddl);
  326. tr.Cells.Add(td);
  327. td = new TableCell();
  328. var txt = new TextBox();
  329. txt.ID = "txt_" + index.ToString();
  330. //txt.Width = 300;
  331. txt.CssClass = "RemarksTextBox";
  332. txt.TextMode = TextBoxMode.MultiLine;
  333. txt.Rows = 3;
  334. txt.Text = item["remarks"].ToString();
  335. var typet = GetStatic.ReadQueryString("type", "").ToLower();
  336. if (typet == "rating")
  337. txt.ReadOnly = false;
  338. else txt.ReadOnly = true;
  339. td.Controls.Add(txt);
  340. tr.Cells.Add(td);
  341. }
  342. myData.Rows.Add(tr);
  343. }
  344. hdnRowsCount.Value = index.ToString();
  345. }
  346. void PrintSummaryTable(DataSet ds)
  347. {
  348. Dictionary<string, decimal> CatTotalList = new Dictionary<string, decimal>();
  349. //string[,] weight = new string[,] { {"","","","" }, { } };
  350. var catWeightList = new ItemList<string, decimal>();
  351. //ItemList<string, decimal> subCatTotalList;
  352. var maxScore = 5;
  353. var totalMaxScore = 0; // maxScore*itemCount
  354. decimal totalScore = 0;
  355. decimal Score = 0;
  356. string strTable = @" <table runat='server' id='tblSummary' width='300px'>
  357. <tr>
  358. <th width='200px' style='text-align: left;'>
  359. Risk Category
  360. </th>
  361. <th width='50px' style='text-align: left;'>
  362. Score
  363. </th>
  364. <th width='50px' style='text-align: left;'>
  365. Rating
  366. </th>
  367. </tr>";
  368. if (ds.Tables.Count > 1 && ds.Tables[1].Rows.Count > 1)
  369. {
  370. DataTable dtSummary = ds.Tables[1];
  371. if (dtSummary.Rows.Count > 1)
  372. {
  373. for (int i = 0; i < dtSummary.Rows.Count; i++)
  374. {
  375. decimal score;
  376. decimal ratingScore = 0;
  377. if (decimal.TryParse(dtSummary.Rows[i]["score"].ToString(), out score))
  378. ratingScore = score;
  379. strTable += "<tr class='" + rating(ratingScore).ToLower() + "'><td>";
  380. strTable += dtSummary.Rows[i]["riskCategory"].ToString() + "</td><td>";
  381. strTable += ratingScore.ToString("0.00") + "</td><td>" + rating(ratingScore) + "</td></tr>";
  382. }
  383. }
  384. }
  385. else
  386. {
  387. string expression = "type = 'A'";
  388. DataRow[] Category;
  389. Category = ds.Tables[0].Select(expression);
  390. int index = 0;
  391. foreach (var item in Category)
  392. {
  393. index++;
  394. strTable += "<tr><td>";
  395. strTable += item["summaryDescription"].ToString() + "</td><td>";
  396. catWeightList.Add(item["summaryDescription"].ToString(), Convert.ToDecimal(item["weight"].ToString()));
  397. string expression1 = "ParentId Like '" + index.ToString() + ".%' and type = 'B'";
  398. DataRow[] SubCategory;
  399. SubCategory = ds.Tables[0].Select(expression1);
  400. decimal subCatWeight = Convert.ToDecimal(item["weight"].ToString()) / SubCategory.Length;
  401. int subCatIndex = 0;
  402. //subCatTotalList = new ItemList<string, decimal>();
  403. Dictionary<string, decimal> subCatTotalList = new Dictionary<string, decimal>();
  404. foreach (var subCat in SubCategory)
  405. {
  406. subCatIndex++;
  407. expression = "ParentId Like '" + index.ToString() + "." + subCatIndex.ToString() + "' and type = 'C'";
  408. DataRow[] foundRows;
  409. foundRows = ds.Tables[0].Select(expression);
  410. var itemCount = foundRows.Length;
  411. totalMaxScore = maxScore * itemCount;
  412. decimal subTotal = 0;
  413. foreach (var row in foundRows)
  414. {
  415. if (decimal.TryParse(row["score"].ToString(), out Score))
  416. subTotal += Score;
  417. }
  418. subCatTotalList.Add(subCatIndex.IntToLetter(), (subTotal / totalMaxScore) * subCatWeight);
  419. }
  420. decimal subCatTotal = 0;
  421. foreach (KeyValuePair<string, decimal> kvp in subCatTotalList)
  422. {
  423. subCatTotal += kvp.Value;
  424. }
  425. var score = (subCatTotal / Convert.ToDecimal(item["weight"].ToString())) * maxScore;
  426. strTable += (score).ToString("0.00") + "</td><td>" + rating(score) + "</td></tr>";
  427. totalScore += score * Convert.ToDecimal(item["weight"].ToString()) / 100;
  428. }
  429. strTable += "<tr><td>";
  430. strTable += "Overall " + "</td><td>";
  431. strTable += (totalScore).ToString("0.00") + "</td><td>" + rating(totalScore) + "</td></tr>";
  432. }
  433. strTable += "</table>";
  434. divSummary.InnerHtml = strTable;
  435. //DataSet ds1 = ConvertHTMLTablesToDataSet(strTable);
  436. }
  437. DataTable PrepareSummaryTable(DataTable dtDetails)
  438. {
  439. Dictionary<string, decimal> CatTotalList = new Dictionary<string, decimal>();
  440. var catWeightList = new ItemList<string, decimal>();
  441. var maxScore = 5;
  442. var totalMaxScore = 0;
  443. decimal totalScore = 0;
  444. decimal Score = 0;
  445. DataTable dt = new DataTable();
  446. dt.TableName = "dtSummary";
  447. dt.Columns.Add("brMasterId", typeof(string));
  448. dt.Columns.Add("riskCategory", typeof(string));
  449. dt.Columns.Add("score", typeof(string));
  450. dt.Columns.Add("rating", typeof(string));
  451. string expression = "type = 'A'";
  452. DataRow[] Category;
  453. Category = dtDetails.Select(expression);
  454. int index = 0;
  455. DataRow dr;
  456. foreach (var item in Category)
  457. {
  458. index++;
  459. dr = dt.NewRow();
  460. dr[0] = item["rowId"].ToString();
  461. dr[1] = item["summaryDescription"].ToString();
  462. catWeightList.Add(item["summaryDescription"].ToString(), Convert.ToDecimal(item["weight"].ToString()));
  463. string expression1 = "ParentId Like '" + index.ToString() + ".%' and type = 'B'";
  464. DataRow[] SubCategory;
  465. SubCategory = dtDetails.Select(expression1);
  466. decimal subCatWeight = Convert.ToDecimal(item["weight"].ToString()) / SubCategory.Length;
  467. int subCatIndex = 0;
  468. //subCatTotalList = new ItemList<string, decimal>();
  469. Dictionary<string, decimal> subCatTotalList = new Dictionary<string, decimal>();
  470. foreach (var subCat in SubCategory)
  471. {
  472. subCatIndex++;
  473. expression = "ParentId Like '" + index.ToString() + "." + subCatIndex.ToString() + "' and type = 'C'";
  474. DataRow[] foundRows;
  475. foundRows = dtDetails.Select(expression);
  476. var itemCount = foundRows.Length;
  477. totalMaxScore = maxScore * itemCount;
  478. decimal subTotal = 0;
  479. foreach (var row in foundRows)
  480. {
  481. if (decimal.TryParse(row["score"].ToString(), out Score))
  482. subTotal += Score;
  483. }
  484. subCatTotalList.Add(subCatIndex.IntToLetter(), (subTotal / totalMaxScore) * subCatWeight);
  485. }
  486. decimal subCatTotal = 0;
  487. foreach (KeyValuePair<string, decimal> kvp in subCatTotalList)
  488. {
  489. subCatTotal += kvp.Value;
  490. }
  491. var score = (subCatTotal / Convert.ToDecimal(item["weight"].ToString())) * maxScore;
  492. totalScore += score * Convert.ToDecimal(item["weight"].ToString()) / 100;
  493. dr[2] = (score).ToString("0.00");
  494. dr[3] = rating(score);
  495. dt.Rows.Add(dr);
  496. }
  497. dr = dt.NewRow();
  498. dr[0] = index.ToString();
  499. dr[1] = "Overall";
  500. dr[2] = (totalScore).ToString("0.00");
  501. dr[3] = rating(totalScore);
  502. dt.Rows.Add(dr);
  503. return dt;
  504. }
  505. string rating(decimal score)
  506. {
  507. string result = "";
  508. string[] scoringCriteria = hdnscoringCriteria.Value.Split(':');
  509. if (scoringCriteria.Length >= 3)
  510. {
  511. if (score <= Convert.ToDecimal(scoringCriteria[0]))
  512. result = scoringCriteria[1];
  513. else if (score <= Convert.ToDecimal(scoringCriteria[2]))
  514. result = scoringCriteria[3];
  515. else if (score > Convert.ToDecimal(scoringCriteria[2]))
  516. result = scoringCriteria[5];
  517. }
  518. return result;
  519. }
  520. protected void btnBranchRating_Click(object sender, EventArgs e)
  521. {
  522. var sb = new StringBuilder("<root>");
  523. var brDetaildId = GetStatic.ReadQueryString("brId", "");
  524. var branchId = GetStatic.ReadQueryString("bId", "");
  525. //var isratingCompleted = "Y";
  526. Table mytbl = (Table)Page.FindControl("myData");
  527. for (int i = 1; i <= mytbl.Rows.Count - 2; i++)
  528. {
  529. HiddenField hdnId = (HiddenField)mytbl.Rows[i].FindControl("hdn_" + i.ToString());
  530. DropDownList ddlScore = (DropDownList)mytbl.Rows[i].FindControl("ddl_" + i.ToString());
  531. TextBox txtRemarks = (TextBox)mytbl.Rows[i].FindControl("txt_" + i.ToString());
  532. if (null != hdnId && null != ddlScore && null != txtRemarks)
  533. {
  534. var score = (ddlScore.SelectedValue == "") ? null : ddlScore.SelectedValue;
  535. sb.Append("<row brDetaildId=\"" + brDetaildId + "\" ");
  536. sb.Append(" rowId=\"" + hdnId.Value + "\" ");
  537. sb.Append(" score=\"" + score + "\" ");
  538. sb.Append(" remarks=\"" + obj.FilterStringForXml(txtRemarks.Text.Trim()) + "\" />");
  539. }
  540. }
  541. sb.Append("</root>");
  542. var ds = obj.SaveBranchRating(GetStatic.GetUser(), sb, branchId, brDetaildId, ddlRatingCompleted.SelectedValue, ratingComment.Text.Trim());
  543. if (ds.Tables[0].Rows[0][0].ToString() == "0")
  544. {
  545. DataTable dt = PrepareSummaryTable(ds.Tables[1]);
  546. sb = new StringBuilder("<root>");
  547. for (int i = 0; i < dt.Rows.Count; i++)
  548. {
  549. sb.Append("<row brMasterId=\"" + dt.Rows[i][0].ToString() + "\" ");
  550. sb.Append(" riskCategory=\"" + dt.Rows[i][1].ToString() + "\" ");
  551. sb.Append(" score=\"" + dt.Rows[i][2].ToString() + "\" ");
  552. sb.Append(" rating=\"" + dt.Rows[i][3].ToString() + "\" />");
  553. }
  554. sb.Append("</root>");
  555. var dbresult = obj.SaveRatingSummary(GetStatic.GetUser(), sb, brDetaildId);
  556. }
  557. ManageMessage(ds.Tables[0]);
  558. }
  559. private void ManageMessage(DataTable dt)
  560. {
  561. var url = "List.aspx";
  562. GetStatic.CallJSFunction(this, string.Format("CallBackSave('{0}','{1}", dt.Rows[0][0], dt.Rows[0][1].ToString().Replace("'", "") + "','" + url + "')"));
  563. }
  564. private void ManageMessage(DbResult dr)
  565. {
  566. var url = "List.aspx";
  567. GetStatic.CallJSFunction(this, string.Format("CallBackSave('{0}','{1}", dr.ErrorCode, dr.Msg.Replace("'", "") + "','" + url + "')"));
  568. }
  569. protected void btnSaveBranch_Click(object sender, EventArgs e)
  570. {
  571. if (!string.IsNullOrWhiteSpace(agent.Text))
  572. {
  573. r1.Visible = false;
  574. Page.Validate();
  575. if (fromDate.Text != "" && toDate.Text != "")
  576. {
  577. if (Convert.ToDateTime(toDate.Text) <= Convert.ToDateTime(fromDate.Text))
  578. {
  579. GetStatic.AlertMessage(this, "To Date should be greater than From Date. Please choose valid FROM and To Date.");
  580. return;
  581. }
  582. if (Page.IsValid)
  583. {
  584. var dbResult = obj.SaveBranchForRating(GetStatic.GetUser(), agent.Value, fromDate.Text, toDate.Text);
  585. ManageMessage(dbResult);
  586. }
  587. }
  588. else
  589. {
  590. r1.Visible = true;
  591. }
  592. }
  593. }
  594. private DataSet ConvertHTMLTablesToDataSet(string HTML)
  595. {
  596. // Declarations
  597. DataSet ds = new DataSet();
  598. DataTable dt = null;
  599. DataRow dr = null;
  600. DataColumn dc = null;
  601. string TableExpression = "<table[^>]*>(.*?)</string></string></table>";
  602. string HeaderExpression = "<th[^>]*>(.*?)";
  603. string RowExpression = "<tr[^>]*>(.*?)";
  604. string ColumnExpression = "<td[^>]*>(.*?)";
  605. bool HeadersExist = false;
  606. int iCurrentColumn = 0;
  607. int iCurrentRow = 0;
  608. // Get a match for all the tables in the HTML
  609. MatchCollection Tables = Regex.Matches(HTML, TableExpression, RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.IgnoreCase);
  610. // Loop through each table element
  611. foreach (Match Table in Tables)
  612. {
  613. // Reset the current row counter and the header flag
  614. iCurrentRow = 0;
  615. HeadersExist = false;
  616. // Add a new table to the DataSet
  617. dt = new DataTable();
  618. //Create the relevant amount of columns for this table (use the headers if they exist, otherwise use default names)
  619. if (Table.Value.Contains("<th"))
  620. {
  621. // Set the HeadersExist flag
  622. HeadersExist = true;
  623. // Get a match for all the rows in the table
  624. MatchCollection Headers = Regex.Matches(Table.Value, HeaderExpression, RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.IgnoreCase);
  625. // Loop through each header element
  626. foreach (Match Header in Headers)
  627. {
  628. dt.Columns.Add(Header.Groups[1].ToString());
  629. }
  630. }
  631. else
  632. {
  633. for (int iColumns = 1; iColumns <= Regex.Matches(Regex.Matches(Regex.Matches(Table.Value, TableExpression, RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.IgnoreCase)[0].ToString(), RowExpression, RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.IgnoreCase)[0].ToString(), ColumnExpression, RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.IgnoreCase).Count; iColumns++)
  634. {
  635. dt.Columns.Add("Column " + iColumns);
  636. }
  637. }
  638. //Get a match for all the rows in the table
  639. MatchCollection Rows = Regex.Matches(Table.Value, RowExpression, RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.IgnoreCase);
  640. // Loop through each row element
  641. foreach (Match Row in Rows)
  642. {
  643. // Only loop through the row if it isn't a header row
  644. if (!(iCurrentRow == 0 && HeadersExist))
  645. {
  646. // Create a new row and reset the current column counter
  647. dr = dt.NewRow();
  648. iCurrentColumn = 0;
  649. // Get a match for all the columns in the row
  650. MatchCollection Columns = Regex.Matches(Row.Value, ColumnExpression, RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.IgnoreCase);
  651. // Loop through each column element
  652. foreach (Match Column in Columns)
  653. {
  654. // Add the value to the DataRow
  655. dr[iCurrentColumn] = Column.Groups[1].ToString();
  656. // Increase the current column
  657. iCurrentColumn++;
  658. }
  659. // Add the DataRow to the DataTable
  660. dt.Rows.Add(dr);
  661. }
  662. // Increase the current row counter
  663. iCurrentRow++;
  664. }
  665. // Add the DataTable to the DataSet
  666. ds.Tables.Add(dt);
  667. }
  668. return ds;
  669. }
  670. protected void btnReview_Click(object sender, EventArgs e)
  671. {
  672. if (reviewersComment.Text.Trim() == "")
  673. {
  674. GetStatic.AlertMessage(this, "Reviewer's comment is required.");
  675. return;
  676. }
  677. var brDetaildId = GetStatic.ReadQueryString("brId", "");
  678. var branchId = GetStatic.ReadQueryString("bId", "");
  679. var dbresult = obj.SaveRatingReview(GetStatic.GetUser(), reviewersComment.Text.Trim(), brDetaildId);
  680. ManageMessage(dbresult);
  681. }
  682. protected void btnApprove_Click(object sender, EventArgs e)
  683. {
  684. if (approversComment.Text.Trim() == "")
  685. {
  686. GetStatic.AlertMessage(this, "Approver's comment is required.");
  687. return;
  688. }
  689. var brDetaildId = GetStatic.ReadQueryString("brId", "");
  690. var branchId = GetStatic.ReadQueryString("bId", "");
  691. var dbresult = obj.ApproveBranchRating(GetStatic.GetUser(), approversComment.Text.Trim(), brDetaildId);
  692. ManageMessage(dbresult);
  693. }
  694. protected void ddlRatingCompleted_SelectedIndexChanged(object sender, EventArgs e)
  695. {
  696. if (ddlRatingCompleted.SelectedValue.ToLower() == "y")
  697. {
  698. ctrlEnable = false;
  699. }
  700. else
  701. {
  702. ctrlEnable = true;
  703. }
  704. loadgrid(type, true);
  705. }
  706. protected void Timer1_Tick(object sender, EventArgs e)
  707. {
  708. }
  709. }
  710. public class ItemList<K, T> : Dictionary<K, List<T>>
  711. {
  712. public void Add(K key, T addObject)
  713. {
  714. if (!ContainsKey(key)) Add(key, new List<T>());
  715. if (!base[key].Contains(addObject)) base[key].Add(addObject);
  716. }
  717. }
  718. }