Guest User

Untitled

a guest
Feb 17th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.05 KB | None | 0 0
  1. public class Register_person: INotifyPropertyChanged
  2.  
  3. public event PropertyChangedEventHandler PropertyChanged;
  4. public string _username;
  5. public string _email;
  6. [AutoIncrement,PrimaryKey]
  7. public int Id { get; set; }
  8.  
  9. public string UserName { get
  10. {
  11. return _username;
  12. } set {
  13.  
  14. _username = value;
  15. NotifyPropertyChanged();
  16.  
  17. } }
  18. public string Password { get; set; }
  19. public string ConfirmPassword { get; set; }
  20. public string Email { get {
  21. return _email;
  22. } set {
  23. _email = value;
  24. NotifyPropertyChanged();
  25.  
  26. } }
  27.  
  28. public Register_person()
  29. {
  30.  
  31. }
  32.  
  33. public class Database
  34.  
  35. public Database()
  36. {
  37. Conn= DependencyService.Get<ISQLite>().GetConnection();
  38. Conn.CreateTable<Register_person>();
  39.  
  40. }
  41. public void AddUsers(Register_person users)
  42. {
  43. Conn.Insert(users);
  44. }
  45. public IEnumerable<Register_person> Getdata()
  46. {
  47. return (from t in Conn.Table<Register_person>() select t).ToList();
  48. }
  49. public Register_person GetEmail(string mail)
  50. {
  51. return Conn.Table<Register_person>().FirstOrDefault(t => t.Email == mail);
  52. }
  53. public Register_person GetUsername(string mail1)
  54. {
  55. return Conn.Table<Register_person>().FirstOrDefault(t => t.UserName == mail1);
  56. }
  57.  
  58. private void Login_Clicked(object sender, EventArgs e)
  59. {
  60. try
  61. {
  62. db2 = new Database();
  63. var data = db2.Getdata();
  64. var data1 = data.Where(x => x.UserName == Username.Text && x.Password == Password.Text).FirstOrDefault();
  65.  
  66. if (data1.UserName == Username.Text && data1.Password == Password.Text)
  67. {
  68. Navigation.PushAsync(new Homepage());
  69. }
  70.  
  71.  
  72.  
  73. }
  74. catch (Exception ex)
  75. {
  76.  
  77. if (string.IsNullOrWhiteSpace(Username.Text) || string.IsNullOrWhiteSpace(Password.Text))
  78. {
  79. userlabel.IsVisible = false;
  80. passwordlabel.IsVisible = false;
  81. userlabel1.IsVisible = true;
  82. passwordlabel1.IsVisible = true;
  83.  
  84. }
  85. else
  86. {
  87. userlabel1.IsVisible = false;
  88. passwordlabel1.IsVisible = false;
  89. userlabel.IsVisible = true;
  90. passwordlabel.IsVisible = true;
  91. Password.Text = "";
  92. Forgetpasswordlabel.IsVisible = true;
  93. }
  94. }
  95. }
  96.  
  97. private async void Registerbutton_Clicked(object sender, EventArgs e)
  98. {
  99. users = new Register_person();
  100. db1 = new Database();
  101. useUsername = Username.Text;
  102. useEmail = REmailEntry.Text;
  103. var data1 = db1.GetUsername(useUsername);
  104. var data = db1.GetEmail(useEmail);
  105. var passwor = RpasswordEntry.Text;
  106. var passwordRegex = @"^(?=.*[A-Za-z])(?=.*d)(?=.*[$@$!%*#?&])[A-Za-zd$@$!%*#?&]{8,}$";
  107. var email = REmailEntry.Text;
  108. var emailPattern = @"^([a-zA-Z0-9_-.]+)@([a-zA-Z0-9_-.]+).([a-zA-Z]{2,5})$";
  109.  
  110.  
  111. if (data == null)
  112. {
  113. REmail3.IsVisible = false;
  114. if (data1 == null)
  115. {
  116. Rusername.IsVisible = false;
  117.  
  118. if (string.IsNullOrWhiteSpace(Username.Text) && string.IsNullOrWhiteSpace(RpasswordEntry.Text) && string.IsNullOrWhiteSpace(RcpasswordEntry.Text) && string.IsNullOrWhiteSpace(REmailEntry.Text))
  119. {
  120. await DisplayAlert("Message", "Please Fill all the fields", "ok", "cancel");
  121. }
  122. else if (string.IsNullOrWhiteSpace(Username.Text))
  123. {
  124. Rusername2.IsVisible = true;
  125. }
  126. else if (string.IsNullOrWhiteSpace(RpasswordEntry.Text))
  127. {
  128. Rpassword2.IsVisible = true;
  129. RcpasswordEntry.Text = "";
  130. }
  131. else if (string.IsNullOrWhiteSpace(RcpasswordEntry.Text))
  132. {
  133. RCpassword2.IsVisible = true;
  134. }
  135. else if (string.IsNullOrWhiteSpace(REmailEntry.Text))
  136. {
  137. REmail2.IsVisible = true;
  138. }
  139.  
  140.  
  141. else
  142. {
  143. if (Regex.IsMatch(email, emailPattern))
  144. {
  145. if (Regex.IsMatch(passwor, passwordRegex))
  146. {
  147. if (RpasswordEntry.Text != RcpasswordEntry.Text)
  148. {
  149. RCpassword.IsVisible = true;
  150. RcpasswordEntry.Text = "";
  151. }
  152. else
  153. {
  154. users.UserName = Username.Text;
  155. users.Password = RpasswordEntry.Text;
  156. users.ConfirmPassword = RcpasswordEntry.Text;
  157. users.Email = REmailEntry.Text;
  158.  
  159.  
  160.  
  161. db1.AddUsers(users);
  162.  
  163. await Navigation.PushAsync(new MainPage());
  164. }
  165. }
  166. else
  167. {
  168. Rpassword.IsVisible = true;
  169. }
  170. }
  171.  
  172. else
  173. {
  174. REmail.IsVisible = true;
  175. }
  176. }
  177. }
  178. else
  179. {
  180. Rusername.IsVisible = true;
  181. }
  182. }
  183. else
  184. {
  185. REmail3.IsVisible = true;
  186. }
  187. }
Add Comment
Please, Sign In to add comment