コード例 #1
0
        public Subject parseSubject(DataTable subject)
        {
            string student = (string)subject.Rows[0].ItemArray[0];
            student = student.Substring(student.IndexOf(' ') + 1, student.LastIndexOf(' ') - student.IndexOf(' ') - 2);

            //Console.WriteLine(student.Substring(student.IndexOf(' ') + 1, student.LastIndexOf(' ') - student.IndexOf(' ') - 2));
            string[] row = ((string)subject.Rows[1].ItemArray[0]).Split('.');
            string subname = row[0];
            string semname = row[1];
            string year = row[2].Substring(row[2].Trim().LastIndexOf(' ') + 1);
            Subject subj = new Subject
            {
                Name = subname,
                Semestr = semname,
                Year = year,
                Student = student
            };
            int i = 0;
            while (true)
            {
                var g = subject.Rows[4].ItemArray[i];

                if (g == null) break;
                string str = (string)g;
                try
                {
                    string name = str.Substring(str.IndexOf('(') + 1, str.IndexOf(')') - str.IndexOf('(') - 1).ToLower();
                    // System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator = ".";
                    float coef = float.Parse(str.Substring(str.LastIndexOf(' ') + 1), new System.Globalization.CultureInfo("en-US"));
                    //subj.Sections.Add(name, new Section() { Name = name, Coef = coef });
                    Section sect = new Section { Name = name, Coef = coef };
                    subj.Sections[name] = sect;
                    i += 1;
                }
                catch (Exception)
                {
                    break;
                }
            }
            float tmp = 0;
            float.TryParse((string)subject.Rows[5].ItemArray[i], System.Globalization.NumberStyles.Float, new System.Globalization.CultureInfo("en-US"), out tmp);
            subj.Points = tmp;
            if (float.TryParse((string)subject.Rows[5].ItemArray[i + 2], System.Globalization.NumberStyles.Float, new System.Globalization.CultureInfo("en-US"), out tmp))
            {
                i += 2;
                subj.Points = tmp;
            }
            subj.Mark = (string)subject.Rows[5].ItemArray[i + 1];

            int rowNumber = 8;

            while (rowNumber < subject.Rows.Count && subject.Rows[rowNumber].ItemArray[0] != System.DBNull.Value)
            {
                parseSection(subject, rowNumber, subj.Sections);
                rowNumber += 12;
            }

            return subj;
        }
コード例 #2
0
 public void Edit(Subject subject)
 {
     Subject subj = Subjects.ToList().Find(s => s.SubjectID == subject.SubjectID);
     if (subj == null) Add(subject);
     else subj = subject;
 }
コード例 #3
0
 public void Add(Subject subject)
 {
     Subjects = Subjects.Concat(new [] {subject}).ToList();
 }