Exemplo n.º 1
0
        /// <summary>
        /// 各区县、直属单位为学员报名
        /// </summary>
        /// <param name="id">班级ID</param>
        public ActionResult Signup(int id)
        {
            TrainSignupViewData viewData = new TrainSignupViewData();
            string message = "";
            Org org = GetOrg();
            viewData.OrgCode = org.OrgCode;

            Classes classes = (from c in CQGJ.Classes
                               where c.ClassID == id
                               select c).First();
            viewData.Classes = classes;
            Quota quota = (from q in CQGJ.Quota
                           where q.Org.OrgID == org.OrgID
                           where q.Classes.ClassID == id
                           select q).First();
            viewData.Number = (int)quota.Number;
            viewData.SignupNumber = (int)quota.SignupNumber;

            viewData.UserList = (from s in CQGJ.Student
                                 from u in CQGJ.User
                                 where s.Classes.ClassID == classes.ClassID
                                 where s.User == u
                                 select u).ToList();

            //根据表单提交的数据,更新报名的用户
            //string idlist = GetString("idlist");
            //string[] ids = idlist.Split(new Char[] { ',' });
            //if (Request["idlist"] != null)
            //{
            //    //(本单位)先将数据库有的,而提交的数据中没有的学员删除
            //    List<Student> studentList = (from s in CQGJ.Student
            //                                 where s.Classes.ClassID == classes.ClassID
            //                                 select s).ToList();
            //    foreach (var s in studentList)
            //    {
            //        bool flag = false;
            //        foreach (string temp in ids)
            //        {
            //            if (s.UserReference.EntityKey.EntityKeyValues[0].Value.ToString() == temp)
            //            { flag = true; }
            //        }
            //        if (flag == false)
            //        {
            //            CQGJ.DeleteObject(s);
            //            quota.SignupNumber--;
            //            CQGJ.SaveChanges();
            //        }
            //    }

            //    for (int i = 0; i < ids.Length; i++)
            //    {
            //        try
            //        {
            //            int userid = Convert.ToInt32(ids[i]);
            //            if (userid != 0)
            //            {
            //                //应先判断这个用户ID是否已经报名
            //                Student student = new Student();

            //                List<Student> students = (from s in CQGJ.Student
            //                                          where s.Classes.ClassID == classes.ClassID
            //                                          where s.User.UserID == userid
            //                                          select s).ToList();
            //                if (students.Count() > 0)
            //                { }
            //                else//不存在的时候再执行插入
            //                {
            //                    User user = (from u in CQGJ.User
            //                                 where u.UserID == userid
            //                                 select u).First();
            //                    student.Classes = classes;
            //                    student.User = user;

            //                    //检查是否报名人数已满
            //                    if (quota.Number - quota.SignupNumber >= 1)
            //                    {
            //                        CQGJ.AddToStudent(student);
            //                        quota.SignupNumber++;
            //                        CQGJ.SaveChanges();
            //                    }
            //                    else
            //                    { message = "报名人数超出,请删除部分学员再保存。"; }
            //                }
            //            }
            //            message = "保存成功!";
            //        }
            //        catch { message = "保存失败!"; }
            //    }
            //}
            TempData["message"] = message;
            return View("Signup", viewData);
        }
Exemplo n.º 2
0
        public void Signup(int id)
        {
            TrainSignupViewData viewData = new TrainSignupViewData();
            string message = "";
            int orgID = GetOrgID();
            viewData.OrgCode = ToPassportOrgCode(orgID);

            Classes classes = (from c in CQGJ.Classes
                               where c.ClassID == id
                               select c).First();
            viewData.Classes = classes;
            Quota quota = (from q in CQGJ.Quota
                           where q.Org.OrgID == orgID
                           where q.Classes.ClassID == id
                           select q).First();
            viewData.Number = (int)quota.Number;
            viewData.SignupNumber = (int)quota.SignupNumber;

            viewData.UserList = (from s in CQGJ.Student
                                 from u in CQGJ.User
                                 where s.Classes.ClassID == classes.ClassID
                                 where s.User == u
                                 select u).ToList();

            //获取已经报名的用户ID(PassportUserID)
            //foreach (var s in StudentList)
            //{ viewData.IDList += ToPassportUserID((int)s.UserID) + ","; }

            //根据表单提交的数据,更新报名的用户
            string idlist = GetString("idlist");
            string[] ids = idlist.Split(new Char[] { ',' });
            if (Request["idlist"] != null)
            {
                //(本单位)先将数据库有的,而提交的数据中没有的学员删除
                List<Student> studentList = (from s in CQGJ.Student
                                             where s.Classes.ClassID == classes.ClassID
                                             select s).ToList();
                foreach (var s in studentList)
                {
                    bool flag = false;
                    foreach (string temp in ids)
                    {
                        if (s.UserReference.EntityKey.EntityKeyValues[0].Value.ToString() == temp)
                        { flag = true; }
                    }
                    if (flag == false)
                    {
                        CQGJ.DeleteObject(s);
                        quota.SignupNumber--;
                        CQGJ.SaveChanges();
                    }
                }

                for (int i = 0; i < ids.Length; i++)
                {
                    try
                    {
                        int userid = Convert.ToInt32(ids[i]);
                        if (userid != 0)
                        {
                            //应先判断这个用户ID是否已经报名
                            Student student = new Student();

                            List<Student> students = (from s in CQGJ.Student
                                                      where s.Classes.ClassID == classes.ClassID
                                                      where s.User.UserID == userid
                                                      select s).ToList();
                            if (students.Count() > 0)
                            { }
                            else//不存在的时候再执行插入
                            {
                                User user = (from u in CQGJ.User
                                             where u.UserID == userid
                                             select u).First();
                                student.Classes = classes;
                                student.User = user;

                                //检查是否报名人数已满
                                if (quota.Number - quota.SignupNumber >= 1)
                                {
                                    CQGJ.AddToStudent(student);
                                    quota.SignupNumber++;
                                    CQGJ.SaveChanges();
                                }
                                else
                                { message = "报名人数超出,请删除部分学员再保存。"; }
                            }
                        }
                        message = "保存成功!";
                    }
                    catch { message = "保存失败!"; }
                }
            }
            TempData["message"] = message;
            RenderView("Signup", viewData);
        }