public bool AddModules(IList <Module> controllers)
        {
            try
            {
                _moduleRepository.BeginTransaction();
                foreach (var controller in controllers)
                {
                    foreach (var moduleAction in controller.ModuleActions)
                    {
                        _moduleActionRepository.Save(moduleAction);
                    }
                    if (controller.Id == 0)
                    {
                        controller.CreateTimestamp();
                    }
                    else
                    {
                        controller.UpdateTimestamp();
                    }
                    _moduleRepository.SaveOrUpdate(controller);
                }

                _moduleRepository.CommitTransaction();


                return(true);
            }
            catch (Exception)
            {
                _moduleRepository.RollbackTransaction();
                throw;
            }
        }
        public bool AddModuleActions(IList <ModuleAction> actionResults)
        {
            try
            {
                _moduleActionRepository.BeginTransaction();
                foreach (var actionResult in actionResults)
                {
                    if (actionResult.Id == 0)
                    {
                        actionResult.CreateTimestamp();
                    }
                    else
                    {
                        actionResult.UpdateTimestamp();
                    }
                    _moduleActionRepository.Save(actionResult);
                }

                _moduleActionRepository.CommitTransaction();

                return(true);
            }
            catch (Exception)
            {
                _moduleActionRepository.RollbackTransaction();
                throw;
            }
        }
        public static void GenerateRouteRealDirection()
        {
            using (IRepository rep = ServiceProvider.GetService <IRepositoryFactory>().GenerateRepository <Route>())
            {
                var list = rep.List <Route>();
                foreach (var i in list)
                {
                    using (IRepository rep2 = ServiceProvider.GetService <IRepositoryFactory>().GenerateRepository <Route>())
                    {
                        GenerateRouteDirectionReals(i, rep2);
                    }

                    try
                    {
                        rep.BeginTransaction();
                        rep.Update(i);
                        rep.CommitTransaction();
                    }
                    catch (Exception ex)
                    {
                        rep.RollbackTransaction();
                        ServiceProvider.GetService <IExceptionProcess>().ProcessWithNotify(ex);
                    }
                }
            }
        }
        //public static void GenerateRouteRealDirection(string routeName)
        //{
        //    using (IRepository rep = ServiceProvider.GetService<IRepositoryFactory>().GenerateRepository<Route>())
        //    {
        //        Route route = rep.Get<Route>(routeName);
        //        if (route == null)
        //            return;

        //        GenerateRouteRealDirection(route, rep);
        //    }
        //}
        public static void GenerateRouteSampleTracks(string routeName = null)
        {
            using (IRepository rep = ServiceProvider.GetService <IRepositoryFactory>().GenerateRepository <Route>())
            {
                IList <Route> list;
                if (string.IsNullOrEmpty(routeName))
                {
                    list = rep.List <Route>();
                }
                else
                {
                    list = new List <Route> {
                        rep.Get <Route>(routeName)
                    };
                }
                foreach (var i in list)
                {
                    GenerateRouteSampleTrack(i);

                    try
                    {
                        rep.BeginTransaction();
                        rep.Update(i);
                        rep.CommitTransaction();
                    }
                    catch (Exception ex)
                    {
                        rep.RollbackTransaction();
                        ServiceProvider.GetService <IExceptionProcess>().ProcessWithNotify(ex);
                    }
                }
            }
        }
 object IConvertible.ToType(Type conversionType, IFormatProvider provider)
 {
     try
     {
         IEntityBuffer eb = EntityBufferCollection.Instance[this.GetType()];
         if (eb != null)
         {
             return(eb.Get(this.Identity));
         }
         else
         {
             using (IRepository rep = ServiceProvider.GetService <IRepositoryFactory>().GenerateRepository(this.GetType()))
             {
                 rep.BeginTransaction();
                 var r = rep.Get(this.GetType(), this.Identity);
                 rep.CommitTransaction();
                 return(r);
             }
         }
     }
     catch (Exception ex)
     {
         throw new InvalidCastException("Convert is invalid!", ex);
     }
 }
Exemple #6
0
        public Task HandleAsync(UpdatePhoneCommand command)
        {
            try
            {
                var phone = phoneRepository.Get(command.Id);

                if (phone == null)
                {
                    throw new PhoneNotFound("Phone with this id not found");
                }

                var phoneToPatch = mapper.Map <UpdatePhoneCommand>(command);

                command.PatchDocument().ApplyTo(phoneToPatch);

                mapper.Map(phoneToPatch, phone);

                phoneRepository.Update(phone);
                phoneRepository.CommitTransaction();

                return(Task.CompletedTask);
            }

            catch (PhoneNotFound)
            {
                phoneRepository.RollbackTransaction();
                throw;
            }

            catch (Exception)
            {
                phoneRepository.RollbackTransaction();
                throw;
            }
        }
Exemple #7
0
        /// <summary>
        /// 补填没有进港地的出口票
        /// </summary>
        public static void Helper_出口票_进港地()
        {
            using (IRepository rep = ServiceProvider.GetService <IRepositoryFactory>().GenerateRepository <出口票>())
            {
                IList <出口票> list = (rep as Feng.NH.INHibernateRepository)
                                   .List <出口票>(NHibernate.Criterion.DetachedCriteria.For <出口票>()
                                               .Add(NHibernate.Criterion.Expression.IsNull("进港地编号")));

                if (list != null && list.Count > 0)
                {
                    nbediRead nbedi = new nbediRead();
                    string    mt;
                    foreach (出口票 ckp in list)
                    {
                        try
                        {
                            mt = nbedi.查询进场码头(ckp.船名航次.Split('/')[0], ckp.船名航次.Split('/')[1], ckp.提单号);
                            if (mt == "BLCTMS")
                            {
                                mt = "梅山码头";
                            }
                        }
                        catch
                        {
                            // 查询进场码头的网站可能会发生错误,将被忽略继续执行
                            continue;
                        }
                        ckp.进港地编号 = (string)NameValueMappingCollection.Instance.FindColumn2FromColumn1("人员单位_港区堆场", "全称", "编号", mt);
                        rep.BeginTransaction();
                        rep.Update(ckp);
                        rep.CommitTransaction();
                    }
                }
            }
        }
        public Task Handle(PhoneCreatedEvent @event)
        {
            try
            {
                Guid phoneId = Guid.NewGuid();

                var mappedPhone = mapper.Map <Phone>(@event);

                mappedPhone.Id        = phoneId;
                mappedPhone.AddedDate = DateTime.Now;

                mappedPhone.Dimensions.Id = Guid.NewGuid();
                mappedPhone.Display.Id    = Guid.NewGuid();
                mappedPhone.Media.ForEach(media => media.Id = Guid.NewGuid());

                ordersRepository.Insert(mappedPhone);

                ordersRepository.CommitTransaction();

                return(Task.CompletedTask);
            }

            catch (Exception ex)
            {
                ordersRepository.RollbackTransaction();

                throw new BaseApiException(System.Net.HttpStatusCode.InternalServerError, ex.ToString());
            }
        }
Exemple #9
0
        public static void 提交(ArchiveOperationForm masterForm)
        {
            调节款 tjk = masterForm.ControlManager.DisplayManager.CurrentItem as 调节款;

            if (tjk == null)
            {
                return;
            }

            using (IRepository rep = RepositoryFactory.GenerateRepository <调节款>())
            {
                try
                {
                    rep.BeginTransaction();
                    tjk.Submitted = true;
                    rep.Update(tjk);

                    rep.Initialize(tjk, tjk.调节款明细);
                    foreach (调节款明细 i in tjk.调节款明细)
                    {
                        应收应付款 j = i.Clone() as 应收应付款;
                        j.应收应付源 = tjk;
                        rep.Save(j);
                    }

                    rep.CommitTransaction();
                }
                catch (Exception)
                {
                    rep.RollbackTransaction();
                }
            }
        }
