// Load ra danh sách các contact bằng IDLang
        public void Sel_Ext_ByCode(HttpContext context)
        {
            String jSonString = "";

            string Code = context.Request.QueryString["Code"] != null && context.Request.QueryString["Code"] != "undefined" ? context.Request.QueryString["Code"] : "";
            int IDLang = context.Request.QueryString["IDLang"] != null && context.Request.QueryString["IDLang"] != "undefined" ? int.Parse(context.Request.QueryString["IDLang"]) : 1;

            int IntroLenght = context.Request.QueryString["IntroLenght"] != null && context.Request.QueryString["IntroLenght"] != "undefined" ? int.Parse(context.Request.QueryString["IntroLenght"]) : -1;
            int TitleLenght = context.Request.QueryString["TitleLenght"] != null && context.Request.QueryString["TitleLenght"] != "undefined" ? int.Parse(context.Request.QueryString["TitleLenght"]) : -1;
            int Limit = context.Request.QueryString["Limit"] != null && context.Request.QueryString["Limit"] != "undefined" ? int.Parse(context.Request.QueryString["Limit"]) : -1;
            string Order = context.Request.QueryString["Order"] != null && context.Request.QueryString["Order"] != "undefined" ? context.Request.QueryString["Order"] : "-1";
            string IsDesc = context.Request.QueryString["IsDesc"] != null && context.Request.QueryString["IsDesc"] != "undefined" ? context.Request.QueryString["IsDesc"] : "-1";

            CategoryLevel2BO aCategoryLevel2BO = new CategoryLevel2BO();
            List<vw_CategoryLevel2ViewAll> obj = aCategoryLevel2BO.Sel_Ext_ByCode(Code);

            List<vw_CategoryLevel2ViewAll> ObjOrder = new List<vw_CategoryLevel2ViewAll>();

            switch (Order)
            {
                case "Code":
                    if (IsDesc == "False")
                    {
                        ObjOrder = obj.OrderBy(a => a.Code).ToList();
                    }
                    else
                    {
                        ObjOrder = obj.OrderByDescending(a => a.Code).ToList();
                    }
                    break;

                case "CategoryNameLevel2":
                    if (IsDesc == "False")
                    {
                        ObjOrder = obj.OrderBy(a => a.CategoryNameLevel2).ToList();
                    }
                    else
                    {
                        ObjOrder = obj.OrderByDescending(a => a.CategoryNameLevel2).ToList();
                    }
                    break;

                case "CountCategoryLeve1":
                    if (IsDesc == "False")
                    {
                        ObjOrder = obj.OrderBy(a => a.CountCategoryLeve1).ToList();
                    }
                    else
                    {
                        ObjOrder = obj.OrderByDescending(a => a.CountCategoryLeve1).ToList();
                    }
                    break;
                case "CountCategoryLeve1Disable":
                    if (IsDesc == "False")
                    {
                        ObjOrder = obj.OrderBy(a => a.CountCategoryLeve1Disable).ToList();
                    }
                    else
                    {
                        ObjOrder = obj.OrderByDescending(a => a.CountCategoryLeve1Disable).ToList();
                    }
                    break;
                case "CountCategoryLeve1Enable":
                    if (IsDesc == "False")
                    {
                        ObjOrder = obj.OrderBy(a => a.CountCategoryLeve1Enable).ToList();
                    }
                    else
                    {
                        ObjOrder = obj.OrderByDescending(a => a.CountCategoryLeve1Enable).ToList();
                    }
                    break;
                case "Disable":
                    if (IsDesc == "False")
                    {
                        ObjOrder = obj.OrderBy(a => a.Disable).ToList();
                    }
                    else
                    {
                        ObjOrder = obj.OrderByDescending(a => a.Disable).ToList();
                    }
                    break;
                case "ID":
                    if (IsDesc == "False")
                    {
                        ObjOrder = obj.OrderBy(a => a.ID).ToList();
                    }
                    else
                    {
                        ObjOrder = obj.OrderByDescending(a => a.ID).ToList();
                    }
                    break;
                case "IDAlbum":
                    if (IsDesc == "False")
                    {
                        ObjOrder = obj.OrderBy(a => a.IDAlbum).ToList();
                    }
                    else
                    {
                        ObjOrder = obj.OrderByDescending(a => a.IDAlbum).ToList();
                    }
                    break;
                case "IDLang":
                    if (IsDesc == "False")
                    {
                        ObjOrder = obj.OrderBy(a => a.IDLang).ToList();
                    }
                    else
                    {
                        ObjOrder = obj.OrderByDescending(a => a.IDLang).ToList();
                    }
                    break;

                case "Status":
                    if (IsDesc == "False")
                    {
                        ObjOrder = obj.OrderBy(a => a.Status).ToList();
                    }
                    else
                    {
                        ObjOrder = obj.OrderByDescending(a => a.Status).ToList();
                    }
                    break;
                case "Tag":
                    if (IsDesc == "False")
                    {
                        ObjOrder = obj.OrderBy(a => a.Tag).ToList();
                    }
                    else
                    {
                        ObjOrder = obj.OrderByDescending(a => a.Tag).ToList();
                    }
                    break;
                case "Type":
                    if (IsDesc == "False")
                    {
                        ObjOrder = obj.OrderBy(a => a.Type).ToList();
                    }
                    else
                    {
                        ObjOrder = obj.OrderByDescending(a => a.Type).ToList();
                    }
                    break;
                case "ViewCount":
                    if (IsDesc == "False")
                    {
                        ObjOrder = obj.OrderBy(a => a.ViewCount).ToList();
                    }
                    else
                    {
                        ObjOrder = obj.OrderByDescending(a => a.ViewCount).ToList();
                    }
                    break;

                default:
                    ObjOrder = obj;
                    break;
            }

            for (int i = 0; i < ObjOrder.Count; i++)
            {
                if ((TitleLenght > -1) & (ObjOrder[i].CategoryNameLevel2.Length > TitleLenght))
                {
                    ObjOrder[i].CategoryNameLevel2 = ObjOrder[i].CategoryNameLevel2.Substring(0, TitleLenght - 1);
                }
                if ((IntroLenght > -1) & (ObjOrder[i].Info.Length > IntroLenght))
                {
                    ObjOrder[i].Info = ObjOrder[i].Info.Substring(0, IntroLenght - 1);
                }
            }
            List<vw_CategoryLevel2ViewAll> ObjOrderLimit = new List<vw_CategoryLevel2ViewAll>();
            if ((Limit > -1) & (ObjOrder.Count > Limit))
            {
                ObjOrderLimit = ObjOrder.GetRange(0, Limit).ToList();
                _converter.DateTimeFormat = "dd/MM/yyyy";
                jSonString = JsonConvert.SerializeObject(ObjOrderLimit, _converter);
            }
            else
            {
                if (ObjOrder != null)
                {
                    _converter.DateTimeFormat = "dd/MM/yyyy";
                    jSonString = JsonConvert.SerializeObject(ObjOrder, _converter);
                }
            }
            jSonString = "{\"CategoryLevel2\":" + jSonString + "}";
            context.Response.Write(jSonString);
        }
        public void Sel_ListCategoryLevel2_ByType_ByIDLang(HttpContext context)
        {
            String jSonString = "";

            int Type = context.Request.QueryString["Type"] != null && context.Request.QueryString["Type"] != "undefined" ? int.Parse(context.Request.QueryString["Type"]) : -1;
            int IDLang = string.IsNullOrEmpty(context.Request.QueryString["IDLang"]) == false && context.Request.QueryString["IDLang"] != "undefined" ? int.Parse(context.Request.QueryString["IDLang"]) : 1;
            int IntroLenght = context.Request.QueryString["IntroLenght"] != null && context.Request.QueryString["IntroLenght"] != "undefined" ? int.Parse(context.Request.QueryString["IntroLenght"]) : -1;
            int TitleLenght = context.Request.QueryString["TitleLenght"] != null && context.Request.QueryString["TitleLenght"] != "undefined" ? int.Parse(context.Request.QueryString["TitleLenght"]) : -1;
            int Limit = context.Request.QueryString["Limit"] != null && context.Request.QueryString["Limit"] != "undefined" ? int.Parse(context.Request.QueryString["Limit"]) : -1;
            string Order = context.Request.QueryString["Order"] != null && context.Request.QueryString["Order"] != "undefined" ? context.Request.QueryString["Order"] : "-1";
            string IsDesc = context.Request.QueryString["IsDesc"] != null && context.Request.QueryString["IsDesc"] != "undefined" ? context.Request.QueryString["IsDesc"] : "-1";

            CategoryLevel2BO aCategoryLevel2BO = new CategoryLevel2BO();
            List<CategoryLevel2> obj = aCategoryLevel2BO.Sel_ByType_ByIDLang(Type, IDLang);
            List<CategoryLevel2> ObjOrder = new List<CategoryLevel2>();

            switch (Order)
            {
                case "Code":
                    if (IsDesc == "False")
                    {
                        ObjOrder = obj.OrderBy(a => a.Code).ToList();
                    }
                    else
                    {
                        ObjOrder = obj.OrderByDescending(a => a.Code).ToList();
                    }
                    break;
                case "CategoryNameLevel2":
                    if (IsDesc == "False")
                    {
                        ObjOrder = obj.OrderBy(a => a.CategoryNameLevel2).ToList();
                    }
                    else
                    {
                        ObjOrder = obj.OrderByDescending(a => a.CategoryNameLevel2).ToList();
                    }
                    break;

                case "ViewCount":
                    if (IsDesc == "False")
                    {
                        ObjOrder = obj.OrderBy(a => a.ViewCount).ToList();
                    }
                    else
                    {
                        ObjOrder = obj.OrderByDescending(a => a.ViewCount).ToList();
                    }
                    break;

                default:
                    ObjOrder = obj;
                    break;
            }
            for (int i = 0; i < ObjOrder.Count; i++)
            {
                if ((TitleLenght > -1) & (ObjOrder[i].CategoryNameLevel2.Length > TitleLenght))
                {
                    ObjOrder[i].CategoryNameLevel2 = ObjOrder[i].CategoryNameLevel2.Substring(0, TitleLenght - 1);
                }

            }
            List<CategoryLevel2> ObjOrderLimit = new List<CategoryLevel2>();
            if ((Limit > -1) & (ObjOrder.Count > Limit))
            {
                ObjOrderLimit = ObjOrder.GetRange(0, Limit).ToList();
                _converter.DateTimeFormat = "dd/MM/yyyy";
                jSonString = JsonConvert.SerializeObject(ObjOrderLimit, _converter);
            }
            else
            {
                if (ObjOrder != null)
                {
                    _converter.DateTimeFormat = "dd/MM/yyyy";
                    jSonString = JsonConvert.SerializeObject(ObjOrder, _converter);
                }
            }
            jSonString = "{\"CategoryLevel2\":" + jSonString + "}";
            context.Response.Write(jSonString);
        }
        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;
            //=========================
        }
        // Load ra danh sách các contact bằng IDLang
        public void Sel_Ext_ByCode(HttpContext context)
        {
            String jSonString = "";

            string Code = context.Request.QueryString["Code"] != null && context.Request.QueryString["Code"] != "undefined" ? context.Request.QueryString["Code"] : "";
            int IDLang = context.Request.QueryString["IDLang"] != null && context.Request.QueryString["IDLang"] != "undefined" ? int.Parse(context.Request.QueryString["IDLang"]) : 1;

            bool Disable = !String.IsNullOrEmpty(context.Request.QueryString["Disable"]) ? Convert.ToBoolean(context.Request.QueryString["Disable"]) : false;

            int IntroLenght = context.Request.QueryString["IntroLenght"] != null && context.Request.QueryString["IntroLenght"] != "undefined" ? int.Parse(context.Request.QueryString["IntroLenght"]) : -1;
            int TitleLenght = context.Request.QueryString["TitleLenght"] != null && context.Request.QueryString["TitleLenght"] != "undefined" ? int.Parse(context.Request.QueryString["TitleLenght"]) : -1;
            int Limit = context.Request.QueryString["Limit"] != null && context.Request.QueryString["Limit"] != "undefined" ? int.Parse(context.Request.QueryString["Limit"]) : 50;
            string Order = context.Request.QueryString["Order"] != null && context.Request.QueryString["Order"] != "undefined" ? context.Request.QueryString["Order"] : "CategoryLevel1_ID";
            bool IsDesc = context.Request.QueryString["IsDesc"] != null && context.Request.QueryString["IsDesc"] != "undefined" ? bool.Parse(context.Request.QueryString["IsDesc"]) : true;

            CategoryLevel1BO aCategoryLevel1BO = new CategoryLevel1BO();
            List<vw_CategoryLevel1ViewAll> obj = String.IsNullOrEmpty(context.Request.QueryString["Disable"]) ?
                aCategoryLevel1BO.Sel_Ext_ByCode(Code) : aCategoryLevel1BO.Sel_Ext_ByCode(Code, Disable);
            List<vw_CategoryLevel1ViewAll> ObjOrder = new List<vw_CategoryLevel1ViewAll>();

            switch (Order)
            {
                case "CategoryLevel1_Code":
                    if (IsDesc == false)
                    {
                        ObjOrder = obj.OrderBy(a => a.CategoryLevel1_Code).ToList();
                    }
                    else
                    {
                        ObjOrder = obj.OrderByDescending(a => a.CategoryLevel1_Code).ToList();
                    }
                    break;

                case "CategoryLevel2_Code":
                    if (IsDesc ==false)
                    {
                        ObjOrder = obj.OrderBy(a => a.CategoryLevel2_Code).ToList();
                    }
                    else
                    {
                        ObjOrder = obj.OrderByDescending(a => a.CategoryLevel2_Code).ToList();
                    }
                    break;

                case "CountContentDisable":
                    if (IsDesc ==false)
                    {
                        ObjOrder = obj.OrderBy(a => a.CountContentDisable).ToList();
                    }
                    else
                    {
                        ObjOrder = obj.OrderByDescending(a => a.CountContentDisable).ToList();
                    }
                    break;
                case "CountContentEnable":
                    if (IsDesc == false)
                    {
                        ObjOrder = obj.OrderBy(a => a.CountContentEnable).ToList();
                    }
                    else
                    {
                        ObjOrder = obj.OrderByDescending(a => a.CountContentEnable).ToList();
                    }
                    break;
                case "CountContent":
                    if (IsDesc == false)
                    {
                        ObjOrder = obj.OrderBy(a => a.CountContent).ToList();
                    }
                    else
                    {
                        ObjOrder = obj.OrderByDescending(a => a.CountContent).ToList();
                    }
                    break;
                case "CategoryLevel2_Status":
                    if (IsDesc == false)
                    {
                        ObjOrder = obj.OrderBy(a => a.CategoryLevel2_Status).ToList();
                    }
                    else
                    {
                        ObjOrder = obj.OrderByDescending(a => a.CategoryLevel2_Status).ToList();
                    }
                    break;
                case "CategoryLevel2_ID":
                    if (IsDesc == false)
                    {
                        ObjOrder = obj.OrderBy(a => a.CategoryLevel2_ID).ToList();
                    }
                    else
                    {
                        ObjOrder = obj.OrderByDescending(a => a.CategoryLevel2_ID).ToList();
                    }
                    break;
                case "CategoryLevel1_ViewCount":
                    if (IsDesc == false)
                    {
                        ObjOrder = obj.OrderBy(a => a.CategoryLevel1_ViewCount).ToList();
                    }
                    else
                    {
                        ObjOrder = obj.OrderByDescending(a => a.CategoryLevel1_ViewCount).ToList();
                    }
                    break;
                case "CategoryLevel1_Type":
                    if (IsDesc == false)
                    {
                        ObjOrder = obj.OrderBy(a => a.CategoryLevel1_Type).ToList();
                    }
                    else
                    {
                        ObjOrder = obj.OrderByDescending(a => a.CategoryLevel1_Type).ToList();
                    }
                    break;
                case "CategoryLevel1_Status":
                    if (IsDesc == false)
                    {
                        ObjOrder = obj.OrderBy(a => a.CategoryLevel1_Status).ToList();
                    }
                    else
                    {
                        ObjOrder = obj.OrderByDescending(a => a.CategoryLevel1_Status).ToList();
                    }
                    break;
                case "CategoryLevel1_ID":
                    if (IsDesc == false)
                    {
                        ObjOrder = obj.OrderBy(a => a.CategoryLevel1_ID).ToList();
                    }
                    else
                    {
                        ObjOrder = obj.OrderByDescending(a => a.CategoryLevel1_ID).ToList();
                    }
                    break;
                case "CategoryLevel1_CategoryLevel2_Disable":
                    if (IsDesc == false)
                    {
                        ObjOrder = obj.OrderBy(a => a.CategoryLevel1_CategoryLevel2_Disable).ToList();
                    }
                    else
                    {
                        ObjOrder = obj.OrderByDescending(a => a.CategoryLevel1_CategoryLevel2_Disable).ToList();
                    }
                    break;
                default:
                    ObjOrder = obj;
                    break;
            }

            for (int i = 0; i < ObjOrder.Count; i++)
            {
                if ((TitleLenght > -1) & (ObjOrder[i].CategoryLevel1_CategoryNameLevel1.Length > TitleLenght))
                {
                    ObjOrder[i].CategoryLevel1_CategoryNameLevel1 = ObjOrder[i].CategoryLevel1_CategoryNameLevel1.Substring(0, TitleLenght - 1);
                }
                if ((IntroLenght > -1) & (ObjOrder[i].CategoryLevel1_Info.Length > IntroLenght))
                {
                    ObjOrder[i].CategoryLevel1_Info = ObjOrder[i].CategoryLevel1_Info.Substring(0, IntroLenght - 1);
                }
            }
            List<vw_CategoryLevel1ViewAll> ObjOrderLimit = new List<vw_CategoryLevel1ViewAll>();
            if ((Limit > -1) & (ObjOrder.Count > Limit))
            {
                ObjOrderLimit = ObjOrder.GetRange(0, Limit).ToList();
                _converter.DateTimeFormat = "dd/MM/yyyy";
                jSonString = JsonConvert.SerializeObject(ObjOrderLimit, _converter);
            }
            else
            {
                if (ObjOrder != null)
                {
                    _converter.DateTimeFormat = "dd/MM/yyyy";
                    jSonString = JsonConvert.SerializeObject(ObjOrder, _converter);
                }
            }
            jSonString = "{\"CategoryLevel1\":" + jSonString + "}";
            context.Response.Write(jSonString);
        }
        // Load ra danh sách các CategoryLevel1 bằng CodeCategpryLevel2 va IDLang
        public void Sel_Ext_ByCodeCategoryLevel2_ByIDLang(HttpContext context)
        {
            String jSonString = "";
            bool Disable = !String.IsNullOrEmpty(context.Request.QueryString["Disable"])
               ? Convert.ToBoolean(context.Request.QueryString["Disable"])
               : false;
            string CodeCategoryLevel2 = context.Request.QueryString["CodeCategoryLevel2"] != null && context.Request.QueryString["CodeCategoryLevel2"] != "undefined" ? context.Request.QueryString["CodeCategoryLevel2"] : "-1";
            int TitleLenght = context.Request.QueryString["TitleLenght"] != null && context.Request.QueryString["TitleLenght"] != "undefined" ? int.Parse(context.Request.QueryString["TitleLenght"]) : 100;
            int Limit = context.Request.QueryString["Limit"] != null && context.Request.QueryString["Limit"] != "undefined" ? int.Parse(context.Request.QueryString["Limit"]) : 100;
            string Order = context.Request.QueryString["Order"] != null && context.Request.QueryString["Order"] != "undefined" ? context.Request.QueryString["Order"] : "CategoryLevel1_CategoryNameLevel1";
            string IsDesc = context.Request.QueryString["IsDesc"] != null && context.Request.QueryString["IsDesc"] != "undefined" ? context.Request.QueryString["IsDesc"] : "true";

            int IDLang = !string.IsNullOrEmpty(context.Request.QueryString["IDLang"]) ? int.Parse(context.Request.QueryString["IDLang"]) : 1;

            CategoryLevel1BO aCategoryLevel1BO = new CategoryLevel1BO();
            List<vw_CategoryLevel1ViewAll> obj = String.IsNullOrEmpty(context.Request.QueryString["Disable"]) ?
                aCategoryLevel1BO.Sel_Ext_ByCodeCategoryLevel2_ByIDLang(CodeCategoryLevel2, IDLang).ToList() :
                aCategoryLevel1BO.Sel_Ext_ByCodeCategoryLevel2_ByIDLang(CodeCategoryLevel2, IDLang, Disable).ToList();
            List<vw_CategoryLevel1ViewAll> ObjOrder = new List<vw_CategoryLevel1ViewAll>();

            switch (Order)
            {
                case "CategoryLevel1_CategoryNameLevel1":
                    if (IsDesc == "False")
                    {
                        ObjOrder = obj.OrderBy(a => a.CategoryLevel1_CategoryNameLevel1).ToList();
                    }
                    else
                    {
                        ObjOrder = obj.OrderByDescending(a => a.CategoryLevel1_CategoryNameLevel1).ToList();
                    }
                    break;
                case "CategoryLevel2_CategoryNameLevel2":
                    if (IsDesc == "False")
                    {
                        ObjOrder = obj.OrderBy(a => a.CategoryLevel2_CategoryNameLevel2).ToList();
                    }
                    else
                    {
                        ObjOrder = obj.OrderByDescending(a => a.CategoryLevel2_CategoryNameLevel2).ToList();
                    }
                    break;
                case "CategoryLevel1_ID":
                    if (IsDesc == "False")
                    {
                        ObjOrder = obj.OrderBy(a => a.CategoryLevel1_ID).ToList();
                    }
                    else
                    {
                        ObjOrder = obj.OrderByDescending(a => a.CategoryLevel1_ID).ToList();
                    }
                    break;
                default:
                    ObjOrder = obj;
                    break;
            }

            for (int i = 0; i < ObjOrder.Count; i++)
            {
                if ((TitleLenght > -1) & (ObjOrder[i].CategoryLevel1_CategoryNameLevel1.Length > TitleLenght))
                {
                    ObjOrder[i].CategoryLevel1_CategoryNameLevel1 = ObjOrder[i].CategoryLevel1_CategoryNameLevel1.Substring(0, TitleLenght - 1);
                }
            }
            List<vw_CategoryLevel1ViewAll> ObjOrderLimit = new List<vw_CategoryLevel1ViewAll>();
            if ((Limit > -1) & (ObjOrder.Count > Limit))
            {
                ObjOrderLimit = ObjOrder.GetRange(0, Limit).ToList();

                _converter.DateTimeFormat = "dd/MM/yyyy";
                jSonString = JsonConvert.SerializeObject(ObjOrderLimit, _converter);
            }
            else
            {
                if (ObjOrder != null)
                {
                    _converter.DateTimeFormat = "dd/MM/yyyy";
                    jSonString = JsonConvert.SerializeObject(ObjOrder, _converter);
                }
            }
            jSonString = "{\"data\":" + jSonString + "}";
            context.Response.Write(jSonString);
        }
        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<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;
            //=========================
        }