示例#1
0
        public byte[] CreateLabels(CustomerSelectionModel selection)
        {
            var customerTable = GetCustomerTable(selection);
            var config = _configService.GetConfigXml("LabelsFormat");

            var nameFormat = _appSettings.GetValue("MailingLabelNameFormat");
            var streetUnitNumberFormat = _appSettings.GetValue("FormattedLocale_StreetUnitNumber");
            var ds = MailingLabelFormatter.Format(customerTable, nameFormat, streetUnitNumberFormat);

            var fontSize = _appSettings.GetValue<int>("PrintLabelFontSize");
            PdfLabelGenerator generator;
            if (fontSize > 0)
                generator = new PdfLabelGenerator(config, ds, HttpContext.Current.Server.MapPath("~/content/fonts/arialuni.ttf"), fontSize);
            else
                generator = new PdfLabelGenerator(config, ds, HttpContext.Current.Server.MapPath("~/content/fonts/arialuni.ttf"));

            var stream = new MemoryStream();
            generator.SavePdf(stream);

            return stream.ToArray();
        }
示例#2
0
        DataTable GetCustomerTable(CustomerSelectionModel selection)
        {
            var consultant = _consultantContext.Consultant;

            var customers = GetCustomers(selection);

            var table = new DataTable("Customer");
            table.Columns.Add("NewLine", typeof(string), "convert(13, 'System.Char') + convert(10, 'System.Char')");
            table.Columns.Add("CustomerId", typeof(Guid));
            table.Columns.Add("ConsultantKey", typeof(Guid));
            table.Columns.Add("FirstName", typeof(string));
            table.Columns.Add("MiddleName", typeof(string));
            table.Columns.Add("LastName", typeof(string));
            table.Columns.Add("NameText", typeof(string), CUSTOMER_NAMETEXT_COLEXPR);
            table.Columns.Add("EmailAddress", typeof(string));
            table.Columns.Add("HomePhoneNumber", typeof(string));
            table.Columns.Add("HomePhoneExtension", typeof(string));
            table.Columns.Add("HomePhoneIsPrimary", typeof(bool));
            table.Columns.Add("HomePhoneText", typeof(string), CUSTOMER_HOMEPHONETEXT_COLEXPR);
            table.Columns.Add("MobilePhoneNumber", typeof(string));
            table.Columns.Add("MobilePhoneExtension", typeof(string));
            table.Columns.Add("MobilePhoneIsPrimary", typeof(bool));
            table.Columns.Add("MobilePhoneText", typeof(string), CUSTOMER_MOBILEPHONETEXT_COLEXPR);
            table.Columns.Add("WorkPhoneNumber", typeof(string));
            table.Columns.Add("WorkPhoneExtension", typeof(string));
            table.Columns.Add("WorkPhoneIsPrimary", typeof(bool));
            table.Columns.Add("WorkPhoneText", typeof(string), CUSTOMER_WORKPHONETEXT_COLEXPR);
            table.Columns.Add("PhoneNumbersText", typeof(string), CUSTOMER_PHONENUMBERSTEXT_COLEXPR);
            table.Columns.Add("PrimaryAddressAddressee", typeof(string));
            table.Columns.Add("PrimaryAddressStreet", typeof(string));
            table.Columns.Add("PrimaryAddressUnitNumber", typeof(string));
            table.Columns.Add("PrimaryAddressCity", typeof(string));
            table.Columns.Add("PrimaryAddressRegionCode", typeof(string));
            table.Columns.Add("PrimaryAddressRegionName", typeof(string));
            table.Columns.Add("PrimaryAddressCountry", typeof(string));
            table.Columns.Add("PrimaryAddressPostalCode", typeof(string));
            table.Columns.Add("PrimaryAddressText", typeof(string));
            table.Columns.Add("PreferredLanguage", typeof(string));
            table.Columns.Add("PreferredLanguageText", typeof(string), CUSTOMER_PREFERREDLANGUAGETEXT_COLEXPR);
            table.Columns.Add("IsPcp", typeof(bool));
            table.Columns.Add("IsPcpText", typeof(string), CUSTOMER_ISPCPTEXT_COLEXPR);
            table.Columns.Add("BirthMonth", typeof(Int16));
            table.Columns.Add("BirthDay", typeof(Int16));
            table.Columns.Add("LastOrderDateUtc", typeof(DateTime));
            table.Columns.Add("DateAddedUtc", typeof(DateTime));
            //table.Columns.Add("LastViewedDateUtc", typeof(DateTime));

            foreach (var customer in customers)
            {
                var row = table.NewRow();

                row["CustomerId"]    = customer.CustomerId;
                row["ConsultantKey"] = customer.ConsultantKey;
                row["FirstName"]     = TrimAndNullify(customer.FirstName);
                row["MiddleName"]    = TrimAndNullify(customer.MiddleName);
                row["LastName"]      = TrimAndNullify(customer.LastName);
                row["EmailAddress"]  = TrimAndNullify(customer.EmailAddress);

                var homePhone = customer.PhoneNumbers.FirstOrDefault(p => p.PhoneNumberType == PhoneNumberType.Home);
                if (homePhone != null)
                {
                    row["HomePhoneNumber"] = PhoneFormatter.FormatLocal(homePhone.Number, consultant.SubsidiaryCode);
                    row["HomePhoneExtension"] = TrimAndNullify(homePhone.Extension);
                    row["HomePhoneIsPrimary"] = homePhone.IsPrimary;
                }

                var mobilePhone = customer.PhoneNumbers.FirstOrDefault(p => p.PhoneNumberType == PhoneNumberType.Mobile);
                if (mobilePhone != null)
                {
                    row["MobilePhoneNumber"] = PhoneFormatter.FormatLocal(mobilePhone.Number, consultant.SubsidiaryCode);
                    row["MobilePhoneExtension"] = TrimAndNullify(mobilePhone.Extension);
                    row["MobilePhoneIsPrimary"] = mobilePhone.IsPrimary;
                }

                var workPhone = customer.PhoneNumbers.FirstOrDefault(p => p.PhoneNumberType == PhoneNumberType.Work);
                if (workPhone != null)
                {
                    row["WorkPhoneNumber"] = PhoneFormatter.FormatLocal(workPhone.Number, consultant.SubsidiaryCode);
                    row["WorkPhoneExtension"] = TrimAndNullify(workPhone.Extension);
                    row["WorkPhoneIsPrimary"] = workPhone.IsPrimary;
                }

                row["PrimaryAddressAddressee"]  = TrimAndNullify(customer.Addressee);
                row["PrimaryAddressStreet"]     = TrimAndNullify(customer.Street);
                row["PrimaryAddressUnitNumber"] = TrimAndNullify(customer.UnitNumber);
                row["PrimaryAddressCity"]       = TrimAndNullify(customer.City);
                row["PrimaryAddressRegionCode"] = TrimAndNullify(customer.RegionCode);
                row["PrimaryAddressPostalCode"] = TrimAndNullify(customer.PostalCode);
                row["PrimaryAddressCountry"]    = TrimAndNullify(customer.CountryCode);

                var streetUnitNumber = string.Format(_appSettings.GetValue("FormattedLocale_StreetUnitNumber"), customer.Street, customer.UnitNumber).Trim();
                var address = AddressFormatter.Format(customer.City, customer.RegionCode, customer.PostalCode);
                var customerAddressComponents = new List<string>();
                if (!string.IsNullOrEmpty(streetUnitNumber)) customerAddressComponents.Add(streetUnitNumber);
                if (!string.IsNullOrEmpty(address)) customerAddressComponents.Add(address);
                if (!string.IsNullOrEmpty(customer.CountryCode)) customerAddressComponents.Add(customer.CountryCode);
                var customerAddressBlock = string.Join("\n", customerAddressComponents);
                row["PrimaryAddressText"] = TrimAndNullify(customerAddressBlock);

                row["PreferredLanguage"]   = TrimAndNullify(customer.PreferredLanguage);
                row["IsPcp"]               = customer.IsPcp;
                row["BirthMonth"]          = customer.BirthMonth.HasValue ? (object)customer.BirthMonth.Value : DBNull.Value;
                row["BirthDay"]            = customer.BirthDay.HasValue ? (object)customer.BirthDay.Value : DBNull.Value;
                row["LastOrderDateUtc"]    = customer.LastOrderDateUtc.HasValue ? (object)customer.LastOrderDateUtc.Value : DBNull.Value;
                row["DateAddedUtc"]        = customer.DateAddedUtc;
                //row["LastViewedDateUtc"] = customer.LastViewedDateUtc.HasValue ? (object)customer.LastViewedDateUtc.Value : DBNull.Value;

                table.Rows.Add(row);
            }

            return table;
        }
