Пример #1
0
 public Connection GetCurrentPeriod(Period currentPeriod, int studentID, string password)
 {
     try
     {
         Data.StudentID = studentID;
         Data.Password  = password;
         string baseHtml = Function.GetHTML("http://obisis.erciyes.edu.tr/");
         Data.GetURLs(baseHtml);
         string       html = Function.GetHTML(Data.LessonsURL);
         HtmlDocument doc  = new HtmlDocument();
         doc.LoadHtml(html);
         HtmlNode           node = doc.DocumentNode;
         HtmlNodeCollection col  = node.SelectNodes("//table[@id='ctl00_dgDers']//tr");
         for (int i = 1; i < col.Count; i++)
         {
             HtmlNode item          = col[i];
             string   code          = item.SelectSingleNode("./td[1]").InnerText;
             string   absent        = Function.TidyText(item.SelectSingleNode("./td[3]").InnerText);
             string   firstMidMark  = Function.TidyText(item.SelectSingleNode("./td[4]").InnerText);
             string   secondMidMark = Function.TidyText(item.SelectSingleNode("./td[5]").InnerText);
             string   thirdMidMark  = Function.TidyText(item.SelectSingleNode("./td[6]").InnerText);
             string   finalMark     = Function.TidyText(item.SelectSingleNode("./td[7]").InnerText);
             string   intMark       = Function.TidyText(item.SelectSingleNode("./td[8]").InnerText);
             string   average       = Function.TidyText(item.SelectSingleNode("./td[9]").InnerText);
             string   grade         = Function.TidyText(item.SelectSingleNode("./td[10]").InnerText);
             string   state         = Function.TidyText(item.SelectSingleNode("./td[11]").InnerText);
             string   firstMidDate  = Function.TidyText(item.SelectSingleNode("./td[12]").InnerText);
             string   secondMidDate = Function.TidyText(item.SelectSingleNode("./td[13]").InnerText);
             string   thirdMidDate  = Function.TidyText(item.SelectSingleNode("./td[14]").InnerText);
             string   finalDate     = Function.TidyText(item.SelectSingleNode("./td[15]").InnerText);
             string   intDate       = Function.TidyText(item.SelectSingleNode("./td[16]").InnerText);
             string   intRight      = Function.TidyText(item.SelectSingleNode("./td[17]").InnerText);
             Lesson   lesson        = currentPeriod.Lessons.SingleOrDefault(x => x.Code == code);
             if (lesson != null)
             {
                 lesson.AbsentState = absent == "G" ? AbsentType.Passed : absent == "D" ? AbsentType.Failed : absent == "M" ? AbsentType.Free : (AbsentType?)null;
                 if (!string.IsNullOrEmpty(firstMidMark))
                 {
                     lesson.FirstMidterm = new Exam()
                     {
                         Mark = Convert.ToInt32(firstMidMark), Date = !string.IsNullOrEmpty(firstMidDate) ? Convert.ToDateTime(firstMidDate) : (DateTime?)null
                     }
                 }
                 ;
                 if (!string.IsNullOrEmpty(secondMidMark))
                 {
                     lesson.FirstMidterm = new Exam()
                     {
                         Mark = Convert.ToInt32(secondMidMark), Date = !string.IsNullOrEmpty(secondMidDate) ? Convert.ToDateTime(secondMidDate) : (DateTime?)null
                     }
                 }
                 ;
                 if (!string.IsNullOrEmpty(thirdMidMark))
                 {
                     lesson.FirstMidterm = new Exam()
                     {
                         Mark = Convert.ToInt32(thirdMidMark), Date = !string.IsNullOrEmpty(thirdMidDate) ? Convert.ToDateTime(thirdMidDate) : (DateTime?)null
                     }
                 }
                 ;
                 if (!string.IsNullOrEmpty(finalMark))
                 {
                     lesson.FirstMidterm = new Exam()
                     {
                         Mark = Convert.ToInt32(finalMark), Date = !string.IsNullOrEmpty(finalDate) ? Convert.ToDateTime(finalDate) : (DateTime?)null
                     }
                 }
                 ;
                 if (!string.IsNullOrEmpty(intMark))
                 {
                     lesson.FirstMidterm = new Exam()
                     {
                         Mark = Convert.ToInt32(intMark), Date = !string.IsNullOrEmpty(intDate) ? Convert.ToDateTime(intDate) : (DateTime?)null
                     }
                 }
                 ;
                 if (!string.IsNullOrEmpty(average))
                 {
                     lesson.Average = Convert.ToInt32(average);
                 }
                 lesson.Grade = Lesson.GetGrade(grade);
                 lesson.State = state == "Geçti" ? true : state == "Kaldı" ? false : (bool?)null;
                 if (!string.IsNullOrEmpty(intRight))
                 {
                     lesson.IntegrationRight = intRight == "Yok" ? false : true;
                 }
             }
         }
         this.State      = true;
         this.Message    = null;
         this.DataObject = currentPeriod;
     }
     catch (Exception)
     {
         this.State      = false;
         this.Message    = "Geçerli döneme erişilemiyor..";
         this.DataObject = null;
     }
     return(this);
 }
