Exemple #1
0
        public List <CYQ> getCYQ(string Num)
        {
            try
            {
                IQueryable <CYQ> SearchData;
                bool             numIsEmpty = String.IsNullOrEmpty(Num);

                if (!numIsEmpty)
                {
                    int Id = int.Parse(Num);
                    SearchData = db.CYQs.Where(p => p.Stock_Number.Equals(Id));

                    if (SearchData.Count() == 0)
                    {
                        List <CYQ> nullCYQ = new List <CYQ>();
                        return(nullCYQ);
                    }
                    else
                    {
                        return(SearchData.ToList().OrderByDescending(p => p.Publish_Week).ToList());
                    }
                }
                else
                {
                    List <CYQ> nullCYQ = new List <CYQ>();
                    return(nullCYQ);
                }
            }
            catch (System.IO.IOException e)
            {
                logger.Error(LogUtility.GetExceptionDetails(e));
                return(null);
            }
        }
Exemple #2
0
        public List <Exchange> getExchangeList(ForPaging Paging, string Currency)
        {
            try
            {
                IQueryable <Exchange> SearchData;
                SearchData = db.Exchanges.Where(p => p.Currency.Equals(Currency));

                if (String.IsNullOrEmpty(Currency) || SearchData.Count() == 0)
                {
                    List <Exchange> nullExchange = new List <Exchange>();
                    Paging.MaxPage = 1;
                    Paging.SetRightPage();
                    return(nullExchange);
                }
                else
                {
                    Paging.MaxPage = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(SearchData.Count() / Paging.ItemNum)));
                    Paging.SetRightPage();
                    return(SearchData.OrderByDescending(p => p.QuotedDate).Skip((Paging.NowPage - 1) * Paging.ItemNum).Take(Paging.ItemNum).ToList());
                }
            }
            catch (System.IO.IOException e)
            {
                logger.Error(LogUtility.GetExceptionDetails(e));
                return(null);
            }
        }
Exemple #3
0
        public List <Stock> getStockList(ForPaging Paging, string Num)
        {
            try
            {
                IQueryable <Stock> SearchData;
                bool numIsEmpty = String.IsNullOrEmpty(Num);

                if (!numIsEmpty)
                {
                    int Id = int.Parse(Num);
                    SearchData = db.Stocks.Where(p => p.Id.Equals(Id));

                    if (SearchData.Count() == 0)
                    {
                        List <Stock> nullStock = new List <Stock>();
                        Paging.MaxPage = 1;
                        Paging.SetRightPage();
                        return(nullStock);
                    }
                    else
                    {
                        Paging.MaxPage = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(SearchData.Count() / Paging.ItemNum)));
                        Paging.SetRightPage();
                        return(SearchData.ToList().OrderByDescending(p => p.Price_Date).Skip((Paging.NowPage - 1) * Paging.ItemNum).Take(Paging.ItemNum).ToList());
                    }
                }
                else
                {
                    List <Stock> nullStock = new List <Stock>();
                    Paging.MaxPage = 1;
                    Paging.SetRightPage();
                    return(nullStock);
                }
            }
            catch (System.IO.IOException e)
            {
                logger.Error(LogUtility.GetExceptionDetails(e));
                return(null);
            }
        }
        //根據搜尋來取得資料陣列的方法
        public List <Products> GetDataList(ForPaging Paging, ProductsView searchCondition)
        {
            //宣告要接受全部搜尋資料的物件
            IQueryable <Products> SearchData;

            SearchData = db.Products;

            string productID   = "";
            string productName = "";

            if (searchCondition.ProductID != null)
            {
                productID = searchCondition.ProductID.ToString().Trim();
            }

            if (searchCondition.ProductName != null)
            {
                productName = searchCondition.ProductName.Trim();
            }

            if (String.IsNullOrEmpty(productID) == false)
            {
                SearchData = SearchData.Where(p => p.ProductID.ToString().Contains(productID));
            }

            if (String.IsNullOrEmpty(productName) == false)
            {
                SearchData = SearchData.Where(p => p.ProductName.ToString().Contains(productName));
            }

            //計算所需的總頁數
            Paging.MaxPage = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(SearchData.Count()) / Paging.ItemNum));

            //重新設定正確的頁數,避免有不正確值傳入
            Paging.SetRightPage();

            //先排序再根據分頁來回傳所需部分的資料陣列
            return(SearchData.OrderByDescending(p => p.ProductID).Skip((Paging.NowPage - 1) * Paging.ItemNum).Take(Paging.ItemNum).ToList());
        }