public ProcInst GetProcInst(int loginId)
 {
     ProcInst procInst = new ProcInst();
     using (var edm = new DianPingK2ServerLogContext())
     {
         procInst = edm.ProcInst.AsQueryable()
             .Where(_ => _.ID == loginId).FirstOrDefault();
     }
     return procInst;
 }
 public List<ActInstDest> queryByPorcInstIdAndActInstId(int procInstId, int actInstId)
 {
     List<ActInstDest> list = new List<ActInstDest>();
     using (var edm = new DianPingK2ServerLogContext())
     {
         list = edm.ActInstDest.AsQueryable()
             .Where(_ => _.ProcInstID == procInstId)
             .Where(_ => _.ActInstID == actInstId)
             .Where(_ => _.Status == 0).ToList(); ;
     }
     return list;
 }
 public List<ActInst> GetProcessStatusByFolio(string folio)
 {
     List<ActInst> result = new List<ActInst>();
     //var transactionOptions = new System.Transactions.TransactionOptions();
     //transactionOptions.IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted;
     //using (var transactionScope = new System.Transactions.TransactionScope(System.Transactions.TransactionScopeOption.Required, transactionOptions))
     //{
         var edm = new DianPingK2ServerLogContext();
         result = edm.ActInst.Include("ProcInst").Include("Act")
             .Where(_ => _.Status == 2)
             .Where(_ => _.ProcInst.Folio == folio)
             .Where(_ => _.Act.Type == 1)
             .ToList();
     //    transactionScope.Complete();
     //}
     return result;
 }
