Exemplo 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), couples: true);
                case "CouplesBoth":
                    return new CsvResult(ctl.FetchCouplesBothList(sort, id), couples: true);
            }
            return Content("no format");
        }
Exemplo 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, "{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();
        }
Exemplo n.º 3
0
        public ActionResult Csv(Guid id, string format, bool?sortzip, bool?titles, bool?useMailFlags)
        {
            var ctl = new MailingController(RequestManager)
            {
                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), couples: true));

            case "CouplesBoth":
                return(new CsvResult(ctl.FetchCouplesBothList(sort, id), couples: true));
            }
            return(Content("no format"));
        }
Exemplo n.º 4
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();
            }
        }
Exemplo n.º 5
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, "=========", "{0}\n{1},{2:g}".Fmt(Util.UserName, q.Count(), DateTime.Now), 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();
        }
Exemplo n.º 6
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;
            }
            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 if ((format == "CouplesEither" || format == "CouplesBoth") && m.CoupleName.HasValue())
                {
                    ph.AddLine(m.CoupleName, font);
                }
                else
                {
                    ph.AddLine(m.LabelName, font);
                }
                if (m.MailingAddress.HasValue())
                {
                    ph.AddLine(m.MailingAddress.Trim(), font);
                }
                else
                {
                    ph.AddLine(m.Address, font);
                    ph.AddLine(m.Address2, font);
                    ph.AddLine(m.CSZ, 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();
        }
Exemplo n.º 7
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":
                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));
            }
        }