示例#3
0
        public byte[] Print(CustomerSelectionModel selection)
        {
            var consultant = _consultantContext.Consultant;
            using (var designerFileStream = GetLocalizedTemplate("Customer_PrintList_Designer.xls"))
            {
                if (designerFileStream != null)
                {
                    var consultantName = string.Format(_appSettings.GetValue("ConsultantNameFormat"), consultant.FirstName, consultant.LastName);
                    var now = DateTime.Now;

                    var data = new DataSet("PrintList");
                    var stringsTable = GetStringsTable();
                    data.Tables.Add(stringsTable);

                    var customerTable = GetCustomerTable(selection);
                    data.Tables.Add(customerTable);

                    var designer = new WorkbookDesigner();
                    designer.Workbook = new Workbook(designerFileStream, new Aspose.Cells.LoadOptions(LoadFormat.Excel97To2003));
                    SetWorkbookBuiltInProperties(designer.Workbook, consultantName);
                    SetWorksheetHeader(designer.Workbook, 0, consultantName, Resources.GetString("PRINTLIST_DOCUMENTTITLE"), now.ToLongDateString());
                    SetWorksheetFooter(designer.Workbook, 0, Resources.GetString("PRINTLIST_FOOTERLEFTSCRIPT").Trim(), Resources.GetString("PRINTLIST_FOOTERCENTERSCRIPT").Trim(), Resources.GetString("PRINTLIST_FOOTERRIGHTSCRIPT").Trim());
                    designer.SetDataSource(data);
                    designer.Process();

                    var stream = new MemoryStream();
                    designer.Workbook.Save(stream, new XlsSaveOptions(SaveFormat.Pdf));

                    // position the stream at the beginnin so it will be ready for writing to the output
                    stream.Seek(0, SeekOrigin.Begin);

                    return stream.ToArray();
                }
            }

            return null;
        }
