Beispiel #1
0
 public ActionResult Excel(Guid id, string format, bool? titles)
 {
     var ctl = new MailingController {UseTitles = titles ?? false};
     switch (format)
     {
         case "Individual":
         case "GroupAddress":
             return new ExcelResult(ExportPeople.FetchExcelList(id, maxExcelRows));
         case "Library":
             return new ExcelResult(ExportPeople.FetchExcelLibraryList(id));
         case "Family":
             return new ExcelResult(ctl.FetchExcelFamily(id, maxExcelRows));
         case "AllFamily":
             return new ExcelResult(ExportPeople.FetchExcelListFamily(id));
         case "ParentsOf":
             return new ExcelResult(ctl.FetchExcelParents(id, maxExcelRows));
         case "CouplesEither":
             return new ExcelResult(ctl.FetchExcelCouplesEither(id, maxExcelRows));
         case "CouplesBoth":
             return new ExcelResult(ctl.FetchExcelCouplesBoth(id, maxExcelRows));
         case "Involvement":
             return new ExcelResult(ExportInvolvements.InvolvementList(id));
         case "Children":
             return new ExcelResult(ExportInvolvements.ChildrenList(id, maxExcelRows));
         case "Church":
             return new ExcelResult(ExportInvolvements.ChurchList(id, maxExcelRows));
         case "Attend":
             return new ExcelResult(ExportInvolvements.AttendList(id, maxExcelRows));
         case "Organization":
             return new ExcelResult(ExportInvolvements.OrgMemberList(id));
         case "Promotion":
             return new ExcelResult(ExportInvolvements.PromoList(id, maxExcelRows));
         case "IndividualPicture":
             Response.ContentType = "application/vnd.ms-excel";
             Response.AddHeader("content-disposition", "attachment;filename=pictures.xls");
             return View("Picture", ExportPeople.FetchExcelListPics(id, maxExcelRows));
         case "FamilyMembers":
             Response.ContentType = "application/vnd.ms-excel";
             Response.AddHeader("content-disposition", "attachment;filename=familymembers.xls");
             return View("FamilyMembers", ExportPeople.FetchExcelListFamilyMembers(id));
     }
     return Content("no format");
 }
Beispiel #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var labelNameFormat = Request.QueryString["format"];
            int? qid = Request.QueryString["id"].ToInt2();
            var r = Response;
            r.Clear();
            var useweb = Request.QueryString["web"];

            string header =
            @"<html xmlns:x=""urn:schemas-microsoft-com:office:excel"">
            <head>
            <meta http-equiv=Content-Type content=""text/html; charset=utf-8"">
            <style>
            <!--table
            br {mso-data-placement:same-cell;}
            tr {vertical-align:top;}
            td.Text {mso-number-format:\@}
            -->
            </style>
            </head>
            <body>";
            r.Charset = "";

            if (!qid.HasValue && labelNameFormat != "Groups")
            {
                r.Write("no queryid");
                r.Flush();
                r.End();
            }
            if (useweb != "true")
            {
                r.ContentType = "application/vnd.ms-excel";
                r.AddHeader("Content-Disposition", "attachment;filename=CMSPeople.xls");
            }
            r.Write(header);
            var ctl = new MailingController();
            var useTitles = Request.QueryString["titles"];
            ctl.UseTitles = useTitles == "true";
            var dg = new DataGrid();
            dg.EnableViewState = false;
            switch (labelNameFormat)
            {
                case "Individual":
                case "GroupAddress":
                    dg.DataSource = ExportPeople.FetchExcelList(qid.Value, maxExcelRows);
                    dg.DataBind();
                    dg.RenderControl(new HtmlTextWriter(r.Output));
                    break;
                case "IndividualPicture":
                    GridView1.EnableViewState = false;
                    GridView1.AllowPaging = false;
                    GridView1.DataSource = ExportPeople.FetchExcelListPics(qid.Value, maxExcelRows);
                    GridView1.DataBind();
                    GridView1.RenderControl(new HtmlTextWriter(r.Output));
                    break;
                case "Library":
                    dg.DataSource = ExportPeople.FetchExcelLibraryList(qid.Value);
                    dg.DataBind();
                    dg.RenderControl(new HtmlTextWriter(r.Output));
                    break;
                case "Family":
                    dg.DataSource = ctl.FetchExcelFamily(qid.Value, maxExcelRows);
                    dg.DataBind();
                    dg.RenderControl(new HtmlTextWriter(r.Output));
                    break;
                case "FamilyMembers":
                    FamilyMembers.EnableViewState = false;
                    FamilyMembers.AllowPaging = false;
                    FamilyMembers.DataSource = ExportPeople.FetchExcelListFamilyMembers(qid.Value);
                    FamilyMembers.DataBind();
                    FamilyMembers.RenderControl(new HtmlTextWriter(r.Output));
                    break;
                case "AllFamily":
                    dg.DataSource = ExportPeople.FetchExcelListFamily(qid.Value);
                    dg.DataBind();
                    dg.RenderControl(new HtmlTextWriter(r.Output));
                    break;
                case "ParentsOf":
                    dg.DataSource = ctl.FetchExcelParents(qid.Value, maxExcelRows);
                    dg.DataBind();
                    dg.RenderControl(new HtmlTextWriter(r.Output));
                    break;
                case "CouplesEither":
                    dg.DataSource = ctl.FetchExcelCouplesEither(qid.Value, maxExcelRows);
                    dg.DataBind();
                    dg.RenderControl(new HtmlTextWriter(r.Output));
                    break;
                case "CouplesBoth":
                    dg.DataSource = ctl.FetchExcelCouplesBoth(qid.Value, maxExcelRows);
                    dg.DataBind();
                    dg.RenderControl(new HtmlTextWriter(r.Output));
                    break;
                case "Involvement":
                    dg.DataSource = ExportInvolvements.InvolvementList(qid.Value);
                    dg.DataBind();
                    dg.RenderControl(new HtmlTextWriter(r.Output));
                    break;
                case "Children":
                    dg.DataSource = ExportInvolvements.ChildrenList(qid.Value, maxExcelRows);
                    dg.DataBind();
                    dg.RenderControl(new HtmlTextWriter(r.Output));
                    break;
                case "Church":
                    dg.DataSource = ExportInvolvements.ChurchList(qid.Value, maxExcelRows);
                    dg.DataBind();
                    dg.RenderControl(new HtmlTextWriter(r.Output));
                    break;
                case "Attend":
                    dg.DataSource = ExportInvolvements.AttendList(qid.Value, maxExcelRows);
                    dg.DataBind();
                    dg.RenderControl(new HtmlTextWriter(r.Output));
                    break;
                case "Organization":
                    dg.DataSource = ExportInvolvements.OrgMemberList(qid.Value);
                    dg.DataBind();
                    dg.RenderControl(new HtmlTextWriter(r.Output));
                    break;
                case "Groups":
                    dg.DataSource = ExportInvolvements.OrgMemberListGroups();
                    dg.DataBind();
                    dg.RenderControl(new HtmlTextWriter(r.Output));
                    break;
                case "Promotion":
                    dg.DataSource = ExportInvolvements.PromoList(qid.Value, maxExcelRows);
                    dg.DataBind();
                    dg.RenderControl(new HtmlTextWriter(r.Output));
                    break;
            }
            r.Write("</body></HTML>");
            r.Flush();
            r.End();
        }