Esempio n. 1
0
        public IList <D_User_Model> GetUserByUserLoginName(List <string> UserLoginName)
        {
            ICriteria ic = NhSession.CreateCriteria(typeof(D_User_Model));

            ic.Add(Restrictions.In("UserLoginName", UserLoginName));
            return(ic.List <D_User_Model>());
        }
Esempio n. 2
0
        /// <summary>
        /// 分页获取数据字典
        /// </summary>
        /// <param name="page"></param>
        /// <param name="rowCount"></param>
        /// <param name="roleName"></param>
        /// <param name="createDate"></param>
        /// <param name="totalCount"></param>
        /// <returns></returns>
        public IList <D_Dictionary_Model> GetAllByPage(int startCount, int rowCount, DicTypeEnum?dicType, string dicName, string createDate, out int totalCount)
        {
            ICriteria ic = NhSession.CreateCriteria(typeof(D_Dictionary_Model));

            if (!string.IsNullOrEmpty(dicName))
            {
                ic.Add(Restrictions.Like("DicName", dicName, MatchMode.Anywhere));
            }

            if (!string.IsNullOrEmpty(createDate))
            {
                ic.Add(Restrictions.Le("CreateDateTime", createDate));
            }
            if (dicType.HasValue)
            {
                ic.Add(Restrictions.Eq("DicType", dicType));
            }

            ic.Add(Restrictions.Eq("DataStatus", false));

            ICriteria pageCrit = CriteriaTransformer.Clone(ic);

            totalCount = Convert.ToInt32(pageCrit.SetProjection(Projections.RowCount()).UniqueResult());

            ic.AddOrder(new Order("Ord", false));

            IList <D_Dictionary_Model> list = ic.SetFirstResult(startCount).SetMaxResults(rowCount).List <D_Dictionary_Model>();

            return(list);
        }
Esempio n. 3
0
        /// <summary>
        /// 获取所有用户角色信息
        /// </summary>
        /// <returns></returns>
        public IList <D_Role_Model> GetAll()
        {
            ICriteria            ic   = NhSession.CreateCriteria(typeof(D_Role_Model));
            IList <D_Role_Model> list = ic.List <D_Role_Model>() ?? new List <D_Role_Model>();

            return(list);
        }
Esempio n. 4
0
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="model"></param>
        /// <returns>true or false</returns>
        public bool SaveList(List <D_Board_User_Role_Model> models)
        {
            NHibernate.ITransaction tran = NhSession.BeginTransaction();
            try
            {
                foreach (var item in models)
                {
                    NhSession.SaveOrUpdate(item);
                }

                tran.Commit();
                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (!tran.WasCommitted && !tran.WasRolledBack)
                {
                    tran.Rollback();
                }
            }
        }
        public void RemoveRelation(IRelationById item, AbstractScopedCache repositoryScopedCache)
        {
            var sessionIdAsString = GetSessionId().ToString("n");

            using (DisposableTimer.TraceDuration <NhSessionHelper>("In RemoveRelation for session " + sessionIdAsString, "End RemoveRelation for session " + sessionIdAsString))
            {
                var relationType = GetOrCreateNodeRelationType(item.Type.RelationName, repositoryScopedCache);

                // Nh should handle this for us but got an error with mappings atm in SqlCe (APN 09/11/11)
                // Clear session cache to make sure it loads all of the tags in order to delete them all
                NhSession.Flush();

                // Clear the repository cache of this relation in case one has been added and then removed in the same unit of work
                var cacheKey = GenerateCacheKeyForRelation(item, relationType);
                repositoryScopedCache.InvalidateItems(cacheKey);

                var sourceIdValue      = (Guid)item.SourceId.Value;
                var destinationIdValue = (Guid)item.DestinationId.Value;

                var existingRelation = GetDbRelation(relationType.Alias, sourceIdValue, destinationIdValue).ToArray();

                if (existingRelation.Any())
                {
                    existingRelation.ForEach(x => NhSession.Delete(x));
                }
            }
        }
        public IEnumerable <RelationById> PerformGetParentRelations(HiveId childId, RelationType relationType = null)
        {
            if (childId.Value.Type != HiveIdValueTypes.Guid)
            {
                return(Enumerable.Empty <RelationById>());
            }

            using (NhProfilerLogging.Start(NhSession, "PerformGetParentRelations",
                                           new OdbcParameter("childId", childId),
                                           new OdbcParameter("relationType", relationType)))
            {
                var value = (Guid)childId.Value;
                // Reference the value here because otherwise it gets lost in NH's query cache

                var query = NhSession.QueryOver <NodeRelation>()
                            .Where(x => x.EndNode.Id == value)
                            .Fetch(x => x.StartNode).Lazy
                            .Fetch(x => x.EndNode).Lazy
                            .Fetch(x => x.NodeRelationTags).Eager
                            .Fetch(x => x.NodeRelationType).Eager;

                if (relationType != null)
                {
                    var relationName  = relationType.RelationName;
                    var nodeRelations = query.JoinQueryOver <NodeRelationType>(x => x.NodeRelationType).Where(x => x.Alias == relationName).Cacheable().List();
                    return(nodeRelations.Select(MapNodeRelation).ToList());
                }

                var relations = query.Cacheable().List();
                return(relations.Select(MapNodeRelation).ToList());
            }
        }
Esempio n. 7
0
        public IList <D_Board_User_Role_Model> GetModelListByUser(D_User_Model userModel)
        {
            ICriteria ic = NhSession.CreateCriteria(typeof(D_Board_User_Role_Model));;

            ic.Add(Restrictions.Eq("UserGuid", userModel));
            //IList<D_Board_User_Role_Model> list = ic.List<D_Board_User_Role_Model>();
            return(ic.List <D_Board_User_Role_Model>());
        }
Esempio n. 8
0
        /// <summary>
        /// 获取所有用户角色权限
        /// </summary>
        /// <returns></returns>
        public IList <D_Role_Permissions_Model> GetRole_Permissions_ByRole(D_Role_Model role)
        {
            ICriteria ic = NhSession.CreateCriteria(typeof(D_Role_Permissions_Model));

            ic.Add(Restrictions.Eq("RoleGuid", role));
            ic.Add(Restrictions.Eq("DataStatus", false));
            IList <D_Role_Permissions_Model> list = ic.List <D_Role_Permissions_Model>() ?? new List <D_Role_Permissions_Model>();

            return(list);
        }
Esempio n. 9
0
        public D_User_Model GetUserByUserLoginName(string userLoginName)
        {
            ICriteria ic = NhSession.CreateCriteria(typeof(D_User_Model));

            ic.Add(Restrictions.Eq("UserLoginName", userLoginName));
            ic.Add(Restrictions.Eq("DataStatus", false));
            D_User_Model model = ic.UniqueResult <D_User_Model>();

            return(model);
        }
Esempio n. 10
0
        public D_Board_User_Role_Model GetOne(D_Board_Model boardModel, D_User_Model userModel, D_Role_Model roleModel)
        {
            ICriteria ic = NhSession.CreateCriteria(typeof(D_Board_User_Role_Model));

            ic.Add(Restrictions.Eq("BoardGuid", boardModel));
            ic.Add(Restrictions.Eq("UserGuid", userModel));
            ic.Add(Restrictions.Eq("RoleGuid", roleModel));
            return(ic.List <D_Board_User_Role_Model>().SingleOrDefault());
            //IList<D_Board_User_Role_Model> list = ic.List<D_Board_User_Role_Model>();
            //return list.FirstOrDefault<D_Board_User_Role_Model>();
        }
