public static int InsertDepartment(Department newDepartment) { String sqlInsert = @"INSERT INTO DEPARTMENT(DEPARTMENTNAME) VALUES (@DEPARTMENTNAME)"; SqlParameter[] sqlParameters = { new SqlParameter("@DEPARTMENTNAME", newDepartment.DepartmentName) }; return SqlResult.ExecuteNonQuery(sqlInsert, sqlParameters); }
private void buttonOk_Click(object sender, EventArgs e) { if (!superValidator1.Validate()) return; try { if (UserAction == "edit") { DepartmentDetail.DepartmentName = textBoxDepartmentName.Text; DialogResult dialogResult = MessageBox.Show("Xác nhận cập nhập thông tin phòng ban", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialogResult == DialogResult.Yes) { if (Department.UpdateDepartment(DepartmentDetail) > 0) MessageBox.Show("Cập nhập thông tin phòng ban thành công thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { Department newDepartment = new Department(0, textBoxDepartmentName.Text); if (Department.InsertDepartment(newDepartment) > 0) MessageBox.Show("Thêm phòng ban thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch { MessageBox.Show("Lỗi dữ liệu", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } this.Close(); }
public FormDepartmentDetail(Department departmentDetail, String userAction) { InitializeComponent(); this.DepartmentDetail = departmentDetail; this.UserAction = userAction; if (this.UserAction == "edit") SetDepartmentDetail(departmentDetail); }
public static int UpdateDepartment(Department updateDepartment) { string sqlUpdate = @"UPDATE DEPARTMENT SET DEPARTMENTNAME = @DEPARTMENTNAME WHERE (DEPARTMENTID =@DEPARTMENTID)"; SqlParameter[] sqlParameters = { new SqlParameter("@DEPARTMENTID", updateDepartment.DepartmentID), new SqlParameter("@DEPARTMENTNAME", updateDepartment.DepartmentName)}; return SqlResult.ExecuteNonQuery(sqlUpdate, sqlParameters); }
public static Department GetDepartment(int departmentID) { Department newDepartment = new Department(); int tempInterger; string sqlSelect = @"SELECT DEPARTMENTID, DEPARTMENTNAME FROM DEPARTMENT WHERE (DEPARTMENTID=@DEPARTMENTID)"; SqlParameter[] sqlParameters = { new SqlParameter("@DEPARTMENTID", departmentID) }; DataTable dataTable = SqlResult.ExecuteQuery(sqlSelect,sqlParameters); if (dataTable.Rows.Count > 0) { int.TryParse(dataTable.Rows[0][0].ToString(), out tempInterger); newDepartment.DepartmentID = tempInterger; newDepartment.DepartmentName = dataTable.Rows[0][1].ToString(); } return newDepartment; }
private void SetDepartmentDetail(Department departmentDetail) { textBoxDepartmentID.Text = departmentDetail.DepartmentID.ToString(); textBoxDepartmentName.Text = departmentDetail.DepartmentName; }