-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
127 lines (122 loc) · 5.85 KB
/
MainWindow.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
using System.Windows;
using System.IO;
using System.Runtime.Serialization.Json;
using System.Collections.Generic;
using System.Linq;
using laba4.JsonClass;
namespace laba4
{
public partial class MainWindow : Window
{
public string PathJsonFile = @"C:\Users\Totkt\source\repos\laba4\data\file.json";
public JsonProfStandart jsonProfStandart { get; set; }
public List<Standart> standart { get; set; }
public List<Subject> subject { get; set; }
public List<ProgressIdentifier> progressIdentifier { get; set; }
public Term[] terms { get; set; }
public CurseInfo[] curseInfo { get; set; }
public MainWindow()
{
InitializeComponent();
jsonProfStandart = LoadJsonFile(PathJsonFile);
standart = getStandartInData(jsonProfStandart);
progressIdentifier = getProgressIdentifierInData(jsonProfStandart);
subject = getSubjectsInfoInData(jsonProfStandart);
terms = getTerms(subject);
curseInfo = getCurseInfos(jsonProfStandart);
this.DataContext = this;
}
public JsonProfStandart LoadJsonFile(string PathJsonFile)
{
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(JsonProfStandart));
JsonProfStandart returnResult;
using (FileStream fs = new FileStream(PathJsonFile, FileMode.OpenOrCreate))
{
returnResult = (JsonProfStandart)serializer.ReadObject(fs);
}
return returnResult;
}
private List<Standart> getStandartInData(JsonProfStandart jsonProfStandart)
{
List<Standart> returnResult = new List<Standart>();
foreach(ProfessionalStandards PS in jsonProfStandart.content.section4.professionalStandards)
{
string id = PS.content.Split(' ').First();
string name = PS.content.Replace(id + " ", "");
if (!id.Contains("06."))
{
id = "";
name = PS.content;
}
returnResult.Add(new Standart(id, name));
}
return returnResult;
}
private List<ProgressIdentifier> getProgressIdentifierInData(JsonProfStandart jsonProfStandart)
{
List<ProgressIdentifier> returnResult = new List<ProgressIdentifier>();
foreach (UniversalCompetencyRows item in jsonProfStandart.content.section4.universalCompetencyRows)
{
ProgressIdentifier temp = new ProgressIdentifier();
temp.code = item.competence.code.Replace("\n","");
temp.title = item.competence.title.Replace("\n", "");
temp.knowLabel = item.indicators[0].content.Split(' ').First().Replace("\n", "");
temp.knowDescription = item.indicators[0].content.Replace(temp.knowLabel + " ", "").Replace("\n", "");
temp.possessLabel = item.indicators[1].content.Split(' ').First().Replace("\n", "");
temp.possessDescription = item.indicators[1].content.Replace(temp.possessLabel + " ", "").Replace("\n", "");
temp.canLabel = item.indicators[1].content.Split(' ').First().Replace("\n", "");
temp.canDescription = item.indicators[1].content.Replace(temp.canLabel + " ", "").Replace("\n", "");
returnResult.Add(temp);
}
return returnResult;
}
private List<Subject> getSubjectsInfoInData(JsonProfStandart jsonProfStandart)
{
List<Subject> returnResult = new List<Subject>();
foreach(Subrows item in jsonProfStandart.content.section5.eduPlan.block1.subrows)
{
string[] d = item.description.Split('>');
string temp = "";
foreach (string str in d)
{
if (str.IndexOf('<') == -1)
{
temp += str;
continue;
}
temp += str.Remove(str.IndexOf('<'));
}
returnResult.Add(new Subject(item.index, item.title, temp,
item.competences.Select(n => n.code).ToArray(), item.unitsCost, item.terms));
}
return returnResult;
}
private Term[] getTerms(List<Subject> subject)
{
const ushort countTerm = 8;
Term[] terms = new Term[countTerm];
for (ushort i = 0; i < countTerm; i++)
terms[i] = new Term($"Семестр №{i + 1}", i, getSubjectsInTerm(i, subject));
return terms;
}
private List<Subject> getSubjectsInTerm(ushort trem, List<Subject> subject)
=> subject.Where(n => n.terms[trem].terms == true).ToList();
private void ListBox_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
=> SubjectTable.ItemsSource = terms[ListTerm.SelectedIndex].subject;
private CurseInfo[] getCurseInfos(JsonProfStandart jsonProfStandart)
{
int countCurse = jsonProfStandart.content.section5.calendarPlanTable.courses.Count();
const string templateCurseName = "Курс";
if (countCurse < 1) return null;
CurseInfo[] returnResult = new CurseInfo[countCurse];
for(int i = 0; i < countCurse; i++)
returnResult[i] = new CurseInfo($"{templateCurseName} {i + 1}", i,
jsonProfStandart.content.section5.calendarPlanTable.courses[i]);
return returnResult;
}
private void ListCourse_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
TimelineTable.ItemsSource = curseInfo[ListCourse.SelectedIndex].content;
}
}
}