コード例 #1
0
 /// <summary>
 /// Catching a column header click on the defendant datagridview.  It saves the
 /// currently selected defendnant so it can try and restore after a sort operation.
 /// </summary>
 /// <param name="sender">not used</param>
 /// <param name="e">mouse event arguments for cellmousedown event in the defendant datagridview.</param>
 private void dgvDefendants_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
 {
     if (e.RowIndex == -1 && dgvDefendants.SelectedRows.Count > 0)
     {
         _defendantTemp = ((Defendant)dgvDefendants.SelectedRows[0].DataBoundItem);
     }
 }
コード例 #2
0
        public static Defendant CreateCurrentDefendant(SqlDataReader dr)
        {
            Defendant defendant = new Defendant();

            int      id;
            string   updatedby;
            DateTime?updateddate;

            if (!dr.IsClosed && dr.HasRows)
            {
                // getting id that uniquely identifies the object
                id          = Convert.ToInt32(dr["defendantid"]);
                updatedby   = dr["updatedby"].ToString();
                updateddate = (DateTime?)dr["updateddate"];

                defendant = new Defendant(id, updatedby, updateddate);

                defendant.RaiseChangedEvents = false;

                defendant.FirstName  = dr["firstname"].ToString();
                defendant.MiddleName = dr["middlename"].ToString();
                defendant.LastName   = dr["lastname"].ToString();
                defendant.Aka        = dr["aka"].ToString();
                defendant.SSN        = dr["ssn"].ToString();
                if (!dr.IsDBNull(dr.GetOrdinal("birthdate")))
                {
                    defendant.BirthDate = dr["birthdate"].ToString();
                }
                defendant.DriversLicense      = dr["driverslicense"].ToString();
                defendant.Street1             = dr["street1"].ToString();
                defendant.Street2             = dr["street2"].ToString();
                defendant.City                = dr["city"].ToString();
                defendant.StateID             = (dr.IsDBNull(dr.GetOrdinal("stateid"))) ? -1 : Convert.ToInt32(dr["stateid"].ToString());
                defendant.Zip                 = dr["zip"].ToString();
                defendant.HomePhone           = dr["phonehome"].ToString();
                defendant.MobilePhone         = dr["phonemobile"].ToString();
                defendant.HasProbationOfficer = (dr.IsDBNull(dr.GetOrdinal("hasprobationofficer"))) ? false : Convert.ToBoolean(dr["hasprobationofficer"].ToString());
                defendant.ProbationOfficer    = dr["probationofficer"].ToString();
                if (!dr.IsDBNull(dr.GetOrdinal("barreduntil")))
                {
                    defendant.BarredUntil = dr["barreduntil"].ToString();
                }
                defendant.Notes = dr["notes"].ToString();
                if (!dr.IsDBNull(dr.GetOrdinal("active")))
                {
                    defendant.Active = Convert.ToBoolean(dr["active"].ToString());
                }
                defendant.Save(false);

                defendant.RaiseChangedEvents = true;
            }

            return(defendant);
        }
コード例 #3
0
        private bool CanChangeCurrentDefendant()
        {
            bool rtnValue = true;

            if (bindingDefendants.Current != null)
            {
                Defendant defendant = (Defendant)bindingDefendants.Current;

                switch (defendant.MyState)
                {
                case MyObjectState.New:
                case MyObjectState.Modified:

                    switch (MyMessageBox.Show(this, "Defendant", MyDisplayMessage.SaveConfirm))
                    {
                    case DialogResult.Yes:
                        try
                        {
                            defendant.Save(true);
                            bindingDefendants.ResetCurrentItem();
                            rtnValue = true;
                        }
                        catch (MyException ex)
                        {
                            MyMessageBox.Show(this, "Defendant", MyDisplayMessage.SaveError, ex);
                            rtnValue = false;
                        }
                        break;

                    case DialogResult.No:
                        if (defendant.MyState == MyObjectState.New)
                        {
                            bindingDefendants.RemoveCurrent();
                            bindingDefendants.ResetBindings(false);
                            ucDefendant.Focus();
                        }
                        else
                        {
                            defendant.Reset();
                        }
                        rtnValue = true;
                        break;

                    case DialogResult.Cancel:
                        rtnValue = false;
                        break;
                    }
                    break;
                }
            }
            return(rtnValue);
        }
コード例 #4
0
 /// <summary>
 /// Highlights the defendant object argument in the defendant datagridview.
 /// Helps to specify behavior of highligted defendant after sorts, inserts,
 /// and delete operations.
 /// </summary>
 /// <param name="defendant">The defendnat object to be highlighted.</param>
 private void ResetDataGridViewDefendant(Defendant defendant)
 {
     if (defendant != null)
     {
         int row = bindingDefendants.IndexOf(defendant);
         if (row >= 0)
         {
             dgvDefendants.BeginInvoke((MethodInvoker) delegate()
             {
                 this.SuspendLayout();
                 dgvDefendants.Rows[row].Selected = true;
                 dgvDefendants.CurrentCell        = dgvDefendants[0, row];
                 this.ResumeLayout();
             });
         }
     }
 }
コード例 #5
0
        private void ucFilter_OnFilterChanged(object sender, string filterString)
        {
            if (CanChangeCurrentDefendant())
            {
                // can change the defendant, so save the currently selected, so I can try and reselct it after the filter
                if (bindingDefendants.Current != null)
                {
                    _defendantTemp = ((Defendant)dgvDefendants.SelectedRows[0].DataBoundItem);
                }


                this.SuspendLayout();
                this.dgvDefendants.SuspendLayout();

                // set the filter
                if (!string.IsNullOrEmpty(filterString))
                {
                    bindingDefendants.Filter = filterString;
                    _strFilter = ((ucFilter)sender).FilterValue;
                }
                else
                {
                    bindingDefendants.Filter = null;
                    bindingDefendants.ResetBindings(false);
                }

                if (_defendantTemp != null)
                {
                    ResetDataGridViewDefendant(_defendantTemp);
                    _defendantTemp = null;
                }

                this.dgvDefendants.ResumeLayout(false);
                this.ResumeLayout(false);
            }
            else
            {
                // set the filter back to the previous value
                ((ucFilter)sender).FilterValue = _strFilter;
            }
        }
コード例 #6
0
 /// <summary>
 /// The defendant datagridview has been sorted.  Reselecting the defendant
 /// that was selected before the sort.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void dgvDefendants_Sorted(object sender, EventArgs e)
 {
     ResetDataGridViewDefendant(_defendantTemp);
     _defendantTemp = null;
 }
コード例 #7
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();
                }
            }
        }