private void button2_Click(object sender, EventArgs e) { DataGridViewRow dr = dataGridView1.SelectedRows[0]; nhansurutgon nscu = new nhansurutgon(dr.Cells[0].Value.ToString(), dr.Cells[1].Value.ToString(), (dr.Cells[2].Value == null) ? "" : dr.Cells[2].Value.ToString(), (dr.Cells[3].Value == null) ? "" : dr.Cells[3].Value.ToString(), (dr.Cells[4].Value == null) ? "" : dr.Cells[4].Value.ToString(), (dr.Cells[5].Value == null) ? "" : dr.Cells[5].Value.ToString()); nhansurutgon nsmoi = new nhansurutgon(manv.Text, ten.Text, cbnghe.Text, cbchucvu.Text, cbkhoa.Text, cbpb.Text); DialogResult dialogResult = MessageBox.Show(string.Format("Xác nhận cập nhật thông tin nhân sự {0}?", nscu.ten), "Thông báo", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { int iduser = taikhoan.Loadnhansu().Single(x => x.manv == nscu.manv).iduser; short idkhoa = (cbkhoa.Text == "") ? short.Parse("0") : taikhoan.Loadkhoa().Single(x => x.ten == nsmoi.khoa).idkhoa; short idpb = (cbpb.Text == "") ? short.Parse("0") : taikhoan.Loadphongban().Single(x => x.ten == nsmoi.pb).idphongban; taikhoan.Capnhatnhansu(iduser, nsmoi.ten, nsmoi.manv, idkhoa, idpb, nsmoi.nghe, nsmoi.chucvu, email.Text, sdt.Text, manv.Text); MessageBox.Show("Cập nhật thành công", "Thông báo"); } clear(); loaddata(); }
private List <nhansurutgon> rutgon(List <nhansu> nhansuraw) { List <nhansurutgon> nsrutgon = new List <nhansurutgon>(); foreach (nhansu item in nhansuraw) { nhansurutgon tk = new nhansurutgon("", "", "", "", "", ""); tk.ten = item.hoten; tk.manv = item.manv; tk.nghe = item.nghenghiep; if (item.idphongban != null) { tk.pb = taikhoan.Layphongban(item.idphongban); } tk.chucvu = item.chucvu; if (item.idkhoa != null) { tk.khoa = taikhoan.Laykhoa(item.idkhoa); } nsrutgon.Add(tk); } return(nsrutgon); }
private void loaddata() { List <nhansu> loadnhansu = taikhoan.Loadnhansu(); List <nhansurutgon> nsrutgon = new List <nhansurutgon>(); foreach (nhansu item in loadnhansu) { nhansurutgon tk = new nhansurutgon("", "", "", "", "", ""); tk.ten = item.hoten; tk.manv = item.manv; tk.nghe = item.nghenghiep; if (item.idphongban != null) { tk.pb = taikhoan.Layphongban(item.idphongban); } tk.chucvu = item.chucvu; if (item.idkhoa != null) { tk.khoa = taikhoan.Laykhoa(item.idkhoa); } nsrutgon.Add(tk); } dataGridView1.DataSource = nsrutgon; // wrap text dataGridView1.DefaultCellStyle.WrapMode = DataGridViewTriState.True; dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells; dataGridView1.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells; dataGridView1.Columns[0].DefaultCellStyle.WrapMode = DataGridViewTriState.True; // dataGridView1.Columns[0].HeaderText = "Mã nhân viên"; dataGridView1.Columns[1].HeaderText = "Họ tên"; dataGridView1.Columns[2].HeaderText = "Nghề nghiệp"; dataGridView1.Columns[3].HeaderText = "Chức vụ"; dataGridView1.Columns[4].HeaderText = "Khoa lâm sàng"; dataGridView1.Columns[5].HeaderText = "Phòng ban"; //for (int i = 7; i < 14; i++) //{ // dataGridView1.Columns[i].Visible = false; //} }