Guest User

yannai hamelech2

a guest
Mar 12th, 2018
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.71 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using HELPER;
  8. using MODEL;
  9. using MODEL.MyService;
  10.  
  11. namespace WEB_VIEW_GUI
  12. {
  13. public partial class frmSignUp : System.Web.UI.Page
  14. {
  15. private bool editMode;
  16. private User newUser;
  17. private User oldUser;
  18. private Users users;
  19.  
  20. private string redirectTo;
  21.  
  22.  
  23. protected void Page_Load(object sender, EventArgs e)
  24. {
  25. final.Visible = false;
  26.  
  27. users = new Users();
  28. users.SelectAll();
  29.  
  30.  
  31.  
  32.  
  33. editMode = (Request.QueryString["EDITMODE"] != null && Request.QueryString["EDITMODE"] == "TRUE") ? true : false;
  34.  
  35. if (editMode)
  36. {
  37. oldUser = (User)Session["OLDUSER"];
  38. ConfirmButton.Text = "Update";
  39.  
  40. redirectTo = "~/Users/Admin/Tables/frmUsers.aspx";
  41. }
  42. else
  43. {
  44. ConfirmButton.Text = "Register";
  45. redirectTo = "~/Home.aspx";
  46.  
  47. }
  48.  
  49. if (!IsPostBack)
  50. {
  51. if (editMode)
  52. {
  53. PopulateCustomer();
  54. }
  55. // customers.countries.Insert(0, new Country() { Num = 0, Name = "Pick your country" });
  56. // HELPER.WebFormUtilities.SetComboBox<Country>(CountriesDDL, customers.countries, "Name", "Num");
  57. users.cities.Insert(0, new City() { Num = 0, Name = "Select City" });
  58. HELPER.WebFormUtilities.SetComboBox<City>(CityDDL, users.cities, "Name", "num");
  59.  
  60. users.countries.Insert(0, new Country() { Num = 0, Name = "Select Country" });
  61. HELPER.WebFormUtilities.SetComboBox<Country>(CountryDDL, users.countries, "Name", "num");
  62.  
  63. users.roles.Insert(0, new UserRole() { Num = 0, Name = "Select Role" });
  64. HELPER.WebFormUtilities.SetComboBox<UserRole>(rolesDDL, users.roles, "Name", "num");
  65.  
  66.  
  67. }
  68. }
  69. protected void PopulateCustomer()
  70. {
  71.  
  72. FirstNameTextBox.Text = oldUser.FirstName;
  73. LastNameTextBox.Text = oldUser.LastName;
  74. genderDDL.SelectedValue = oldUser.Gender;
  75. EmailTextBox.Text = oldUser.Email;
  76. date.Text = oldUser.BirthDate.ToString();
  77. // newUser.BirthDate = Convert.ToDateTime(date.Text);//
  78. AddressTextBox.Text = oldUser.Address;
  79. CityDDL.SelectedValue = oldUser.CityNo.ToString();
  80. ZipCodeTextBox.Text = oldUser.ZipCode;
  81. CountryDDL.SelectedValue = oldUser.CountryNo.ToString();
  82. AreaCodeTextBox.Text = oldUser.AreaCodeNo;
  83. PhoneNumberTextBox.Text = oldUser.Phone;
  84. //PasswordTextBox.Text = oldUser.Pass;
  85. rolesDDL.SelectedValue = oldUser.RoleNo.ToString();
  86.  
  87. }
  88.  
  89. protected void ConfirmButton_Click(object sender, EventArgs e)
  90. {
  91.  
  92. bool isOk = false ;
  93.  
  94. newUser = new User();
  95. SetProperties();
  96.  
  97. if (!editMode)
  98. {
  99. isOk = users.Add(newUser);
  100. }
  101. else
  102. {
  103. isOk = users.Modify(oldUser, newUser);
  104. }
  105. if (isOk)
  106. {
  107. if (users.Save())
  108. {
  109. if (!editMode)
  110. {
  111. System.Diagnostics.Debug.WriteLine("Success");
  112. registerForm.Visible = false;
  113. Message.Text = "Welcome to the family, " + newUser.FirstName + "!";
  114. final.Visible = true;
  115.  
  116. // Talk.Text = "Thanks for your registration " + newCustomer.FullName;
  117. // Talk.BackColor = System.Drawing.Color.Lime;
  118. // Talk.Visible = true;
  119. }
  120. else
  121. {
  122. System.Diagnostics.Debug.WriteLine("Success");
  123. registerForm.Visible = false;
  124. Message.Text = "User " + newUser.Email +" updated successfully!";
  125. final.Visible = true;
  126. }
  127.  
  128. }
  129. else
  130. {
  131. registerForm.Visible = false;
  132. Message.Text = "Uh, Oh. Something went wrong. Please try again later.";
  133. final.Visible = true;
  134. }
  135. }
  136. else
  137. {
  138. registerForm.Visible = false;
  139. Message.Text = "Uh, Oh. Something went wrong. Please try using a different email.";
  140. final.Visible = true;
  141. }
  142.  
  143. }
  144. protected void SetProperties()
  145. {
  146.  
  147.  
  148.  
  149. newUser.FirstName = FirstNameTextBox.Text;
  150. newUser.LastName = LastNameTextBox.Text;
  151. newUser.Gender = genderDDL.SelectedValue;
  152. newUser.Email = EmailTextBox.Text;
  153. newUser.BirthDate = Convert.ToDateTime(date.Text);
  154. newUser.Address = AddressTextBox.Text;
  155. newUser.CityNo = Convert.ToInt32(CityDDL.SelectedValue);
  156. newUser.ZipCode = ZipCodeTextBox.Text;
  157. newUser.CountryNo = Convert.ToInt32(CountryDDL.SelectedValue);
  158. newUser.AreaCodeNo = AreaCodeTextBox.Text;
  159. newUser.Phone = PhoneNumberTextBox.Text;
  160. newUser.Pass = PasswordTextBox.Text;
  161. newUser.RoleNo = Convert.ToInt32(rolesDDL.SelectedValue);
  162.  
  163.  
  164. System.Diagnostics.Debug.WriteLine(newUser.RoleNo);
  165. newUser.SetCity(users.cities);
  166. newUser.SetCountry(users.countries);
  167. newUser.SetUserRole(users.roles);
  168.  
  169. }
  170.  
  171. protected void CountryDDL_SelectedIndexChanged(object sender, EventArgs e)
  172. {
  173. int value = Convert.ToInt32(CountryDDL.SelectedValue);
  174. Country cSelected = new Country();
  175. Country[] arr = users.countries.ToArray();
  176. int i = 0;
  177. bool found = false;
  178. while(i < arr.Length && !found)
  179. {
  180. if (arr[i].Num == value)
  181. cSelected = arr[i];
  182. i++;
  183. }
  184.  
  185. string code = cSelected.PhoneCountryCode;
  186. AreaCodeTextBox.Text = code;
  187.  
  188.  
  189.  
  190. }
  191.  
  192. protected void continueButton_ServerClick(object sender, EventArgs e)
  193. {
  194. System.Diagnostics.Debug.WriteLine("gooooooo");
  195.  
  196. Response.Redirect(redirectTo);
  197. }
  198. }
  199. }
Add Comment
Please, Sign In to add comment