Exemple #1
0
        private void FillAllWishesAsEmpty_Click(object sender, EventArgs e)
        {
            if (_tokenSource != null)
            {
                _tokenSource.Cancel();
            }

            _cToken = _tokenSource.Token;

            Task.Factory.StartNew(() =>
            {
                
                progress.BeginInvoke(new Action(() => progress.Text = "Удаление"));
                var wishIds = _repo.TeacherWishes.GetAllTeacherWishes().Select(tw => tw.TeacherWishId).ToList();
                var wishCount = wishIds.Count;
                for (int i = 0; i < wishIds.Count; i++)                
                {
                    _repo.TeacherWishes.RemoveTeacherWish(wishIds[i]);

                    if (i % 500 == 0)
                    {
                        int counter = i;
                        progress.BeginInvoke(new Action(() => progress.Text = "Удаление - " + counter + " / " + wishCount));
                    }
                }

                progress.BeginInvoke(new Action(() => progress.Text = "Удаление звонков преподавателей"));

                foreach (var ring in _repo.CustomTeacherAttributes.GetFiltredCustomTeacherAttributes(attr => attr.Key == "TeacherRing"))
                {
                    _repo.CustomTeacherAttributes.RemoveCustomTeacherAttribute(ring.CustomTeacherAttributeId);
                }

                var standard80RingsStrings = new List<string>
                {"8:00", "9:25", "11:05", "12:35", "14:00", "15:40", "17:05", "18:35"};

                var rings = _repo.Rings.GetFiltredRings(r => standard80RingsStrings.Contains(r.Time.ToString("H:mm"))).ToList();

                var teachers = _repo.Teachers.GetAllTeachers().OrderBy(t => t.FIO).ToList();
                var teachersCount = teachers.Count;

                
                for (int i = 0; i < teachersCount; i++)
                {                
                    var teacher = teachers[i];

                    int counter = i;
                    progress.BeginInvoke(new Action(() => progress.Text = teacher.FIO + " " + counter + " / " + teachersCount + " = " + (counter / teachersCount).ToString("F2")));

                    foreach (var ring in rings)
                    {
                        var newRing = new CustomTeacherAttribute(teacher, "TeacherRing", ring.RingId.ToString(CultureInfo.InvariantCulture));

                        _repo.CustomTeacherAttributes.AddCustomTeacherAttribute(newRing);
                    }

                    foreach (var calendar in _repo.Calendars.GetAllCalendars().OrderBy(c => c.Date.Date))
                    {
                        foreach (var ring in rings)
                        {
                            var newWish = new TeacherWish(teacher, calendar, ring, 0);

                            _repo.TeacherWishes.AddTeacherWish(newWish);
                        }
                    }
                }

                progress.BeginInvoke(new Action(() => progress.Text = ""));
            }, _cToken);            
        }       
Exemple #2
0
        private void wishesView_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if ((e.RowIndex == -1) || (e.ColumnIndex == -1))
            {
                return;
            }

            var dow = e.ColumnIndex - 1;

            var teacher = ((List<Teacher>)teacherList.DataSource)[teacherList.SelectedIndex];

            DataGridViewCell cell = wishesView.Rows[e.RowIndex].Cells[e.ColumnIndex];

            var textSaved = cell.Value.ToString();

            bool correct = true;

            int simpleWish;
            if (int.TryParse(cell.Value.ToString(), out simpleWish))
            {
                var calendars = _repo.Calendars.GetDowCalendars(dow);

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

                foreach (var calendar in calendars)
                {
                    var teacherWish = new TeacherWish(teacher, calendar, ring, simpleWish);

                    _repo.TeacherWishes.AddOrUpdateTeacherWish(teacherWish);
                }

                var cToken = _tokenSource.Token;
                Task.Run(new Action(() => RefreshWishes(teacher, cToken)));

                return;
            }
            
            var wishesParts = cell.Value.ToString()
                .Split(';')
                .Select(p => p.Replace(" ", string.Empty));

            foreach (var item in wishesParts)
            {
                var wishParts = item.Split('@');

                if (wishParts.Count() != 2)
                {
                    correct = false;
                    break;
                }
                
                try 
	            {
                    var weeks = CommonFunctions.WeeksStringToList(wishParts[0]);
                    var wish = int.Parse(wishParts[1]);                    

                    foreach (var week in weeks)
                    {
                        var calendar = _repo.CommonFunctions.GetCalendarFromDowAndWeek(dow, week);
                        var ring = _repo.Rings.GetRing(((List<RingWeekView>)wishesView.DataSource)[e.RowIndex].RingId);

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

                        _repo.TeacherWishes.AddOrUpdateTeacherWish(teacherWish);
                    }

	            }
	            catch
	            {
                    correct = false;
                    break;
	            }                
            }

            if (correct)
            {
                var cToken = _tokenSource.Token;
                Task.Run(new Action(() => RefreshWishes(teacher, cToken)));
            }
            else
            {
                cell.Value = textSaved;
                MessageBox.Show(cell.Value.ToString(), "Неправильный формат");
            }
        }
Exemple #3
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);
                }
            }
        }
Exemple #4
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);                    
                }
            }
        }