示例#1
0
        private List<Contents> ConvertList(List<Contents> ListContent, int TitleLenght, int IntroLenght, int Limit, string Order, bool IsDesc)
        {
            if ((Limit == null) || (Limit <= 0)) {
                Limit = ListContent.Count;
            }
            if (Limit > ListContent.Count) {
                Limit = ListContent.Count;
            }

            if ((TitleLenght == null) || (TitleLenght <= 0)) {
                TitleLenght = 1000;
            }
            if ((IntroLenght == null) || (IntroLenght <= 0)) {
                IntroLenght = 1000;
            }

            //=========================

            switch (Order) {
                case "Code":
                    if (IsDesc == false) {
                        ListContent = ListContent.OrderBy(a => a.Code).ToList();
                    }
                    else {
                        ListContent = ListContent.OrderByDescending(a => a.Code).ToList();
                    }
                    break;
                case "DateCreated":
                    if (IsDesc == false) {
                        ListContent = ListContent.OrderBy(a => a.DateCreated).ToList();
                    }
                    else {
                        ListContent = ListContent.OrderByDescending(a => a.DateCreated).ToList();
                    }
                    break;
                case "DateEdited":
                    if (IsDesc == false) {
                        ListContent = ListContent.OrderBy(a => a.DateEdited).ToList();
                    }
                    else {
                        ListContent = ListContent.OrderByDescending(a => a.DateEdited).ToList();
                    }
                    break;
                case "CommentCount":
                    if (IsDesc == false) {
                        ListContent = ListContent.OrderBy(a => a.CommentCount).ToList();
                    }
                    else {
                        ListContent = ListContent.OrderByDescending(a => a.CommentCount).ToList();
                    }
                    break;
                //==============================================================================
                case "ExpireDate":
                    if (IsDesc == false) {
                        ListContent = ListContent.OrderBy(a => a.ExpireDate).ToList();
                    }
                    else {
                        ListContent = ListContent.OrderByDescending(a => a.ExpireDate).ToList();
                    }
                    break;
                //==============================================================================
                case "ID":
                    if (IsDesc == false) {
                        ListContent = ListContent.OrderBy(a => a.ID).ToList();
                    }
                    else {
                        ListContent = ListContent.OrderByDescending(a => a.ID).ToList();
                    }
                    break;
                //==============================================================================
                case "LikeCount":
                    if (IsDesc == false) {
                        ListContent = ListContent.OrderBy(a => a.LikeCount).ToList();
                    }
                    else {
                        ListContent = ListContent.OrderByDescending(a => a.LikeCount).ToList();
                    }
                    break;
                //==============================================================================
                case "PublishDate":
                    if (IsDesc == false) {
                        ListContent = ListContent.OrderBy(a => a.PublishDate).ToList();
                    }
                    else {
                        ListContent = ListContent.OrderByDescending(a => a.PublishDate).ToList();
                    }
                    break;
                //==============================================================================
                case "ViewCount":
                    if (IsDesc == false) {
                        ListContent = ListContent.OrderBy(a => a.ViewCount).ToList();
                    }
                    else {
                        ListContent = ListContent.OrderByDescending(a => a.ViewCount).ToList();
                    }
                    break;
                //==============================================================================
                case "Vote":
                    if (IsDesc == false) {
                        ListContent = ListContent.OrderBy(a => a.Vote).ToList();
                    }
                    else {
                        ListContent = ListContent.OrderByDescending(a => a.Vote).ToList();
                    }
                    break;
                //==============================================================================
                case "Type":
                    if (IsDesc == false) {
                        ListContent = ListContent.OrderBy(a => a.Type).ToList();
                    }
                    else {
                        ListContent = ListContent.OrderByDescending(a => a.Type).ToList();
                    }
                    break;
                //==============================================================================
                case "Title":
                    if (IsDesc == false) {
                        ListContent = ListContent.OrderBy(a => a.Title).ToList();
                    }
                    else {
                        ListContent = ListContent.OrderByDescending(a => a.Title).ToList();
                    }
                    break;
                //==============================================================================
                case "Status":
                    if (IsDesc == false) {
                        ListContent = ListContent.OrderBy(a => a.Status).ToList();
                    }
                    else {
                        ListContent = ListContent.OrderByDescending(a => a.Status).ToList();
                    }
                    break;
                //==============================================================================
                case "Disable":
                    if (IsDesc == false) {
                        ListContent = ListContent.OrderBy(a => a.Disable).ToList();
                    }
                    else {
                        ListContent = ListContent.OrderByDescending(a => a.Disable).ToList();
                    }
                    break;
                //==============================================================================
                default:

                    break;
            }
            //###############################################################################
            int TitleLenght_Tempt = TitleLenght;
            int IntroLenght_Tempt = IntroLenght;

            for (int i = 0; i < Limit; i++) {
                if (ListContent[i].Title.Length < TitleLenght_Tempt) {
                    TitleLenght_Tempt = ListContent[i].Title.Length;
                }
                if (ListContent[i].Intro.Length < IntroLenght_Tempt) {
                    IntroLenght_Tempt = ListContent[i].Intro.Length;
                }

                //if (TitleLenght == 0) { TitleLenght = 1; }
                //if (IntroLenght == 0) { IntroLenght = 1; }

                ListContent[i].Title = ListContent[i].Title.Substring(0, TitleLenght_Tempt);
                ListContent[i].Intro = ListContent[i].Intro.Substring(0, IntroLenght_Tempt);

                TitleLenght_Tempt = TitleLenght;
                IntroLenght_Tempt = IntroLenght;
            }

            ListContent = ListContent.GetRange(0, Limit).ToList();
            return ListContent;
            //=========================
        }
        private List<CategoryLevel2> ConvertList(List<CategoryLevel2> ListCategoryLevel2, int InfoLenght, int IntroLenght, int Limit, string Order, bool IsDesc)
        {
            if ((Limit == null) || (Limit <= 0))
            {
                Limit = ListCategoryLevel2.Count;
            }
            if (Limit > ListCategoryLevel2.Count)
            {
                Limit = ListCategoryLevel2.Count;
            }

            if ((InfoLenght == null) || (InfoLenght <= 0))
            {
                InfoLenght = 1000;
            }
            if ((IntroLenght == null) || (IntroLenght <= 0))
            {
                IntroLenght = 1000;
            }

            //=========================

            switch (Order)
            {
                case "Code":
                    if (IsDesc == false)
                    {
                        ListCategoryLevel2 = ListCategoryLevel2.OrderBy(a => a.Code).ToList();
                    }
                    else
                    {
                        ListCategoryLevel2 = ListCategoryLevel2.OrderByDescending(a => a.Code).ToList();
                    }
                    break;
                case "CategoryNameLevel2":
                    if (IsDesc == false)
                    {
                        ListCategoryLevel2 = ListCategoryLevel2.OrderBy(a => a.CategoryNameLevel2).ToList();
                    }
                    else
                    {
                        ListCategoryLevel2 = ListCategoryLevel2.OrderByDescending(a => a.CategoryNameLevel2).ToList();
                    }
                    break;
                case "Status":
                    if (IsDesc == false)
                    {
                        ListCategoryLevel2 = ListCategoryLevel2.OrderBy(a => a.Status).ToList();
                    }
                    else
                    {
                        ListCategoryLevel2 = ListCategoryLevel2.OrderByDescending(a => a.Status).ToList();
                    }
                    break;
                case "Disable":
                    if (IsDesc == false)
                    {
                        ListCategoryLevel2 = ListCategoryLevel2.OrderBy(a => a.Disable).ToList();
                    }
                    else
                    {
                        ListCategoryLevel2 = ListCategoryLevel2.OrderByDescending(a => a.Disable).ToList();
                    }
                    break;
                //==============================================================================
                case "IDLang":
                    if (IsDesc == false)
                    {
                        ListCategoryLevel2 = ListCategoryLevel2.OrderBy(a => a.IDLang).ToList();
                    }
                    else
                    {
                        ListCategoryLevel2 = ListCategoryLevel2.OrderByDescending(a => a.IDLang).ToList();
                    }
                    break;
                //==============================================================================
                case "ID":
                    if (IsDesc == false)
                    {
                        ListCategoryLevel2 = ListCategoryLevel2.OrderBy(a => a.ID).ToList();
                    }
                    else
                    {
                        ListCategoryLevel2 = ListCategoryLevel2.OrderByDescending(a => a.ID).ToList();
                    }
                    break;
                //==============================================================================
                case "Type":
                    if (IsDesc == false)
                    {
                        ListCategoryLevel2 = ListCategoryLevel2.OrderBy(a => a.Type).ToList();
                    }
                    else
                    {
                        ListCategoryLevel2 = ListCategoryLevel2.OrderByDescending(a => a.Type).ToList();
                    }
                    break;
                //==============================================================================
                case "Note":
                    if (IsDesc == false)
                    {
                        ListCategoryLevel2 = ListCategoryLevel2.OrderBy(a => a.Note).ToList();
                    }
                    else
                    {
                        ListCategoryLevel2 = ListCategoryLevel2.OrderByDescending(a => a.Note).ToList();
                    }
                    break;
                //==============================================================================
                case "Image":
                    if (IsDesc == false)
                    {
                        ListCategoryLevel2 = ListCategoryLevel2.OrderBy(a => a.Image).ToList();
                    }
                    else
                    {
                        ListCategoryLevel2 = ListCategoryLevel2.OrderByDescending(a => a.Image).ToList();
                    }
                    break;
                //==============================================================================
                case "Image1":
                    if (IsDesc == false)
                    {
                        ListCategoryLevel2 = ListCategoryLevel2.OrderBy(a => a.Image1).ToList();
                    }
                    else
                    {
                        ListCategoryLevel2 = ListCategoryLevel2.OrderByDescending(a => a.Image1).ToList();
                    }
                    break;
                //==============================================================================
                case "Image2":
                    if (IsDesc == false)
                    {
                        ListCategoryLevel2 = ListCategoryLevel2.OrderBy(a => a.Image2).ToList();
                    }
                    else
                    {
                        ListCategoryLevel2 = ListCategoryLevel2.OrderByDescending(a => a.Image2).ToList();
                    }
                    break;
                //==============================================================================
                case "Image3":
                    if (IsDesc == false)
                    {
                        ListCategoryLevel2 = ListCategoryLevel2.OrderBy(a => a.Image3).ToList();
                    }
                    else
                    {
                        ListCategoryLevel2 = ListCategoryLevel2.OrderByDescending(a => a.Image3).ToList();
                    }
                    break;
                //==============================================================================
                case "Tag":
                    if (IsDesc == false)
                    {
                        ListCategoryLevel2 = ListCategoryLevel2.OrderBy(a => a.Tag).ToList();
                    }
                    else
                    {
                        ListCategoryLevel2 = ListCategoryLevel2.OrderByDescending(a => a.Tag).ToList();
                    }
                    break;
                //==============================================================================
                case "Info":
                    if (IsDesc == false)
                    {
                        ListCategoryLevel2 = ListCategoryLevel2.OrderBy(a => a.Info).ToList();
                    }
                    else
                    {
                        ListCategoryLevel2 = ListCategoryLevel2.OrderByDescending(a => a.Info).ToList();
                    }
                    break;
                //==============================================================================
                case "Intro":
                    if (IsDesc == false)
                    {
                        ListCategoryLevel2 = ListCategoryLevel2.OrderBy(a => a.Intro).ToList();
                    }
                    else
                    {
                        ListCategoryLevel2 = ListCategoryLevel2.OrderByDescending(a => a.Intro).ToList();
                    }
                    break;

                //==============================================================================
                case "IDAlbum":
                    if (IsDesc == false)
                    {
                        ListCategoryLevel2 = ListCategoryLevel2.OrderBy(a => a.IDAlbum).ToList();
                    }
                    else
                    {
                        ListCategoryLevel2 = ListCategoryLevel2.OrderByDescending(a => a.IDAlbum).ToList();
                    }
                    break;

                //==============================================================================
                case "ViewCount":
                    if (IsDesc == false)
                    {
                        ListCategoryLevel2 = ListCategoryLevel2.OrderBy(a => a.ViewCount).ToList();
                    }
                    else
                    {
                        ListCategoryLevel2 = ListCategoryLevel2.OrderByDescending(a => a.ViewCount).ToList();
                    }
                    break;
                //==============================================================================
                default:

                    break;
            }
            //###############################################################################
            int InfoLenght_Tempt = InfoLenght;
            int IntroLenght_Tempt = IntroLenght;

            for (int i = 0; i < Limit; i++)
            {
                if (ListCategoryLevel2[i].Info.Length < InfoLenght)
                {
                    InfoLenght_Tempt = ListCategoryLevel2[i].Info.Length;
                }
                if (ListCategoryLevel2[i].Intro.Length < IntroLenght_Tempt)
                {
                    IntroLenght_Tempt = ListCategoryLevel2[i].Intro.Length;
                }

                //if (TitleLenght == 0) { TitleLenght = 1; }
                //if (IntroLenght == 0) { IntroLenght = 1; }

                ListCategoryLevel2[i].Info = ListCategoryLevel2[i].Info.Substring(0, InfoLenght_Tempt);
                ListCategoryLevel2[i].Intro = ListCategoryLevel2[i].Intro.Substring(0, IntroLenght_Tempt);

                InfoLenght_Tempt = InfoLenght;
                IntroLenght_Tempt = IntroLenght;
            }

            ListCategoryLevel2 = ListCategoryLevel2.GetRange(0, Limit).ToList();
            return ListCategoryLevel2;
            //=========================
        }
