private void btnEditGV_Click(object sender, EventArgs e) { if (this.lstInstructor.SelectedIndices.Count <= 0) { MessageBox.Show("Bạn chưa chọn đối tượng !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (this.lstInstructor.Items.Count == 0) { return; } Instructor ins = new Instructor(); //Lấy GV từ database với key tương ứng (id) ins = GVController.GetInstructor(this.lstInstructor.SelectedItems[0].SubItems[1].Text); string oldID = ins.id; //Dùng form frmAddGV với chức năng sửa frmAddGV addform = new frmAddGV(ref ins); addform.ShowDialog(); // Sửa trên database( tìm index và sửa) GVController.Update(ins, oldID); // Update trên listview this.lstInstructor.SelectedItems[0].SubItems[1].Text = ins.id.ToString(); this.lstInstructor.SelectedItems[0].SubItems[2].Text = ins.name.ToString(); this.lstInstructor.SelectedItems[0].SubItems[3].Text = ins.gender; this.lstInstructor.SelectedItems[0].SubItems[5].Text = ins.birthday.ToShortDateString(); this.lstInstructor.SelectedItems[0].SubItems[4].Text = ins.phone; this.lstInstructor.SelectedItems[0].SubItems[6].Text = ins.subject; }
private void btnAddGV_Click(object sender, EventArgs e) { // Dùng form Add_GV frmAddGV addform = new frmAddGV(); addform.ShowDialog(); // Nếu cancel (instructor ==null) thì return if (addform.instuctor.name == null) { return; } // Hiển thị lên listview Instructor GV = addform.instuctor; ListViewItem infoGV = new ListViewItem(STT.ToString()); infoGV.SubItems.Add(new ListViewItem.ListViewSubItem(infoGV, GV.id.ToString())); infoGV.SubItems.Add(new ListViewItem.ListViewSubItem(infoGV, GV.name.ToString())); infoGV.SubItems.Add(new ListViewItem.ListViewSubItem(infoGV, GV.gender.ToString())); infoGV.SubItems.Add(new ListViewItem.ListViewSubItem(infoGV, GV.birthday.ToShortDateString())); infoGV.SubItems.Add(new ListViewItem.ListViewSubItem(infoGV, GV.phone.ToString())); infoGV.SubItems.Add(new ListViewItem.ListViewSubItem(infoGV, GV.subject)); //Dùng str để đưa danh sách môn học về trong 1 ô this.lstInstructor.Items.Add(infoGV); //Thêm vào list, dùng database //GVController.AddGV(addform.instuctor); // Tăng STT STT++; if (GVController.AddGV(GV) == true) { GVController.AddGV(GV); } else { MessageBox.Show("Err add GV"); } }