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.

126 lines
4.4 KiB

  1. using Swift.DAL.BL.System.GeneralSettings;
  2. using Swift.web.Library;
  3. using System;
  4. using System.Data;
  5. using System.Text;
  6. using System.Text.RegularExpressions;
  7. using System.Web;
  8. using System.Web.Script.Serialization;
  9. namespace Swift.web.Agent
  10. {
  11. public partial class AgentMain : System.Web.UI.Page
  12. {
  13. private RemittanceLibrary _remit = new RemittanceLibrary();
  14. protected void Page_Load(object sender, EventArgs e)
  15. {
  16. var MethodName = Request.Form["MethodName"];
  17. if (MethodName == "Messages")
  18. {
  19. PopulateMessageDetail();
  20. }
  21. if (!IsPostBack)
  22. {
  23. _remit.CheckSession();
  24. ManageSendPayMenus();
  25. // PopulateMessage();
  26. PopulateTxnCount();
  27. PopulateMessages();
  28. }
  29. }
  30. private void PopulateMessageDetail()
  31. {
  32. string msgId = Request.Form["MessageId"];
  33. var obj = new MessageSettingDao();
  34. DataRow dr = obj.GetNewsFeederMessage(msgId);
  35. if (dr == null)
  36. {
  37. return;
  38. }
  39. MessageData _data = new MessageData();
  40. _data.CreatedBy = dr["createdBy"].ToString();
  41. _data.CreatedDate = dr["createdDate"].ToString();
  42. _data.Message = dr["newsFeederMsg"].ToString();
  43. var json = new JavaScriptSerializer().Serialize(_data);
  44. JsonSerialize(json);
  45. }
  46. public class MessageData
  47. {
  48. public string CreatedBy { get; set; }
  49. public string CreatedDate { get; set; }
  50. public string Message { get; set; }
  51. }
  52. private void JsonSerialize<T>(T obk)
  53. {
  54. JavaScriptSerializer jsonData = new JavaScriptSerializer();
  55. string jsonString = jsonData.Serialize(obk);
  56. HttpContext.Current.Response.ContentType = "application/json";
  57. HttpContext.Current.Response.Write(jsonString);
  58. HttpContext.Current.Response.End();
  59. }
  60. private void ManageSendPayMenus()
  61. {
  62. if (GetStatic.ReadSession("agentType", "").ToLower() == "send")
  63. {
  64. sendingAgent.Visible = true;
  65. sendingAgent1.Visible = true;
  66. payAgent.Visible = false;
  67. payAgent1.Visible = false;
  68. }
  69. else if (GetStatic.ReadSession("agentType", "").ToLower() == "pay")
  70. {
  71. sendingAgent.Visible = false;
  72. sendingAgent1.Visible = false;
  73. payAgent.Visible = true;
  74. payAgent1.Visible = true;
  75. }
  76. }
  77. private void PopulateTxnCount()
  78. {
  79. string sql = "exec proc_txnCountAgent @agentId = '" + GetStatic.GetBranch() + "'";
  80. DataRow dr = _remit.ExecuteDataRow(sql);
  81. if (dr == null)
  82. {
  83. return;
  84. }
  85. iSend.Text = dr["iSend"].ToString();
  86. iCancel.Text = dr["iCancel"].ToString();
  87. iPaid.Text = dr["iPaid"].ToString();
  88. iUnpaid.Text = dr["iUnpaid"].ToString();
  89. }
  90. protected void PopulateMessages()
  91. {
  92. var obj = new MessageSettingDao();
  93. var dt = obj.GetNewsFeeder(GetStatic.GetUser(), GetStatic.GetUserType(), GetStatic.GetCountryId(), GetStatic.GetAgent(), GetStatic.GetBranch());
  94. if (dt.Rows.Count == 0 || dt == null)
  95. {
  96. return;
  97. }
  98. StringBuilder sb = new StringBuilder();
  99. foreach (DataRow item in dt.Rows)
  100. {
  101. string msgId = item["msgId"].ToString();
  102. sb.AppendLine("<li class=\"list-group-item\">");
  103. sb.AppendLine("<a href=\"javascript:void(0);\" onclick=\"ShowMessage('" + msgId + "')\" data-toggle=\"modal\">" + GetMessageToShow(item["newsFeederMsg"].ToString()) + "</a>");
  104. sb.AppendLine("<small><i class=\"fa fa-clock-o\"></i>&nbsp;" + item["msgDate"].ToString() + "</small>");
  105. sb.AppendLine("</li>");
  106. }
  107. messages.InnerHtml = sb.ToString();
  108. }
  109. private string GetMessageToShow(string message)
  110. {
  111. string pureString = Regex.Replace(message, "<.*?>", String.Empty);
  112. return pureString.Substring(0, Math.Min(pureString.Length, 40));
  113. }
  114. }
  115. }