private void Save_Button_Click(object sender, EventArgs e) { string TempGioiTinh; if (Nam_RadioButton.Checked == true) { TempGioiTinh = "Nam"; } else { TempGioiTinh = "Nữ"; } if (Them) { blNV = new BLNhanVien(); if (Password_TextBox.Text == "") { MessageBox.Show("Chưa nhập mật khẩu"); } else { if (blNV.ThemNV(MaNV_TextBox.Text, TenNV_TextBox.Text, ChucVu_ComboBox.Text, Luong_TextBox.Text, NgaySinh_DateTimePicker.Value.Date.ToString(), TempGioiTinh, Password_TextBox.Text) == true) { LoadData(); MessageBox.Show(" Them thanh cong"); } else { MessageBox.Show(" Them that bai"); } this.Password_TextBox.ResetText(); this.Password_TextBox.Enabled = false; } } else { blNV = new BLNhanVien(); if (blNV.CapNhatNV(MaNV_TextBox.Text, TenNV_TextBox.Text, ChucVu_ComboBox.Text, Luong_TextBox.Text, NgaySinh_DateTimePicker.Value.Date.ToString(), TempGioiTinh) == true) { LoadData(); MessageBox.Show(" Cap nhat thanh cong"); } else { MessageBox.Show(" Cap nhat that bai"); } } }
private void btnLuu_Click(object sender, EventArgs e) { // Mở kết nối // Thêm dữ liệu if (Them) { try { // Thực hiện lệnh BLNhanVien blNV = new BLNhanVien(); string macv = dt.Tables[0].Rows[cboCongViec.SelectedIndex]["MaCV"].ToString(); blNV.ThemNV(this.txtMaNV.Text, this.txtTenNV.Text, macv, this.txtGT.Text, this.txtSDT.Text, this.txtDiaChi.Text, Convert.ToInt32(txtLuong.Text), ref err); //blXe.ThemXe("ba","con","co",1,1, ref err); // Load lại dữ liệu trên DataGridView LoadData(); // Thông báo MessageBox.Show("Đã thêm xong!"); } catch { MessageBox.Show("Không thêm được. Lỗi rồi!"); } } else { // Thực hiện lệnh BLNhanVien blNV = new BLNhanVien(); string macv = dt.Tables[0].Rows[cboCongViec.SelectedIndex]["MaCV"].ToString(); if (!blNV.CapNhatNV(this.txtMaNV.Text, this.txtTenNV.Text, macv, this.txtGT.Text, this.txtSDT.Text, this.txtDiaChi.Text, Convert.ToInt32(txtLuong.Text), ref err))// Load lại dữ liệu trên DataGridView { MessageBox.Show("Có lỗi phát sinh,Cập nhật thất bại!"); return; } LoadData(); // Thông báo MessageBox.Show("Đã sửa xong!"); } // Đóng kết nối }
private void btnLuu_Click(object sender, EventArgs e) { if (rdoNam.Checked == true) { gt = "Nam"; } else { if (rdoNu.Checked == true) { gt = "Nu"; } } // bDate = DateTime.Parse(dateTimePickerNgSinh.Text).ToString("yyyy-MM-dd"); // sDate = DateTime.Parse(dateTimePickerNgBD.Text).ToString("yyyy-MM-dd"); // float salary = float.Parse(txtLuong.Text); if (Them) { try { BLNhanVien blNV = new BLNhanVien(); blNV.ThemNV(this.txtMaNV.Text, this.txtHoTen.Text, this.gt, this.txtDC.Text, this.txtDT.Text, this.txtEmail.Text, ref err); LoadData(); MessageBox.Show("Đã thêm xong!"); } catch (SqlException) { MessageBox.Show("Không thêm được. Lỗi rồi!"); } } else { BLNhanVien blNV = new BLNhanVien(); blNV.CapNhatNV(this.txtMaNV.Text, this.txtHoTen.Text, this.gt, this.txtDC.Text, this.txtDT.Text, this.txtEmail.Text, ref err); LoadData(); MessageBox.Show("Đã sửa xong!"); } }
private void BtnLuu_Click(object sender, EventArgs e) { checkBoxNam.Checked = false; checkBoxNu.Checked = false; checkBoxKhac.Checked = false; if (them == true) { if (dbNhanVien.KiemTraMaNV(txtMaNV.Text) == 0) { if (dbNhanVien.ThemNV(this.txtMaNV.Text, this.txtTenNV.Text, this.cbGioiTinh.Text, this.txtSDT.Text, this.txtDiaChi.Text, this.txtEmail.Text, this.txtMK.Text, this.cbQuyen.Text, this.txtCN.Text) == true) { MessageBox.Show("Thêm Thành Công", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); LoadData(); } else { MessageBox.Show("Không Thể Thêm", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } } else { MessageBox.Show("Trùng Mã Nhân Viên", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { if (dbNhanVien.CapNhatNV(this.txtMaNV.Text, this.txtTenNV.Text, this.cbGioiTinh.Text, this.txtSDT.Text, this.txtDiaChi.Text, this.txtEmail.Text, this.txtMK.Text, this.cbQuyen.Text, this.txtCN.Text) == true) { MessageBox.Show("Cập nhật Thành Công", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); LoadData(); } else { MessageBox.Show("Không Thể Cập Nhật", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } } }