Esempio n. 1
0
        public List <DeliveryListVModel> GetList2(string cls = null)
        {
            List <DeliveryListVModel> dv = new List <DeliveryListVModel>();
            List <DelivFlowModel>     rf = new List <DelivFlowModel>();
            List <DelivFlowModel>     rf2;
            // Get Login User's details.
            var ur = _userRepo.Find(usr => usr.UserName == User.Identity.Name).FirstOrDefault();

            switch (cls)
            {
            case "已處理":
                rf2 = _context.DelivFlows.FromSql("SELECT * FROM BMEDDELIVFLOWS WHERE STATUS ='?'")
                      .Where(m => m.UserId != ur.Id).ToList();
                if (!userManager.IsInRole(User, "Usual"))
                {
                    rf.AddRange(rf2);
                }
                else
                {
                    foreach (DelivFlowModel f in rf2)
                    {
                        if (_context.DelivFlows.Where(m => m.DocId == f.DocId).Where(m => m.UserId == ur.Id).Count() > 0)
                        {
                            rf.Add(f);
                        }
                    }
                }

                break;

            case "已結案":
                rf2 = _context.DelivFlows.FromSql("SELECT * FROM BMEDDELIVFLOWS WHERE STATUS ='2'").ToList();
                if (!userManager.IsInRole(User, "Usual"))
                {
                    rf.AddRange(rf2);
                }
                else
                {
                    foreach (DelivFlowModel f in rf2)
                    {
                        if (_context.DelivFlows.Where(m => m.DocId == f.DocId).Where(m => m.UserId == ur.Id).Count() > 0)
                        {
                            rf.Add(f);
                        }
                    }
                }
                break;

            case "所有":
                rf2 = _context.DelivFlows.FromSql("SELECT * FROM BMEDDELIVFLOWS WHERE STATUS ='2' OR STATUS ='?'").ToList();
                if (!userManager.IsInRole(User, "Usual"))
                {
                    rf.AddRange(rf2);
                }
                else
                {
                    foreach (DelivFlowModel f in rf2)
                    {
                        if (_context.DelivFlows.Where(m => m.DocId == f.DocId).Where(m => m.UserId == ur.Id).Count() > 0)
                        {
                            rf.Add(f);
                        }
                    }
                }
                break;

            default:
                rf = _context.DelivFlows.FromSql("SELECT * FROM BMEDDELIVFLOWS WHERE STATUS ='?'")
                     .Where(m => m.UserId == ur.Id).ToList();
                break;
            }
            rf.OrderByDescending(m => m.Rtt);
            DeliveryListVModel i;

            foreach (DelivFlowModel f in rf)
            {
                DeliveryModel r = _context.Deliveries.Find(f.DocId);
                AppUserModel  p = _context.AppUsers.Find(r.UserId);
                i            = new DeliveryListVModel();
                i.DocType    = "驗收";
                i.DocId      = r.DocId;
                i.UserId     = r.UserId;
                i.UserName   = r.UserName;
                i.ContractNo = r.ContractNo;
                i.PurchaseNo = r.PurchaseNo;
                i.CrlItemNo  = r.CrlItemNo;
                i.AccDpt     = r.AccDpt;
                i.AccDptNam  = _context.Departments.Find(r.AccDpt) == null ? "" : _context.Departments.Find(r.AccDpt).Name_C;
                i.BudgetId   = "";
                if (f.Status == "?")
                {
                    i.Days = DateTime.Now.Subtract(r.ApplyDate.GetValueOrDefault()).Days;
                }
                else
                {
                    i.Days = null;
                }
                i.Flg      = f.Status;
                i.FlowUid  = f.UserId;
                i.VendorNo = r.VendorId;
                dv.Add(i);
            }
            //
            return(dv);
        }
