public void Save(string fileName) { using (StreamWriter fileStream = new StreamWriter(fileName, false, System.Text.Encoding.UTF8)) { fileStream.WriteLine("CPF"); fileStream.WriteLine(StipendBox.Text); fileStream.WriteLine(Start_Period.ToString()); fileStream.WriteLine(Finish_Period.ToString()); string subjectString = ""; SubjectsList.ForEach(subj => { subjectString += (subj.ToString() + " "); }); fileStream.WriteLine(subjectString); StudentList.ForEach(stud => { fileStream.Write(stud.IdStudent.ToString() + " - "); string assessmentString = ""; foreach (KeyValuePair <int, int> entry in stud.AssessmentsList) { assessmentString += (entry.Key.ToString() + ":" + entry.Value.ToString() + " "); } fileStream.WriteLine(assessmentString); }); } }
public void AddSubject(int subject) { if (!SubjectsList.Contains(subject)) { SubjectsList.Add(subject); StudentList.ForEach(stud => { stud.AssessmentsList.Add(subject, 0); }); } UpdateTable(); }
public void RemoveSubject(int subject, bool update = true) { if (SubjectsList.Contains(subject)) { SubjectsList.Remove(subject); StudentList.ForEach(stud => { if (stud.AssessmentsList.ContainsKey(subject)) { stud.AssessmentsList.Remove(subject); } }); } if (update) { UpdateTable(); } }
public void AddStudent(int student) { bool isSet = false; StudentList.ForEach(stud => { if (stud.IdStudent == student) { isSet = true; return; } }); if (!isSet) { AssessmentsStudent newStudent = new AssessmentsStudent(student); SubjectsList.ForEach(subject => { newStudent.AssessmentsList.Add(subject, 0); }); StudentList.Add(newStudent); } UpdateTable(); }
public MainWindow() { InitializeComponent(); MyWCFServiceClient srv = new MyWCFServiceClient(); Student stu = srv.StudentSelectByID(1); StudentList students = srv.StudentSelectAll(); String str = ""; students.ForEach(s => str += s.FirstName + " "); MessageBox.Show(str); //MessageBox.Show(stu == null ? "is null !!!" : stu.City.Name + " " + stu.FirstName); //string s = srv.GetData(3); //MessageBox.Show(s); //System.Diagnostics.Debug.WriteLine("ABC:" + stu.FirstName); //MessageBox.Show(stu == null?"null":stu.FirstName); }
public void UpdateTable() { Table.Rows.Clear(); Table.Columns.Clear(); Table.CellValueChanged -= UpdateData; List <int> removeSubjects = new List <int>(); SubjectsList.ForEach(subject => { Subject subjectInfo = Subjects.GetSubjectByID(subject); if (subjectInfo == null) { removeSubjects.Add(subject); } }); removeSubjects.ForEach(remove => { RemoveSubject(remove, false); }); SubjectsList.ForEach(subject => { Subject subjectInfo = Subjects.GetSubjectByID(subject); DataGridViewColumn newCol = new DataGridViewColumn() { Name = subjectInfo.Id.ToString(), HeaderText = subjectInfo.Title, SortMode = DataGridViewColumnSortMode.NotSortable, CellTemplate = new DataGridViewTextBoxCell() }; Table.Columns.Add(newCol); }); DataGridViewColumn averageAssessmentCol = new DataGridViewColumn { ReadOnly = true, HeaderText = "Средняя оценка", CellTemplate = new DataGridViewTextBoxCell(), DefaultCellStyle = new DataGridViewCellStyle { BackColor = System.Drawing.Color.FromArgb(200, 200, 200) } }; Table.Columns.Add(averageAssessmentCol); DataGridViewColumn stipendCol = new DataGridViewColumn { ReadOnly = true, HeaderText = "Стипендия", CellTemplate = new DataGridViewTextBoxCell(), }; Table.Columns.Add(stipendCol); List <int> removeStudents = new List <int>(); StudentList.ForEach(student => { Student studentInfo = Students.GetStudentByID(student.IdStudent); if (studentInfo == null) { removeStudents.Add(student.IdStudent); } }); removeStudents.ForEach(remove => { RemoveStudent(remove, false); }); StudentList.ForEach(student => { Student studentInfo = Students.GetStudentByID(student.IdStudent); DataGridViewRow row = new DataGridViewRow(); string studentName = studentInfo.FullName + " (" + Groups.GetGroupByID(studentInfo.Id_Group).Number + ")"; row.HeaderCell.Value = studentName; row.Tag = student; Table.Rows.Add(row); int RowHeaderWidth = 9 * studentName.Length; if (RowHeaderWidth > Table.RowHeadersWidth) { Table.RowHeadersWidth = RowHeaderWidth; } }); int i = 0, j = 0; StudentList.ForEach(stud => { j = 0; double averageAssessment = 0; double assessmentCounr = 0; SubjectsList.ForEach(subj => { int assessments = stud.AssessmentsList[subj]; averageAssessment += assessments; assessmentCounr++; Table[j, i].Value = assessments; j++; }); averageAssessment /= assessmentCounr; Table[j, i].Value = Math.Round(averageAssessment, 2); Student student = Students.GetStudentByID(stud.IdStudent); double allowance = 0; if (averageAssessment >= 9 && student.Active_Participation) { allowance = 1.5; Table[j + 1, i].Style.BackColor = System.Drawing.Color.FromArgb(28, 193, 243); } else if (averageAssessment >= 9) { allowance = 1.25; Table[j + 1, i].Style.BackColor = System.Drawing.Color.FromArgb(80, 216, 103); } else if (averageAssessment > 5) { allowance = 1; } else { Table[j + 1, i].Style.BackColor = System.Drawing.Color.FromArgb(253, 81, 81); } Double.TryParse(StipendBox.Text, out double stipend); stipend *= allowance; Table[j + 1, i].Value = Math.Round(stipend, 2); i++; }); Table.CellValueChanged += UpdateData; }