Esempio n. 11
0
        /// <summary>
        /// 获取字典值通过数据字典枚举
        /// </summary>
        /// <returns></returns>
        public IList <D_Dictionary_Model> GetDictionaryByDicType(DicTypeEnum dicType)
        {
            ICriteria ic = NhSession.CreateCriteria(typeof(D_Dictionary_Model));

            ic.Add(Restrictions.Eq("DicType", dicType));

            ic.Add(Restrictions.Eq("DataStatus", false));

            IList <D_Dictionary_Model> list = ic.List <D_Dictionary_Model>() ?? new List <D_Dictionary_Model>();

            return(list);
        }
Esempio n. 12
0
        public IList <D_WorkFlowLog_Model> GetAllByPage(int startCount, int rowCount, D_Report_Model reportModel, out int totalCount)
        {
            ICriteria ic = NhSession.CreateCriteria(typeof(D_WorkFlowLog_Model));

            ic.Add(Restrictions.Eq("ReportGuid", reportModel));

            ICriteria pageCrit = CriteriaTransformer.Clone(ic);

            totalCount = Convert.ToInt32(pageCrit.SetProjection(Projections.RowCount()).UniqueResult());

            IList <D_WorkFlowLog_Model> list = ic.SetFirstResult(startCount).SetMaxResults(rowCount).List <D_WorkFlowLog_Model>();

            return(list);
        }
Esempio n. 13
0
        public void MapAndMerge(AbstractEntity entity, MappingEngineCollection mappers)
        {
            using (DisposableTimer.TraceDuration <NhSessionHelper>("Start MapAndMerge for entity " + entity.Id, "End MapAndMerge"))
                using (NhProfilerLogging.Start(NhSession, "MapAndMerge",
                                               new OdbcParameter("entity", entity)))
                {
                    var rdbmsEntity = mappers.MapToIntent <IReferenceByGuid>(entity);

                    // Track ID generation on the Rdbms object so that it can be pinged to the AbstractEntity upon Save/Update commit
                    rdbmsEntity = NhSession.Merge(rdbmsEntity) as IReferenceByGuid;

                    //InnerDataContext.NhibernateSession.SaveOrUpdate(rdbmsEntity);
                    mappers.Map(rdbmsEntity, entity, rdbmsEntity.GetType(), entity.GetType());
                }
        }
Esempio n. 14
0
 private IEnumerable <NodeRelation> GetDbRelation(string relationName, Guid sourceValue, Guid destValue)
 {
     return(NhSession.QueryOver <NodeRelation>()
            .Where(x => x.StartNode.Id == sourceValue)
            .And(x => x.EndNode.Id == destValue)
            .Fetch(x => x.StartNode).Lazy
            .Fetch(x => x.EndNode).Lazy
            .Fetch(x => x.NodeRelationTags).Eager
            .Fetch(x => x.NodeRelationType).Eager
            .JoinQueryOver(x => x.NodeRelationType)
            .Where(x => x.Alias == relationName)
            .Cacheable()
            .List()
            .Distinct()); // This query generates a cartesian product of the NodeRelationTags and NH 'handily' gives us x * NodeRelations so can't do a Take(1)
 }
Esempio n. 15
0
        public bool SaveWorkFlowLog(D_Report_Model model, D_WorkFlowLog_Model logModel)
        {
            NHibernate.ITransaction tran = NhSession.BeginTransaction();
            try
            {
                logModel.ReportGuid = model;

                NhSession.SaveOrUpdate(model.ReportD2);
                NhSession.SaveOrUpdate(model);
                if (model.ReportD8DataModels.Count > 0)
                {
                    foreach (var item in model.ReportD8DataModels)
                    {
                        NhSession.SaveOrUpdate(item);
                    }
                }
                if (model.WorkFlow_Models.Count > 0)
                {
                    foreach (var item in model.WorkFlow_Models)
                    {
                        NhSession.SaveOrUpdate(item);
                    }
                }
                if (model.WorkFlowLog_Models.Count > 0)
                {
                    foreach (var item in model.WorkFlowLog_Models)
                    {
                        NhSession.SaveOrUpdate(item);
                    }
                }

                NhSession.SaveOrUpdate(model);

                tran.Commit();
                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (!tran.WasCommitted && !tran.WasRolledBack)
                {
                    tran.Rollback();
                }
            }
        }
Esempio n. 16
0
        public NodeRelationType GetOrCreateNodeRelationType(string alias, AbstractScopedCache repositoryScopedCache)
        {
            return(repositoryScopedCache.GetOrCreateTyped(
                       "NodeRelationType-" + alias,
                       () =>
            {
                var existing = NhSession.QueryOver <NodeRelationType>()
                               .Where(x => x.Alias == alias)
                               .Cacheable()
                               .Take(1)
                               .SingleOrDefault <NodeRelationType>();

                return existing ?? new NodeRelationType()
                {
                    Alias = alias, Id = alias.EncodeAsGuid()
                };
            }));
        }
Esempio n. 17
0
        /// <summary>
        /// 分页获取板块
        /// </summary>
        /// <param name="page"></param>
        /// <param name="rowCount"></param>
        /// <param name="roleName"></param>
        /// <param name="createDate"></param>
        /// <param name="totalCount"></param>
        /// <returns></returns>
        public IList <D_Board_User_Role_Model> GetAllByPage(int startCount, int rowCount, Model.D_Board_Model boardModel, out int totalCount)
        {
            ICriteria ic = NhSession.CreateCriteria(typeof(D_Board_User_Role_Model));

            ic.Add(Restrictions.Eq("BoardGuid", boardModel));

            //if (!string.IsNullOrEmpty(createDate))
            //    ic.Add(Restrictions.Le("CreateDateTime", createDate));

            ICriteria pageCrit = CriteriaTransformer.Clone(ic);

            totalCount = Convert.ToInt32(pageCrit.SetProjection(Projections.RowCount()).UniqueResult());

            ic.AddOrder(Order.Desc("CreateDateTime"));

            IList <D_Board_User_Role_Model> list = ic.SetFirstResult(startCount).SetMaxResults(rowCount).List <D_Board_User_Role_Model>();

            return(list);
        }
Esempio n. 18
0
        /// <summary>
        /// 分页获取报表列表
        /// </summary>
        /// <param name="page"></param>
        /// <param name="rowCount"></param>
        /// <param name="roleName"></param>
        /// <param name="createDate"></param>
        /// <param name="totalCount"></param>
        /// <returns></returns>
        public IList <D_Report_Model> GetAllByPage(int startCount, int rowCount, List <Model.D_Board_Model> boardModel, string reportNo, string createDate, out int totalCount)
        {
            ICriteria ic = NhSession.CreateCriteria(typeof(D_Report_Model));

            if (boardModel != null)
            {
                if (boardModel.Count > 0)
                {
                    ic.Add(Restrictions.In("ReportBoardGuid", boardModel));
                }
                else
                {
                    ic.Add(Restrictions.IsNull("ReportBoardGuid"));
                }
            }
            else
            {
                ic.Add(Restrictions.IsNull("ReportBoardGuid"));
            }

            if (!string.IsNullOrEmpty(reportNo))
            {
                ic.Add(Restrictions.Like("ReportNo", reportNo, MatchMode.Anywhere));
            }

            if (!string.IsNullOrEmpty(createDate))
            {
                ic.Add(Restrictions.Le("CreateDateTime", createDate));
            }

            ic.Add(Restrictions.Eq("DataStatus", false));

            ICriteria pageCrit = CriteriaTransformer.Clone(ic);

            totalCount = Convert.ToInt32(pageCrit.SetProjection(Projections.RowCount()).UniqueResult());

            ic.AddOrder(Order.Desc("ModifyDateTime"));
            IList <D_Report_Model> list = ic.SetFirstResult(startCount).SetMaxResults(rowCount).List <D_Report_Model>();

            return(list);
        }