Exemple #10
0
        public bool  达专家任务(任务 rw, DateTime?时间要求始, DateTime?时间要求止, string 区域编号, int?缓急程度, DateTime 达时间)
        {
            using (IRepository rep = base.GenerateRepository())
            {
                try
                {
                    rep.BeginTransaction();
                    专家任务 zjrw = new 专家任务();
                    zjrw.新任务号     = "O" + rw.任务号;
                    zjrw.IsActive = true;
                    zjrw.时间要求始    = 时间要求始.HasValue ? 时间要求始.Value : zjrw.时间要求始;
                    zjrw.时间要求止    = 时间要求止.HasValue ? 时间要求止.Value : zjrw.时间要求止;
                    zjrw.区域编号     = 区域编号;
                    zjrw.缓急程度     = 缓急程度.HasValue ? 缓急程度.Value : 0;
                    zjrw.达时间      = 达时间;
                    zjrw.任务性质     = Get专家任务性质(rw);
                    base.Save(rep, zjrw);

                    rw.专家任务 = zjrw;
                    m_任务dao.Update(rep, rw);
                    rep.CommitTransaction();

                    return(true);
                }
                catch (Exception ex)
                {
                    rep.RollbackTransaction();
                    rw.专家任务 = null;
                    ExceptionProcess.ProcessWithNotify(ex);

                    return(false);
                }
            }
        }
Exemple #11
0
        //private 专家任务Dao 专家任务Dao
        //{
        //    get
        //    {
        //        if (m_专家任务dao == null)
        //        {
        //            m_专家任务dao = new 专家任务Dao();
        //        }
        //        return m_专家任务dao;
        //    }
        //}
        /// <summary>
        /// 专家任务.车辆作业 = null,Delete(车辆作业)
        /// </summary>
        /// <param name="clzy"></param>
        public void 撤销车辆作业(车辆作业 clzy)
        {
            if (clzy == null)
            {
                return;
            }

            using (IRepository rep = this.GenerateRepository())
            {
                try
                {
                    rep.BeginTransaction();

                    专家任务 zjrw = clzy.专家任务;
                    zjrw.车辆作业 = null;
                    m_专家任务dao.Update(rep, zjrw);
                    base.Delete(rep, clzy);

                    rep.CommitTransaction();
                }
                catch (Exception)
                {
                    rep.RollbackTransaction();
                    throw;
                }
            }
        }
Exemple #12
0
        public void 处理作业异常(车辆作业 车辆作业, string 处理结果, DateTime?处理时间, bool 准备处理)
        {
            using (IRepository rep = this.GenerateRepository())
            {
                try
                {
                    作业异常情况 entity = rep.Get <作业异常情况>(车辆作业.最新作业状态.作业异常Id);
                    if (!string.IsNullOrEmpty(处理结果))
                    {
                        entity.处理结果 = 处理结果;
                        entity.处理状态 = "已处理";
                        entity.处理时间 = 处理时间.HasValue ? 处理时间.Value : System.DateTime.Now;
                    }
                    else if (准备处理)
                    {
                        entity.处理状态 = "处理中";
                    }
                    else
                    {
                        entity.处理状态 = "待处理";
                    }

                    rep.BeginTransaction();
                    base.Update(rep, entity);
                    rep.CommitTransaction();

                    Update最新状态(车辆作业, entity);
                }
                catch (Exception)
                {
                    rep.RollbackTransaction();
                    throw;
                }
            }
        }
Exemple #13
0
        public static void 撤销提交(ArchiveOperationForm masterForm)
        {
            调节款 tjk = masterForm.ControlManager.DisplayManager.CurrentItem as 调节款;

            if (tjk == null)
            {
                return;
            }

            using (IRepository rep = RepositoryFactory.GenerateRepository <调节款>())
            {
                try
                {
                    rep.BeginTransaction();
                    tjk.Submitted = false;
                    rep.Update(tjk);

                    IList <应收应付款> list = rep.Session.CreateCriteria <应收应付款>()
                                         .Add(NHibernate.Criterion.Expression.Eq("应收应付源", tjk))
                                         .List <应收应付款>();
                    foreach (应收应付款 i in list)
                    {
                        rep.Delete(i);
                    }
                    rep.CommitTransaction();
                }
                catch (Exception)
                {
                    rep.RollbackTransaction();
                }
            }
        }
Exemple #14
0
        private async Task SaveToDb(params CurrencyValue[] values)
        {
            var dbCurrencies = await _repository.Query <Currency>()
                               .ToDictionaryAsync(c => c.Name, StringComparer.OrdinalIgnoreCase);

            _repository.BeginTransaction();
            foreach (var value in values)
            {
                if (!dbCurrencies.TryGetValue(value.Name, out var currency))
                {
                    currency = new Currency {
                        Name = value.Name
                    };
                    await _repository.InsertAsync(currency);

                    await _repository.SaveChangesAsync();

                    dbCurrencies.Add(value.Name, currency);
                }

                var currencyValue = new DAL.Context.CurrencyValue
                {
                    Date       = value.Date,
                    Value      = value.Value,
                    Currency   = currency,
                    Amount     = value.Amount,
                    CurrencyId = currency?.Id ?? 0
                };

                await _repository.MergeAsync(currencyValue, cv => new { cv.Date, cv.CurrencyId });
            }

            _repository.CommitTransaction();
        }
Exemple #15
0
        public static void 自动填备注(ArchiveOperationForm masterForm)
        {
            int successCount = 0, skipCount = 0;

            ProgressAsyncHelper asyncHelper = new ProgressAsyncHelper(
                new Feng.Async.AsyncHelper.DoWork(delegate()
            {
                using (IRepository rep = ServiceProvider.GetService <IRepositoryFactory>().GenerateRepository <业务费用>())
                {
                    rep.BeginTransaction();
                    foreach (Xceed.Grid.DataRow row in masterForm.MasterGrid.GridControl.SelectedRows)
                    {
                        if (!row.Cells["状态"].Value.ToString().Contains("64"))         // 只有“未对账”的费用才会自动填备注
                        {
                            if (MessageForm.ShowYesNo("第 " + row.Cells["Id"].Value.ToString() + " 条不是未对账费用!" + Environment.NewLine
                                                      + "提单号:" + row.Cells["提单号"].Value.ToString()
                                                      + " 箱号:" + row.Cells["箱号"].Value.ToString()
                                                      + " 费用项:" + row.Cells["费用项"].Value.ToString()
                                                      + Environment.NewLine + "“是”跳过继续,“否”取消所有操作?", "提示"))
                            {
                                skipCount++;
                                continue;
                            }
                            else
                            {
                                successCount = skipCount = 0;
                                rep.RollbackTransaction();
                                return(null);
                            }
                        }

                        IList <业务费用> ywfy = (rep as Feng.NH.INHibernateRepository).List <业务费用>(NHibernate.Criterion.DetachedCriteria.For <业务费用>()
                                                                                               .Add(NHibernate.Criterion.Expression.Eq("费用实体.ID", new Guid(row.Cells["费用实体"].Value.ToString())))
                                                                                               .Add(NHibernate.Criterion.Expression.Eq("箱Id", new Guid(row.Cells["箱"].Value.ToString())))
                                                                                               .Add(NHibernate.Criterion.Expression.Eq("费用项编号", row.Cells["费用项"].Value.ToString()))
                                                                                               .Add(NHibernate.Criterion.Expression.Eq("相关人编号", row.Cells["相关人"].Value.ToString()))
                                                                                               .Add(NHibernate.Criterion.Expression.Eq("金额", (decimal)row.Cells["金额"].Value)));

                        if (ywfy.Count > 1)
                        {
                            rep.RollbackTransaction();
                            throw new NullReferenceException("第 " + row.Cells["Id"].Value.ToString() + " 条对应了" + ywfy.Count + "条财务费用"
                                                             + Environment.NewLine + "可能由于重复登记,请先查看删除多余记录");
                        }

                        ywfy[0].备注 += row.Cells["备注"].Value.ToString();
                        new 业务费用Dao().Update(rep, ywfy[0]);
                        successCount++;
                    }

                    rep.CommitTransaction();
                }
                return(null);
            }),
                new Feng.Async.AsyncHelper.WorkDone(delegate(object result)
            {
                MessageForm.ShowInfo("成功" + successCount + "条, 跳过" + skipCount + "条");
            }), masterForm, "执行");
        }
Exemple #16
0
 private void CommitTransaction(IRepository rep, OperateArgs <T> e)
 {
     if (rep.IsSupportTransaction)
     {
         OnTransactionCommitting(e);
         rep.CommitTransaction();
         OnTransactionCommited(e);
     }
 }
