Exemple #1
0
        public static ScoreModel AnalyseHtmlResult(string result,string stuid)
        {
            ScoreModel model = new ScoreModel();

            string pattern = @"<td.*>([^<>]+)</td>";
            Regex reg = new Regex(pattern, RegexOptions.IgnoreCase);
            /*
            foreach (Match m in reg.Matches(result))
            {
                Console.WriteLine(m.Groups[1].Value.Trim());
            }
            */
            var matches = reg.Matches(result);
            model.StudentNumber = matches[0].Groups[1].Value.Replace("学号:",string.Empty).Trim();
            model.StudentName = matches[1].Groups[1].Value.Replace("姓名:", string.Empty).Trim();
            model.ClassNumber = matches[2].Groups[1].Value.Replace("课程编号:", string.Empty).Trim();
            model.Term = matches[3].Groups[1].Value.Replace("上课学期", string.Empty).Trim();
            model.ClassName = matches[4].Groups[1].Value.Replace("课程名称:", string.Empty).Trim();
            model.Credit = matches[5].Groups[1].Value.Replace("学分", string.Empty).Trim();
            model.Teacher = matches[6].Groups[1].Value.Replace("任课教师", string.Empty).Trim();
            model.Score = matches[7].Groups[1].Value.Replace("总评成绩", string.Empty).Trim();
            model.CreditGet = matches[8].Groups[1].Value.Replace("获得学分", string.Empty).Trim();
            if (matches.Count >= 15)
            {
                //英语基础(有两门成绩)
                model.Credit = "3.0";
                model.CreditGet = "3.0";
                if (model.Score.Equals(""))
                {
                    model.Score = double.Parse(matches[14].Groups[1].Value.Trim() == "" ? "0.0" : matches[14].Groups[1].Value.Trim()) > 0.0 ?
                   matches[14].Groups[1].Value.Trim() : model.Score;
                }
                else
                {
                    model.Score = double.Parse(matches[14].Groups[1].Value.Trim() == "" ? "0.0" : matches[14].Groups[1].Value.Trim()) > double.Parse(model.Score) ?
                   matches[14].Groups[1].Value.Trim() : model.Score;
                }
            }
            model.Id = stuid;

            return model;
        }
