示例#1
0
        public ActionResult Print()
        {
            var rawClasses  = Request["Classes"];
            var rawShicvas  = Request["Shicvas"];
            var rawLines    = Request["Lines"];
            var rawStations = Request["Stations"];
            var req         = new StudentSearchRequest
            {
                PageSize                = Int32.MaxValue,
                PageNumber              = 1,
                SortColumn              = Request["SortColumn"],
                SortOrder               = Request["SortOrder"],
                StudentId               = Request["Id"].Trim(),
                Name                    = Request["Name"].Trim(),
                Class                   = rawClasses.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries),
                Shicva                  = rawShicvas.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries),
                LineIds                 = rawLines.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray(),
                StationIds              = rawStations.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray(),
                City                    = Request["City"].Trim().ToLower(),
                Street                  = Request["Street"].Trim().ToLower(),
                House                   = Request["House"].Trim().ToLower(),
                Active                  = int.Parse(Request["Active"]),
                PayStatus               = int.Parse(Request["PayStatus"]),
                Subcidy                 = int.Parse(Request["Subcidy"]),
                SibilingAtSchool        = int.Parse(Request["Sibiling"]),
                SpecialRequest          = int.Parse(Request["Request"]),
                DistanceFromSchoolFrom  = int.Parse(Request["DFSFrom"]) * 1000,
                DistanceFromSchoolTo    = int.Parse(Request["DFSTo"]) * 1000,
                DistanceFromStationFrom = int.Parse(Request["DFStFrom"]),
                DistanceFromStationTo   = int.Parse(Request["DFStTo"]),
                Direction               = int.Parse(Request["Direction"])
            };

            using (var logic = new tblStudentLogic())
            {
                var ttl = 0;
                ViewBag.List = logic.GetStudentsForTable(req, out ttl);
            }
            return(View());
        }
示例#2
0
        public JsonResult StudentsForTable(GridSettings grid)
        {
            var rawClasses  = Request["Classes"];
            var rawShicvas  = Request["Shicvas"];
            var rawLines    = Request["Lines"];
            var rawStations = Request["Stations"];
            var req         = new StudentSearchRequest
            {
                SortColumn              = grid.SortColumn,
                SortOrder               = grid.SortOrder,
                PageNumber              = grid.PageIndex,
                PageSize                = grid.PageSize,
                StudentId               = Request["Id"].Trim(),
                Name                    = Request["Name"].Trim(),
                Class                   = rawClasses.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries),
                Shicva                  = rawShicvas.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries),
                LineIds                 = rawLines.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray(),
                StationIds              = rawStations.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray(),
                City                    = Request["City"].Trim().ToLower(),
                Street                  = Request["Street"].Trim().ToLower(),
                House                   = Request["House"].Trim().ToLower(),
                Active                  = int.Parse(Request["Active"]),
                registrationStatus      = int.Parse(Request["registrationStatus"]),
                PayStatus               = int.Parse(Request["PayStatus"]),
                Subcidy                 = int.Parse(Request["Subcidy"]),
                SibilingAtSchool        = int.Parse(Request["Sibiling"]),
                SpecialRequest          = int.Parse(Request["Request"]),
                DistanceFromSchoolFrom  = int.Parse(Request["DFSFrom"]) * 1000,
                DistanceFromSchoolTo    = int.Parse(Request["DFSTo"]) * 1000,
                DistanceFromStationFrom = int.Parse(Request["DFStFrom"]),
                DistanceFromStationTo   = int.Parse(Request["DFStTo"]),
                Direction               = int.Parse(Request["Direction"])
            };
            var total    = 0;
            var logic    = new tblStudentLogic();
            var lst      = logic.GetStudentsForTable(req, out total);
            var jsonData = new
            {
                total   = (int)Math.Ceiling((double)total / grid.PageSize),
                page    = grid.PageIndex,
                records = total,
                rows    = (from stud in lst
                           select
                           new
                {
                    id = stud.Id,
                    cell = new string[] {
                        stud.StudentId,
                        stud.FirstName,
                        stud.LastName,
                        stud.Class,
                        stud.Shicva,
                        stud.Address,
                        stud.registrationStatus.HasValue?stud.registrationStatus.ToString():"null",
                        stud.PayStatus.HasValue?stud.PayStatus.ToString():"null",
                        stud.Active.HasValue?stud.Active.ToString():"null",
                        stud.SibilingAtSchool.HasValue?stud.SibilingAtSchool.ToString():"null",
                        stud.SpecialRequest.ToString(),
                        stud.DistanceToSchool.ToString(),
                        stud.LineName
                    }
                })
            };
            var r = new JsonResult {
                Data = jsonData
            };

            return(r);
        }