Пример #2
0
        public static List <Period> GetPeriods(string html)
        {
            List <Period> periods = new List <Period>();
            HtmlDocument  doc     = new HtmlDocument();

            doc.LoadHtml(html);
            HtmlNode                  node   = doc.DocumentNode;
            HtmlNodeCollection        col    = node.SelectNodes("//table[@id='ctl00_gvDersDurum']//tr");
            Period                    period = new Period();
            ObisisMobileServiceClient client = new ObisisMobileServiceClient();

            for (int i = 1; i < col.Count; i++)
            {
                HtmlNode item = col[i];
                if (item.InnerText.Contains("ORTALAMASI"))
                {
                    if (i != 1)
                    {
                        periods.Add(period);
                    }
                    period = new Period();
                    string text = item.InnerText.Replace("\r", "").Replace("\t", "").Replace("\n", "");
                    period.Name     = Function.TidyText(text.Split(' ')[1]);
                    period.Code     = GetCode(period.Name);
                    period.Year     = text.Split(' ')[0];
                    period.YearCode = GetYearCode(period.Year);
                    period.GANO     = Convert.ToDouble(text.Split(':')[1].Replace(",", "").Replace(".", "").Trim()) / 100;
                    period.Lessons  = new List <Lesson>();
                    OgrenciResult result = client.OgrenciBilgiGetir(Data.StudentID.ToString(), Data.Password, period.YearCode, period.Code);
                    DataTable     dt     = result.Data.Tables[0];
                    foreach (DataRow data in dt.Rows)
                    {
                        Lesson lesson = new Lesson()
                        {
                            Name         = Function.TidyText(data["DERS_ADI_TR"].ToString()),
                            FirstMidterm = new Exam()
                            {
                                Mark = string.IsNullOrEmpty(data["VIZE1"].ToString()) ? (int?)null : Convert.ToInt32(data["VIZE1"])
                            },
                            SecondMidterm = new Exam()
                            {
                                Mark = string.IsNullOrEmpty(data["VIZE2"].ToString()) ? (int?)null : Convert.ToInt32(data["VIZE2"])
                            },
                            ThirdMidterm = new Exam()
                            {
                                Mark = string.IsNullOrEmpty(data["VIZE3"].ToString()) ? (int?)null : Convert.ToInt32(data["VIZE3"])
                            },
                            Final = new Exam()
                            {
                                Mark = string.IsNullOrEmpty(data["FINAL"].ToString()) ? (int?)null : Convert.ToInt32(data["FINAL"])
                            },
                            Integration = new Exam()
                            {
                                Mark = string.IsNullOrEmpty(data["BUTUNLEME"].ToString()) ? (int?)null : Convert.ToInt32(data["BUTUNLEME"])
                            },
                            Average = string.IsNullOrEmpty(data["ORTALAMA"].ToString()) ? (int?)null : Convert.ToInt32(data["ORTALAMA"]),
                            Grade   = string.IsNullOrEmpty(data["HARF_NOTU"].ToString()) ? null : Lesson.GetGrade(data["HARF_NOTU"].ToString()),
                            State   = string.IsNullOrEmpty(data["GECTI_KALDI"].ToString()) ? (bool?)null : data["GECTI_KALDI"].ToString() == "GEÇTİ"
                        };
                        period.Lessons.Add(lesson);
                    }
                }
                else
                {
                    string code       = item.SelectSingleNode("./td[1]").InnerText;
                    string name       = Function.TidyText(item.SelectSingleNode("./td[2]").InnerText);
                    double credit     = Convert.ToDouble(item.SelectSingleNode("./td[6]").InnerText.Trim().Replace(",", "."));
                    int    cls        = Convert.ToInt32(item.SelectSingleNode("./td[3]").InnerText);
                    bool   ganoEffect = item.SelectSingleNode("./td[8]").InnerText != "&nbsp;" && item.SelectSingleNode("./td[9]").InnerText == "&nbsp;" ? false : true;
                    double factor     = item.SelectSingleNode("./td[9]").InnerText == "&nbsp;" ? 0.0 : Convert.ToDouble(item.SelectSingleNode("./td[9]").InnerText.Trim());

                    Lesson lesson = period.Lessons.SingleOrDefault(x => x.Name == name);
                    if (lesson != null)
                    {
                        lesson.Code          = code;
                        lesson.Credit        = credit;
                        lesson.AverageEffect = ganoEffect;
                        lesson.SuccessFactor = factor;
                        lesson.Class         = cls;
                    }
                }
                if (i == col.Count - 1)
                {
                    periods.Add(period);
                }
            }
            return(periods.OrderBy(x => x.YearCode).ThenBy(x => x.Code).ToList());
        }