private void ResultInitializer() { if (File.Exists(Resources.ResultsData) && File.ReadAllText(Resources.ResultsData) != "") { var json = File.ReadAllText(Resources.ResultsData); var results = JsonConvert.DeserializeObject <List <Result> >(json); foreach (var result in results) { ResultsData.Get().Add(result); } } //UpdateResults(); }
public FormDeleteResults() { InitializeComponent(); foreach (Result res in ResultsData.Get()) { if (!_listOfCourses.Contains(res.Course)) { _listOfCourses.Add(res.Course); } } drawCourses(); }
private void UpdateResults(params object[] newRow) { ResultsData.Get().Add(new Result { ResultType = newRow[6] as string, Mark = newRow[4] as string, Platoon = newRow[2] as string, StudentName = newRow[3] as string, TestName = newRow[1] as string, Timestamp = (DateTime)newRow[5], Course = newRow[0] as string }); File.WriteAllText(Resources.ResultsData, JsonConvert.SerializeObject(ResultsData.Get())); }
public void deleteCheckedResults() { foreach (Control ctrl in panelWithCourses.Controls) { if (ctrl is CheckBox) { if (((CheckBox)ctrl).Checked) { ResultsData.Get().RemoveAll(p => p.Course == ctrl.Text); DirectoryInfo diTests = new DirectoryInfo(_parameters.Get().ResultsPath + @"\Тестирование\" + ctrl.Text); DirectoryInfo diStudy = new DirectoryInfo(_parameters.Get().ResultsPath + @"\Обучение\" + ctrl.Text); if (!diTests.Exists || !diStudy.Exists) { continue; } foreach (FileInfo file in diTests.GetFiles()) { file.Delete(); } foreach (DirectoryInfo dir in diTests.GetDirectories()) { dir.Delete(true); } foreach (FileInfo file in diStudy.GetFiles()) { file.Delete(); } foreach (DirectoryInfo dir in diStudy.GetDirectories()) { dir.Delete(true); } } } } File.WriteAllText(Resources.ResultsData, JsonConvert.SerializeObject(ResultsData.Get())); MessageBox.Show("Результаты удалены", "Успех!"); }
public void saveResults() { listColumns = new Dictionary <string, string> { }; dicCourses = new Dictionary <string, List <Result> > { }; docnameAndResults = new Dictionary <string, List <DataGridViewRow> > { }; foreach (Result res in ResultsData.Get()) { if (res.ResultType != _typeRes1) { continue; } if (!dicCourses.ContainsKey(res.Course)) { dicCourses.Add(res.Course, new List <Result> { }); } dicCourses[res.Course].Add(res); } //Коллекция для создания заголовков listColumns.Add("Course", "Предмет"); listColumns.Add("TestName", "Название Теста"); listColumns.Add("Platoon", "Взвод"); listColumns.Add("StudentName", "ФИО"); listColumns.Add("Mark", "Результат"); listColumns.Add("Timestamp", "Дата"); foreach (KeyValuePair <string, List <Result> > keyValue in dicCourses) { docnameAndResults.Clear(); var wrongSymbols = "/\\<>:?\"|*"; //Создаем папку под каждый предмет string courseDir = _parameters.Get().ResultsPath + @"\" + new string(_typeRes2.Where(c => !wrongSymbols.Contains(c)).ToArray()) + @"\" + new string(keyValue.Key.Where(c => !wrongSymbols.Contains(c)).ToArray()); if (!Directory.Exists(courseDir)) { Directory.CreateDirectory(courseDir); } //Создание таблицы, которую вставим в Word DataGridView tempTable = new DataGridView(); //Добаляем заголовочную строку таблице foreach (KeyValuePair <string, string> courseNameAndText in listColumns) { var column = new DataGridViewColumn { HeaderText = courseNameAndText.Value, Name = courseNameAndText.Key, CellTemplate = new DataGridViewTextBoxCell() }; tempTable.Columns.Add(column); } //Создание мапы <взвод - название теста> в конкретном предмете foreach (Result res in keyValue.Value) { string name = res.Platoon + "взвод. " + res.TestName; if (!docnameAndResults.ContainsKey(name)) { docnameAndResults.Add(name, new List <DataGridViewRow> { }); } DataGridViewRow rowForInsert = new DataGridViewRow(); rowForInsert.CreateCells(_testsTable); rowForInsert.Cells[0].Value = res.Course; rowForInsert.Cells[1].Value = res.TestName; rowForInsert.Cells[2].Value = res.Platoon; rowForInsert.Cells[3].Value = res.StudentName; rowForInsert.Cells[4].Value = res.Mark; rowForInsert.Cells[5].Value = res.Timestamp; docnameAndResults[name].Add(rowForInsert); } foreach (var keyValueDocAndRows in docnameAndResults) { tempTable.Rows.Clear(); foreach (DataGridViewRow rowTemp in keyValueDocAndRows.Value) { DataGridViewRow rowForInsert = new DataGridViewRow(); rowForInsert = (DataGridViewRow)rowTemp.Clone(); int intColIndex = 0; foreach (DataGridViewCell cell in rowTemp.Cells) { rowForInsert.Cells[intColIndex].Value = cell.Value; intColIndex++; } tempTable.Rows.Add(rowForInsert); } ws.Export_Data_To_Word(tempTable, courseDir + @"\" + new string(keyValueDocAndRows.Key.Where(c => !wrongSymbols.Contains(c)).ToArray()) + ".doc"); } } }