Ejemplo n.º 1
0
        public ActionResult Csv(Guid id, string format, bool? sortzip, bool? titles, bool? useMailFlags)
        {
            var ctl = new MailingController {UseTitles = titles ?? false, UseMailFlags = useMailFlags ?? false};

            var sort = "Name";
            if (sortzip ?? false)
                sort = "Zip";

            switch (format)
            {
                case "Individual":
                case "GroupAddress":
                    return new CsvResult(ctl.FetchIndividualList(sort, id));
                case "FamilyMembers":
                    return new CsvResult(ctl.FetchFamilyMembers(sort, id));
                case "Family":
                    return new CsvResult(ctl.FetchFamilyList(sort, id));
                case "ParentsOf":
                    return new CsvResult(ctl.FetchParentsOfList(sort, id));
                case "CouplesEither":
                    return new CsvResult(ctl.FetchCouplesEitherList(sort, id));
                case "CouplesBoth":
                    return new CsvResult(ctl.FetchCouplesBothList(sort, id));
            }
            return Content("no format");
        }
Ejemplo n.º 2
0
        public override void ExecuteResult(ControllerContext context)
        {
            var Response = context.HttpContext.Response;
            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "filename=foo.pdf");

            var document = new Document();
            document.SetPageSize(new Rectangle(72 * W, 72 * H));
            document.SetMargins(14f, 0f, 3.6f, 1f);
            var w = PdfWriter.GetInstance(document, Response.OutputStream);
            document.Open();
            dc = w.DirectContent;

            var ctl = new MailingController {UseTitles = titles, UseMailFlags = useMailFlags};

            IEnumerable<MailingController.MailingInfo> q = null;
            switch (format)
            {
                case "Individual":
                case "GroupAddress":
                    q = ctl.FetchIndividualList(sort, qid);
                    break;
                case "FamilyMembers":
                case "Family":
                    q = ctl.FetchFamilyList(sort, qid);
                    break;
                case "ParentsOf":
                    q = ctl.FetchParentsOfList(sort, qid);
                    break;
                case "CouplesEither":
                    q = ctl.FetchCouplesEitherList(sort, qid);
                    break;
                case "CouplesBoth":
                    q = ctl.FetchCouplesBothList(sort, qid);
                    break;
            }
            AddLabel(document, "=========", $"{Util.UserName}\n{q.Count()},{DateTime.Now:g}", String.Empty);
            foreach (var m in q)
            {
                var label = m.LabelName;
                if (m.CoupleName.HasValue() && format.StartsWith("Couples"))
                    label = m.CoupleName;
                var address = "";
                if (m.MailingAddress.HasValue())
                    address = m.MailingAddress;
                else
                {
                    var sb = new StringBuilder(m.Address);
                    if (m.Address2.HasValue())
                        sb.AppendFormat("\n{0}", m.Address2);
                    sb.AppendFormat("\n{0}", m.CSZ);
                    address = sb.ToString();
                }
                AddLabel(document, label, address, Util.PickFirst(m.CellPhone.FmtFone("C "), m.HomePhone.FmtFone("H ")));
            }
            document.Close();
        }
Ejemplo n.º 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var context = HttpContext.Current;
            int? qid = context.Request.QueryString["id"].ToInt2();
            var labelNameFormat = context.Request.QueryString["format"];
            var ctl = new MailingController();
            var sortZip = context.Request.QueryString["sortZip"];
            var sort = "Name";
            var useTitles = context.Request.QueryString["titles"];
                ctl.UseTitles = useTitles == "true";
            if (sortZip == "true")
                sort = "Zip";
            IEnumerable<MailingController.MailingInfo> q = null;
            switch (labelNameFormat)
            {
                case "Individual":
                case "GroupAddress":
                    q = ctl.FetchIndividualList(sort, qid.Value);
                    break;
                case "FamilyMembers":
                    q = ctl.FetchFamilyMembers(sort, qid.Value);
                    break;
                case "Family":
                    q = ctl.FetchFamilyList(sort, qid.Value);
                    break;
                case "ParentsOf":
                    q = ctl.FetchParentsOfList(sort, qid.Value);
                    break;
                case "CouplesEither":
                    q = ctl.FetchCouplesEitherList(sort, qid.Value);
                    break;
                case "CouplesBoth":
                    q = ctl.FetchCouplesBothList(sort, qid.Value);
                    break;
            }
            var r = context.Response;
            if (q == null)
            {
                r.Write("no format");
                return;
            }

            r.Clear();
            r.ContentType = "text/plain";
            r.AddHeader("Content-Disposition", "attachment;filename=CMSPeople.csv");
            r.Charset = "";
            if (!qid.HasValue)
            {
                r.Write("no queryid");
                r.Flush();
                r.End();
            }
            foreach (var mi in q)
                r.Write(string.Format("\"{0}\",\"{1}\",\"{2}\",\"{3}\",\"{4}\",{5},{6}\r\n",
                    mi.LabelName, mi.Address, mi.Address2, mi.City, mi.State, mi.Zip.FmtZip(), mi.PeopleId));
        }
Ejemplo n.º 4
0
        public static DataTable FetchExcelList(Guid queryid, int maximumRows, bool useMailFlags)
        {
            //var Db = Db;
            var query = DbUtil.Db.PeopleQuery(queryid);

            if (useMailFlags)
            {
                query = MailingController.FilterMailFlags(query);
            }

            var q = from p in query
                    let om                     = p.OrganizationMembers.SingleOrDefault(om => om.OrganizationId == p.BibleFellowshipClassId)
                                       let oid = p.PeopleExtras.FirstOrDefault(pe => pe.Field == "OtherId").Data
                                                 select new
            {
                p.PeopleId,
                Title     = p.TitleCode,
                FirstName = p.PreferredName,
                p.LastName,
                Address      = p.PrimaryAddress,
                Address2     = p.PrimaryAddress2,
                City         = p.PrimaryCity,
                State        = p.PrimaryState,
                Country      = p.PrimaryCountry,
                Zip          = p.PrimaryZip.FmtZip(),
                Email        = p.EmailAddress,
                BirthDate    = Person.FormatBirthday(p.BirthYr, p.BirthMonth, p.BirthDay, p.PeopleId),
                BirthDay     = Person.FormatBirthday(null, p.BirthMonth, p.BirthDay, p.PeopleId),
                JoinDate     = p.JoinDate.FormatDate(),
                HomePhone    = p.HomePhone.FmtFone(),
                CellPhone    = p.CellPhone.FmtFone(),
                WorkPhone    = p.WorkPhone.FmtFone(),
                MemberStatus = p.MemberStatus.Description,
                Age          = Person.AgeDisplay(p.Age, p.PeopleId).ToString(),
                Married      = p.MaritalStatus.Description,
                Wedding      = p.WeddingDate.FormatDate(),
                p.FamilyId,
                FamilyPosition   = p.FamilyPosition.Description,
                Gender           = p.Gender.Description,
                School           = p.SchoolOther,
                Grade            = p.Grade.ToString(),
                FellowshipLeader = p.BFClass.LeaderName,
                AttendPctBF      = (om == null ? 0 : om.AttendPct == null ? 0 : om.AttendPct.Value),
                FellowshipClass  = (om == null ? "" : om.Organization.OrganizationName),
                p.AltName,
                Employer     = p.EmployerOther,
                OtherId      = oid ?? "",
                Campus       = p.Campu == null ? "" : p.Campu.Description,
                DecisionDate = p.DecisionDate.FormatDate()
            };

            return(q.Take(maximumRows).ToDataTable());
        }
