Ejemplo n.º 1
0
        public static TrainingDayPageContext CreateTrainingDayWindow(TrainingDayDTO day, UserDTO user, CustomerDTO customer, IEntryObjectBuilderProvider builder = null)
        {
            if (day.GlobalId == Constants.UnsavedGlobalId)
            {
                day.AllowComments = UserContext.Current.ProfileInformation.Settings.AllowTrainingDayComments;
                //set default entries for newly created TrainingDay
                var options = UserContext.Current.Settings.GuiState.CalendarOptions;
                foreach (var defaultEntry in options.DefaultEntries)
                {
                    if (defaultEntry.IsDefault == true)
                    {
                        var plugin = PluginsManager.Instance.GetEntryObjectProvider(defaultEntry.ModuleId);
                        if (plugin != null && plugin.EntryObjectType.CanBeManuallyAdded())
                        {
                            var entry = day.AddEntry(plugin.EntryObjectType);
                            if (builder != null)
                            {
                                builder.EntryObjectCreated(entry);
                            }
                            if (day.TrainingDate.IsFuture())
                            {//for entries in future set planned status
                                entry.Status = EntryObjectStatus.Planned;
                            }
                        }
                    }
                }
                //needed for SizeEntryDTO for example
                day.ChangeDate(day.TrainingDate);
            }
            TrainingDayPageContext context = new TrainingDayPageContext(user, customer, day, builder);

            return(context);
        }
Ejemplo n.º 2
0
        public void TestChangeDate()
        {
            DateTime       now     = DateTime.Now;
            DateTime       newDate = now.AddDays(2);
            TrainingDayDTO day     = new TrainingDayDTO(now);

            day.AddEntry(new MyEntry1());
            day.AddEntry(new MyEntry1());
            var entry3 = new MyEntry3();

            day.AddEntry(entry3);
            day.ChangeDate(newDate);
            Assert.AreEqual(newDate.Date, day.TrainingDate);
            Assert.AreEqual(newDate, entry3.NewDateTime);
        }
Ejemplo n.º 3
0
        private void monthCalendar1_DayDragDrop(object sender, DayDragDropEventArgs e)
        {
            try
            {
                TrainingDayDTO day = (TrainingDayDTO)e.Data.GetData(typeof(TrainingDayDTO));
                if ((e.KeyState & 8) == 8)
                {
                    //using (var scope = new TransactionScope())
                    //{
                    //    day = TrainingDay.GetById(day.Id);
                    //    var newDay = day.Copy();
                    //    if (newDay.Objects.Count == 0)
                    //    {
                    //        FMMessageBox.ShowError(ApplicationStrings.ErrorCannotCopyTrainingDayFixedEntries);
                    //        return;
                    //    }

                    //    newDay.ChangeDate(e.Date);
                    //    newDay.Save();
                    //    scope.VoteCommit();
                    //}
                    if (day.Id != Constants.UnsavedObjectId)
                    {//user select Cut operation so we should only move this one time (not many time like with Copy operation)
                        WorkoutDayGetOperation operation = new WorkoutDayGetOperation();
                        operation.UserId          = User.Id;
                        operation.Operation       = GetOperation.Current;
                        operation.WorkoutDateTime = day.TrainingDate;
                        day = ServiceManager.GetTrainingDay(operation);
                    }
                    day = day.Copy();
                    day.ChangeDate(e.Date);
                    ServiceManager.SaveTrainingDay(day);
                    this.Fill(User, e.Date);
                }
                else if (FMMessageBox.AskYesNo(ApplicationStrings.QMoveTrainingDay) == DialogResult.Yes)
                {
                    if (day.CanMove)
                    {
                        //using (var scope = new TransactionScope())
                        //{
                        //    day = TrainingDay.GetById(day.Id);
                        //    day.ChangeDate(e.Date);
                        //    day.Save();
                        //    scope.VoteCommit();
                        //}
                        if (day.Id != Constants.UnsavedObjectId)
                        {//user select Cut operation so we should only move this one time (not many time like with Copy operation)
                            WorkoutDayGetOperation operation = new WorkoutDayGetOperation();
                            operation.UserId          = User.Id;
                            operation.Operation       = GetOperation.Current;
                            operation.WorkoutDateTime = day.TrainingDate;
                            day = ServiceManager.GetTrainingDay(operation);
                        }
                        day.ChangeDate(e.Date);
                        ServiceManager.SaveTrainingDay(day);
                        this.Fill(User, e.Date);
                    }
                    else
                    {
                        FMMessageBox.ShowError(ApplicationStrings.ErrorCannotMoveTrainingDayFixedEntries);
                    }
                }
            }
            catch (OldDataException ex)
            {
                ExceptionHandler.Default.Process(ex, ApplicationStrings.ErrorOldTrainingDay, ErrorWindow.MessageBox);
            }
            catch (Exception ex)
            {
                ExceptionHandler.Default.Process(ex, ApplicationStrings.ErrorMoveTrainingDay, ErrorWindow.EMailReport);
            }
        }
