private async void Button_Click(object sender, RoutedEventArgs e) { MainWindow mainWindow = (MainWindow)Application.Current.MainWindow; if (!string.IsNullOrEmpty(Usertxt.Text) && !string.IsNullOrEmpty(passwordtxt.Password) && !string.IsNullOrEmpty(showUserCmb.Text)) { var controller = await mainWindow.ShowProgressAsync("Please wait...", "Process is Going on..!"); controller.SetIndeterminate(); await TaskEx.Delay(1000); Log.Info("Before: to add user check existence of user in CreateUser"); LoginUser _u = (LoginUser)Application.Current.Properties["User"]; if (!Queries.IsExists <LoginUser>(x => x.FirstName == Usertxt.Text.ToLower())) { Log.Info("Before: to add New user"); LoginUser _user = new LoginUser(); _user.FirstName = Usertxt.Text; _user.Password = passwordtxt.Password; _user.Role = showUserCmb.Text; _user.Trial = _u.Trial; Queries.Add <LoginUser>(_user); Log.Info("After: to add New user,Successfully in CreateUser"); await TaskEx.Delay(2000); await controller.CloseAsync(); await mainWindow.ShowMessageAsync("User Added Successfully", ""); Helpful.CloseAllFlyouts(mainWindow.Flyouts); } else { await TaskEx.Delay(2000); await controller.CloseAsync(); await mainWindow.ShowMessageAsync("Please Select another Username:"******""); Usertxt.Text = string.Empty; Usertxt.Focus(); } Log.Info("After: to add user check existence of user,Successfully in CreateUser"); } else { await mainWindow.ShowMessageAsync("Please Fill all the fields", ""); } }
/*this func send massege if user name empy*/ private void Login_Click(object sender, EventArgs e) { SqlConnection c = new SqlConnection(scn); if (string.IsNullOrEmpty(Usertxt.Text)) //if string empty { MessageBox.Show("Please enter your user name", "Message", MessageBoxButtons.OK, MessageBoxIcon.Warning); //shoe warning Usertxt.Focus(); //focus on username box return; //end }//end click if (string.IsNullOrEmpty(txtPassword.Text)) //if string empty { MessageBox.Show("Please enter your user password", "Message", MessageBoxButtons.OK, MessageBoxIcon.Warning); //shoe warning Usertxt.Focus(); //focus on username box return; //end } String q = "select Users.userid,Users.permission,Users.first_name,Users.last_name,Users.Email from Users where username like '" + Usertxt.Text.ToString() + "' and Users.password like '" + txtPassword.Text + "'"; SqlDataAdapter da = new SqlDataAdapter(q, c); DataTable dt = new DataTable(); if (c.State != ConnectionState.Open) { c.Open(); } da.Fill(dt); if (dt.Rows.Count == 0) { MessageBox.Show("incorect username and password", "Message", MessageBoxButtons.OK, MessageBoxIcon.Warning);//shoe warning } else if (dt.Rows.Count >= 2) { MessageBox.Show("more then one account", "Message", MessageBoxButtons.OK, MessageBoxIcon.Warning);//shoe warning } else { if (dt.Rows[0].Field <int>("permission") == 5) { c.Close(); //c is bussy so close c.Open(); //open to new connection. da = new SqlDataAdapter("select Year from Student where username like '" + Usertxt.Text.ToString() + "'", c); //get year DataTable dr = new DataTable(); // da.Fill(dr); OStudent s = new OStudent(dt.Rows[0].Field <int>("userid").ToString(), dt.Rows[0].Field <String>("first_name").ToString(), dt.Rows[0].Field <String>("last_name").ToString(), dt.Rows[0].Field <String>("Email").ToString(), dr.Rows[0].Field <String>("Year")[0]); c.Close(); MainStudent f = new MainStudent(s, scn); this.Hide(); f.ShowDialog(this); } if (dt.Rows[0].Field <int>("permission") == 1) { c.Close();//c is bussy so close MenuStudentCoordinator f = new MenuStudentCoordinator(scn); this.Hide(); f.ShowDialog(this); } if (dt.Rows[0].Field <int>("permission") == 3) { c.Close();//c is bussy so close OLecture l = new OLecture(dt.Rows[0].Field <int>("userid").ToString(), dt.Rows[0].Field <String>("first_name").ToString(), dt.Rows[0].Field <String>("last_name").ToString(), dt.Rows[0].Field <String>("Email").ToString()); c.Close(); MenuLecturer f = new MenuLecturer(l, c); this.Hide(); f.ShowDialog(this); } if (dt.Rows[0].Field <int>("permission") == 2) { c.Close();//c is bussy so close OTutor t = new OTutor(dt.Rows[0].Field <int>("userid").ToString(), dt.Rows[0].Field <String>("first_name").ToString(), dt.Rows[0].Field <String>("last_name").ToString(), dt.Rows[0].Field <String>("Email").ToString()); c.Close(); MenuTutor f = new MenuTutor(c, t); this.Hide(); f.ShowDialog(this); } } }
private async void Button_Click(object sender, RoutedEventArgs e) { Log.Info("Before: To change password in ManageUser"); MainWindow mainWindow = (MainWindow)Application.Current.MainWindow; var controller = await mainWindow.ShowProgressAsync("Please wait...", "Process is Going on..!"); controller.SetIndeterminate(); if (Userlistcmb.SelectedItem != null && !string.IsNullOrEmpty(oldpwdtxt.Password) && !string.IsNullOrEmpty(Newpwdtxt.Password) && !string.IsNullOrEmpty(confirmpwdtxt.Password) && !string.IsNullOrEmpty(Usertxt.Text)) { Log.Info("Before: To check username with password is exist in ManageUser"); LoginUser _loguser = Queries.GetDataByCondition <LoginUser>(x => x.FirstName == Userlistcmb.Text && x.Password == oldpwdtxt.Password); Log.Info("After: To check username with password is exist, Successfully in ManageUser"); if (_loguser != null) { if (Newpwdtxt.Password == confirmpwdtxt.Password) { if (!Queries.IsExists <LoginUser>(x => x.FirstName == Usertxt.Text.ToLower())) { Log.Info("Before: To change user password in ManageUser"); _loguser.Password = Newpwdtxt.Password; _loguser.FirstName = Usertxt.Text; Queries.Update <LoginUser>(_loguser); Application.Current.Properties["User"] = _loguser; await TaskEx.Delay(2000); await controller.CloseAsync(); await mainWindow.ShowMessageAsync("Record Updated Successfully", ""); Newpwdtxt.Password = oldpwdtxt.Password = confirmpwdtxt.Password = string.Empty; Helpful.CloseAllFlyouts(mainWindow.Flyouts); Log.Info("After: To change user password,Successfully in ManageUser"); } else { await TaskEx.Delay(2000); await controller.CloseAsync(); await mainWindow.ShowMessageAsync("Please Select another Username:"******""); Usertxt.Text = string.Empty; Usertxt.Focus(); } } else { await TaskEx.Delay(2000); await controller.CloseAsync(); await mainWindow.ShowMessageAsync("New Password should be match with Confirm Password", ""); Newpwdtxt.Password = confirmpwdtxt.Password = string.Empty; Newpwdtxt.Focus(); } } else { // please enter valid password await TaskEx.Delay(2000); await controller.CloseAsync(); await mainWindow.ShowMessageAsync("Please enter valid password", ""); oldpwdtxt.Focus(); oldpwdtxt.Password = string.Empty; } } else { await TaskEx.Delay(2000); await controller.CloseAsync(); await mainWindow.ShowMessageAsync("Please Fill all the fields", ""); // please fill all the field. } Log.Info("After: To change password in ManageUser"); }