Exemple #2
0
        /// <summary>
        /// 进度改变
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            tempModel = e.UserState as ScoreModel;
            if (e.UserState != null)
            {
                ClassScores.Add(tempModel);
            }

            processValue.Text = e.ProgressPercentage.ToString();
            progressbar.Value = e.ProgressPercentage;
            TaskbarItemInfo.ProgressValue = (double)e.ProgressPercentage / 100;

            if (tempModel != null)
            {
                if (CurrentQueryMode == QueryMode.加权平均分 || CurrentQueryMode == QueryMode.MultiPersonSingleClass)
                {
                    //计算均分
                    avaScoreAll.Text = (((double.Parse(avaScoreAll.Text) * (ClassScores.Count - 1)) + double.Parse(tempModel.Score))
                        / ClassScores.Count).ToString("F2");
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// 多人加权平均分
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void worker_DoWork_加权平均(object sender, DoWorkEventArgs e)
        {
            worker.ReportProgress(10);
            WorkerArgs args = e.Argument as WorkerArgs;
            try
            {
                Student student = new Student();

                if (args.isStudentNoRangeValid)
                {
                    int count = (int.Parse(args.StudentEndNo) - int.Parse(args.StudentStartNo)) + 1;
                    if (count <= 0)
                    {
                        MessageBox.Show("结束值不能小于起始值");
                        return;
                    }

                    using (TableAdapter<Student> adapter = TableAdapter<Student>.Open())
                    {
                        List<ScoreModel> scorelist;
                        ScoreModel scoremodel = null;
                        //遍历所有学生
                        for (int i = 0; i < count; i++)
                        {
                            //输入的是学号范围,先根据学号查询Id
                            var ret = adapter.Select().Where(Where.Equal("Number", (int.Parse(args.StudentStartNo) + i).ToString("D4")));
                            if (ret != null && ret.Count() > 0)
                            {
                                scorelist = new List<ScoreModel>();
                                ScoreModel model = new ScoreModel();
                                //学生id
                                args.StudentId = ret.First().StuId;
                                //查询各科成绩
                                for (int j = 0; j < classes.Count; j++)
                                {
                                    string q_result = Helper.HttpGet(args.Url,
                                        querypara.Replace("$stuid$", args.StudentId).
                                        Replace("#classid#", classes[j].Key));
                                    scoremodel = Helper.AnalyseHtmlResult(q_result, args.StudentId);
                                    model.StudentNumber = scoremodel.StudentNumber;
                                    model.StudentName = scoremodel.StudentName;
                                    model.Id = scoremodel.Id;
                                    if (scoremodel.ClassName.Equals("课程名称")) scoremodel = null;
                                    if (scoremodel!=null) scorelist.Add(scoremodel);
                                }

                                //计算加权平均分
                                double avaScore;
                                var list = scorelist.Where(t => (!string.IsNullOrEmpty(t.Score) && !string.IsNullOrEmpty(t.CreditGet) && isValidNumber(t.CreditGet)));//学分不为空的
                                double totalCredit = list.Select(t => double.Parse(t.CreditGet)).Sum();
                                if (totalCredit != 0)
                                {
                                    avaScore = (list.Select(t => double.Parse(t.Score == "" ? "0.0" : t.Score) * double.Parse(t.CreditGet)).Sum() / totalCredit);

                                    model.Credit = totalCredit.ToString();
                                    model.Teacher = "";
                                    model.Score = avaScore.ToString("F2");
                                    model.CreditGet = totalCredit.ToString();

                                    worker.ReportProgress((int)((i + 1) / (float)count * 100), model);
                                }
                            }
                        }
                    }
                }
                else
                {
                    int count = (int.Parse(args.StudentEndId) - int.Parse(args.StudentStartId)) + 1;
                    if (count <= 0)
                    {
                        MessageBox.Show("结束值不能小于起始值");
                        return;
                    }

                    List<ScoreModel> scorelist;
                    ScoreModel scoremodel = null;
                    for (int i = 0; i < count; i++)
                    {
                        scorelist = new List<ScoreModel>();
                        ScoreModel model = new ScoreModel();
                        //查询各科成绩
                        for (int j = 0; j < classes.Count; j++)
                        {
                            string q_result = Helper.HttpGet(args.Url,
                                querypara.Replace("$stuid$", (int.Parse(args.StudentStartId) + i).ToString("D4")).
                                        Replace("#classid#", classes[j].Key));
                            scoremodel = Helper.AnalyseHtmlResult(q_result, (int.Parse(args.StudentStartId) + i).ToString("D4"));
                            model.StudentNumber = scoremodel.StudentNumber;
                            model.StudentName = scoremodel.StudentName;
                            model.Id = scoremodel.Id;
                            if (scoremodel.ClassName.Equals("课程名称")) scoremodel = null;
                            if (scoremodel != null) scorelist.Add(scoremodel);
                        }

                        //计算加权平均分
                        double avaScore;
                        var list = scorelist.Where(t => (!string.IsNullOrEmpty(t.Score) && !string.IsNullOrEmpty(t.CreditGet) && isValidNumber(t.CreditGet)));//学分不为空的
                        double totalCredit = list.Select(t => double.Parse(t.CreditGet)).Sum();
                        if (totalCredit != 0)
                        {
                            avaScore = (list.Select(t => double.Parse(t.Score == "" ? "0.0" : t.Score) * double.Parse(t.CreditGet)).Sum() / totalCredit);

                            model.ClassNumber = "";
                            model.Term = "";
                            model.ClassName = "";
                            model.Credit = totalCredit.ToString();
                            model.Teacher = "";
                            model.Score = avaScore.ToString("F2");
                            model.CreditGet = totalCredit.ToString();

                            worker.ReportProgress((int)((i + 1) / (float)count * 100), model);
                        }

                    }
                }
            }
            catch (Exception e1)
            {
                MessageBox.Show(e1.Message);
            }
        }