public ActionResult Index(int?id, int?num)
        {
            Guid cID = Guid.Empty;

            if (num == null)
            {
                num = 0;
            }

            List <SelectListItem> classIDList = new List <SelectListItem>();


            string             UserName  = User.Identity.Name;
            int                UserID    = _icedts.SelectUserByAccout(UserName).UserID;
            List <CEDTS_Class> ClassList = _icedts.GetClassbyUserID(UserID);

            for (int i = 0; i < ClassList.Count; i++)
            {
                classIDList.Add(new SelectListItem {
                    Text = ClassList[i].ClassName, Value = ClassList[i].ClassID.ToString()
                });
            }
            //if (num != 0)
            //{
            classIDList[num.Value].Selected = true;
            cID = Guid.Parse(classIDList[num.Value].Value);
            //}

            ViewData["classIDList"] = classIDList;
            CEDTS_User Teacher = _icedts.SelectUserByAccout(User.Identity.Name);

            PartnerID = Teacher.PartnerID.Value;
            // MajorID = Teacher.MajorID.Value;
            //GradeID = Teacher.GradeID.Value;
            ClassID = cID;

            List <CEDTS_Test> testList = _test.SelectTest();

            List <Cedts_UserTest> utList     = new List <Cedts_UserTest>();
            List <int>            useridList = _icedts.SelectUser(null, ClassID).Where(p => p.State == true).Select(p => p.UserID).ToList();;

            foreach (var test in testList)
            {
                if (useridList.Contains(test.UserID.Value))
                {
                    Cedts_UserTest ut = new Cedts_UserTest();
                    ut.TestID     = test.TestID;
                    ut.UserName   = _test.GetUserName(test.UserID.Value);
                    ut.PaperID    = test.PaperID;
                    ut.PaperTitle = _test.GetPaperTitle(test.PaperID);
                    ut.TotalScore = test.TotalScore.Value;
                    ut.Remark     = test.Remark;
                    ut.IsChecked  = test.IsChecked.Value;
                    utList.Add(ut);
                }
            }
            return(View(utList.AsQueryable().ToPagedList(id ?? 1, 10)));
        }
Beispiel #2
0
 public ActionResult Edit(CEDTS_User user)
 {
     if (user.UserPassword != "" && user.UserPassword != null)
     {
         user.UserPassword = _admin.HashPassword(user.UserPassword);
     }
     _admin.EditUser(user);
     return(RedirectToAction("Index"));
 }
 public ActionResult Create(CEDTS_User User)
 {
     User.UserPassword = _icedts.HashPassword(User.UserPassword);
     User.Role         = "普通用户";
     User.State        = true;
     User.RegisterTime = DateTime.Now;
     User.ClassID      = ClassID1;
     _icedts.SaveUser(User);
     return(RedirectToAction("Index", new { ClassID = ClassID1 }));
 }
Beispiel #4
0
        public ActionResult Create(CEDTS_User user)
        {
            try
            {
                user.UserPassword = _admin.HashPassword(user.UserPassword);
                user.Role         = "管理员";
                _admin.CreateUser(user);

                return(RedirectToAction("Index"));
            }

            catch
            {
                return(View());
            }
        }
        public ActionResult Excel(string filepath)
        {
            string Q          = string.Empty;
            string connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filepath + ";Extended Properties=Excel 12.0;";



            DataSet ds = ExcelDataSource(connString, ExcelSheetName(connString)[0].ToString());

            if (ds.Tables[0].Columns.Count != 5)
            {
                System.IO.Directory.Delete(AppDomain.CurrentDomain.BaseDirectory + "TempExcel", true);
                return(Json(new { message = "2", url = "导入失败!您的Excel文件格式不正确!" }));
            }
            string Err   = string.Empty;
            int    count = 0;

            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                CEDTS_User user = new CEDTS_User();

                user.UserAccount  = ds.Tables[0].Rows[i][0].ToString();
                user.UserNickname = ds.Tables[0].Rows[i][1].ToString();
                user.Sex          = ds.Tables[0].Rows[i][2].ToString();
                user.Email        = ds.Tables[0].Rows[i][3].ToString();
                user.Phone        = ds.Tables[0].Rows[i][4].ToString();

                if (user.UserAccount == "" || user.UserAccount == null || user.Email == "" || user.Email == null || user.Sex == "" || user.Sex == null || user.UserNickname == "" || user.UserNickname == null)
                {
                    Err += (i + 2) + ",";
                    Q   += "不能导入空信息" + ",";
                    continue;
                }
                if (_icedts.SelectUserByAccout(user.UserAccount) != null || _icedts.SelectUserByEmail(user.Email) != null)
                {
                    Err += (i + 2) + ",";
                    Q   += "帐号或邮箱已存在" + ",";
                    continue;
                }
                if (!Regex.IsMatch(user.Email, @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"))
                {
                    Err += (i + 2) + ",";
                    Q   += "邮箱格式不正确" + ",";
                    continue;
                }
                if (user.Phone != null || user.Phone != "")
                {
                    if (!Regex.IsMatch(user.Phone, @"((\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$)"))
                    {
                        Err += (i + 2) + ",";
                        Q   += "联系电话格式不正确" + ",";
                        continue;
                    }
                }

                user.UserPassword  = _icedts.HashPassword("123123");
                user.Role          = "普通用户";
                user.RegisterTime  = DateTime.Now;
                user.PartnerID     = PartnerID;
                user.MajorID       = MajorID;
                user.GradeID       = GradeID;
                user.ClassID       = ClassID1;
                user.StudentNumber = user.UserAccount;
                user.State         = true;

                _icedts.SaveUser(user);
                count++;
            }

            System.IO.Directory.Delete(AppDomain.CurrentDomain.BaseDirectory + "TempExcel", true);
            return(Json(new { message = "1", url = Err + count.ToString(), why = Q }));
        }