Ejemplo n.º 1
0
        private bool CanChangeCurrentRestrictedCasePrefix()
        {
            bool rtnValue = true;

            if (bindingRestrictedCasePrefixes.Current != null)
            {
                RestrictedCasePrefix restrictedcaseprefix = (RestrictedCasePrefix)bindingRestrictedCasePrefixes.Current;

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

                    switch (MyMessageBox.Show(this, "Restricted Case Prefixes", MyDisplayMessage.SaveConfirm))
                    {
                    case DialogResult.Yes:
                        dgvRestrictedCasePrefixes.EndEdit();
                        bindingRestrictedCasePrefixes.EndEdit();
                        try
                        {
                            restrictedcaseprefix.Save(true);
                            bindingRestrictedCasePrefixes.ResetCurrentItem();
                            rtnValue = true;
                        }
                        catch (MyException ex)
                        {
                            MyMessageBox.Show(this, "Restricted Case Prefixes", MyDisplayMessage.SaveError, ex);
                            rtnValue = false;
                        }
                        break;

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

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

            return(rtnValue);
        }
        public static RestrictedCasePrefix CreateCasePrefix(SqlDataReader dr)
        {
            RestrictedCasePrefix prefix = new RestrictedCasePrefix();

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

                prefix = new RestrictedCasePrefix(id, updatedby, updateddate);

                prefix.RaiseChangedEvents = false;

                prefix.CasePrefix = dr["prefix"].ToString();
                prefix.Save(false);

                prefix.RaiseChangedEvents = true;
            }

            return(prefix);
        }
Ejemplo n.º 3
0
        private void mnuRestrictedCasePrefixes_Click(object sender, EventArgs e)
        {
            RestrictedCasePrefix restrictedcaseprefix = (RestrictedCasePrefix)bindingRestrictedCasePrefixes.Current;

            /********************************************************************************
            *   New
            ********************************************************************************/
            if (sender.Equals(mnuRestrictedCasePrefixesNew))
            {
                if (CanChangeCurrentRestrictedCasePrefix())
                {
                    _GridViewState = GridViewState.Adding;
                    bindingRestrictedCasePrefixes.AddNew();
                    _GridViewState = GridViewState.None;
                }
            }

            /********************************************************************************
            *   Remove
            ********************************************************************************/
            else if (sender.Equals(mnuRestrictedCasePrefixesRemove))
            {
                if (DialogResult.OK == MyMessageBox.Show(this, "Restricted Case Prefixes", MyDisplayMessage.RemoveConfirm))
                {
                    try
                    {
                        bindingRestrictedCasePrefixes.RemoveCurrent();
                        bindingRestrictedCasePrefixes.ResetBindings(false);
                    }
                    catch (MyException ex)
                    {
                        MyMessageBox.Show(this, "Restricted Case Prefixes", MyDisplayMessage.RemoveError, ex);
                    }
                }
            }

            /********************************************************************************
            *   Refresh
            ********************************************************************************/
            else if (sender.Equals(mnuRestrictedCasePrefixesRefresh))
            {
                if (!restrictedcaseprefix.MyState.Equals(MyObjectState.Current))
                {
                    if (DialogResult.Cancel == MyMessageBox.Show(this, "Restricted Case Prefixes", MyDisplayMessage.RefreshConfirm))
                    {
                        return;
                    }
                }

                try
                {
                    restrictedcaseprefix.Refresh();
                    bindingRestrictedCasePrefixes.ResetBindings(false);
                }
                catch (MyException ex)
                {
                    MyMessageBox.Show(this, "Restricted Case Prefixes", MyDisplayMessage.RefreshError, ex);
                }
            }

            /********************************************************************************
            *   Save
            ********************************************************************************/
            else if (sender.Equals(mnuRestrictedCasePrefixesSave))
            {
                dgvRestrictedCasePrefixes.EndEdit();
                bindingRestrictedCasePrefixes.EndEdit();
                try
                {
                    restrictedcaseprefix.Save(true);
                    bindingRestrictedCasePrefixes.ResetBindings(false);


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

                    ResetDataGridViewRestrictedCasePrefixes(restrictedcaseprefix);
                }
                catch (MyException ex)
                {
                    MyMessageBox.Show(this, "Restricted Case Prefixes", MyDisplayMessage.SaveError, ex);
                }
            }

            /********************************************************************************
            *   Cancel
            ********************************************************************************/
            else if (sender.Equals(mnuRestrictedCasePrefixesCancel))
            {
                if (restrictedcaseprefix.MyState == MyObjectState.New)
                {
                    bindingRestrictedCasePrefixes.RemoveCurrent();
                }
                else
                {
                    restrictedcaseprefix.Reset();
                    bindingRestrictedCasePrefixes.ResetCurrentItem();
                }
            }
        }