예제 #1
0
        private void simpleButton1_Click(object sender, EventArgs e)
        {
            if (CurrentStore != null)
            {
                if (OpenCloseTimes != null)
                {
                    StoreWorkingTime newtime = OpenCloseTimes.BuildNewEntity();

                    if (newtime != null)
                    {
                        EntityOpenCloseTime = newtime;
                    }
                    else
                    {
                        ErrorMessage(GetLocalized("ErrorCantNewOpenCloseOutOfRange"));
                        return;
                    }
                }
                else
                {
                    EntityOpenCloseTime         = ClientEnvironment.StoreService.StoreWorkingTimeService.CreateEntity();
                    EntityOpenCloseTime.StoreID = CurrentStoreID;
                    StartDate = DateTime.Today;
                    EndDate   = DateTimeSql.SmallDatetimeMax;
                }
                UpdateButtonState();
            }
        }
예제 #2
0
        private void newOpencloseToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (OpenCloseTimes != null)
            {
                StoreWorkingTime newtime = OpenCloseTimes.BuildNewEntity();

                if (newtime != null)
                {
                    ucOpenCloseHours.EntityOpenCloseTime = newtime;
                }
                else
                {
                    ErrorMessage(GetLocalized("ErrorCantNewOpenCloseOutOfRange"));
                    return;
                }
            }
        }
예제 #3
0
 public void ApplyOpenCloseTimes(StoreWorkingTime times)
 {
     foreach (StoreDay sd in Values)
     {
         if (times.BeginTime <= sd.Date && sd.Date <= times.EndTime)
         {
             foreach (StoreWTWeekday weekday in times.StoreWTWeekdays)
             {
                 if (weekday.Weekday == (byte)sd.Date.DayOfWeek)
                 {
                     sd.OpenTime  = weekday.Opentime;
                     sd.CloseTime = weekday.Closetime;
                     sd.Undefined = false;
                 }
             }
         }
     }
 }
예제 #4
0
 private static void CopyEntity(StoreWorkingTime source, StoreWorkingTime dest)
 {
     dest.ID        = source.ID;
     dest.StoreID   = source.StoreID;
     dest.BeginTime = source.BeginTime;
     dest.EndTime   = source.EndTime;
     foreach (StoreWTWeekday wdSource in source.StoreWTWeekdays)
     {
         foreach (StoreWTWeekday wdDest in dest.StoreWTWeekdays)
         {
             if (wdDest.Weekday == wdSource.Weekday)
             {
                 wdDest.ID        = wdSource.ID;
                 wdDest.Opentime  = wdSource.Opentime;
                 wdDest.Closetime = wdSource.Closetime;
                 continue;
             }
         }
     }
 }
예제 #5
0
 public void SuggestOptions(StoreWorkingTime previousWorkingTime, StoreWorkingTime nextWorkingTime)
 {
     rdo_ExpandPrevious.Enabled       = previousWorkingTime != null;
     rdo_ExpandNext.Enabled           = nextWorkingTime != null;
     rdo_LeaveRangesUnchanged.Enabled = (previousWorkingTime != null && nextWorkingTime == null);
     if (!rdo_ExpandPrevious.Enabled && rdo_ExpandPrevious.Checked)
     {
         rdo_ExpandPrevious.Checked = false;
         rdo_ExpandNext.Checked     = true;
     }
     if (!rdo_ExpandNext.Enabled && rdo_ExpandNext.Checked)
     {
         rdo_ExpandNext.Checked = false;
         if (rdo_LeaveRangesUnchanged.Enabled)
         {
             rdo_LeaveRangesUnchanged.Checked = true;
         }
         else
         if (rdo_ExpandPrevious.Enabled)
         {
             rdo_ExpandPrevious.Checked = true;
         }
     }
 }
예제 #6
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"));
                }
            }
        }
예제 #7
0
 private void ShowFocusedEntityDetails()
 {
     BeforeChangeEntity();
     _focusedRange = FocusedEntity;
     FireChangeTimeRange();
 }