Esempio n. 19
0
 /// <summary>
 /// 删除数据字典
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public bool Delete(D_Dictionary_Model model)
 {
     NHibernate.ITransaction tran = NhSession.BeginTransaction();
     try
     {
         NhSession.Delete(model);
         tran.Commit();
         return(true);
     }
     catch (Exception ex)
     {
         throw ex;
     }
     finally
     {
         if (!tran.WasCommitted && !tran.WasRolledBack)
         {
             tran.Rollback();
         }
     }
 }
Esempio n. 20
0
        public IList <D_User_Model> GetAllByPage(int page, int rowCount, string userName, string userCode, string departmentName,
                                                 string userLoginName, string createDate, out int totalCount)
        {
            ICriteria ic = NhSession.CreateCriteria(typeof(D_User_Model));

            if (!string.IsNullOrEmpty(userName))
            {
                ic.Add(Restrictions.Like("UserName", userName, MatchMode.Anywhere));
            }

            if (!string.IsNullOrEmpty(userCode))
            {
                ic.Add(Restrictions.Like("UserCode", userCode, MatchMode.Anywhere));
            }

            if (!string.IsNullOrEmpty(userLoginName))
            {
                ic.Add(Restrictions.Like("UserLoginName", userLoginName, MatchMode.Anywhere));
            }

            if (!string.IsNullOrEmpty(departmentName))
            {
                ic.Add(Restrictions.Like("DepartmentName", departmentName, MatchMode.Anywhere));
            }

            if (!string.IsNullOrEmpty(createDate))
            {
                ic.Add(Restrictions.Le("CreateDateTime", createDate));
            }

            ic.Add(Restrictions.Eq("DataStatus", false));

            ICriteria pageCrit = CriteriaTransformer.Clone(ic);

            totalCount = Convert.ToInt32(pageCrit.SetProjection(Projections.RowCount()).UniqueResult());

            IList <D_User_Model> list = ic.SetFirstResult(page * rowCount).SetMaxResults(rowCount).List <D_User_Model>();

            return(list);
        }
Esempio n. 21
0
        public IEnumerable <RelationById> PerformGetBranchRelations(HiveId siblingId, RelationType relationType = null)
        {
            if (siblingId.Value.Type != HiveIdValueTypes.Guid)
            {
                return(Enumerable.Empty <RelationById>());
            }

            using (NhProfilerLogging.Start(NhSession, "PerformGetBranchRelations",
                                           new OdbcParameter("siblingId", siblingId),
                                           new OdbcParameter("relationType", relationType)))
            {
                var value = (Guid)siblingId.Value;
                // Reference the value here because otherwise it gets lost in NH's query cache

                var query = NhSession.QueryOver <NodeRelation>()
                            .Fetch(x => x.StartNode).Lazy
                            .Fetch(x => x.EndNode).Lazy
                            .Fetch(x => x.NodeRelationTags).Eager
                            .Fetch(x => x.NodeRelationType).Eager;

                var parentQuery = QueryOver.Of <NodeRelation>().Where(x => x.EndNode.Id == value);

                if (relationType != null)
                {
                    var copyRelationName = relationType.RelationName;

                    var parentQueryWithType = parentQuery
                                              .JoinQueryOver(x => x.NodeRelationType)
                                              .Where(x => x.Alias == copyRelationName);

                    return(query.WithSubquery.WhereProperty(x => x.StartNode.Id).In(parentQueryWithType.Select(x => x.StartNode.Id).Take(1))
                           .CacheRegion("Relations").Cacheable().List().Select(MapNodeRelation));
                }
                else
                {
                    return(query.WithSubquery.WhereProperty(x => x.StartNode.Id).In(parentQuery.Select(x => x.StartNode.Id).Take(1))
                           .CacheRegion("Relations").Cacheable().List().Select(MapNodeRelation));
                }
            }
        }
Esempio n. 22
0
        public void MapAndMerge <T>(Revision <T> entity, MappingEngineCollection mappers) where T : class, IVersionableEntity
        {
            HiveId hiveId   = entity.MetaData != null ? entity.MetaData.Id : HiveId.Empty;
            HiveId entityId = entity.Item != null ? entity.Item.Id : HiveId.Empty;

            using (DisposableTimer.TraceDuration <NhSessionHelper>("Start MapAndMerge for revision " + hiveId + " entity " + entityId, "End MapAndMerge"))
                using (NhProfilerLogging.Start(NhSession, "MapAndMerge<T> (Revision<T>)",
                                               new OdbcParameter("entity", entity)))
                {
                    var rdbmsEntity = mappers.MapToIntent <IReferenceByGuid>(entity);

                    // Track ID generation on the Rdbms object so that it can be pinged to the AbstractEntity upon Save/Update commit
                    rdbmsEntity = NhSession.Merge(rdbmsEntity) as IReferenceByGuid;

                    // 16th Jan 12 (APN) NH is not flushing if the above merged entity is queried before the transaction is committed, despite
                    // the flushmode being Auto. So, explicit call to Flush here pending a bugfix/ better solution
                    NhSession.Flush();

                    //InnerDataContext.NhibernateSession.SaveOrUpdate(rdbmsEntity);
                    mappers.Map(rdbmsEntity, entity, rdbmsEntity.GetType(), entity.GetType());
                }
        }
Esempio n. 23
0
        public void AddAttributeValueFuturesToSession(Guid[] versionIds, NodeVersion outerVersionSelect)
        {
            Attribute            attribAlias    = null;
            Attribute            aliasForString = null;
            AttributeStringValue stringsLoader  = null;
            var strings = NhSession.QueryOver <Attribute>(() => attribAlias)
                          .Left.JoinAlias(() => attribAlias.AttributeStringValues, () => stringsLoader)
                          .Where(() => attribAlias.NodeVersion.Id.IsIn(versionIds))
                          .Future <Attribute>();

            Attribute            aliasForLongString = null;
            AttributeStringValue longStringsLoader  = null;
            var longStrings = NhSession.QueryOver <Attribute>(() => attribAlias)
                              .Left.JoinAlias(() => attribAlias.AttributeLongStringValues, () => longStringsLoader)
                              .Where(() => attribAlias.NodeVersion.Id.IsIn(versionIds))
                              .Future <Attribute>();

            Attribute             aliasForInteger = null;
            AttributeIntegerValue integerLoader   = null;
            var integers = NhSession.QueryOver <Attribute>(() => attribAlias)
                           .Left.JoinAlias(() => attribAlias.AttributeIntegerValues, () => integerLoader)
                           .Where(() => attribAlias.NodeVersion.Id.IsIn(versionIds))
                           .Future <Attribute>();

            Attribute             aliasForDecimal = null;
            AttributeDecimalValue decimalLoader   = null;
            var decimals = NhSession.QueryOver <Attribute>(() => attribAlias)
                           .Left.JoinAlias(() => attribAlias.AttributeDecimalValues, () => decimalLoader)
                           .Where(() => attribAlias.NodeVersion.Id.IsIn(versionIds))
                           .Future <Attribute>();

            Attribute          aliasForDate = null;
            AttributeDateValue dateLoader   = null;
            var dates = NhSession.QueryOver <Attribute>(() => attribAlias)
                        .Left.JoinAlias(() => attribAlias.AttributeDateValues, () => dateLoader)
                        .Where(() => attribAlias.NodeVersion.Id.IsIn(versionIds))
                        .Future <Attribute>();
        }
