public bool themHocSinh(HocSinh h)
        {
            try
            {
                conn.Open();

                SQL = "insert into HOCSINH values('" + h.Mahs + "', N'" + h.Hohs + "', N'" + h.Tenhs + "', '" + h.Ns +
                      "', N'" + h.Gt + "', N'" + h.Dc + "', '" + h.Sdt + "', N'" + h.htBo + "', N'" + h.nnBo + "', N'" + h.htMe +
                      "', N'" + h.nnMe + "')";

                SqlCommand cmd = new SqlCommand(SQL, conn);
                int        kq  = (int)cmd.ExecuteNonQuery();
                if (kq > 0)
                {
                    return(true);
                }
            }
            catch
            {
            }
            finally
            {
                conn.Close();
            }
            return(false);
        }
Exemplo n.º 2
0
 private void btnThemHS_Click(object sender, EventArgs e)
 {
     if (txtMaHS.Text != "")
     {
         if (txtHoHS.Text != "" && txtTenHS.Text != "" &&
             txtHTBo.Text != "" && txtHTMe.Text != "" && txtDC.Text != "" && txtSDT.Text != "")
         {
             HocSinh hs = new HocSinh(txtMaHS.Text, txtHoHS.Text, txtTenHS.Text, dtpNS.Value,
                                      cbbGT.Text, txtDC.Text, txtSDT.Text, txtHTBo.Text, txtNNBo.Text, txtHTMe.Text, txtNNMe.Text);
             if (chs.suaHocSinh(hs))
             {
                 MessageBox.Show("sửa thành công");
                 frmMain f = new frmMain();
                 this.Hide();
                 f.ShowDialog();
                 f.Close();
             }
             else
             {
                 MessageBox.Show("sửa không thành công");
             }
         }
         else
         {
             MessageBox.Show("xin vui lòng nhập đủ thông tin");
         }
     }
     else
     {
         MessageBox.Show("xin vui lòng nhập mã học sinh để sủa thông tin");
     }
 }
        public List <HocSinh> GetDSHocSinhChuaXepLop()
        {
            OpenConnection();
            SqlCommand com = new SqlCommand();

            com.CommandType = CommandType.Text;
            com.CommandText = " select * from HOCSINH "
                              + "where MaHocSinh not in (select MaHocSinh from QUATRINHHOCTAP)";
            com.Connection = conn;

            SqlDataReader  reader        = com.ExecuteReader();
            List <HocSinh> listdshocsinh = new List <HocSinh>();
            string         namsinh       = null;

            while (reader.Read())
            {
                string ma       = reader.GetInt32(0).ToString();
                String ten      = reader.GetString(1);
                string gioitinh = reader.GetString(2);
                namsinh = reader.GetDateTime(3).ToString();
                string diachi    = reader.GetString(4);
                string email     = reader.GetString(5);
                string trangThai = reader.GetString(6);


                HocSinh dshocsinh = new HocSinh(ma, ten, gioitinh, diachi, email, namsinh, trangThai);
                listdshocsinh.Add(dshocsinh);
            }

            reader.Close();
            CloseConnection();
            return(listdshocsinh);
        }
