Ejemplo n.º 1
0
    public static TRetunrLoadData LoadData(CSearch itemSearch)
    {
        TRetunrLoadData   result = new TRetunrLoadData();
        PTTGC_EPIEntities db     = new PTTGC_EPIEntities();

        var      lstHistory  = db.TViewMenu_History.ToList();
        DateTime dStartValue = DateTime.ParseExact(itemSearch.sStartDate, "dd/MM/yyyy", new CultureInfo("en-US"));
        DateTime dEndValue   = DateTime.ParseExact(itemSearch.sEndDate, "dd/MM/yyyy", new CultureInfo("en-US"));
        var      lstMenu     = db.TMenu.Where(w => w.cActive == "Y").ToList();
        var      lstUser     = db.mTUser.ToList();

        sslstData  = new List <TDataTable>();
        lstHistory = lstHistory.Where(w => (w.dAction.Value.Date >= dStartValue.Date && w.dAction.Value.Date <= dEndValue)).ToList();
        var lstData = (from a in lstHistory
                       from b in lstMenu.Where(w => w.nMenuID == a.nMenuID)
                       from c in lstUser.Where(w => w.ID == a.nUserID)
                       select new TDataTable
        {
            nLogID = a.nLogID,
            nMenuID = a.nMenuID,
            nUserID = a.nUserID,
            dActionDate = a.dAction,
            Firstname = c.Firstname,
            Username = c.Username,
            Lastname = c.Lastname,
            sMenu = b.sMenuName,
            nLevel = b.nLevel,
            nHead = b.sMenuHeadID
        }).ToList();

        lstData.ForEach(f =>
        {
            f.sAction = SystemFunction.CovertDateEn2Th(f.dActionDate.Value + "", "EN4");
            if (f.nLevel == 2)
            {
                var mu = lstMenu.FirstOrDefault(w => w.nMenuID == f.nHead);
                if (mu != null)
                {
                    f.sMenu = mu.sMenuName;
                    var mu2 = lstMenu.FirstOrDefault(w => w.nMenuID == mu.sMenuHeadID);
                    if (mu != null)
                    {
                        f.sMenuHead = mu2.sMenuName;
                    }
                }
            }
            else if (f.nLevel == 1)
            {
                var mu = lstMenu.FirstOrDefault(w => w.nMenuID == f.nHead);
                if (mu != null)
                {
                    f.sMenuHead = mu.sMenuName;
                }
            }
            else
            {
                f.sMenuHead = f.sMenu;
                f.sMenu     = "";
            }
        });
        #region//SORT
        int?nSortCol = SystemFunction.GetIntNull(itemSearch.sIndexCol);
        switch ((itemSearch.sOrderBy + "").ToLower())
        {
        case SystemFunction.ASC:
        {
            switch (nSortCol)
            {
            case 1: lstData = lstData.OrderBy(o => o.Username).ToList(); break;

            case 2: lstData = lstData.OrderBy(o => o.Firstname).ToList(); break;

            case 3: lstData = lstData.OrderBy(o => o.sMenuHead).ToList(); break;

            case 4: lstData = lstData.OrderBy(o => o.sMenu).ToList(); break;

            case 5: lstData = lstData.OrderBy(o => o.dActionDate).ToList(); break;
            }
        }
        break;

        case SystemFunction.DESC:
        {
            switch (nSortCol)
            {
            case 1: lstData = lstData.OrderByDescending(o => o.Username).ToList(); break;

            case 2: lstData = lstData.OrderByDescending(o => o.Firstname).ToList(); break;

            case 3: lstData = lstData.OrderByDescending(o => o.sMenuHead).ToList(); break;

            case 4: lstData = lstData.OrderByDescending(o => o.sMenu).ToList(); break;

            case 5: lstData = lstData.OrderByDescending(o => o.dActionDate).ToList(); break;
            }
        }
        break;
        }
        #endregion
        sslstData = lstData;
        #region//Final Action >> Skip Take Data For Javasacript
        sysGlobalClass.Pagination dataPage = new sysGlobalClass.Pagination();
        dataPage = SystemFunction.GetPaginationSmall(SystemFunction.GetIntNullToZero(itemSearch.sPageSize), SystemFunction.GetIntNullToZero(itemSearch.sPageIndex), lstData.Count);
        lstData  = lstData.Skip(dataPage.nSkipData).Take(dataPage.nTakeData).ToList();

        result.lstData           = lstData;
        result.nPageCount        = dataPage.nPageCount;
        result.nPageIndex        = dataPage.nPageIndex;
        result.sPageInfo         = dataPage.sPageInfo;
        result.sContentPageIndex = dataPage.sContentPageIndex;
        result.nStartItemIndex   = dataPage.nStartItemIndex;
        #endregion

        return(result);
    }