private void ThemNhanVien(Class.ThemNV NV) { try { SqlConnection Con = KetNoiCSDL.KetNoiSQL(); Con.Open(); string ThemNV = string.Format("insert into NhanVien(MaNhanVien, TenNhanVien, SDT, NgaySinh, GioiTinh, DiaChi, NgayVaoLamViec,KinhNghiem,SoGioDaChay, LoaiNV, MaCV) values(@MaNV, @Ten, @SDT, @NgaySinh, @GioiTinh, @DiaChi, @NgayLam, @KinhNghiem, @SoGioLam, @LoaiNV, @MaCV)"); string InsertCVNV = string.Format("insert into PhanCongViec(MaCongViec) values(@MaCV)"); string InsertDanhGia = string.Format("insert into DanhGiaNhanVien(MaNhanVien) values(@MaNhanVien)"); DataTable user = new DataTable(); SqlCommand Com = new SqlCommand(ThemNV, Con); SqlCommand ComCV = new SqlCommand(InsertCVNV, Con); SqlCommand ComDG = new SqlCommand(InsertDanhGia, Con); DateTime NS; DateTime.TryParse(NV.NgaySinh, out NS); DateTime NL; DateTime.TryParse(NV.NgayLamViec, out NL); //ThemNV Com.Parameters.Add(new SqlParameter("@MaNV", NV.MaNhanVien)); Com.Parameters.Add(new SqlParameter("@Ten", NV.TenNhanVien)); Com.Parameters.Add(new SqlParameter("@SDT", NV.SDT)); Com.Parameters.Add(new SqlParameter("@NgaySinh", NS)); Com.Parameters.Add(new SqlParameter("@GioiTinh", NV.GioiTinh)); Com.Parameters.Add(new SqlParameter("@DiaChi", NV.DiaChi)); Com.Parameters.Add(new SqlParameter("@NgayLam", NL)); Com.Parameters.Add(new SqlParameter("@KinhNghiem", NV.KinhNghiem)); Com.Parameters.Add(new SqlParameter("@SoGioLam", NV.SoGioDaChay)); Com.Parameters.Add(new SqlParameter("@LoaiNV", NV.LoaiNV)); Com.Parameters.Add(new SqlParameter("@MaCV", NV.MaCV)); //InsertCVNV ComCV.Parameters.Add(new SqlParameter("@MaCV", NV.MaCV)); //InsertDGNV ComDG.Parameters.Add(new SqlParameter("@MaNhanVien", NV.MaNhanVien)); SqlDataAdapter adapt1 = new SqlDataAdapter(ComCV); SqlDataAdapter adapt = new SqlDataAdapter(Com); SqlDataAdapter adapt2 = new SqlDataAdapter(ComDG); adapt1.Fill(user); adapt.Fill(user); adapt2.Fill(user); Con.Close(); MetroFramework.MetroMessageBox.Show(this, string.Format("Đã Thêm Nhân Viên {0}!", NV.TenNhanVien), "Compelete", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } catch (Exception EX) { MetroFramework.MetroMessageBox.Show(this, EX.Message); } }
private void EditNhanVien(Class.ThemNV NV) { try { SqlConnection Con = KetNoiCSDL.KetNoiSQL(); Con.Open(); string ThemNV = string.Format("update NhanVien set TenNhanVien= @Ten,SDT = @SDT,NgaySinh= @NgaySinh,GioiTinh=@GioiTinh,DiaChi=@DiaChi,KinhNghiem=@KinhNghiem,SoGioDaChay=@SoGioLam,LoaiNV = @LoaiNV where MaNhanVien=@MaNhanVien"); DataTable user = new DataTable(); SqlCommand Com = new SqlCommand(ThemNV, Con); DateTime NS; DateTime.TryParse(NV.NgaySinh, out NS); //ThemNV Com.Parameters.Add(new SqlParameter("@Ten", NV.TenNhanVien)); Com.Parameters.Add(new SqlParameter("@SDT", NV.SDT)); Com.Parameters.Add(new SqlParameter("@NgaySinh", NS)); Com.Parameters.Add(new SqlParameter("@GioiTinh", NV.GioiTinh)); Com.Parameters.Add(new SqlParameter("@DiaChi", NV.DiaChi)); Com.Parameters.Add(new SqlParameter("@KinhNghiem", NV.KinhNghiem)); Com.Parameters.Add(new SqlParameter("@SoGioLam", NV.SoGioDaChay)); Com.Parameters.Add(new SqlParameter("@LoaiNV", NV.LoaiNV)); Com.Parameters.Add(new SqlParameter("@MaNhanVien", MaNhanVien_FormMain)); SqlDataAdapter adapt = new SqlDataAdapter(Com); adapt.Fill(user); Con.Close(); MetroFramework.MetroMessageBox.Show(this, string.Format("Đã Edit Nhân Viên {0}!", NV.TenNhanVien), "Compelete", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } catch (Exception EX) { MetroFramework.MetroMessageBox.Show(this, EX.Message); } }
private Class.ThemNV LayDuLieuNhap() { Class.ThemNV Temp = new Class.ThemNV(); Temp.TenNhanVien = txtTen.Text; Temp.MaNhanVien = Convert.ToInt32(lblMaNhanVien.Text); Temp.SDT = txtSDT.Text; Temp.NgaySinh = txtNgaySinh.Value.ToShortDateString(); if (rdNam.Checked == true) { Temp.GioiTinh = "Nam"; } else { Temp.GioiTinh = "Nữ"; } Temp.DiaChi = txtDiaChi.Text; Temp.KinhNghiem = txtKinhNghiem.Text; Temp.SoGioDaChay = txtSohChay.Text; Temp.LoaiNV = txtLoaiNhanVien.SelectedValue.ToString(); Temp.MaCV = lblMaNhanVien.Text; return(Temp); }