public User Update(User user) { using (var connection = new SqlConnection(_connectionString)) { connection.Open(); using (SqlCommand command = new SqlCommand("dbo.uspUpdateUser", connection)) { command.Connection = connection; command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.Add(new SqlParameter("@pUserId", user.UserID)); command.Parameters.Add(new SqlParameter("@pLoginName", user.LoginName)); command.Parameters.Add(new SqlParameter("@pPassword", user.Password)); command.Parameters.Add(new SqlParameter("@pFirstName", user.FirstName)); command.Parameters.Add(new SqlParameter("@pLastName", user.LastName)); command.Parameters.Add(new SqlParameter("@pActiveUser", LoggedInDetails.GetUserLogged())); var rowsAffected = command.ExecuteNonQuery(); if (rowsAffected == 0) { throw new Exception("Sql Connection Error"); } return(user); } } }
public Student Insert(Student student) { using (var connection = new SqlConnection(_connectionString)) { connection.Open(); using (SqlCommand command = new SqlCommand("dbo.uspAddStudent", connection)) { command.Connection = connection; command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.Add(new SqlParameter("@pFirstName", student.FirstName)); command.Parameters.Add(new SqlParameter("@pLastName", student.LastName)); command.Parameters.Add(new SqlParameter("@pEmail", student.Email)); command.Parameters.Add(new SqlParameter("@pPhone", student.Phone)); command.Parameters.Add(new SqlParameter("@pAddressLine1", student.AddressLine1)); command.Parameters.Add(new SqlParameter("@pAddressLine2", student.AddressLine2)); command.Parameters.Add(new SqlParameter("@pCity", student.City)); command.Parameters.Add(new SqlParameter("@pCounty", student.County)); command.Parameters.Add(new SqlParameter("@pCountry", student.Country)); command.Parameters.Add(new SqlParameter("@pLevel", student.Level)); command.Parameters.Add(new SqlParameter("@pCourse", student.Course)); command.Parameters.Add(new SqlParameter("@pStudentNumber", student.StudentNumber)); command.Parameters.Add(new SqlParameter("@pActiveUser", LoggedInDetails.GetUserLogged())); var rowsAffected = command.ExecuteNonQuery(); if (rowsAffected == 0) { throw new Exception("Sql Connection Error"); } return(student); } } }
private void logoutToolStripMenuItem_Click(object sender, EventArgs e) { if (!LoggedInDetails.GetLoggedInState()) { // login openForm(new FormLogin()); } else { //logout LoggedInDetails.SetLoggedInState(false); } setLoginLogoutState(LoggedInDetails.GetLoggedInState()); setTsUserName(); }
public void Delete(int id) { using (var connection = new SqlConnection(_connectionString)) { connection.Open(); using (SqlCommand command = new SqlCommand("dbo.uspDeleteUser", connection)) { command.Connection = connection; command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.Add(new SqlParameter("@pUserID", id)); command.Parameters.Add(new SqlParameter("@pLoginName", LoggedInDetails.GetUserLogged())); command.ExecuteNonQuery(); } } }
public void Delete(long studentNumber) { using (var connection = new SqlConnection(_connectionString)) { connection.Open(); using (SqlCommand command = new SqlCommand("dbo.uspDeleteStudent", connection)) { command.Connection = connection; command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.Add(new SqlParameter("@pStudentNumber", studentNumber)); command.Parameters.Add(new SqlParameter("@pActiveUser", LoggedInDetails.GetUserLogged())); command.ExecuteNonQuery(); } } }
private void btn_Login_Click(object sender, EventArgs e) { var userRepository = new UserRepository(); var response = userRepository.Login(txtBox_login.Text, txtbox_password.Text); if (response == LoginEnum.Successful) { LoggedInDetails.SetUserLogged(txtBox_login.Text); LoggedInDetails.SetLoggedInState(true); Close(); return; } if (response == LoginEnum.IncorrectLogin) { GeneralTools.WarningBox("Incorrect login."); } if (response == LoginEnum.IncorrectPassword) { GeneralTools.WarningBox("Incorrect password."); } }
private void FormLogin_Load(object sender, EventArgs e) { LoggedInDetails.SetLoggedInState(); }
private void setTsUserName() { tsUserName.Text = LoggedInDetails.GetUserLogged(); }
private void frmMain_Load(object sender, EventArgs e) { setTsFrmName(); setLoginLogoutState(LoggedInDetails.GetLoggedInState()); }