예제 #1
0
        private void DeleteFocusedWorkingHours()
        {
            if (FocusedEntity != null)
            {
                if (FocusedEntity.BeginTime > DateTime.Today)
                {
                    if (QuestionMessageYes(GetLocalized("QuestionRemoveStoreOpenClose")))
                    {
                        StoreWorkingTime           previousWorkingTime = OpenCloseTimes.FindPrevious(FocusedEntity);
                        StoreWorkingTime           nextWorkingTime     = OpenCloseTimes.FindNext(FocusedEntity);
                        OpenCloseHoursExtendOption extendAction        = OpenCloseHoursExtendOption.Undefined;

                        if (OpenCloseTimes.Count > 1)
                        {
                            // Check whether a hole in schedule is created, prompt user to select which range should be extended to cover the hole
                            using (FormExtendOpenCloseHours formExtendOptions = new FormExtendOpenCloseHours())
                            {
                                formExtendOptions.SuggestOptions(previousWorkingTime, nextWorkingTime);
                                if (formExtendOptions.ShowDialog(FindForm()) != DialogResult.OK)
                                {
                                    return;
                                }
                                extendAction = formExtendOptions.SelectedExtendOption;
                            }
                        }

                        try
                        {
                            StoreWorkingTime focusedWorkingTime = FocusedEntity;
                            ClientEnvironment.StoreService.StoreWorkingTimeService.DeleteByID(focusedWorkingTime.ID);
                            OpenCloseTimes.RemoveEntityById(FocusedEntity.ID);
                            switch (extendAction)
                            {
                            case OpenCloseHoursExtendOption.Previous:
                                previousWorkingTime.EndTime = focusedWorkingTime.EndTime;
                                ClientEnvironment.StoreService.StoreWorkingTimeService.Update(previousWorkingTime);
                                OpenCloseTimes.SetEntity(previousWorkingTime);
                                break;

                            case OpenCloseHoursExtendOption.Next:
                                nextWorkingTime.BeginTime = focusedWorkingTime.BeginTime;
                                ClientEnvironment.StoreService.StoreWorkingTimeService.Update(nextWorkingTime);
                                OpenCloseTimes.SetEntity(nextWorkingTime);
                                break;

                            default:
                                break;
                            }
                        }
                        catch (EntityException ex)
                        {
                            ProcessEntityException(ex);
                        }
                        ShowFocusedEntityDetails();
                    }
                }
                else
                {
                    ErrorMessage(GetLocalized("CantDeleteOpenClose-EntityInUsed"));
                }
            }
        }
예제 #2
0
        private void DeleteFocusedWorkingHours()
        {
            if (FocusedEntity != null)
            {
                if (FocusedEntity.BeginTime > DateTime.Today)
                {
                    if (QuestionMessageYes(GetLocalized("QuestionRemoveStoreOpenClose")))
                    {
                        StoreWorkingTime previousWorkingTime = OpenCloseTimes.FindPrevious(FocusedEntity);
                        StoreWorkingTime nextWorkingTime = OpenCloseTimes.FindNext(FocusedEntity);
                        OpenCloseHoursExtendOption extendAction = OpenCloseHoursExtendOption.Undefined;

                        if (OpenCloseTimes.Count > 1)
                        {
                            // Check whether a hole in schedule is created, prompt user to select which range should be extended to cover the hole
                            using (FormExtendOpenCloseHours formExtendOptions = new FormExtendOpenCloseHours())
                            {
                                formExtendOptions.SuggestOptions(previousWorkingTime, nextWorkingTime);
                                if (formExtendOptions.ShowDialog(FindForm()) != DialogResult.OK)
                                {
                                    return;
                                }
                                extendAction = formExtendOptions.SelectedExtendOption;
                            }
                        }

                        try
                        {
                            StoreWorkingTime focusedWorkingTime = FocusedEntity;
                            ClientEnvironment.StoreService.StoreWorkingTimeService.DeleteByID(focusedWorkingTime.ID);
                            OpenCloseTimes.RemoveEntityById(FocusedEntity.ID);
                            switch (extendAction)
                            {
                                case OpenCloseHoursExtendOption.Previous:
                                    previousWorkingTime.EndTime = focusedWorkingTime.EndTime;
                                    ClientEnvironment.StoreService.StoreWorkingTimeService.Update(previousWorkingTime);
                                    OpenCloseTimes.SetEntity(previousWorkingTime);
                                    break;
                                case OpenCloseHoursExtendOption.Next:
                                    nextWorkingTime.BeginTime = focusedWorkingTime.BeginTime;
                                    ClientEnvironment.StoreService.StoreWorkingTimeService.Update(nextWorkingTime);
                                    OpenCloseTimes.SetEntity(nextWorkingTime);
                                    break;
                                default:
                                    break;
                            }
                        }
                        catch (EntityException ex)
                        {
                            ProcessEntityException(ex);
                        }
                        ShowFocusedEntityDetails();
                    }
                }
                else
                {
                    ErrorMessage(GetLocalized("CantDeleteOpenClose-EntityInUsed"));
                }
            }
        }