예제 #1
0
        private void độcGiảToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
            DocGia frm = new DocGia();

            frm.Show();
        }
예제 #2
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            if (key == 1)
            {
                if (txtMaSV.Text != "" && txtHoten.Text != "" && txtDiachi.Text != "" && txtLop.Text != "")
                {
                    string gioitinh = "";
                    if (rbNam.Checked)
                    {
                        gioitinh = "Nam";
                    }
                    else if (rbNu.Checked)
                    {
                        gioitinh = "Nữ";
                    }

                    DocGia dg = new DocGia(txtMaSV.Text.ToString().Trim(), txtHoten.Text.ToString().Trim(), DateTime.Parse(dtgNgaySinh.Text.ToString()), gioitinh, txtDiachi.Text.ToString().Trim(), txtLop.Text.ToString().Trim());
                    if (bal_docgia.Them(dg) == true)
                    {
                        ClearText();
                        ShowData();
                        MessageBox.Show("Thêm thành công");
                        frmDocGia_Load(sender, e);
                        key = 0;
                    }
                    else
                    {
                        Exception ex = bal_docgia.GetEx();
                        MessageBox.Show(ex.Message);
                        MessageBox.Show("Mã độc giả đã tồn tại");
                    }
                }
                else
                {
                    MessageBox.Show("Bạn cần nhập đủ thông tin ");
                }
            }

            if (key == 2)
            {
                if (txtMaSV.Text != "" && txtHoten.Text != "" && txtDiachi.Text != "" && txtLop.Text != "")
                {
                    string gioitinh = "";
                    if (rbNam.Checked)
                    {
                        gioitinh = "Nam";
                    }
                    else if (rbNu.Checked)
                    {
                        gioitinh = "Nữ";
                    }

                    DocGia dg = new DocGia(txtMaSV.Text.ToString().Trim(), txtHoten.Text.ToString().Trim(), DateTime.Parse(dtgNgaySinh.Text.ToString()), gioitinh, txtDiachi.Text.Trim(), txtLop.Text.ToString().Trim());
                    if (bal_docgia.Sua(dg) == true)
                    {
                        ClearText();
                        ShowData();
                        MessageBox.Show("Sửa thành công");
                        frmDocGia_Load(sender, e);
                        key = 0;
                    }
                    else
                    {
                        Exception ex = bal_docgia.GetEx();
                        MessageBox.Show(ex.Message);
                        MessageBox.Show("Có lỗi xảy ra");
                    }
                }
                else
                {
                    MessageBox.Show("Chọn dòng bạn muốn sửa và hãy nhập đầy đủ thông tin");
                }
            }
            if (key == 3)
            {
                if (txtMaSV.Text.Length != 0)
                {
                    string query = @"DELETE FROM SinhVien Where masv='" + txtMaSV.Text + "'";

                    if (bal_docgia.Xoa(txtMaSV.Text.Trim()))
                    {
                        ClearText();
                        ShowData();
                        MessageBox.Show("Xóa thành công");
                        frmDocGia_Load(sender, e);
                        key = 0;
                    }
                    else
                    {
                        Exception ex = bal_docgia.GetEx();
                        MessageBox.Show(ex.Message);
                        MessageBox.Show("Không Thể Xóa Độc Giả Này");
                    }
                }
                else
                {
                    MessageBox.Show("Vui lòng chọn");
                }
            }
        }