private void AddClick(object sender, EventArgs e) { int sOrder; int.TryParse(SortingOrder.Text, out sOrder); var newFaculty = new Faculty(FacultyName.Text, FacultyLetter.Text, sOrder); _repo.AddFaculty(newFaculty); RefreshView(RefreshType.FacultiesOnly); }
private void AddClick(object sender, EventArgs e) { int sOrder; int.TryParse(SortingOrder.Text, out sOrder); var newFaculty = new Faculty(FacultyName.Text, FacultyLetter.Text, sOrder, TitleOfSemesterScheduleSigner.Text, SemesterScheduleSigner.Text, TitleOfSessionScheduleSigner.Text, SessionScheduleSigner.Text); _repo.Faculties.AddFaculty(newFaculty); RefreshView(RefreshType.FacultiesOnly); }
public GroupsInFaculty FindGroupsInFaculty(StudentGroup sg, Faculty f) { using (var context = new ScheduleContext(ConnectionString)) { return context.GroupsInFaculties .Include(gif => gif.StudentGroup) .Include(gif => gif.Faculty) .FirstOrDefault(gif => gif.StudentGroup.StudentGroupId == sg.StudentGroupId && gif.Faculty.FacultyId == f.FacultyId); } }
public Faculty AddFaculty(Faculty faculty) { using (var context = new ScheduleContext(ConnectionString)) { faculty.FacultyId = 0; context.Faculties.Add(faculty); context.SaveChanges(); return faculty; } }
public void UpdateFaculty(Faculty faculty) { using (var context = new ScheduleContext(ConnectionString)) { var curFaculty = context.Faculties.FirstOrDefault(f => f.FacultyId == faculty.FacultyId); curFaculty.Name = faculty.Name; curFaculty.Letter = faculty.Letter; curFaculty.SortingOrder = faculty.SortingOrder; curFaculty.DeanSigningSchedule = faculty.DeanSigningSchedule; curFaculty.ScheduleSigningTitle = faculty.ScheduleSigningTitle; curFaculty.DeanSigningSessionSchedule = faculty.DeanSigningSessionSchedule; curFaculty.SessionSigningTitle = faculty.SessionSigningTitle; context.SaveChanges(); } }
private static Table GetAndPutDowStartSchedule(ScheduleRepository repo, int lessonLength, int dayOfWeek, bool weekFiltered, int weekFilter, bool weeksMarksVisible, Faculty faculty, _Document oDoc, object oEndOfDoc, _Application oWord, CancellationToken cToken) { cToken.ThrowIfCancellationRequested(); var schedule = repo.Lessons.GetFacultyDowSchedule(faculty.FacultyId, dayOfWeek, weekFiltered, weekFilter, false, false); cToken.ThrowIfCancellationRequested(); var timeList = new List<string>(); foreach (var group in schedule) { foreach (var time in @group.Value.Keys) { if (!timeList.Contains(time)) { timeList.Add(time); } } } Range wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range; Table oTable = oDoc.Tables.Add(wrdRng, 1 + timeList.Count, 1 + (schedule.Count * 2)); oTable.Borders.Enable = 1; oTable.Range.ParagraphFormat.SpaceAfter = 0.0F; oTable.Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft; oTable.Range.Font.Size = 11; oTable.Range.Font.Bold = 0; oTable.Columns[1].Width = oWord.CentimetersToPoints(2.44f); float colWidth = 25.64F / schedule.Count; for (int i = 0; i < schedule.Count * 2; i += 2) { oTable.Columns[i + 2].Width = oWord.CentimetersToPoints(colWidth - 1.1f); oTable.Columns[i + 3].Width = oWord.CentimetersToPoints(1.1f); } oTable.Range.Font.Underline = WdUnderline.wdUnderlineNone; oTable.Cell(1, 1).Range.Text = "Время занятий";//Constants.DOWLocal[dayOfWeek]; oTable.Cell(1, 1).Range.Font.Bold = 1; oTable.Cell(1, 1).Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter; int groupColumn = 2; foreach (var group in schedule) { var groupObject = repo.StudentGroups.GetStudentGroup(@group.Key); var groupName = groupObject.Name; oTable.Cell(1, groupColumn).Range.Text = groupName; oTable.Cell(1, groupColumn).Range.Font.Bold = 1; oTable.Cell(1, groupColumn).Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter; oTable.Cell(1, groupColumn).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter; oTable.Cell(1, groupColumn + 1).Range.Text = "Ауд"; oTable.Cell(1, groupColumn + 1).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter; groupColumn += 2; } var timeRowIndexList = new List<int>(); var timeRowIndex = 2; foreach (var time in timeList.OrderBy(t => int.Parse(t.Split(':')[0]) * 60 + int.Parse(t.Split(':')[1]))) { cToken.ThrowIfCancellationRequested(); var hour = int.Parse(time.Substring(0, 2)); var minute = int.Parse(time.Substring(3, 2)); minute += lessonLength; while (minute >= 60) { hour++; minute -= 60; } timeRowIndexList.Add(timeRowIndex); oTable.Cell(timeRowIndex, 1).Range.Text = time + "-" + hour.ToString("D2") + ":" + minute.ToString("D2"); oTable.Cell(timeRowIndex, 1).Range.Font.Bold = 1; oTable.Cell(timeRowIndex, 1).Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter; oTable.Cell(timeRowIndex, 1).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter; var columnGroupIndex = 2; foreach (var group in schedule) { if (@group.Value.ContainsKey(time)) { oTable.Cell(timeRowIndex, columnGroupIndex).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter; var groupDowTimeLessons = @group.Value[time] .OrderBy(tfd => tfd.Value.Item2.Select(l => repo.CommonFunctions.CalculateWeekNumber(l.Item1.Calendar.Date)).Min()) .ToList(); var tfdIndex = 0; if (groupDowTimeLessons.Count() == 2) { if (groupDowTimeLessons[0].Value.Item1.Contains("(чёт.") && groupDowTimeLessons[1].Value.Item1.Contains("(нечёт.")) { var tmp = groupDowTimeLessons[0]; groupDowTimeLessons[0] = groupDowTimeLessons[1]; groupDowTimeLessons[1] = tmp; } } if ( ((@group.Value[time].Count == 2) && ((groupDowTimeLessons[0].Value.Item1.Contains("нечёт.")) && (groupDowTimeLessons[1].Value.Item1.Contains("чёт.")))) || ((@group.Value[time].Count == 1) && (groupDowTimeLessons[0].Value.Item1.Contains("чёт.")))) { var rng = oTable.Cell(timeRowIndex, columnGroupIndex).Range; rng.Borders[WdBorderType.wdBorderDiagonalUp].LineStyle = WdLineStyle.wdLineStyleSingle; } var groupObject = repo.StudentGroups.GetStudentGroup(@group.Key); var subGroupOne = repo.StudentGroups.GetFirstFiltredStudentGroups(sg => sg.Name == groupObject.Name + "1"); var subGroupTwo = repo.StudentGroups.GetFirstFiltredStudentGroups(sg => sg.Name == groupObject.Name + "2"); if (groupDowTimeLessons.Count() == 2) { if (((subGroupOne != null) && (subGroupTwo != null)) && ((groupDowTimeLessons[0].Value.Item2[0].Item1.TeacherForDiscipline.Discipline.StudentGroup.StudentGroupId == subGroupTwo.StudentGroupId) && (groupDowTimeLessons[1].Value.Item2[0].Item1.TeacherForDiscipline.Discipline.StudentGroup.StudentGroupId == subGroupOne.StudentGroupId))) { var tmp = groupDowTimeLessons[0]; groupDowTimeLessons[0] = groupDowTimeLessons[1]; groupDowTimeLessons[1] = tmp; } } var addSubGroupColumn = 0; if ((groupDowTimeLessons.Count() == 1) && (subGroupOne != null) && (groupDowTimeLessons[0].Value.Item2[0].Item1.TeacherForDiscipline.Discipline.StudentGroup.StudentGroupId == subGroupOne.StudentGroupId)) { addSubGroupColumn = 1; var emptytfd = new KeyValuePair<int, Tuple<string, List<Tuple<Lesson, int>>, string>>(-1, null); groupDowTimeLessons.Add(emptytfd); } if ((groupDowTimeLessons.Count() == 1) && (subGroupTwo != null) && (groupDowTimeLessons[0].Value.Item2[0].Item1.TeacherForDiscipline.Discipline.StudentGroup.StudentGroupId == subGroupTwo.StudentGroupId)) { addSubGroupColumn = 1; var emptytfd = new KeyValuePair<int, Tuple<string, List<Tuple<Lesson, int>>, string>>(-1, null); groupDowTimeLessons.Add(emptytfd); var tmp = groupDowTimeLessons[0]; groupDowTimeLessons[0] = groupDowTimeLessons[1]; groupDowTimeLessons[1] = tmp; } var timeTable = oDoc.Tables.Add(oTable.Cell(timeRowIndex, columnGroupIndex).Range, 1, @group.Value[time].Count + addSubGroupColumn); if (!((groupDowTimeLessons.Count == 2) && (((groupDowTimeLessons[0].Value != null) && (groupDowTimeLessons[1].Value != null)) && ((groupDowTimeLessons[0].Value.Item1.Contains("нечёт.")) && (groupDowTimeLessons[1].Value.Item1.Contains("чёт.")))))) { for (int i = 0; i < groupDowTimeLessons.Count - 1; i++) { timeTable.Cell(1, i + 1).Borders[WdBorderType.wdBorderRight].Visible = true; } } timeTable.Range.ParagraphFormat.SpaceAfter = 0.0F; timeTable.Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft; timeTable.Range.Font.Size = 10; timeTable.Range.Font.Bold = 0; foreach (var tfdData in groupDowTimeLessons) { var cellText = ""; if (tfdData.Value == null) { tfdIndex++; continue; } var discName = tfdData.Value.Item2[0].Item1.TeacherForDiscipline.Discipline.Name; var shorteningDictionary = new Dictionary<string, string> { {"Английский язык", "Англ. яз."}, {"Немецкий язык", "Нем. яз."}, {"Французский язык", "Франц. яз."} }; if (shorteningDictionary.ContainsKey(discName)) { discName = shorteningDictionary[discName]; } // Discipline name cellText += discName + Environment.NewLine; // Teacher FIO var ommitInitials = @group.Value[time].Count != 1; String teacherFio = ShortenFio(tfdData.Value.Item2[0].Item1.TeacherForDiscipline.Teacher.FIO, ommitInitials); cellText += teacherFio; // Total weeks if (weeksMarksVisible) { /* if (tfdData.Value.Item1.Contains("(чёт.")) { cellText += "(чёт.)" + Environment.NewLine; } if (tfdData.Value.Item1.Contains("(нечёт.")) { cellText += "(нечёт.)" + Environment.NewLine; } */ //cellText += "(" + tfdData.Value.Item1 + ")" + Environment.NewLine; } String audText = ""; // Auditoriums var audWeekList = tfdData.Value.Item2.ToDictionary(l => repo.CommonFunctions.CalculateWeekNumber(l.Item1.Calendar.Date), l => l.Item1.Auditorium.Name); var grouped = audWeekList.GroupBy(a => a.Value); var enumerable = grouped as List<IGrouping<string, KeyValuePair<int, string>>> ?? grouped.ToList(); var gcount = enumerable.Count(); if (gcount == 1) { audText += ShortenAudName(enumerable.ElementAt(0).Key); } else { for (int j = 0; j < gcount; j++) { var jItem = enumerable.OrderBy(e => e.Select(ag => ag.Key).ToList().Min()).ElementAt(j); audText += CommonFunctions.CombineWeeks(jItem.Select(ag => ag.Key).ToList()) + " - " + ShortenAudName(jItem.Key); if (j != gcount - 1) { audText += Environment.NewLine; } } } if ((groupDowTimeLessons.Count == 1) && (groupDowTimeLessons[0].Value.Item1.Contains("(чёт."))) { cellText = Environment.NewLine + cellText; } if ((groupDowTimeLessons.Count == 1) && (groupDowTimeLessons[0].Value.Item1.Contains("(нечёт."))) { cellText = cellText + Environment.NewLine; } //Auditoriums timeTable.Cell(1, tfdIndex + 1).Range.Text = cellText; timeTable.Cell(1, tfdIndex + 1).Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter; /* * FIO in one line var lineSpacing = timeTable.Cell(1, tfdIndex + 1).Range.ParagraphFormat.LineSpacing; var Height = timeTable.Cell(1, tfdIndex + 1).Height; if (Height > lineSpacing * 2) { } */ timeTable.Cell(1, tfdIndex + 1).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter; var audCellText = oTable.Cell(timeRowIndex, columnGroupIndex + 1).Range.Text; if (audCellText == "\r\a") { oTable.Cell(timeRowIndex, columnGroupIndex + 1).Range.Text = audText; } else { oTable.Cell(timeRowIndex, columnGroupIndex + 1).Range.Text = audCellText + "/ " + audText; } oTable.Cell(timeRowIndex, columnGroupIndex + 1).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter; if ((@group.Value[time].Count == 2) && ((groupDowTimeLessons[0].Value.Item1.Contains("нечёт.")) && (groupDowTimeLessons[1].Value.Item1.Contains("чёт.")))) { timeTable.Cell(1, tfdIndex + 1).Range.ParagraphFormat.Alignment = (tfdIndex == 0) ? WdParagraphAlignment.wdAlignParagraphLeft : WdParagraphAlignment.wdAlignParagraphRight; } if ((groupDowTimeLessons.Count == 1) && (groupDowTimeLessons[0].Value.Item1.Contains("(чёт."))) { timeTable.Cell(1, tfdIndex + 1).Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphRight; } tfdIndex++; } } columnGroupIndex += 2; } timeRowIndex++; } return oTable; }
private static Table GetAndPutDowSchedule(ScheduleRepository repo, int lessonLength, int dayOfWeek, bool weekFiltered, int weekFilter, bool weeksMarksVisible, Faculty faculty, _Document oDoc, object oEndOfDoc, _Application oWord, Table tableToContinue, CancellationToken cToken) { cToken.ThrowIfCancellationRequested(); var schedule = repo.Lessons.GetFacultyDowSchedule(faculty.FacultyId, dayOfWeek, weekFiltered, weekFilter, false, false); cToken.ThrowIfCancellationRequested(); var timeList = new List<string>(); foreach (var group in schedule) { foreach (var time in @group.Value.Keys) { if (!timeList.Contains(time)) { timeList.Add(time); } } } Range wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range; Table oTable; var tableRowOffset = 0; if (tableToContinue == null) { oTable = oDoc.Tables.Add(wrdRng, 1 + timeList.Count, 1 + schedule.Count); oTable.Borders.Enable = 1; oTable.Range.ParagraphFormat.SpaceAfter = 0.0F; oTable.Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft; oTable.Range.Font.Size = 10; oTable.Range.Font.Bold = 0; oTable.Columns[1].Width = oWord.CentimetersToPoints(2.44f); float colWidth = 25.64F / schedule.Count; for (int i = 0; i < schedule.Count; i++) { oTable.Columns[i + 2].Width = oWord.CentimetersToPoints(colWidth); } } else { oTable = tableToContinue; tableRowOffset = oTable.Rows.Count; for (int i = 0; i < 1 + timeList.Count; i++) { oTable.Rows.Add(); for (int j = 1; j <= 1 + schedule.Count; j++) { oTable.Cell(tableRowOffset + i + 1, j).Borders[WdBorderType.wdBorderDiagonalUp].Visible = false; } } } oTable.Cell(tableRowOffset + 1, 1).Range.Text = Constants.DowLocal[dayOfWeek]; oTable.Cell(tableRowOffset + 1, 1).Range.Bold = 1; oTable.Cell(tableRowOffset + 1, 1).Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter; int groupColumn = 2; foreach (var group in schedule) { var groupObject = repo.StudentGroups.GetStudentGroup(@group.Key); var groupName = groupObject.Name; oTable.Cell(tableRowOffset + 1, groupColumn).Range.Text = groupName; oTable.Cell(tableRowOffset + 1, groupColumn).Range.Bold = 1; oTable.Cell(tableRowOffset + 1, groupColumn).Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter; groupColumn++; } var timeRowIndexList = new List<int>(); var timeRowIndex = 2; foreach (var time in timeList.OrderBy(t => int.Parse(t.Split(':')[0]) * 60 + int.Parse(t.Split(':')[1]))) { cToken.ThrowIfCancellationRequested(); var hour = int.Parse(time.Substring(0, 2)); var minute = int.Parse(time.Substring(3, 2)); minute += lessonLength; while (minute >= 60) { hour++; minute -= 60; } timeRowIndexList.Add(timeRowIndex); oTable.Cell(tableRowOffset + timeRowIndex, 1).Range.Text = time + " - " + hour.ToString("D2") + ":" + minute.ToString("D2"); oTable.Cell(tableRowOffset + timeRowIndex, 1).Range.Bold = 1; oTable.Cell(tableRowOffset + timeRowIndex, 1).Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter; oTable.Cell(tableRowOffset + timeRowIndex, 1).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter; var columnGroupIndex = 2; foreach (var group in schedule) { if (@group.Value.ContainsKey(time)) { oTable.Cell(tableRowOffset + timeRowIndex, columnGroupIndex).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter; var groupDowTimeLessons = @group.Value[time] .OrderBy(tfd => tfd.Value.Item2.Select(l => repo.CommonFunctions.CalculateWeekNumber(l.Item1.Calendar.Date)).Min()) .ToList(); var groupObject = repo.StudentGroups.GetStudentGroup(@group.Key); var subgroupIds = new List<int>(); var subGroupOne = repo.StudentGroups.GetFirstFiltredStudentGroups(sg => sg.Name == groupObject.Name + "1"); if (subGroupOne != null) subgroupIds.Add(subGroupOne.StudentGroupId); var subGroupTwo = repo.StudentGroups.GetFirstFiltredStudentGroups(sg => sg.Name == groupObject.Name + "2"); if (subGroupTwo != null) subgroupIds.Add(subGroupTwo.StudentGroupId); var subgroups = false; var groupIds = groupDowTimeLessons.Select( l => l.Value.Item2[0].Item1.TeacherForDiscipline.Discipline.StudentGroup .StudentGroupId).ToList(); if (groupIds.Intersect(subgroupIds).Count() > 0) { subgroups = true; } Table subgroupsTable = null; Table timeTable = null; List<KeyValuePair<int, Tuple<string, List<Tuple<Lesson, int>>, string>>> group1Items = null; if (subGroupOne != null) { group1Items = groupDowTimeLessons.Where( l => l.Value.Item2[0].Item1.TeacherForDiscipline.Discipline.StudentGroup .StudentGroupId == subGroupOne.StudentGroupId).ToList(); } List<KeyValuePair<int, Tuple<string, List<Tuple<Lesson, int>>, string>>> group2Items = null; if (subGroupTwo != null) { group2Items = groupDowTimeLessons.Where( l => l.Value.Item2[0].Item1.TeacherForDiscipline.Discipline.StudentGroup .StudentGroupId == subGroupTwo.StudentGroupId).ToList(); } if (subgroups) { subgroupsTable = oDoc.Tables.Add(oTable.Cell(tableRowOffset + timeRowIndex, columnGroupIndex).Range, 1, 2); subgroupsTable.Cell(1, 1).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter; subgroupsTable.Cell(1, 2).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter; subgroupsTable.Cell(1, 1).Borders[WdBorderType.wdBorderRight].Visible = true; PutDowSchedulePutGroupOrSubGroupDowTimeItem(repo, oDoc, subgroupsTable.Cell(1, 1), group1Items, true); PutDowSchedulePutGroupOrSubGroupDowTimeItem(repo, oDoc, subgroupsTable.Cell(1, 2), group2Items, true); } else { PutDowSchedulePutGroupOrSubGroupDowTimeItem(repo, oDoc, oTable.Cell(tableRowOffset + timeRowIndex, columnGroupIndex), groupDowTimeLessons, false); } } columnGroupIndex++; } timeRowIndex++; } return oTable; }