示例#3
0
        private List<vw_ContentsViewAll> ConvertList(List<vw_ContentsViewAll> ListContent, int TitleLenght, int IntroLenght, int Limit, string Order, bool IsDesc)
        {
            if ((Limit == null) || (Limit <= 0)) {
                Limit = ListContent.Count;
            }
            if (Limit > ListContent.Count) {
                Limit = ListContent.Count;
            }

            if ((TitleLenght == null) || (TitleLenght <= 0)) {
                TitleLenght = 1000;
            }
            if ((IntroLenght == null) || (IntroLenght <= 0)) {
                IntroLenght = 1000;
            }

            //=========================

            switch (Order) {
                case "Contents_Code":
                    if (IsDesc == false) {
                        ListContent = ListContent.OrderBy(a => a.Contents_Code).ToList();
                    }
                    else {
                        ListContent = ListContent.OrderByDescending(a => a.Contents_Code).ToList();
                    }
                    break;
                case "Contents_DateCreated":
                    if (IsDesc == false) {
                        ListContent = ListContent.OrderBy(a => a.Contents_DateCreated).ToList();
                    }
                    else {
                        ListContent = ListContent.OrderByDescending(a => a.Contents_DateCreated).ToList();
                    }
                    break;
                case "Contents_DateEdited":
                    if (IsDesc == false) {
                        ListContent = ListContent.OrderBy(a => a.Contents_DateEdited).ToList();
                    }
                    else {
                        ListContent = ListContent.OrderByDescending(a => a.Contents_DateEdited).ToList();
                    }
                    break;
                case "Contents_CommentCount":
                    if (IsDesc == false) {
                        ListContent = ListContent.OrderBy(a => a.Contents_CommentCount).ToList();
                    }
                    else {
                        ListContent = ListContent.OrderByDescending(a => a.Contents_CommentCount).ToList();
                    }
                    break;
                //==============================================================================
                case "Contents_ExpireDate":
                    if (IsDesc == false) {
                        ListContent = ListContent.OrderBy(a => a.Contents_ExpireDate).ToList();
                    }
                    else {
                        ListContent = ListContent.OrderByDescending(a => a.Contents_ExpireDate).ToList();
                    }
                    break;
                //==============================================================================
                case "Contents_ID":
                    if (IsDesc == false) {
                        ListContent = ListContent.OrderBy(a => a.Contents_ID).ToList();
                    }
                    else {
                        ListContent = ListContent.OrderByDescending(a => a.Contents_ID).ToList();
                    }
                    break;
                //==============================================================================
                case "Contents_LikeCount":
                    if (IsDesc == false) {
                        ListContent = ListContent.OrderBy(a => a.Contents_LikeCount).ToList();
                    }
                    else {
                        ListContent = ListContent.OrderByDescending(a => a.Contents_LikeCount).ToList();
                    }
                    break;
                //==============================================================================
                case "Contents_PublishDate":
                    if (IsDesc == false) {
                        ListContent = ListContent.OrderBy(a => a.Contents_PublishDate).ToList();
                    }
                    else {
                        ListContent = ListContent.OrderByDescending(a => a.Contents_PublishDate).ToList();
                    }
                    break;
                //==============================================================================
                case "Contents_ViewCount":
                    if (IsDesc == false) {
                        ListContent = ListContent.OrderBy(a => a.Contents_ViewCount).ToList();
                    }
                    else {
                        ListContent = ListContent.OrderByDescending(a => a.Contents_ViewCount).ToList();
                    }
                    break;
                //==============================================================================
                case "Contents_Vote":
                    if (IsDesc == false) {
                        ListContent = ListContent.OrderBy(a => a.Contents_Vote).ToList();
                    }
                    else {
                        ListContent = ListContent.OrderByDescending(a => a.Contents_Vote).ToList();
                    }
                    break;
                //==============================================================================
                case "Contents_Type":
                    if (IsDesc == false) {
                        ListContent = ListContent.OrderBy(a => a.Contents_Type).ToList();
                    }
                    else {
                        ListContent = ListContent.OrderByDescending(a => a.Contents_Type).ToList();
                    }
                    break;
                //==============================================================================
                case "Contents_Title":
                    if (IsDesc == false) {
                        ListContent = ListContent.OrderBy(a => a.Contents_Title).ToList();
                    }
                    else {
                        ListContent = ListContent.OrderByDescending(a => a.Contents_Title).ToList();
                    }
                    break;
                //==============================================================================
                case "Contents_Status":
                    if (IsDesc == false) {
                        ListContent = ListContent.OrderBy(a => a.Contents_Status).ToList();
                    }
                    else {
                        ListContent = ListContent.OrderByDescending(a => a.Contents_Status).ToList();
                    }
                    break;
                //==============================================================================
                case "Contents_Disable":
                    if (IsDesc == false) {
                        ListContent = ListContent.OrderBy(a => a.Contents_Disable).ToList();
                    }
                    else {
                        ListContent = ListContent.OrderByDescending(a => a.Contents_Disable).ToList();
                    }
                    break;
                //###############################################################################
                case "CategoryLevel1_CategoryNameLevel1":
                    if (IsDesc == false) {
                        ListContent = ListContent.OrderBy(a => a.CategoryLevel1_CategoryNameLevel1).ToList();
                    }
                    else {
                        ListContent = ListContent.OrderByDescending(a => a.CategoryLevel1_CategoryNameLevel1).ToList();
                    }
                    break;
                //==============================================================================
                case "CategoryLevel1_Code":
                    if (IsDesc == false) {
                        ListContent = ListContent.OrderBy(a => a.CategoryLevel1_Code).ToList();
                    }
                    else {
                        ListContent = ListContent.OrderByDescending(a => a.CategoryLevel1_Code).ToList();
                    }
                    break;
                //==============================================================================
                case "CategoryLevel1_Disable":
                    if (IsDesc == false) {
                        ListContent = ListContent.OrderBy(a => a.CategoryLevel1_Disable).ToList();
                    }
                    else {
                        ListContent = ListContent.OrderByDescending(a => a.CategoryLevel1_Disable).ToList();
                    }
                    break;
                //==============================================================================
                case "CategoryLevel1_Status":
                    if (IsDesc == false) {
                        ListContent = ListContent.OrderBy(a => a.CategoryLevel1_Status).ToList();
                    }
                    else {
                        ListContent = ListContent.OrderByDescending(a => a.CategoryLevel1_Status).ToList();
                    }
                    break;
                //==============================================================================
                case "CategoryLevel1_Type":
                    if (IsDesc == false) {
                        ListContent = ListContent.OrderBy(a => a.CategoryLevel1_Type).ToList();
                    }
                    else {
                        ListContent = ListContent.OrderByDescending(a => a.CategoryLevel1_Type).ToList();
                    }
                    break;
                //==============================================================================
                case "CategoryLevel1_ViewCount":
                    if (IsDesc == false) {
                        ListContent = ListContent.OrderBy(a => a.CategoryLevel1_ViewCount).ToList();
                    }
                    else {
                        ListContent = ListContent.OrderByDescending(a => a.CategoryLevel1_ViewCount).ToList();
                    }
                    break;
                //###############################################################################
                case "Contents_CategoryLevel1_Disable":
                    if (IsDesc == false) {
                        ListContent = ListContent.OrderBy(a => a.Contents_CategoryLevel1_Disable).ToList();
                    }
                    else {
                        ListContent = ListContent.OrderByDescending(a => a.Contents_CategoryLevel1_Disable).ToList();
                    }
                    break;
                //==============================================================================
                case "Contents_CategoryLevel1_Status":
                    if (IsDesc == false) {
                        ListContent = ListContent.OrderBy(a => a.Contents_CategoryLevel1_Status).ToList();
                    }
                    else {
                        ListContent = ListContent.OrderByDescending(a => a.Contents_CategoryLevel1_Status).ToList();
                    }
                    break;
                //==============================================================================
                case "Contents_CategoryLevel1_Type":
                    if (IsDesc == false) {
                        ListContent = ListContent.OrderBy(a => a.Contents_CategoryLevel1_Type).ToList();
                    }
                    else {
                        ListContent = ListContent.OrderByDescending(a => a.Contents_CategoryLevel1_Type).ToList();
                    }
                    break;
                //==============================================================================
                default:

                    break;
            }

            //###############################################################################
            int TitleLenght_Tempt = TitleLenght;
            int IntroLenght_Tempt = IntroLenght;

            for (int i = 0; i < Limit; i++) {
                if (ListContent[i].Contents_Title.Length < TitleLenght_Tempt) {
                    TitleLenght_Tempt = ListContent[i].Contents_Title.Length;
                }
                if (ListContent[i].Contents_Intro.Length < IntroLenght_Tempt) {
                    IntroLenght_Tempt = ListContent[i].Contents_Intro.Length;
                }

                //if (TitleLenght == 0) { TitleLenght = 1; }
                //if (IntroLenght == 0) { IntroLenght = 1; }

                ListContent[i].Contents_Title = ListContent[i].Contents_Title.Substring(0, TitleLenght_Tempt);
                ListContent[i].Contents_Intro = ListContent[i].Contents_Intro.Substring(0, IntroLenght_Tempt);

                TitleLenght_Tempt = TitleLenght;
                IntroLenght_Tempt = IntroLenght;
            }

            ListContent = ListContent.GetRange(0, Limit).ToList();
            return ListContent;
            //=========================
        }