Пример #1
0
        private void TsbXoaNhom_Click(object sender, EventArgs e)
        {
            try
            {
                int    hanghientai = dgvGroup.CurrentCell.RowIndex;
                String tenNhom     = dgvGroup.Rows[hanghientai].Cells[0].Value.ToString();
                if (tenNhom != null)
                {
                    if (MessageBox.Show("Bạn có thực sự muốn xóa nhóm này không?", "Thông báo",
                                        MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.OK)
                    {
                        dgvGroup.Rows.RemoveAt(dgvGroup.CurrentCell.RowIndex);
                        bdsGroups.DataSource = dgvGroup.DataSource;
                        LienHe.RemoveListContact(tenNhom);
                        Nhom.Remove(tenNhom);
                        dgvContacts.Rows.Clear();
                        List <LienHe> dslh = LienHe.GetList(dgvGroup.Rows[0].Cells[0].FormattedValue.ToString());
                        if (dslh != null)
                        {
                            foreach (var i in dslh)
                            {
                                dgvContacts.Rows.Add(i.TenGoi, i.Email, i.SDT);
                            }

                            LienHe lh = LienHe.GetLienHe(dgvContacts.Rows[0].Cells[0].FormattedValue.ToString());
                            if (lh != null)
                            {
                                label1.Text    = "Địa chỉ:";
                                label2.Text    = "Email:";
                                label3.Text    = "Số điện thoại:";
                                lblTenGoi.Text = lh.TenGoi;
                                lblDiaChi.Text = lh.DiaChi;
                                lblEmail.Text  = lh.Email;
                                lblSDT.Text    = lh.SDT;
                            }
                            else
                            {
                                lblTenGoi.Text = "";
                                lblDiaChi.Text = "";
                                lblEmail.Text  = "";
                                lblSDT.Text    = "";
                                label1.Text    = "";
                                label2.Text    = "";
                                label3.Text    = "";
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Vui lòng chọn nhóm muốn xóa", "Thông báo", MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
            }
        }