示例#1
0
        public bool Add(SinhVien sv, HocPhan hp)
        {
            string        sql = "INSERT INTO SINHVIEN(MaSV, TenSV, GioiTinh, NamSinh, QueQuan, NoiCuTru) VALUES (@MaSV, @TenSV, @GioiTinh, @NamSinh, @QueQuan, @NoiCuTru); INSERT INTO HOCPHAN(MaHocPhan, TenHocPhan, DiemSo, DiemChu, MaSV) VALUES(@MaHocPhan, @TenHocPhan, @DiemSo, @DiemChu, @MaSV);";
            SqlConnection con = dc.getConnect();

            try
            {
                cmd = new SqlCommand(sql, con);
                con.Open();
                cmd.Parameters.Add("@MaSV", SqlDbType.Int).Value            = sv.MaSV;
                cmd.Parameters.Add("@TenSV", SqlDbType.NVarChar).Value      = sv.TenSV;
                cmd.Parameters.Add("@GioiTinh", SqlDbType.NVarChar).Value   = sv.GioiTinh;
                cmd.Parameters.Add("@NamSinh", SqlDbType.NVarChar).Value    = sv.NamSinh;
                cmd.Parameters.Add("@QueQuan", SqlDbType.NVarChar).Value    = sv.QueQuan;
                cmd.Parameters.Add("@NoiCuTru", SqlDbType.NVarChar).Value   = sv.NoiCuTru;
                cmd.Parameters.Add("@MaHocPhan", SqlDbType.Int).Value       = hp.MaHocPhan;
                cmd.Parameters.Add("@TenHocPhan", SqlDbType.NVarChar).Value = hp.TenHocPhan;
                cmd.Parameters.Add("@DiemSo", SqlDbType.NVarChar).Value     = hp.DiemSo;
                cmd.Parameters.Add("@DiemChu", SqlDbType.NVarChar).Value    = hp.DiemChu;
                cmd.ExecuteNonQuery();
                con.Close();
            }
            catch (Exception e)
            {
                return(false);
            }
            return(true);
        }
示例#2
0
        public bool Update(SinhVien sv, HocPhan hp)
        {
            string        sql = "UPDATE SINHVIEN SET TenSV = @TenSV, GioiTinh = @GioiTinh, NamSinh = @NamSinh, QueQuan = @QueQuan, NoiCuTru = @NoiCuTru WHERE MaSV = @MaSV; UPDATE HOCPHAN SET MaHocPhan = @MaHocPhan, TenHocPhan = @TenHocPhan, DiemSo = @DiemSo, DiemChu = @DiemChu WHERE MaSV = @MaSV;";
            SqlConnection con = dc.getConnect();

            try
            {
                cmd = new SqlCommand(sql, con);
                con.Open();
                cmd.Parameters.Add("@MaSV", SqlDbType.Int).Value            = sv.MaSV;
                cmd.Parameters.Add("@TenSV", SqlDbType.NVarChar).Value      = sv.TenSV;
                cmd.Parameters.Add("@GioiTinh", SqlDbType.NVarChar).Value   = sv.GioiTinh;
                cmd.Parameters.Add("@NamSinh", SqlDbType.NVarChar).Value    = sv.NamSinh;
                cmd.Parameters.Add("@QueQuan", SqlDbType.NVarChar).Value    = sv.QueQuan;
                cmd.Parameters.Add("@NoiCuTru", SqlDbType.NVarChar).Value   = sv.NoiCuTru;
                cmd.Parameters.Add("@MaHocPhan", SqlDbType.Int).Value       = hp.MaHocPhan;
                cmd.Parameters.Add("@TenHocPhan", SqlDbType.NVarChar).Value = hp.TenHocPhan;
                cmd.Parameters.Add("@DiemSo", SqlDbType.NVarChar).Value     = hp.DiemSo;
                cmd.Parameters.Add("@DiemChu", SqlDbType.NVarChar).Value    = hp.DiemChu;
                cmd.ExecuteNonQuery();
                con.Close();
            }
            catch (Exception e)
            {
                return(false);
            }
            return(true);
        }
示例#3
0
        private void BtnSua_Click(object sender, EventArgs e)
        {
            SinhVien sv = new SinhVien();
            HocPhan  hp = new HocPhan();

            sv.MaSV       = int.Parse(txtMaSV.Text);
            sv.TenSV      = txtTenSV.Text;
            sv.NamSinh    = comboBoxNamSinh.Text;
            sv.QueQuan    = txtQueQuan.Text;
            sv.NoiCuTru   = txtNoiCuTru.Text;
            hp.MaHocPhan  = int.Parse(txtMaHocPhan.Text);
            hp.TenHocPhan = txtTenHocPhan.Text;
            hp.DiemSo     = txtDiemSo.Text;
            hp.DiemChu    = txtDiemChu.Text;
            if (radioButtonNam.Checked)
            {
                sv.GioiTinh = "Nam";
            }
            else
            {
                sv.GioiTinh = "Nữ";
            }
            if (csql.Update(sv, hp) == true)
            {
                ShowAll();
            }
            else
            {
                MessageBox.Show("Đã có lỗi xảy ra!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }