Esempio n. 1
0
        public Accountable AddAccountable(Accountable newAccountable, User user)
        {
            AuthenticateUser(user);

            this.ChechIsAdmin(user, typeof(Accountable));

            using (CFAPContext ctx = new CFAPContext())
            {
                ctx.Configuration.ProxyCreationEnabled = false;
                try
                {
                    ctx.Accountables.Add(newAccountable);
                    ctx.SaveChanges(DbConcurencyUpdateOptions.ClientPriority);
                }
                catch (DbEntityValidationException ex)
                {
                    throw new FaultException <DataNotValidException>(new DataNotValidException(ex.EntityValidationErrors));
                }
                catch (Exception ex)
                {
                    throw new FaultException <DbException>(new DbException(ex));
                }
            }

            return(newAccountable);
        }
Esempio n. 2
0
 private void radGridView_CellDoubleClick(object sender, GridViewCellEventArgs e)
 {
     if (e.Row.DataBoundItem is Accountable)
     {
         Accountable accountableToChange = (Accountable)e.Row.DataBoundItem;
         new ChangeAccountableForm(accountableToChange, ChangeDataOptions.ChangeData).ShowDialog();
         this.Accountables.ResetBindings();
     }
 }
Esempio n. 3
0
        public ChangeAccountableForm(Accountable accountable, ChangeDataOptions changeDataOption)
        {
            InitializeComponent();

            this.accountable      = accountable;
            this.changeDataOption = changeDataOption;

            InitializeFileds();
            InitializeButtons();

            businessLogic = new CFAPBusinessLogic(new ExceptionsHandlerUI());
        }
Esempio n. 4
0
        public Accountable UpdateAccountable(Accountable accountableToUpdate, User user, DbConcurencyUpdateOptions concurencyUpdateOption)
        {
            AuthenticateUser(user);

            this.ChechIsAdmin(user, typeof(Accountable));

            using (CFAPContext ctx = new CFAPContext())
            {
                ctx.Configuration.ProxyCreationEnabled = false;

                try
                {
                    ctx.Accountables.Attach(accountableToUpdate);

                    var accountableToUpdateDbVersion = (Accountable)ctx.Entry(accountableToUpdate).GetDatabaseValues().ToObject();
                    if (accountableToUpdateDbVersion.ReadOnly)
                    {
                        throw new ReadOnlyException();
                    }

                    ctx.Entry(accountableToUpdate).State = EntityState.Modified;
                    ctx.SaveChanges(concurencyUpdateOption);
                }
                catch (ReadOnlyException)
                {
                    throw new FaultException <TryChangeReadOnlyFiledException>(new TryChangeReadOnlyFiledException(typeof(Accountable), accountableToUpdate.Id, accountableToUpdate.AccountableName, user));
                }
                catch (DbUpdateConcurrencyException ex)
                {
                    var currentValue = accountableToUpdate;
                    var dbValue      = (Accountable)ex.Entries.Single().GetDatabaseValues().ToObject();
                    ConcurrencyException <Accountable> concurrencyException = new ConcurrencyException <Accountable>(dbValue, currentValue);
                    throw new FaultException <ConcurrencyException <Accountable> >(concurrencyException);
                }
                catch (DbEntityValidationException ex)
                {
                    throw new FaultException <DataNotValidException>(new DataNotValidException(ex.EntityValidationErrors));
                }
                catch (Exception ex)
                {
                    throw new FaultException <DbException>(new DbException(ex));
                }
            }

            return(accountableToUpdate);
        }
Esempio n. 5
0
        void AttachChekedAccountable()
        {
            if (this.filter.Accountables == null || this.filter.Accountables.Length == 0)
            {
                return;
            }

            foreach (var item in this.radCheckedDropDownList_Accountables.Items)
            {
                Accountable accountable   = (Accountable)item.DataBoundItem;
                var         isCheckedItem = this.filter.Accountables.Where(a => a.Id == accountable.Id).FirstOrDefault() != null;
                if (!isCheckedItem)
                {
                    continue;
                }

                Type         itemType        = item.GetType();
                PropertyInfo checkedProperty = itemType.GetRuntimeProperty("Checked");
                checkedProperty.SetValue(item, true);
            }
        }
Esempio n. 6
0
        void AttachAccountables()
        {
            if (CFAPBusinessLogic.Accountables == null && CFAPBusinessLogic.Accountables.Count == 0)
            {
                MessageBox.Show("Данные подотчетных лиц не были получены.", "Ошибка загрузки данных", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            this.radCheckedDropDownList_Accountables.DataSource = CFAPBusinessLogic.Accountables;

            if (user.IsAccountable == false || user.Accountable == null)
            {
                return;
            }

            foreach (var item in this.radCheckedDropDownList_Accountables.Items)
            {
                Accountable accountable = item.DataBoundItem as Accountable;
                if (accountable == null)
                {
                    continue;
                }

                if (changeDataOption == ChangeDataOptions.AddNew)
                {
                    continue;
                }

                if (accountable.Id != user.Accountable.Id)
                {
                    continue;
                }

                //Обходной маневр. Невозможно присовить значения этому свойсту напрямую, но оно там есть
                Type         itemType        = item.GetType();
                PropertyInfo checkedProperty = itemType.GetRuntimeProperty("Checked");
                checkedProperty.SetValue(item, true);
            }
        }