Пример #1
0
        /// <summary>
        /// Gets the list of data for use by the jqgrid plug-in
        /// </summary>
        public IActionResult OnGetGridData(string sidx, string sord, int _page, int rows, bool isforJqGrid = true)
        {
            int totalRecords  = CourseEnrollment.GetRecordCount();
            int startRowIndex = ((_page * rows) - rows);
            List <CourseEnrollment> objCourseEnrollmentCol = CourseEnrollment.SelectSkipAndTake(rows, startRowIndex, sidx + " " + sord);
            int totalPages = (int)Math.Ceiling((float)totalRecords / (float)rows);

            if (objCourseEnrollmentCol is null)
            {
                return(new JsonResult("{ total = 0, page = 0, records = 0, rows = null }"));
            }

            var jsonData = new
            {
                total = totalPages,
                _page,
                records = totalRecords,
                rows    = (
                    from objCourseEnrollment in objCourseEnrollmentCol
                    select new
                {
                    id = objCourseEnrollment.EnrollmentId,
                    cell = new string[] {
                        objCourseEnrollment.EnrollmentId.ToString(),
                        objCourseEnrollment.CourseName.ToString(),
                        objCourseEnrollment.StudentName.ToString(),
                        objCourseEnrollment.Comments
                    }
                }).ToArray()
            };

            return(new JsonResult(jsonData));
        }
        public void GetData(string sidx, string sord, int?_page)
        {
            int rows = Functions.GetGridNumberOfRows();
            int numberOfPagesToShow = Functions.GetGridNumberOfPagesToShow();
            int currentPage         = _page is null ? 1 : Convert.ToInt32(_page);
            int startRowIndex       = ((currentPage * rows) - rows);
            int totalRecords        = CourseEnrollment.GetRecordCount();
            int totalPages          = (int)Math.Ceiling((float)totalRecords / (float)rows);
            List <CourseEnrollment> objCourseEnrollmentCol = CourseEnrollment.SelectSkipAndTake(rows, startRowIndex, sidx + " " + sord);

            // fields and titles
            string[,] fieldNames = new string[, ] {
                { "EnrollmentId", "Enrollment Id" },
                { "CourseName", "Course Name" },
                { "StudentName", "Student Name" },
                { "Comments", "Comments" }
            };

            // assign properties
            CourseEnrollmentData       = objCourseEnrollmentCol;
            CourseEnrollmentFieldNames = fieldNames;
            TotalPages           = totalPages;
            CurrentPage          = currentPage;
            FieldToSort          = String.IsNullOrEmpty(sidx) ? "EnrollmentId" : sidx;
            FieldSortOrder       = String.IsNullOrEmpty(sord) ? "asc" : sord;
            FieldToSortWithOrder = String.IsNullOrEmpty(sidx) ? "EnrollmentId" : (sidx + " " + sord).Trim();
            NumberOfPagesToShow  = numberOfPagesToShow;
            StartPage            = Functions.GetPagerStartPage(currentPage, numberOfPagesToShow, totalPages);
            EndPage = Functions.GetPagerEndPage(StartPage, currentPage, numberOfPagesToShow, totalPages);
        }
        /// <summary>
        /// Gets the list of data for use by the jqgrid plug-in
        /// </summary>
        public IActionResult OnGetGridDataGroupedByCourseName(string sidx, string sord, int _page, int rows)
        {
            // using a groupField in the jqgrid passes that field
            // along with the field to sort, remove the groupField
            string groupBy = "CourseName asc, ";

            sidx = sidx.Replace(groupBy, "");

            int totalRecords  = CourseEnrollment.GetRecordCount();
            int startRowIndex = ((_page * rows) - rows);

            List <CourseEnrollment> objCourseEnrollmentCol = CourseEnrollment.SelectSkipAndTake(rows, startRowIndex, sidx + " " + sord);
            int totalPages = (int)Math.Ceiling((float)totalRecords / (float)rows);

            if (objCourseEnrollmentCol is null)
            {
                return(new JsonResult("{ total = 0, page = 0, records = 0, rows = null }"));
            }

            var jsonData = new
            {
                total = totalPages,
                _page,
                records = totalRecords,
                rows    = (
                    from objCourseEnrollment in objCourseEnrollmentCol
                    select new
                {
                    id = objCourseEnrollment.EnrollmentId,
                    cell = new string[] {
                        objCourseEnrollment.EnrollmentId.ToString(),
                        objCourseEnrollment.CourseName.ToString(),
                        objCourseEnrollment.StudentName.ToString(),
                        objCourseEnrollment.Comments,
                        objCourseEnrollment.CourseNameNavigation.CourseName
                    }
                }).ToArray()
            };

            return(new JsonResult(jsonData));
        }
Пример #4
0
 /// <summary>
 /// Shows how to get the total number of records
 /// </summary>
 private void GetRecordCount()
 {
     // get the total number of records in the CourseEnrollment table
     int totalRecordCount = CourseEnrollment.GetRecordCount();
 }