private void butOK_Click(object sender, EventArgs e)
        {
            int   countProcsLinkedToOrthoCase = 0;
            float percent = 0;          //Placeholder

            if (!float.TryParse(textPercentage.Text, out percent))
            {
                MsgBox.Show(this, "Percent is invalid. Please enter a valid number to continue.");
                return;
            }
            bool hasDiscount = false;

            for (int i = 0; i < _listProcs.Count; i++)
            {
                if (_listProcs[i].Discount != 0)
                {
                    hasDiscount = true;
                    break;
                }
            }
            if (hasDiscount &&         //A discount exists for a procedure
                !MsgBox.Show(this, MsgBoxButtons.YesNo, "One or more of the selected procedures has a discount value already set.  This will overwrite current discount values with a new value.  Continue?"))
            {
                return;
            }
            List <long> listProcNumsLinkedToOrthoCases = OrthoProcLinks.GetManyForProcs(_listProcs.Select(x => x.ProcNum).ToList()).Select(y => y.ProcNum).ToList();

            for (int j = 0; j < _listProcs.Count; j++)
            {
                if (listProcNumsLinkedToOrthoCases.Contains(_listProcs[j].ProcNum))
                {
                    countProcsLinkedToOrthoCase++;
                }
                else if (percent == 0)
                {
                    _listProcs[j].Discount = 0;                  //Potentially clears out old discount.
                }
                else
                {
                    _listProcs[j].Discount = _listProcs[j].ProcFee * (percent / 100);
                }
                if (_listProcs[j].Discount != _oldListProcs[j].Discount)               //Discount was changed
                {
                    string message = Lan.g(this, "Discount created or changed from Treat Plan module for procedure")
                                     + ": " + ProcedureCodes.GetProcCode(_listProcs[j].CodeNum).ProcCode + "  " + Lan.g(this, "Dated")
                                     + ": " + _listProcs[j].ProcDate.ToShortDateString() + "  " + Lan.g(this, "With a Fee of") + ": " + _listProcs[j].ProcFee.ToString("c") + ".  " + Lan.g(this, "Attributed a") + " " + percent
                                     + " " + Lan.g(this, "percent discount, changing the discount value from") + " " + _oldListProcs[j].Discount.ToString("c") + " " + Lan.g(this, "to") + " " + _listProcs[j].Discount.ToString("c");
                    SecurityLogs.MakeLogEntry(Permissions.TreatPlanDiscountEdit, _listProcs[j].PatNum, message);
                }
                Procedures.Update(_listProcs[j], _oldListProcs[j]);
            }
            if (countProcsLinkedToOrthoCase > 0)
            {
                string countProcsSkipped = countProcsLinkedToOrthoCase.ToString();
                MessageBox.Show(this, Lans.g(this, "Procedures attached to ortho cases cannot have discounts. Procedures skipped:") + " " + countProcsSkipped);
            }
            DialogResult = DialogResult.OK;
        }
Esempio n. 2
0
        private bool IsValid(int numberEntriesSelected)
        {
            //No procedures selected AND (rigorous adjustments are fully enforced OR the Fixed Amount option is not selected).
            if (numberEntriesSelected == 0 && (_rigorousAdjustments == 0 || !radioFixedAmt.Checked))
            {
                MsgBox.Show(this, "You must select a procedure to add the adjustment to.");
                return(false);
            }
            if (listTypePos.SelectedIndex == -1 && listTypeNeg.SelectedIndex == -1)
            {
                MsgBox.Show(this, "Please pick an adjustment type.");
                return(false);
            }
            if (comboProv.SelectedIndex == -1)
            {
                MsgBox.Show(this, "Please pick a provider.");
                return(false);
            }
            if (PrefC.HasClinicsEnabled && comboClinic.SelectedIndex == -1)
            {
                MsgBox.Show(this, "Please pick a clinic.");
                return(false);
            }
            if (string.IsNullOrWhiteSpace(dateAdjustment.Text) || dateAdjustment.errorProvider1.GetError(dateAdjustment) != "")
            {
                MsgBox.Show(this, "Please enter a valid date.");
                return(false);
            }
            if (PIn.Date(dateAdjustment.Text).Date > DateTime.Today.Date && !PrefC.GetBool(PrefName.FutureTransDatesAllowed))
            {
                MsgBox.Show(this, "Adjustments cannot be made for future dates");
                return(false);
            }
            if (string.IsNullOrWhiteSpace(textAmt.Text) || textAmt.errorProvider1.GetError(textAmt) != "")
            {
                MsgBox.Show(this, "Please enter a valid amount.");
                return(false);
            }
            List <OrthoProcLink> listOrthoProcLinks = OrthoProcLinks.GetManyForProcs(gridMain.SelectedGridRows.Select(x => ((MultiAdjEntry)x.Tag).Proc.ProcNum).ToList());

            if (listOrthoProcLinks.Count > 0)
            {
                MsgBox.Show(this, "One or more of the selected procedures cannot be adjusted because it is attached to an ortho case." +
                            " Please deselect these items and try again.");
                return(false);
            }
            return(true);
        }