Exemplo n.º 1
0
        private void xuLyHieuChinh(String maSV, String ho, String ten, bool phaiSV, DateTime ngaySinh,
                                   String noiSinh, String diaChi, bool nghiHoc)
        {
            try
            {
                DsSinhVienTheoLopBindingSource.EndEdit();
                DsSinhVienTheoLopBindingSource.ResetCurrentItem();
                this.DsSinhVienTheoLopTableAdapter.Connection.ConnectionString = Program.connstr;
                this.DsSinhVienTheoLopTableAdapter.Update(maSV, ho, ten, phaiSV, ngaySinh, noiSinh, diaChi, nghiHoc);

                MessageBox.Show("Hiệu chỉnh thành công", "", MessageBoxButtons.OK);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Lỗi hiệu chỉnh sinh viên.\n" + ex.Message, "", MessageBoxButtons.OK);
                return;
            }

            gcSinhVien.Enabled = true;
            btnThem.Enabled    = btnHieuChinh.Enabled = btnXoa.Enabled = btnReload.Enabled = btnThoat.Enabled = true;
            btnGhi.Enabled     = false;

            panelDetail.Enabled = false;

            vitriLop = cmbLop.SelectedIndex;
            reload();
            cmbLop.SelectedIndex = vitriLop;
        }
Exemplo n.º 2
0
        private void xuLyThem(bool haveUndo, String maSV, String ho, String ten, String maLop,
                              bool phai, DateTime ngaySinh, String noiSinh, String diaChi, bool nghiHoc)
        {
            if (Program.conn.State == ConnectionState.Closed)
            {
                Program.conn.Open();
            }
            String strLenh = "dbo.sp_KiemTraMaSV";

            Program.sqlcmd             = Program.conn.CreateCommand();
            Program.sqlcmd.CommandType = CommandType.StoredProcedure;
            Program.sqlcmd.CommandText = strLenh;
            Program.sqlcmd.Parameters.Add("@MASV", SqlDbType.Text).Value   = maSV;
            Program.sqlcmd.Parameters.Add("@Ret", SqlDbType.Int).Direction = ParameterDirection.ReturnValue;
            Program.sqlcmd.ExecuteNonQuery();
            String Ret = Program.sqlcmd.Parameters["@Ret"].Value.ToString();

            if (Ret == "1")
            {
                MessageBox.Show("Mã sinh viên bị trùng!", "", MessageBoxButtons.OK);
                txtMaSV.Focus();
                Program.conn.Close();
                return;
            }

            try
            {
                DsSinhVienTheoLopBindingSource.EndEdit();
                DsSinhVienTheoLopBindingSource.ResetCurrentItem();
                this.DsSinhVienTheoLopTableAdapter.Connection.ConnectionString = Program.connstr;
                this.DsSinhVienTheoLopTableAdapter.Insert(maSV, ho, ten, maLop, phai,
                                                          ngaySinh, noiSinh, diaChi, nghiHoc);

                vitriLop = cmbLop.SelectedIndex;
                reload();
                cmbLop.SelectedIndex = vitriLop;

                if (haveUndo)
                {
                    MessageBox.Show("Thêm sinh viên thành công", "", MessageBoxButtons.OK);
                }
                else
                {
                    MessageBox.Show("Phục hồi thành công", "", MessageBoxButtons.OK);
                }


                if (haveUndo)
                {
                    Program.ObjectUndo obj = new Program.ObjectUndo(Program.THEM, maSV);
                    st.Push(obj);
                }
                updateUIButtonPhucHoi();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Lỗi ghi sinh viên.\n" + ex.Message, "", MessageBoxButtons.OK);
                return;
            }

            gcSinhVien.Enabled = true;
            btnThem.Enabled    = btnHieuChinh.Enabled = btnXoa.Enabled = btnReload.Enabled = btnThoat.Enabled = true;
            cmbLop.Enabled     = true;

            updateUIcmbKhoa();
            btnGhi.Enabled = false;

            panelDetail.Enabled = false;
        }