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.

609 lines
27 KiB

  1. using System;
  2. using System.ComponentModel;
  3. using System.Data;
  4. using System.Text;
  5. using Swift.DAL.BL.Remit.Transaction;
  6. using Swift.DAL.BL.System.GeneralSettings;
  7. using Swift.DAL.SwiftDAL;
  8. using Swift.web.Library;
  9. namespace Swift.web.Remit.UserControl
  10. {
  11. public partial class UcTransactionSend : System.Web.UI.UserControl
  12. {
  13. private RemittanceLibrary sl = new RemittanceLibrary();
  14. private SmtpMailSetting smtpMailSetting = new SmtpMailSetting();
  15. private const string ModifyPayoutLocationId = "20121520";
  16. private const string ModifyPayoutLocationIdAg = "40101730";
  17. public bool ShowDetailBlock { get; set; }
  18. public bool ShowLogBlock { get; set; }
  19. private bool _showCommentBlock = true;
  20. public bool ShowCommentBlock
  21. {
  22. get { return _showCommentBlock; }
  23. set { _showCommentBlock = value; }
  24. }
  25. public bool ShowBankDetail { get; set; }
  26. public bool ShowOfac { get; set; }
  27. public bool ShowCompliance { get; set; }
  28. public bool ShowApproveButton { get; set; }
  29. public bool ShowSettlment { get; set; }
  30. public string PAgent
  31. {
  32. get { return pAgent.Value; }
  33. set { pAgent.Value = value; }
  34. }
  35. public string PSuperAgent
  36. {
  37. get { return hdnPsuperAgent.Value; }
  38. set { hdnPsuperAgent.Value = value; }
  39. }
  40. public string TranNo
  41. {
  42. get { return hddTranId.Value; }
  43. set { hddTranId.Value = value; }
  44. }
  45. public string CtrlNo
  46. {
  47. get { return lblControlNo.Text; }
  48. set { lblControlNo.Text = value; }
  49. }
  50. public string PayTokenId
  51. {
  52. get { return hddPayTokenId.Value; }
  53. set { hddPayTokenId.Value = value; }
  54. }
  55. public string TranStatus
  56. {
  57. get { return tranStatus.Text; }
  58. set { tranStatus.Text = value; }
  59. }
  60. public string ModeOfPayment
  61. {
  62. get { return modeOfPayment.Text; }
  63. set { modeOfPayment.Text = value; }
  64. }
  65. public string CreatedBy
  66. {
  67. get { return createdBy.Text; }
  68. set { createdBy.Text = value; }
  69. }
  70. public string ApprovedBy
  71. {
  72. get { return approvedBy.Text; }
  73. set { approvedBy.Text = value; }
  74. }
  75. public string PaidBy
  76. {
  77. get { return paidBy.Text; }
  78. set { paidBy.Text = value; }
  79. }
  80. public string CancelRequestedBy
  81. {
  82. get { return cancelRequestedBy.Text; }
  83. set { cancelRequestedBy.Text = value; }
  84. }
  85. public string CancelApprovedBy
  86. {
  87. get { return cancelApprovedBy.Text; }
  88. set { cancelApprovedBy.Text = value; }
  89. }
  90. public bool TranFound { get; set; }
  91. public void SearchData(string tranNo, string ctrlNo, string mode, string lockMode)
  92. {
  93. SearchData(tranNo, ctrlNo, mode, lockMode, "SEARCH", "ADM:SEARCH TXN");
  94. }
  95. public void SearchData(string tranNo, string ctrlNo, string mode, string lockMode, string viewType, string viewMsg)
  96. {
  97. tranNoName.Text = GetStatic.GetTranNoName();
  98. TranNo = tranNo;
  99. CtrlNo = ctrlNo;
  100. TranFound = false;
  101. var obj = new TranViewDao();
  102. var ds = obj.SelectTransactionInt(GetStatic.GetUser(), ctrlNo, TranNo, lockMode, viewType, viewMsg, GetStatic.GetIp(), GetStatic.GetDcInfo());
  103. if (ds == null)
  104. {
  105. sl.ManageInvalidControlNoAttempt(Page, GetStatic.GetUser(), "N");
  106. return;
  107. }
  108. if (ds.Tables.Count > 1)
  109. {
  110. if (ds.Tables[0].Rows.Count > 0)
  111. {
  112. TranFound = true;
  113. sl.ManageInvalidControlNoAttempt(Page, GetStatic.GetUser(), "Y");
  114. var tRow = ds.Tables[0].Rows[0];
  115. lblControlNo.Text = tRow["controlNo"].ToString();
  116. hddTranId.Value = tRow["tranId"].ToString();
  117. hdnPsuperAgent.Value = tRow["pSuperAgent"].ToString();
  118. lblTranNo.Text = tRow["holdTranId"].ToString();
  119. lblTranRefId.Text = tRow["tranId"].ToString();
  120. TranNo = lblTranRefId.Text;
  121. if (tRow["sMemId"].ToString() == "")
  122. sDisMemId.Visible = false;
  123. else
  124. {
  125. sDisMemId.Visible = true;
  126. sMemId.Text = tRow["sMemId"].ToString();
  127. }
  128. if (tRow["rMemId"].ToString() == "")
  129. rDisMemId.Visible = false;
  130. else
  131. {
  132. rDisMemId.Visible = true;
  133. rMemId.Text = tRow["rMemId"].ToString();
  134. }
  135. PAgent = tRow["pAgent"].ToString();
  136. PSuperAgent = tRow["pSuperAgent"].ToString();
  137. if (tRow["tranStatus"].ToString().ToUpper() == "LOCK")
  138. {
  139. lockAudit.Visible = true;
  140. var html = new StringBuilder("Locked By ");
  141. html.Append(tRow["lockedBy"] + " on " + tRow["lockedDate"]);
  142. lockAudit.InnerHtml = html.ToString();
  143. }
  144. if (mode == "u") // mode: modification transaction
  145. {
  146. sName.Text = GetLinkTextForModification("Sender Name", "senderName", tRow);
  147. sName.Text = GetLinkTextForModification("Sender Name", "senderName", tRow);
  148. sAddress.Text = GetLinkTextForModification("Sender Address", "sAddress", tRow);
  149. sContactNo.Text = GetLinkTextForModification("Sender Contact No", "sContactNo", tRow);
  150. sIdType.Text = GetLinkTextForModification("Sender Id Type", "sIdType", tRow);
  151. sIdNo.Text = GetLinkTextForModification("Sender Id No", "sIdNo", tRow);
  152. rName.Text = GetLinkTextForModification("Receiver Name", "receiverName", tRow);
  153. rAddress.Text = GetLinkTextForModification("Receiver Address", "rAddress", tRow);
  154. rContactNo.Text = GetLinkTextForModification("Receiver Contact No", "rContactNo", tRow);
  155. rIdType.Text = GetLinkTextForModification("Receiver Id Type", "rIdType", tRow);
  156. rIdNo.Text = GetLinkTextForModification("Receiver Id No", "rIdNo", tRow);
  157. sTelNo.Text = tRow["sTelNo"].ToString();
  158. rTelNo.Text = tRow["rTelNo"].ToString();
  159. if (tRow["paymentMethod"].ToString().ToUpper() == "BANK DEPOSIT")
  160. {
  161. accountNo.Text = GetLinkTextForModification("Account No", "accountNo", tRow);
  162. bankName.Text = GetLinkTextForModification("Bank Name", "BankName", tRow);
  163. branchName.Text = GetLinkTextForModification("Branch Name", "pBranchName", tRow);
  164. }
  165. }
  166. else
  167. {
  168. sName.Text = tRow["senderName"].ToString();
  169. sAddress.Text = tRow["sAddress"].ToString();
  170. sContactNo.Text = tRow["sContactNo"].ToString();
  171. sTelNo.Text = tRow["sTelNo"].ToString();
  172. sIdType.Text = tRow["sIdType"].ToString();
  173. sIdNo.Text = tRow["sIdNo"].ToString();
  174. rName.Text = tRow["receiverName"].ToString();
  175. rAddress.Text = tRow["rAddress"].ToString();
  176. rContactNo.Text = tRow["rContactNo"].ToString();
  177. rIdType.Text = tRow["rIdType"].ToString();
  178. rIdNo.Text = tRow["rIdNo"].ToString();
  179. rTelNo.Text = tRow["rTelNo"].ToString();
  180. }
  181. if (tRow["tranStatus"].ToString().ToUpper() == "CANCEL")
  182. {
  183. showHideTranStatus.Visible = true;
  184. highLightTranStatus.InnerText = "CANCELLED Transaction";
  185. }
  186. if (tRow["tranStatus"].ToString().ToUpper() == "BLOCK")
  187. {
  188. showHideTranStatus.Visible = true;
  189. highLightTranStatus.InnerText = "Block Transaction";
  190. }
  191. if (tRow["tranStatus"].ToString().ToUpper() == "CANCELREQUEST")
  192. {
  193. showHideTranStatus.Visible = true;
  194. highLightTranStatus.InnerText = "Cancel Requested !";
  195. }
  196. if (tRow["tranStatus"].ToString().ToUpper() == "LOCK")
  197. {
  198. showHideTranStatus.Visible = true;
  199. highLightTranStatus.InnerText = "Locked Transaction!";
  200. }
  201. if (tRow["tranStatus"].ToString().ToUpper() == "COMPLIANCE")
  202. {
  203. showHideTranStatus.Visible = true;
  204. highLightTranStatus.InnerText = "Compliance Transaction!";
  205. }
  206. if (tRow["tranStatus"].ToString().ToUpper() == "OFAC")
  207. {
  208. showHideTranStatus.Visible = true;
  209. highLightTranStatus.InnerText = "OFAC Transaction!";
  210. }
  211. sCountry.Text = tRow["sCountryName"].ToString();
  212. sCity.Text = tRow["sCity"].ToString();
  213. sEmail.Text = tRow["sEmail"].ToString();
  214. sValidityDate.Text = tRow["sValidDate"].ToString();
  215. sNativeCountry.Text = tRow["nativeCountry"].ToString();
  216. rCountry.Text = tRow["rCountryName"].ToString();
  217. rCity.Text = tRow["rCity"].ToString();
  218. //Sending Agent Detail
  219. sAgentName.Text = tRow["sAgentName"].ToString();
  220. sBranchName.Text = tRow["sBranchName"].ToString();
  221. sAgentCountry.Text = tRow["sCountryName"].ToString();
  222. sAgentAddress.Text = tRow["sAgentAddress"].ToString();
  223. //Payout Agent Detail
  224. pAgentCountry.Text = tRow["pAgentCountry"].ToString();
  225. pAgentAddress.Text = tRow["pAgentAddress"].ToString();
  226. if (sl.HasRight(ModifyPayoutLocationId) || sl.HasRight(ModifyPayoutLocationIdAg))
  227. {
  228. if (mode == "u" && tRow["paymentMethod"].ToString().ToUpper() != "BANK DEPOSIT") // mode: modification payout location
  229. {
  230. accountNo.Text = tRow["accountNo"].ToString();
  231. bankName.Text = tRow["BankName"].ToString();
  232. branchName.Text = tRow["BranchName"].ToString();
  233. pBranchName.Text = tRow["pBranchName"].ToString();
  234. }
  235. else if (mode == "u" && tRow["paymentMethod"].ToString().ToUpper() == "BANK DEPOSIT") //modify mode & bank deposit mode
  236. {
  237. accountNo.Text = GetLinkPayoutLocation("Account Number", "accountNo", tRow);
  238. bankName.Text = GetLinkPayoutLocation("Bank Name", "BankName", tRow);
  239. branchName.Text = GetLinkPayoutLocation("Branch Name", "BranchName", tRow);
  240. pBranchName.Text = GetLinkPayoutLocation("Paying Branch", "pBranchName", tRow);
  241. }
  242. else
  243. {
  244. accountNo.Text = tRow["accountNo"].ToString();
  245. bankName.Text = tRow["BankName"].ToString();
  246. branchName.Text = tRow["BranchName"].ToString();
  247. pBranchName.Text = tRow["pBranchName"].ToString();
  248. }
  249. }
  250. else
  251. {
  252. accountNo.Text = tRow["accountNo"].ToString();
  253. bankName.Text = tRow["BankName"].ToString();
  254. branchName.Text = tRow["BranchName"].ToString();
  255. pBranchName.Text = tRow["pBranchName"].ToString();
  256. }
  257. pAgentName.Text = tRow["expectedPayoutAgent"].ToString();
  258. //sAgentComm.Text = GetStatic.FormatData(tRow["sAgentComm"].ToString(), "M");
  259. //sAgentCommCurr.Text = tRow["sAgentCommCurrency"].ToString();
  260. if (payStatus.Text == "Paid")
  261. {
  262. payAgentComm.Visible = true;
  263. pAgentComm.Text = GetStatic.FormatData(tRow["pAgentComm"].ToString(), "M");
  264. pAgentCommCurr.Text = tRow["pAgentCommCurrency"].ToString();
  265. }
  266. //Transaction Information
  267. pnlShowBankDetail.Visible = tRow["paymentMethod"].ToString().ToUpper().Equals("BANK DEPOSIT");
  268. modeOfPayment.Text = tRow["paymentMethod"].ToString();
  269. lblStatus.Text = tRow["payStatus"].ToString();
  270. tranStatus.Text = tRow["tranStatus"].ToString();
  271. lbltrnsubStatus.Text = tRow["tranStatus"].ToString();
  272. payStatus.Text = tRow["payStatus"].ToString();
  273. payoutMsg.Text = tRow["payoutMsg"].ToString();
  274. sourceOfFund.Text = tRow["sourceOfFund"].ToString();
  275. reasonOfRemit.Text = tRow["purposeOfRemit"].ToString();
  276. //Payout Amount
  277. //handling.Text = GetStatic.FormatData(tRow["handlingFee"].ToString(), "M");
  278. //exRate.Text = tRow["exRate"].ToString();
  279. custRate.Text = tRow["custRate"].ToString();
  280. //settRate.Text = tRow["settRate"].ToString();
  281. transferAmount.Text = tRow["tAmt"].ToString();// GetStatic.FormatData(tRow["tAmt"].ToString(), "M");
  282. serviceCharge.Text = GetStatic.FormatData(tRow["serviceCharge"].ToString(), "M");
  283. total.Text = tRow["cAmt"].ToString();//GetStatic.FormatData(tRow["cAmt"].ToString(), "M");
  284. payoutAmt.Text = GetStatic.FormatData(tRow["pAmt"].ToString(), "M");
  285. relationship.Text = tRow["relationship"].ToString();
  286. tAmtCurr.Text = tRow["collCurr"].ToString();
  287. scCurr.Text = tRow["collCurr"].ToString();
  288. totalCurr.Text = tRow["collCurr"].ToString();
  289. pAmtCurr.Text = tRow["payoutCurr"].ToString();
  290. //Transaction Log Information
  291. createdBy.Text = tRow["createdBy"].ToString();
  292. createdDate.Text = tRow["createdDate"].ToString();
  293. approvedBy.Text = tRow["approvedBy"].ToString();
  294. approvedDate.Text = tRow["approvedDate"].ToString();
  295. paidBy.Text = tRow["paidBy"].ToString();
  296. paidDate.Text = tRow["paidDate"].ToString();
  297. cancelRequestedBy.Text = tRow["cancelRequestBy"].ToString();
  298. cancelRequestedDate.Text = tRow["cancelRequestDate"].ToString();
  299. cancelApprovedBy.Text = tRow["cancelApprovedBy"].ToString();
  300. cancelApprovedDate.Text = tRow["cancelApprovedDate"].ToString();
  301. hddPayTokenId.Value = tRow["payTokenId"].ToString();
  302. tblCreatedLog.Visible = createdBy.Text != "";
  303. tblApprovedLog.Visible = approvedBy.Text != "";
  304. tblPaidLog.Visible = paidBy.Text != "";
  305. tblCancelRequestedLog.Visible = cancelRequestedBy.Text != "";
  306. tblCancelApprovedLog.Visible = cancelApprovedBy.Text != "";
  307. }
  308. if (ds.Tables[1].Rows.Count > 0)
  309. {
  310. pnlLog.Visible = true;
  311. var dt = ds.Tables[1];
  312. var str = new StringBuilder("<table class='table' border=\"0\" cellspacing=0 cellpadding=\"3\">");
  313. str.Append("<tr>");
  314. str.Append("<th>Updated By</th>");
  315. str.Append("<th width='130px'>Updated Date</th>");
  316. str.Append("<th>Message</th>");
  317. //str.Append("<th>Msg Type</th>");
  318. str.Append("</tr>");
  319. foreach (DataRow dr in dt.Rows)
  320. {
  321. str.Append("<tr>");
  322. str.Append("<td align='left'>" + dr["createdBy"] + "</td>");
  323. str.Append("<td align='left'>" + dr["createdDate"] + "</td>");
  324. if (dr["fileType"].ToString() == "")
  325. {
  326. str.Append("<td align='left'>" + dr["message"] + "</td>");
  327. }
  328. else
  329. {
  330. str.Append("<td align='left'><a title='View Deposit Slip' target='_blank' href='/doc/" + lblControlNo.Text + "/" + dr["rowId"].ToString() + "." + dr["fileType"].ToString() + "'>" + dr["message"] + "</a></td>");
  331. }
  332. // str.Append("<td align='left'>" + dr["msgType"] + "</td>");
  333. str.Append("</tr>");
  334. }
  335. str.Append("</table>");
  336. rptLog.InnerHtml = str.ToString();
  337. }
  338. if (ds.Tables[2].Rows.Count > 0)
  339. {
  340. var sb = new StringBuilder("");
  341. sb.AppendLine("<table class='table' style=\"width: 100%\" border=\"0\" cellspacing=0 cellpadding=\"3\"><tr>");
  342. sb.AppendLine("<th nowrap='nowrap' align='left'>BANK/CASH</th>");
  343. sb.AppendLine("<th nowrap='nowrap' align='left'>Voucher No</th>");
  344. sb.AppendLine("<th nowrap='nowrap' align='left'>Amount</th>");
  345. sb.AppendLine("<th nowrap='nowrap' align='left'>Deposit Date</th>");
  346. sb.AppendLine("<th nowrap='nowrap' align='left'>Narration</th></tr>");
  347. for (int a = 0; a < ds.Tables[2].Rows.Count; a++)
  348. {
  349. sb.AppendLine("<tr>");
  350. sb.AppendLine("<td align='left'>" + ds.Tables[2].Rows[a]["bankName"] + "</td>");
  351. sb.AppendLine("<td align='left'>" + ds.Tables[2].Rows[a]["voucherNo"] + "</td>");
  352. sb.AppendLine("<td align='left'>" + GetStatic.ShowDecimal(ds.Tables[2].Rows[a]["Amt"].ToString()) + "</td>");
  353. sb.AppendLine("<td align='left'>" + ds.Tables[2].Rows[a]["collDate"] + "</td>");
  354. sb.AppendLine("<td align='left'>" + ds.Tables[2].Rows[a]["narration"] + "</td>");
  355. sb.AppendLine("</tr>");
  356. }
  357. sb.AppendLine("</table>");
  358. Ddetail.InnerHtml = sb.ToString();
  359. }
  360. }
  361. }
  362. public void SearchData(string tranNo, string ctrlNo)
  363. {
  364. SearchData(tranNo, ctrlNo, "");
  365. }
  366. public void SearchData(string tranNo, string ctrlNo, string lockMode)
  367. {
  368. SearchData(tranNo, ctrlNo, "", lockMode);
  369. }
  370. public string GetLinkTextForModification(string label, string fieldName, DataRow dr)
  371. {
  372. var str = "<a href=# title='Edit Record'><div class = \"link\" onclick = \"EditData('" + label + "', '" + fieldName + "', '" + dr[fieldName] + "','" + hddTranId.Value + "')\">" +
  373. dr[fieldName] + "<img border=0 src=\"" + GetStatic.GetUrlRoot() + "/Images/edit.gif\"/></a></div>";
  374. return str;
  375. }
  376. public string GetLinkPayoutLocation(string label, string fieldName, DataRow dr)
  377. {
  378. var str = "<a href=# title='Edit Record'><div class = \"link\" onclick = \"EditPayoutLocation('" + label + "', '" + fieldName + "', '" + dr[fieldName] + "','" + hddTranId.Value + "')\">" +
  379. dr[fieldName] + "<img border=0 src=\"" + GetStatic.GetUrlRoot() + "/Images/edit.gif\"/></a></div>";
  380. return str;
  381. }
  382. public void SearchData()
  383. {
  384. //if TranNo is not blank, search by tranNo
  385. //if CtrlNo is not blank, search by ctrlNo
  386. }
  387. private void ManageMessage(DbResult dbResult)
  388. {
  389. GetStatic.SetMessage(dbResult);
  390. GetStatic.AlertMessage(Page);
  391. }
  392. protected void Page_Load(object sender, EventArgs e)
  393. {
  394. Authenticate();
  395. pnlDetail.Visible = ShowDetailBlock;
  396. pnlComment.Visible = ShowCommentBlock;
  397. lblAddComp.Visible = ShowCommentBlock;
  398. lblSettl.Visible = ShowSettlment;
  399. }
  400. private void Authenticate()
  401. {
  402. sl.CheckSession();
  403. }
  404. protected void btnAdd_Click(object sender, EventArgs e)
  405. {
  406. if (GetStatic.GetIsApiFlag() == "Y")
  407. AddCommentApi();
  408. else
  409. AddComment();
  410. comments.Text = "";
  411. ShowLog();
  412. }
  413. #region for desplaying a transaction comments log
  414. public void ShowLog()
  415. {
  416. var obj = new TranViewDao();
  417. var ds = obj.DisplayLog(GetStatic.GetUser(), lblControlNo.Text, hddTranId.Value, "");
  418. if (ds == null)
  419. return;
  420. if (ds.Tables[0].Rows.Count > 0)
  421. {
  422. pnlLog.Visible = true;
  423. var dt = ds.Tables[0];
  424. var str = new StringBuilder("<table class='table' border=\"1\" cellspacing=0 cellpadding=\"3\">");
  425. str.Append("<tr>");
  426. str.Append("<th>Updated By</th>");
  427. str.Append("<th width='130px'>Updated Date</th>");
  428. str.Append("<th>Message</th>");
  429. // str.Append("<th>Msg Type</th>");
  430. str.Append("</tr>");
  431. foreach (DataRow dr in dt.Rows)
  432. {
  433. str.Append("<tr>");
  434. str.Append("<td align='left'>" + dr["createdBy"] + "</td>");
  435. str.Append("<td align='left'>" + dr["createdDate"] + "</td>");
  436. if (dr["fileType"].ToString() == "")
  437. {
  438. str.Append("<td align='left'>" + dr["message"] + "</td>");
  439. }
  440. else
  441. {
  442. str.Append("<td align='left'><a title='View Deposit Slip' target='_blank' href='/doc/" + lblControlNo.Text + "/" + dr["rowId"].ToString() + "." + dr["fileType"].ToString() + "'>" + dr["message"] + "</a></td>");
  443. }
  444. //str.Append("<td align='left'>" + dr["msgType"] + "</td>");
  445. str.Append("</tr>");
  446. }
  447. str.Append("</table>");
  448. rptLog.InnerHtml = str.ToString();
  449. }
  450. }
  451. #endregion
  452. public void AddComment()
  453. {
  454. var obj = new TranViewDao();
  455. DbResult dbResult = obj.AddComment(GetStatic.GetUser(), lblControlNo.Text, hddTranId.Value, comments.Text);
  456. ManageMessage(dbResult);
  457. if (dbResult.ErrorCode != "0")
  458. {
  459. GetStatic.CallBackJs1(Page, "Result", "alert('" + dbResult.Msg + "')");
  460. return;
  461. }
  462. else
  463. {
  464. SetupEmailSetting();
  465. SendMail();
  466. }
  467. }
  468. public void AddCommentApi()
  469. {
  470. GetStatic.AddTroubleTicket(Page, lblControlNo.Text, comments.Text, 2);
  471. AddComment();
  472. }
  473. private delegate void DoStuff(); //delegate for the action
  474. private void SendMail()
  475. {
  476. var myAction = new DoStuff(AsyncMailProcessing);
  477. //invoke it asynchrnously, control passes to next statement
  478. myAction.BeginInvoke(null, null);
  479. }
  480. private void AsyncMailProcessing()
  481. {
  482. var bw = new BackgroundWorker();
  483. // this allows our worker to report progress during work
  484. bw.WorkerReportsProgress = true;
  485. // what to do in the background thread
  486. bw.DoWork += new DoWorkEventHandler(
  487. delegate(object o, DoWorkEventArgs args)
  488. {
  489. var b = o as BackgroundWorker;
  490. smtpMailSetting.SendSmtpMail(smtpMailSetting);
  491. });
  492. // what to do when progress changed (update the progress bar for example)
  493. bw.ProgressChanged += new ProgressChangedEventHandler(
  494. delegate(object o, ProgressChangedEventArgs args)
  495. {
  496. //label1.Text = string.Format("{0}% Completed", args.ProgressPercentage);
  497. });
  498. // what to do when worker completes its task (notify the user)
  499. bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(
  500. delegate(object o, RunWorkerCompletedEventArgs args)
  501. {
  502. var dbResult = new DbResult();
  503. dbResult.SetError("0", "Mail Sent Successfully", "");
  504. GetStatic.PrintMessage(Page, dbResult);
  505. });
  506. bw.RunWorkerAsync();
  507. }
  508. private void SetupEmailSetting()
  509. {
  510. var obj = new SystemEmailSetupDao();
  511. var ds = obj.GetDataForEmail(GetStatic.GetUser(), "Trouble", lblControlNo.Text, comments.Text);
  512. if (ds == null)
  513. return;
  514. if (ds.Tables.Count == 0)
  515. return;
  516. if (ds.Tables.Count > 1)
  517. {
  518. //Email Server Settings
  519. if (ds.Tables[0].Rows.Count > 0)
  520. {
  521. var dr1 = ds.Tables[0].Rows[0];
  522. smtpMailSetting.SmtpServer = dr1["smtpServer"].ToString();
  523. smtpMailSetting.SmtpPort = Convert.ToInt32(dr1["smtpPort"]);
  524. smtpMailSetting.SendEmailId = dr1["sendID"].ToString();
  525. smtpMailSetting.SendEmailPwd = dr1["sendPSW"].ToString();
  526. smtpMailSetting.EnableSsl = GetStatic.GetCharToBool(dr1["enableSsl"].ToString());
  527. }
  528. if (ds.Tables[1].Rows.Count == 0)
  529. return;
  530. //Email Receiver
  531. if (ds.Tables[1].Rows.Count > 0)
  532. {
  533. var dt = ds.Tables[1];
  534. foreach (DataRow dr2 in dt.Rows)
  535. {
  536. if (!string.IsNullOrEmpty(smtpMailSetting.ToEmails))
  537. smtpMailSetting.ToEmails = smtpMailSetting.ToEmails + ",";
  538. smtpMailSetting.ToEmails = smtpMailSetting.ToEmails + dr2["email"].ToString();
  539. }
  540. }
  541. //Email Subject and Body
  542. if (ds.Tables[2].Rows.Count > 0)
  543. {
  544. var dr3 = ds.Tables[2].Rows[0];
  545. if (dr3 == null)
  546. return;
  547. smtpMailSetting.MsgSubject = dr3[0].ToString();
  548. smtpMailSetting.MsgBody = dr3[1].ToString();
  549. }
  550. }
  551. }
  552. }
  553. }