Beispiel #1
0
        /// <summary>
        /// Crea la DoSearchHeader con i metodi standard.
        /// Se non implementati, vengono usati quelli standard
        /// </summary>
        /// <returns></returns>
        public ICollection <THeader> DoSearchHeader()
        {
            ICollection <THeader> searchHeaderList;
            IQueryOver <T, T>     queryOver = CreateQueryOver();

            queryOver = DecorateCriteria(queryOver);
            queryOver = ExecutePaging(queryOver);
            queryOver = AttachSortExpressions(queryOver);
            queryOver = AttachFilterExpressions(queryOver);
            queryOver = SetProjectionsHeaders(queryOver);
            using (ITransaction transaction = NHibernateSession.BeginTransaction())
            {
                try
                {
                    searchHeaderList = queryOver.List <THeader>();
                    transaction.Commit();
                }
                catch (Exception)
                {
                    transaction.Rollback();
                    throw;
                }
                return(searchHeaderList);
            }
        }
 /// <summary>
 /// Deletes the specified entity set.
 /// It doesn't delete weak entititied included here, unless database does it using integrity rules
 /// </summary>
 /// <param name="entitySet">The entity set.</param>
 /// <param name="parameters">The parameters.</param>
 public void Delete(object entitySet, DeleteParameters parameters)
 {
     if (parameters.DetailEntityObjects == null ||
         parameters.DetailEntityObjects.Count == 0)
     {
         // delete without transaction
         NHibernateSession.Delete(entitySet);
         if (this.AutoSave)
         {
             SaveChanges();
         }
     }
     else
     {
         // update with transaction
         //TODO: It needs to use dataaccess layer of that entity
         using (var tx = NHibernateSession.BeginTransaction())
         {
             NHibernateSession.Delete(entitySet);
             SaveDetailEntities(parameters.DetailEntityObjects);
             tx.Commit();
         }
         if (this.AutoSave)
         {
             SaveChanges();
         }
     }
 }
Beispiel #3
0
        /// <summary>
        /// 删除异常数据和成本数据
        /// </summary>
        /// <param name="wayBillCostID"></param>
        /// <returns></returns>
        public int DeleteException(int wayBillCostID, WayBillException Excmodel, WayBillCost Costmodel)
        {
            using (ITransaction trans = NHibernateSession.BeginTransaction())
            {
                try
                {
                    var a = 0;
                    //删除异常数据
                    var query = NHibernateSession.CreateSQLQuery("DELETE FROM ExpressNoExceptionDetail WHERE WayBillCostID = :WayBillCostID");
                    query.SetParameter("WayBillCostID", wayBillCostID);
                    query.ExecuteUpdate();

                    //删除成本数据
                    query = NHibernateSession.CreateSQLQuery("DELETE FROM WayBillCost WHERE ID = :ID");
                    query.SetParameter("ID", wayBillCostID);
                    query.ExecuteUpdate();

                    //添加删除异常记录
                    query = NHibernateSession.CreateSQLQuery("insert into  DelExpressNoExceptionDetail (ExpressNo,ExceptionType,ExceptionMsg,CreateTime,LoadBillNO,Status,WayBillCostID,PostingTime,DelTime) values (:ExpressNo,:ExceptionType,:ExceptionMsg,:CreateTime,:LoadBillNO,:Status,:WayBillCostID,:PostingTime,:DelTime)");
                    query.SetParameter("ExpressNo", Excmodel.ExpressNo);                  //运单号
                    query.SetParameter("ExceptionType", Excmodel.ExceptionType);          //异常类型
                    query.SetParameter("ExceptionMsg", Excmodel.ExceptionMsg);            //异常说明
                    query.SetParameter("CreateTime", DateTime.Now);                       //创建时间
                    query.SetParameter("LoadBillNO", Excmodel.LoadBillNum);               //提单号
                    query.SetParameter("Status", 0);                                      //状态
                    query.SetParameter("WayBillCostID", Excmodel.WayBillCostID);          //异常成本ID
                    query.SetParameter("PostingTime", Excmodel.PostingTime);              //收寄日期
                    query.SetParameter("DelTime", DateTime.Now);                          //删除时间
                    query.ExecuteUpdate();

                    //添加删除成本记录
                    query = NHibernateSession.CreateSQLQuery("insert into  DelWayBillCostEx (ExpressNo,WayBillFee,Weight,CreateTime,SendAddress,ProcessingFee,Product,BatchNO,PostingTime,ReconcileDate,PayStatus,PayTime,DelTime) values (:ExpressNo,:WayBillFee,:Weight,:CreateTime,:SendAddress,:ProcessingFee,:Product,:BatchNO,:PostingTime,:ReconcileDate,:PayStatus,:PayTime,:DelTime)");
                    query.SetParameter("ExpressNo", Costmodel.ExpressNo);               //邮件号
                    query.SetParameter("WayBillFee", Costmodel.WayBillFee);             //邮资
                    query.SetParameter("Weight", Costmodel.Weight);                     //重量
                    query.SetParameter("CreateTime", DateTime.Now);                     //创建时间
                    query.SetParameter("SendAddress", Costmodel.SendAddress);           //寄达地
                    query.SetParameter("ProcessingFee", Costmodel.ProcessingFee);       //邮件处理费
                    query.SetParameter("Product", Costmodel.Product);                   //产品

                    query.SetParameter("BatchNO", Costmodel.BatchNO);                   //批次
                    query.SetParameter("PostingTime", Costmodel.PostingTime);           //收寄日期

                    query.SetParameter("ReconcileDate", Costmodel.ReconcileDate);       //结算月份
                    query.SetParameter("PayStatus", Costmodel.PayStatus);               //结算状态
                    query.SetParameter("PayTime", Costmodel.PayTime);                   //结算时间
                    query.SetParameter("DelTime", DateTime.Now);                        //删除时间
                    query.ExecuteUpdate();
                    trans.Commit();
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    throw ex;
                }
            }
            return(1);
        }