Example #4
0
        public List <ActInst> GetProcessStatusByProcInstId(int procInstId)
        {
            List <ActInst> result = new List <ActInst>();
            //var transactionOptions = new System.Transactions.TransactionOptions();
            //transactionOptions.IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted;
            //using (var transactionScope = new System.Transactions.TransactionScope(System.Transactions.TransactionScopeOption.Required, transactionOptions))
            //{
            var edm = new DianPing.WorkFlow.Repositories.Interface.DianPingK2ServerLog.Entity.DianPingK2ServerLogContext();

            result = edm.ActInst.Include("ProcInst").Include("Act")
                     .Where(_ => _.Status == 2)
                     .Where(_ => _.ProcInst.ID == procInstId)
                     .Where(_ => _.Act.Type == 1)
                     .ToList();
            //    transactionScope.Complete();
            //}
            //----------------------
            //var edm = new DianPing.WorkFlow.Repositories.Interface.DianPingK2ServerLog.Entity.DianPingK2ServerLogContext();
            //var result =
            //     (from _ in edm.ProcInst
            //      from ai in _.ActInst.Where(a => a.Status == 2 && a.Act.Type == 1).DefaultIfEmpty()
            //      from ac in edm.Act
            //      //join ac in edm.Act on ai.Act.ID equals ac.ID into acgroup
            //      where _.ID == procInstId

            //      select new
            //      {
            //          ProcInstId = _.ID,
            //          Folio = _.Folio,
            //          ActInst = ai,
            //          WorkList = _.Worklist,
            //          Status = _.Status
            //      }
            //          ).ToList();

            //List<K2Status> list = new List<K2Status>();
            //foreach (var item in result)
            //{
            //    K2Status status = new K2Status()
            //    {
            //        Folio = item.Folio,
            //        ProcInstId = item.ProcInstId,
            //        LoginIds = item.WorkList.Where(_ => _.Status == 0).Select(t => Convert.ToInt32(t.Destination.Replace("K2SQL:", ""))).ToList(),
            //        Activity = item.Status.ToString()
            //    };
            //    if (item.ActInst != null)
            //    {
            //        status.Activity = item.ActInst.Act.Name;
            //        status.StartDate = item.ActInst.StartDate;
            //    }
            //    list.Add(status);
            //}
            //----------------------
            //    foreach (var item in result.GroupBy(_ => _.ActName))
            //    {
            //           list.Add(new K2Status
            //           {
            //                Activity = item.Key,
            //                ProcInstId = item.Select(_ => _.Folio).FirstOrDefault(),
            //                  Folio = item.Select(_=>_.Folio).FirstOrDefault(),
            //                   StartDate = item.Select(_=>_.StartDate).FirstOrDefault(),
            //LoginIds = item.Select

            //            ID = item.Key,
            //            ActInst = item.Select(_=> new ActInst{ ID = _.Act}).ToList(),

            //           });
            //       }

            //var aa =  edm.ProcInst.Include(_ => _.ActInst).Include(_ => _.ActInst.Select(y => y.Act))
            //.Where(_ => _.ID == procInstId)
            //.Where(_ => _.ActInst.Any(t => t.Act.Type == 1))

            //.ToList();
            //edm.Database.SqlQuery(K2Status," SELECT  ","")
            return(result);
        }
        //public IList<Models.Worklist> GetWorkList(string destination, DateTime startDate, DateTime endDate)
        //{
        //    using (var edm = new Models.DianPingK2ServerLogContext())
        //    {
        //        //return edm.Worklist.Select(_ =>
        //        //    new Models.Worklist
        //        //    {
        //        //        DestType = _.DestType,
        //        //        ProcInst = new Models.ProcInst
        //        //        {
        //        //            Folio = _.ProcInst.Folio
        //        //        }
        //        //    }).Where(_ => _.Destination == destination && _.ProcInst.StartDate > startDate).ToList();
        //        return edm.Worklist.Include("ProcInst")
        //            .Where(_ => _.Destination == destination && _.ProcInst.StartDate > startDate).ToList();
        //    }
        //}
        public QueryListResultBase<Worklist> GetWorkList(QueryCriteriaBase<QueryWorkList> queryPara)
        {
            var result = new QueryListResultBase<Worklist>();

            var transactionOptions = new System.Transactions.TransactionOptions();
            transactionOptions.IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted;

            var edm = new DianPingK2ServerLogContext();
            //edm.Database.ExecuteSqlCommand("SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;");

            var query = edm.Worklist.Include("ProcInst").AsQueryable().Where(_ => _.Status == 0);

            if (queryPara != null)
            {
                var criteria = queryPara.QueryCriteria;
                if (criteria != null)
                {
                    //if (criteria.ProcessFullName != null && criteria.ProcessFullName.Count > 0)
                    //{
                    //    query = query.Where(_ => criteria.ProcessFullName.Contains(_.ProcInst.proc.ProcSet.FullName));
                    //}
                    if (criteria.ProcessCodes != null && criteria.ProcessCodes.Count > 0)
                    {
                        query = query.Where(_ => criteria.ProcessCodes.Contains(_.ProcInst.proc.ProcSet.Descr));
                    }
                    if (criteria.LoginIds != null && criteria.LoginIds.Count > 0)
                    {
                        IList<string> loginIdsStr = criteria.LoginIds.Select(_ => string.Format("K2SQL:{0}", _)).ToList();
                        query = query.Where(_ => loginIdsStr.Contains(_.Destination));
                    }
                    if (criteria.OriginatorLoginIds != null && criteria.OriginatorLoginIds.Count > 0)
                    {
                        IList<string> loginIdsStr = criteria.OriginatorLoginIds.Select(_ => string.Format("K2SQL:{0}", _)).ToList();
                        query = query.Where(_ => loginIdsStr.Contains(_.ProcInst.Originator));
                    }
                    if (criteria.ProcInstIds != null && criteria.ProcInstIds.Count > 0)
                    {
                        query = query.Where(_ => criteria.ProcInstIds.Contains(_.ProcInst.ID));
                    }
                    if (!string.IsNullOrEmpty(criteria.Folio))
                    {
                        query = query.Where(_ => _.ProcInst.Folio.StartsWith(criteria.Folio));
                    }
                    if (criteria.TaskStartDate != null)
                    {
                        if (criteria.TaskStartDate.DateFrom.HasValue)
                        {
                            query = query.Where(_ => _.StartDate >= criteria.TaskStartDate.DateFrom.Value);
                        }
                        if (criteria.TaskStartDate.DateTo.HasValue)
                        {
                            query = query.Where(_ => _.StartDate < criteria.TaskStartDate.DateTo.Value);
                        }
                    }
                    if (criteria.ProcessStartDate != null)
                    {
                        if (criteria.ProcessStartDate.DateFrom.HasValue)
                        {
                            query = query.Where(_ => _.ProcInst.StartDate >= criteria.ProcessStartDate.DateFrom.Value);
                        }
                        if (criteria.ProcessStartDate.DateTo.HasValue)
                        {
                            query = query.Where(_ => _.ProcInst.StartDate < criteria.ProcessStartDate.DateTo.Value);
                        }
                    }
                    if (queryPara.PagingInfo != null)
                    {
                        using (var transactionScope = new System.Transactions.TransactionScope(System.Transactions.TransactionScopeOption.Required, transactionOptions))
                        {
                            queryPara.PagingInfo.ItemCount = query.Count();
                            transactionScope.Complete();
                        }
                        if (queryPara.PagingInfo.SortField != null)
                        {
                            switch (queryPara.PagingInfo.SortField.ToLower())
                            {
                                case "folio":
                                    if (queryPara.PagingInfo.SortOrder == Common.Enum.SortOrder.Descending)
                                    {
                                        query = query.OrderByDescending(_ => _.ProcInst.Folio);
                                    }
                                    else
                                    {
                                        query = query.OrderBy(_ => _.ProcInst.Folio);
                                    }
                                    break;
                                case "worklisttime":
                                    if (queryPara.PagingInfo.SortOrder == Common.Enum.SortOrder.Descending)
                                    {
                                        query = query.OrderByDescending(_ => _.StartDate);
                                    }
                                    else
                                    {
                                        query = query.OrderBy(_ => _.StartDate);
                                    }
                                    break;
                                case "procstarttime":
                                    if (queryPara.PagingInfo.SortOrder == Common.Enum.SortOrder.Descending)
                                    {
                                        query = query.OrderByDescending(_ => _.ProcInst.StartDate);
                                    }
                                    else
                                    {
                                        query = query.OrderBy(_ => _.ProcInst.StartDate);
                                    }
                                    break;
                                default:
                                    query = query.OrderByDescending(_ => _.StartDate);
                                    break;
                            }
                        }
                        else
                        {
                            query = query.OrderByDescending(_ => _.StartDate);
                        }
                        query = query
                            .Skip(queryPara.PagingInfo.PageIndex == 0 ? 0 : (queryPara.PagingInfo.PageIndex - 1) * queryPara.PagingInfo.PageSize)
                            .Take(queryPara.PagingInfo.PageSize);
                    }
                }
                result.PagingInfo = queryPara.PagingInfo;
            }
            //result.PagingInfo = null;

            using (var transactionScope = new System.Transactions.TransactionScope(System.Transactions.TransactionScopeOption.Required, transactionOptions))
            {
                result.ResultList = query.ToList();
                transactionScope.Complete();
            }
            return result;
        }
        public List<ActInst> GetProcessStatusByProcInstId(int procInstId)
        {
            List<ActInst> result = new List<ActInst>();
            //var transactionOptions = new System.Transactions.TransactionOptions();
            //transactionOptions.IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted;
            //using (var transactionScope = new System.Transactions.TransactionScope(System.Transactions.TransactionScopeOption.Required, transactionOptions))
            //{
            var edm = new DianPing.WorkFlow.Repositories.Interface.DianPingK2ServerLog.Entity.DianPingK2ServerLogContext();
            result = edm.ActInst.Include("ProcInst").Include("Act")
                .Where(_ => _.Status == 2)
                .Where(_ => _.ProcInst.ID == procInstId)
                .Where(_ => _.Act.Type == 1)
                .ToList();
            //    transactionScope.Complete();
            //}
            //----------------------
                //var edm = new DianPing.WorkFlow.Repositories.Interface.DianPingK2ServerLog.Entity.DianPingK2ServerLogContext();
                //var result =
                //     (from _ in edm.ProcInst
                //      from ai in _.ActInst.Where(a => a.Status == 2 && a.Act.Type == 1).DefaultIfEmpty()
                //      from ac in edm.Act
                //      //join ac in edm.Act on ai.Act.ID equals ac.ID into acgroup
                //      where _.ID == procInstId

                //      select new
                //      {
                //          ProcInstId = _.ID,
                //          Folio = _.Folio,
                //          ActInst = ai,
                //          WorkList = _.Worklist,
                //          Status = _.Status
                //      }
                //          ).ToList();

                //List<K2Status> list = new List<K2Status>();
                //foreach (var item in result)
                //{
                //    K2Status status = new K2Status()
                //    {
                //        Folio = item.Folio,
                //        ProcInstId = item.ProcInstId,
                //        LoginIds = item.WorkList.Where(_ => _.Status == 0).Select(t => Convert.ToInt32(t.Destination.Replace("K2SQL:", ""))).ToList(),
                //        Activity = item.Status.ToString()
                //    };
                //    if (item.ActInst != null)
                //    {
                //        status.Activity = item.ActInst.Act.Name;
                //        status.StartDate = item.ActInst.StartDate;
                //    }
                //    list.Add(status);
                //}
            //----------------------
               //    foreach (var item in result.GroupBy(_ => _.ActName))
               //    {
               //           list.Add(new K2Status
               //           {
               //                Activity = item.Key,
               //                ProcInstId = item.Select(_ => _.Folio).FirstOrDefault(),
               //                  Folio = item.Select(_=>_.Folio).FirstOrDefault(),
               //                   StartDate = item.Select(_=>_.StartDate).FirstOrDefault(),
               //LoginIds = item.Select

               //            ID = item.Key,
               //            ActInst = item.Select(_=> new ActInst{ ID = _.Act}).ToList(),

               //           });
               //       }

                //var aa =  edm.ProcInst.Include(_ => _.ActInst).Include(_ => _.ActInst.Select(y => y.Act))
                //.Where(_ => _.ID == procInstId)
                //.Where(_ => _.ActInst.Any(t => t.Act.Type == 1))

                //.ToList();
            //edm.Database.SqlQuery(K2Status," SELECT  ","")
            return result;
        }
 public ProcInst GetProcInstById(int Id)
 {
     var edm = new DianPingK2ServerLogContext();
     return edm.ProcInst.Where(_ => _.ID == Id).FirstOrDefault();
 }
 public ProcInst GetProcInstByFolio(string Folio)
 {
     var edm = new DianPingK2ServerLogContext();
     return edm.ProcInst.Where(_ => _.Folio == Folio).FirstOrDefault<ProcInst>();
 }