Exemplo n.º 1
0
        public ActionResult EditSelfInfo(string sex, string birth, string country, string province, string city, string area, string marry, string household, string tel, string qq, string mail, string policy, HttpPostedFileBase photo, string name, string pwd)
        {
            string id       = Session["account"].ToString();
            string school   = Session["school"].ToString();
            var    self     = (from s in db.教师表 select s).SingleOrDefault(s => s.教师工号.Equals(id) && s.所在学校代码.Equals(school));
            var    pwdSelf  = (from s in db.密码表 select s).SingleOrDefault(s => s.账号.Equals(id));
            string savePath = Server.MapPath("~/images/TeacherPicture/");

            if (!Directory.Exists(savePath))
            {
                Directory.CreateDirectory(savePath);
            }
            photo = Request.Files["photo"];

            try
            {
                if (!photo.FileName.Equals(string.Empty))
                {
                    string fileType = photo.FileName.Split(new char[1] {
                        '.'
                    }, StringSplitOptions.RemoveEmptyEntries)[1];
                    string fileName = name + id + "." + fileType;
                    photo.SaveAs(savePath + fileName);
                    self.证件照路径 = fileName;
                }
                if (!pwd.Equals(string.Empty))
                {
                    if (pwd.Equals("123456"))
                    {
                        pwdSelf.密码 = pwd;
                    }
                    else
                    {
                        pwdSelf.密码 = MD5Helper.getStringMd5Hash(pwd);
                    }
                }
                if (!sex.Equals(string.Empty))
                {
                    self.性别代码 = sex;
                }
                self.出生日期 = Convert.ToDateTime(birth);
                if (!country.Equals(string.Empty))
                {
                    self.国家代码 = country;
                }
                if (!province.Equals(string.Empty))
                {
                    self.省份代码 = province;
                }
                if (!city.Equals(string.Empty))
                {
                    self.城市代码 = city;
                }
                if (!area.Equals(string.Empty))
                {
                    self.区县代码 = area;
                }
                if (!marry.Equals(string.Empty))
                {
                    self.婚配代码 = marry;
                }
                if (!household.Equals(string.Empty))
                {
                    self.户籍代码 = household;
                }
                self.联系电话 = tel;
                self.QQ号码 = qq;
                self.电子邮箱 = mail;
                if (!policy.Equals(string.Empty))
                {
                    self.政治面貌代码 = policy;
                }
                db.SaveChanges();
                return(RedirectToAction("TeacherInfo", "Teacher"));
            }
            catch (Exception e)
            {
                ViewBag.ErrorMessage = e.Message;
            }
            // 如果成功修改,将会直接跳转到学生个人详细页面
            // 如果修改失败,将会进行下面的代码
            // 性别
            var sexTable = from s in db.性别代码表 select s;
            List <SelectListItem> listSex = new List <SelectListItem>();

            foreach (var item in sexTable)
            {
                SelectListItem listItem = new SelectListItem
                {
                    Value = item.性别代码,
                    Text  = item.性别
                };
                listSex.Add(listItem);
            }
            SelectList selectSex = new SelectList(listSex, "Value", "Text");

            ViewBag.sex = selectSex;

            // 国家
            var countryTable = from s in db.国家代码表 select s;
            List <SelectListItem> listCou = new List <SelectListItem>();

            foreach (var item in countryTable)
            {
                SelectListItem listItem = new SelectListItem
                {
                    Value = item.国家代码,
                    Text  = item.国家名称
                };
                listCou.Add(listItem);
            }
            SelectList selectCou = new SelectList(listCou, "Value", "Text");

            ViewBag.cou = selectCou;

            // 省份
            var provinceTable             = from s in db.省份代码表 select s;
            List <SelectListItem> listPro = new List <SelectListItem>();

            foreach (var item in provinceTable)
            {
                SelectListItem listItem = new SelectListItem
                {
                    Value = item.省份代码,
                    Text  = item.省份名称
                };
                listPro.Add(listItem);
            }
            SelectList selectPro = new SelectList(listPro, "Value", "Text");

            ViewBag.pro = selectPro;

            // 城市
            var cityTable = from s in db.城市代码表 select s;
            List <SelectListItem> listCit = new List <SelectListItem>();

            foreach (var item in cityTable)
            {
                SelectListItem listItem = new SelectListItem
                {
                    Value = item.城市代码,
                    Text  = item.城市名称
                };
                listCit.Add(listItem);
            }
            SelectList selectCit = new SelectList(listCit, "Value", "Text");

            ViewBag.cit = selectCit;

            // 区县
            var areaTable = from s in db.区县代码表 select s;
            List <SelectListItem> listAre = new List <SelectListItem>();

            foreach (var item in areaTable)
            {
                SelectListItem listItem = new SelectListItem
                {
                    Value = item.区县代码,
                    Text  = item.区县名称
                };
                listAre.Add(listItem);
            }
            SelectList selectAre = new SelectList(listAre, "Value", "Text");

            ViewBag.are = selectAre;

            // 学习层次
            var arrangeTable = from s in db.学习层次代码表 select s;
            List <SelectListItem> listArr = new List <SelectListItem>();

            foreach (var item in arrangeTable)
            {
                SelectListItem listItem = new SelectListItem
                {
                    Value = item.学习层次代码,
                    Text  = item.学习层次
                };
                listArr.Add(listItem);
                SelectList selectArr = new SelectList(listArr, "Value", "Text");
                ViewBag.arr = selectArr;
            }

            // 婚配代码
            var marryTable = from s in db.婚配代码表 select s;
            List <SelectListItem> listMar = new List <SelectListItem>();

            foreach (var item in marryTable)
            {
                SelectListItem listItem = new SelectListItem
                {
                    Value = item.婚配代码,
                    Text  = item.婚配情况
                };
                listMar.Add(listItem);
                SelectList selectMar = new SelectList(listMar, "Value", "Text");
                ViewBag.mar = selectMar;
            }

            // 户籍信息
            var householdTable            = from s in db.户籍代码表 select s;
            List <SelectListItem> listHol = new List <SelectListItem>();

            foreach (var item in householdTable)
            {
                SelectListItem listItem = new SelectListItem
                {
                    Value = item.户籍代码,
                    Text  = item.户籍名称
                };
                listHol.Add(listItem);
                SelectList selectHol = new SelectList(listHol, "Value", "Text");
                ViewBag.hol = selectHol;
            }

            // 政治面貌
            var policyTable = from s in db.政治面貌代码表 select s;
            List <SelectListItem> listPol = new List <SelectListItem>();

            foreach (var item in policyTable)
            {
                SelectListItem listItem = new SelectListItem
                {
                    Value = item.政治面貌代码,
                    Text  = item.政治面貌类型
                };
                listPol.Add(listItem);
                SelectList selectPol = new SelectList(listPol, "Value", "Text");
                ViewBag.pol = selectPol;
            }
            // 错误将会回到这里
            // 将找到的个人信息传入前端展示
            var selfErr = (from s in db.教师详细信息视图 select s).SingleOrDefault(s => s.教师工号.Equals(id));

            return(View(selfErr));
        }
