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.

187 lines
6.0 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using Swift.DAL.BL.Remit.Administration;
  5. using Swift.DAL.SwiftDAL;
  6. using Swift.web.Component.Grid;
  7. using Swift.web.Component.Grid.gridHelper;
  8. using Swift.web.Library;
  9. namespace Swift.web.Remit.ExchangeRate.RateMask
  10. {
  11. public partial class RoundingSetup : System.Web.UI.Page
  12. {
  13. private const string ViewFunctionId = "30012000";
  14. private const string AddEditFunctionId = "30012010";
  15. protected const string GridName = "g_cr";
  16. private readonly SwiftGrid grid = new SwiftGrid();
  17. private readonly CurrencyDao obj = new CurrencyDao();
  18. private readonly StaticDataDdl sdd = new StaticDataDdl();
  19. private readonly SwiftLibrary swiftLibrary = new SwiftLibrary();
  20. protected void Page_Load(object sender, EventArgs e)
  21. {
  22. Authenticate();
  23. if (!IsPostBack)
  24. {
  25. Misc.MakeNumericTextbox(ref cDecimal);
  26. if (Convert.ToInt32((GetId() == "" ? "0" : GetId())) > 0)
  27. {
  28. PopulateDataById();
  29. }
  30. else
  31. {
  32. PopulateDdl(null);
  33. }
  34. }
  35. DeleteRow();
  36. LoadGrid();
  37. }
  38. #region Method
  39. protected string GetCurrencyCode()
  40. {
  41. return GetCurrCode();
  42. }
  43. protected string GetCurrCode()
  44. {
  45. return GetStatic.ReadQueryString("currencyCode", "");
  46. }
  47. protected long GetCurrencyId()
  48. {
  49. return GetStatic.ReadNumericDataFromQueryString("currencyId");
  50. }
  51. protected string GetId()
  52. {
  53. return grid.GetRowId();
  54. }
  55. private void Authenticate()
  56. {
  57. swiftLibrary.CheckAuthentication(ViewFunctionId + "," + AddEditFunctionId);
  58. }
  59. private void PopulateDdl(DataRow dr)
  60. {
  61. sdd.SetDDL(ref tranType, "exec proc_serviceTypeMaster @flag='l2'", "serviceTypeId", "typeTitle", GetStatic.GetRowData(dr, "tranType"), "All");
  62. sdd.SetDDL2(ref place, "SELECT valueId,detailTitle FROM staticDataValue WHERE typeID=7100 AND isActive = 'Y'", "detailTitle", GetStatic.GetRowData(dr, "place"), "0");
  63. }
  64. private void PopulateDataById()
  65. {
  66. DataRow dr = obj.SelectCurrRoundById(GetStatic.GetUser(), countryCurrencyId.Value);
  67. if (dr == null)
  68. return;
  69. cDecimal.Text = dr["currDecimal"].ToString();
  70. cDecimal.ReadOnly = (place.Text != "" ? true : false);
  71. PopulateDdl(dr);
  72. }
  73. private void Update()
  74. {
  75. DbResult dbResult = obj.UpdateCurrRound(GetStatic.GetUser(), GetId(), GetCurrCode(),
  76. place.Text, cDecimal.Text, tranType.Text);
  77. ManageMessage(dbResult);
  78. }
  79. private void ManageMessage(DbResult dbResult)
  80. {
  81. GetStatic.SetMessage(dbResult);
  82. if (dbResult.ErrorCode != "0")
  83. {
  84. GetStatic.AlertMessage(Page);
  85. return;
  86. }
  87. else
  88. {
  89. LoadGrid();
  90. }
  91. }
  92. private void LoadGrid()
  93. {
  94. grid.ColumnList = new List<GridColumn>
  95. {
  96. new GridColumn("currency", "Currency Code", "", "T"),
  97. new GridColumn("typeTitle", "Tran Type", "", "T"),
  98. new GridColumn("place", "Placing", "", "T"),
  99. new GridColumn("currDecimal", "Decimal", "", "T")
  100. };
  101. bool allowAddEdit = swiftLibrary.HasRight(AddEditFunctionId);
  102. grid.GridDataSource = SwiftGrid.GridDS.RemittanceDB;
  103. grid.GridType = 1;
  104. grid.GridName = GridName;
  105. grid.ShowAddButton = allowAddEdit;
  106. grid.ShowFilterForm = false;
  107. grid.ShowPagingBar = false;
  108. grid.GridWidth = 450;
  109. grid.RowIdField = "rowID";
  110. grid.CallBackFunction = "GridCallBack()";
  111. grid.DisableSorting = false;
  112. grid.ThisPage = "PayoutRounding.aspx";
  113. grid.MultiSelect = false;
  114. grid.ShowCheckBox = true;
  115. grid.SelectionCheckBoxList = grid.GetRowId();
  116. grid.AllowEdit = false;
  117. grid.AllowDelete = allowAddEdit;
  118. string sql = "EXEC proc_currencyPayoutRound @flag = 's', @currency = " + grid.FilterString(GetCurrCode());
  119. grid.SetComma();
  120. rpt_grid.InnerHtml = grid.CreateGrid(sql);
  121. }
  122. private void DeleteRow()
  123. {
  124. string id = grid.GetCurrentRowId(GridName);
  125. if (string.IsNullOrEmpty(id))
  126. return;
  127. DbResult dbResult = obj.DeleteCurrRound(GetStatic.GetUser(), id);
  128. ManageMessage(dbResult);
  129. }
  130. private void Edit()
  131. {
  132. string id = grid.GetRowId();
  133. countryCurrencyId.Value = id;
  134. PopulateDataById();
  135. }
  136. #endregion
  137. #region Element Method
  138. protected void btnSumit_Click(object sender, EventArgs e)
  139. {
  140. Update();
  141. }
  142. protected void btnSave_Click(object sender, EventArgs e)
  143. {
  144. DbResult dbResult = obj.UpdateCurrRound(GetStatic.GetUser(), GetId(), GetCurrCode(),
  145. place.Text, cDecimal.Text, tranType.Text);
  146. ManageMessage(dbResult);
  147. LoadGrid();
  148. }
  149. protected void btnEdit_Click(object sender, EventArgs e)
  150. {
  151. Edit();
  152. }
  153. #endregion
  154. protected void place_SelectedIndexChanged(object sender, EventArgs e)
  155. {
  156. cDecimal.ReadOnly = (place.Text != "");
  157. cDecimal.Text = (place.Text != "" ? "0" : cDecimal.Text);
  158. place.Focus();
  159. }
  160. }
  161. }