Exemple #17
0
        public static void 自动生成费用(ArchiveOperationForm masterForm)
        {
            Dictionary <string, object> setData = masterForm.Tag as Dictionary <string, object>;
            费用实体 entity;

            using (IRepository rep = ServiceProvider.GetService <IRepositoryFactory>().GenerateRepository <业务费用>())
            {
                rep.BeginTransaction();
                entity = rep.Get <费用实体>(setData["费用实体"]);
                rep.CommitTransaction();
            }

            if (entity.费用实体类型编号 == 11 /*费用实体类型.进口*/)
            {
                using (IRepository rep = ServiceProvider.GetService <IRepositoryFactory>().GenerateRepository <进口票>())
                {
                    进口票 piao = rep.Get <进口票>(setData["费用实体"]);
                    rep.Initialize(piao.箱, piao);
                    process_fy_yw.批量生成费用(rep, entity.费用实体类型编号, piao, piao.箱, (string)setData["费用项"], !setData.ContainsKey("收付标志") ? null : (收付标志?)setData["收付标志"]);
                }
            }
            else if (entity.费用实体类型编号 == 15 /*费用实体类型.内贸出港*/)
            {
                using (IRepository rep = ServiceProvider.GetService <IRepositoryFactory>().GenerateRepository <内贸出港票>())
                {
                    内贸出港票 piao = rep.Get <内贸出港票>(setData["费用实体"]);
                    rep.Initialize(piao.箱, piao);
                    process_fy_yw.批量生成费用(rep, entity.费用实体类型编号, piao, piao.箱, (string)setData["费用项"], !setData.ContainsKey("收付标志") ? null : (收付标志?)setData["收付标志"]);
                }
            }
            else if (entity.费用实体类型编号 == 45 /*费用实体类型.进口其他业务*/)
            {
                using (IRepository rep = ServiceProvider.GetService <IRepositoryFactory>().GenerateRepository <进口其他业务票>())
                {
                    进口其他业务票 piao = rep.Get <进口其他业务票>(setData["费用实体"]);
                    rep.Initialize(piao.箱, piao);
                    process_fy_yw.批量生成费用(rep, entity.费用实体类型编号, piao, piao.箱, (string)setData["费用项"], !setData.ContainsKey("收付标志") ? null : (收付标志?)setData["收付标志"]);
                }
            }
            else if (entity.费用实体类型编号 == 13 /*费用实体类型.出口*/)
            {
                using (IRepository rep = ServiceProvider.GetService <IRepositoryFactory>().GenerateRepository <出口票>())
                {
                    出口票 piao = rep.Get <出口票>(setData["费用实体"]);
                    rep.Initialize(piao.箱, piao);
                    process_fy_yw.批量生成费用(rep, entity.费用实体类型编号, piao, piao.箱, (string)setData["费用项"], !setData.ContainsKey("收付标志") ? null : (收付标志?)setData["收付标志"]);
                }
            }

            (masterForm.MasterGrid as IBoundGrid).ReloadData();
        }
        /// <summary>
        /// 生成多个报表,并保存到月报表数据中
        /// </summary>
        /// <param name="reportInfoNames"></param>
        /// <param name="dateStart"></param>
        /// <param name="dateEnd"></param>
        public static void GenerateMonthReport(MonthReportInfo monthReportInfo, string[] reportInfoNames)
        {
            LogEntityDao <MonthReportInfo>     dao    = new LogEntityDao <MonthReportInfo>();
            LogEntityDao <MonthReportDataInfo> subDao = new LogEntityDao <MonthReportDataInfo>();

            using (IRepository rep = ServiceProvider.GetService <IRepositoryFactory>().GenerateRepository <MonthReportInfo>())
            {
                try
                {
                    rep.BeginTransaction();
                    dao.Update(rep, monthReportInfo);

                    if (monthReportInfo.Reports != null)
                    {
                        foreach (MonthReportDataInfo i in monthReportInfo.Reports)
                        {
                            rep.Delete(i);
                        }
                        monthReportInfo.Reports.Clear();
                    }
                    foreach (string s in reportInfoNames)
                    {
                        MonthReportDataInfo dataInfo = new MonthReportDataInfo();
                        dataInfo.Name        = s;
                        dataInfo.MonthReport = monthReportInfo;
                        dataInfo.Data        = GenerateReport(s, monthReportInfo.报表日期起, monthReportInfo.报表日期止);
                        dataInfo.ClientId    = 0;
                        dataInfo.OrgId       = 0;

                        if (monthReportInfo.Reports == null)
                        {
                            monthReportInfo.Reports = new List <MonthReportDataInfo>();
                        }
                        monthReportInfo.Reports.Add(dataInfo);

                        subDao.Save(rep, dataInfo);
                    }

                    rep.CommitTransaction();
                }
                catch (Exception ex)
                {
                    rep.RollbackTransaction();
                    ExceptionProcess.ProcessWithNotify(ex);
                }
            }
        }
