private void DeleteRecordToolStripButton_Click(object sender, EventArgs e) { int rowIndex = StudentDataGridView.Rows.GetFirstRow(DataGridViewElementStates.Selected); SqlDataReader dataReader; try { if (rowIndex != -1) { int StudentId = Convert.ToInt32(StudentDataGridView.Rows[rowIndex].Cells["StudentId"].Value); string query = "DELETE FROM dbo.Student WHERE StudentId='" + StudentId + "';"; SqlConnection Sqlcon = new SqlConnection(AppSetting.ConnectionString()); SqlCommand SqlCom = new SqlCommand(query, Sqlcon); Sqlcon.Open(); dataReader = SqlCom.ExecuteReader(); SMSMessageBox.ShowSuccessMessage("Row Deleted"); while (dataReader.Read()) { } LoadDataIntoGridView(); } else { SMSMessageBox.ShowErrorMessage("Please Select Row"); } } catch (Exception ex) { SMSMessageBox.ShowErrorMessage("Error Message"); } }
public static List <SelectListItem> GetAllRoles(int roleId) { List <SelectListItem> roles = new List <SelectListItem>(); using (SqlConnection conn = new SqlConnection(AppSetting.ConnectionString())) { using (SqlCommand cmd = new SqlCommand("usp_RolesGetRolesByRoleId", conn)) { cmd.CommandType = System.Data.CommandType.StoredProcedure; conn.Open(); cmd.Parameters.AddWithValue("@RoleId", roleId); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { SelectListItem item = new SelectListItem(); item.Value = reader["RoleName"].ToString(); item.Text = reader["RoleName"].ToString(); roles.Add(item); } } } return(roles); }
private void LoadDataAndBindIntoControls() { DbSQLServer dbSQLServer = new DbSQLServer(AppSetting.ConnectionString()); DataTable dataTabe = dbSQLServer.GetDataList("usp_EmployeesGetEmployeesDetailsById", new DbParameter { Parameter = "@EmployeeId", Value = this.EmployeeId }); DataRow dtRow = dataTabe.Rows[0]; EmployeeIDTextBox.Text = dtRow["EmployeeId"].ToString(); FullNameTextBox.Text = dtRow["FullName"].ToString(); dateTimePicker1.Value = Convert.ToDateTime(dtRow["DateOfBirth"]); NICTextBox.Text = dtRow["NICNumber"].ToString(); EmailTextBox.Text = dtRow["EmailAddress"].ToString(); TelephoneTextBox.Text = dtRow["Telephone"].ToString(); MobileETextBox.Text = dtRow["Mobile"].ToString(); dateTimePicker2.Value = Convert.ToDateTime(dtRow["EmploymentDate"]); AddressLineTextBox.Text = dtRow["AddressLine"].ToString(); PostCodeBox.Text = dtRow["PostCode"].ToString(); CurrentSalaryTextBox.Text = dtRow["CurrentSalary"].ToString(); StartingSalaryTextBox.Text = dtRow["StartingSalary"].ToString(); CommentsTextBox.Text = dtRow["Comments"].ToString(); pictureBox1.Image = (dtRow["Photo"] is DBNull) ? null : ImageManipulations.PutPhoto((byte[])dtRow["Photo"]); CityComboBox.SelectedValue = dtRow["CityId"]; DistrictComboBox.SelectedValue = dtRow["DistrictId"]; GenderComboBox.SelectedValue = dtRow["GenderId"]; BranchComboBox.SelectedValue = dtRow["BranchId"]; JobTitleComboBox.SelectedValue = dtRow["JobTitleId"]; HasLeftComboBox.Text = (Convert.ToBoolean(dtRow["HasLeft"]) == true) ? "Yes" : "No"; ReasonLeftComboBox.SelectedValue = dtRow["ReasonLeftId"]; DateLeftDateTimePicker.Value = Convert.ToDateTime(dtRow["DateLeft"]); CommentsTextBox.Text = dtRow["Comments"].ToString(); }
public static List <UserModel> GetAllUsers() { List <UserModel> users = new List <UserModel>(); using (SqlConnection conn = new SqlConnection(AppSetting.ConnectionString())) { using (SqlCommand cmd = new SqlCommand("usp_UsersGetAllUsers", conn)) { cmd.CommandType = System.Data.CommandType.StoredProcedure; conn.Open(); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { UserModel user = new UserModel(); user.UserId = Convert.ToInt32(reader["UserId"]); user.UserName = reader["UserName"].ToString(); user.FullName = reader["FullName"].ToString(); user.Email = reader["Email"].ToString(); users.Add(user); } } } return(users); }
public static UserProfile GetUserProfileData(int currentUserId) { UserProfile userProfile = new UserProfile(); using (SqlConnection conn = new SqlConnection(AppSetting.ConnectionString())) { using (SqlCommand cmd = new SqlCommand("usp_UsersGetUserProfileData", conn)) { cmd.CommandType = System.Data.CommandType.StoredProcedure; conn.Open(); cmd.Parameters.AddWithValue("@UserId", currentUserId); SqlDataReader reader = cmd.ExecuteReader(); reader.Read(); userProfile.FullName = reader["FullName"].ToString(); userProfile.Email = reader["Email"].ToString(); userProfile.Address = reader["Address"].ToString(); } } return(userProfile); }
public static void LoadDataIntoDataGridView(DataGridView dgv, string storedProceName) { DBSQLServer db = new DBSQLServer(AppSetting.ConnectionString()); dgv.DataSource = db.GetDataList(storedProceName); dgv.MultiSelect = false; dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; dgv.SelectionMode = DataGridViewSelectionMode.FullRowSelect; }
public static void LoadDataIntoComboBox(ComboBox cb, string storedProceName, DBParameter[] parameters) { DBSQLServer db = new DBSQLServer(AppSetting.ConnectionString()); cb.DataSource = db.GetDataList(storedProceName, parameters); cb.DisplayMember = "Description"; cb.ValueMember = "Id"; cb.SelectedIndex = -1; cb.DropDownStyle = ComboBoxStyle.DropDownList; }
public static void LoadDataIntoComboBox(ComboBox cb, DBParameter parameter) { DBSQLServer db = new DBSQLServer(AppSetting.ConnectionString()); cb.DataSource = db.GetDataList("usp_ListTypesDataGetDataByListTypeId", parameter); cb.DisplayMember = "Description"; cb.ValueMember = "Id"; cb.SelectedIndex = -1; cb.DropDownStyle = ComboBoxStyle.DropDownList; }
public static void LoadDataIntoComboBox(ComboBox comboBox, string storedProcedureName, DbParameter[] dbParameters) { DbSQLServer dbSQLServer = new DbSQLServer(AppSetting.ConnectionString()); comboBox.DataSource = dbSQLServer.GetDataList(storedProcedureName, dbParameters); comboBox.DisplayMember = "Description"; comboBox.ValueMember = "Id"; comboBox.SelectedIndex = -1; comboBox.DropDownStyle = ComboBoxStyle.DropDownList; }
public static void LoadDataIntoComboBox(ComboBox comboBox, DbParameter dbParameter) { DbSQLServer dbSQLServer = new DbSQLServer(AppSetting.ConnectionString()); comboBox.DataSource = dbSQLServer.GetDataList("usp_GetListTypesDataById", dbParameter); comboBox.DisplayMember = "Description"; comboBox.ValueMember = "Id"; comboBox.SelectedIndex = -1; comboBox.DropDownStyle = ComboBoxStyle.DropDownList; }
private void SearchTextBox_TextChanged(object sender, EventArgs e) { Sqlcon = new SqlConnection(AppSetting.ConnectionString()); string query = "SELECT * FROM dbo.Student WHERE StudentName LIKE'" + SearchTextBox.Text + "%'"; Sqlcon.Open(); SqlCommand SqlCom = new SqlCommand(query, Sqlcon); SqlDataAdapter adp = new SqlDataAdapter(SqlCom); DataTable dt = new DataTable(); adp.Fill(dt); StudentDataGridView.DataSource = dt; }
public static void UpdateUserProfile(UserProfile userProfile) { using (SqlConnection conn = new SqlConnection(AppSetting.ConnectionString())) { using (SqlCommand cmd = new SqlCommand("usp_UsersUpdateUserProfile", conn)) { cmd.CommandType = System.Data.CommandType.StoredProcedure; conn.Open(); cmd.Parameters.AddWithValue("@UserId", WebSecurity.CurrentUserId); cmd.Parameters.AddWithValue("@FullName", userProfile.FullName); cmd.Parameters.AddWithValue("@Email", userProfile.Email); cmd.Parameters.AddWithValue("@Address", userProfile.Address); cmd.ExecuteNonQuery(); } } }
private void SignInButton_Click(object sender, EventArgs e) { if (isFormValid()) { DBSQLServer db = new DBSQLServer(AppSetting.ConnectionString()); bool isLoginDetailsCorrect = Convert.ToBoolean(db.GetScalarValue("usp_UsersCheckLoginDetails", GetParameter())); if (isLoginDetailsCorrect) { GetLoggedInUserSetting(); this.Hide(); DashboardForm df = new DashboardForm(); df.Show(); } else { SMSMessageBox.ShowErrorMessage("User name/Password is not correct"); } } }
private void LoadDataAndBindIntoControls() { DBSQLServer db = new DBSQLServer(AppSetting.ConnectionString()); DataTable dtEmployee = db.GetDataList("usp_EmployeesGetEmployeeDetailsId", new DBParameter { Parameter = "@EmployeeId", Value = this.EmployeeId }); DataRow row = dtEmployee.Rows[0]; EmployeeIdTextBox.Text = row["EmployeeId"].ToString(); FullNameTextBox.Text = row["FullName"].ToString(); DateOfBirthDateTimePicker.Value = Convert.ToDateTime(row["DateOfBirth"]); CNICTextBox.Text = row["CNICNumber"].ToString(); EmailAddressTextBox.Text = row["EmailAddress"].ToString(); MobileTextBox.Text = row["Mobile"].ToString(); TelephoneTextBox.Text = row["Telephone"].ToString(); GenderComboBox.SelectedValue = row["GenderId"]; EmploymentDateDateTimePicker.Value = Convert.ToDateTime(row["EmploymentDate"]); BranchComboBox.SelectedValue = row["BranchId"]; PhotoPictureBox.Image = (row["Photo"] is DBNull) ? null : ImageManipulation.PutPhoto((byte[])row["Photo"]); AddressLineTextBox.Text = row["AddressLine"].ToString(); CityComboBox.SelectedValue = row["CityId"]; DistrictComboBox.SelectedValue = row["DistrictId"]; PostralCodeTextBox.Text = row["PostralCode"].ToString(); JobTitleComboBox.SelectedValue = row["JobTitleId"]; CurrentSalaryTextBox.Text = row["CurrentSalary"].ToString(); StartingSalaryTextBox.Text = row["StartingSalary"].ToString(); HasLeftComboBox.Text = (Convert.ToBoolean(row["HasLeft"]) == true) ? "Yes" : "No"; if (row["DateLeft"] is DBNull) { DateLeftDateTimePicker.CustomFormat = " "; } else { DateLeftDateTimePicker.Value = Convert.ToDateTime(row["DateLeft"]); } ReasonLeftComboBox.SelectedValue = row["ReasonLeftId"]; CommentsTextBox.Text = row["Comments"].ToString(); }
private void LoadDataAndBindIntoControls() { DBSQLServer db = new DBSQLServer(AppSetting.ConnectionString()); DataTable dtEmployee = db.GetDataList("usp_StudentGetStudentDetailsById", new DBParameter { Parameter = "@StudentId", Value = this.StudentId }); DataRow row = dtEmployee.Rows[0]; StudentIdTextBox.Text = row["StudentId"].ToString(); StudentNameTextBox.Text = row["StudentName"].ToString(); FatherNameTextBox.Text = row["FatherName"].ToString(); PhoneNumberTextBox.Text = row["PhoneNumber"].ToString(); CityComboBox.SelectedValue = row["CityId"]; EmailAddressTextBox.Text = row["EmailAddress"].ToString(); DepartmentComboBox.SelectedValue = row["DepartmentId"]; AddressLineTextBox.Text = row["AddressLine"].ToString(); }
private void btnLogin_Click(object sender, EventArgs e) { if (IsFormValid()) { DbSQLServer db = new DbSQLServer(AppSetting.ConnectionString()); bool isLoginDetailsCorrect = Convert.ToBoolean(db.GetScalarValue("sp_CheckLoginDetails", GetPrameters())); if (isLoginDetailsCorrect) { this.Hide(); frmDashboard frm = new frmDashboard(); frm.Show(); } else { MessageBox.Show("Netačno korisničko ime ili šifra.\nPokušajte opet.", "Greška", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void LoadDataAndBindToControlIfUpdate() { if (this.IsUpdate) { DBSQLServer db = new DBSQLServer(AppSetting.ConnectionString()); DBParameter para = new DBParameter(); para.Parameter = "@BranchId"; para.Value = this.BranchId; DataTable dtBranch = db.GetDataList("usp_BranchesGetBranchDetailByBranchId", para); DataRow row = dtBranch.Rows[0]; BranchNameTextBox.Text = row["BranchName"].ToString(); EmailAddressTextBox.Text = row["Email"].ToString(); TelephoneTextBox.Text = row["Telephone"].ToString(); WebSiteAddressTextBox.Text = row["WebSite"].ToString(); AddressLineTextBox.Text = row["AddressLine"].ToString(); CityNameComboBox.SelectedValue = row["CityId"]; DistrictNameComboBox.SelectedValue = row["DistrictId"]; PostralCodeTextBox.Text = row["PostralCode"].ToString(); LogoPictureBox.Image = (row["branchImage"] is DBNull) ? null : ImageManipulation.PutPhoto((byte[])row["branchImage"]); } }
private void btnSignIn_Click(object sender, EventArgs e) { if (IsFormValid()) { DbSQLServer dbSQLServer = new DbSQLServer(AppSetting.ConnectionString()); bool isLoginDetailsCorrect = Convert.ToBoolean(dbSQLServer.GetScalarValue("usp_UsersCheckLoginDetails", GetParameters())); if (isLoginDetailsCorrect) { GetLoggedInUserSettings(); this.Hide(); DashboardForm dashboardForm = new DashboardForm(); dashboardForm.Show(); } else { JIMessageBox.ShowErrorMessage("User Name/Password is incorrect"); //MessageBox.Show("User Name/Password is incorrect", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void LoadDataAndBindToControlIfUpdate() { if (this.IsUpdate) { DbSQLServer dbSQLServer = new DbSQLServer(AppSetting.ConnectionString()); //DbParameter dbPara = new DbParameter(); //dbPara.Parameter = "@BranchId"; //dbPara.Value = this.BranchId; DataTable dtBranchTable = dbSQLServer.GetDataList("usp_BranchesGetBrancheDetailByBranchId", new DbParameter { Parameter = "@BranchId", Value = this.BranchId }); DataRow row = dtBranchTable.Rows[0]; BranchNameTextBox.Text = row["BranchName"].ToString(); EmailTextBox.Text = row["Email"].ToString(); MobileTextBox.Text = row["Mobile"].ToString(); WebAddressTextBox.Text = row["Website"].ToString(); LogoPictureBox.Image = (row["branchImage"] is DBNull)? null : ImageManipulations.PutPhoto((byte[])row["branchImage"]); AddressLineTextBox.Text = row["AddressLine"].ToString(); CityComboBox1.SelectedValue = row["CityId"]; DistrictComboBox2.SelectedValue = row["DistrictId"]; PostCodeTextBox.Text = row["PostCode"].ToString(); } }
private void GenerateStudentId() { DBSQLServer db = new DBSQLServer(AppSetting.ConnectionString()); StudentIdTextBox.Text = db.GetScalarValue("usp_StudentsGenerateNewStudentId").ToString(); }
private void SaveOrUpdateRecord(string storedProceName) { DBSQLServer db = new DBSQLServer(AppSetting.ConnectionString()); db.SaveOrUpdateRecord(storedProceName, GetObject()); }
private void GenerateEmployeeId() { DbSQLServer dBSQLSerevr = new DbSQLServer(AppSetting.ConnectionString()); EmployeeIDTextBox.Text = dBSQLSerevr.GetScalarValue("usp_EmployeesGenerateNewEmployeeId").ToString(); }