Esempio n. 2
0
        public List <DeliveryListVModel> GetDeliveryList(string cls = null)
        {
            List <DeliveryListVModel> dv = new List <DeliveryListVModel>();
            List <DelivFlowModel>     rf = new List <DelivFlowModel>();
            List <DelivFlowModel>     rf2;
            // Get Login User's details.
            var ur = _userRepo.Find(usr => usr.UserName == User.Identity.Name).FirstOrDefault();

            switch (cls)
            {
            case "已處理":
                rf2 = _context.DelivFlows.Where(df => df.Status == "?")
                      .Where(m => m.UserId != ur.Id).ToList();
                if (!userManager.IsInRole(User, "Usual"))
                {
                    rf.AddRange(rf2);
                }
                else
                {
                    foreach (DelivFlowModel f in rf2)
                    {
                        if (_context.DelivFlows.Where(m => m.DocId == f.DocId).Where(m => m.UserId == ur.Id).Count() > 0)
                        {
                            rf.Add(f);
                        }
                    }
                }

                break;

            case "已結案":
                rf2 = _context.DelivFlows.Where(df => df.Status == "2").ToList();
                if (!userManager.IsInRole(User, "Usual"))
                {
                    rf.AddRange(rf2);
                }
                else
                {
                    foreach (DelivFlowModel f in rf2)
                    {
                        if (_context.DelivFlows.Where(m => m.DocId == f.DocId).Where(m => m.UserId == ur.Id).Count() > 0)
                        {
                            rf.Add(f);
                        }
                    }
                }
                break;

            case "所有":
                rf2 = _context.DelivFlows.Where(df => df.Status == "2" || df.Status == "?").ToList();
                if (!userManager.IsInRole(User, "Usual"))
                {
                    rf.AddRange(rf2);
                }
                else
                {
                    foreach (DelivFlowModel f in rf2)
                    {
                        if (_context.DelivFlows.Where(m => m.DocId == f.DocId).Where(m => m.UserId == ur.Id).Count() > 0)
                        {
                            rf.Add(f);
                        }
                    }
                }
                break;

            case "查詢":
                rf2 = _context.DelivFlows.Where(df => df.Status == "?").ToList();
                DeliveryModel r;
                foreach (DelivFlowModel f in rf2)
                {
                    r = _context.Deliveries.Find(f.DocId);
                    rf.Add(f);
                }
                break;

            default:
                rf = _context.DelivFlows.Where(df => df.Status == "?")
                     .Where(m => m.UserId == ur.Id).ToList();
                break;
            }
            rf.OrderByDescending(m => m.Rtt);
            DeliveryListVModel i;

            foreach (DelivFlowModel f in rf)
            {
                DeliveryModel   r = _context.Deliveries.Find(f.DocId);
                AppUserModel    p = r == null ? null : _context.AppUsers.Find(r.UserId);
                DepartmentModel c = p == null ? null : _context.Departments.Find(p.DptId);
                //BuyEvaluate b = db.BuyEvaluates.Find(r.PurchaseNo);
                if (r != null)
                {
                    i          = new DeliveryListVModel();
                    i.DocType  = "驗收";
                    i.DocId    = r.DocId;
                    i.UserId   = r.UserId;
                    i.UserName = r.UserName;
                    if (p != null)
                    {
                        i.Company    = p.DptId;
                        i.CompanyNam = c == null ? "" : c.Name_C;
                    }
                    i.ContractNo = r.ContractNo;
                    i.PurchaseNo = r.PurchaseNo;
                    i.CrlItemNo  = r.CrlItemNo;
                    i.AccDpt     = r.AccDpt;
                    var accDpt = _context.Departments.Find(r.AccDpt);
                    i.AccDptNam = accDpt == null ? "" : accDpt.Name_C;
                    i.BudgetId  = "";
                    if (f.Status == "?")
                    {
                        i.Days = DateTime.Now.Subtract(r.ApplyDate.GetValueOrDefault()).Days;
                    }
                    else
                    {
                        i.Days = null;
                    }
                    i.Flg       = f.Status;
                    i.FlowUid   = f.UserId;
                    i.VendorNo  = r.VendorId;
                    i.ApplyDate = r.ApplyDate;
                    dv.Add(i);
                }
            }
            //
            return(dv);
        }