Exemple #19
0
        public void 开始监控(车辆作业 车辆作业, DateTime 时间, string 驾驶员编号, string 车载Id)
        {
            using (IRepository rep = this.GenerateRepository())
            {
                try
                {
                    rep.BeginTransaction();

                    Track track = null;
                    if (!string.IsNullOrEmpty(车载Id))
                    {
                        track             = new Track();
                        track.Name        = "作业" + 车辆作业.作业号;
                        track.VehicleName = 车载Id;
                        track.StartTime   = 时间;
                        track.IsActive    = true;
                        track.Route       = GetDefaultRoute(车辆作业);
                        m_trackDao.Save(rep, track);
                    }

                    车辆作业.驾驶员编号 = 驾驶员编号;
                    车辆作业.开始时间  = 时间;
                    车辆作业.车载Id号 = 车载Id;
                    m_车辆作业Dao.Update(rep, 车辆作业);
                    车辆作业.Track = track == null ? null : (long?)track.ID;

                    作业监控状态 entity = new 作业监控状态();
                    entity.IsActive = true;
                    entity.车辆作业     = 车辆作业;
                    entity.时间       = 时间;
                    更新作业监控状态(rep, entity, 车辆作业.最新作业状态, null, null);
                    if (track != null && track.Route != null && track.Route.Time.HasValue)
                    {
                        entity.预计到达时间 = System.DateTime.Now.AddMinutes(track.Route.Time.Value);
                    }
                    base.Save(rep, entity);

                    rep.CommitTransaction();
                    Update最新状态(车辆作业, entity);
                }
                catch (Exception)
                {
                    rep.RollbackTransaction();
                    throw;
                }
            }
        }
