Guest User

Untitled

a guest
Nov 3rd, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.90 KB | None | 0 0
  1. #region LoginMethod
  2. bool login = false;
  3. public async Task GetAccounts()
  4. {
  5. MainWin w = new MainWin();
  6.  
  7. await Task.Run(() =>
  8.  
  9. {
  10. btn_join.Content = "در حال برسی اکانت شما";
  11. this.Dispatcher.Invoke(() =>
  12. {
  13. using (SqlConnection connection = new SqlConnection(PublicVar.ConnectionString))
  14. {
  15. gymEntities2 database = new gymEntities2();
  16. SqlConnection con1 = new SqlConnection(PublicVar.ConnectionString);
  17. PublicVar.TodayTime = String.Format("{0:yyyy/MM/dd}", Convert.ToDateTime(TimeNow.Text));
  18. con1.Open();
  19.  
  20.  
  21. SqlCommand Actives = new SqlCommand("Select DISTINCT (LockEndDate) from LockTable Where Username = '" + txt_username.Text + "' and Password = '" + txt_password.Password + "'", con1);
  22. object Active = Actives.ExecuteScalar();
  23. string SystemActive = Convert.ToString(Active);
  24.  
  25.  
  26. // SqlCommand Commandcmds = new SqlCommand("update VW_TimeOut set UserActive = 2 where UserEndDate < '" + String.Format("{0:yyyy/MM/dd}", Convert.ToDateTime(TimeNow.Text)) + "'", con1);
  27. // Commandcmds.ExecuteScalar();
  28.  
  29.  
  30. SqlCommand Commandcmd = new SqlCommand("SELECT COUNT(*) FROM LockTable Where Username = '" + txt_username.Text + "' and Password = '" + txt_password.Password + "' and LockEndDate between '" + String.Format("{0:yyyy/MM/dd}", Convert.ToDateTime(Lock.Text)) + "' And '" + SystemActive + "'", con1);
  31. int userCount = (int)Commandcmd.ExecuteScalar();
  32.  
  33.  
  34. //Find Gym ID -> To Set Public Value Strings
  35. SqlCommand FindGymID = new SqlCommand("Select DISTINCT (LockID) from LockTable Where Username = '" + txt_username.Text + "' and Password = '" + txt_password.Password + "'", con1);
  36. object ObGymID = FindGymID.ExecuteScalar();
  37.  
  38.  
  39.  
  40. if (userCount > 0)
  41. {
  42. try
  43. {
  44. RegistryKey UsernameKey = Registry.CurrentUser.CreateSubKey("SOFTWARE\GYM");
  45.  
  46.  
  47.  
  48.  
  49.  
  50. if (CheakRem.IsChecked == true)
  51. if ((string)UsernameKey.GetValue("UserNameRegister") != "")
  52. {
  53. UsernameKey.SetValue("UserNameRegister", txt_username.Text.Trim());
  54. UsernameKey.SetValue("PasswordRegister", Module.Decode.EncryptTextUsingUTF8(txt_password.Password.Trim()));
  55. }
  56.  
  57. PublicVar.GymID = Convert.ToString(ObGymID);
  58. login = true;
  59.  
  60. }
  61.  
  62. catch
  63. {
  64. MessageBox.Show("مشکلی در ورود کاربر به وجود آمد");
  65. w.Username = null;
  66. w.Password = null;
  67. }
  68.  
  69.  
  70. }
  71. else
  72. {
  73. ErrorPage pageerror = new ErrorPage();
  74. pageerror.Show();
  75. pageerror.Error_Lable.Content = "زمان اکانت شما به پایان رسیده است";
  76. con1.Close();
  77. w.Username = null;
  78. w.Password = null;
  79. }
  80. con1.Close();
  81.  
  82.  
  83. }
  84.  
  85. });
  86.  
  87.  
  88. });
  89.  
  90.  
  91. if (login == true)
  92. {
  93. w.Username = txt_username.Text;
  94. w.Password = txt_password.Password;
  95. w.Show();
  96. this.Close();
  97. }
  98. }
  99. #endregion
  100.  
  101. private async void btn_join_Click(object sender, RoutedEventArgs e)
  102. {
  103.  
  104. await GetAccounts();
  105.  
  106.  
  107. }
Add Comment
Please, Sign In to add comment