예제 #1
0
        public static void TeachersSchedule(ScheduleRepository repo, TeacherSchedule tsForm, bool OnlyFutureDates, CancellationToken cToken)
        {
            var teachers = repo.Teachers.GetAllTeachers().OrderBy(t => t.FIO).ToList();

            object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */
            int pageCounter = 0;

            //Start Word and create a new document.
            _Application oWord = new Application { Visible = true };
            _Document oDoc = oWord.Documents.Add();

            oDoc.PageSetup.Orientation = WdOrientation.wdOrientPortrait;
            oDoc.PageSetup.TopMargin = oWord.CentimetersToPoints(1);
            oDoc.PageSetup.BottomMargin = oWord.CentimetersToPoints(1);
            oDoc.PageSetup.LeftMargin = oWord.CentimetersToPoints(1);
            oDoc.PageSetup.RightMargin = oWord.CentimetersToPoints(1);

            foreach (var teacher in teachers)
            {
                var result = tsForm.GetTeacherScheduleToView(teacher.TeacherId, false, -1, false, OnlyFutureDates, cToken);

                var isColumnEmpty = GetEmptyColumnIndexes(result);
                var columnTitles = new List<string>();
                var columnIndexes = new List<int>();
                for (int i = 1; i <= 7; i++)
                {
                    if (!isColumnEmpty[i])
                    {
                        columnTitles.Add(Constants.DowLocal[i]);
                        columnIndexes.Add(i);
                    }
                }

                Paragraph oPara1 = oDoc.Content.Paragraphs.Add();
                oPara1.Range.Text = "Расписание СГОАН (" + teacher.FIO + ")";
                oPara1.Range.Font.Bold = 0;
                oPara1.Range.Font.Size = 10;
                oPara1.Range.ParagraphFormat.LineSpacingRule =
                    WdLineSpacing.wdLineSpaceSingle;
                oPara1.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
                oPara1.SpaceAfter = 0;
                oPara1.Range.InsertParagraphAfter();

                Range wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;

                var dowCount = isColumnEmpty.Count(dow => !dow.Value);

                Table oTable = oDoc.Tables.Add(wrdRng, 1 + result.Count, 1 + dowCount);
                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.Cell(1, 1).Range.Text = "Время";
                oTable.Cell(1, 1).Range.ParagraphFormat.Alignment =
                            WdParagraphAlignment.wdAlignParagraphCenter;

                oTable.Columns[1].Width = oWord.CentimetersToPoints(2.44f);
                float colWidth = 16.3F / dowCount;
                for (int i = 0; i < dowCount; i++)
                {
                    oTable.Columns[i + 2].Width = oWord.CentimetersToPoints(colWidth);
                    oTable.Cell(1, i + 2).Range.Text = columnTitles[i];
                    oTable.Cell(1, i + 2).Range.ParagraphFormat.Alignment =
                            WdParagraphAlignment.wdAlignParagraphCenter;
                }

                for (int i = 0; i < result.Count; i++)
                {
                    oTable.Cell(2 + i, 1).Range.Text = result[i].Time;
                    oTable.Cell(2 + i, 1).Range.ParagraphFormat.Alignment =
                                WdParagraphAlignment.wdAlignParagraphCenter;
                    oTable.Cell(2 + i, 1).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;

                    for (int j = 0; j < dowCount; j++)
                    {
                        var dowIndex = columnIndexes[j];
                        switch (dowIndex)
                        {
                            case 1:
                                oTable.Cell(2 + i, 2 + j).Range.Text = result[i].MonLessons;
                                break;
                            case 2:
                                oTable.Cell(2 + i, 2 + j).Range.Text = result[i].TueLessons;
                                break;
                            case 3:
                                oTable.Cell(2 + i, 2 + j).Range.Text = result[i].WedLessons;
                                break;
                            case 4:
                                oTable.Cell(2 + i, 2 + j).Range.Text = result[i].ThuLessons;
                                break;
                            case 5:
                                oTable.Cell(2 + i, 2 + j).Range.Text = result[i].FriLessons;
                                break;
                            case 6:
                                oTable.Cell(2 + i, 2 + j).Range.Text = result[i].SatLessons;
                                break;
                            case 7:
                                oTable.Cell(2 + i, 2 + j).Range.Text = result[i].SunLessons;
                                break;
                        }

                        oTable.Cell(2 + i, 2 + j).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;

                    }
                }

                pageCounter++;
                int pageCount;
                float fontSize = 10.5F;
                do
                {
                    fontSize -= 0.5F;
                    oTable.Range.Font.Size = fontSize;

                    if (fontSize <= 3)
                    {
                        break;
                    }

                    pageCount = oDoc.ComputeStatistics(WdStatistic.wdStatisticPages);
                } while (pageCount > pageCounter);

                var endOfDoc = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
                endOfDoc.Font.Size = 1;
                endOfDoc.InsertBreak(WdBreakType.wdSectionBreakNextPage);
            }

            oDoc.Undo();

            Marshal.ReleaseComObject(oWord);
        }
예제 #2
0
        private void ShowTeacherScheduleForm()
        {
            if (_teacherScheduleFormOpened)
            {
                TeacherScheduleForm.Activate();
                TeacherScheduleForm.Focus();
                return;
            }

            TeacherScheduleForm = new TeacherSchedule(Repo);
            _teacherScheduleFormOpened = true;
            TeacherScheduleForm.Show();
            _teacherScheduleFormOpened = false;
        }
예제 #3
0
 private void TeacherScheduleClick(object sender, EventArgs e)
 {
     var teacherScheduleForm = new TeacherSchedule(_repo);
     teacherScheduleForm.ShowDialog();
 }
예제 #4
0
        private void setLayout_Click(object sender, EventArgs e)
        {
            var width = Screen.PrimaryScreen.WorkingArea.Width;
            var height = Screen.PrimaryScreen.WorkingArea.Height;

            Top = 0;
            Left = 0;
            Width = width/2;
            Height = height/2;

            var allAudsForm = new Auditoriums(Repo);
            allAudsForm.Show();
            allAudsForm.Left = 0;
            allAudsForm.Top = height/2;
            allAudsForm.Width = width/2;
            allAudsForm.Height = height/2;

            var discListForm = new DisciplineList(Repo);
            discListForm.Show();
            discListForm.Left = width/2;
            discListForm.Top = 0;
            discListForm.Width = width/2;
            discListForm.Height = height/2;

            var teachersSchedule = new TeacherSchedule(Repo);
            teachersSchedule.Show();
            teachersSchedule.Left = width/2;
            teachersSchedule.Top = height/2;
            teachersSchedule.Width = width/2;
            teachersSchedule.Height = height/2;
        }