Esempio n. 24
0
        public void AddRelation(IReadonlyRelation <IRelatableEntity, IRelatableEntity> item, AbstractScopedCache repositoryScopedCache)
        {
            var sessionIdAsString = GetSessionId().ToString("n");

            using (DisposableTimer.TraceDuration <NhSessionHelper>("In AddRelation for session " + sessionIdAsString, "End AddRelation for session " + sessionIdAsString))
            {
                // Get the source and destination items from the Nh session
                var sourceNode = NhSession.Get <Node>((Guid)item.SourceId.Value);
                var destNode   = NhSession.Get <Node>((Guid)item.DestinationId.Value);

                // Check the Nh session is already aware of the items
                if (sourceNode == null || destNode == null)
                {
                    string extraMessage = string.Empty;
                    if (sourceNode == null)
                    {
                        extraMessage = "Source {0} cannot be found.\n".InvariantFormat(item.SourceId.Value);
                    }
                    if (destNode == null)
                    {
                        extraMessage += "Destination {0} cannot be found.".InvariantFormat(item.DestinationId.Value);
                    }
                    throw new InvalidOperationException(
                              "Before adding a relation between source {0} and destination {1}, you must call AddOrUpdate with those items or they must already exist in the datastore.\n{2}"
                              .InvariantFormat(item.SourceId, item.DestinationId, extraMessage));
                }

                // Try to load an existing relation of the same type between the two
                var relationType = GetOrCreateNodeRelationType(item.Type.RelationName, repositoryScopedCache);

                // Grab the existing relation (if exists) using the compound key of start node / end node / relation type
                var cacheKey = GenerateCacheKeyForRelation(item, relationType);

                NodeRelation relationToReturn = repositoryScopedCache.GetOrCreateTyped(
                    cacheKey,
                    () =>
                {
                    return(NhSession
                           .QueryOver <NodeRelation>()
                           .Where(x => x.StartNode == sourceNode && x.EndNode == destNode && x.NodeRelationType == relationType)
                           .Cacheable()
                           .SingleOrDefault());
                });

                // Avoid a duplicate by checking if one already exists
                if (relationToReturn != null)
                {
                    // Make sure existing relation has ordinal
                    relationToReturn.Ordinal = item.Ordinal;
                }
                else
                {
                    // Create a new relation
                    relationToReturn = new NodeRelation {
                        StartNode = sourceNode, EndNode = destNode, NodeRelationType = relationType, Ordinal = item.Ordinal
                    };
                    relationToReturn = NhSession.Merge(relationToReturn) as NodeRelation;
                }

                // Ensure metadata correct on existing or new entity
                CreateAndAddRelationTags(item, relationToReturn);
            }
        }
Esempio n. 25
0
        public ActionResult CancelApprove(Report_WorkFlow_Log_Model model)
        {
            bool success = false;

            try
            {
                string type = Request.Form["type"] == null ? string.Empty : Request.Form["type"].ToString();
                Model.D_Report_Model dataModel = NhSession.Get <Model.D_Report_Model>(model.ReportGuid);
                if (dataModel != null)
                {
                    if (dataModel.ReportCancelStatus == 0)
                    {
                        return(Json(new { success = success, message = "请先提交本8D Report" }, JsonRequestBehavior.AllowGet));
                    }

                    if (!string.IsNullOrEmpty(type))
                    {
                        Model.D_WorkFlowLog_Model logModel = new D_WorkFlowLog_Model();
                        switch (type)
                        {
                        case "0":
                            if (dataModel.ReportStatus == (int)ReportStatusEnum.TeamLeader)
                            {
                                dataModel.ReportStatus    = (int)ReportStatusEnum.New;
                                dataModel.CurrentStepUser = string.Empty;
                                dataModel.PreStepUser     = string.Empty;
                                dataModel.PreStepType     = string.Empty;

                                logModel.OperateType = "Cancel";
                            }
                            break;

                        case "1":
                            if (dataModel.ReportCancelStatus == (int)ReportCancelStatusEnum.TeamLeader)
                            {
                                dataModel.ReportCancelStatus = (int)ReportCancelStatusEnum.QE;
                                dataModel.CurrentStepUser    = dataModel.ResponsibleQE;
                            }
                            else if (dataModel.ReportCancelStatus == (int)ReportCancelStatusEnum.QE)
                            {
                                dataModel.ReportCancelStatus = (int)ReportCancelStatusEnum.Sponsor;
                                dataModel.CurrentStepUser    = dataModel.Sponaor;
                            }
                            else if (dataModel.ReportCancelStatus == (int)ReportCancelStatusEnum.Sponsor)
                            {
                                dataModel.ReportCancelStatus = (int)ReportCancelStatusEnum.Completed;
                                dataModel.CurrentStepUser    = string.Empty;
                            }
                            dataModel.PreStepUser = string.Empty;
                            dataModel.PreStepType = string.Empty;

                            logModel.OperateType = "Approve";
                            break;

                        case "2":
                            dataModel.ReportCancelStatus = (int)ReportCancelStatusEnum.TeamLeader;
                            if (model.ReportCancelStatus == (int)ReportCancelStatusEnum.QE)
                            {
                                dataModel.PreStepType = ((int)ReportCancelStatusEnum.QE).ToString();

                                dataModel.PreStepUser     = dataModel.ResponsibleQE;
                                dataModel.CurrentStepUser = dataModel.Team_Leader;
                            }
                            if (model.ReportCancelStatus == (int)ReportCancelStatusEnum.Sponsor)
                            {
                                dataModel.PreStepType = ((int)ReportCancelStatusEnum.Sponsor).ToString();

                                dataModel.PreStepUser     = dataModel.Sponaor;
                                dataModel.CurrentStepUser = dataModel.Team_Leader;
                            }

                            logModel.OperateType = "Review";
                            break;

                        case "3":
                            if (dataModel.PreStepType == ((int)ReportCancelStatusEnum.QE).ToString())
                            {
                                dataModel.ReportCancelStatus = (int)ReportCancelStatusEnum.QE;
                                dataModel.CurrentStepUser    = dataModel.PreStepUser;
                                dataModel.PreStepUser        = string.Empty;
                                dataModel.PreStepType        = string.Empty;

                                logModel.OperateType = "Submit Review To QE";
                            }
                            if (dataModel.PreStepType == ((int)ReportCancelStatusEnum.Sponsor).ToString())
                            {
                                dataModel.ReportCancelStatus = (int)ReportCancelStatusEnum.Sponsor;
                                dataModel.CurrentStepUser    = dataModel.PreStepUser;
                                dataModel.PreStepUser        = string.Empty;
                                dataModel.PreStepType        = string.Empty;

                                logModel.OperateType = "Submit Review To Sponsor";
                            }
                            break;

                        //case "4":
                        //    dataModel.ReportCancelStatus = (int)ReportStatusEnum.Sponsor;
                        //    logModel.OperateType = "Submit Review To Sponsor";
                        //    break;
                        case "5":
                            dataModel.ReportCancelStatus = (int)ReportCancelStatusEnum.TeamLeader;
                            dataModel.CurrentStepUser    = dataModel.Team_Leader;
                            dataModel.PreStepType        = "";
                            dataModel.PreStepUser        = "";
                            logModel.OperateType         = "Reject";
                            break;

                        default:
                            break;
                        }

                        logModel.ReportGuid     = dataModel;
                        logModel.Status         = ((ReportCancelStatusEnum)dataModel.ReportCancelStatus).ToString();
                        logModel.CreateUser     = UserView.UserLoginName;
                        logModel.CreateUserName = UserView.UserName;
                        logModel.Comments       = model.Comment;
                        logModel.CreateDateTime = DateTime.Now;

                        dataModel.WorkFlowLog_Models.Add(logModel);

                        success = new DAL.D_Report_DAL().SaveWorkFlowLog(dataModel, logModel);
                    }
                }

                return(Json(new { success = success, message = "成功" }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { success = success, message = ex.Message }));
            }
        }