示例#4
0
        List<CustomerListItem> GetCustomers(CustomerSelectionModel selection)
        {
            var queryService = _clientFactory.GetCustomersQueryServiceClient();

            // fetch the selected customers in batches of 200
            var customers = selection.Ids
                .Chunk(200)
                .Select(batch => queryService.QueryCustomerListByCustomerIds(batch.ToArray()))
                .SelectMany(batch => batch);

            var sortFormat = _appSettings.GetValue("CustomerNameSortFormat");
            customers = customers.OrderBy(c => string.Format(sortFormat, c.FirstName, c.MiddleName, c.LastName));

            return customers.ToList();
        }
示例#5
0
        public ActionResult Print([Bind(Prefix = "id[]")] Guid[] ids)
        {
            var model = new CustomerSelectionModel { Ids = ids };
            var fileName = string.Format(Resources.GetString("EXPORTCUSTOMERS_PRINT_FILENAME"), DateTime.Now);
            Response.Headers.Remove("Content-Disposition");
            Response.Headers.Add("Content-Disposition", string.Format("attachment; filename={0}", fileName));
            Response.SetCookie(new HttpCookie("fileDownload", "true") { Path = "/" });

            var data = _customerListService.Print(model);
            if (data != null)
                return File(data, "application/pdf");
            else
                return new EmptyResult();
        }