Example #1
0
        //
        // GET: /Student/

        public ActionResult Index()
        {
            try
            {
                string num = Request.Cookies["studentInfo"]["studentNum"];
                if (string.IsNullOrEmpty(num))
                {
                    return(Content("请登录后重试"));
                }
                int stuid = bLLStudent.Details(c => c.StuNum == num).FirstOrDefault().StuID;
                ViewBag.ClassForm = new SelectList(db.Class, "ClassForm", "ClassName");
                var        s    = bllselectsub.GetAll().Where(c => c.StuID == stuid).ToList();
                List <int> list = new List <int> ();
                foreach (var item in s)
                {
                    list.Add(item.SubID);
                }
                //return View(bllSub.GetAll().Where(c=>list.Contains(c.SubID)).AsEnumerable());
                return(View(bllSub.GetAll().AsEnumerable().OrderByDescending(c => c.SubID)));
            }
            catch
            {
                return(Content("请登录后重试"));
            }
        }
Example #2
0
        public ActionResult StudentLogin(string userNum, string pwd)
        {
            var student = bllStudent.Details(c => c.StuNum == userNum);

            if (student.Count() == 0)
            {
                return(Content("请联系管理员添加相关信息!"));
            }
            if (student.FirstOrDefault().StuPwd != pwd)
            {
                return(Content("密码错误"));
            }
            if (Request.Cookies["studentInfo"] == null)
            {
                Request.Cookies.Remove("studentInfo");
                HttpCookie studentInfoCookies = new HttpCookie("studentInfo");
                studentInfoCookies["studentNum"] = userNum;
                studentInfoCookies["pwd"]        = pwd;
                String studentName = System.Web.HttpUtility.UrlEncode(bllStudent.Details(c => c.StuNum == userNum).FirstOrDefault().StuName, System.Text.Encoding.UTF8);
                studentInfoCookies["studentName"]    = studentName;
                studentInfoCookies["studentPicture"] = bllStudent.Details(c => c.StuNum == userNum).FirstOrDefault().StuPicture;
                Response.Cookies.Add(studentInfoCookies);
                return(Content("ok"));
            }
            else
            {
                Request.Cookies.Remove("studentInfo");
                HttpCookie studentInfoCookies = new HttpCookie("studentInfo");
                studentInfoCookies["studentNum"] = userNum;
                studentInfoCookies["pwd"]        = pwd;
                String studentName = System.Web.HttpUtility.UrlEncode(bllStudent.Details(c => c.StuNum == userNum).FirstOrDefault().StuName, System.Text.Encoding.UTF8);
                studentInfoCookies["studentName"]    = studentName;
                studentInfoCookies["studentPicture"] = bllStudent.Details(c => c.StuNum == userNum).FirstOrDefault().StuPicture;
                Response.Cookies.Add(studentInfoCookies);
                return(Content("ok"));
            }
        }
Example #3
0
        public ActionResult ExportExcel(int subID)
        {
            List <Student> students   = new List <Student>();
            var            studentsid = selectSub.GetAll().Where(c => c.SubID == subID);

            foreach (var item in studentsid)
            {
                students.Add(bLLStudent.Details(c => c.StuID == item.StuID).FirstOrDefault());
            }
            MemoryStream stream    = new MemoryStream();
            var          workbook  = new HSSFWorkbook();
            var          sheet     = workbook.CreateSheet();
            var          headerRow = sheet.CreateRow(0);

            headerRow.CreateCell(0).SetCellValue("ID");
            headerRow.CreateCell(1).SetCellValue("学生姓名");
            headerRow.CreateCell(2).SetCellValue("学生学号");
            headerRow.CreateCell(3).SetCellValue("学生班级");
            for (int i = 0; i < students.Count; i++)
            {
                foreach (var item in students)
                {
                    var newRow = sheet.CreateRow(i + 1);
                    newRow.CreateCell(0).SetCellValue(item.StuID);
                    newRow.CreateCell(1).SetCellValue(item.StuName);
                    newRow.CreateCell(2).SetCellValue(item.StuNum);
                    newRow.CreateCell(3).SetCellValue(bllClass.Details(c => c.ClassForm == item.ClassForm).FirstOrDefault().ClassNum);
                }
            }

            workbook.Write(stream);
            stream.Flush();
            stream.Position = 0;
            sheet           = null;
            headerRow       = null;
            workbook        = null;
            return(File(stream, "application/vnd.ms-excel", "选择" + bllSub.Details(c => c.SubID == subID).FirstOrDefault().SubName + "此课程的学生信息.xls"));
        }