示例#3
0
        public FileContentResult GetExcel()
        {
            Response.Cookies.Add(new HttpCookie("fileDownload", "true"));

            var rawClasses  = Request["Classes"];
            var rawShicvas  = Request["Shicvas"];
            var rawLines    = Request["Lines"];
            var rawStations = Request["Stations"];
            var req         = new StudentSearchRequest
            {
                PageSize                = Int32.MaxValue,
                PageNumber              = 1,
                SortColumn              = Request["SortColumn"],
                SortOrder               = Request["SortOrder"],
                StudentId               = Request["Id"].Trim(),
                Name                    = Request["Name"].Trim(),
                Class                   = rawClasses.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries),
                Shicva                  = rawShicvas.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries),
                LineIds                 = rawLines.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray(),
                StationIds              = rawStations.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray(),
                City                    = Request["City"].Trim().ToLower(),
                Street                  = Request["Street"].Trim().ToLower(),
                House                   = Request["House"].Trim().ToLower(),
                Active                  = int.Parse(Request["Active"]),
                PayStatus               = int.Parse(Request["PayStatus"]),
                Subcidy                 = int.Parse(Request["Subcidy"]),
                SibilingAtSchool        = int.Parse(Request["Sibiling"]),
                SpecialRequest          = int.Parse(Request["Request"]),
                DistanceFromSchoolFrom  = int.Parse(Request["DFSFrom"]) * 1000,
                DistanceFromSchoolTo    = int.Parse(Request["DFSTo"]) * 1000,
                DistanceFromStationFrom = int.Parse(Request["DFStFrom"]),
                DistanceFromStationTo   = int.Parse(Request["DFStTo"]),
                Direction               = int.Parse(Request["Direction"])
            };
            int ttl = 0;
            List <StudentFullInfo> lst = null;

            using (var logic = new tblStudentLogic())
            {
                lst = logic.GetStudentsForTable(req, out ttl);
            }
            var workbook  = new XLWorkbook();
            var worksheet = workbook.Worksheets.Add("Students");

            worksheet.Cell("A1").Value = "Id";
            worksheet.Cell("B1").Value = "First Name";
            worksheet.Cell("C1").Value = "Last Name";
            worksheet.Cell("D1").Value = "Class";
            worksheet.Cell("E1").Value = "Shicva";
            worksheet.Cell("F1").Value = "Address";
            worksheet.Cell("G1").Value = "Payment";
            worksheet.Cell("H1").Value = "Active";
            worksheet.Cell("I1").Value = "Sibiling";
            worksheet.Cell("J1").Value = "Special request";
            worksheet.Cell("K1").Value = "Distance to School";
            worksheet.Cell("L1").Value = "Line & station";
            worksheet.Cell("M1").Value = "Email";
            worksheet.Cell("N1").Value = "Phone";
            worksheet.Cell("O1").Value = "Subsidy";
            worksheet.Cell("P1").Value = "Year Registration";
            worksheet.Cell("Q1").Value = "School";

            worksheet.Cell("A1").Style.Font.Bold            = true;
            worksheet.Cell("A1").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
            worksheet.Column("A").Width                     = 6;
            worksheet.Cell("B1").Style.Font.Bold            = true;
            worksheet.Cell("B1").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
            worksheet.Column("B").Width                     = 12;
            worksheet.Cell("C1").Style.Font.Bold            = true;
            worksheet.Cell("C1").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
            worksheet.Column("C").Width                     = 12;
            worksheet.Cell("D1").Style.Font.Bold            = true;
            worksheet.Cell("D1").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
            worksheet.Column("D").Width                     = 8;
            worksheet.Cell("E1").Style.Font.Bold            = true;
            worksheet.Cell("E1").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
            worksheet.Column("E").Width                     = 8;
            worksheet.Cell("F1").Style.Font.Bold            = true;
            worksheet.Cell("F1").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
            worksheet.Column("F").Width                     = 20;
            worksheet.Cell("G1").Style.Font.Bold            = true;
            worksheet.Cell("G1").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
            worksheet.Column("G").Width                     = 8;
            worksheet.Cell("H1").Style.Font.Bold            = true;
            worksheet.Cell("H1").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
            worksheet.Column("H").Width                     = 8;
            worksheet.Cell("I1").Style.Font.Bold            = true;
            worksheet.Cell("I1").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
            worksheet.Column("I").Width                     = 8;
            worksheet.Cell("J1").Style.Font.Bold            = true;
            worksheet.Cell("J1").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
            worksheet.Column("J").Width                     = 14;
            worksheet.Cell("K1").Style.Font.Bold            = true;
            worksheet.Cell("K1").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
            worksheet.Column("K").Width                     = 16;
            worksheet.Cell("L1").Style.Font.Bold            = true;
            worksheet.Cell("L1").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
            worksheet.Column("L").Width                     = 20;

            var row = 2;

            foreach (var stud in lst)
            {
                worksheet.Cell(row, "A").Value = stud.StudentId;
                worksheet.Cell(row, "B").Value = stud.FirstName;
                worksheet.Cell(row, "C").Value = stud.LastName;
                worksheet.Cell(row, "D").Value = stud.Class;
                worksheet.Cell(row, "E").Value = stud.Shicva;
                worksheet.Cell(row, "F").Value = stud.Address;
                worksheet.Cell(row, "G").Value = stud.PayStatus == true ? "Yes" : "No";
                worksheet.Cell(row, "H").Value = stud.Active == true ? "Yes" : "No";
                worksheet.Cell(row, "I").Value = stud.SibilingAtSchool == true ? "Yes" : "No";
                worksheet.Cell(row, "J").Value = stud.SpecialRequest == true ? "Yes" : "No";
                worksheet.Cell(row, "K").Value = stud.DistanceToSchool + " m.";
                worksheet.Cell(row, "L").Value = stud.LineName;

                row++;
            }

            var ms = new MemoryStream();

            workbook.SaveAs(ms);
            ms.Position = 0;
            var sr = new BinaryReader(ms);

            return(File(sr.ReadBytes((int)ms.Length), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "Students.xlsx"));;
        }