Exemple #1
0
 ///<summary></summary>
 private static bool Overlaps(Schedule sched)
 {
     Schedule[] SchedListDay = Schedules.RefreshPeriod(sched.SchedDate, sched.SchedDate);
     Schedule[] ListForType  = Schedules.GetForType(SchedListDay, sched.SchedType, sched.ProvNum);
     for (int i = 0; i < ListForType.Length; i++)
     {
         if (ListForType[i].SchedType == ScheduleType.Blockout)
         {
             //skip if blockout, and ops don't interfere
             if (sched.Op != 0 && ListForType[i].Op != 0)                //neither op can be zero, or they will interfere
             {
                 if (sched.Op != ListForType[i].Op)
                 {
                     continue;
                 }
             }
         }
         if (sched.ScheduleNum != ListForType[i].ScheduleNum &&
             sched.StartTime.TimeOfDay >= ListForType[i].StartTime.TimeOfDay &&
             sched.StartTime.TimeOfDay < ListForType[i].StopTime.TimeOfDay)
         {
             return(true);
         }
         if (sched.ScheduleNum != ListForType[i].ScheduleNum &&
             sched.StopTime.TimeOfDay > ListForType[i].StartTime.TimeOfDay &&
             sched.StopTime.TimeOfDay <= ListForType[i].StopTime.TimeOfDay)
         {
             return(true);
         }
         if (sched.ScheduleNum != ListForType[i].ScheduleNum &&
             sched.StartTime.TimeOfDay <= ListForType[i].StartTime.TimeOfDay &&
             sched.StopTime.TimeOfDay >= ListForType[i].StopTime.TimeOfDay)
         {
             return(true);
         }
     }
     return(false);
 }
        private void butRepeat_Click(object sender, EventArgs e)
        {
            if (textDateFrom.errorProvider1.GetError(textDateFrom) != "" ||
                textDateTo.errorProvider1.GetError(textDateTo) != "")
            {
                MsgBox.Show(this, "Please fix errors first.");
                return;
            }
            try{
                int.Parse(textRepeat.Text);
            }
            catch {
                MsgBox.Show(this, "Please fix number box first.");
                return;
            }
            if (gridMain.SelectedCell.X == -1)
            {
                MsgBox.Show(this, "Please select a date first.");
                return;
            }
            if (DateCopyStart.Year < 1880)
            {
                MsgBox.Show(this, "Please copy a selection to the clipboard first.");
                return;
            }
            if (ProvsChanged)
            {
                MsgBox.Show(this, "Provider or Employee selection has been changed.  Please refresh first.");
                return;
            }
            //calculate which day or week is currently selected.
            DateTime dateSelectedStart;
            DateTime dateSelectedEnd;
            bool     isWeek = DateCopyStart != DateCopyEnd;

            if (isWeek)
            {
                int startI = 1;
                if (checkWeekend.Checked)
                {
                    startI = 0;
                }
                dateSelectedStart = Schedules.GetDateCal(PIn.PDate(textDateFrom.Text), gridMain.SelectedCell.Y, startI);
                if (checkWeekend.Checked)
                {
                    dateSelectedEnd = dateSelectedStart.AddDays(6);
                }
                else
                {
                    dateSelectedEnd = dateSelectedStart.AddDays(4);
                }
            }
            else
            {
                int selectedCol = gridMain.SelectedCell.X;
                if (!checkWeekend.Checked)
                {
                    selectedCol++;
                }
                dateSelectedStart = Schedules.GetDateCal(PIn.PDate(textDateFrom.Text), gridMain.SelectedCell.Y, selectedCol);
                dateSelectedEnd   = dateSelectedStart;
            }
            //it is allowed to paste back over the same day or week.
            //if(dateSelectedStart==DateCopyStart) {
            //	MsgBox.Show(this,"Not allowed to paste back onto the same date as is on the clipboard.");
            //	return;
            //}
            List <int> provNums = new List <int>();

            for (int i = 0; i < listProv.SelectedIndices.Count; i++)
            {
                provNums.Add(Providers.List[listProv.SelectedIndices[i]].ProvNum);
            }
            List <int> empNums = new List <int>();

            for (int i = 0; i < listEmp.SelectedIndices.Count; i++)
            {
                empNums.Add(Employees.ListShort[listEmp.SelectedIndices[i]].EmployeeNum);
            }
            List <Schedule> SchedList = Schedules.RefreshPeriod(DateCopyStart, DateCopyEnd, provNums.ToArray(),
                                                                empNums.ToArray(), checkPractice.Checked);
            Schedule sched;
            int      weekDelta = 0;
            TimeSpan span;

            if (isWeek)
            {
                span      = dateSelectedStart - DateCopyStart;
                weekDelta = span.Days / 7; //usually a positive # representing a future paste, but can be negative
            }
            int dayDelta = 0;              //this is needed when repeat pasting days in order to calculate skipping weekends.

            //dayDelta will start out zero and increment separately from r.
            for (int r = 0; r < PIn.PInt(textRepeat.Text); r++)
            {
                if (checkReplace.Checked)
                {
                    if (isWeek)
                    {
                        Schedules.Clear(dateSelectedStart.AddDays(r * 7), dateSelectedEnd.AddDays(r * 7),
                                        provNums.ToArray(), empNums.ToArray(), checkPractice.Checked);
                    }
                    else
                    {
                        Schedules.Clear(dateSelectedStart.AddDays(dayDelta), dateSelectedEnd.AddDays(dayDelta),
                                        provNums.ToArray(), empNums.ToArray(), checkPractice.Checked);
                    }
                }
                for (int i = 0; i < SchedList.Count; i++)
                {
                    sched = SchedList[i].Copy();
                    if (isWeek)
                    {
                        sched.SchedDate = sched.SchedDate.AddDays((weekDelta + r) * 7);
                    }
                    else
                    {
                        sched.SchedDate = dateSelectedStart.AddDays(dayDelta);
                    }
                    Schedules.Insert(sched);
                }
                if (!checkWeekend.Checked && dateSelectedStart.AddDays(dayDelta).DayOfWeek == DayOfWeek.Friday)
                {
                    dayDelta += 3;
                }
                else
                {
                    dayDelta++;
                }
            }
            DateTime rememberDateStart = DateCopyStart;
            DateTime rememberDateEnd   = DateCopyEnd;

            FillGrid();
            DateCopyStart = rememberDateStart;
            DateCopyEnd   = rememberDateEnd;
            if (isWeek)
            {
                textClipboard.Text = DateCopyStart.ToShortDateString() + "-" + DateCopyEnd.ToShortDateString();
            }
            else
            {
                textClipboard.Text = DateCopyStart.ToShortDateString();
            }
            changed = true;
        }
        private void butPaste_Click(object sender, EventArgs e)
        {
            if (textDateFrom.errorProvider1.GetError(textDateFrom) != "" ||
                textDateTo.errorProvider1.GetError(textDateTo) != "")
            {
                MsgBox.Show(this, "Please fix errors first.");
                return;
            }
            if (gridMain.SelectedCell.X == -1)
            {
                MsgBox.Show(this, "Please select a date first.");
                return;
            }
            if (DateCopyStart.Year < 1880)
            {
                MsgBox.Show(this, "Please copy a selection to the clipboard first.");
                return;
            }
            if (ProvsChanged)
            {
                MsgBox.Show(this, "Provider or Employee selection has been changed.  Please refresh first.");
                return;
            }
            //calculate which day or week is currently selected.
            DateTime dateSelectedStart;
            DateTime dateSelectedEnd;
            bool     isWeek = DateCopyStart != DateCopyEnd;

            if (isWeek)
            {
                int startI = 1;
                if (checkWeekend.Checked)
                {
                    startI = 0;
                }
                dateSelectedStart = Schedules.GetDateCal(PIn.PDate(textDateFrom.Text), gridMain.SelectedCell.Y, startI);
                if (checkWeekend.Checked)
                {
                    dateSelectedEnd = dateSelectedStart.AddDays(6);
                }
                else
                {
                    dateSelectedEnd = dateSelectedStart.AddDays(4);
                }
            }
            else
            {
                int selectedCol = gridMain.SelectedCell.X;
                if (!checkWeekend.Checked)
                {
                    selectedCol++;
                }
                dateSelectedStart = Schedules.GetDateCal(PIn.PDate(textDateFrom.Text), gridMain.SelectedCell.Y, selectedCol);
                dateSelectedEnd   = dateSelectedStart;
            }
            //it's not allowed to paste back over the same day or week.
            if (dateSelectedStart == DateCopyStart)
            {
                MsgBox.Show(this, "Not allowed to paste back onto the same date as is on the clipboard.");
                return;
            }
            List <int> provNums = new List <int>();

            for (int i = 0; i < listProv.SelectedIndices.Count; i++)
            {
                provNums.Add(Providers.List[listProv.SelectedIndices[i]].ProvNum);
            }
            List <int> empNums = new List <int>();

            for (int i = 0; i < listEmp.SelectedIndices.Count; i++)
            {
                empNums.Add(Employees.ListShort[listEmp.SelectedIndices[i]].EmployeeNum);
            }
            if (checkReplace.Checked)
            {
                Schedules.Clear(dateSelectedStart, dateSelectedEnd, provNums.ToArray(), empNums.ToArray(), checkPractice.Checked);
            }
            List <Schedule> SchedList = Schedules.RefreshPeriod(DateCopyStart, DateCopyEnd, provNums.ToArray(),
                                                                empNums.ToArray(), checkPractice.Checked);
            Schedule sched;
            int      weekDelta = 0;

            if (isWeek)
            {
                TimeSpan span = dateSelectedStart - DateCopyStart;
                weekDelta = span.Days / 7;            //usually a positive # representing a future paste, but can be negative
            }
            for (int i = 0; i < SchedList.Count; i++)
            {
                sched = SchedList[i];
                if (isWeek)
                {
                    sched.SchedDate = sched.SchedDate.AddDays(weekDelta * 7);
                }
                else
                {
                    sched.SchedDate = dateSelectedStart;
                }
                Schedules.Insert(sched);
            }
            DateTime rememberDateStart = DateCopyStart;
            DateTime rememberDateEnd   = DateCopyEnd;

            FillGrid();
            DateCopyStart = rememberDateStart;
            DateCopyEnd   = rememberDateEnd;
            if (isWeek)
            {
                textClipboard.Text = DateCopyStart.ToShortDateString() + "-" + DateCopyEnd.ToShortDateString();
            }
            else
            {
                textClipboard.Text = DateCopyStart.ToShortDateString();
            }
            changed = true;
        }