예제 #8
0
        public override bool Commit()
        {
            if (Entity != null && IsValid() && IsModified() && !ReadOnly)
            {
                StoreWorkingTime holeCoverWorkingTime     = null;
                StoreWorkingTime copyHoleCoverWorkingTime = null;

                if (OpenCloseTimes.Count > 1)
                {
                    // If Start Date or End Date is modified, the hole in Schedule should be covered by previous or next schedule
                    if (StartDate != EntityOpenCloseTime.BeginTime)
                    {
                        holeCoverWorkingTime = OpenCloseTimes.FindPrevious(EntityOpenCloseTime);
                        if (holeCoverWorkingTime != null)
                        {
                            copyHoleCoverWorkingTime = ClientEnvironment.StoreService.StoreWorkingTimeService.CreateEntity();
                            CopyEntity(holeCoverWorkingTime, copyHoleCoverWorkingTime);
                            copyHoleCoverWorkingTime.EndTime = StartDate.AddDays(-1);
                        }
                    }
                    else if (EndDate != EntityOpenCloseTime.EndTime)
                    {
                        holeCoverWorkingTime = OpenCloseTimes.FindNext(EntityOpenCloseTime);
                        if (holeCoverWorkingTime != null)
                        {
                            copyHoleCoverWorkingTime = ClientEnvironment.StoreService.StoreWorkingTimeService.CreateEntity();
                            CopyEntity(holeCoverWorkingTime, copyHoleCoverWorkingTime);
                            copyHoleCoverWorkingTime.BeginTime = EndDate.AddDays(1);
                        }
                    }
                }

                StoreWorkingTime copyWorkingTime = ClientEnvironment.StoreWorkingTimeService.CreateEntity();

                CopyEntity(EntityOpenCloseTime, copyWorkingTime);

                foreach (StoreWTWeekday wd in copyWorkingTime.StoreWTWeekdays)
                {
                    _copyList[wd.Weekday].DisplayString = _dictOfEdit[wd.Weekday].Text;
                    _copyList[wd.Weekday].Copy(wd);
                }

                copyWorkingTime.BeginTime = StartDate;
                copyWorkingTime.EndTime   = EndDate;
                copyWorkingTime.StoreID   = CurrentStoreID;

                try
                {
                    bool isNew = copyWorkingTime.IsNew;

                    copyWorkingTime = ClientEnvironment.StoreService.StoreWorkingTimeService.SaveOrUpdate(copyWorkingTime);

                    CopyEntity(copyWorkingTime, EntityOpenCloseTime);
                    UpdateButtonState();
                    if (OnEntityChanged != null)
                    {
                        OnEntityChanged(new EntityChangedArgs(EntityOpenCloseTime, (isNew) ? ChangedEntityType.New : ChangedEntityType.Edit));
                    }

                    // Update previous or next Working Time range to cover the hole create
                    if (holeCoverWorkingTime != null)
                    {
                        CopyEntity(ClientEnvironment.StoreService.StoreWorkingTimeService.Update(copyHoleCoverWorkingTime), holeCoverWorkingTime);
                        if (OnEntityChanged != null)
                        {
                            OnEntityChanged(new EntityChangedArgs(holeCoverWorkingTime, ChangedEntityType.Edit));
                        }
                    }
                    //Recalculate  Additional hours
                    //Delete calculated Additional hours after change Date range for out of range data
                    RecalculateStoreAdditionalHours();
                    Modified = true;
                    return(true);
                } catch (ValidationException)
                {
                    ErrorMessage(GetLocalized("ErrorDateRangeIntersect"));
                    deStart.Focus();
                    return(false);
                }

                /*catch (DBDuplicateKeyException)
                 * {
                 *  ErrorMessage(GetLocalized("ErrorDateRangeIntersect"));
                 *  deStart.Focus();
                 *  return false;
                 * }*/
                catch (EntityException ex)
                {
                    ProcessEntityException(ex);
                    return(false);
                }
            }
            return(false);
        }