Exemplo n.º 4
0
        private void btnThemHS_Click(object sender, EventArgs e)
        {
            int      maHS = 1; int lopHienTai;
            DateTime ngaySinh;
            string   hoTen, gioiTinh, diaChi, sdt, email, tenLop;
            bool     tinhTrang;

            hoTen      = txtHoTen.Text.Trim();
            gioiTinh   = cbGT.Text.Trim();
            sdt        = txtSDT.Text.Trim();
            ngaySinh   = txtNS.Value;
            diaChi     = txtDiaChi.Text.Trim();
            email      = txtEmail.Text.Trim();
            tinhTrang  = int.Parse(cbTinhTrang.SelectedValue.ToString()) != (int)TinhTrang.DangHoc;
            lopHienTai = int.Parse(cbLop.SelectedValue.ToString());
            tenLop     = cbLop.SelectedValue.ToString();
            HocSinh hs = new HocSinh(maHS, hoTen, gioiTinh, ngaySinh, diaChi, sdt, email, tinhTrang, lopHienTai, tenLop);

            try
            {
                int i = new HocSinhBUS().ThemHocSinh(hs);
                if (i > -1)
                {
                    MessageBox.Show("Thêm thành công");
                    Close();
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Nhập sai thông tin");
                return;
            }
        }
Exemplo n.º 5
0
        public void insertHocSinh(HocSinh hs)
        {
            string          query    = string.Format("INSERT dbo.HOCSINH( HOTEN ,GIOITINH , NGAYSINH , NOISINH ,DANTOC ,TONGIAO) VALUES( '{0}' , '{1}' , '{2}' ,'{3}' , '{4}' ,  '{5}')", hs.HoTen, hs.GioiTinh, hs.NgaySinh.ToShortDateString(), hs.NoiSinh, hs.DanToc, hs.TonGiao);
            DatabaseConnect dtConnet = new DatabaseConnect();

            dtConnet.ExecuteNonQuery(query);
        }
        private void btnEdit_Click_1(object sender, EventArgs e)
        {
            using (frmAddEditStudent fmAE = new frmAddEditStudent())
            {
                int selectIndex = dgvHocSinh.CurrentRow.Index;

                if (selectIndex < 0)
                {
                    MessageBox.Show("Chọn bản ghi cần sửa!");
                }
                else
                {
                    string id = dgvHocSinh[0, selectIndex].Value.ToString();
                    fmAE.Id = id;
                    if (fmAE.ShowDialog() == DialogResult.OK)
                    {
                        HocSinh hs = fmAE.getHocSinh();
                        if (bsHs.UpdateHocSinh(hs))
                        {
                            MessageBox.Show("Sửa thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else
                        {
                            MessageBox.Show("Sửa thất bại", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else
                    {
                        return;
                    }
                }
            }
        }
        public async Task <ActionResult <HocSinh> > PostHocSinh(HocSinh hocSinh)
        {
            _context.HocSinhs.Add(hocSinh);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetHocSinh", new { id = hocSinh.id }, hocSinh));
        }
Exemplo n.º 8
0
 public ErrType SuaTTHS(HocSinh hs)
 {
     using (var db = new BusinessContext())
     {
         HocSinh hocsinh = db.HocSinhs.Find(hs.HocSinhID);
         if (hocsinh != null)
         {
             hocsinh.HoTen    = InputHelper.NhapStr("nhap ho ten: ", "err", 0, 20);
             hocsinh.QueQuan  = InputHelper.NhapStr("nhap que quan: ", "err");
             hocsinh.NgaySinh = InputHelper.NhapDate("nhap ngay sinh: ", "err", new DateTime(2001 / 1 / 1), new DateTime(2013 / 12 / 31));
             Boolean ok = true;
             do
             {
                 hocsinh.LopID = InputHelper.NhapInt("Nhap ma lop: ", "err");
                 Lop l = db.Lops.Find(hocsinh.LopID);
                 if (l == null)
                 {
                     Console.WriteLine("lop khong ton tai");
                     ok = false;
                 }
                 else
                 {
                     ok = true;
                 }
             }while (!ok);
             db.SaveChanges();
             return(ErrType.succes);
         }
         else
         {
             return(ErrType.emptylist);
         }
     }
 }
Exemplo n.º 9
0
        public bool Insert(HocSinh hocSinh)
        {
            SqlConnection connection = new SqlConnection(connectionString);

            try
            {
                if (connection.State == ConnectionState.Closed)
                {
                    connection.Open();
                }
                string     sql     = "INSERT INTO HocSinh(MaHS, TenHS, DiaChi) VALUES(@maHS, @tenHS, @diaChi)";
                SqlCommand command = new SqlCommand(sql, connection);
                command.Parameters.AddWithValue("@maHS", hocSinh.MaHS);
                command.Parameters.AddWithValue("@tenHS", hocSinh.TenHS);
                command.Parameters.AddWithValue("@diaChi", hocSinh.DiaChi);
                if (command.ExecuteNonQuery() > 0)
                {
                    return(true);
                }
                connection.Close();
            }
            catch (Exception e)
            {
                return(false);
            }
            return(false);
        }
Exemplo n.º 10
0
        public HocSinh getHocSinh(DataRow row)
        {
            HocSinh hs = new HocSinh();

            hs.Ma  = row["ma"].ToString().Trim();
            hs.Ten = row["ten"].ToString().Trim();
            int gt = 1;

            if (int.TryParse(row["gioitinh"].ToString().Trim(), out gt))
            {
                hs.GioiTinh = gt;
            }
            DateTime ns = new DateTime();

            if (DateTime.TryParse(row["ngaysinh"].ToString().Trim(), out ns))
            {
                hs.NgaySinh = ns;
            }
            hs.DanToc    = row["dantoc"].ToString().Trim();
            hs.DiaChi    = row["diachi"].ToString().Trim();
            hs.LopMa     = row["Lopma"].ToString().Trim();
            hs.DienThoai = row["Sodienthoai"].ToString().Trim();
            hs.Email     = row["email"].ToString().Trim();
            return(hs);
        }
Exemplo n.º 11
0
 public ErrType ChuyenLopChoHS(HocSinh hs)
 {
     using (var db = new BusinessContext())
     {
         HocSinh hocsinh = db.HocSinhs.Find(hs.HocSinhID);
         if (hocsinh != null)
         {
             Boolean ok = true;
             do
             {
                 hocsinh.LopID = InputHelper.NhapInt("Nhap ma lop: ", "err");
                 Lop l = db.Lops.Find(hocsinh.LopID);
                 if (l == null)
                 {
                     Console.WriteLine("lop khong ton tai");
                     ok = false;
                 }
                 else
                 {
                     ok = true;
                 }
             }while (!ok);
             db.SaveChanges();
             return(ErrType.succes);
         }
         else
         {
             return(ErrType.emptylist);
         }
     }
 }
Exemplo n.º 12
0
        public HocSinh[] getListHocSinh()
        {
            //DataTable table = da.Query("select hs.Ma, hs.Ten, hs.GioiTinh, hs.NgaySinh , hs.Email, hs.DanToc, "
            //    + " hs.Sodienthoai, lhp.ma as [Lopma], hs.Diachi from Hocsinh hs inner join Lophocphan lhp on hs.Lopma = lhp.ma");
            //DataTable table = da.Query("select hs.Ma, hs.Ten, hs.GioiTinh, hs.NgaySinh , hs.Email, hs.DanToc, hs.Lopma ,"
            //   + " hs.Sodienthoai, hs.Diachi from Hocsinh hs");
            //<<<<<<< HEAD

            DataTable table = da.Query("select hs.Ma, hs.Ten, hs.GioiTinh, hs.NgaySinh, hs.Sodienthoai , hs.Email,hs.DanToc, "
                                       + "hs.DiaChi, hs.Sodienthoai, lhp.ma as [Lopma] from Hocsinh hs inner join Lophocphan lhp on hs.Lopma = lhp.ma where hs.Trangthai=1");
            //=======
            //            DataTable table = da.Query("select hs.Ma, hs.Ten, hs.GioiTinh, hs.NgaySinh, hs.Sodienthoai , hs.Email,hs.DanToc,hs.DiaChi, hs.Sodienthoai, lhp.ma as [Lopma] from Hocsinh hs inner join Lophocphan lhp on hs.Lopma = lhp.ma where hs.Trangthai=1");
            //>>>>>>> 62440c2b927b403c2b74c7968b4d4de2fddb1bbb

            int n = table.Rows.Count;
            int i;

            if (n == 0)
            {
                return(null);
            }
            HocSinh[] list = new HocSinh[n];
            for (i = 0; i < n; i++)
            {
                list[i] = getHocSinh(table.Rows[i]);
            }
            return(list);
        }
Exemplo n.º 13
0
        private void button1_Click(object sender, EventArgs e)
        {
            HocSinh gv = new HocSinh();

            gv.MaHS     = textBox1.Text;
            gv.HoTen    = textBox2.Text;
            gv.DiaChi   = textBox3.Text;
            gv.TenLop   = comboBox2.Text;
            gv.GT       = comboBox1.Text;
            gv.NgaySinh = dateTimePicker1.Value;
            bool add = new HocSinhDAO().Insert(gv);

            if (!add)
            {
                MessageBox.Show("Mã HS đã tồn tại", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                MessageBox.Show("Đã thêm học sinh", "Thành công", MessageBoxButtons.OK, MessageBoxIcon.Information);
                dtg_HocSinh.DataSource = new HocSinhDAO().ListAll();
                textBox1.Text          = "";
                textBox2.Text          = "";
                textBox3.Text          = "";
            }
        }
Exemplo n.º 14
0
 public bool Them(HocSinh hs)
 {
     try
     {
         string query = @"INSERT INTO dbo.HocSinh
             ( MaHS ,
               Ten ,
               DiaChi ,
               GioiTinh ,
               NgaySinh ,
               TenNguoiThan ,
               MaLH
             )
     VALUES  ( '" + hs.MaHS + "' ,N'" + hs.Ten + "' ,N'" + hs.DiaChi + "' ,N'" + hs.GioiTinh + "' ,'" + hs.NgaySinh + "' ,N'" + hs.TenNguoiThan + "' ,'" + hs.MaLH + "')";
         OpenConection();
         ExecuteQueries(query);
         CloseConnection();
         return(true);
     }
     catch (Exception ex)
     {
         SetEx(ex);
         return(false);
     }
 }
Exemplo n.º 15
0
        public ActionResult HocSinh()
        {
            string        connectString = ConfigurationManager.ConnectionStrings["QLSV"].ConnectionString;
            SqlConnection conn          = new SqlConnection(connectString);
            string        query         = "SELECT sID,sName,C.cName FROM STUDENT JOIN CLASS AS C ON STUDENT.cID = C.CID";

            if (conn.State == System.Data.ConnectionState.Closed)
            {
                conn.Open();
            }
            SqlCommand cmd = new SqlCommand(query, conn);

            cmd.CommandType = System.Data.CommandType.Text;
            SqlDataReader  dr      = cmd.ExecuteReader();
            List <HocSinh> lstData = new List <HocSinh>();

            while (dr.Read())
            {
                HocSinh hs = new HocSinh();
                hs.sID   = Convert.ToInt32(dr["sID"].ToString());
                hs.sName = dr["sName"].ToString();
                hs.cName = dr["cName"].ToString();
                lstData.Add(hs);
            }
            return(View(lstData));
        }
Exemplo n.º 16
0
        public bool Update(HocSinh hocSinh)
        {
            SqlConnection connection = new SqlConnection(connectionString);

            try
            {
                if (connection.State == ConnectionState.Closed)
                {
                    connection.Open();
                }
                string     sql     = "UPDATE HocSinh SET TenHS = @tenHS, DiaChi = @diaChi WHERE MaHS = @maHS";
                SqlCommand command = new SqlCommand(sql, connection);
                command.Parameters.AddWithValue("@maHS", hocSinh.MaHS);
                command.Parameters.AddWithValue("@tenHS", hocSinh.TenHS);
                command.Parameters.AddWithValue("@diaChi", hocSinh.DiaChi);
                if (command.ExecuteNonQuery() > 0)
                {
                    return(true);
                }
                connection.Close();
            }
            catch (Exception e)
            {
                return(false);
            }
            return(false);
        }
        private void btnEdit_Click(object sender, EventArgs e)
        {
            using (frmAddEditStudent fmAE = new frmAddEditStudent())
            {
                int    selectIndex = dgvHocSinh.SelectedRows[0].Index;
                string id          = dgvHocSinh[0, selectIndex].Value.ToString();

                fmAE.Id = id;
                if (fmAE.ShowDialog() == DialogResult.OK)
                {
                    HocSinh gv = fmAE.getHocSinh();
                    if (bsHs.UpdateHocSinh(gv))
                    {
                        MessageBox.Show("Sửa thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("Sửa thất bại", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    return;
                }
            }
        }
Exemplo n.º 18
0
        public bool Delete(HocSinh hocSinh)
        {
            SqlConnection connection = new SqlConnection(connectionString);

            try
            {
                if (connection.State == ConnectionState.Closed)
                {
                    connection.Open();
                }
                string     sql     = "DELETE FROM HocSinh  WHERE MaHS = @maHS";
                SqlCommand command = new SqlCommand(sql, connection);
                command.Parameters.AddWithValue("@maHS", hocSinh.MaHS);
                if (command.ExecuteNonQuery() > 0)
                {
                    return(true);
                }
                connection.Close();
            }
            catch (Exception e)
            {
                return(false);
            }
            return(false);
        }
Exemplo n.º 19
0
        public async Task <IActionResult> PutHocSinh(int id, HocSinh hocSinh)
        {
            if (id != hocSinh.id)
            {
                return(BadRequest());
            }

            _context.Entry(hocSinh).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!HocSinhExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public IHttpActionResult PutHocSinh(int id, HocSinh hocSinh)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != hocSinh.MaHocSinh)
            {
                return(BadRequest());
            }

            db.Entry(hocSinh).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!HocSinhExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 21
0
        private void TrangChu_Load(object sender, EventArgs e)
        {
            FormBorderStyle = FormBorderStyle.None;
            WindowState     = FormWindowState.Maximized;

            hs = this.Tag as HocSinh;
            gv = this.Tag as GiaoVien;
            if (gv != null && gv.ten == "admin")
            {
                lbChucVu.Text             = "Admin";
                lbTenNguoiDung.Text       = "Admin";
                btnThongTinCaNhan.Visible = false;
            }
            else if (hs != null)
            {
                HocSinh hocsinh = db.HocSinh.Where(m => m.maHS == hs.maHS).SingleOrDefault();
                lbChucVu.Text       = "Học sinh";
                lbTenNguoiDung.Text = hocsinh.ten.ToString();
            }
            else
            {
                GiaoVien giaovine = db.GiaoVien.Where(m => m.maGV == gv.maGV).SingleOrDefault();
                lbChucVu.Text       = "Giáo viên";
                lbTenNguoiDung.Text = giaovine.ten.ToString();
            }
        }
Exemplo n.º 22
0
        private void btnDangnhap_Click(object sender, EventArgs e)
        {
            GiaoVien gv = db.GiaoVien.Where(m => m.taiKhoan == txtname.Text && m.matKhau == txtpasswold.Text).SingleOrDefault();
            HocSinh  hs = db.HocSinh.Where(m => m.taiKhoan == txtname.Text && m.matKhau == txtpasswold.Text).SingleOrDefault();

            if (gv == null && hs == null)
            {
                MessageBox.Show("Tài khoản hoặc mật khẩu không chính xác!", "Đăng nhập không thành công", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else
            {
                if (gv != null)
                {
                    QuanLyAdmin ql = new QuanLyAdmin();
                    this.Hide();
                    ql.Tag = gv;
                    ql.ShowDialog();
                    this.Close();
                }
                else
                {
                    QuanLyAdmin ql = new QuanLyAdmin();
                    this.Hide();
                    ql.Tag = hs;
                    ql.ShowDialog();
                    this.Close();
                }
            }
        }
 private void btnThemHS_Click(object sender, EventArgs e)
 {
     if (txtMaHS.Text != "" && txtHoHS.Text != "" && txtTenHS.Text != "" &&
         txtHTBo.Text != "" && txtHTMe.Text != "" && txtDC.Text != "" && txtSDT.Text != "")
     {
         HocSinh hs = new HocSinh(txtMaHS.Text, txtHoHS.Text, txtTenHS.Text, dtpNS.Value,
                                  cbbGT.Text, txtDC.Text, txtSDT.Text, txtHTBo.Text, txtNNBo.Text, txtHTMe.Text, txtNNMe.Text);
         if (chs.themHocSinh(hs))
         {
             MessageBox.Show("thêm thành công! Vui lòng lựa chọn lớp học cho học sinh vừa thêm");
             frmThemHSDSLop f = new frmThemHSDSLop();
             this.Hide();
             //f.ShowDialog();
             //f.Close();
             f.Show();
         }
         else
         {
             MessageBox.Show("thêm không thành công");
         }
     }
     else
     {
         MessageBox.Show("xin vui lòng nhập đủ thông tin");
     }
 }
Exemplo n.º 24
0
        public static List <HocSinh> layDSHocSinh()
        {
            List <HocSinh> dsHS = new List <HocSinh>();
            DataTable      dtHS = DataProvider.TruyVan_LayDuLieu("SELECT * FROM HocSinh");

            foreach (DataRow r in dtHS.Rows)
            {
                HocSinh hs = new HocSinh
                {
                    MaHS   = r["MaHS"].ToString(),
                    TenHS  = r["TenHS"].ToString(),
                    DiaChi = r["DiaChi"].ToString(),
                    MaLop  = r["MaLop"].ToString()
                };
                if (r["NgaySinh"].ToString() != "")
                {
                    hs.NgaySinh = DateTime.Parse(r["NgaySinh"].ToString());
                }
                if (r["DTB"].ToString() != "")
                {
                    hs.DTB = double.Parse(r["DTB"].ToString());
                }
                dsHS.Add(hs);
            }
            return(dsHS);
        }
Exemplo n.º 25
0
        public void SuaHocSinh(HocSinh hs)
        {
            string          query    = string.Format("UPDATE dbo.HOCSINH SET HOTEN ='{0}' ,GIOITINH='{1}',NGAYSINH='{2}',NOISINH='{3}',DANTOC='{4}',TONGIAO='{5}' WHERE MAHOCSINH= {6}", hs.HoTen, hs.GioiTinh, hs.NgaySinh.ToShortDateString(), hs.NoiSinh, hs.DanToc, hs.TonGiao, hs.MaHocSinh);
            DatabaseConnect dtConnet = new DatabaseConnect();

            dtConnet.ExecuteNonQuery(query);
        }
Exemplo n.º 26
0
        public static List <HocSinh> timTheoTenHS(string ten)
        {
            List <HocSinh> dsHS = new List <HocSinh>();

            SqlParameter[] pa = new SqlParameter[1];
            pa[0] = new SqlParameter("Ten", ten);
            DataTable dtHS = DataProvider.SelectData("SELECT * FROM HocSinh WHERE TenHS LIKE N'%' + @Ten + '%'", CommandType.Text, pa);

            foreach (DataRow r in dtHS.Rows)
            {
                HocSinh hs = new HocSinh
                {
                    MaHS   = r["MaHS"].ToString(),
                    TenHS  = r["TenHS"].ToString(),
                    DiaChi = r["DiaChi"].ToString(),
                    MaLop  = r["MaLop"].ToString()
                };
                if (r["NgaySinh"].ToString() != "")
                {
                    hs.NgaySinh = DateTime.Parse(r["NgaySinh"].ToString());
                }
                if (r["DTB"].ToString() != "")
                {
                    hs.DTB = double.Parse(r["DTB"].ToString());
                }
                dsHS.Add(hs);
            }
            return(dsHS);
        }
        public HocSinh GetHocSinh(string mahocsinh)
        {
            OpenConnection();
            SqlCommand com = new SqlCommand();

            com.CommandType = CommandType.Text;
            com.CommandText = "Select * from HOCSINH where mahocsinh=@ma";
            com.Parameters.Add("@ma", SqlDbType.Int).Value = Int32.Parse(mahocsinh);
            com.Connection = conn;

            SqlDataReader  reader        = com.ExecuteReader();
            List <HocSinh> listdshocsinh = new List <HocSinh>();
            HocSinh        dshocsinh     = null;

            if (reader.Read())
            {
                string ma        = reader.GetInt32(0) + "";
                String ten       = reader.GetString(1);
                string gioitinh  = reader.GetString(2);
                string namsinh   = reader.GetDateTime(3).ToString();
                string diachi    = reader.GetString(4);
                string email     = reader.GetString(5);
                string trangThai = reader.GetString(6);


                dshocsinh = new HocSinh(ma, ten, gioitinh, diachi, email, namsinh, trangThai);
                listdshocsinh.Add(dshocsinh);
            }

            reader.Close();
            CloseConnection();

            return(dshocsinh);
        }
Exemplo n.º 28
0
        static void Main(string[] args)
        {
            int spt, i, tam = 0;

            HocSinh[] hs;
            do
            {
                Console.Write("Nhap so luong phan tu cua mang:  ");
                spt = int.Parse(Console.ReadLine());
                if (spt < 0 || spt > 10)
                {
                    Console.WriteLine("so luong phan tu cua mang khong hop le xin kiem tra lai !");
                }
            } while (spt < 0 || spt > 10);
            hs = new HocSinh[spt];

            //			Nhap hoc sinh
            for (i = 0; i < hs.Length; i++)
            {
                hs[i] = Nhap();
            }
            //			Xuat danh sach hoc sinh
            for (i = 0; i < hs.Length; i++)
            {
                Xuat(hs[i]);
            }
            // danh sach gioi toan
            for (i = 0; i < hs.Length; i++)
            {
                dshctoan(hs[i]);
            }
            Console.ReadKey();
        }
        public List <HocSinh> GetDSHocSinhTheoLop(string maLop)
        {
            OpenConnection();
            SqlCommand com = new SqlCommand();

            com.CommandType = CommandType.Text;
            com.CommandText = "select * from hocsinh,QUATRINHHOCTAP where HOCSINH.MaHocSinh=QUATRINHHOCTAP.MaHocSinh and malop=@ma";
            com.Parameters.Add("@ma", SqlDbType.VarChar).Value = maLop;
            com.Connection = conn;

            SqlDataReader  reader        = com.ExecuteReader();
            List <HocSinh> listdshocsinh = new List <HocSinh>();
            string         namsinh       = null;

            while (reader.Read())
            {
                string ma       = reader.GetInt32(0).ToString();
                String ten      = reader.GetString(1);
                string gioitinh = reader.GetString(2);
                namsinh = reader.GetDateTime(3).ToString();
                string diachi    = reader.GetString(4);
                string email     = reader.GetString(5);
                string trangThai = reader.GetString(6);


                HocSinh dshocsinh = new HocSinh(ma, ten, gioitinh, diachi, email, namsinh, trangThai);
                listdshocsinh.Add(dshocsinh);
            }

            reader.Close();
            CloseConnection();
            return(listdshocsinh);
        }
Exemplo n.º 30
0
        public static bool suaHocSinh(HocSinh hs)
        {
            //kiểm tra ràng buộc tự nhiên
            //RBTN1: tên phải có
            if (hs.TenHS == "")
            {
                return(false);
            }
            //kiểm tra ràng buộc nghiệp vụ
            //RBNV1 : tuổi tối thiểu 15
            int tuoi = DateTime.Now.Year - hs.NgaySinh.Year;

            if (tuoi < 15)
            {
                return(false);
            }
            //thực hiện thêm
            try
            {
                HocSinhDAO.suaHocSinh(hs);
                return(true);
            }
            catch
            {
                return(false);
            }
        }