Esempio n. 26
0
        public IQueryOver <NodeVersion, NodeVersionStatusHistory> GenerateVersionedQuery(out NodeVersion outerVersionSelectAlias, Guid[] nodeIds = null, RevisionStatusType revisionStatus = null, bool limitToLatestRevision = true)
        {
            // We want the NodeVersion table, joined to the NodeVersionStatusHistory table,
            // ordered by the status history date descending, but we only want the latest one

            Node        node             = null;
            NodeVersion subSelectVersion = null;
            NodeVersionStatusHistory subSelectTopStatus = null;
            NodeVersion           outerVersionSelect    = null;
            NodeVersionStatusType subSelectStatusType   = null;

            // First define the subselection of the top 1 version items when joined and sorted by version status history in date-descending order
            // We also add a clause to say "where the outer selected version's node id equals the subselected node id" since it's selecting the top 1
            // so we want it to be the 1 latest-date item relevant for each row of the outer select
            var subSelectTopStatusByDate = QueryOver.Of(() => subSelectTopStatus)
                                           //.Where(() => subSelectTopStatus.NodeVersion.Id == outerVersionSelect.Id);
                                           .JoinQueryOver(() => subSelectTopStatus.NodeVersion, () => subSelectVersion)
                                           .JoinQueryOver(() => subSelectVersion.Node, () => node)
                                           .Where(() => subSelectTopStatus.NodeVersion.Id == subSelectVersion.Id)
                                           .And(() => outerVersionSelect.Node.Id == node.Id);

            int takeCount = limitToLatestRevision ? 1 : 999;

            // Now we need to add a filter for the revision status type, if one was supplied
            QueryOver <NodeVersionStatusHistory> subSelectTopStatusByDateWithFilter = null;
            QueryOver <NodeVersionStatusHistory> excludeNegatingStatusses           = null;

            if (revisionStatus != null)
            {
                var statusAlias = revisionStatus.Alias;

                if (revisionStatus.NegatedByTypes.Any())
                {
                    NodeVersionStatusHistory negateHistory = null;
                    NodeVersionStatusType    negateType    = null;
                    NodeVersion negateVersion   = null;
                    var         negatingAliases = revisionStatus.NegatedByTypes.Select(x => x.Alias).ToArray();

                    //var first = negatingAliases.First();
                    excludeNegatingStatusses = QueryOver.Of(() => negateHistory)
                                               .JoinAlias(() => negateHistory.NodeVersionStatusType, () => negateType)
                                               .JoinAlias(() => negateHistory.NodeVersion, () => negateVersion)
                                               .Where(() => negateType.Alias.IsIn(negatingAliases))
                                               .And(() => outerVersionSelect.Node == negateVersion.Node)
                                               .Select(Projections.SqlFunction("coalesce", NHibernateUtil.DateTime, Projections.Max <NodeVersionStatusHistory>(x => x.Date), new ConstantProjection(new DateTime(1981, 8, 1))));

                    //excludeNegatingStatusses = QueryOver.Of(() => negateHistory)
                    //    .JoinAlias(() => negateHistory.NodeVersionStatusType, () => negateType)
                    //    .JoinAlias(() => negateHistory.NodeVersion, () => negateVersion)
                    //    .JoinAlias(() => negateVersion.Node, () => node)
                    //    .Where(() => negateType.Alias.IsIn(negatingAliases))
                    //    .And(() => negateHistory.Date > subSelectTopStatus.Date)
                    //    //.And(() => subSelectTopStatus.NodeVersion.Id == negateVersion.Id)
                    //    .And(() => outerVersionSelect.Node.Id == node.Id)
                    //    .Select(x => x.Id)
                    //    .Take(1);

                    //excludeNegatingStatusses = QueryOver.Of(() => negateHistory)
                    //    .JoinAlias(() => negateHistory.NodeVersionStatusType, () => negateType)
                    //    .JoinAlias(() => negateHistory.NodeVersion, () => negateVersion)
                    //    .JoinAlias(() => negateVersion.Node, () => node)
                    //    .Where(() => negateType.Alias.IsIn(negatingAliases))
                    //    .And(() => outerVersionSelect.Node.Id == node.Id)
                    //    .And(() => negateHistory.Date > subSelectTopStatus.Date)
                    //    .OrderBy(x => x.Date).Desc
                    //    .Select(x => x.Id)
                    //    .Take(1);
                }

                var subSelectBuilder = subSelectTopStatusByDate
                                       .And(() => subSelectStatusType.Alias == statusAlias)
                                       .JoinQueryOver(x => subSelectTopStatus.NodeVersionStatusType, () => subSelectStatusType)
                                       .OrderBy(() => subSelectTopStatus.Date).Desc;

                if (excludeNegatingStatusses != null)
                {
                    // Yeah, I know, horrible to check Sql dialect when generating query, but Nh's dialect support doesn't allow a provider-based
                    // way of telling whether the db engine supports / requires "all" to be prefix before a subquery when doing an operation.
                    // e.g. SqlCe requires "blah > all (select max(blah) from blah)", SqlServer doesn't mind, SQLite doesn't support it
                    if (RequiresAllForGtSubquery())
                    {
                        subSelectBuilder = subSelectBuilder.WithSubquery.WhereProperty(() => subSelectTopStatus.Date).GtAll(excludeNegatingStatusses);
                    }
                    else
                    {
                        subSelectBuilder = subSelectBuilder.WithSubquery.WhereProperty(() => subSelectTopStatus.Date).Gt(excludeNegatingStatusses);
                    }

                    //subSelectBuilder = subSelectBuilder.WithSubquery.WhereNotExists(excludeNegatingStatusses);
                    //subSelectBuilder = subSelectBuilder.WithSubquery.WhereProperty(() => subSelectTopStatus.Id).NotIn(excludeNegatingStatusses);
                }

                subSelectTopStatusByDateWithFilter = subSelectBuilder.Select(x => subSelectTopStatus.NodeVersion.Id).Take(takeCount);
                // We have to include a Take here for compatibility with SqlServerCe
            }
            else
            {
                subSelectTopStatusByDateWithFilter = subSelectTopStatusByDate
                                                     .OrderBy(() => subSelectTopStatus.Date).Desc
                                                     .Select(x => subSelectTopStatus.NodeVersion.Id).Take(takeCount);
                // We have to include a Take here for compatibility with SqlServerCe
            }

            NodeVersionStatusHistory outerHistoryForSort = null;
            IQueryOver <NodeVersion, NodeVersionStatusHistory> outerQuery = NhSession.QueryOver <NodeVersion>(
                () => outerVersionSelect)
                                                                            //.Fetch(x => x.AttributeSchemaDefinition).Eager
                                                                            .Fetch(x => x.Attributes).Eager
                                                                            // We load these eagerly rather than in a Future to avoid a separate query
                                                                            .Fetch(x => x.Node).Eager
                                                                            // There's a 1-m mapping between Node-NodeVersion so safe to load this with a join too rather than with a future
                                                                            .Inner.JoinQueryOver(x => outerHistoryForSort.NodeVersionStatusType, () => subSelectStatusType)
                                                                            .Inner.JoinQueryOver(x => outerVersionSelect.NodeVersionStatuses, () => outerHistoryForSort);

            NodeVersion innerVersion = null;
            NodeVersionStatusHistory innerHistory = null;
            NodeVersionStatusType    innerType    = null;
            var buildInnerHistorySubQuery         = QueryOver.Of <NodeVersionStatusHistory>(() => innerHistory)
                                                    .JoinQueryOver(() => innerHistory.NodeVersion, () => innerVersion)
                                                    .JoinQueryOver(() => innerHistory.NodeVersionStatusType, () => innerType)
                                                    .Where(() => innerVersion.Node == outerVersionSelect.Node);

            if (revisionStatus != null)
            {
                var statusAlias = revisionStatus.Alias;
                buildInnerHistorySubQuery = buildInnerHistorySubQuery
                                            .And(() => innerType.Alias == statusAlias);

                NodeVersionStatusType reselectType = null;
                outerQuery = outerQuery
                             .And(() => subSelectStatusType.Alias == statusAlias);

                // Yeah, I know, horrible to check Sql dialect when generating query, but Nh's dialect support doesn't allow a provider-based
                // way of telling whether the db engine supports / requires "all" to be prefix before a subquery when doing an operation.
                // e.g. SqlCe requires "blah > all (select max(blah) from blah)", SqlServer doesn't mind, SQLite doesn't support it
                if (excludeNegatingStatusses != null)
                {
                    if (RequiresAllForGtSubquery())
                    {
                        outerQuery = outerQuery.WithSubquery.WhereProperty(() => outerHistoryForSort.Date).GtAll(excludeNegatingStatusses);
                    }
                    else
                    {
                        outerQuery = outerQuery.WithSubquery.WhereProperty(() => outerHistoryForSort.Date).Gt(excludeNegatingStatusses);
                    }
                }
            }

            var subQueryInnerHistory = buildInnerHistorySubQuery.Select(x => x.Id)
                                       .OrderBy(() => innerHistory.Date).Desc
                                       .Take(takeCount);

            outerQuery = outerQuery
                         .OrderBy(() => outerHistoryForSort.Date).Asc
                         .WithSubquery.WhereProperty(() => outerHistoryForSort.Id).In(subQueryInnerHistory);

            //// Based on perf testing of SqlCe queries, it shaves a lot off execution time if we specify the status type in the
            //// outer query in addition to the subquery
            //if (revisionStatus != null)
            //{
            //    var statusAlias = revisionStatus.Alias;
            //    outerQuery = outerQuery
            //        .And(x => subSelectStatusType.Alias == statusAlias);
            //}

            //outerQuery = outerQuery
            //    .OrderBy(() => outerHistoryForSort.Date).Asc
            //    .WithSubquery.WhereProperty(() => outerVersionSelect.Id).In(subSelectTopStatusByDateWithFilter.Clone());

            if (nodeIds != null && nodeIds.Any())
            {
                outerQuery = outerQuery.And(() => outerVersionSelect.Node.Id.IsIn(nodeIds));
            }

            outerVersionSelectAlias = outerVersionSelect;
            return(outerQuery);
        }