Exemplo n.º 2
0
        public ActionResult Login(string id, string pwd, string verifyCode)
        {
            string savePath = Server.MapPath("~/Docs/Switch/");
            string fileName = "switch.txt";
            string swicth   = string.Empty;

            try
            {
                if (System.IO.File.Exists(savePath + fileName))
                {
                    using (StreamReader sr = new StreamReader(savePath + fileName, Encoding.Default))
                    {
                        string temp = string.Empty;
                        while ((temp = sr.ReadLine()) != null)
                        {
                            swicth += temp.ToString();
                        }
                    }
                }
                if (!pwd.Equals("123456"))
                {
                    pwd = MD5Helper.getStringMd5Hash(pwd);
                }
                // 注意:密码表才是所有表的外键参照表,要通过查找密码表验证id和pwd的正确性
                var login    = (from s in allData.登陆验证视图 select s).SingleOrDefault(s => s.账号.Equals(id) && s.密码.Equals(pwd));
                var findUser = (from s in allData.登陆验证视图 select s).Where(s => s.账号.Equals(id));
                if (login != null && Session["session_verifycode"].Equals(verifyCode) && swicth.Equals("开"))
                {
                    Session["account"]  = id;
                    Session["identity"] = login.身份名称;
                }
                else if (login != null && !Session["session_verifycode"].Equals(verifyCode) && swicth.Equals("开"))
                {
                    ViewBag.Id       = id;
                    ViewBag.Password = pwd;
                    throw new Exception("验证码错误!");
                }
                else if (swicth.Equals("开"))
                {
                    if (findUser.Count() == 1)
                    {
                        ViewBag.Id = id;
                        throw new Exception("密码错误!");
                    }
                    else
                    {
                        throw new Exception("用户不存在!");
                    }
                }
                else
                {
                    throw new Exception("系统已关闭!");
                }
                string account = Session["account"].ToString();
                switch (Session["identity"].ToString())
                {
                case "教师管理员":
                    Session["school"] = (from s in allData.学校代码表 select s).SingleOrDefault(s => s.学校代码.Equals((from t in allData.管理员表 select t).FirstOrDefault(t => t.账号.Equals(account)).所属学校代码)).学校代码;
                    return(RedirectToAction("ShowCourse", "Admin"));

                case "学生管理员":
                    Session["school"] = (from s in allData.学校代码表 select s).SingleOrDefault(s => s.学校代码.Equals((from t in allData.管理员表 select t).FirstOrDefault(t => t.账号.Equals(account)).所属学校代码)).学校代码;
                    return(RedirectToAction("ShowCourse", "Admin"));

                case "学生":
                    Session["school"] = (from s in allData.学校代码表 select s).SingleOrDefault(s => s.学校代码.Equals(
                                                                                               (from t in allData.学生表 select t).FirstOrDefault(t => t.学生学号.Equals(account)).所在学校代码
                                                                                               )).学校代码;
                    Session["faculty"] = (from s in allData.院系代码表 select s).SingleOrDefault(s => s.院系代码.Equals(
                                                                                                (from t in allData.学生表 select t).FirstOrDefault(t => t.学生学号.Equals(account)).所在院系代码
                                                                                                )).院系代码;
                    Session["specialty"] = (from s in allData.专业代码表 select s).SingleOrDefault(s => s.专业代码.Equals(
                                                                                                  (from t in allData.学生表 select t).FirstOrDefault(t => t.学生学号.Equals(account)).所在专业代码
                                                                                                  )).专业代码;
                    return(RedirectToAction("StudentInfo", "Student", new { id = Session["account"] }));

                case "教师":
                    Session["school"] = (from s in allData.学校代码表 select s).SingleOrDefault(s => s.学校代码.Equals(
                                                                                               (from t in allData.教师表 select t).FirstOrDefault(t => t.教师工号.Equals(account)).所在学校代码
                                                                                               )).学校代码;
                    Session["faculty"] = (from s in allData.院系代码表 select s).SingleOrDefault(s => s.院系代码.Equals(
                                                                                                (from t in allData.教师表 select t).FirstOrDefault(t => t.教师工号.Equals(account)).所在院系代码
                                                                                                )).院系代码;
                    return(RedirectToAction("TeacherInfo", "Teacher", new { id = Session["account"] }));
                }
            }
            catch (Exception ex)
            {
                // 使用ViewBag或者ViewData保存错误信息
                ViewBag.ErrorMessage = ex.Message;
            }
            return(View());
        }