Exemple #1
0
        public bool SaveTrainingDay(bool isWindowClosing)
        {
            bool           res         = true;
            Guid?          customerId  = null;
            Guid?          userId      = null;
            TrainingDayDTO originalDay = null;

            Dispatcher.Invoke(new Action(delegate
            {
                if (!validateControls())
                {
                    res = false;
                    return;
                }
                customerId = Customer != null ? Customer.GlobalId : (Guid?)null;
                userId     = User != null ? User.GlobalId : (Guid?)null;
                foreach (TabItemViewModel tabPage in xtraTabControl1.Items)
                {
                    IEntryObjectControl entryControl = (IEntryObjectControl)tabPage.Content;
                    entryControl.UpdateEntryObject();
                }
                originalDay = TrainingDayPageContext.Day;
                if (commentsControl != null)
                {
                    day.AllowComments = commentsControl.AllowComments;
                }
            }));

            if (!res)
            {
                return(false);
            }

            if (day.GlobalId == Constants.UnsavedGlobalId && day.IsEmpty)
            {
                return(true);
            }

            var result = ServiceManager.SaveTrainingDay(day);

            day = result.TrainingDay;
            TrainingDayDTO tempDay = null;
            var            cache   = TrainingDaysReposidory.GetCache(customerId, userId);

            if (day == null)
            {
                tempDay = day = new TrainingDayDTO(originalDay.TrainingDate);
                cache.Remove(originalDay.TrainingDate);
            }
            else
            {
                tempDay = day.StandardClone();
                cache.Add(tempDay);
            }
            ensureRemindersRefreshed(originalDay, day);


            Dispatcher.Invoke(new Action(delegate
            {
                //if (TrainingDayPageContext.Day.IsNew)
                //{
                //    rowSplitter.Process(tempDay.IsNew);
                //}
                TrainingDayPageContext.Day = tempDay;
                SetModifiedFlag();

                if (commentsControl != null)
                {
                    commentsControl.Fill(day);
                }
                foreach (var tabItemViewModel in Tabs)
                {
                    var ctrl = (IEntryObjectControl)tabItemViewModel.Content;
                    ctrl.AfterSave(false);
                }

                Tabs.Clear();
                refreshTabs(filterType, result);
            }));


            return(true);
        }
        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());
                        }
                    }
                }
            }
        }