Example #1
0
        private void add_Click(object sender, EventArgs e)
        {
            if (_repo.Teachers.FindTeacher(teacherFIO.Text, teacherPhone.Text) != null)
            {
                MessageBox.Show("Такой преподаватель уже есть.");
                return;
            }

            var newTeacher = new Teacher { FIO = teacherFIO.Text, Phone = teacherPhone.Text };
            _repo.Teachers.AddTeacher(newTeacher);

            RefreshView((int)RefreshType.TeachersOnly);

            var teacherList = (List<Teacher>)TeacherListView.DataSource;
            var addedTeacher = teacherList.FirstOrDefault(t => t.FIO == newTeacher.FIO);

            var newIndex = -1;
            for (int i = 0; i < teacherList.Count; i++)
            {
                if (teacherList[i].FIO == newTeacher.FIO)
                {
                    newIndex = i;
                }
            }

            if (newIndex != -1)
            {
                TeacherListView.ClearSelection();
                TeacherListView.Rows[newIndex].Selected = true;
                TeacherListView.FirstDisplayedScrollingRowIndex = newIndex;
            }

            filter.Focus();
        }
Example #2
0
 public TeacherWish(Teacher teacher, Calendar calendar, Ring ring, int wish)
 {
     Teacher = teacher;
     Calendar = calendar;
     Ring = ring;
     Wish = wish;
 }
Example #3
0
        public ChooseRings(ScheduleRepository repo, Teacher teacher)
        {
            InitializeComponent();

            _repo = repo;
            _teacher = teacher;
        }
Example #4
0
        private void add_Click(object sender, EventArgs e)
        {
            if (_repo.FindTeacher(teacherFIO.Text, teacherPhone.Text) != null)
            {
                MessageBox.Show("Такой преподаватель уже есть.");
                return;
            }

            var newTeacher = new Teacher { FIO = teacherFIO.Text, Phone = teacherPhone.Text };
            _repo.AddTeacher(newTeacher);

            RefreshView((int)refreshType.teachersOnly);

            TeacherListView.ClearSelection();
            TeacherListView.Rows[TeacherListView.Rows.Count - 1].Selected = true;
            TeacherListView.FirstDisplayedScrollingRowIndex = TeacherListView.RowCount - 1;

            filter.Focus();
        }
 public List<Discipline> GetTeacherDisciplines(Teacher teacher)
 {
     using (var context = new ScheduleContext(ConnectionString))
     {
         return context.TeacherForDiscipline
             .Where(tfd => tfd.Teacher.TeacherId == teacher.TeacherId)
             .Select(tefd => tefd.Discipline)
             .Include(d => d.StudentGroup)
             .ToList();
     }
 }
 public TeacherForDiscipline FindTeacherForDiscipline(Teacher t, Discipline d)
 {
     using (var context = new ScheduleContext(ConnectionString))
     {
         return context.TeacherForDiscipline.Include(tfd => tfd.Teacher).Include(tfd => tfd.Discipline.StudentGroup).FirstOrDefault(tfd => tfd.Teacher.TeacherId == t.TeacherId && tfd.Discipline.DisciplineId == d.DisciplineId);
     }
 }
Example #7
0
        public static void TeacherSchedule(List<TeacherScheduleTimeView> result, Teacher teacher, bool landscape, CancellationToken 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);
                }
            }

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

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

            oDoc.PageSetup.Orientation = landscape ? WdOrientation.wdOrientLandscape : 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);

            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 = (landscape ? 25.64F : 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;

                }
            }

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

                if (fontSize <= 3)
                {
                    break;
                }

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

            Marshal.ReleaseComObject(oWord);
        }
