示例#1
0
        private void bt_xoa_Click(object sender, EventArgs e)
        {
            int currentRowIndex = data_hieuxe.CurrentCellAddress.Y;// 'current row selected

            //'Verify that indexing OK
            if (-1 < currentRowIndex && currentRowIndex < data_hieuxe.RowCount)
            {
                HieuXeDTO hx = new HieuXeDTO();
                hx.Mahieuxe = int.Parse(tb_mahieuxe.Text);

                //2. Kiểm tra data hợp lệ or not

                //3. Thêm vào DB
                bool kq = hxBus.xoa(hx);
                if (kq == false)
                {
                    MessageBox.Show("Xóa hiệu xe thất bại. Vui lòng kiểm tra lại dũ liệu");
                }
                else
                {
                    MessageBox.Show("Xóa hiệu xe thành công");
                    this.loadData_Vao_GridView();
                    tb_mahieuxe.Clear();
                    tb_hieuxe.Clear();
                }
            }
            CurrencyManager myCurrencyManager = (CurrencyManager)this.BindingContext[data_hieuxe.DataSource];

            myCurrencyManager.Refresh();
        }
        private void btXoa_Click(object sender, EventArgs e)
        {
            DialogResult = MessageBox.Show("Bạn có chắc chắn muốn xóa ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (DialogResult == DialogResult.Yes)
            {
                HieuXeDTO hx = new HieuXeDTO();

                hx.HieuXe = txtHieuXe.Text;
                bool kq2 = hxBus.xoa(hx);
                if (kq2 == false)
                {
                    MessageBox.Show("Xóa thông tin thất bại. Vui lòng kiểm tra lại dữ liệu");
                }
                else
                {
                    MessageBox.Show("Xóa thông tin thành công");
                }
                this.loadData_Vao_GridView();

                txtHieuXe.Text = "";
            }
        }