示例#1
0
文件: GpdBl.cs 项目: andreyu/Reports
        /// <summary>
        /// Процедура сохранения договора в базе данных.
        /// </summary>
        /// <param name="model">Текущая модель.</param>
        /// <param name="error">Переменная для возврата текста сообщения об ошибке.</param>
        public bool SaveGpdContract(GpdContractEditModel model, out string error)
        {
            error = string.Empty;
            //нельзя отменить договор, если есть занесеный акт
            if (model.StatusID == 3 && GpdContractDao.ExistsReadyActs(model.Id))
            {
                error = "Нельзя отклонить данный договор, так как к нему уже есть готовые акты! Чтобы отменить занесение договора нужно, чтобы акт имел статус черновика!";
                return false;
            }
            UserRole currentUserRole = AuthenticationService.CurrentUser.UserRole;
            IUser currentUseId = AuthenticationService.CurrentUser;

            try
            {
                GpdContract gpdContract;// = GpdContractDao.Get(model.Id);

                if (model.Id == 0)
                {
                    gpdContract = new GpdContract
                    {
                        CreatorID = currentUseId.Id,
                        DepartmentId = model.DepartmentId,
                        PersonID = model.PersonID,
                        CTID = model.CTID,
                        StatusID = model.StatusID,
                        NumContract = model.NumContract,
                        NameContract = model.NameContract,
                        DateBegin = model.DateBegin,
                        DateEnd = model.DateEnd,
                        GPDID = model.GPDID,
                        GPDContractID = model.GPDContractID,
                        PurposePayment = model.PurposePayment,
                        DateP = model.DateP,
                        IsLong = model.DateP.HasValue ? true : false,
                        PaymentPeriodID = model.PaymentPeriodID,
                        Amount = model.Amount,
                        //DSID = model.DSID,
                        PayerID = model.PayerID,
                        PayeeID = model.PayeeID,
                        PAccountID = model.PAccountID,
                        MagEntities = new List<GpdMagProlongation>()
                    };
                }
                else
                {
                    gpdContract = GpdContractDao.Get(model.Id);
                    //if (model.DateP.HasValue && gpdContract.StatusID != 4)
                    //{
                    //    gpdContract.StatusID = model.StatusID == 3 ? 4 : model.StatusID;

                    //    if (model.DateP.HasValue && model.DatePOld.Value != model.DateP.Value)
                    //    {
                    //        gpdContract.DateP = model.DateP.Value;
                    //        gpdContract.IsLong = model.DateP.HasValue ? true : false;
                    //        gpdContract.EditDate = DateTime.Now;
                    //        gpdContract.EditorID = currentUseId.Id;
                    //    }
                    //}
                    //else
                    //{
                    //    //gpdContract.CreatorID = model.CreatorID;

                    //}
                    gpdContract.DepartmentId = model.DepartmentId;
                    gpdContract.PersonID = model.PersonID;
                    gpdContract.CTID = model.CTID;
                    gpdContract.StatusID = model.SendTo1C.HasValue ? 1 : model.StatusID == 3 ? 4 : model.StatusID;
                    gpdContract.NumContract = model.NumContract;
                    gpdContract.NameContract = model.NameContract;
                    gpdContract.DateBegin = model.DateBegin.Value;
                    gpdContract.DateEnd = model.DateEnd.Value;
                    gpdContract.GPDID = model.GPDID;
                    gpdContract.GPDContractID = model.GPDContractID;
                    gpdContract.PurposePayment = model.PurposePayment;
                    gpdContract.PaymentPeriodID = model.PaymentPeriodID;
                    gpdContract.Amount = model.Amount;
                    //gpdContract.DSID = model.DSID;
                    gpdContract.PayerID = model.PayerID;
                    gpdContract.PayeeID = model.PayeeID;
                    gpdContract.PAccountID = model.PAccountID;
                    gpdContract.EditDate = DateTime.Now;
                    gpdContract.EditorID = currentUseId.Id;
                    if (model.DateP.HasValue)
                    {
                        gpdContract.DateP = model.DateP.Value;
                        gpdContract.IsLong = true;
                        //gpdContract.StatusID = model.StatusID;
                    }
                    else
                        gpdContract.IsLong = false;
                }

                //если некоторые поля необязательны или сохраняем черновик
                if (gpdContract.CTID == 0) gpdContract.CTID = null;
                if (gpdContract.PersonID == 0) gpdContract.PersonID = null;
                if (gpdContract.PaymentPeriodID == 0) gpdContract.PaymentPeriodID = null;
                if (gpdContract.PayerID == 0) gpdContract.PayerID = null;
                if (gpdContract.PayeeID == 0) gpdContract.PayeeID = null;
                if (gpdContract.PAccountID == 0) gpdContract.PAccountID = null;
                if (gpdContract.DepartmentId == 0) gpdContract.DepartmentId = null;

                ChangeEntityProperties(gpdContract, model, currentUseId.Id);
                GpdContractDao.SaveAndFlush(gpdContract);
                model.Id = gpdContract.Id;
                return true;
            }
            catch (Exception ex)
            {
                GpdContractDao.RollbackTran();
                Log.Error("Error on SaveMissionOrderEditModel:", ex);
                error = string.Format("Исключение:{0}", ex.GetBaseException().Message);
                return false;
            }
            finally
            {
                //SetUserInfoModel(user, model);
                //SetStaticFields(model, missionHotels);
                //LoadDictionaries(model);
                //SetHiddenFields(model);
            }
        }
示例#2
0
文件: GpdBl.cs 项目: andreyu/Reports
 /// <summary>
 /// Редактируем подчиненную строку (журнал дат пролонгации договоров)
 /// </summary>
 /// <param name="entity">Объект договора.</param>
 /// <param name="model">Модель.</param>
 /// <param name="UserID">ID пользователя.</param>
 protected void ChangeEntityProperties(GpdContract entity, GpdContractEditModel model, int UserID)
 {
     if (model.DateP == null) return;
     if (model.DateP.HasValue && model.DatePOld != model.DateP)
     {
         //создаем строку для подчиненной таблицы
         GpdMagProlongation MagProlong = new GpdMagProlongation
         {
             //GCID = entity.Id,
             DateP = model.DateP,
             CreatorID = UserID,
             GpdContracts = entity
         };
         entity.MagEntities.Add(MagProlong);
     }
 }