private void mnuPayments_Click(object sender, EventArgs e)
        {
            /********************************************************************************
            *   Add
            ********************************************************************************/
            if (sender.Equals(mnuPlanPaymentsAdd))
            {
                dgvPayments.EndEdit();

                frmPayment frm = new frmPayment(ref bindingPayments);

                if (!frm.IsDisposed)
                {
                    frm.ShowDialog(this);
                    dgvPayments_CreateTotalAmount(this, new DataGridViewCellEventArgs(2, 0));
                }
            }

            /********************************************************************************
            *   Remove
            ********************************************************************************/
            else if (sender.Equals(mnuPlanPaymentsRemove))
            {
                List <FeePayment> lstPlanPayments = new List <FeePayment>();

                foreach (DataGridViewRow dgr in dgvPayments.SelectedRows)
                {
                    lstPlanPayments.Add((FeePayment)dgr.DataBoundItem);
                }


                dgvPayments.SuspendLayout();
                if (lstPlanPayments.Count > 0)
                {
                    foreach (FeePayment planfee in lstPlanPayments)
                    {
                        try
                        {
                            bindingPayments.Remove(planfee);
                        }
                        catch (MyException ex)
                        {
                            MyMessageBox.Show(this, "Plan Payments", MyDisplayMessage.RemoveError, ex);
                        }
                    }
                }

                dgvPayments.ResumeLayout();
                lstPlanPayments.Clear();
                dgvPayments.ClearSelection();
            }
        }