Ejemplo n.º 5
0
 public ActionResult Excel(Guid id, string format, bool? titles, bool? useMailFlags)
 {
     var ctl = new MailingController {UseTitles = titles ?? false, UseMailFlags = useMailFlags ?? false};
     switch (format)
     {
         case "Individual":
         case "GroupAddress":
             return new ExcelResult(ExportPeople.FetchExcelList(id, maxExcelRows, useMailFlags ?? false));
         case "Library":
             return new ExcelResult(ExportPeople.FetchExcelLibraryList(id));
         case "AllFamily":
             return new ExcelResult(ExportPeople.FetchExcelListFamily(id));
         case "Family":
             return new ExcelResult(ctl.FetchExcelFamily(id, maxExcelRows));
         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":
             return ExcelExportModel.Result(id);
     //                case "IndividualPicture2":
     //                    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");
 }
Ejemplo n.º 6
0
        public override void ExecuteResult(ControllerContext context)
        {
            var Response = context.HttpContext.Response;
            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "filename=foo.pdf");

            var document = new Document();
            document.SetPageSize(new Rectangle(72 * W, 72 * H));
            document.SetMargins(14f, 0f, 3.6f, 1f);
            var w = PdfWriter.GetInstance(document, Response.OutputStream);
            document.Open();
            dc = w.DirectContent;

            var ctl = new MailingController();
            ctl.UseTitles = titles;

            IEnumerable<MailingController.MailingInfo> q = null;
            switch (format)
            {
                case "Individual":
                case "GroupAddress":
                    q = ctl.FetchIndividualList(sort, qid);
                    break;
                case "FamilyMembers":
                case "Family":
                    q = ctl.FetchFamilyList(sort, qid);
                    break;
                case "ParentsOf":
                    q = ctl.FetchParentsOfList(sort, qid);
                    break;
                case "CouplesEither":
                    q = ctl.FetchCouplesEitherList(sort, qid);
                    break;
                case "CouplesBoth":
                    q = ctl.FetchCouplesBothList(sort, qid);
                    break;
            }
            AddLabel(document, "=========", Util.UserName, "{0} labels printed".Fmt(q.Count()), "{0:g}".Fmt(DateTime.Now), String.Empty);
            foreach (var m in q)
                AddLabel(document, m.LabelName, m.Address, m.Address2, m.CityStateZip, Util.PickFirst(m.CellPhone.FmtFone("C "), m.HomePhone.FmtFone("H ")));

            document.Close();
        }
