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.

679 lines
28 KiB

  1. using OfficeOpenXml;
  2. using OfficeOpenXml.Style;
  3. using OfficeOpenXml.Table;
  4. using Swift.API.GoogleAuthenticator;
  5. using Swift.DAL.BL.System.UserManagement;
  6. using Swift.DAL.SwiftDAL;
  7. using Swift.web.Library;
  8. using Swift.web.SwiftSystem.UserManagement.ApplicationUserPool;
  9. using System;
  10. using System.Data;
  11. using System.Globalization;
  12. using System.IO;
  13. using System.Text;
  14. using System.Web;
  15. using System.Web.UI.WebControls;
  16. namespace Swift.web.SendMoney
  17. {
  18. public partial class Default : System.Web.UI.Page
  19. {
  20. private ApplicationUserDao user = new ApplicationUserDao();
  21. private UserPool userPool = UserPool.GetInstance();
  22. protected GoogleAuthenticatorAPI _auth = new GoogleAuthenticatorAPI();
  23. private readonly StaticDataDdl _sdd = new StaticDataDdl();
  24. protected string use2FA = "Y";
  25. protected void Page_Load(object sender, EventArgs e)
  26. {
  27. //var usr = Server.HtmlEncode(User.Identity.Name);
  28. //Response.Write(usr);
  29. //username.Attributes.Add("onkeypress", "ClearMessage()");
  30. //pwd.Attributes.Add("onkeypress", "isCapslock((event?event:evt))");
  31. //employeeId.Attributes.Add("onkeypress", "ClearMessage()");
  32. //ExportToExcel();
  33. if (!IsPostBack)
  34. {
  35. if (GetStatic.ReadWebConfig("UseGoogle2FAuthAgent", "") != "Y")
  36. {
  37. use2FA = "N";
  38. DisableGoogle2FAuth();
  39. }
  40. else
  41. {
  42. EnableGoogle2FAuth();
  43. }
  44. var userPool = UserPool.GetInstance();
  45. userPool.RemoveUser(GetStatic.GetUser());
  46. Session.Clear();
  47. Session.Abandon();
  48. PopulateDDL();
  49. //ValidateDc();
  50. //ValidateIPAddress();
  51. }
  52. }
  53. private void ExportToExcel()
  54. {
  55. ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
  56. ExcelPackage ExcelPkg = new ExcelPackage();
  57. ExcelWorksheet wsSheet1 = ExcelPkg.Workbook.Worksheets.Add("Sheet1");
  58. using (ExcelRange Rng = wsSheet1.Cells["B2:I2"])
  59. {
  60. Rng.Value = "Everyday Be Coding - Format Table using EPPlus .Net Library - Part 15(B)";
  61. Rng.Merge = true;
  62. Rng.Style.Font.Size = 16;
  63. Rng.Style.Font.Bold = true;
  64. Rng.Style.Font.Italic = true;
  65. }
  66. using (ExcelRange Rng = wsSheet1.Cells["B4:G12"])
  67. {
  68. ExcelTableCollection tblcollection = wsSheet1.Tables;
  69. ExcelTable table = tblcollection.Add(Rng, "tblSalesman");
  70. //Set Columns position & name
  71. table.Columns[0].Name = "Id";
  72. table.Columns[1].Name = "Salesman Name";
  73. table.Columns[2].Name = "Sales Amount";
  74. table.Columns[3].Name = "Profits";
  75. table.Columns[4].Name = "Country";
  76. table.Columns[5].Name = "Date";
  77. //table.ShowHeader = false;
  78. table.ShowFilter = true;
  79. table.ShowTotal = true;
  80. //Add TotalsRowFormula into Excel table Columns
  81. table.Columns[0].TotalsRowLabel = "Total Rows";
  82. table.Columns[1].TotalsRowFormula = "SUBTOTAL(102,[Id])"; //102 = Count
  83. table.Columns[2].TotalsRowFormula = "SUBTOTAL(109,[Sales Amount])"; //109 = Sum
  84. table.Columns[3].TotalsRowFormula = "SUBTOTAL(101,[Profits])"; //101 = Average
  85. //Add TotalsRowFunction into Excel table Columns
  86. //table.Columns[0].TotalsRowLabel = "Total Rows";
  87. //able.Columns[1].TotalsRowFunction = RowFunctions.Count;
  88. //table.Columns[2].TotalsRowFunction = RowFunctions.Sum;
  89. //table.Columns[3].TotalsRowFunction = RowFunctions.Average;
  90. table.TableStyle = TableStyles.Dark9;
  91. }
  92. //Insert data into the Excel Table Cells
  93. //"ID" Column
  94. string IntCellFormat = "###0;";
  95. using (ExcelRange Rng = wsSheet1.Cells["B5"])
  96. {
  97. Rng.Style.Numberformat.Format = IntCellFormat;
  98. Rng.Value = Convert.ToInt32("1001");
  99. }
  100. using (ExcelRange Rng = wsSheet1.Cells["B6"])
  101. {
  102. Rng.Style.Numberformat.Format = IntCellFormat;
  103. Rng.Value = Convert.ToInt32("1002");
  104. }
  105. using (ExcelRange Rng = wsSheet1.Cells["B7"])
  106. {
  107. Rng.Style.Numberformat.Format = IntCellFormat;
  108. Rng.Value = Convert.ToInt32("1003");
  109. }
  110. using (ExcelRange Rng = wsSheet1.Cells["B8"])
  111. {
  112. Rng.Style.Numberformat.Format = IntCellFormat;
  113. Rng.Value = Convert.ToInt32("1004");
  114. }
  115. using (ExcelRange Rng = wsSheet1.Cells["B9"])
  116. {
  117. Rng.Style.Numberformat.Format = IntCellFormat;
  118. Rng.Value = Convert.ToInt32("1005");
  119. }
  120. using (ExcelRange Rng = wsSheet1.Cells["B10"])
  121. {
  122. Rng.Style.Numberformat.Format = IntCellFormat;
  123. Rng.Value = Convert.ToInt32("1006");
  124. }
  125. using (ExcelRange Rng = wsSheet1.Cells["B11"])
  126. {
  127. Rng.Style.Numberformat.Format = IntCellFormat;
  128. Rng.Value = Convert.ToInt32("1007");
  129. }
  130. using (ExcelRange Rng = wsSheet1.Cells["B12"])
  131. {
  132. Rng.Style.Numberformat.Format = IntCellFormat;
  133. Rng.Value = Convert.ToInt32("1008");
  134. }
  135. //"Salesman Name" Column
  136. using (ExcelRange Rng = wsSheet1.Cells["C5"])
  137. {
  138. Rng.Value = "John";
  139. }
  140. using (ExcelRange Rng = wsSheet1.Cells["C6"])
  141. {
  142. Rng.Value = "Sunil";
  143. }
  144. using (ExcelRange Rng = wsSheet1.Cells["C7"])
  145. {
  146. Rng.Value = "Smith";
  147. }
  148. using (ExcelRange Rng = wsSheet1.Cells["C8"])
  149. {
  150. Rng.Value = "Rohit";
  151. }
  152. using (ExcelRange Rng = wsSheet1.Cells["C9"])
  153. {
  154. Rng.Value = "Matt";
  155. }
  156. using (ExcelRange Rng = wsSheet1.Cells["C10"])
  157. {
  158. Rng.Value = "Jack";
  159. }
  160. using (ExcelRange Rng = wsSheet1.Cells["C11"])
  161. {
  162. Rng.Value = "johnson";
  163. }
  164. using (ExcelRange Rng = wsSheet1.Cells["C12"])
  165. {
  166. Rng.Value = "Brown";
  167. }
  168. using (ExcelRange Rng = wsSheet1.Cells["C12"])
  169. {
  170. Rng.Value = "Brown";
  171. }
  172. using (ExcelRange Rng = wsSheet1.Cells["C13"])
  173. {
  174. Rng.Style.HorizontalAlignment = ExcelHorizontalAlignment.Left;
  175. }
  176. //"Sales Amount" Column
  177. string CurrencyCellFormat = "$###,###,##0.00";
  178. using (ExcelRange Rng = wsSheet1.Cells["D5"])//3
  179. {
  180. Rng.Style.Numberformat.Format = CurrencyCellFormat;
  181. Rng.Value = Convert.ToDecimal("700.00");
  182. }
  183. using (ExcelRange Rng = wsSheet1.Cells["D6"])
  184. {
  185. Rng.Style.Numberformat.Format = CurrencyCellFormat;
  186. Rng.Value = Convert.ToDecimal("800.00");
  187. }
  188. using (ExcelRange Rng = wsSheet1.Cells["D7"])
  189. {
  190. Rng.Style.Numberformat.Format = CurrencyCellFormat;
  191. Rng.Value = Convert.ToDecimal("1000.00");
  192. }
  193. using (ExcelRange Rng = wsSheet1.Cells["D8"])
  194. {
  195. Rng.Style.Numberformat.Format = CurrencyCellFormat;
  196. Rng.Value = Convert.ToDecimal("1100.00");
  197. }
  198. using (ExcelRange Rng = wsSheet1.Cells["D9"])
  199. {
  200. Rng.Style.Numberformat.Format = CurrencyCellFormat;
  201. Rng.Value = Convert.ToDecimal("5000.00");
  202. }
  203. using (ExcelRange Rng = wsSheet1.Cells["D10"])
  204. {
  205. Rng.Style.Numberformat.Format = CurrencyCellFormat;
  206. Rng.Value = Convert.ToDecimal("200.00");
  207. }
  208. using (ExcelRange Rng = wsSheet1.Cells["D11"])
  209. {
  210. Rng.Style.Numberformat.Format = CurrencyCellFormat;
  211. Rng.Value = Convert.ToDecimal("100.00");
  212. }
  213. using (ExcelRange Rng = wsSheet1.Cells["D12"])
  214. {
  215. Rng.Style.Numberformat.Format = CurrencyCellFormat;
  216. Rng.Value = Convert.ToDecimal("200.00");
  217. }
  218. using (ExcelRange Rng = wsSheet1.Cells["D13"])
  219. {
  220. Rng.Style.Numberformat.Format = CurrencyCellFormat;
  221. Rng.Style.HorizontalAlignment = ExcelHorizontalAlignment.Right;
  222. }
  223. //"Profits" Column
  224. string PersentageCellFormat = "#0\\.00%";
  225. using (ExcelRange Rng = wsSheet1.Cells["E5"])
  226. {
  227. Rng.Style.Numberformat.Format = PersentageCellFormat;
  228. Rng.Value = Convert.ToDecimal(50.01);
  229. }
  230. using (ExcelRange Rng = wsSheet1.Cells["E6"])
  231. {
  232. Rng.Style.Numberformat.Format = PersentageCellFormat;
  233. Rng.Value = Convert.ToDecimal(20.02);
  234. }
  235. using (ExcelRange Rng = wsSheet1.Cells["E7"])
  236. {
  237. Rng.Style.Numberformat.Format = PersentageCellFormat;
  238. Rng.Value = Convert.ToInt32(56.30);
  239. }
  240. using (ExcelRange Rng = wsSheet1.Cells["E8"])
  241. {
  242. Rng.Style.Numberformat.Format = PersentageCellFormat;
  243. Rng.Value = Convert.ToDecimal(45.90);
  244. }
  245. using (ExcelRange Rng = wsSheet1.Cells["E9"])
  246. {
  247. Rng.Style.Numberformat.Format = PersentageCellFormat;
  248. Rng.Value = Convert.ToDecimal(90.92);
  249. }
  250. using (ExcelRange Rng = wsSheet1.Cells["E10"])
  251. {
  252. Rng.Style.Numberformat.Format = PersentageCellFormat;
  253. Rng.Value = Convert.ToDecimal(80.88);
  254. }
  255. using (ExcelRange Rng = wsSheet1.Cells["E11"])
  256. {
  257. Rng.Style.Numberformat.Format = PersentageCellFormat;
  258. Rng.Value = Convert.ToDecimal(76.90);
  259. }
  260. using (ExcelRange Rng = wsSheet1.Cells["E12"])
  261. {
  262. Rng.Style.Numberformat.Format = PersentageCellFormat;
  263. Rng.Value = Convert.ToDecimal(39.9);
  264. }
  265. using (ExcelRange Rng = wsSheet1.Cells["E13"])
  266. {
  267. Rng.Style.Numberformat.Format = PersentageCellFormat;
  268. Rng.Style.HorizontalAlignment = ExcelHorizontalAlignment.Right;
  269. }
  270. //"Country" Column
  271. using (ExcelRange Rng = wsSheet1.Cells["F5"])
  272. {
  273. Rng.Value = "UK";
  274. }
  275. using (ExcelRange Rng = wsSheet1.Cells["F6"])
  276. {
  277. Rng.Value = "IND";
  278. }
  279. using (ExcelRange Rng = wsSheet1.Cells["F7"])
  280. {
  281. Rng.Value = "USA";
  282. }
  283. using (ExcelRange Rng = wsSheet1.Cells["F8"])
  284. {
  285. Rng.Value = "IND";
  286. }
  287. using (ExcelRange Rng = wsSheet1.Cells["F9"])
  288. {
  289. Rng.Value = "USA";
  290. }
  291. using (ExcelRange Rng = wsSheet1.Cells["F10"])
  292. {
  293. Rng.Value = "IND";
  294. }
  295. using (ExcelRange Rng = wsSheet1.Cells["F11"])
  296. {
  297. Rng.Value = "UK";
  298. }
  299. using (ExcelRange Rng = wsSheet1.Cells["F12"])
  300. {
  301. Rng.Value = "UK";
  302. }
  303. //"Date" Column
  304. string DateCellFormat = "mm/dd/yyyy";
  305. using (ExcelRange Rng = wsSheet1.Cells["G5"])
  306. {
  307. Rng.Style.Numberformat.Format = DateCellFormat;
  308. Rng.Value = Convert.ToDateTime("10/30/2016");
  309. }
  310. using (ExcelRange Rng = wsSheet1.Cells["G6"])
  311. {
  312. Rng.Style.Numberformat.Format = DateCellFormat;
  313. Rng.Value = Convert.ToDateTime("06/23/2017");
  314. }
  315. using (ExcelRange Rng = wsSheet1.Cells["G7"])
  316. {
  317. Rng.Style.Numberformat.Format = DateCellFormat;
  318. Rng.Value = Convert.ToDateTime("05/13/2017");
  319. }
  320. using (ExcelRange Rng = wsSheet1.Cells["G8"])
  321. {
  322. Rng.Style.Numberformat.Format = DateCellFormat;
  323. Rng.Value = Convert.ToDateTime("09/10/2017");
  324. }
  325. using (ExcelRange Rng = wsSheet1.Cells["G9"])
  326. {
  327. Rng.Style.Numberformat.Format = DateCellFormat;
  328. Rng.Value = Convert.ToDateTime("07/26/2017");
  329. }
  330. using (ExcelRange Rng = wsSheet1.Cells["G10"])
  331. {
  332. Rng.Style.Numberformat.Format = DateCellFormat;
  333. Rng.Value = Convert.ToDateTime("08/26/2017");
  334. }
  335. using (ExcelRange Rng = wsSheet1.Cells["G11"])
  336. {
  337. Rng.Style.Numberformat.Format = DateCellFormat;
  338. Rng.Value = Convert.ToDateTime("09/10/2017");
  339. }
  340. using (ExcelRange Rng = wsSheet1.Cells["G12"]) //1
  341. {
  342. Rng.Style.Numberformat.Format = DateTimeFormatInfo.CurrentInfo.ShortDatePattern;
  343. Rng.Value = Convert.ToDateTime("09/10/2017");
  344. }
  345. using (ExcelRange Rng = wsSheet1.Cells["I12"])
  346. {
  347. Rng.Style.Numberformat.Format = DateTimeFormatInfo.CurrentInfo.ShortDatePattern;
  348. Rng.Value = Convert.ToDateTime("09/10/2017");
  349. }
  350. using (ExcelRange Rng = wsSheet1.Cells["J12"]) //2
  351. {
  352. Rng.Style.Numberformat.Format = "yyyy-mm-dd hh:mm:ss";
  353. Rng.Value = Convert.ToDateTime("09/10/2017");
  354. }
  355. using (ExcelRange Rng = wsSheet1.Cells["K12"])
  356. {
  357. Rng.Style.Numberformat.Format = "#,##0.00";
  358. Rng.Value = Convert.ToDouble("500000.06");
  359. }
  360. wsSheet1.Cells[wsSheet1.Dimension.Address].AutoFitColumns();
  361. //ExcelPkg.SaveAs(new FileInfo(@"E:\FormatExcelTable.xlsx"));
  362. ExcelPkg.Workbook.Properties.Title = "DetailTransactionReport";
  363. this.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
  364. this.Response.AddHeader(
  365. "content-disposition",
  366. string.Format("attachment; filename={0}", "test.xlsx"));
  367. this.Response.BinaryWrite(ExcelPkg.GetAsByteArray());
  368. }
  369. private void EnableGoogle2FAuth()
  370. {
  371. Google2FAuthDiv.Visible = true;
  372. verificationCode.Enabled = true;
  373. Google2FAuthDivCode.Visible = false;
  374. employeeId.Enabled = false;
  375. }
  376. private void PopulateDDL()
  377. {
  378. _sdd.SetDDL(ref ddlBranch, "EXEC proc_sendPageLoadData @flag='LOGIN-BRANCH'", "agentId", "agentName", "", "Select Login Branch");
  379. }
  380. private void DisableGoogle2FAuth()
  381. {
  382. Google2FAuthDiv.Visible = false;
  383. verificationCode.Enabled = false;
  384. Google2FAuthDivCode.Visible = true;
  385. employeeId.Enabled = true;
  386. }
  387. private void ValidateDc()
  388. {
  389. var ipAddress = Request.ServerVariables["REMOTE_ADDR"];
  390. var dcIdNo = Request.ClientCertificate["SERIALNUMBER"];
  391. var dcUserName = Request.ClientCertificate["SUBJECTCN"];
  392. var res = user.ValidateDcId(dcIdNo, dcUserName, ipAddress);
  393. if (res.ErrorCode != "0")
  394. {
  395. Response.Redirect(GetStatic.GetUrlRoot() + "/SiteDown/");
  396. }
  397. }
  398. private void ValidateIPAddress()
  399. {
  400. var ipAddress = Request.ServerVariables["REMOTE_ADDR"];
  401. System.Web.HttpBrowserCapabilities browser = Request.Browser;
  402. var result = user.GetIpStatus(ipAddress, browser.Platform);
  403. if (result.ErrorCode == "1")
  404. {
  405. //LoginBox.Visible = false;
  406. //sslRow.Visible = false;
  407. errMsg.InnerHtml = result.Msg;
  408. var mailBody = "<div style=\"font-size:24px; font-weight:bold\"> Suspicious Access From Outside Nepal </div><br />";
  409. mailBody += "<div style=\"background-color:#F00; font-size:18px; font-weight:bold; width:300px;\">IP: " + ipAddress + "</div><br />";
  410. mailBody += "<div style=\"font-size:18px; font-weight:bold; width:300px;\"> System Info </div>";
  411. var info = GetUserInfo(true);
  412. info = info.Replace("-:::-", "<br />");
  413. mailBody += info;
  414. var email = "";
  415. //GetStatic.SendEmail(ref email, "", "", "", "Fraud Analysis", mailBody, "", "0");
  416. }
  417. if (result.Id.Replace(ipAddress + ",", "") == "Y")
  418. {
  419. Response.Redirect(GetStatic.GetUrlRoot() + "/SiteDown/");
  420. }
  421. }
  422. private void EnableLogin()
  423. {
  424. btnLogin.Enabled = true;
  425. }
  426. private void DisableLogin()
  427. {
  428. btnLogin.Enabled = false;
  429. }
  430. private void Authenticate()
  431. {
  432. string IsForTablet = GetStatic.ReadFormData("checkbox_login_as_tab", "false") == "on" ? "true" : "false";
  433. DisableLogin();
  434. GetStatic.WriteCookie("loginType", "AGENTINT");
  435. var ipAddress = Request.ServerVariables["REMOTE_ADDR"];
  436. var dcIdNo = Request.ClientCertificate["SERIALNUMBER"];
  437. var dcUserName = Request.ClientCertificate["SUBJECTCN"];
  438. var dr = user.DoLoginForIntlAgent(username.Text, pwd.Text, employeeId.Text, GetUserInfo(), ipAddress, dcIdNo, dcUserName, GetStatic.GetLocation(ipAddress), verificationCode.Text, ddlBranch.SelectedValue, GetStatic.ReadWebConfig("UseGoogle2FAuthAgent", ""));
  439. //Check Authentication From DB
  440. if (dr.ErrorCode != "0")
  441. {
  442. if (dr.ErrorCode == "2")
  443. {
  444. var dbr = ManageLoginAttempts(dr.Id, dr.AttemptCount);
  445. if (dbr.ErrorCode != "-13")
  446. dr.Msg = dbr.Msg;
  447. }
  448. errMsg.InnerHtml = dr.Msg;
  449. errMsg.Visible = true;
  450. EnableLogin();
  451. return;
  452. }
  453. if (GetStatic.ReadWebConfig("UseGoogle2FAuthAgent", "") == "Y")
  454. {
  455. if (string.IsNullOrEmpty(dr.UserUniqueKey))
  456. {
  457. errMsg.InnerText = "Please contact JME Head office to get QR code for accessing JME Remit system!";
  458. errMsg.Visible = true;
  459. EnableLogin();
  460. return;
  461. }
  462. var _dbRes = _auth.Verify2FA(verificationCode.Text, dr.UserUniqueKey);
  463. user.Log2FAuth(dr.logId, _dbRes.ErrorCode == "0" ? "1" : "0");
  464. if (_dbRes.ErrorCode != "0")
  465. {
  466. errMsg.InnerText = _dbRes.Msg;
  467. errMsg.Visible = true;
  468. EnableLogin();
  469. return;
  470. }
  471. }
  472. var usrName = user.FilterQuote(username.Text);
  473. if (dr.UserAccessLevel.ToUpper() == "S")
  474. {
  475. if (userPool.IsUserExists(usrName))
  476. {
  477. //Session.Add("call", "admin");
  478. Session.Add("usr", usrName);
  479. var url = GetStatic.GetUrlRoot() + "/LoginSession.aspx";
  480. Response.Redirect(url);
  481. return;
  482. }
  483. }
  484. //Check User Pool
  485. var dbResult = ManageUserSession(dr, IsForTablet);
  486. if (dbResult.ErrorCode != "0")
  487. {
  488. errMsg.InnerHtml = dbResult.Msg;
  489. //mes.ForeColor = System.Drawing.Color.Red;
  490. EnableLogin();
  491. return;
  492. }
  493. if (dr.isForcePwdChanged.ToUpper() == "Y")
  494. {
  495. Response.Redirect("../SwiftSystem/UserManagement/AgentUserSetup/ChangePassword.aspx");
  496. }
  497. Response.Redirect("/AgentNew/Dashboard.aspx");
  498. }
  499. private DbResult ManageUserSession(UserDetails ud, string IsForTablet)
  500. {
  501. Session.Clear();
  502. var res = SetUserPool(ud);
  503. if (res.ErrorCode != "0")
  504. return res;
  505. GetStatic.WriteSession("IsForTablet", IsForTablet);
  506. GetStatic.WriteSession("admin", ud.Id);
  507. GetStatic.WriteSession("fullname", ud.FullName);
  508. GetStatic.WriteCookie("loginType", "AGENT");
  509. //GetStatic.WriteSession("branchId", ud.Branch);
  510. //GetStatic.WriteSession("branchName", ud.BranchName);
  511. //GetStatic.WriteSession("address", ud.Address);
  512. //GetStatic.WriteSession("userType", ud.UserType);
  513. var cookieKey = ud.Id + "_userSessionId";
  514. GetStatic.WriteCookie(cookieKey, GetStatic.GetSessionId());
  515. return res;
  516. }
  517. private DbResult SetUserPool(UserDetails ud)
  518. {
  519. GetStatic.WriteSession("branch", ud.Branch);
  520. GetStatic.WriteSession("branchName", ud.BranchName);
  521. GetStatic.WriteSession("agent", ud.Agent);
  522. GetStatic.WriteSession("agentName", ud.AgentName);
  523. GetStatic.WriteSession("branch", ddlBranch.SelectedValue);
  524. GetStatic.WriteSession("branchName", ddlBranch.SelectedItem.Text);
  525. GetStatic.WriteSession("agent", ddlBranch.SelectedValue);
  526. GetStatic.WriteSession("agentName", ddlBranch.SelectedItem.Text);
  527. GetStatic.WriteSession("superAgent", ud.SuperAgent);
  528. GetStatic.WriteSession("superAgentName", ud.SuperAgentName);
  529. //GetStatic.WriteSession("settlingAgent", ud.SettlingAgent);
  530. GetStatic.WriteSession("settlingAgent", ddlBranch.SelectedValue);
  531. //GetStatic.WriteSession("mapCodeInt", ud.MapCodeInt);
  532. //GetStatic.WriteSession("parentMapCodeInt", ud.ParentMapCodeInt);
  533. //GetStatic.WriteSession("mapCodeDom", ud.MapCodeDom);
  534. GetStatic.WriteSession("mapCodeInt", ddlBranch.SelectedValue);
  535. GetStatic.WriteSession("parentMapCodeInt", ddlBranch.SelectedValue);
  536. GetStatic.WriteSession("mapCodeDom", ddlBranch.SelectedValue);
  537. GetStatic.WriteSession("agentType", ud.AgentType);
  538. GetStatic.WriteSession("isActAsBranch", ud.IsActAsBranch);
  539. GetStatic.WriteSession("fromSendTrnTime", ud.FromSendTrnTime);
  540. GetStatic.WriteSession("toSendTrnTime", ud.ToSendTrnTime);
  541. GetStatic.WriteSession("fromPayTrnTime", ud.FromPayTrnTime);
  542. GetStatic.WriteSession("toPayTrnTime", ud.ToPayTrnTime);
  543. GetStatic.WriteSession("country", ud.Country);
  544. GetStatic.WriteSession("countryId", ud.CountryId);
  545. GetStatic.WriteSession("userType", ud.UserType);
  546. GetStatic.WriteSession("isHeadOffice", ud.IsHeadOffice);
  547. GetStatic.WriteSession("newBranchId", ud.newBranchId);
  548. GetStatic.WriteSession("agentLocation", ud.AgentLocation);
  549. GetStatic.WriteSession("agentGrp", ud.AgentGrp);
  550. GetStatic.WriteSession("agentEmail", ud.AgentEmail);
  551. GetStatic.WriteSession("agentPhone", ud.AgentPhone);
  552. GetStatic.WriteSession("user", ud.Id);
  553. GetStatic.WriteSession("agentType", "send");
  554. HttpBrowserCapabilities browser = Request.Browser;
  555. var usr = new LoggedInUser();
  556. Session[ud.Agent + "Menu"] = new StringBuilder();
  557. usr.UserId = GetStatic.ParseInt(ud.UserId);
  558. usr.UserName = ud.Id;
  559. usr.UserFullName = ud.FullName;
  560. usr.LoginTime = DateTime.Now;
  561. usr.UserAccessLevel = ud.UserAccessLevel;
  562. usr.UserAgentName = ud.BranchName;
  563. usr.SessionTimeOutPeriod = GetStatic.ParseInt(ud.sessionTimeOut);
  564. usr.LastLoginTime = Convert.ToDateTime(ud.LastLoginTs);
  565. Session.Timeout = usr.SessionTimeOutPeriod;
  566. usr.LoginAddress = ud.LoginAddress;
  567. usr.LastLoginTime = Convert.ToDateTime(ud.LastLoginTs);
  568. usr.Browser = browser.Browser + "/" + browser.Type;
  569. usr.IPAddress = Request.ServerVariables["REMOTE_ADDR"];
  570. usr.SessionID = GetStatic.GetSessionId();
  571. usr.DcInfo = Request.ClientCertificate["SERIALNUMBER"] + ":" + Request.ClientCertificate["SUBJECTCN"];
  572. return userPool.AddUser(usr);
  573. }
  574. private DbResult ManageLoginAttempts(string id, int attemptCount)
  575. {
  576. var countLoginAttemptsInt = GetStatic.ParseInt(GetStatic.ReadSession(id, "0"));
  577. countLoginAttemptsInt++;
  578. GetStatic.WriteSession(id, (countLoginAttemptsInt).ToString());
  579. var dbResult = new DbResult();
  580. dbResult.SetError("-13", "", "");
  581. if (countLoginAttemptsInt >= attemptCount)
  582. {
  583. var lockReason = "Your account has been locked to due to continuous invalid login attempt.";
  584. dbResult = user.DoLockAccount(id, lockReason);
  585. GetStatic.WriteSession(id, "0");
  586. dbResult.SetError("2", lockReason, "");
  587. //dbResult.ErrorCode = "2";
  588. }
  589. return dbResult;
  590. }
  591. private string GetUserInfo()
  592. {
  593. return "";// "IP Adress = " + Request.ServerVariables["REMOTE_ADDR"];
  594. }
  595. private string GetUserInfo(bool fullInfo)
  596. {
  597. System.Web.HttpBrowserCapabilities browser = Request.Browser;
  598. string str = " Browser Capabilities = Values -:::-"
  599. + "Type = " + browser.Type + "-:::-" //-:::-
  600. + "Name = " + browser.Browser + "-:::-"
  601. + "Version = " + browser.Version + "-:::-"
  602. + "Major Version = " + browser.MajorVersion + "-:::-"
  603. + "Minor Version = " + browser.MinorVersion + "-:::-"
  604. + "Platform = " + browser.Platform + "-:::-"
  605. + "Is Beta = " + browser.Beta + "-:::-"
  606. + "Is Crawler = " + browser.Crawler + "-:::-"
  607. + "Is AOL = " + browser.AOL + "-:::-"
  608. + "Is Win16 = " + browser.Win16 + "-:::-"
  609. + "Is Win32 = " + browser.Win32 + "-:::-"
  610. + "Supports Frames = " + browser.Frames + "-:::-"
  611. + "Supports Tables = " + browser.Tables + "-:::-"
  612. + "Supports Cookies = " + browser.Cookies + "-:::-"
  613. + "Supports VBScript = " + browser.VBScript + "-:::-"
  614. + "Supports JavaScript = " + browser.EcmaScriptVersion.ToString() + "-:::-"
  615. + "Supports Java Applets = " + browser.JavaApplets + "-:::-"
  616. + "Supports ActiveX Controls = " + browser.ActiveXControls + "-:::-"
  617. + "Supports JavaScript Version = " + browser["JavaScriptVersion"] + "-:::-"
  618. + "CDF = " + browser.CDF + "-:::-"
  619. + "IP Adress = " + Request.ServerVariables["REMOTE_ADDR"] + "-:::-"
  620. + "User Agent = " + Request.ServerVariables["HTTP_USER_AGENT"] + "-:::-"
  621. + "Refrerer = " + Request.ServerVariables["HTTP_REFERER"] + "-:::-"
  622. + "Http Accept = " + Request.ServerVariables["HTTP_ACCEPT"] + "-:::-"
  623. + "Language = " + Request.ServerVariables["HTTP_ACCEPT_LANGUAGE"];
  624. return str;
  625. }
  626. protected void btnLogin_Click(object sender, EventArgs e)
  627. {
  628. Authenticate();
  629. }
  630. protected void btnFlushUser_Click(object sender, EventArgs e)
  631. {
  632. userPool.RemoveUser(GetStatic.GetUser());
  633. }
  634. }
  635. }