private void dgvPaymentArrangementTypes_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
 {
     if (e.RowIndex == -1 && dgvPaymentArrangementTypes.SelectedRows.Count > 0)
     {
         _GridViewState = GridViewState.Sorting;
         _paymentArrangementTypeTemp = ((PaymentArrangementType)dgvPaymentArrangementTypes.SelectedRows[0].DataBoundItem);
     }
 }
        private bool CanChangeCurrentPaymentArrangementType()
        {
            bool rtnValue = true;

            if (bindingPaymentArrangementTypes.Current != null)
            {
                PaymentArrangementType paymentarrangementtype = (PaymentArrangementType)bindingPaymentArrangementTypes.Current;

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

                    switch (MyMessageBox.Show(this, "Payment Arrangement Type", MyDisplayMessage.SaveConfirm))
                    {
                    case DialogResult.Yes:
                        dgvPaymentArrangementTypes.EndEdit();
                        bindingPaymentArrangementTypes.EndEdit();
                        try
                        {
                            paymentarrangementtype.Save(true);
                            bindingPaymentArrangementTypes.ResetCurrentItem();
                            rtnValue = true;
                        }
                        catch (MyException ex)
                        {
                            MyMessageBox.Show(this, "Payment Arrangement Type", MyDisplayMessage.SaveError, ex);
                            rtnValue = false;
                        }
                        break;

                    case DialogResult.No:
                        if (paymentarrangementtype.MyState == MyObjectState.New)
                        {
                            bindingPaymentArrangementTypes.RemoveCurrent();
                            bindingPaymentArrangementTypes.ResetBindings(false);
                        }
                        else
                        {
                            paymentarrangementtype.Reset();
                        }
                        rtnValue = true;
                        break;

                    case DialogResult.Cancel:
                        rtnValue = false;
                        break;
                    }
                    break;
                }
            }

            return(rtnValue);
        }
 private void dgvPaymentArrangementTypes_Sorted(object sender, EventArgs e)
 {
     if (_paymentArrangementTypeTemp != null)
     {
         int row = bindingPaymentArrangementTypes.IndexOf(_paymentArrangementTypeTemp);
         dgvPaymentArrangementTypes.BeginInvoke((MethodInvoker) delegate()
         {
             dgvPaymentArrangementTypes.Rows[row].Selected = true;
             dgvPaymentArrangementTypes.CurrentCell        = dgvPaymentArrangementTypes[0, row];
         });
     }
     _paymentArrangementTypeTemp = null;
     _GridViewState = GridViewState.None;
 }
 private void ResetDataGridViewPaymentArrangementType(PaymentArrangementType paymentarrangementtype)
 {
     if (paymentarrangementtype != null)
     {
         int row = bindingPaymentArrangementTypes.IndexOf(paymentarrangementtype);
         if (row >= 0)
         {
             dgvPaymentArrangementTypes.BeginInvoke((MethodInvoker) delegate()
             {
                 dgvPaymentArrangementTypes.Rows[row].Selected = true;
                 dgvPaymentArrangementTypes.CurrentCell        = dgvPaymentArrangementTypes[0, row];
             });
         }
     }
 }
        public static PaymentArrangementType CreatePaymentArrangementType(SqlDataReader dr)
        {
            PaymentArrangementType payperiod = new PaymentArrangementType();

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

                payperiod = new PaymentArrangementType(id, updatedby, updateddate);

                payperiod.RaiseChangedEvents = false;

                payperiod.PaymentArrangementTypeName = dr["paymentarrangementtype"].ToString();
                payperiod.Save(false);

                payperiod.RaiseChangedEvents = true;
            }

            return(payperiod);
        }
        private void mnuPaymentArrangementType_Click(object sender, EventArgs e)
        {
            PaymentArrangementType paymentarrangementtype = (PaymentArrangementType)bindingPaymentArrangementTypes.Current;

            /********************************************************************************
            *   New
            ********************************************************************************/
            if (sender.Equals(mnuPaymentArrangementTypeNew))
            {
                if (CanChangeCurrentPaymentArrangementType())
                {
                    _GridViewState = GridViewState.Adding;
                    bindingPaymentArrangementTypes.AddNew();
                    _GridViewState = GridViewState.None;
                }
            }

            /********************************************************************************
            *   Remove
            ********************************************************************************/
            else if (sender.Equals(mnuPaymentArrangementTypeRemove))
            {
                if (DialogResult.OK == MyMessageBox.Show(this, "Payment Arrangement Type", MyDisplayMessage.RemoveConfirm))
                {
                    try
                    {
                        bindingPaymentArrangementTypes.RemoveCurrent();
                        bindingPaymentArrangementTypes.ResetBindings(false);
                    }
                    catch (MyException ex)
                    {
                        MyMessageBox.Show(this, "Payment Arrangement Type", MyDisplayMessage.RemoveError, ex);
                    }
                }
            }

            /********************************************************************************
            *   Refresh
            ********************************************************************************/
            else if (sender.Equals(mnuPaymentArrangementTypeRefresh))
            {
                if (!paymentarrangementtype.MyState.Equals(MyObjectState.Current))
                {
                    if (DialogResult.Cancel == MyMessageBox.Show(this, "Payment Arrangement Type", MyDisplayMessage.RefreshConfirm))
                    {
                        return;
                    }
                }

                try
                {
                    paymentarrangementtype.Refresh();
                    bindingPaymentArrangementTypes.ResetBindings(false);
                }
                catch (MyException ex)
                {
                    MyMessageBox.Show(this, "Payment Arrangement Type", MyDisplayMessage.RefreshError, ex);
                }
            }

            /********************************************************************************
            *   Save
            ********************************************************************************/
            else if (sender.Equals(mnuPaymentArrangementTypeSave))
            {
                dgvPaymentArrangementTypes.EndEdit();
                bindingPaymentArrangementTypes.EndEdit();
                try
                {
                    paymentarrangementtype.Save(true);
                    bindingPaymentArrangementTypes.ResetBindings(false);


                    bindingPaymentArrangementTypes.Sort = "";
                    if (dgvPaymentArrangementTypes.SortOrder == SortOrder.Descending)
                    {
                        bindingPaymentArrangementTypes.Sort = dgvPaymentArrangementTypes.SortedColumn.DataPropertyName + " DESC";
                    }
                    else
                    {
                        bindingPaymentArrangementTypes.Sort = dgvPaymentArrangementTypes.SortedColumn.DataPropertyName + " ASC";
                    }

                    ResetDataGridViewPaymentArrangementType(paymentarrangementtype);
                }
                catch (MyException ex)
                {
                    MyMessageBox.Show(this, "Payment Arrangement Type", MyDisplayMessage.SaveError, ex);
                }
            }

            /********************************************************************************
            *   Cancel
            ********************************************************************************/
            else if (sender.Equals(mnuPaymentArrangementTypeCancel))
            {
                if (paymentarrangementtype.MyState == MyObjectState.New)
                {
                    bindingPaymentArrangementTypes.RemoveCurrent();
                }
                else
                {
                    paymentarrangementtype.Reset();
                    bindingPaymentArrangementTypes.ResetCurrentItem();
                }
            }
        }