Пример #1
0
        public async Task GetAccounts()
        {
            int total1 = 0;

            using (SqlConnection connection = new SqlConnection(PublicVar.ConnectionString))
            {
                gymEntities2  database = new gymEntities2();
                SqlConnection con1     = new SqlConnection(PublicVar.ConnectionString);
                PublicVar.TodayTime = String.Format("{0:yyyy/MM/dd}", Convert.ToDateTime(TimeNow.Text));
                con1.Open();


                SqlCommand Actives      = new SqlCommand("Select DISTINCT (LockEndDate) from LockTable Where Username = '******' and Password = '******'", con1);
                object     Active       = Actives.ExecuteScalar();
                string     SystemActive = Convert.ToString(Active);
                MainWin    w            = new MainWin();

                //   SqlCommand Commandcmds = new SqlCommand("update VW_TimeOut set UserActive = 2 where UserEndDate < '" + String.Format("{0:yyyy/MM/dd}", Convert.ToDateTime(TimeNow.Text)) + "'", con1);
                //   Commandcmds.ExecuteScalar();


                SqlCommand Commandcmd = new SqlCommand("SELECT COUNT(*) FROM LockTable Where Username = '******' and Password = '******' and LockEndDate between '" + String.Format("{0:yyyy/MM/dd}", Convert.ToDateTime(Lock.Text)) + "' And '" + SystemActive + "'", con1);
                int        userCount  = (int)Commandcmd.ExecuteScalar();


                if (userCount > 0)
                {
                    try
                    {
                        RegistryKey UsernameKey = Registry.CurrentUser.CreateSubKey("SOFTWARE\\GYM");



                        if (CheakRem.IsChecked == true)
                        {
                            if ((string)UsernameKey.GetValue("UserNameRegister") != "")
                            {
                                UsernameKey.SetValue("UserNameRegister", txt_username.Text.Trim());
                                UsernameKey.SetValue("PasswordRegister", Module.Decode.EncryptTextUsingUTF8(txt_password.Password.Trim()));
                            }
                        }

                        login = true;
                    }

                    catch
                    {
                        MessageBox.Show("مشکلی در ورود کاربر به وجود آمد");
                        w.Username = null;
                        w.Password = null;
                    }
                }
                else
                {
                    ErrorPage pageerror = new ErrorPage();
                    pageerror.Show();
                    pageerror.Error_Lable.Content = "زمان اکانت شما به پایان رسیده است";
                    con1.Close();
                    w.Username = null;
                    w.Password = null;
                }
                con1.Close();
            }
        }