Exemple #20
0
        /// <summary>
        /// 保存并返回车辆作业
        /// </summary>
        /// <param name="cl"></param>
        /// <param name="zjrw"></param>
        /// <param name="bz"></param>
        /// <returns></returns>
        public 车辆作业 生成车辆作业(车辆 cl, 专家任务 zjrw, string bz)
        {
            if (cl == null || zjrw == null)
            {
                return(null);
            }

            using (IRepository rep = this.GenerateRepository())
            {
                try
                {
                    rep.BeginTransaction();

                    车辆作业 clzy = new 车辆作业();
                    clzy.车辆       = cl;
                    clzy.专家任务     = zjrw;
                    clzy.IsActive = true;
                    clzy.作业号      = 生成作业号(zjrw.新任务号);
                    clzy.备注       = bz;
                    base.Save(rep, clzy);

                    zjrw.车辆作业 = clzy;
                    m_专家任务dao.Update(rep, zjrw);

                    作业监控状态 entity = new 作业监控状态();
                    entity.IsActive = true;
                    entity.车辆作业     = clzy;
                    entity.时间       = System.DateTime.Now;
                    作业监控Dao.更新作业监控状态(rep, entity, clzy.最新作业状态, null, null);
                    //var route = m_作业监控Dao.GetDefaultRoute(clzy);
                    //if (route != null && route.Time.HasValue)
                    //{
                    //    entity.预计到达时间 = System.DateTime.Now.AddMinutes(route.Time.Value);
                    //}
                    m_作业监控Dao.Save(rep, entity);

                    rep.CommitTransaction();

                    return(clzy);
                }
                catch (Exception)
                {
                    rep.RollbackTransaction();
                    throw;
                }
            }
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="action"></param>
 public static void DoInRepository(Action <IRepository> action)
 {
     using (IRepository rep = ServiceProvider.GetService <IRepositoryFactory>().GenerateRepository())
     {
         try
         {
             rep.BeginTransaction();
             action(rep);
             rep.CommitTransaction();
         }
         catch (Exception)
         {
             rep.RollbackTransaction();
             throw;
         }
     }
 }
Exemple #22
0
        private void Load()
        {
            m_buffers = new System.Collections.Generic.Dictionary <object, object>();

            using (IRepository rep = ServiceProvider.GetService <IRepositoryFactory>().GenerateRepository(m_persistentClass))
            {
                rep.BeginTransaction();
                IList list = rep.List(m_persistentClass);
                rep.CommitTransaction();

                foreach (object i in list)
                {
                    object id = EntityScript.GetPropertyValue(i, ServiceProvider.GetService <IEntityMetadataGenerator>().GenerateEntityMetadata(m_persistentClass).IdName);
                    m_buffers[id] = i;
                }
            }
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="dao"></param>
 /// <param name="action"></param>
 public static void DoInRepository(IRepositoryDao dao, Action <IRepository> action)
 {
     using (IRepository rep = dao.GenerateRepository())
     {
         try
         {
             rep.BeginTransaction();
             action(rep);
             rep.CommitTransaction();
         }
         catch (Exception)
         {
             rep.RollbackTransaction();
             throw;
         }
     }
 }
Exemple #24
0
        /// <summary>
        ///
        /// </summary>
        public void ResumeOperation()
        {
            if (m_suspendRep == null)
            {
                throw new InvalidOperationException("you should call SuspendOperation first!");
            }

            try
            {
                if (m_suspendRep.IsSupportTransaction)
                {
                    m_suspendRep.CommitTransaction();
                }
                //OnTransactionCommited(new OperateArgs<T>(rep, OperateType.Update, entity));

                Clear();
            }
            catch (InvalidUserOperationException)
            {
                // 出错的时候,MemoryBll不清空
                if (m_suspendRep.IsSupportTransaction)
                {
                    m_suspendRep.RollbackTransaction();
                }
                //OnTransactionRollbacked(new OperateArgs<T>(rep, OperateType.Update, entity));

                throw;
            }
            catch (Exception)
            {
                if (m_suspendRep.IsSupportTransaction)
                {
                    m_suspendRep.RollbackTransaction();
                }
                //OnTransactionRollbacked(new OperateArgs<T>(rep, OperateType.Update, entity));

                Clear();
                throw;
            }
            finally
            {
                m_suspendRep.Dispose();
                m_suspendRep = null;
            }
        }
        public AccountType AddSavingsInterest(AccountType AccountType)
        {
            _AccountType = new Repository <AccountType>(_session);
            _AccountType.BeginTransaction();

            try
            {
                _AccountType.Update(AccountType);
                _AccountType.CommitTransaction();
            }
            catch (Exception)
            {
                _AccountType.RollbackTransaction();
                throw;
            }

            return(AccountType);
        }
        public Transaction AddTransaction(Transaction Transaction)
        {
            _Transaction = new Repository <Transaction>(_session);
            _Transaction.BeginTransaction();

            try
            {
                _Transaction.Save(Transaction);
                _Transaction.CommitTransaction();
            }
            catch (Exception)
            {
                _Transaction.RollbackTransaction();
                throw;
            }

            return(Transaction);
        }
        public Customer CreateUser(Customer Customer)
        {
            _Customer = new Repository <Customer>(_session);
            _Customer.BeginTransaction();

            try
            {
                _Customer.Save(Customer);
                _Customer.CommitTransaction();
            }
            catch (Exception)
            {
                _Customer.RollbackTransaction();
                throw;
            }

            return(Customer);
        }
        public Account AddAccount(Account Account)
        {
            _Account = new Repository <Account>(_session);
            _Account.BeginTransaction();

            try
            {
                _Account.Save(Account);
                _Account.CommitTransaction();
            }
            catch (Exception)
            {
                _Account.RollbackTransaction();
                throw;
            }

            return(Account);
        }
        public UserProfile InsertRole(UserProfile UserProfile)
        {
            _UserProfile = new Repository <UserProfile>(_session);
            _UserProfile.BeginTransaction();

            try
            {
                _UserProfile.Save(UserProfile);
                _UserProfile.CommitTransaction();
            }
            catch (Exception)
            {
                _UserProfile.RollbackTransaction();
                throw;
            }

            return(UserProfile);
        }
        public Task <CreatePhoneCommandResponse> HandleAsync(CreatePhoneCommand command)
        {
            try
            {
                Guid phoneId = Guid.NewGuid();

                var mappedPhone = mapper.Map <Phone>(command);

                mappedPhone.Id        = phoneId;
                mappedPhone.AddedDate = DateTime.Now;

                mappedPhone.Dimensions.Id = Guid.NewGuid();
                mappedPhone.Display.Id    = Guid.NewGuid();
                mappedPhone.Media.ForEach(media => media.Id = Guid.NewGuid());

                phoneRepository.Insert(mappedPhone);

                eventBus.Publish(new PhoneCreatedEvent(
                                     command.Name,
                                     command.Manufacturer,
                                     command.Dimensions,
                                     command.Weight,
                                     command.Display,
                                     command.CPUModel,
                                     command.RAM,
                                     command.OS,
                                     command.Price,
                                     command.Media));

                phoneRepository.CommitTransaction();

                return(Task.FromResult(new CreatePhoneCommandResponse()
                {
                    Id = phoneId,
                    Links = mediaTypeCheckService.CanCreateHATEOASLink() ? hateoasLinksService.CreateLinksForPhones(phoneId) : null
                }));
            }

            catch (Exception ex)
            {
                phoneRepository.RollbackTransaction();
                throw new BaseApiException(System.Net.HttpStatusCode.InternalServerError, ex.ToString());
            }
        }
Exemple #31
0
        public static int 批量生成费用(IRepository rep, 车辆产值 票, IEnumerable 箱, string 费用项编号, 收付标志? 收付标志)
        {
            int cnt = 0;

            // 需按照委托人合同和付款合同生成相应费用和费用理论值
            // 如果总体来生成,则按照:
            // 如果费用已经打了完全标志,则不生成。如果相应理论值已经生成过,也不生成。
            // 如果单个费用项来生成,则不管理论值是否已经生成过
            // Todo: 理论值可能显示生成票的,后来信息完全了再生成箱的,此时要删除票的
            //using (IRepository rep = ServiceProvider.GetService<IRepositoryFactory>().GenerateRepository(票.GetType()))
            {
                try
                {
                    rep.BeginTransaction();

                    IList<业务费用理论值> llzs = (rep as Feng.NH.INHibernateRepository).List<业务费用理论值>(NHibernate.Criterion.DetachedCriteria.For<业务费用理论值>()
                                            .Add(NHibernate.Criterion.Expression.Eq("费用实体.ID", 票.ID)));

                    rep.Initialize(票.费用, 票);

                    process_fy_generate.批量生成费用(rep, 票, 箱, 费用项编号, 收付标志, llzs);

                    ////  有几项(发票税,贴息费)要看收款费用
                    // 不行,会多生成
                    //批量生成费用付款(rep, 费用实体类型, 票, 箱, 费用项编号, 收付标志, llzs);

                    rep.CommitTransaction();
                }
                catch (Exception ex)
                {
                    rep.RollbackTransaction();
                    ServiceProvider.GetService<IExceptionProcess>().ProcessWithNotify(ex);
                }
            }
            return cnt;
        }
Exemple #32
0
 private void SaveFiles(IRepository rep, KeyValuePair<string, IList<string>> fileList)
 {
     foreach (string file in fileList.Value)
     {
         try
         {
             rep.BeginTransaction();
             if (File.Exists(file))
             {
                 byte[] bytes = ReadFile(file);
                 if (bytes == null || bytes.Length == 0)
                 {
                     Console.WriteLine("ForWatcher Error:<" + fileList.Key + ">" + Environment.NewLine
                         + "Nor found the file or fileStream length is 0 \"" + file + "\"");
                     continue;
                 }
                 FileInfo fileInfo = new FileInfo(file);
                 AttachmentInfo newAtt = new AttachmentInfo();
                 newAtt.EntityName = m_EntityName;
                 newAtt.EntityId = fileList.Key;
                 newAtt.FileName = fileInfo.Name;
                 newAtt.Data = bytes;
                 newAtt.Description = "附件";
                 newAtt.Created = fileInfo.CreationTime;
                 newAtt.CreatedBy = "服务";
                 newAtt.Updated = fileInfo.LastWriteTime;
                 rep.Save(newAtt);
             }
             rep.CommitTransaction();
         }
         catch (Exception ex)
         {
             rep.RollbackTransaction();
             Console.WriteLine("ForWatcher Error:<" + fileList.Key + ">" + Environment.NewLine + ex.Message);
             System.Windows.Forms.MessageBox.Show("<" + fileList.Key + ">" + Environment.NewLine + ex.Message, "ForWatcher Error");
             continue;
         }
     }
 }