private void txtSearch_KeyUp(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { string key = txtSearch.Text; string tenNhom = (string)dgvNhom.CurrentCell.Value; List <DanhBa> list = DanhBa.getDanhBaTheoNhom(tenNhom); List <DanhBa> rs = new List <DanhBa>(); for (int i = 0; i < list.Count; i++) { if (list.ElementAt(i).tenGoi.Equals(key) || list.ElementAt(i).email.Equals(key) || list.ElementAt(i).sdt.Equals(key)) { rs.Add(list.ElementAt(i)); } } bdsDanhBa.DataSource = rs; dgvDanhBa.DataSource = bdsDanhBa; } if (txtSearch.Text.Equals("")) { string tenNhom = (string)dgvNhom.CurrentCell.Value; List <DanhBa> list = DanhBa.getDanhBaTheoNhom(tenNhom); bdsDanhBa.DataSource = list; dgvDanhBa.DataSource = bdsDanhBa; } }
private void dgvNhom_CellClick(object sender, DataGridViewCellEventArgs e) { string tenNhom = (string)dgvNhom.CurrentCell.Value; List <DanhBa> list = DanhBa.getDanhBaTheoNhom(tenNhom); bdsDanhBa.DataSource = list; dgvDanhBa.DataSource = bdsDanhBa; }
private void btnRefresh_Click(object sender, EventArgs e) { List <Nhom> listNhom = Nhom.getNhom(); bdsNhom.DataSource = listNhom; dgvNhom.DataSource = bdsNhom; string tenNhom = (string)dgvNhom.CurrentCell.Value; List <DanhBa> list = DanhBa.getDanhBaTheoNhom(tenNhom); bdsDanhBa.DataSource = list; dgvDanhBa.DataSource = bdsDanhBa; }
private void btnXoaNhom_Click(object sender, EventArgs e) { string tenNhomXoa = (string)dgvNhom.CurrentCell.Value; string pathNhom = Application.StartupPath + @"/DATA/Nhom.txt"; string pathDanhBa = Application.StartupPath + @"/DATA/DanhBa.txt"; string[] linesNhom = File.ReadAllLines(pathNhom); string[] linesDanhBa = File.ReadAllLines(pathDanhBa); File.WriteAllText(pathNhom, ""); File.WriteAllText(pathDanhBa, ""); string newline = System.Environment.NewLine; for (int i = 0; i < linesNhom.Length; i++) { string[] temp = linesNhom[i].Split(new char[] { '#' }); if (!temp[1].Equals(tenNhomXoa)) { File.AppendAllText(pathNhom, linesNhom[i] + newline, Encoding.Unicode); } } for (int i = 0; i < linesDanhBa.Length; i++) { string[] temp = linesDanhBa[i].Split(new char[] { '#' }); if (!temp[0].Equals(tenNhomXoa)) { File.AppendAllText(pathDanhBa, linesDanhBa[i] + newline, Encoding.Unicode); } } List <Nhom> listNhom = Nhom.getNhom(); bdsNhom.DataSource = listNhom; dgvNhom.DataSource = bdsNhom; string tenNhom = (string)dgvNhom.CurrentCell.Value; List <DanhBa> list = DanhBa.getDanhBaTheoNhom(tenNhom); bdsDanhBa.DataSource = list; dgvDanhBa.DataSource = bdsDanhBa; }