コード例 #1
0
 private void btn_Xoa_Click(object sender, EventArgs e)
 {
     if (SelectedNode != null &&
         MessageBox.Show("Bạn muốn xoá thành phố / quốc gia này?", "Hỏi", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
     {
         if (SelectedNode.Level == 0)
         {
             oQuocGia.ID = Convert.ToInt32(SelectedNode.Name);
             try
             {
                 oQuocGia.Delete();
                 GetTinhTP_QuocGia();
                 UpdateTreeVDonVi();
                 MessageBox.Show("Xoá quốc gia thành công.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 txt_Ten.Text = "";
                 comB_QuocGia.SelectedIndex = -1;
             }
             catch (Exception)
             {
                 MessageBox.Show("Xoá quốc gia không thành công.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
         }
         else
         {
             oTinhTP.ID = Convert.ToInt16(SelectedNode.Name);
             try
             {
                 oTinhTP.Delete();
                 GetTinhTP_QuocGia();
                 UpdateTreeVDonVi();
                 MessageBox.Show("Xoá thành phố thành công.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
             catch (Exception)
             {
                 MessageBox.Show("Xoá thành phố không thành công.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
         }
     }
 }