Example #2
0
        private void mnuDefendant_Click(object sender, EventArgs e)
        {
            Defendant defendant = (Defendant)bindingDefendants.Current;

            /********************************************************************************
            *   New
            ********************************************************************************/
            if (sender.Equals(mnuDefendantNew))
            {
                if (CanChangeCurrentDefendant())
                {
                    this.SuspendLayout();

                    if (ucFilter.FilterValue.Length > 0)
                    {
                        bindingDefendants.Filter = "";
                        ucFilter.FilterValue     = "";
                    }

                    _GridViewState = GridViewState.Adding;
                    bindingDefendants.AddNew();
                    _GridViewState = GridViewState.None;

                    bindingDefendants.ResetCurrentItem();

                    this.ResumeLayout(false);

                    ucDefendant.Focus();
                }
            }

            /********************************************************************************
             *   Remove
             *********************************************************************************
             * else if( sender.Equals( mnuDefendantRemove ) )
             * {
             *  if( DialogResult.OK == MyMessageBox.Show( this, "Defendant", MyDisplayMessage.RemoveConfirm ) )
             *  {
             *      this.SuspendLayout();
             *
             *      try
             *      {
             *          bindingDefendants.RemoveCurrent();
             *          bindingDefendants.ResetBindings( false );
             *          this.ucFilter.Focus();
             *      }
             *      catch( MyException ex )
             *      {
             *          MyMessageBox.Show( this, "Defendant", MyDisplayMessage.RemoveError, ex );
             *      }
             *
             *      bindingDefendants.ResetCurrentItem();
             *
             *      this.ResumeLayout( false );
             *  }
             *
             * }*/
            /********************************************************************************
            *   Refresh
            ********************************************************************************/
            else if (sender.Equals(mnuDefendantRefresh))
            {
                if (!defendant.MyState.Equals(MyObjectState.Current))
                {
                    if (DialogResult.Cancel == MyMessageBox.Show(this, "Defendant", MyDisplayMessage.RefreshConfirm))
                    {
                        return;
                    }
                }

                this.Cursor = Cursors.WaitCursor;
                this.SuspendLayout();
                ucDefendant.SuspendLayout();

                try
                {
                    defendant.Refresh();
                    bindingDefendants.ResetBindings(false);
                    ucDefendant.Update();
                    ucDefendant.Focus();
                }
                catch (MyException ex)
                {
                    MyMessageBox.Show(this, "Defendant", MyDisplayMessage.RefreshError, ex);
                }

                ucDefendant.ResumeLayout(false);
                this.ResumeLayout(false);
                this.Cursor = Cursors.Default;
            }

            /********************************************************************************
            *   Save
            ********************************************************************************/
            else if (sender.Equals(mnuDefendantSave))
            {
                ucDefendant.Select();
                bindingDefendants.EndEdit();

                this.Cursor = Cursors.WaitCursor;
                this.SuspendLayout();

                try
                {
                    defendant.Save(true);
                    bindingDefendants.Sort = "";

                    // setting sort
                    string strSort      = string.Empty;
                    string strSortOrder = (dgvDefendants.SortOrder == SortOrder.Descending) ? "DESC" : "ASC";
                    if (dgvDefendants.SortedColumn.DataPropertyName.ToLower() == "lastname")
                    {
                        strSort = "LastName " + strSortOrder + ", FirstName " + strSortOrder;
                    }
                    else
                    {
                        strSort = "FirstName " + strSortOrder + ", LastName " + strSortOrder;
                    }
                    bindingDefendants.Sort = strSort;

                    ResetDataGridViewDefendant(defendant);
                }
                catch (MyException ex)
                {
                    MyMessageBox.Show(this, "Defendant", MyDisplayMessage.SaveError, ex);
                }
                catch (ArgumentOutOfRangeException)
                {
                    MyMessageBox.Show(this, "Payment Arrangement", MyDisplayMessage.PaymentArrangementOverlapping);
                }

                this.ResumeLayout(false);
                this.Cursor = Cursors.Default;
            }

            /********************************************************************************
            *   Cancel
            ********************************************************************************/
            else if (sender.Equals(mnuDefendantCancel))
            {
                this.SuspendLayout();
                if (defendant.MyState == MyObjectState.New)
                {
                    bindingDefendants.RemoveCurrent();
                    if (bindingDefendants.Count > 0)
                    {
                        bindingDefendants.Position = 0;
                        ucDefendant.Focus();
                    }
                    else
                    {
                        this.ucFilter.Focus();
                    }
                }
                else
                {
                    defendant.Reset();
                    bindingDefendants.ResetCurrentItem();
                }
                this.ResumeLayout(false);
            }

            /********************************************************************************
            *   Notes
            ********************************************************************************/
            else if (sender.Equals(mnuDefendantNotes))
            {
                if (frmNotes == null)
                {
                    frmNotes = new frmNotes();

                    frmNotes.DataBindings.Add("Notes", bindingDefendants, "Notes", true, DataSourceUpdateMode.OnPropertyChanged);
                    frmNotes.FormClosed += new FormClosedEventHandler(frmNotes_FormClosed);
                }

                if (!frmNotes.Visible)
                {
                    frmNotes.Show(this);
                }
                else
                {
                    frmNotes.Focus();
                }
            }

            /********************************************************************************
            *   Mail Merge
            ********************************************************************************/
            else if (sender.Equals(mnuDefendantMailMerge))
            {
                if (!MailMerge.StoreDirectoryConfigured() && !MailMerge.StoreDirectoryExists())
                {
                    MyMessageBox.Show(this, "MS Word Mail Merge", MyDisplayMessage.MailMergeDirectoryError);
                    return;
                }

                frmMailMergeTemplates frm = new frmMailMergeTemplates();
                if (DialogResult.Cancel == frm.ShowDialog(this) || string.IsNullOrEmpty(frm.SelectedMailMergeTemplatePath))
                {
                    return;
                }


                this.Cursor = Cursors.WaitCursor;

                int    defendantid  = ((Defendant)bindingDefendants.Current).ID;
                int    planid       = ucPlans.PlanId;
                string templatePath = frm.SelectedMailMergeTemplatePath;

                try
                {
                    MailMerge.PerformMailMerge(defendantid, planid, templatePath);
                }
                catch (Exception ex)
                {
                    MyMessageBox.Show(this, "Mail Merge", MyDisplayMessage.MailMergeDocumentMergeError, new MyException(ex.Message.ToString(), MyErrorType.MailMergeError, ex));
                }

                this.Cursor = Cursors.Default;
            }

            /********************************************************************************
            *   Make Payment
            ********************************************************************************/
            else if (sender.Equals(mnuDefendantPayment))
            {
                BindingSource bindingPayments = new BindingSource(new BindingSource(bindingDefendants, "Plans"), "Payments");

                frmPayment frm = new frmPayment(ref bindingPayments);

                if (!frm.IsDisposed)
                {
                    frm.ShowDialog(this);
                    bindingDefendants.ResetCurrentItem();
                }
            }

            /********************************************************************************
            *   Remove/Archive - doesn't delete from the database
            ********************************************************************************/
            else if (sender.Equals(mnuDefendantRemove))
            {
                if (DialogResult.OK == MyMessageBox.Show(this, "Remove Defendant", MyDisplayMessage.Archive))
                {
                    this.SuspendLayout();

                    defendant.Reset();

                    defendant.RaiseChangedEvents = false;
                    defendant.Active             = false;
                    defendant.Save(true);

                    // set state to new to fake out the collection into removing it but not removing it from the db.
                    //defendant.MyState = MyObjectState.New;
                    defendant.RaiseChangedEvents = true;

                    try
                    {
                        bindingDefendants.Remove(defendant);
                        bindingDefendants.ResetBindings(true);
                        this.ucFilter.Focus();
                    }
                    catch (MyException ex)
                    {
                        MyMessageBox.Show(this, "Defendant", MyDisplayMessage.RemoveError, ex);
                    }

                    this.ResumeLayout();
                }
            }
        }