Esempio n. 1
0
        //public PhuHuynh getParentByIdStudent(int id)
        //{
        //    return _context.PhuHuynhs.;
        //}

        //public List<int> InsertList(PhuHuynh[] entity)
        //{
        //    List<int> list = new List<int>();

        //    for(int i = 0; i < 2; i++)
        //    {
        //        _context.PhuHuynhs.Add(entity[i]);
        //        _context.SaveChanges();

        //        list = list.Add(entity[i].MaPhuHuynh);
        //    }
        //    return list;
        //}

        public bool Update(PhuHuynh entity)
        {
            try {
                var _entity = _context.PhuHuynhs.Find(entity.MaPhuHuynh);
                _entity.TenPhuHuynh = entity.TenPhuHuynh;
                _entity.SDT         = entity.SDT;
                _entity.GioiTinh    = entity.GioiTinh;
                _entity.DiaChi      = entity.DiaChi;
                _entity.Email       = entity.Email;
                _context.SaveChanges();

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Esempio n. 2
0
        public ActionResult CreateDetails(HocVienDetails hocVienDetails, HttpPostedFileBase hinhAnhDetail)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    string path = "";
                    if (hinhAnhDetail != null && hinhAnhDetail.ContentLength > 0)
                    {
                        string extension = Path.GetExtension(hinhAnhDetail.FileName);
                        if (extension.Equals(".jpg") || extension.Equals(".png") || extension.Equals(".jpeg"))
                        {
                            path = Path.Combine(Server.MapPath("~/Img/HocVien/"), hinhAnhDetail.FileName);
                            hinhAnhDetail.SaveAs(path);
                        }

                        var _daoHocVien  = new HocVienDao();
                        var _daoPhuHuynh = new PhuHuynhDao();

                        var hocVien = new HocVien();

                        hocVien.TenHocVien = hocVienDetails.HocVien.TenHocVien;
                        hocVien.TaiKhoan   = hocVienDetails.HocVien.TaiKhoan;
                        hocVien.MatKhau    = hocVienDetails.HocVien.MatKhau;
                        hocVien.HinhAnh    = hinhAnhDetail.FileName;
                        hocVien.GioiTinh   = hocVienDetails.HocVien.GioiTinh;
                        hocVien.SDT        = hocVienDetails.HocVien.SDT;
                        hocVien.Email      = hocVienDetails.HocVien.Email;
                        hocVien.DiaChi     = hocVienDetails.HocVien.DiaChi;
                        hocVien.NgaySinh   = hocVienDetails.HocVien.NgaySinh;
                        hocVien.GhiChu     = hocVienDetails.HocVien.GhiChu;
                        hocVien.TrangThai  = hocVienDetails.HocVien.TrangThai;
                        hocVien.Nguon      = hocVienDetails.HocVien.Nguon;

                        // Thêm học viên
                        int _maHocVien = _daoHocVien.Insert(hocVien);

                        for (int i = 0; i < 2; i++)
                        {
                            var _phuHuynh = new PhuHuynh();

                            _phuHuynh.TenPhuHuynh = hocVienDetails.LstPhuHuynh[i].TenPhuHuynh;

                            _phuHuynh.TenPhuHuynh = hocVienDetails.LstPhuHuynh[i].TenPhuHuynh;
                            _phuHuynh.SDT         = hocVienDetails.LstPhuHuynh[i].SDT;
                            _phuHuynh.GioiTinh    = hocVienDetails.LstPhuHuynh[i].GioiTinh;
                            _phuHuynh.DiaChi      = hocVienDetails.LstPhuHuynh[i].DiaChi;
                            _phuHuynh.Email       = hocVienDetails.LstPhuHuynh[i].Email;
                            _phuHuynh.MaHocVien   = _maHocVien;

                            int _maPhuHuynh = _daoPhuHuynh.Insert(_phuHuynh);
                        }

                        if (_maHocVien > 0 && _maHocVien > 0)
                        {
                            if (hocVien.Email == null)
                            {
                                return(RedirectToAction("Index", "HocVien"));
                            }
                            else
                            {
                                string content = System.IO.File.ReadAllText(Server.MapPath("~/Assets/Email/HocVien.html"));

                                content = content.Replace("{{TenHV}}", hocVien.TenHocVien.ToString());
                                content = content.Replace("{{NgaySinh}}", hocVien.NgaySinh.ToString());
                                content = content.Replace("{{SDT}}", hocVien.SDT.ToString());
                                content = content.Replace("{{DiaChi}}", hocVien.DiaChi.ToString());
                                content = content.Replace("{{NgayDangKy}}", hocVien.NgayDangKy.ToString());

                                new MailHelper().SendMail(hocVien.Email, "Chào mừng em đã tham gia vào đại gia đình Đan Thanh!", content);
                                SetAlert("Thêm thành công", 1);
                                return(RedirectToAction("Index", "HocVien"));
                            }
                        }
                        else
                        {
                            ModelState.AddModelError("", "Có lỗi khi thêm chi tiết học viên");
                        }
                    }
                }
                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Esempio n. 3
0
 public int Insert(PhuHuynh entity)
 {
     _context.PhuHuynhs.Add(entity);
     _context.SaveChanges();
     return(entity.MaPhuHuynh);
 }
Esempio n. 4
0
        public IActionResult StudentView(Users user, HocSinh hs, PhuHuynh[] phList)
        {
            if (HttpContext.Session.GetString("SessionUser") == null)
            {
                return(RedirectToAction("ValidateForm", "Validation"));
            }
            SqlDataReader dr  = null;
            SqlConnection con = new SqlConnection();

            con.ConnectionString = configuration.GetConnectionString("QLHVContext");
            userTemp             = user;

            //Lấy dữ liệu HocSinh
            con.Open();
            SqlCommand cmd = new SqlCommand();

            cmd.Connection = con;

            string getLop = "";

            cmd.CommandText = "Select *from HocSinh where IDHS = '" + user.ID + "'";
            dr = cmd.ExecuteReader();
            if (dr.Read())
            {
                hs.IDHS     = Convert.ToInt32(dr["ID"]);
                hs.HoTen    = dr["HoTen"].ToString();
                hs.TenLop   = dr["TenLop"].ToString();
                hs.DCHT     = dr["DCHT"].ToString();
                hs.DCTT     = dr["DCTT"].ToString();
                hs.DanToc   = dr["DanToc"].ToString();
                hs.CheDo    = dr["CheDo"].ToString();
                hs.SDT      = dr["SDT"].ToString();
                hs.GioiTinh = dr["GioiTinh"].ToString();
                hs.NgaySinh = Convert.ToDateTime(dr["NgaySinh"]);
            }
            hsTemp = hs;
            con.Close();

            con.Open();
            cmd            = new SqlCommand();
            cmd.Connection = con;

            cmd.CommandText = "Select [IDL] from Lop where ID = '" + hs.TenLop + "'";
            dr = cmd.ExecuteReader();
            if (dr.Read())
            {
                getLop = dr["IDL"].ToString();
            }
            con.Close();
            //Lấy dữ liệu QuanHe, Phu Huynh
            phList = new PhuHuynh[5];
            con.Open();
            cmd.Connection = con;
            int count = 0;

            cmd.CommandText = "Select [TenQuanHe],[SDT],[NgheNghiep],[HoTen] " +
                              "from QuanHe Inner Join PhuHuynh on PhuHuynh.ID = QuanHe.IDPH " +
                              "where IDHS = '" + hs.IDHS + "'";
            dr = cmd.ExecuteReader();
            while (dr.Read() || count < 3)
            {
                PhuHuynh ph = new PhuHuynh();
                try
                {
                    if (dr["TenQuanHe"].ToString() == "Mẹ")
                    {
                        ph.SDT        = dr["SDT"].ToString();
                        ph.NgheNghiep = dr["NgheNghiep"].ToString();
                        ph.HoTen      = dr["HoTen"].ToString();
                    }

                    else if (dr["TenQuanHe"].ToString() == "Cha")
                    {
                        ph.SDT        = dr["SDT"].ToString();
                        ph.NgheNghiep = dr["NgheNghiep"].ToString();
                        ph.HoTen      = dr["HoTen"].ToString();
                    }

                    else if (dr["TenQuanHe"].ToString() == "Giám Hộ")
                    {
                        ph.SDT        = dr["SDT"].ToString();
                        ph.NgheNghiep = dr["NgheNghiep"].ToString();
                        ph.HoTen      = dr["HoTen"].ToString();
                    }

                    else
                    {
                        ph.SDT        = "Không có";
                        ph.HoTen      = "Không có";
                        ph.NgheNghiep = "Không có";
                    }
                }
                catch (Exception e)
                {
                    ph.SDT        = "Không có";
                    ph.HoTen      = "Không có";
                    ph.NgheNghiep = "Không có";
                    phList[count] = ph;
                    count++;
                }

                phList[count] = ph;
                count++;
            }

            con.Close();

            //Dựa vào dữ liệu quan hệ lấy ra thông tin phụ huynh

            ViewData["Class"]   = getLop;
            ViewData["Student"] = hs;
            ViewData["Parent"]  = phList;
            return(View());
        }