示例#1
0
        private void butUndo_Click(object sender, EventArgs e)
        {
            string chargeType = (radioFinanceCharge.Checked?"Finance":"Billing");

            if (MessageBox.Show(Lan.g(this, "Undo all " + chargeType.ToLower() + " charges for") + " " + textDateUndo.Text + "?", "", MessageBoxButtons.OKCancel)
                != DialogResult.OK)
            {
                return;
            }
            Action actionCloseProgress = null;
            int    rowsAffected        = 0;

            try {
                actionCloseProgress = ODProgressOld.ShowProgressStatus(chargeType + "Charge", this,
                                                                       Lan.g(this, "Deleting " + chargeType.ToLower() + " charge adjustments") + "...");
                Cursor       = Cursors.WaitCursor;
                rowsAffected = (int)Adjustments.UndoFinanceOrBillingCharges(PIn.Date(textDateUndo.Text), radioBillingCharge.Checked);
            }
            finally {
                actionCloseProgress?.Invoke();                //effectively terminates progress bar
                Cursor = Cursors.Default;
            }
            MessageBox.Show(Lan.g(this, chargeType + " charge adjustments deleted") + ": " + rowsAffected);
            if (rowsAffected == 0)
            {
                DialogResult = DialogResult.OK;
                return;
            }
            actionCloseProgress = null;
            if (PrefC.GetBool(PrefName.AgingIsEnterprise))
            {
                if (!RunAgingEnterprise())
                {
                    MsgBox.Show(this, "There was an error calculating aging after the " + chargeType.ToLower() + " charge adjustments were deleted.\r\n"
                                + "You should run aging later to update affected accounts.");
                }
            }
            else
            {
                try {
                    DateTime asOfDate = (PrefC.GetBool(PrefName.AgingCalculatedMonthlyInsteadOfDaily)?PrefC.GetDate(PrefName.DateLastAging):DateTime.Today);
                    actionCloseProgress = ODProgressOld.ShowProgressStatus("FinanceCharge", this, Lan.g(this, "Calculating aging for all patients as of") + " "
                                                                           + asOfDate.ToShortDateString() + "...");
                    Cursor = Cursors.WaitCursor;
                    Ledgers.RunAging();
                }
                catch (MySqlException ex) {
                    actionCloseProgress?.Invoke();                    //effectively terminates progress bar
                    Cursor = Cursors.Default;
                    if (ex == null || ex.Number != 1213)              //not a deadlock error, just throw
                    {
                        throw;
                    }
                    MsgBox.Show(this, "There was a deadlock error calculating aging after the " + chargeType.ToLower() + " charge adjustments were deleted.\r\n"
                                + "You should run aging later to update affected accounts.");
                }
                finally {
                    actionCloseProgress?.Invoke();                    //effectively terminates progress bar
                    Cursor = Cursors.Default;
                }
            }
            SecurityLogs.MakeLogEntry(Permissions.Setup, 0, chargeType + " Charges undo. Date " + textDateUndo.Text);
            DialogResult = DialogResult.OK;
        }