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.

579 lines
25 KiB

  1. using System;
  2. using System.Data;
  3. using System.Data.SqlClient;
  4. using System.Text;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using Swift.DAL.SwiftDAL;
  8. using Swift.web.Library;
  9. using Swift.DAL.BL.SwiftSystem;
  10. namespace Swift.web.SwiftSystem.UserManagement.AgentSetup
  11. {
  12. public partial class Manage : Page
  13. {
  14. private const string ViewFunctionId = "20111000";
  15. private const string AddEditFunctionId = "20111010";
  16. private const string DeleteFunctionId = "20111020";
  17. private readonly StaticDataDdl _sdd = new StaticDataDdl();
  18. private readonly AgentDao obj = new AgentDao();
  19. protected void Page_Load(object sender, EventArgs e)
  20. {
  21. Authenticate();
  22. string PType = GetPageType();
  23. if (!IsPostBack)
  24. {
  25. intlCheck.Checked = false;
  26. branchCodeField.Visible = false;
  27. var actAsBranch = GetStatic.ReadQueryString("actAsBranch", "");
  28. if (actAsBranch == "N" && GetAgentType() == "2902")
  29. {
  30. intlCheck.Checked = true;
  31. }
  32. if (actAsBranch == "Y" && GetAgentType() == "2903")
  33. {
  34. branchCodeField.Visible = true;
  35. }
  36. //payOption.Items.Insert(0, new ListItem("Select", ""));
  37. pnl1.Visible = GetMode().ToString() == "1";
  38. MakeNumericTextBox();
  39. CheckMessageHead();
  40. btnDelete.Visible = (GetAgentId() > 0 ? true : false);
  41. if (GetAgentId() > 0)
  42. {
  43. //spnCname.InnerHtml = _sdd.GetAgentBreadCrumb(GetAgentId().ToString());
  44. LoadTab();
  45. PopulateDataById();
  46. ManageEditMode();
  47. }
  48. else
  49. {
  50. // spnCname.InnerHtml = _sdd.GetAgentBreadCrumb(GetParentId().ToString());
  51. PopulateDdl(null);
  52. ConfigurePageLoad();
  53. PullDefaultValueById();
  54. }
  55. }
  56. if (PType == "agentDetail")
  57. {
  58. bntSubmit.Visible = false;
  59. btnDelete.Visible = false;
  60. divTab.InnerHtml = "";
  61. }
  62. }
  63. private void LoadTab()
  64. {
  65. divTab.Visible = true;
  66. var html = new StringBuilder();
  67. var agentId = GetAgentId();
  68. var mode = GetMode();
  69. var parentId = GetParentId();
  70. var sParentId = GetParentId();
  71. var aType = GetAgentType();
  72. var actAsBranch = GetActAsBranchFlag();
  73. html.Append(
  74. "<table width=\"100%\" border=\"0\" align=\"left\" cellpadding=\"0\" cellspacing=\"0\" style=\"clear: both; margin-left:16px;\">" +
  75. "<tr><td height=\"10\">");
  76. html.Append("<ul class=\"nav nav-tabs\" role=\"tablist\"><li class=\"active\"> <a href=\"#\" class=\"selected\">Agent Information </a></li>" +
  77. "<li> <a href=\"../../../Remit/Administration/AgentSetup/AgentCurrency.aspx?agentId=" + agentId + "&mode=" + mode + "&parent_id=" + parentId + "&sParentId=" + sParentId + "&aType=" + aType + "&actAsBranch=" + actAsBranch + "\"> Allowed Currency </a></li>" +
  78. "<li> <a href=\"../../../Remit/Administration/AgentSetup/AgentBusinessHistory.aspx?agentId=" + agentId + "&mode=" + mode + "&parent_id=" + parentId + "&sParentId=" + sParentId + "&aType=" + aType + "&actAsBranch=" + actAsBranch + "\"> Business History </a></li>" +
  79. "<li> <a href=\"../../../Remit/Administration/AgentSetup/OwnerInf/List.aspx?agentId=" + agentId + "&mode=" + mode + "&parent_id=" + parentId + "&sParentId=" + sParentId + "&aType=" + aType + "&actAsBranch=" + actAsBranch + "\">Owners</a></li>" +
  80. "<li> <a href=\"../../../Remit/Administration/AgentSetup/Document/List.aspx?agentId=" + agentId + "&mode=" + mode + "&parent_id=" + parentId + "&sParentId=" + sParentId + "&aType=" + aType + "&actAsBranch=" + actAsBranch + "\">Required Document</a></li>" +
  81. "<li> <a href=\"../../../Remit/Administration/AgentSetup/AgentContactPerson/List.aspx?agentId=" + agentId + "&mode=" + mode + "&parent_id=" + parentId + "&sParentId=" + sParentId + "&aType=" + aType + "&actAsBranch=" + actAsBranch + "\">Contact Person</a></li>" +
  82. "<li> <a href=\"../../../Remit/Administration/AgentSetup/AgentBankAccount/List.aspx?agentId=" + agentId + "&mode=" + mode + "&parent_id=" + parentId + "&sParentId=" + sParentId + "&aType=" + aType + "&actAsBranch=" + actAsBranch + "\">Bank Account</a></li>" +
  83. "</ul> ");
  84. html.Append("</td></tr></table>");
  85. divTab.InnerHtml = html.ToString();
  86. }
  87. private void PullDefaultValueById()
  88. {
  89. DataRow dr = obj.PullDefaultValueById(GetStatic.GetUser(), GetParentId().ToString());
  90. if (dr == null)
  91. return;
  92. agentCity.Text = dr["agentCity"].ToString();
  93. //agentZip.Text = dr["agentZip"].ToString();
  94. isActive.SelectedValue = dr["isActive"].ToString();
  95. if (GetAgentType() == "2904")
  96. agentName.Text = dr["agentName"] + " - ";
  97. PopulateDdl(dr);
  98. }
  99. private void CheckMessageHead()
  100. {
  101. if (GetAgentType() == "2904")
  102. headMsgShow.Visible = true;
  103. else if (GetAgentType() == "2903" && GetActAsBranchFlag() == "Y")
  104. headMsgShow.Visible = true;
  105. }
  106. private void ManageEditMode()
  107. {
  108. isSettlingAgent.Enabled = false;
  109. agentCountry.Enabled = false;
  110. }
  111. private void ConfigurePageLoad()
  112. {
  113. isSettlingAgent.Text = "N";
  114. var IsSettling = obj.GetParentAgentSettlementStatus(GetParentId().ToString());
  115. if (GetAgentType() == "2904" || GetActAsBranchFlag() == "Y")
  116. {
  117. if (IsSettling != "Y")
  118. {
  119. isSettlingAgent.Text = "Y";
  120. }
  121. isSettlingAgent.Enabled = false;
  122. }
  123. else
  124. {
  125. if (IsSettling == "Y")
  126. isSettlingAgent.Enabled = false;
  127. else
  128. isSettlingAgent.Enabled = true;
  129. }
  130. }
  131. private void MakeNumericTextBox()
  132. {
  133. //Misc.MakeNumericTextbox(ref agentZip);
  134. }
  135. #region QueryString
  136. protected string GetAgentName()
  137. {
  138. return "Agent Name : " + _sdd.GetAgentName(GetAgentId().ToString());
  139. }
  140. protected string GetFullDetail()
  141. {
  142. return GetStatic.ReadQueryString("fullDetail", "");
  143. }
  144. protected long GetAgentId()
  145. {
  146. return GetStatic.ReadNumericDataFromQueryString("agentId");
  147. }
  148. protected long GetMode()
  149. {
  150. return GetStatic.ReadNumericDataFromQueryString("mode");
  151. }
  152. protected String GetPageType()
  153. {
  154. return GetStatic.ReadQueryString("PageType", "");
  155. }
  156. protected long GetParentId()
  157. {
  158. return GetStatic.ReadNumericDataFromQueryString("parent_id");
  159. }
  160. protected long GetSParentId()
  161. {
  162. return GetStatic.ReadNumericDataFromQueryString("sParentId");
  163. }
  164. protected string GetAgentType()
  165. {
  166. string atype = GetStatic.ReadNumericDataFromQueryString("aType").ToString();
  167. return atype;
  168. }
  169. protected string GetActAsBranchFlag()
  170. {
  171. return GetStatic.ReadQueryString("actAsBranch", "");
  172. }
  173. #endregion
  174. #region Method
  175. private void Authenticate()
  176. {
  177. _sdd.CheckAuthentication(ViewFunctionId);
  178. btnDelete.Visible = _sdd.HasRight(DeleteFunctionId);
  179. bntSubmit.Visible = _sdd.HasRight(AddEditFunctionId);
  180. }
  181. private void PopulateDdl(DataRow dr)
  182. {
  183. string sql = "";
  184. string aType = GetAgentType();
  185. string mode = GetMode().ToString();
  186. if (mode == "1" || mode == "2")
  187. {
  188. if (aType == "")
  189. sql = "SELECT valueId, detailTitle FROM staticDataValue WHERE valueId IN(2900)";
  190. if (aType == "2901")
  191. sql = "SELECT valueId, detailTitle FROM staticDataValue WHERE valueId IN(2901)";
  192. if (aType == "2902" || aType == "2903")
  193. sql = "SELECT valueId, detailTitle FROM staticDataValue WHERE valueId IN(2902)";
  194. if (aType == "2903")
  195. sql = "SELECT valueId, detailTitle FROM staticDataValue WHERE valueId IN(2903)";
  196. if (aType == "2904")
  197. sql = "SELECT valueId, detailTitle FROM staticDataValue WHERE valueId IN(2904)";
  198. }
  199. else
  200. {
  201. if (aType == "2900")
  202. sql = "SELECT valueId, detailTitle FROM staticDataValue WHERE valueId IN(2901)";
  203. else if (aType == "2901")
  204. sql = "SELECT valueId, detailTitle FROM staticDataValue WHERE valueId IN(2902)";
  205. else if (aType == "2902")
  206. sql = "SELECT valueId, detailTitle FROM staticDataValue WHERE valueId IN(2903)";
  207. else if (aType == "2903")
  208. sql = "SELECT valueId, detailTitle FROM staticDataValue WHERE valueId IN(2904)";
  209. }
  210. _sdd.SetDDL(ref agentType, sql, "valueId", "detailTitle", GetStatic.GetRowData(dr, "agentType"), "");
  211. _sdd.SetStaticDdl(ref agentGroup, "4300", GetStatic.GetRowData(dr, "agentGrp"), "Select");
  212. _sdd.SetStaticDdl(ref businessOrgType, "4500", GetStatic.GetRowData(dr, "businessOrgType"), "Select");
  213. _sdd.SetStaticDdl(ref businessType, "6200", GetStatic.GetRowData(dr, "businessType"), "Select");
  214. _sdd.SetDDL(ref agentLocation, "EXEC proc_apiLocation @flag = 'l'", "districtCode", "districtName",
  215. GetStatic.GetRowData(dr, "agentLocation"), "Select");
  216. LoadCountry(ref agentCountry, GetStatic.GetRowData(dr, "agentCountry"));
  217. LoadRegionSettings(agentCountry.SelectedItem.Text);
  218. LoadState(ref agentState, agentCountry.Text, GetStatic.GetRowData(dr, "agentState"));
  219. LoadDistrict(ref agentDistrict, agentState.Text, GetStatic.GetRowData(dr, "agentDistrict"));
  220. _sdd.SetDDL(ref agentSettCurr, "EXEC proc_dropDownLists @flag = 'allCurr'", "currencyCode", "currencyCode",
  221. GetStatic.GetRowData(dr, "agentSettCurr"), "Select");
  222. }
  223. private void PopulateDataById()
  224. {
  225. DataRow dr = obj.SelectById(GetStatic.GetUser(), GetAgentId().ToString());
  226. if (dr == null)
  227. return;
  228. agentName.Text = dr["agentName"].ToString();
  229. agentAddress.Text = dr["agentAddress"].ToString();
  230. agentCity.Text = dr["agentCity"].ToString();
  231. //agentZip.Text = dr["agentZip"].ToString();
  232. agentPhone1.Text = dr["agentPhone1"].ToString();
  233. agentPhone2.Text = dr["agentPhone2"].ToString();
  234. agentFax1.Text = dr["agentFax1"].ToString();
  235. agentFax2.Text = dr["agentFax2"].ToString();
  236. agentMobile1.Text = dr["agentMobile1"].ToString();
  237. agentMobile2.Text = dr["agentMobile2"].ToString();
  238. agentEmail1.Text = dr["agentEmail1"].ToString();
  239. agentEmail2.Text = dr["agentEmail2"].ToString();
  240. bankBranch.Text = dr["bankBranch"].ToString();
  241. bankCode.Text = dr["bankCode"].ToString();
  242. accNumber.Text = dr["bankAccountNumber"].ToString();
  243. accHolderName.Text = dr["accountHolderName"].ToString();
  244. //agentRole.SelectedValue = dr["agentRole"].ToString();
  245. agentType.SelectedValue = dr["agentType"].ToString();
  246. //allowAccountDeposit.Text = dr["allowAccountDeposit"].ToString();
  247. contractExpiryDate.Text = dr["contractExpiryDate1"].ToString();
  248. renewalFollowupDate.Text = dr["renewalFollowupDate1"].ToString();
  249. isSettlingAgent.Text = dr["isSettlingAgent"].ToString();
  250. businessLicense.Text = dr["businessLicense"].ToString();
  251. agentBlock.SelectedValue = dr["agentBlock"].ToString();
  252. branchCode.Text = dr["branchCode"].ToString();
  253. branchCode.ReadOnly = true;
  254. agentDetails.Text = dr["agentDetails"].ToString();
  255. isActive.SelectedValue = dr["isActive"].ToString();
  256. mapCodeDom.Text = dr["mapCodeDom"].ToString();
  257. partnerBankcode.Text = dr["routingCode"].ToString();
  258. agentDetails.Text = dr["agentDetails"].ToString();
  259. headMessage.Text = dr["headMessage"].ToString();
  260. contactPerson1.Text = dr["contactPerson1"].ToString();
  261. contactPerson2.Text = dr["contactPerson2"].ToString();
  262. isHeadOffice.Text = dr["isHeadOffice"].ToString();
  263. isApiPartner.Checked = string.IsNullOrEmpty(dr["isApiPartner"].ToString()) ? false : Convert.ToBoolean(dr["isApiPartner"].ToString());
  264. intlCheck.Checked = string.IsNullOrEmpty(dr["IsIntl"].ToString()) ? false : Convert.ToBoolean(dr["IsIntl"].ToString());
  265. divAuditLog.InnerHtml = _sdd.GetAuditLog(dr);
  266. PopulateDdl(dr);
  267. }
  268. private void Update()
  269. {
  270. string isInt = intlCheck.Checked ? "1" : "0";
  271. string isAPIPartner = isApiPartner.Checked ? "1" : "0";
  272. agentBlock.Text = "U";
  273. try
  274. {
  275. DbResult dbResult = obj.Update(GetStatic.GetUser()
  276. , GetAgentId().ToString()
  277. , GetParentId().ToString()
  278. , agentName.Text
  279. , agentAddress.Text
  280. , agentCity.Text
  281. , agentCountry.Text
  282. , agentCountry.Text == "" ? agentCountry.Text : agentCountry.SelectedItem.Text
  283. , agentState.Text == "" ? agentState.Text : agentState.SelectedItem.Text
  284. , agentDistrict.Text == "" ? agentDistrict.Text : agentDistrict.SelectedItem.Text
  285. //, agentZip.Text
  286. , agentLocation.Text
  287. , agentPhone1.Text
  288. , agentPhone2.Text
  289. , agentFax1.Text
  290. , agentFax2.Text
  291. , agentMobile1.Text
  292. , agentMobile2.Text
  293. , agentEmail1.Text
  294. , agentEmail2.Text
  295. , bankBranch.Text
  296. , bankCode.Text
  297. , accNumber.Text
  298. , accHolderName.Text
  299. , businessOrgType.Text
  300. , businessType.Text
  301. , agentType.Text
  302. , GetActAsBranchFlag()
  303. , contractExpiryDate.Text
  304. , renewalFollowupDate.Text
  305. , isSettlingAgent.Text
  306. , agentGroup.Text
  307. , businessLicense.Text
  308. , agentBlock.Text
  309. , agentDetails.Text
  310. , isActive.Text
  311. , headMessage.Text
  312. , mapCodeDom.Text
  313. , partnerBankcode.Text
  314. , agentSettCurr.Text
  315. , contactPerson1.Text
  316. , contactPerson2.Text
  317. , isInt
  318. , isAPIPartner
  319. , isHeadOffice.Text,
  320. branchCode.Text
  321. );
  322. lblMsg.Text = dbResult.Msg;
  323. ManageMessage(dbResult);
  324. }
  325. catch (SqlException ex)
  326. {
  327. var dbResult = new DbResult();
  328. dbResult.SetError("1", "Cannot save data : " + ex, "");
  329. ManageMessage(dbResult);
  330. }
  331. }
  332. private void DeleteRow()
  333. {
  334. DbResult dbResult = obj.Delete(GetStatic.GetUser(), GetAgentId().ToString());
  335. ManageMessage(dbResult);
  336. }
  337. private void ManageMessage(DbResult dbResult)
  338. {
  339. GetStatic.SetMessage(dbResult);
  340. if (dbResult.ErrorCode == "0")
  341. {
  342. if (GetMode().ToString() == "1")
  343. Response.Redirect("Functions/ListAgent.aspx");
  344. else
  345. {
  346. Response.Redirect("List.aspx");
  347. string mes = GetStatic.ParseResultJsPrint(dbResult);
  348. mes = mes.Replace("<center>", "");
  349. mes = mes.Replace("</center>", "");
  350. string scriptName = "CallBack";
  351. string functionName = "CallBack('" + mes + "')";
  352. GetStatic.CallBackJs1(Page, scriptName, functionName);
  353. Session.Remove("message");
  354. }
  355. //ScriptManager.RegisterStartupScript(this, this.GetType(), "CloseWindow", "parent.parent.GB_hide()", true);
  356. }
  357. else
  358. {
  359. if (GetMode() == 2)
  360. GetStatic.AlertMessage(Page);
  361. else
  362. GetStatic.PrintMessage(Page);
  363. }
  364. }
  365. private void LoadState(ref DropDownList ddl, string countryId, string defaultValue)
  366. {
  367. //string sql = "EXEC Proc_dropdown_remit @flag='static', @typeId = '2'";
  368. //_sdd.SetDDL3(ref ddl, sql, "valueId", "detailTitle", defaultValue, "Select");
  369. string sql = "exec proc_dropdown_remit @flag='filterState', @countryId = '" + agentCountry.SelectedValue + "'";
  370. _sdd.SetDDL3(ref ddl, sql, "stateId", "stateName", defaultValue, "select");
  371. }
  372. private void LoadDistrict(ref DropDownList ddl, string zone, string defaultValue)
  373. {
  374. //string sql = "EXEC Proc_dropdown_remit @flag='static', @typeId = '3'";
  375. //_sdd.SetDDL3(ref ddl, sql, "valueId", "detailTitle", defaultValue, "Select");
  376. string sql = "EXEC Proc_dropdown_remit @flag = 'filterDist', @zone = '" + agentState.SelectedValue + "'";
  377. _sdd.SetDDL(ref agentDistrict, sql, "districtName", "districtName", defaultValue, "Select District");
  378. }
  379. private void LoadCountry(ref DropDownList ddl, string defaultValue)
  380. {
  381. string sql = "EXEC Proc_dropdown_remit @flag='country'";
  382. _sdd.SetDDL3(ref ddl, sql, "countryId", "countryName", defaultValue, "Select");
  383. }
  384. #endregion
  385. #region Control Methods
  386. protected void bntSubmit_Click(object sender, EventArgs e)
  387. {
  388. string atype = GetStatic.ReadNumericDataFromQueryString("aType").ToString();
  389. if (atype == "2904" && branchCode.Text.Length < 3)
  390. {
  391. var dbResult = new DbResult()
  392. {
  393. ErrorCode = "1",
  394. Msg = "Branch code must be three characters",
  395. Id = null
  396. };
  397. branchCodeField.Visible = true;
  398. ManageMessage(dbResult);
  399. }
  400. else
  401. {
  402. Update();
  403. }
  404. }
  405. protected void btnDelete_Click(object sender, EventArgs e)
  406. {
  407. DeleteRow();
  408. }
  409. protected void agentCountry_SelectedIndexChanged(object sender, EventArgs e)
  410. {
  411. //if (agentCountry.SelectedValue != "")
  412. //{
  413. // _sdd.SetDDL(ref agentState, "Proc_dropdown_remit @flag = 'filterState', @countryId = '" + agentCountry.SelectedValue + "'", "stateId", "stateName", "", "Select State");
  414. //}
  415. LoadState(ref agentState, agentCountry.Text, "");
  416. LoadRegionSettings(agentCountry.SelectedItem.Text);
  417. agentCountry.Focus();
  418. }
  419. protected void agentState_SelectedIndexChanged(object sender, EventArgs e)
  420. {
  421. //if (agentDistrict.SelectedValue != "")
  422. //{
  423. // _sdd.SetDDL(ref agentDistrict, "Proc_dropdown_remit @flag = 'filterDist', @zone = '" + agentState.SelectedValue + "'", "districtId", "districtName", "", "Select District");
  424. //}
  425. LoadDistrict(ref agentDistrict, agentState.Text, "");
  426. agentState.Focus();
  427. }
  428. protected void companyCountry_SelectedIndexChanged(object sender, EventArgs e)
  429. {
  430. //LoadState(ref companyState, companyCountry.Text, "");
  431. //LoadCompanyRegionSettings(companyCountry.SelectedItem.Text);
  432. //companyCountry.Focus();
  433. }
  434. protected void companyState_SelectedIndexChanged(object sender, EventArgs e)
  435. {
  436. //LoadDistrict(ref companyDistrict, companyState.Text, "");
  437. //companyState.Focus();
  438. }
  439. protected void LoadRegionSettings(string countryId)
  440. {
  441. if (countryId == "Nepal")
  442. {
  443. lblRegionType.Text = "Zone";
  444. //pnlDistrict.Visible = true;
  445. //pnlZip.Visible = false;
  446. agentLocation.Enabled = true;
  447. spnAgentLocation.Visible = true;
  448. // rfvAgentLocation.Enabled = true;
  449. }
  450. else
  451. {
  452. lblRegionType.Text = "State";
  453. //pnlDistrict.Visible = false;
  454. //pnlZip.Visible = true;
  455. agentLocation.Text = "";
  456. agentLocation.Enabled = false;
  457. spnAgentLocation.Visible = false;
  458. // rfvAgentLocation.Enabled = false;
  459. }
  460. }
  461. protected void LoadCompanyRegionSettings(string countryId)
  462. {
  463. //if (countryId == "Nepal")
  464. //{
  465. // lblCompanyRegionType.Text = "Zone";
  466. // pnlCompanyDistrict.Visible = true;
  467. // pnlCompanyZip.Visible = false;
  468. //}
  469. //else
  470. //{
  471. // lblCompanyRegionType.Text = "State";
  472. // pnlCompanyDistrict.Visible = false;
  473. // pnlCompanyZip.Visible = true;
  474. //}
  475. }
  476. #endregion
  477. protected void payOption_SelectedIndexChanged(object sender, EventArgs e)
  478. {
  479. //ManagePayOption(payOption.Text);
  480. //payOption.Focus();
  481. }
  482. private void ManagePayOption(string pOption)
  483. {
  484. //switch (pOption)
  485. //{
  486. // case "10":
  487. // mapCodeIntAC.Enabled = false;
  488. // mapCodeDomAC.Enabled = false;
  489. // allowAccountDeposit.Text = "N";
  490. // allowAccountDeposit.Enabled = false;
  491. // break;
  492. // case "20":
  493. // //mapCodeIntAC.Enabled = false;
  494. // allowAccountDeposit.Enabled = true;
  495. // break;
  496. // case "30":
  497. // mapCodeIntAC.Enabled = true;
  498. // allowAccountDeposit.Enabled = true;
  499. // break;
  500. // case "40":
  501. // mapCodeIntAC.Enabled = true;
  502. // allowAccountDeposit.Enabled = true;
  503. // break;
  504. // default:
  505. // mapCodeIntAC.Enabled = true;
  506. // allowAccountDeposit.Enabled = true;
  507. // break;
  508. //}
  509. }
  510. protected void allowAccountDeposit_SelectedIndexChanged(object sender, EventArgs e)
  511. {
  512. //mapCodeDomAC.Enabled = allowAccountDeposit.Text == "Y";
  513. //allowAccountDeposit.Focus();
  514. }
  515. }
  516. }