Exemplo n.º 1
0
        public string Exjson(string pageIndex, string pageSize, int type)
        {
            if (string.IsNullOrEmpty(pageIndex) || string.IsNullOrEmpty(pageSize))
            {
                pageIndex = "1";
                pageSize  = "60";
            }
            int ipageIndex                = Convert.ToInt32(pageIndex);
            int ipageSize                 = Convert.ToInt32(pageSize);
            ExperimentOperation eo        = new ExperimentOperation();
            long count                    = eo.SearchCount(u => u.experiment_isDel == false && u.experiment_class == type);
            List <Experiment> experiments = eo.Search(u => u.experiment_isDel == false && u.experiment_class == type, i => i.experiment_title, ipageIndex, ipageSize);
            StringBuilder     sb          = new StringBuilder();
            string            s           = "{\"total\":" + count + ",\"rows\":[";

            sb.Append(s);
            foreach (Experiment e in experiments)
            {
                long id         = e.experiment_id;
                long chooseSNum = new ChooseOperation().SearchCount(u => u.choose_id == id && u.choose_isDel == false);
                s = "{\"id\":\"" + e.experiment_id + "\",\"title\":\"" + e.experiment_title + "\",\"num\":\"" + chooseSNum + "\",\"max\":\"" + e.experiment_peopleNum + "\",\"btn\":\" <button class='btn' value='" + e.experiment_id + "' type='button'>选择</button>\"},";
                sb.Append(s);
            }
            s = sb.ToString();
            if (count > 0)
            {
                s = s.Substring(0, s.Length - 1);
            }
            return(s + "]}");
        }
Exemplo n.º 2
0
        public JsonStatus ModifyStudentFromProject(string mark, string student_num, long projectId)
        {
            JsonStatus        js          = new JsonStatus();
            List <Student>    students    = new StudentOperation().Search(d => d.student_number == student_num && d.student_isDel == false);
            List <Experiment> experiments = new ExperimentOperation().Search(d => d.experiment_isDel == false && d.experiment_id == projectId);

            if (experiments.Count >= 1)
            {
                if (students.Count >= 1)
                {
                    switch (mark)
                    {
                    case "add":
                    {
                        if (base.SearchCount(d => d.Student.student_number == student_num && d.choose_isDel == false && d.Student.student_isDel == false) <= 0)
                        {
                            Choos c = new Choos()
                            {
                                choose_id              = 1,
                                choose_isDel           = false,
                                choose_ownExperimentId = projectId,
                                choose_ownStudentId    = students[0].student_id
                            };
                            base.Add(c);
                            js.status = "1";
                            js.msg    = "添加成功!";
                        }
                        else
                        {
                            js.status = "0";
                            js.msg    = "添加失败!该学生已选择另一课题如要添加请先在另一表中删除!";
                        }
                        break;
                    }

                    case "remove":
                    {
                        List <Choos> chooses = base.Search(d => d.choose_isDel == false && d.Student.student_number == student_num && d.choose_ownExperimentId == projectId && d.choose_isDel == false);
                        if (chooses.Count >= 1)
                        {
                            chooses[0].choose_isDel = true;
                            base.Modify(chooses[0], "choose_isDel");
                            js.status = "1";
                            js.msg    = "删除成功!";
                        }
                        else
                        {
                            js.status = "0";
                            js.msg    = "删除失败!数据异常!";
                        }
                        break;
                    }
                    }
                }
                else
                {
                    js.status = "0";
                    js.msg    = mark == "add" ? "输入的学号不存在!请检查输入是否正确!" : "数据异常!";
                }
            }
            else
            {
                js.status = "0";
                js.msg    = "操作失败!数据异常!";
            }
            return(js);
        }
Exemplo n.º 3
0
        public JsonStatus ExpermentProjectChoose(string expirmentId, long studentId)
        {
            JsonStatus     js       = new JsonStatus();
            List <Student> students = new StudentOperation().Search(m => m.student_id == studentId && m.student_isDel == false);
            long           pId      = 0;

            try
            {
                pId = Convert.ToInt64(expirmentId);
                List <Experiment> experiments = new ExperimentOperation().Search(d => d.experiment_isDel == false && d.experiment_id == pId);
                List <Choos>      chooses     = base.Search(d => d.choose_ownStudentId == studentId && d.choose_isDel == false && d.choose_ownExperimentId == pId);
                if (students.Count >= 1 && experiments.Count >= 1)
                {
                    if (experiments[0].experiment_allowGrades.Split(',').Contains(students[0].student_grade.ToString()))
                    {
                        if (experiments[0].experiment_peopleNum > base.SearchCount(d => d.choose_isDel == false && d.choose_ownExperimentId == pId))
                        {
                            if (chooses.Count == 0 && ((experiments[0].experiment_class == (int)ExpermentType.Graduate && base.SearchCount(d => d.choose_ownStudentId == studentId && d.choose_isDel == false && d.Experiment.experiment_class == (int)ExpermentType.Graduate) == 0) || experiments[0].experiment_class != (int)ExpermentType.Graduate))
                            {
                                try
                                {
                                    Choos c = new Choos()
                                    {
                                        choose_id              = 1,
                                        choose_isDel           = false,
                                        choose_ownExperimentId = pId,
                                        choose_ownStudentId    = studentId,
                                    };
                                    base.Add(c);
                                    js.status = "1";
                                    js.msg    = "选择成功!";
                                }
                                catch
                                {
                                    js.status = "0";
                                    js.msg    = "选择失败!未知错误.....";
                                }
                            }
                            else
                            {
                                js.status = "0";
                                js.msg    = "你已选择!不能再次选择!如要修改请联系管理员.....";
                            }
                        }
                        else
                        {
                            js.status = "0";
                            js.msg    = "选择失败!人数已满.....";
                        }
                    }
                    else
                    {
                        js.status = "0";
                        js.msg    = "选择失败!你现在无权选择.....";
                    }
                }
                else
                {
                    js.status = "0";
                    js.msg    = "选择失败!数据错误.....";
                }
            }
            catch
            {
                js.status = "0";
                js.msg    = "选择失败!数据错误.....";
            }

            return(js);
        }