Пример #1
0
        void menuItemProv_Click(object sender, EventArgs e)
        {
            Appointment apt = Appointments.GetOneApt(ListPinBoardItems[SelectedIndex].AptNum);

            if (apt == null)
            {
                ClearAt(SelectedIndex);
                MessageBox.Show("Appointment not found.");
                return;
            }
            Appointment oldApt  = apt.Copy();
            long        provNum = apt.ProvNum;

            if (apt.IsHygiene)
            {
                provNum = apt.ProvHyg;
            }
            FormProviderPick formPick = new FormProviderPick();

            formPick.SelectedProvNum = provNum;
            formPick.ShowDialog();
            if (formPick.DialogResult != DialogResult.OK)
            {
                return;
            }
            if (formPick.SelectedProvNum == provNum)
            {
                return;                //provider not changed.
            }
            if (apt.IsHygiene)
            {
                apt.ProvHyg = formPick.SelectedProvNum;
            }
            else
            {
                apt.ProvNum = formPick.SelectedProvNum;
            }
            #region Provider Term Date Check
            //Prevents appointments with providers that are past their term end date from being scheduled
            //Allows for unscheduled appointments to skip the check as it will check when they go to schedule.
            if (apt.AptStatus != ApptStatus.UnschedList)
            {
                string message = Providers.CheckApptProvidersTermDates(apt);
                if (message != "")
                {
                    MessageBox.Show(this, message);                   //translated in Providers S class method
                    return;
                }
            }
            #endregion Provider Term Date Check
            List <Procedure> procsForSingleApt = Procedures.GetProcsForSingle(apt.AptNum, false);
            if (MsgBox.Show(this, MsgBoxButtons.YesNo, "Change length for new provider?"))
            {
                List <long> codeNums = new List <long>();
                for (int p = 0; p < procsForSingleApt.Count; p++)
                {
                    codeNums.Add(procsForSingleApt[p].CodeNum);
                }
                string calcPattern = Appointments.CalculatePattern(apt.ProvNum, apt.ProvHyg, codeNums, true);
                if (apt.Pattern != calcPattern)
                {
                    if (!apt.TimeLocked || MsgBox.Show(this, MsgBoxButtons.YesNo, "Appointment length is locked.  Change length for new provider anyway?"))
                    {
                        apt.Pattern = calcPattern;
                    }
                }
            }
            Appointments.Update(apt, oldApt);
            ProcFeeHelper    procFeeHelper  = new ProcFeeHelper(apt.PatNum);
            bool             isUpdatingFees = false;
            List <Procedure> listProcsNew   = procsForSingleApt.Select(x => Procedures.UpdateProcInAppointment(apt, x.Copy())).ToList();
            if (procsForSingleApt.Exists(x => x.ProvNum != listProcsNew.FirstOrDefault(y => y.ProcNum == x.ProcNum).ProvNum))         //Either the primary or hygienist changed.
            {
                string promptText = "";
                isUpdatingFees = Procedures.ShouldFeesChange(listProcsNew, procsForSingleApt, ref promptText, procFeeHelper);
                if (isUpdatingFees)                 //Made it pass the pref check.
                {
                    if (promptText != "" && !MsgBox.Show(this, MsgBoxButtons.YesNo, promptText))
                    {
                        isUpdatingFees = false;
                    }
                }
            }
            Procedures.SetProvidersInAppointment(apt, procsForSingleApt, isUpdatingFees, procFeeHelper);
            OnModuleNeedsRefresh();
            //this will also trigger ContrAppt to send a new appt to the pinboard.
        }