Ejemplo n.º 7
0
        public override void ExecuteResult(ControllerContext context)
        {
            var ctl = new MailingController {
                UseTitles = Titles ?? false, UseMailFlags = UseMailFlags ?? false
            };
            var response = context.HttpContext.Response;
            IEnumerable <MailingController.MailingInfo> q = null;

            switch (Format)
            {
            case "Individual":
                q = ctl.FetchIndividualList(Sort, id);
                break;

            case "GroupAddress":
                q = ctl.GroupByAddress(Sort, id);
                break;

            case "Family":
            case "FamilyMembers":
                q = ctl.FetchFamilyList(Sort, id);
                break;

            case "ParentsOf":
                q = ctl.FetchParentsOfList(Sort, id);
                break;

            case "CouplesEither":
                q = ctl.FetchCouplesEitherList(Sort, id);
                break;

            case "CouplesBoth":
                q = ctl.FetchCouplesBothList(Sort, id);
                break;

            default:
                response.Write("unknown format");
                return;
            }

            var  bytes    = AveryLabelTemplate() ?? Resource1.DocxAveryLabel;
            var  ms       = new MemoryStream(bytes);
            var  docx     = DocX.Load(ms);
            var  row      = 0;
            var  col      = 0;
            DocX finaldoc = null;
            DocX currpage = null;

            foreach (var p in q)
            {
                if (currpage == null || (row == 0 && col == 0))
                {
                    currpage = docx.Copy();
                }

                if (Skip > 0)
                {
                    row = Skip / 3;
                    col = Skip % 3;
                    if (col > 0)
                    {
                        col *= 2;
                    }
                    Skip = 0;
                }
                var cell = currpage.Tables[0].Rows[row].Cells[col];
                var pg   = cell.Paragraphs[0];

                if (Format == "GroupAddress")
                {
                    pg.InsertText(p.LabelName + " " + p.LastName);
                }
                else if ((Format == "CouplesEither" || Format == "CouplesBoth") && p.CoupleName.HasValue())
                {
                    pg.InsertText(p.CoupleName);
                }
                else
                {
                    pg.InsertText(p.LabelName);
                }

                if (p.MailingAddress.HasValue())
                {
                    pg.InsertText($"\n{p.MailingAddress.Trim()}");
                }
                else
                {
                    pg.InsertText($"\n{p.Address}");
                    if (p.Address2.HasValue())
                    {
                        pg.InsertText($"\n{p.Address2}");
                    }
                    pg.InsertText($"\n{p.CSZ}");
                }
                if (UsePhone == true)
                {
                    var phone = Util.PickFirst(p.CellPhone.FmtFone("C "), p.HomePhone.FmtFone("H "));
                    pg.InsertText($"\n{phone}");
                }

                col += 2;
                if (col != 6)
                {
                    continue;
                }
                col = 0;
                row++;
                if (row != 10)
                {
                    continue;
                }
                row = 0;
                if (finaldoc == null)
                {
                    finaldoc = currpage;
                }
                else
                {
                    finaldoc.InsertDocument(currpage);
                }
                currpage = null;
            }
            if (finaldoc == null && currpage == null)
            {
                response.Write("no data found");
                return;
            }
            if (finaldoc == null)
            {
                finaldoc = currpage;
            }
            else if (currpage != null)
            {
                finaldoc.InsertDocument(currpage);
            }

            response.Clear();
            response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
            response.AddHeader("content-disposition", $"attachment;filename=AveryLabels-{DateTime.Now.ToSortableDateTime()}.docx");

            ms = new MemoryStream();
            finaldoc.SaveAs(ms);
            ms.WriteTo(response.OutputStream);
            response.End();
        }
Ejemplo n.º 8
0
        public override void ExecuteResult(ControllerContext context)
        {
            var ctl = new MailingController { UseTitles = titles ?? false, UseMailFlags = useMailFlags ?? false };
            var Response = context.HttpContext.Response;

            IEnumerable<MailingController.MailingInfo> q = null;
            switch (format)
            {
                case "Individual":
                    q = ctl.FetchIndividualList(sort, id);
                    break;
                case "GroupAddress":
                    q = ctl.GroupByAddress(id);
                    break;
                case "Family":
                case "FamilyMembers":
                    q = ctl.FetchFamilyList(sort, id);
                    break;
                case "ParentsOf":
                    q = ctl.FetchParentsOfList(sort, id);
                    break;
                case "CouplesEither":
                    q = ctl.FetchCouplesEitherList(sort, id);
                    break;
                case "CouplesBoth":
                    q = ctl.FetchCouplesBothList(sort, id);
                    break;
                default:
                    Response.Write("unknown format");
                    return;
            }
            if (!q.Any())
            {
                Response.Write("no data found");
                return;
            }
            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "filename=foo.pdf");

            var document = new Document(PageSize.LETTER);
            document.SetMargins(50f, 36f, 32f, 36f);
            var w = PdfWriter.GetInstance(document, Response.OutputStream);
            document.Open();
            dc = w.DirectContent;

            var cols = new float[] { W, W, W - 25f };
            var t = new PdfPTable(cols);
            t.SetTotalWidth(cols);
            t.HorizontalAlignment = Element.ALIGN_CENTER;
            t.LockedWidth = true;
            t.DefaultCell.Border = PdfPCell.NO_BORDER;
            t.DefaultCell.FixedHeight = H;
            t.DefaultCell.VerticalAlignment = PdfPCell.ALIGN_MIDDLE;
            t.DefaultCell.PaddingLeft = 8f;
            t.DefaultCell.PaddingRight = 8f;
            t.DefaultCell.SetLeading(2.0f, 1f);

            if (skip > 0)
            {
                var blankCell = new PdfPCell(t.DefaultCell);

                for (int iX = 0; iX < skip; iX++)
                {
                    t.AddCell(blankCell);
                }
            }

            foreach (var m in q)
            {
                var c = new PdfPCell(t.DefaultCell);
                var ph = new Paragraph();
                if (format == "GroupAddress")
                    ph.AddLine(m.LabelName + " " + m.LastName, font);
                else
                    ph.AddLine(m.LabelName, font);
                ph.AddLine(m.Address, font);
                ph.AddLine(m.Address2, font);
                ph.AddLine(m.CityStateZip, font);
                c.AddElement(ph);
                if (usephone)
                {
                    var phone = Util.PickFirst(m.CellPhone.FmtFone("C "), m.HomePhone.FmtFone("H "));
                    var p = new Paragraph();
                    c.PaddingRight = 7f;
                    p.Alignment = Element.ALIGN_RIGHT;
                    p.Add(new Chunk(phone, smfont));
                    p.ExtraParagraphSpace = 0f;
                    c.AddElement(p);
                }
                t.AddCell(c);
            }
            t.CompleteRow();
            document.Add(t);

            document.Close();
        }
