private void butCopyWeek_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;
            }
            int startI = 1;

            if (checkWeekend.Checked)
            {
                startI = 0;
            }
            DateCopyStart = Schedules.GetDateCal(PIn.PDate(textDateFrom.Text), gridMain.SelectedCell.Y, startI);
            if (checkWeekend.Checked)
            {
                DateCopyEnd = DateCopyStart.AddDays(6);
            }
            else
            {
                DateCopyEnd = DateCopyStart.AddDays(4);
            }
            textClipboard.Text = DateCopyStart.ToShortDateString() + "-" + DateCopyEnd.ToShortDateString();
        }
        private void butDelete_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 (ProvsChanged)
            {
                MsgBox.Show(this, "Provider or Employee selection has been changed.  Please refresh first.");
                return;
            }
            if (!MsgBox.Show(this, true, "Delete all displayed entries for the entire selected week?"))
            {
                return;
            }
            int startI = 1;

            if (checkWeekend.Checked)
            {
                startI = 0;
            }
            DateTime dateSelectedStart = Schedules.GetDateCal(PIn.PDate(textDateFrom.Text), gridMain.SelectedCell.Y, startI);
            DateTime dateSelectedEnd;

            if (checkWeekend.Checked)
            {
                dateSelectedEnd = dateSelectedStart.AddDays(6);
            }
            else
            {
                dateSelectedEnd = dateSelectedStart.AddDays(4);
            }
            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);
            }
            Schedules.Clear(dateSelectedStart, dateSelectedEnd, provNums.ToArray(), empNums.ToArray(), checkPractice.Checked);
            FillGrid();
            changed = true;
        }
Beispiel #3
0
        private void gridMain_CellDoubleClick(object sender, ODGridClickEventArgs e)
        {
            if (!Security.IsAuthorized(Permissions.Schedules, DateTime.MinValue))
            {
                return;
            }
            if (textDateFrom.errorProvider1.GetError(textDateFrom) != "" ||
                textDateTo.errorProvider1.GetError(textDateTo) != "")
            {
                MsgBox.Show(this, "Please fix errors first.");
                return;
            }
            int clickedCol = e.Col;

            if (!checkWeekend.Checked)
            {
                clickedCol++;
            }
            //the "clickedCell" is in terms of the entire 7 col layout.
            Point    clickedCell  = new Point(clickedCol, e.Row);
            DateTime selectedDate = Schedules.GetDateCal(PIn.Date(textDateFrom.Text), e.Row, clickedCol);

            if (selectedDate < PIn.Date(textDateFrom.Text) || selectedDate > PIn.Date(textDateTo.Text))
            {
                return;
            }
            //MessageBox.Show(selectedDate.ToShortDateString());
            FormScheduleDayEdit FormS = new FormScheduleDayEdit(selectedDate);

            FormS.ShowDialog();
            if (FormS.DialogResult != DialogResult.OK)
            {
                return;
            }
            FillGrid();
            if (checkWeekend.Checked)
            {
                gridMain.SetSelected(clickedCell);
            }
            else
            {
                gridMain.SetSelected(new Point(clickedCell.X - 1, clickedCell.Y));
            }
            changed = true;
        }
        private void butCopyDay_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;
            }
            int selectedCol = gridMain.SelectedCell.X;

            if (!checkWeekend.Checked)
            {
                selectedCol++;
            }
            DateCopyStart      = Schedules.GetDateCal(PIn.PDate(textDateFrom.Text), gridMain.SelectedCell.Y, selectedCol);
            DateCopyEnd        = DateCopyStart;
            textClipboard.Text = DateCopyStart.ToShortDateString();
        }
        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;
        }