Example #8
0
        private void RefreshTeacherDisciplines(Teacher teacher)
        {
            var teacherDisciplines = _repo.Disciplines.GetTeacherDisciplines(teacher);

            var discView = DisciplineView.DisciplinesToView(_repo, teacherDisciplines);

            TFDListView.DataSource = discView;

            TFDListView.Columns["DisciplineId"].Visible = false;
            TFDListView.Columns["Name"].Width = 270;
            TFDListView.Columns["Attestation"].Width = 80;
            TFDListView.Columns["AuditoriumHours"].Width = 80;
            TFDListView.Columns["LectureHours"].Width = 80;
            TFDListView.Columns["PracticalHours"].Width = 80;
            TFDListView.Columns["StudentGroupName"].Width = 80;

            TFDListView.ClearSelection();
        }
 public CustomTeacherAttribute(Teacher teacher, string key, string value)
 {
     Teacher = teacher;
     Key = key;
     Value = value;
 }
Example #10
0
        private void RefreshRings(Teacher teacher, CancellationToken cToken)
        {
            _listBoxInitialization = true;
            
            var teacherRingIds = _repo
                .CustomTeacherAttributes
                .GetFiltredCustomTeacherAttributes(cta => (cta.Teacher.TeacherId == teacher.TeacherId) && (cta.Key == "TeacherRing"))
                .Select(cta => int.Parse(cta.Value))
                .ToList();

            var allRingViews = RingView.RingsToView(_repo.Rings.GetAllRings().OrderBy(r => r.Time.TimeOfDay).ToList());

            RingsList.BeginInvoke(new Action(() => {
                RingsList.ValueMember = "RingId";
                RingsList.DisplayMember = "Time";
                RingsList.DataSource = allRingViews;

                RingsList.ClearSelected();

                for (int i = 0; i < RingsList.Items.Count; i++)
                {
                    var ringId = allRingViews[i].RingId;

                    if (teacherRingIds.Contains(ringId))
                    {
                        RingsList.SetSelected(i, true);
                    }
                }
            }));
            
            _listBoxInitialization = false;
        }
Example #11
0
        private void SetSelectionWish(Teacher teacher, int wishValue, DataGridViewSelectedCellCollection collection, CancellationToken cToken)
        {
            for (int i = 0; i < collection.Count; i++)
            {
                var cell = collection[i];
                var dow = cell.ColumnIndex - 1;

                if (cell.ColumnIndex <= 1)
                {
                    continue;
                }

                var calendars = _repo.Calendars.GetDowCalendars(dow);

                cToken.ThrowIfCancellationRequested();

                var ring = _repo.Rings.GetRing(((List<RingWeekView>)wishesView.DataSource)[cell.RowIndex].RingId);

                cToken.ThrowIfCancellationRequested();

                foreach (var calendar in calendars)
                {
                    cToken.ThrowIfCancellationRequested();

                    var teacherWish = new TeacherWish(teacher, calendar, ring, wishValue);

                    _repo.TeacherWishes.AddOrUpdateTeacherWish(teacherWish);
                }
            }
        }
Example #12
0
        private void SetTeacherWishesForTeacherRings(Teacher teacher, int wishAmount, CancellationToken cToken)
        {
            foreach (var calendar in _repo.Calendars.GetAllCalendars())
            {
                cToken.ThrowIfCancellationRequested();

                var rings = _repo
                    .CustomTeacherAttributes
                    .GetFiltredCustomTeacherAttributes(cta =>
                        cta.Teacher.TeacherId == teacher.TeacherId &&
                        cta.Key == "TeacherRing")
                    .Select(cta => _repo.Rings.GetRing(int.Parse(cta.Value)));

                foreach (var ring in rings)
                {
                    var wish = new TeacherWish(teacher, calendar, ring, wishAmount);

                    _repo.TeacherWishes.AddOrUpdateTeacherWish(wish);                    
                }
            }
        }
