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.

214 lines
7.5 KiB

  1. using Swift.DAL.BL.Remit.Transaction;
  2. using Swift.DAL.BL.System.GeneralSettings;
  3. using Swift.web.Library;
  4. using System;
  5. using System.ComponentModel;
  6. using System.Data;
  7. using System.Text;
  8. namespace Swift.web.AgentNew.Utilities.ModifyRequest
  9. {
  10. public partial class Summary : System.Web.UI.Page
  11. {
  12. private readonly SwiftLibrary _sl = new SwiftLibrary();
  13. private readonly ModifyTransactionDao _obj = new ModifyTransactionDao();
  14. protected void Page_Load(object sender, EventArgs e)
  15. {
  16. Authenticate();
  17. PrintSummary();
  18. }
  19. private void Authenticate()
  20. {
  21. _sl.CheckSession();
  22. }
  23. private string GetControlNo()
  24. {
  25. return GetStatic.ReadQueryString("controlNo", "");
  26. }
  27. private string GetEmail()
  28. {
  29. return GetStatic.ReadQueryString("email", "");
  30. }
  31. private void PrintSummary()
  32. {
  33. string cNo = GetControlNo();
  34. if (string.IsNullOrEmpty(cNo))
  35. return;
  36. PopulateModification(cNo);
  37. hdnEmail.Value = GetEmail();
  38. controlNoLbl.Text = GetStatic.GetTranNoName();
  39. controlNo.Text = GetControlNo();
  40. hdnEmail.Value = hdnEmail.Value == ""
  41. ? "bijay@swifttech.com.np"
  42. : hdnEmail.Value;
  43. ComposeAndSendMail();
  44. }
  45. private void PopulateModification(string cNo)
  46. {
  47. var ds = _obj.DisplayModification(GetStatic.GetUser(), cNo);
  48. if (ds == null)
  49. return;
  50. if (ds.Tables[0].Rows.Count > 0)
  51. {
  52. var dt = ds.Tables[0];
  53. int cols = dt.Columns.Count;
  54. var str = new StringBuilder("<table class='table table-bordered' border='0' style=\"width:600px;border: 0px solid black;\" cellspacing='3' cellpadding='3'>");
  55. str.Append("<tr>");
  56. for (int i = 0; i < cols; i++)
  57. {
  58. str.Append("<th align=\"left\">" + dt.Columns[i].ColumnName + "</th>");
  59. }
  60. str.Append("</tr>");
  61. foreach (DataRow dr in dt.Rows)
  62. {
  63. str.Append("<tr>");
  64. for (int i = 0; i < cols; i++)
  65. {
  66. str.Append("<td align=\"left\">" + dr[i] + "</td>");
  67. }
  68. str.Append("</tr>");
  69. }
  70. str.Append("</table>");
  71. DvModification.InnerHtml = str.ToString();
  72. }
  73. }
  74. #region Mail Send
  75. private void ComposeAndSendMail()
  76. {
  77. ComposeMail();
  78. SendMail();
  79. }
  80. private readonly SmtpMailSetting _smtpMailSetting = new SmtpMailSetting();
  81. private readonly SmtpMailSetting _mailToAgent = new SmtpMailSetting();
  82. private delegate void DoStuff(); //delegate for the action
  83. private void SendMail()
  84. {
  85. var myAction = new DoStuff(AsyncMailProcessing);
  86. //invoke it asynchrnously, control passes to next statement
  87. myAction.BeginInvoke(null, null);
  88. }
  89. private void AsyncMailProcessing()
  90. {
  91. var bw = new BackgroundWorker();
  92. // this allows our worker to report progress during work
  93. bw.WorkerReportsProgress = true;
  94. // what to do in the background thread
  95. bw.DoWork += new DoWorkEventHandler(
  96. delegate (object o, DoWorkEventArgs args)
  97. {
  98. var b = o as BackgroundWorker;
  99. _smtpMailSetting.SendSmtpMail(_smtpMailSetting);
  100. if (!string.IsNullOrEmpty(hdnEmail.Value))
  101. _mailToAgent.SendSmtpMail(_mailToAgent);
  102. });
  103. // what to do when progress changed (update the progress bar for example)
  104. bw.ProgressChanged += new ProgressChangedEventHandler(
  105. delegate (object o, ProgressChangedEventArgs args)
  106. {
  107. //label1.Text = string.Format("{0}% Completed", args.ProgressPercentage);
  108. });
  109. // what to do when worker completes its task (notify the user)
  110. bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(
  111. delegate (object o, RunWorkerCompletedEventArgs args)
  112. {
  113. GetStatic.PrintSuccessMessage(Page, "Mail sent successfully");
  114. });
  115. bw.RunWorkerAsync();
  116. }
  117. //Compose Email From Email Template for Admin
  118. private void ComposeMail()
  119. {
  120. var obj = new SystemEmailSetupDao();
  121. var ds = obj.GetDataForEmail(GetStatic.GetUser(), "Modification Request", GetControlNo(), DvModification.InnerHtml);
  122. if (ds == null)
  123. return;
  124. if (ds.Tables.Count == 0)
  125. return;
  126. if (ds.Tables.Count > 1)
  127. {
  128. //Email Server Settings
  129. if (ds.Tables[0].Rows.Count > 0)
  130. {
  131. var dr1 = ds.Tables[0].Rows[0];
  132. _smtpMailSetting.SmtpServer = dr1["smtpServer"].ToString();
  133. _smtpMailSetting.SmtpPort = Convert.ToInt32(dr1["smtpPort"]);
  134. _smtpMailSetting.SendEmailId = dr1["sendID"].ToString();
  135. _smtpMailSetting.SendEmailPwd = dr1["sendPSW"].ToString();
  136. _smtpMailSetting.EnableSsl = GetStatic.GetCharToBool(dr1["enableSsl"].ToString());
  137. _mailToAgent.SmtpServer = dr1["smtpServer"].ToString();
  138. _mailToAgent.SmtpPort = Convert.ToInt32(dr1["smtpPort"]);
  139. _mailToAgent.SendEmailId = dr1["sendID"].ToString();
  140. _mailToAgent.SendEmailPwd = dr1["sendPSW"].ToString();
  141. _mailToAgent.EnableSsl = GetStatic.GetCharToBool(dr1["enableSsl"].ToString());
  142. }
  143. if (ds.Tables[1].Rows.Count == 0)
  144. return;
  145. //Email Receiver
  146. if (ds.Tables[1].Rows.Count > 0)
  147. {
  148. var dt = ds.Tables[1];
  149. foreach (DataRow dr2 in dt.Rows)
  150. {
  151. if (!string.IsNullOrEmpty(_smtpMailSetting.ToEmails))
  152. _smtpMailSetting.ToEmails = _smtpMailSetting.ToEmails + ",";
  153. _smtpMailSetting.ToEmails = _smtpMailSetting.ToEmails + dr2["email"].ToString();
  154. }
  155. }
  156. var mailTo = hdnEmail.Value;
  157. _mailToAgent.ToEmails = mailTo;
  158. //Email Subject and Body
  159. if (ds.Tables[2].Rows.Count > 0)
  160. {
  161. var dr3 = ds.Tables[2].Rows[0];
  162. if (dr3 == null)
  163. return;
  164. _smtpMailSetting.MsgSubject = dr3[0].ToString();
  165. _smtpMailSetting.MsgBody = dr3[1].ToString();
  166. }
  167. //Email Subject and Body to Agent
  168. if (ds.Tables.Count > 3)
  169. {
  170. if (ds.Tables[3].Rows.Count > 0)
  171. {
  172. var dr4 = ds.Tables[3].Rows[0];
  173. if (dr4 == null)
  174. return;
  175. _mailToAgent.MsgSubject = dr4[0].ToString();
  176. _mailToAgent.MsgBody = dr4[1].ToString();
  177. }
  178. }
  179. }
  180. }
  181. #endregion Mail Send
  182. }
  183. }