Esempio n. 27
0
        public ActionResult Role_Permission_Edit()
        {
            bool   success     = false;
            string roleGuid    = Request.Form["RoleGuid"];
            string permissions = Request.Form[2].ToString();

            string[] permission = permissions.Split(',');
            using (NHibernate.ITransaction tran = NhSession.BeginTransaction())
            {
                try
                {
                    Guid RoleGuid           = new Guid(roleGuid);
                    Model.D_Role_Model role = NhSession.Get <Model.D_Role_Model>(RoleGuid);
                    ICriteria          ic   = NhSession.CreateCriteria(typeof(Model.D_Role_Permissions_Model));
                    ic.Add(Restrictions.Eq("RoleGuid", role));
                    IList <Model.D_Role_Permissions_Model> rolePermissionList = ic.List <Model.D_Role_Permissions_Model>();

                    foreach (var item in rolePermissionList)
                    {
                        item.DataStatus     = true;
                        item.ModifyDateTime = DateTime.Now;
                        item.ModifyUserGuid = UserView.UserGuid;
                        item.ModifyUserName = UserView.UserName;
                        NhSession.Update(item);
                    }

                    foreach (var item in permission)
                    {
                        Model.D_Role_Permissions_Model rolePermission = rolePermissionList.SingleOrDefault(m => m.Permissions == item);
                        if (rolePermission == null)
                        {
                            rolePermission = new Model.D_Role_Permissions_Model();
                            rolePermission.CreateDateTime = DateTime.Now;
                            rolePermission.CreateUserGuid = UserView.UserGuid;
                            rolePermission.CreateUserName = UserView.UserName;
                            rolePermission.RoleGuid       = role;
                            rolePermission.Permissions    = item;
                        }

                        rolePermission.DataStatus     = false;
                        rolePermission.ModifyDateTime = DateTime.Now;
                        rolePermission.ModifyUserGuid = UserView.UserGuid;
                        rolePermission.ModifyUserName = UserView.UserName;

                        NhSession.SaveOrUpdate(rolePermission);
                    }
                    tran.Commit();
                    return(Json(new { success = success, message = "成功" }, JsonRequestBehavior.AllowGet));
                }
                catch (Exception ex)
                {
                    return(Json(new { success = success, message = ex.Message }));
                }
                finally
                {
                    if (!tran.WasCommitted && !tran.WasRolledBack)
                    {
                        tran.Rollback();
                    }
                }
            }
        }