Example #13
0
        private void ShowWishes(List<RingWeekView> wishView, Teacher teacher)
        {
            wishesView.DataSource = wishView;

            var wish = _repo.CustomTeacherAttributes.GetCustomTeacherAttribute(teacher, "WindowsPossible");
            if (wish != null)
            {
                windowsPossible.Checked = true;
                windowsPossibleSize.Text = wish.Value;
            }

            wish = _repo.CustomTeacherAttributes.GetCustomTeacherAttribute(teacher, "LessonsLimit");
            if (wish != null)
            {
                LessonsLimitedPerDay.Checked = true;
                LessonsLimitPerDay.Text = wish.Value;
            }

            wish = _repo.CustomTeacherAttributes.GetCustomTeacherAttribute(teacher, "FitAllLessonsDaysCount");
            if (wish != null)
            {
                FitAllLessonsInXDays.Checked = true;
                FitAllLessonsDaysCount.Text = wish.Value;
            }
        }
Example #14
0
 private List<RingWeekView> RefreshWishes(Teacher teacher, CancellationToken cToken)
 {
     return RingWeekView.GetRingWeekView(_repo, teacher, cToken);
 }
        public void UpdateTeacher(Teacher teacher)
        {
            using (var context = new ScheduleContext(ConnectionString))
            {
                var curTeacher = context.Teachers.FirstOrDefault(t => t.TeacherId == teacher.TeacherId);

                curTeacher.FIO = teacher.FIO;
                curTeacher.Phone = teacher.Phone;

                context.SaveChanges();
            }
        }
        public Teacher AddTeacher(Teacher teacher)
        {
            using (var context = new ScheduleContext(ConnectionString))
            {
                teacher.TeacherId = 0;

                context.Teachers.Add(teacher);
                context.SaveChanges();

                return teacher;
            }
        }
Example #17
0
        public static List<RingWeekView> GetRingWeekView(ScheduleRepository repo, Teacher teacher, CancellationToken cToken)
        {
            var result = new List<RingWeekView>();

            cToken.ThrowIfCancellationRequested();

            var filteredWishes = repo
                .TeacherWishes
                .GetFiltredTeacherWishes(w => w.Teacher.TeacherId == teacher.TeacherId)
                .GroupBy(w => w.Ring.RingId, (ringId, ringWishes) =>
                    new
                    {
                        RingId = ringId,
                        RingWishes = ringWishes
                        .GroupBy(rw => Constants.DowRemap[(int)rw.Calendar.Date.DayOfWeek],
                        (dow, wishes) =>
                            new { dayOfWeek = dow, wishes })
                    }
                );

            cToken.ThrowIfCancellationRequested();

            foreach (var ringWishes in filteredWishes)
            {
                cToken.ThrowIfCancellationRequested();

                var ringWeekView = new RingWeekView {RingId = ringWishes.RingId};

                foreach (var dowWishes in ringWishes.RingWishes)
                {
                    switch(dowWishes.dayOfWeek)
                    {
                        case 1:
                            ringWeekView.MonWishes = WishesToString(repo, dowWishes.wishes);
                            break;
                        case 2:
                            ringWeekView.TueWishes = WishesToString(repo, dowWishes.wishes);
                            break;
                        case 3:
                            ringWeekView.WedWishes = WishesToString(repo, dowWishes.wishes);
                            break;
                        case 4:
                            ringWeekView.ThuWishes = WishesToString(repo, dowWishes.wishes);
                            break;
                        case 5:
                            ringWeekView.FriWishes = WishesToString(repo, dowWishes.wishes);
                            break;
                        case 6:
                            ringWeekView.SatWishes = WishesToString(repo, dowWishes.wishes);
                            break;
                        case 7:
                            ringWeekView.SunWishes = WishesToString(repo, dowWishes.wishes);
                            break;
                    }
                }

                ringWeekView.RingTime = repo.Rings.GetRing(ringWeekView.RingId).Time.ToString("HH:mm");

                result.Add(ringWeekView);
            }

            result = result.OrderBy(rwv => repo.Rings.GetRing(rwv.RingId).Time).ToList();

            return result;
        }