Beispiel #4
0
        /// <summary>
        /// 修改后 删除异常记录
        /// </summary>
        /// <param name="costinfo"></param>
        /// <returns></returns>
        public int UpdateException(WayBillCost costinfo, WayBillException model, int WayBillCostID)
        {
            using (ITransaction trans = NHibernateSession.BeginTransaction())
            {
                try
                {
                    int a = 0;
                    //删除异常表记录
                    var query = NHibernateSession.CreateSQLQuery("DELETE FROM ExpressNoExceptionDetail WHERE WayBillCostID = :WayBillCostID ");
                    query.SetParameter("WayBillCostID", WayBillCostID);
                    query.ExecuteUpdate();

                    //修改运单成本信息
                    query = NHibernateSession.CreateSQLQuery("Update WayBillCost set Product=:Product,WayBillFee=:WayBillFee ,ProcessingFee=:ProcessingFee  WHERE ID = :ID ");
                    query.SetParameter("ID", WayBillCostID);
                    query.SetParameter("Product", costinfo.Product);                           //快递类型
                    query.SetParameter("WayBillFee", costinfo.WayBillFee);                     //运费
                    query.SetParameter("ProcessingFee", costinfo.ProcessingFee);               //操作费
                    query.ExecuteUpdate();

                    //添加 已删除运单异常记录
                    query = NHibernateSession.CreateSQLQuery("insert into  DelExpressNoExceptionDetail (ExpressNo,ExceptionType,ExceptionMsg,CreateTime,LoadBillNO,Status,WayBillCostID,PostingTime,DelTime) values (:ExpressNo,:ExceptionType,:ExceptionMsg,:CreateTime,:LoadBillNO,:Status,:WayBillCostID,:PostingTime,:DelTime)");
                    query.SetParameter("ExpressNo", model.ExpressNo);                  //运单号
                    query.SetParameter("ExceptionType", model.ExceptionType);          //异常类型
                    query.SetParameter("ExceptionMsg", model.ExceptionMsg);            //异常说明
                    query.SetParameter("CreateTime", DateTime.Now);                    //创建时间
                    query.SetParameter("LoadBillNO", model.LoadBillNum);               //提单号
                    query.SetParameter("Status", 0);                                   //状态
                    query.SetParameter("WayBillCostID", model.WayBillCostID);          //异常成本ID
                    query.SetParameter("PostingTime", model.PostingTime);              //收寄日期
                    query.SetParameter("DelTime", DateTime.Now);                       //删除时间
                    query.ExecuteUpdate();
                    trans.Commit();
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    throw ex;
                }
            }
            return(1);
        }
        /// <summary>
        /// Metodo che consente di contare i workflow assegnati all'utente.
        /// Questo metodo viene utilizzato nel frameset per riportare il numero dei workflow assegnati all'utente corrente.
        /// </summary>
        /// <returns></returns>
        public override int Count()
        {
            int counter = default(int);
            IQueryOver <WorkflowActivity, WorkflowActivity> queryOver = CreateQueryOver();

            queryOver = DecorateCriteria(queryOver);
            using (ITransaction transaction = NHibernateSession.BeginTransaction())
            {
                try
                {
                    counter = queryOver.RowCount();
                    transaction.Commit();
                }
                catch (Exception)
                {
                    transaction.Rollback();
                    throw;
                }
                return(counter);
            }
        }
 /// <summary>
 /// Inserts the specified entity set.
 /// </summary>
 /// <param name="entitySet">The entity set.</param>
 /// <param name="parameters">The parameters.</param>
 public void Insert(object entitySet, InsertParameters parameters)
 {
     SetEntityObjectAutomaticValueForInsert(entitySet);
     if (parameters.DetailEntityObjects == null ||
         parameters.DetailEntityObjects.Count == 0)
     {
         NHibernateSession.Save(entitySet);
         if (this.AutoSave)
         {
             SaveChanges();
         }
     }
     else
     {
         using (var tx = NHibernateSession.BeginTransaction())
         {
             NHibernateSession.Save(entitySet);
             AutoSetDetailFK((EntityObjectBase)entitySet, parameters.DetailEntityObjects);
             SaveDetailEntities(parameters.DetailEntityObjects);
             tx.Commit();
         }
         //SaveChanges(); no save is required.
     }
 }
        private bool InsertResolution(JsonResolutionModel jsonModel)
        {
            FileLogger.Info(this.Name, "Inizio inserimento Atto");
            Guid       mainChainId              = Guid.Empty;
            Guid       attachmentsChainId       = Guid.Empty;
            Resolution resolution               = new Resolution();
            string     typeDescription          = string.Empty;
            string     typeContainerDescription = string.Empty;

            resolution.Id                = Facade.ParameterFacade.GetIdresolution();
            resolution.Status.Id         = (short)ResolutionStatusId.Attivo;
            resolution.Year              = jsonModel.Anno;
            resolution.ProposeDate       = jsonModel.DataAdozione.ToLocalTime().Date;
            resolution.ProposeUser       = DocSuiteContext.Current.User.FullUserName;
            resolution.AdoptionDate      = jsonModel.DataAdozione.ToLocalTime().Date;
            resolution.AdoptionUser      = DocSuiteContext.Current.User.FullUserName;
            resolution.Number            = jsonModel.Numero;
            resolution.PublishingDate    = jsonModel.DataAdozione.ToLocalTime().Date;
            resolution.PublishingUser    = DocSuiteContext.Current.User.FullUserName;
            resolution.EffectivenessDate = jsonModel.DataEsecutiva.ToLocalTime().Date;
            resolution.EffectivenessUser = DocSuiteContext.Current.User.FullUserName;
            resolution.InclusiveNumber   = jsonModel.Segnatura;
            resolution.ResolutionObject  = jsonModel.Oggetto;
            resolution.Type.Id           = jsonModel.DelDet;
            string[] splitted = jsonModel.Segnatura.Split('/');
            if (splitted.Length > 1 && splitted[1] != null)
            {
                resolution.ServiceNumber = (splitted.Length > 2 && splitted[2] != null) ? string.Concat(splitted[1], "/", splitted[2]) : splitted[1];
            }
            else
            {
                HandleFailure("InsertResolution - La segnatura dell'atto indicata nel file Json non è valida");
                return(false);
            }
            if (jsonModel.DelDet == 1)
            {
                typeDescription          = "Delibera";
                typeContainerDescription = "Delibere";
            }
            else
            {
                if (jsonModel.DelDet == 0)
                {
                    typeDescription          = "Determina";
                    typeContainerDescription = "Determine";
                }
                else
                {
                    HandleFailure("InsertResolution - Errore in elaborazione: la tipologia di atto selezionata non esiste");
                    return(false);
                }
            }
            IList <Container>      containers      = Facade.ContainerFacade.GetContainerByName(string.Concat(typeContainerDescription, " ", jsonModel.Proponente));
            IList <ResolutionKind> resolutionsKind = new ResolutionKindFacade(DocSuiteContext.Current.User.FullUserName).GetByName(jsonModel.TipologiaAtto);
            IList <Contact>        contacts        = GetProposerContacts(jsonModel.Proponente);
            IList <Role>           roles           = Facade.RoleFacade.GetByName(jsonModel.Proponente);
            Category category = Facade.CategoryFacade.GetById(Parameters.ImportResolutionCategoryId);

            if (containers != null && containers.Count() == 1)
            {
                resolution.Container = containers.First();
                resolution.Location  = resolution.Container.ReslLocation;
            }
            else
            {
                HandleFailure(string.Concat("InsertResolution - Errore in elaborazione del contenitore: il contenitore ", typeContainerDescription, " ", jsonModel.Proponente, " non esiste o non è univoco."));
                return(false);
            }
            if (contacts != null && contacts.Count() == 1)
            {
                resolution.AddProposer(contacts.First());
            }
            else
            {
                HandleFailure("InsertResolution - Errore in elaborazione del contatto selezionato: il contatto selezionato non esiste o non è univoco");
                return(false);
            }
            if (category != null)
            {
                resolution.Category = category;
            }
            else
            {
                HandleFailure("InsertResolution - Errore in elaborazione del classificatore: classificatore non trovato.");
                return(false);
            }

            if (resolutionsKind != null && resolutionsKind.Any() && resolutionsKind.Count() == 1)
            {
                resolution.ResolutionKind = resolutionsKind.First();
            }
            else
            {
                HandleFailure("InsertResolution - Errore in elaborazione della tipologia di atto: la tipologia di atto non esiste o non è univoca.");
                return(false);
            }

            resolution.WorkflowType = Facade.TabMasterFacade.GetFieldValue("WorkflowType", DocSuiteContext.Current.ResolutionEnv.Configuration, jsonModel.DelDet);
            string SignatureDocument   = String.Concat(DocSuiteContext.Current.ResolutionEnv.CorporateAcronym, " ", typeDescription, " ", jsonModel.Segnatura, " del ", jsonModel.DataAdozione.ToLocalTime().ToString("d"));
            string SignatureAttachment = String.Concat(SignatureDocument, " (Allegato)");

            try
            {
                FileLogger.Info(this.Name, "InsertResolution - Inizio caricamento documenti in Biblos.");
                string           mainDocumentPath = string.Concat(Parameters.ImportResolutionSourceFolder, jsonModel.MaindocumentPath);
                FileDocumentInfo fileDocumentInfo = new FileDocumentInfo(new FileInfo(mainDocumentPath));
                fileDocumentInfo.Signature = SignatureDocument;
                BiblosDocumentInfo storedDocumentInfo = fileDocumentInfo.ArchiveInBiblos(resolution.Location.DocumentServer, resolution.Location.ReslBiblosDSDB, Guid.Empty);
                mainChainId = storedDocumentInfo.ChainId;
                FileLogger.Info(this.Name, "InsertResolution - Documento principale salvato correttamente in Biblos.");

                int integerMainChainId       = storedDocumentInfo.BiblosChainId;
                int integerAttachmentChainId = -1;
                FileDocumentInfo attachment;

                string attachmentDocumentPath;
                foreach (string attachmentRelativePath in jsonModel.AttachmentsDocumentPath)
                {
                    attachmentDocumentPath = string.Concat(Parameters.ImportResolutionSourceFolder, attachmentRelativePath);
                    attachment             = new FileDocumentInfo(new FileInfo(attachmentDocumentPath));
                    attachment.Signature   = SignatureAttachment;
                    BiblosDocumentInfo attachmentDocumentInfo = attachment.ArchiveInBiblos(resolution.Location.DocumentServer, resolution.Location.ReslBiblosDSDB, attachmentsChainId);
                    attachmentsChainId       = attachmentDocumentInfo.ChainId;
                    integerAttachmentChainId = attachmentDocumentInfo.BiblosChainId;
                    FileLogger.Info(this.Name, "InsertResolution - Allegato salvato correttamente in Biblos.");
                }

                FileResolution fileResolution = new FileResolution();
                fileResolution.Id = resolution.Id;
                fileResolution.IdResolutionFile  = integerMainChainId;
                fileResolution.IdProposalFile    = integerMainChainId;
                fileResolution.IdAssumedProposal = integerMainChainId;
                if (integerAttachmentChainId > 0)
                {
                    fileResolution.IdAttachements = integerAttachmentChainId;
                }
                resolution.File = fileResolution;
                FileLogger.Info(this.Name, "InsertResolution - Fine caricamento documenti in Biblos.");
            }
            catch (Exception ex)
            {
                HandleFailure(string.Concat("InsertResolution - Errore in elaborazione del salvataggio dell'atto in Biblos: ", ex.Message));
                return(false);
            }

            resolution.ResolutionWorkflows = new List <ResolutionWorkflow>();
            resolution.ResolutionWorkflows.Add(CreateResolutionWorkflow(resolution, 1, 0));
            resolution.ResolutionWorkflows.Add(CreateResolutionWorkflow(resolution, 2, 0));
            resolution.ResolutionWorkflows.Add(CreateResolutionWorkflow(resolution, 3, 0));
            resolution.ResolutionWorkflows.Add(CreateResolutionWorkflow(resolution, 4, 1));

            IEnumerable <ResolutionKindDocumentSeries> resolutionDocumentSeries = resolution.ResolutionKind.ResolutionKindDocumentSeries;
            IList <BiblosChainInfo>      documents;
            DocumentSeriesItem           documentSeriesItem;
            ResolutionDocumentSeriesItem resolutionDocumentSeriesItem;

            using (NHibernate.ITransaction transaction = NHibernateSession.BeginTransaction())
            {
                try
                {
                    FileLogger.Info(this.Name, "InsertResolution - Inizio transaction.");
                    Facade.ResolutionFacade.SaveWithoutTransaction(ref resolution);
                    FileLogger.Info(this.Name, "InsertResolution - Inserimento autorizzazioni atto.");
                    if (contacts.First().Role != null)
                    {
                        Facade.ResolutionRoleFacade.AddRole(resolution, contacts.First().Role.Id, DocSuiteContext.Current.ResolutionEnv.AuthorizInsertType, false);
                    }
                    foreach (ResolutionKindDocumentSeries item in resolutionDocumentSeries)
                    {
                        documents                         = new List <BiblosChainInfo>();
                        documentSeriesItem                = new DocumentSeriesItem();
                        resolutionDocumentSeriesItem      = new ResolutionDocumentSeriesItem();
                        documentSeriesItem.Status         = DocumentSeriesItemStatus.Draft;
                        documentSeriesItem.DocumentSeries = Facade.DocumentSeriesFacade.GetById(item.DocumentSeries.Id);
                        documentSeriesItem.Subject        = resolution.ResolutionObject;
                        documentSeriesItem.Category       = resolution.Category;
                        documentSeriesItem.IdMain         = mainChainId;

                        Facade.DocumentSeriesItemFacade.SaveDocumentSeriesItem(documentSeriesItem, resolution.Year.Value,
                                                                               new BiblosChainInfo(new List <DocumentInfo>()), null, null, DocSuiteContext.Current.User.FullUserName,
                                                                               DocumentSeriesItemStatus.Draft, string.Concat("Inserimento bozza di ", item.DocumentSeries.Name), false);

                        if (roles != null && roles.Any() && roles.Count() == 1)
                        {
                            Facade.DocumentSeriesItemRoleFacade.AddOwnerRole(documentSeriesItem, roles.First(), false);
                        }
                        else
                        {
                            HandleFailure("InsertResolution - Errore in elaborazione della tipologia di atto: la tipologia di atto non esiste o non è univoca.");
                            return(false);
                        }

                        resolutionDocumentSeriesItem.IdDocumentSeriesItem = documentSeriesItem.Id;
                        resolutionDocumentSeriesItem.Resolution           = resolution;
                        Facade.ResolutionDocumentSeriesItemFacade.SaveWithoutTransaction(ref resolutionDocumentSeriesItem);
                    }
                    transaction.Commit();

                    //TODO:Invio comando di creazione Resolution alle WebApi
                    // facadeFactory.ResolutionFacade.SendCreateResolutionCommand(resolution);

                    FileLogger.Info(this.Name, "InsertResolution - Transaction completata con successo.");
                }
                catch (Exception ex)
                {
                    FileLogger.Error(this.Name, String.Format("InsertResolution - Errore in salvataggio di atto: Message: {0} - StackTrace: {1}", ex.Message, ex.StackTrace));
                    transaction.Rollback();
                }
            }
            Facade.ResolutionLogFacade.Log(resolution, ResolutionLogType.RI, string.Concat("Inserimento atto n.", resolution.InclusiveNumber));
            return(true);
        }
Beispiel #8
0
        public DbTransaction BeginTransaction()
        {
            ITransaction tran = NHibernateSession.BeginTransaction();// NHibernateSessionManager.Instance.BeginTransactionOn(SessionFactoryConfigPath);

            return(new DbTransaction(tran));
        }
Beispiel #9
0
 public void BeginTran()
 {
     NHibernateSession.BeginTransaction();
 }