Esempio n. 28
0
        public ActionResult Approve(Report_WorkFlow_Log_Model model)
        {
            bool success = false;

            try
            {
                string type = Request.Form["type"] == null ? string.Empty : Request.Form["type"].ToString();
                Model.D_Report_Model dataModel = NhSession.Get <Model.D_Report_Model>(model.ReportGuid);
                if (dataModel != null)
                {
                    if (dataModel.ReportStatus == 0)
                    {
                        return(Json(new { success = success, message = "请先提交本8D Report" }, JsonRequestBehavior.AllowGet));
                    }

                    if (!string.IsNullOrEmpty(type))
                    {
                        Model.D_WorkFlowLog_Model logModel = new D_WorkFlowLog_Model();
                        switch (type)
                        {
                        case "0":
                            if (dataModel.ReportStatus == (int)ReportStatusEnum.TeamLeader)
                            {
                                dataModel.ReportStatus    = (int)ReportStatusEnum.New;
                                dataModel.CurrentStepUser = string.Empty;
                                dataModel.PreStepUser     = string.Empty;
                                dataModel.PreStepType     = string.Empty;

                                logModel.OperateType = "Cancel";
                            }
                            break;

                        case "1":
                            if (dataModel.ReportStatus == (int)ReportStatusEnum.TeamLeader)
                            {
                                dataModel.ReportStatus    = (int)ReportStatusEnum.Sponsor;
                                dataModel.CurrentStepUser = dataModel.Sponaor;
                            }
                            else if (dataModel.ReportStatus == (int)ReportStatusEnum.Sponsor)
                            {
                                dataModel.ReportStatus = (int)ReportStatusEnum.Approve;

                                List <Models.D_User> list = Newtonsoft.Json.JsonConvert.DeserializeObject <List <Models.D_User> >(dataModel.WorkFlow_Models[0].Additional_Approver);

                                dataModel.CurrentStepUser = Newtonsoft.Json.JsonConvert.SerializeObject(list[0]);
                            }
                            else if (dataModel.ReportStatus == (int)ReportStatusEnum.Approve)
                            {
                                Models.D_User        user = Newtonsoft.Json.JsonConvert.DeserializeObject <Models.D_User>(dataModel.CurrentStepUser);
                                List <Models.D_User> list = Newtonsoft.Json.JsonConvert.DeserializeObject <List <Models.D_User> >(dataModel.WorkFlow_Models[0].Additional_Approver);

                                if (user.Serial != list.Count - 1)
                                {
                                    dataModel.CurrentStepUser = Newtonsoft.Json.JsonConvert.SerializeObject(list[user.Serial + 1]);
                                    dataModel.ReportStatus    = (int)ReportStatusEnum.Completed;
                                }
                                else
                                {
                                    dataModel.CurrentStepUser = string.Empty;
                                }
                            }
                            dataModel.PreStepUser = string.Empty;
                            dataModel.PreStepType = string.Empty;

                            logModel.OperateType = "Approve";
                            break;

                        case "2":
                            dataModel.ReportStatus = (int)ReportStatusEnum.TeamLeader;
                            if (model.ReportStatus == (int)ReportStatusEnum.Sponsor)
                            {
                                dataModel.PreStepType = ((int)ReportStatusEnum.Sponsor).ToString();

                                dataModel.PreStepUser     = dataModel.Sponaor;
                                dataModel.CurrentStepUser = dataModel.Team_Leader;

                                //Models.D_User preStepUser = new Models.D_User();
                                //preStepUser.UserGuid = UserView.UserGuid;
                                //preStepUser.UserLoginName = UserView.UserLoginName;
                                //preStepUser.UserName = UserView.UserName;
                                //dataModel.PreStepUser = Newtonsoft.Json.JsonConvert.SerializeObject(preStepUser);
                            }
                            if (model.ReportStatus == (int)ReportStatusEnum.Approve)
                            {
                                dataModel.PreStepType = ((int)ReportStatusEnum.Approve).ToString();

                                dataModel.PreStepUser     = dataModel.CurrentStepUser;
                                dataModel.CurrentStepUser = dataModel.Team_Leader;

                                //Models.D_User preStepUser = new Models.D_User();
                                //preStepUser.UserGuid = UserView.UserGuid;
                                //preStepUser.UserLoginName = UserView.UserLoginName;
                                //preStepUser.UserName = UserView.UserName;
                                //dataModel.PreStepUser = Newtonsoft.Json.JsonConvert.SerializeObject(preStepUser);
                            }


                            logModel.OperateType = "Review";
                            break;

                        case "3":
                            if (dataModel.PreStepType == ((int)ReportStatusEnum.Sponsor).ToString())
                            {
                                dataModel.ReportStatus    = (int)ReportStatusEnum.Sponsor;
                                dataModel.CurrentStepUser = dataModel.PreStepUser;
                                dataModel.PreStepUser     = string.Empty;
                                dataModel.PreStepType     = string.Empty;

                                logModel.OperateType = "Submit Review To Sponsor";
                            }
                            if (dataModel.PreStepType == ((int)ReportStatusEnum.Approve).ToString())
                            {
                                dataModel.ReportStatus    = (int)ReportStatusEnum.Approve;
                                dataModel.CurrentStepUser = dataModel.PreStepUser;
                                dataModel.PreStepUser     = string.Empty;
                                dataModel.PreStepType     = string.Empty;

                                logModel.OperateType = "Submit Review To AA";
                            }
                            break;

                        //case "4":
                        //    dataModel.ReportStatus = (int)ReportStatusEnum.Approve;
                        //    logModel.OperateType = "Submit Review To AA";
                        //    break;
                        case "5":
                            dataModel.ReportStatus    = (int)ReportStatusEnum.TeamLeader;
                            dataModel.CurrentStepUser = dataModel.Team_Leader;
                            dataModel.PreStepType     = "";
                            dataModel.PreStepUser     = "";
                            logModel.OperateType      = "Reject";
                            break;

                        default:
                            break;
                        }

                        logModel.ReportGuid     = dataModel;
                        logModel.Status         = ((ReportStatusEnum)dataModel.ReportStatus).ToString();
                        logModel.CreateUser     = UserView.UserLoginName;
                        logModel.CreateUserName = UserView.UserName;
                        logModel.Comments       = model.Comment;
                        logModel.CreateDateTime = DateTime.Now;

                        dataModel.WorkFlowLog_Models.Add(logModel);

                        success = new DAL.D_Report_DAL().SaveWorkFlowLog(dataModel, logModel);
                    }
                }

                return(Json(new { success = success, message = "成功" }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { success = success, message = ex.Message }));
            }
        }
Esempio n. 29
0
 public virtual IEnumerable <TEntidade> Lista()
 {
     return(NhSession.CreateCriteria <TEntidade>().List <TEntidade>());
 }