Ejemplo n.º 9
0
        public override void ExecuteResult(ControllerContext context)
        {
            var ctl = new MailingController { UseTitles = titles ?? false, UseMailFlags = useMailFlags ?? false };
            var Response = context.HttpContext.Response;

            IEnumerable<MailingController.MailingInfo> q = null;
            switch (format)
            {
                case "Individual":
                    q = ctl.FetchIndividualList(sort, id);
                    break;
                case "GroupAddress":
                    q = ctl.GroupByAddress(sort, id);
                    break;
                case "Family":
                case "FamilyMembers":
                    q = ctl.FetchFamilyList(sort, id);
                    break;
                case "ParentsOf":
                    q = ctl.FetchParentsOfList(sort, id);
                    break;
                case "CouplesEither":
                    q = ctl.FetchCouplesEitherList(sort, id);
                    break;
                case "CouplesBoth":
                    q = ctl.FetchCouplesBothList(sort, id);
                    break;
                default:
                    Response.Write("unknown format");
                    return;
            }
            if (!q.Any())
            {
                Response.Write("no data found");
                return;
            }
            using (var ms = new MemoryStream())
            {
                var dd = DocX.Create("ttt.docx");
                dd.MarginLeft = 30;
                dd.MarginRight = 24;
                dd.MarginTop = 48;
                dd.MarginBottom = 30;
                dd.PageHeight = 1056;
                dd.PageWidth = 816;
                var col = 0;
                var row = 0;
                Table tt = null;
                foreach (var p in q)
                {
                    if (tt == null || col == 0 && row == 0)
                    {
                        tt = dd.InsertTable(10, 5);
                        foreach (var rr in tt.Rows)
                            for (var i = 0; i < 5; i++)
                            {
                                rr.Cells[i].VerticalAlignment = VerticalAlignment.Center;
                                rr.Height = 96.0;
                                rr.Cells[i].Width = i % 2 == 0
                                    ? 252.4667
                                    : 11.4;
                                if (i % 2 == 0)
                                    rr.Cells[i].MarginLeft = 30;
                            }
                    }
                    if (skip > 0)
                    {
                        row = skip / 3;
                        col = skip % 3;
                        if (col > 0)
                            col++;
                        if (col > 2)
                            col++;
                    }
                    var c = tt.Rows[row].Cells[col];

                    if (format == "GroupAddress")
                        c.Paragraphs[0].InsertText(p.LabelName + " " + p.LastName);
                    else if ((format == "CouplesEither" || format == "CouplesBoth") && p.CoupleName.HasValue())
                        c.Paragraphs[0].InsertText(p.CoupleName);
                    else
                        c.Paragraphs[0].InsertText(p.LabelName);


                    if (p.MailingAddress.HasValue())
                        c.InsertParagraph(p.MailingAddress.Trim());
                    else
                    {
                        c.InsertParagraph(p.Address);
                        if (p.Address2.HasValue())
                            c.InsertParagraph(p.Address2);
                        c.InsertParagraph(p.CSZ);
                    }

                    col += 2;
                    if (col == 6)
                    {
                        row++;
                        col = 0;
                        if (row == 10)
                            row = 0;
                    }
                }
                dd.SaveAs(ms);
                Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
                Response.AddHeader("content-disposition", "filename=avery-labels.docx");
                Response.AddHeader("content-length", ms.Length.ToString());
                Response.BinaryWrite(ms.ToArray());
                Response.End();
            }
        }
