private void button3_Click(object sender, EventArgs e)
        {
            tblTacgia objtacgia;

            try
            {
                objtacgia = new tblTacgia(txtMatacgia.Text, txtTentacgia.Text);
            }
            catch (Exception ex)
            {
                string erro = ex.Message;
                MessageBox.Show(erro, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                if (erro.Contains("mã"))
                {
                    txtMatacgia.Focus();
                }
                else
                {
                    txtTentacgia.Focus();
                }
                return;
            }
            tblTacgia objTacgia = new tblTacgia(txtMatacgia.Text, txtTentacgia.Text);
            int       result    = objTacgia.capnhapTacgia();

            if (result == 0)
            {
                MessageBox.Show("Cập nhật Tác giả[" + txtTentacgia.Text + "] thành công!");
            }
            else
            {
                MessageBox.Show("Cập nhật thất bại.Mời bạn cập nhật lại!");
            }
            this.DialogResult = DialogResult.OK;
        }
Exemplo n.º 2
0
        private void btnXoaTacgia_Click(object sender, EventArgs e)
        {
            if (listNhacsi.SelectedItems.Count == 0)
            {
                return;
            }
            DialogResult tb = MessageBox.Show("Bạn có thực sự muốn xóa Tác giả[" + listNhacsi.GetItemText(listNhacsi.SelectedItem) + "] không !", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);

            if (tb == DialogResult.Cancel)
            {
                return;
            }
            string    matg = listNhacsi.SelectedValue.ToString();
            tblTacgia dt   = new tblTacgia(matg);
            int       kq   = dt.xoaTacGia();

            if (kq == 0)
            {
                MessageBox.Show("Bạn đã xóa thành công tác giả[" + listNhacsi.GetItemText(listNhacsi.SelectedItem) + "] thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("Chưa xóa được!");
            }
            load_TacGia();
        }