Esempio n. 30
0
        public ActionResult CancelApprove(Guid?Id)
        {
            Models.Report_WorkFlow_Log_Model logModel = new Models.Report_WorkFlow_Log_Model();
            if (Id.HasValue)
            {
                Model.D_Report_Model dataModel = NhSession.Get <Model.D_Report_Model>(Id.Value);
                logModel.ReportGuid   = dataModel.ReportGuid;
                logModel.ReportStatus = dataModel.ReportStatus;

                ReportAssignModel model = new ReportAssignModel();
                model.LoadBoardSelectList(UserView.Boards);
                model.LoadReportTypeSelectList();
                model.ReportHeader = new ReportHeaderModel();
                model.ReportD1     = new ReoprtD1Model();
                model.ReportD2     = new ReoprtD2Model();
                model.ReportD3     = new ReoprtD3Model();
                model.ReportD4     = new ReoprtD4Model();
                model.ReportD5     = new ReoprtD5Model();
                model.ReportD6     = new ReoprtD6Model();
                model.ReportD7     = new ReoprtD7Model();
                model.WorkFlow     = new ReportWorkFlow();

                if (dataModel != null)
                {
                    #region MyRegion
                    #region 表头
                    model.ReportAssignGuid = dataModel.ReportGuid;
                    model.ReportTitle      = dataModel.ReportTitle;
                    model.ReportType       = dataModel.ReportTypeGuid.DicGuid.ToString();

                    model.BoardGuid   = dataModel.ReportBoardGuid.BoardGuid.ToString();
                    model.ReportOwner = dataModel.ReportOwner;
                    if (!string.IsNullOrEmpty(dataModel.ResponsibleQE))
                    {
                        Models.D_User user = Newtonsoft.Json.JsonConvert.DeserializeObject <D_User>(dataModel.ResponsibleQE);
                        model.ResponsibleQE = user.UserLoginName;
                    }

                    model.ReportNo = dataModel.ReportNo;


                    model.ReportHeader.Bosch_Material_No    = dataModel.Bosch_Material_No;
                    model.ReportHeader.Complaint_TypeMode   = dataModel.Complaint_TypeMode;
                    model.ReportHeader.ComplaintDate        = dataModel.ComplaintDate.HasValue ? dataModel.ComplaintDate.Value.ToString("dd/MM/yyyy") : "";
                    model.ReportHeader.Customer             = dataModel.Customer;
                    model.ReportHeader.Customer_Material_No = dataModel.Customer_Material_No;
                    model.ReportHeader.Issuer = dataModel.Issuer;
                    model.ReportHeader.Manufacturing_Plant = dataModel.Manufacturing_Plant;
                    model.ReportHeader.Product             = dataModel.Product;
                    model.ReportHeader.Serial_No           = dataModel.Serial_No;
                    model.ReportHeader.Supplier_Name       = dataModel.Supplier_Name;
                    model.ReportHeader.Supplier_No         = dataModel.Supplier_No;
                    model.ReportHeader.Warranty_Descision  = dataModel.Warranty_Descision;
                    #endregion

                    #region ReportD1
                    if (!string.IsNullOrEmpty(dataModel.Team_Leader))
                    {
                        model.ReportD1.Team_Leader = Newtonsoft.Json.JsonConvert.DeserializeObject <Models.D_User>(dataModel.Team_Leader).UserLoginName;
                    }

                    if (!string.IsNullOrEmpty(dataModel.Sponaor))
                    {
                        model.ReportD1.Sponaor = Newtonsoft.Json.JsonConvert.DeserializeObject <Models.D_User>(dataModel.Sponaor).UserLoginName;
                    }


                    model.ReportD1.Coordinator = dataModel.Coordinator;
                    if (!string.IsNullOrEmpty(dataModel.Team_Member))
                    {
                        List <Models.D_User> users = Newtonsoft.Json.JsonConvert.DeserializeObject <List <Models.D_User> >(dataModel.Team_Member);
                        foreach (var item in users)
                        {
                            model.ReportD1.Team_Member += item.UserLoginName + ";";
                        }
                        model.ReportD1.Team_Member = model.ReportD1.Team_Member.TrimEnd(';');
                    }

                    #endregion

                    #region ReportD2
                    if (dataModel.ReportD2 != null)
                    {
                        model.ReportD2.Manufacturing_Date = dataModel.ReportD2.Manufacturing_Date.HasValue ? dataModel.ReportD2.Manufacturing_Date.Value.ToString("dd/MM/yyyy") : "";

                        model.ReportD2.Bosch_Description     = dataModel.ReportD2.Bosch_Description;
                        model.ReportD2.Customer_Complaint    = dataModel.ReportD2.Customer_Complaint;
                        model.ReportD2.No_of_complaint_parts = dataModel.ReportD2.No_of_complaint_parts;

                        model.ReportD2.End_of_D2_Date = dataModel.ReportD2.End_of_D2_Date.HasValue ? dataModel.ReportD2.End_of_D2_Date.Value.ToString("dd/MM/yyyy") : "";
                    }
                    #endregion

                    #region ReportD3
                    //model.ReportD3Json = dataModel.ReportD3Json;
                    if (!string.IsNullOrEmpty(dataModel.ReportD3Json))
                    {
                        Models.ReoprtD3Model d3Model = Newtonsoft.Json.JsonConvert.DeserializeObject <Models.ReoprtD3Model>(dataModel.ReportD3Json);
                        model.ReportD3 = d3Model;
                    }
                    #endregion

                    #region ReportD4
                    if (!string.IsNullOrEmpty(dataModel.ReportD4Json))
                    {
                        Models.ReoprtD4Model d4Model = Newtonsoft.Json.JsonConvert.DeserializeObject <Models.ReoprtD4Model>(dataModel.ReportD4Json);
                        model.ReportD4 = d4Model;
                    }
                    #endregion

                    #region ReportD5
                    if (!string.IsNullOrEmpty(dataModel.ReportD5Json))
                    {
                        Models.ReoprtD5Model d5Model = Newtonsoft.Json.JsonConvert.DeserializeObject <Models.ReoprtD5Model>(dataModel.ReportD5Json);
                        model.ReportD5 = d5Model;
                    }
                    #endregion

                    #region ReportD6
                    if (!string.IsNullOrEmpty(dataModel.ReportD6Json))
                    {
                        Models.ReoprtD6Model d6Model = Newtonsoft.Json.JsonConvert.DeserializeObject <Models.ReoprtD6Model>(dataModel.ReportD6Json);
                        model.ReportD6 = d6Model;
                    }
                    #endregion

                    #region ReportD7
                    if (!string.IsNullOrEmpty(dataModel.ReportD7Json))
                    {
                        Models.ReoprtD7Model d7Model = Newtonsoft.Json.JsonConvert.DeserializeObject <Models.ReoprtD7Model>(dataModel.ReportD7Json);
                        model.ReportD7 = d7Model;
                    }
                    #endregion

                    #region ReportD8
                    if (!string.IsNullOrEmpty(dataModel.ReportD8Json))
                    {
                        Models.ReoprtD8Model d8Model = Newtonsoft.Json.JsonConvert.DeserializeObject <Models.ReoprtD8Model>(dataModel.ReportD8Json);
                        model.ReportD8 = d8Model;
                    }

                    foreach (var item in dataModel.ReportD8DataModels)
                    {
                        Models.ReoprtD8Data sign = new ReoprtD8Data();
                        sign.Number        = item.Number;
                        sign.ReportD8Guid  = item.ReportD8Guid.ToString();
                        sign.Signature     = item.Signature;
                        sign.SignatureDate = item.SignatureDate.HasValue ? item.SignatureDate.Value.ToString("dd/MM/yyyy") : "";
                        sign.SponsorName   = item.SponsorName;
                        model.ReportD8Sign.Add(sign);
                    }
                    #endregion
                    #endregion

                    if (dataModel.WorkFlow_Models.Count > 0)
                    {
                        model.WorkFlow.EightD_WorkFlowGuid = dataModel.WorkFlow_Models[0].EightD_WorkFlowGuid;
                        if (!string.IsNullOrEmpty(dataModel.WorkFlow_Models[0].Additional_Approver))
                        {
                            List <Models.D_User> users = Newtonsoft.Json.JsonConvert.DeserializeObject <List <Models.D_User> >(dataModel.WorkFlow_Models[0].Additional_Approver);
                            foreach (var item in users)
                            {
                                model.WorkFlow.Additional_Approver += item.UserLoginName + ";";
                            }
                            model.WorkFlow.Additional_Approver = model.WorkFlow.Additional_Approver.TrimEnd(';');
                        }

                        model.WorkFlow.Comments    = dataModel.WorkFlow_Models[0].Comments;
                        model.WorkFlow.Sponsor     = dataModel.WorkFlow_Models[0].Sponsor;
                        model.WorkFlow.Team_Leader = dataModel.WorkFlow_Models[0].Team_Leader;
                    }

                    model.ReportCancelStatus = dataModel.ReportCancelStatus;
                    model.ReportStatus       = dataModel.ReportStatus;

                    if (!string.IsNullOrEmpty(dataModel.CurrentStepUser))
                    {
                        model.CurrentStepUser = Newtonsoft.Json.JsonConvert.DeserializeObject <Models.D_User>(dataModel.CurrentStepUser);
                    }

                    if (!string.IsNullOrEmpty(dataModel.PreStepUser))
                    {
                        model.PreStepUser = Newtonsoft.Json.JsonConvert.DeserializeObject <Models.D_User>(dataModel.PreStepUser);
                    }

                    model.PreStepType = dataModel.PreStepType;
                }

                logModel.ReportModel = model;
            }
            return(View(logModel));
        }