Exemplo n.º 1
0
        public static void Generate(System.Web.HttpResponseBase Response, string whiteLabel, List <Campaign> campaigns)
        {
            ExcelPackage excel     = new ExcelPackage();
            var          workSheet = excel.Workbook.Worksheets.Add(whiteLabel);

            List <CustomerOrdersStatusVm> customerOrders = new List <CustomerOrdersStatusVm>();

            foreach (var campaign in campaigns)
            {
                customerOrders.Add(CustomerOrdersStatusVm.FromCampaign(campaign));
            }

            workSheet.Cells[1, 1].LoadFromCollection(customerOrders, true);

            var headerRowComplete = workSheet.Row(1);

            headerRowComplete.Style.Font.Size = 13;
            headerRowComplete.Style.Font.Bold = true;

            int Row = 2;

            foreach (var campaign in campaigns)
            {
                var rowComplete = workSheet.Row(Row);
                rowComplete.Style.Fill.PatternType = ExcelFillStyle.Solid;

                if (campaign.Status == (int)CampaignStatus.Monitoring)
                {
                    rowComplete.Style.Fill.BackgroundColor.SetColor(Color.DarkOrange);
                }
                else
                {
                    rowComplete.Style.Fill.BackgroundColor.SetColor(Color.MediumPurple);
                }
                Row++;
            }

            using (var memoryStream = new MemoryStream())
            {
                Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                Response.AddHeader("content-disposition", "attachment;  filename=" + whiteLabel + "OrdersReport.xlsx");
                excel.SaveAs(memoryStream);
                memoryStream.WriteTo(Response.OutputStream);
                Response.Flush();
                Response.End();
            }
        }
        public static CustomerOrdersStatusVm FromCampaign(Campaign campaign)
        {
            string orderNumberRdp = campaign.ReBroadcasted ? campaign.ReBroadcastedOrderNumber : campaign.OrderNumber;

            string[] campaignTypes = { "Graphic Design", "E-Blast", "Redrop- Openers", "Retargeting-Openers" };
            int      ct            = Random.Next(0, 3);

            string[] reportFormats = { "Dataroma", "Static" };
            int      ct2           = Random.Next(0, 1);
            string   status        = (campaign.Status == (int)CampaignStatus.Monitoring) ? "Order Scheduled/Live" :
                                     (campaign.Status == (int)CampaignStatus.Invoiced) ? "Invoiced" : System.Enum.GetName(typeof(CampaignStatus), campaign.Status);

            var ordersStatus = new CustomerOrdersStatusVm
            {
                Report_Sent          = "Yes",
                Report_Needed        = "Yes",
                Status               = status,
                Invoice_No           = "1153",
                Invoice_Date         = System.DateTime.Now.ToString(StringConstants.DateFormatSlashes),
                NXS_IO_Number        = orderNumberRdp,
                Campaign_Type        = campaignTypes[ct],
                Campaign_Name        = campaign.Approved.CampaignName,
                Order_Date           = campaign.CreatedAt.ToString(StringConstants.DateFormatSlashes),
                Broadcast_Date       = campaign.Approved.DeployDate?.ToString(StringConstants.DateFormatSlashes),
                Deployment_Time_EST  = campaign.Approved.DeployDate?.ToString(StringConstants.TimeFormat),
                Broadcast_QTY        = campaign.Approved.Quantity.ToString(),
                Geography            = campaign.Approved.GeoDetails,
                Demographics         = campaign.Approved.Demographics,
                From_Line            = campaign.Approved.FromLine,
                Subject_Line         = campaign.Approved.SubjectLine,
                Special_Instructions = campaign.Approved.SpecialInstructions,
                Supression           = string.IsNullOrEmpty(campaign.Assets.SuppressionFile) ? "Yes" : "No",
                RTG_URL              = campaign.Referrer, //campaign.ReBroadcastDate?.ToString(StringConstants.DateFormatDashes),
                Design_Fee           = "Yes",
                Report_Format        = reportFormats[ct2]
            };

            return(ordersStatus);
        }