コード例 #1
0
        public List<Cog.MLIAD.BusinessLogic.Associate.SoftwareRequest> SearchSoftware(Associate.SoftwareRequest software, int pageIndex, int pageSize, ref int? count)
        {
            using (AssociateConnDataContext asscon = new AssociateConnDataContext())
            {
                try
                {
                    Cog.MLIAD.BusinessLogic.Associate.SoftwareRequest retval = new Cog.MLIAD.BusinessLogic.Associate.SoftwareRequest();
                    var softwares = (from s in asscon.SearchSoftware(software.SoftResourceID, software.SoftCategoryID, software.ProjectID, ref count)
                                     select new Cog.MLIAD.BusinessLogic.Associate.SoftwareRequest()
                                     {
                                         SoftRequestID = s.SoftRequestID,
                                         SoftCategory = s.SoftCategory,
                                         SoftResource = s.SoftResource,
                                         SoftVersion = s.SoftVersion,
                                         ProjectName = s.ProjectName
                                     }).ToList<Cog.MLIAD.BusinessLogic.Associate.SoftwareRequest>();

                    pageSize = (pageSize < 1 ? 10 : pageSize);
                    pageIndex = (pageIndex < 0 ? 0 : pageIndex);
                    count = softwares.Count;
                    if (count < pageSize)
                    {
                        pageIndex = 0;
                        return softwares;
                    }
                    else if (softwares.Count < pageSize * pageIndex)
                    {
                        pageIndex = 0;
                        return new List<BusinessLogic.Associate.SoftwareRequest>(softwares.Take(pageSize));
                    }
                    else
                    {
                        int a = Convert.ToInt32(((count - pageSize * pageIndex) >= pageSize) ? pageSize : (count - pageSize * pageIndex));
                        return new List<BusinessLogic.Associate.SoftwareRequest>(softwares.Skip(pageSize * pageIndex).Take(a));
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }