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.

264 lines
9.8 KiB

  1. using Swift.DAL.BL.Remit.Administration.Agent;
  2. using Swift.DAL.BL.System.UserManagement;
  3. using Swift.DAL.SwiftDAL;
  4. using Swift.web.Library;
  5. using System;
  6. using System.Data;
  7. using System.Web.UI.WebControls;
  8. namespace Swift.web.Remit.AgentOperation.UserManagement
  9. {
  10. public partial class Manage : System.Web.UI.Page
  11. {
  12. private const string ViewFunctionId = "40112500";
  13. private const string AddEditFunctionId = "40112510";
  14. private const string DeleteFunctionId = "40112530";
  15. private readonly ApplicationUserDao _obj = new ApplicationUserDao();
  16. private readonly StaticDataDdl _sdd = new StaticDataDdl();
  17. protected void Page_Load(object sender, EventArgs e)
  18. {
  19. Authenticate();
  20. if (!IsPostBack)
  21. {
  22. LoadBreadCrumb();
  23. if (GetId() > 0)
  24. {
  25. PopulateDataById();
  26. }
  27. else
  28. {
  29. btnDelete.Visible = false;
  30. PopulateDdl(null);
  31. PullDefaultValueById();
  32. }
  33. }
  34. }
  35. private void LoadBreadCrumb()
  36. {
  37. spnCname.InnerHtml = _sdd.GetAgentBreadCrumb(GetAgent());
  38. }
  39. private void PullDefaultValueById()
  40. {
  41. DataRow dr = _obj.PullDefaultValueById(GetStatic.GetUser(), GetAgent().ToString());
  42. if (dr == null)
  43. return;
  44. city.Text = dr["city"].ToString();
  45. country.SelectedValue = dr["countryId"].ToString();
  46. state.SelectedValue = dr["state"].ToString();
  47. zip.Text = dr["zip"].ToString();
  48. }
  49. protected void country_SelectedIndexChanged(object sender, EventArgs e)
  50. {
  51. LoadState(ref state, country.Text, "");
  52. LoadRegionSettings(country.Text);
  53. country.Focus();
  54. }
  55. protected void state_SelectedIndexChanged(object sender, EventArgs e)
  56. {
  57. LoadDistrict(ref district, state.Text, "");
  58. state.Focus();
  59. }
  60. #region Method
  61. protected long GetMode()
  62. {
  63. return GetStatic.ReadNumericDataFromQueryString("mode");
  64. }
  65. private long GetId()
  66. {
  67. return GetStatic.ReadNumericDataFromQueryString("userId");
  68. }
  69. protected string GetAgent()
  70. {
  71. return GetStatic.ReadQueryString("agentId", "");
  72. }
  73. private void Authenticate()
  74. {
  75. _sdd.CheckAuthentication(ViewFunctionId + "," + AddEditFunctionId + "," + DeleteFunctionId);
  76. btnDelete.Visible = _sdd.HasRight(DeleteFunctionId);
  77. btnSumit.Visible = _sdd.HasRight(AddEditFunctionId);
  78. }
  79. private void PopulateDdl(DataRow dr)
  80. {
  81. _sdd.SetStaticDdl(ref salutation, "1700", GetStatic.GetRowData(dr, "salutation"), "Select");
  82. _sdd.SetDDL(ref country, "EXEC proc_countryMaster @flag = 'l'", "countryId", "countryName",
  83. GetStatic.GetRowData(dr, "countryId"), "Select");
  84. LoadState(ref state, country.Text, GetStatic.GetRowData(dr, "state"));
  85. LoadDistrict(ref district, state.Text, GetStatic.GetRowData(dr, "district"));
  86. LoadRegionSettings(country.Text);
  87. _sdd.SetStaticDdl(ref gender, "1800", GetStatic.GetRowData(dr, "gender"), "Select");
  88. //_sdd.SetDDL(ref branch,
  89. // "EXEC proc_agentMaster @flag = 'al4', @user = " + _sdd.FilterString(GetStatic.GetUser()),
  90. // "agentId", "agentName", GetStatic.GetRowData(dr, "agentId"), "Select");
  91. if (GetAgent() != "")
  92. {
  93. var agentDao = new AgentDao();
  94. branchName.Text = agentDao.SelectAgentById(GetAgent());
  95. hdnBranchName.Value = agentDao.SelectAgentById(GetAgent());
  96. }
  97. }
  98. private void PopulateDataById()
  99. {
  100. DataRow dr = _obj.SelectById(GetStatic.GetUser(), GetId().ToString());
  101. if (dr == null)
  102. return;
  103. salutation.Text = dr["salutation"].ToString();
  104. userName.Text = dr["userName"].ToString();
  105. firstName.Text = dr["firstName"].ToString();
  106. middleName.Text = dr["middleName"].ToString();
  107. lastName.Text = dr["lastName"].ToString();
  108. gender.Text = dr["gender"].ToString();
  109. var res = dr["agentName"].ToString().Split('|');
  110. hdnBranchName.Value = res[0] + "|" + res[1];
  111. branchName.Text = res[0] + "|" + res[1];
  112. hdnAgentType.Value = res[2];
  113. address.Text = dr["address"].ToString();
  114. city.Text = dr["city"].ToString();
  115. country.SelectedValue = dr["countryId"].ToString();
  116. telephoneNo.Text = dr["telephoneNo"].ToString();
  117. mobileNo.Text = dr["mobileNo"].ToString();
  118. email.Text = dr["email"].ToString();
  119. userName.Text = dr["userName"].ToString();
  120. pwd.Text = dr["pwd"].ToString();
  121. confirmPassword.Text = dr["pwd"].ToString();
  122. userName.Enabled = false;
  123. pwd.Attributes.Add("value", "xxxxxxxxxxxxxxxx");
  124. pwd.Enabled = false;
  125. confirmPassword.Attributes.Add("value", "xxxxxxxxxxxxxxxx");
  126. confirmPassword.Enabled = false;
  127. PopulateDdl(dr);
  128. }
  129. //private void Update()
  130. //{
  131. // var res = hdnBranchName.Value.Split('|');
  132. // hdnBranchId.Value = res[1];
  133. // DbResult dbResult = _obj.Update(GetStatic.GetUser()
  134. // , GetId().ToString()
  135. // , userName.Text
  136. // , salutation.Text
  137. // , firstName.Text
  138. // , middleName.Text
  139. // , lastName.Text
  140. // , gender.SelectedValue
  141. // , state.Text
  142. // , district.Text
  143. // , zip.Text
  144. // , address.Text
  145. // , city.Text
  146. // , country.SelectedValue
  147. // , telephoneNo.Text
  148. // , mobileNo.Text
  149. // , email.Text
  150. // , pwd.Text
  151. // , hdnBranchId.Value
  152. // , "15"
  153. // , "12"
  154. // , "300"
  155. // , "00:00:00"
  156. // , "23:59:59"
  157. // , "S"
  158. // , "60"
  159. // , "00:00:00"
  160. // , "23:59:59"
  161. // , "07:00:00"
  162. // , "17:00:00"
  163. // , "00:00:00"
  164. // , "23:59:59"
  165. // , ""
  166. // , ""
  167. // , ""
  168. // , ""
  169. // , ""
  170. // );
  171. // ManageMessage(dbResult);
  172. //}
  173. private void DeleteRow()
  174. {
  175. DbResult dbResult = _obj.Delete(GetStatic.GetUser(), GetId().ToString());
  176. ManageMessage(dbResult);
  177. }
  178. private void ManageMessage(DbResult dbResult)
  179. {
  180. GetStatic.SetMessage(dbResult);
  181. if (dbResult.ErrorCode == "0")
  182. {
  183. Response.Redirect("List.aspx?agentId=" + GetAgent() + "&mode=" + GetMode());
  184. }
  185. else
  186. {
  187. GetStatic.PrintMessage(Page);
  188. }
  189. }
  190. private void LoadState(ref DropDownList ddl, string countryId, string defaultValue)
  191. {
  192. string sql = "EXEC proc_countryStateMaster @flag = 'csl', @countryId = " + _sdd.FilterString(countryId);
  193. _sdd.SetDDL(ref ddl, sql, "stateId", "stateName", defaultValue, "Select");
  194. }
  195. private void LoadDistrict(ref DropDownList ddl, string zone, string defaultValue)
  196. {
  197. string sql = "EXEC proc_zoneDistrictMap @flag = 'l', @zone = " + _sdd.FilterString(zone);
  198. _sdd.SetDDL(ref ddl, sql, "districtId", "districtName", defaultValue, "Select");
  199. }
  200. protected void LoadRegionSettings(string countryId)
  201. {
  202. if (countryId == "151")
  203. {
  204. lblRegionType.Text = "Zone";
  205. pnlDistrict.Visible = true;
  206. pnlZip.Visible = false;
  207. }
  208. else
  209. {
  210. lblRegionType.Text = "State";
  211. pnlDistrict.Visible = false;
  212. pnlZip.Visible = true;
  213. }
  214. }
  215. #endregion Method
  216. #region Element Method
  217. protected void btnSumit_Click(object sender, EventArgs e)
  218. {
  219. //Update();
  220. }
  221. protected void btnDelete_Click(object sender, EventArgs e)
  222. {
  223. DeleteRow();
  224. }
  225. protected void btnBack_Click(object sender, EventArgs e)
  226. {
  227. Response.Redirect("List.aspx?agentId=" + GetAgent() + "&mode=" + GetMode());
  228. }
  229. #endregion Element Method
  230. }
  231. }