Ejemplo n.º 10
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();
        }
Ejemplo n.º 11
0
        public override void ExecuteResult(ControllerContext context)
        {
            var ctl = new MailingController { UseTitles = Titles ?? false, UseMailFlags = UseMailFlags ?? false };
            var response = context.HttpContext.Response;
            IEnumerable<MailingController.MailingInfo> q = null;
            switch (Format)
            {
                case "Individual":
                    q = ctl.FetchIndividualList(Sort, id);
                    break;
                case "GroupAddress":
                    q = ctl.GroupByAddress(Sort, id);
                    break;
                case "Family":
                case "FamilyMembers":
                    q = ctl.FetchFamilyList(Sort, id);
                    break;
                case "ParentsOf":
                    q = ctl.FetchParentsOfList(Sort, id);
                    break;
                case "CouplesEither":
                    q = ctl.FetchCouplesEitherList(Sort, id);
                    break;
                case "CouplesBoth":
                    q = ctl.FetchCouplesBothList(Sort, id);
                    break;
                default:
                    response.Write("unknown format");
                    return;
            }

            var bytes = AveryLabelTemplate() ?? Resource1.DocxAveryLabel;
            var ms = new MemoryStream(bytes);
            var docx = DocX.Load(ms);
            var row = 0;
            var col = 0;
            DocX finaldoc = null;
            DocX currpage = null;
            foreach (var p in q)
            {
                if(currpage == null || (row == 0 && col == 0))
                    currpage = docx.Copy();

                if (Skip > 0)
                {
                    row = Skip/3;
                    col = Skip%3;
                    if (col > 0)
                        col *= 2;
                    Skip = 0;
                }
                var cell = currpage.Tables[0].Rows[row].Cells[col];
                var pg = cell.Paragraphs[0];

                if (Format == "GroupAddress")
                    pg.InsertText(p.LabelName + " " + p.LastName);
                else if ((Format == "CouplesEither" || Format == "CouplesBoth") && p.CoupleName.HasValue())
                    pg.InsertText(p.CoupleName);
                else
                    pg.InsertText(p.LabelName);

                if (p.MailingAddress.HasValue())
                    pg.InsertText($"\n{p.MailingAddress.Trim()}");
                else
                {
                    pg.InsertText($"\n{p.Address}");
                    if (p.Address2.HasValue())
                        pg.InsertText($"\n{p.Address2}");
                    pg.InsertText($"\n{p.CSZ}");
                }

                col+=2;
                if (col != 6)
                    continue;
                col = 0;
                row++;
                if (row != 10)
                    continue;
                row = 0;
                if (finaldoc == null)
                    finaldoc = currpage;
                else
                    finaldoc.InsertDocument(currpage);
                currpage = null;
            }
            if(finaldoc == null && currpage == null)
            {
                response.Write("no data found");
                return;
            }
            if (finaldoc == null)
                finaldoc = currpage;
            else if(currpage != null)
                finaldoc.InsertDocument(currpage);

            context.HttpContext.Response.Clear();
            context.HttpContext.Response.ContentType =
                "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
            context.HttpContext.Response.AddHeader("Content-Disposition",
                $"attachment;filename=AveryLabels-{DateTime.Now.ToSortableDateTime()}.docx");
            finaldoc.SaveAs(context.HttpContext.Response.OutputStream);
        }