Ejemplo n.º 4
0
        private void openTrainingDay(DateTime selectedDate)
        {
            AddTrainingDay dlg = new AddTrainingDay();

            if (!isFilled || UserContext.LoginStatus != LoginStatus.Logged || IsSelectedDateFuture)
            {
                return;
            }

            var day  = new TrainingDayDTO(selectedDate, UserContext.CurrentProfile.Id);
            var info = monthCalendar1.GetDateInfo(selectedDate);

            if (info.Length > 0)
            {
                day = (TrainingDayDTO)info[0].Tag;
            }
            else if (ReadOnly)
            {
                return;
            }

            if (day.Id == Constants.UnsavedObjectId)
            {
                //set default entries for newly created TrainingDay
                var options = UserContext.Settings.GuiState.CalendarOptions;
                foreach (var defaultEntry in options.DefaultEntries)
                {
                    if (defaultEntry.Value)
                    {
                        var plugin = PluginsManager.Instance.GetEntryObjectProvider(defaultEntry.Key);
                        if (plugin != null)
                        {
                            day.AddEntry(plugin.EntryObjectType);
                        }
                    }
                }
                //needed for SizeEntryDTO for example
                day.ChangeDate(selectedDate);
            }
            dlg.Fill(day, User);
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    //save day only when we didn't press Delete button (deleting is performed directly in usrAddTrainingDay control)
                    if (dlg.DayRemoved)
                    {
                        monthCalendar1.RemoveDateInfo(dlg.CurrentDay.TrainingDate);
                        return;
                    }
                }
                catch (Exception ex)
                {
                    ExceptionHandler.Default.Process(ex, ApplicationStrings.ErrorRemoveTrainingDay, ErrorWindow.EMailReport);
                    return;
                }
            }
            //day = ServiceManager.Instance.SaveTrainingDay(UserContext.Token, day);
            if (dlg.FillRequired)
            {
                Fill(User, day.TrainingDate);
            }
        }
Ejemplo n.º 5
0
        private void monthCalendar1_Drop(object sender, RoutedEventArgs e)
        {
            ExDragEventArgs arg = (ExDragEventArgs)e;

            if (arg.DragEventArgs.Data.GetDataPresent("DateTime"))
            {
                DateTime date       = (DateTime)arg.DragEventArgs.Data.GetData("DateTime");
                DateTime targetDate = (DateTime)arg.DirectTarget.Tag;
                var      result     = entriesViewer.CalendarControl.GetDateInfo(date);
                if (result.Count == 1)
                {
                    var dayInfo = (TrainingDayInfo)result[0];

                    TrainingDayDTO day = getTrainingDay(date);
                    if (targetDate.IsFuture() && !UIHelper.EnsurePremiumLicence())
                    {
                        return;
                    }
                    if (Keyboard.IsKeyDown(Key.LeftCtrl))
                    {
                        dayInfo.IsProcessing = true;
                        ParentWindow.RunAsynchronousOperation(x =>
                        {
                            //if (day.GlobalId != Constants.UnsavedGlobalId)
                            //{//user select Cut operation so we should only move this one time (not many time like with Copy operation)
                            //    WorkoutDayGetOperation operation = new WorkoutDayGetOperation();
                            //    operation.UserId = User.Id;
                            //    operation.Operation = GetOperation.Current;
                            //    operation.WorkoutDateTime = day.TrainingDate;
                            //    day = ServiceManager.GetTrainingDay(operation);
                            //}
                            try
                            {
                                day = day.Copy();
                                day.ChangeDate(targetDate);
                                var result1 = ServiceManager.SaveTrainingDay(day);
                                if (result1.TrainingDay != null)
                                {
                                    cache.Add(result1.TrainingDay);
                                }
                            }
                            catch (OldDataException ex)
                            {
                                UIHelper.Invoke(() => ExceptionHandler.Default.Process(ex, "ErrorOldTrainingDay".TranslateStrings(), ErrorWindow.MessageBox), Dispatcher);
                            }
                            catch (Exception ex)
                            {
                                UIHelper.Invoke(() => ExceptionHandler.Default.Process(ex, "ErrorMoveTrainingDay".TranslateStrings(), ErrorWindow.EMailReport), Dispatcher);
                            }
                            finally
                            {
                                dayInfo.IsProcessing = false;
                            }
                        });
                    }
                    else if (BAMessageBox.AskYesNo("QMoveTrainingDay".TranslateStrings()) == MessageBoxResult.Yes)
                    {
                        if (day.CanMove)
                        {
                            dayInfo.IsProcessing = true;
                            ParentWindow.RunAsynchronousOperation(x =>
                            {
                                //if (day.GlobalId != Constants.UnsavedGlobalId)
                                //{//user select Cut operation so we should only move this one time (not many time like with Copy operation)
                                //    WorkoutDayGetOperation operation = new WorkoutDayGetOperation();
                                //    operation.UserId = User.Id;
                                //    operation.Operation = GetOperation.Current;
                                //    operation.WorkoutDateTime = day.TrainingDate;
                                //    day = ServiceManager.GetTrainingDay(operation);
                                //}
                                try
                                {
                                    day = day.StandardClone();
                                    day.ChangeDate(targetDate);
                                    var result1 = ServiceManager.SaveTrainingDay(day);
                                    cache.Remove(date);

                                    if (result1.TrainingDay != null)
                                    {
                                        day = result1.TrainingDay;
                                        cache.Add(day);
                                    }
                                }
                                catch (OldDataException ex)
                                {
                                    UIHelper.Invoke(() => ExceptionHandler.Default.Process(ex, "ErrorOldTrainingDay".TranslateStrings(), ErrorWindow.MessageBox), Dispatcher);
                                }
                                catch (Exception ex)
                                {
                                    UIHelper.Invoke(() => ExceptionHandler.Default.Process(ex, "ErrorMoveTrainingDay".TranslateStrings(), ErrorWindow.EMailReport), Dispatcher);
                                }
                                finally
                                {
                                    dayInfo.IsProcessing = false;
                                }
                            });
                        }
                        else
                        {
                            BAMessageBox.ShowError("ErrorCannotMoveTrainingDayFixedEntries".TranslateStrings());
                        }
                    }
                }
            }
        }