Beispiel #1
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(Client).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ClientExists(Client.ID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Beispiel #2
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Client.Add(Client);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Beispiel #3
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Vendor = await _context.Vendor.FindAsync(id);

            if (Vendor != null)
            {
                _context.Vendor.Remove(Vendor);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Beispiel #4
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Client = await _context.Client.FindAsync(id);

            if (Client != null)
            {
                _context.Client.Remove(Client);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Beispiel #5
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Oct20Payroll = await _context.Oct20Payroll.FindAsync(id);

            if (Oct20Payroll != null)
            {
                _context.Oct20Payroll.Remove(Oct20Payroll);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Beispiel #6
0
        public async Task <IActionResult> OnPostAsync(Invoice model)
        //public IActionResult OnPost(Invoice model)
        {
            // ComponentInfo.SetLicense("FREE-LICENSE-KEY");

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Invoice.Add(Invoice);
            await _context.SaveChangesAsync();

            /*  SaveOptions options = GetSaveOptions(model.SelectedFormat);
             * DocumentModel document = this.Process(model);
             *
             *
             * return File(GetBytes(document, options), options.ContentType, "Invoice." + model.SelectedFormat.ToLowerInvariant());
             * // return RedirectToPage("./Index"); */



            // string webRootPath = _hostingEnvironment.WebRootPath;
            string fileName = @"Invoice.pdf";
            //    string URL = string.Format("{0}://{1}/{2}", Request.Scheme, Request.Host, fileName);
            //    FileInfo file = new FileInfo(Path.Combine(fileName));
            var memoryStream = new MemoryStream();


            //create a PDF document
            PdfDocument doc = new PdfDocument();

            doc.PageSettings.Size = PdfPageSize.A4;

            //reset the default margins to 0
            doc.PageSettings.Margins = new PdfMargins(0);

            //create a PdfMargins object, the parameters indicate the page margins you want to set
            PdfMargins margins = new PdfMargins(0, 40, 0, 40);

            //create a header template with content and apply it to page template
            doc.Template.Top    = CreateHeaderTemplate(doc, margins);
            doc.Template.Bottom = CreateFooterTemplate(doc, margins);

            //apply blank templates to other parts of page template
            //  doc.Template.Bottom = new PdfPageTemplateElement(doc.PageSettings.Size.Width, margins.Bottom);
            doc.Template.Left  = new PdfPageTemplateElement(margins.Left, doc.PageSettings.Size.Height);
            doc.Template.Right = new PdfPageTemplateElement(margins.Right, doc.PageSettings.Size.Height);


            PdfPageBase     page  = doc.Pages.Add();
            PdfTrueTypeFont font  = new PdfTrueTypeFont(new Font("Arial", 18f, FontStyle.Bold));
            PdfSolidBrush   brush = new PdfSolidBrush(Color.Gray);

            page.Canvas.DrawString(String.Format("#{0}", Invoice.ID), font, brush, new PointF(520, 0));


            PdfTrueTypeFont font2  = new PdfTrueTypeFont(new Font("Arial", 11f, FontStyle.Bold));
            PdfTrueTypeFont font3  = new PdfTrueTypeFont(new Font("Arial", 10f, FontStyle.Bold));
            PdfSolidBrush   brush2 = new PdfSolidBrush(Color.Black);
            PdfSolidBrush   brush3 = new PdfSolidBrush(Color.White);

            page.Canvas.DrawString("Date:\nValid Until: ", font2, brush, new PointF(420, 25));

            page.Canvas.DrawString(String.Format("{0}\n{1}", DateTime.Now.ToString("MMM dd, yyyy"), Invoice.Date.ToString("MMM dd, yyyy")), font2, brush2, new PointF(490, 25));

            page.Canvas.DrawString("Bill To:", font3, brush, new PointF(70, 55));
            page.Canvas.DrawString(String.Format("{0}\n{1}\n{2}, {3}", Invoice.Name, Invoice.Project, Invoice.City, Invoice.Country), font3, brush2, new PointF(70, 70));



            /*    String[] data
             * = {
             * "Item;Quantity;Rate;Amount",
             * String.Format("{0};{1};{2};{3}",Invoice.Item1,Invoice.Quantity1,Invoice.Rate1,Invoice.Amount1)
             * };
             *  String[][] dataSource
             *      = new String[data.Length][];
             *  for (int i = 0; i < data.Length; i++)
             *  {
             *      dataSource[i] = data[i].Split(';');
             *  }
             *
             *  PdfTable table = new PdfTable();
             *  table.Style.CellPadding = 3;
             *  table.Style.BorderPen = new PdfPen(brush3, 0.75f);
             *  table.Style.HeaderStyle.StringFormat = new PdfStringFormat(PdfTextAlignment.Center);
             *  table.Style.HeaderSource = PdfHeaderSource.Rows;
             *  table.Style.HeaderRowCount = 1;
             *  table.Style.ShowHeader = true;
             *  table.Style.HeaderStyle.BackgroundBrush = PdfBrushes.Black;
             *  table.DataSource = dataSource;
             *  foreach (PdfColumn column in table.Columns)
             *  {
             *      column.StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
             *  }
             *  table.Draw(page, new PointF(100, 135));
             */



            PdfGrid grid = new PdfGrid();

            grid.Columns.Add(5);
            float width = page.Canvas.ClientSize.Width - (grid.Columns.Count + 1);

            for (int j = 0; j < grid.Columns.Count; j++)
            {
                grid.Columns[j].Width = width * 0.20f;
            }

            PdfGridRow row0   = grid.Rows.Add();
            PdfGridRow row1   = grid.Rows.Add();
            PdfGridRow row2   = grid.Rows.Add();
            PdfGridRow row3   = grid.Rows.Add();
            PdfGridRow row4   = grid.Rows.Add();
            PdfGridRow row5   = grid.Rows.Add();
            PdfGridRow row6   = grid.Rows.Add();
            PdfGridRow row7   = grid.Rows.Add();
            float      height = 20.0f;

            for (int i = 0; i < grid.Rows.Count; i++)
            {
                grid.Rows[i].Height = height;
            }


            //SET CAP ~56 LETTERS


            row0.Style.Font      = new PdfTrueTypeFont(new Font("Arial", 10f, FontStyle.Bold), true);
            row0.Style.TextBrush = new PdfSolidBrush(Color.White);
            row1.Style.Font      = new PdfTrueTypeFont(new Font("Arial", 10f, FontStyle.Bold), true);


            row0.Cells[0].Value                 = "\tItem";
            row0.Cells[0].StringFormat          = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
            row0.Cells[0].Style.BackgroundBrush = PdfBrushes.Black;
            // row0.Cells[0].RowSpan = 2;
            row0.Cells[0].ColumnSpan = 2;
            //  row0.Cells[0].Style.BackgroundBrush = PdfBrushes.Black;

            row1.Cells[0].Value        = String.Format(" {0}", Invoice.Item1);
            row1.Cells[0].StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
            row1.Cells[0].ColumnSpan   = 2;

            row2.Cells[0].Value        = String.Format(" {0}", Invoice.Item2);
            row2.Cells[0].StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
            row2.Cells[0].ColumnSpan   = 2;
            row3.Cells[0].Value        = String.Format(" {0}", Invoice.Item3);
            row3.Cells[0].StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
            row3.Cells[0].ColumnSpan   = 2;
            row4.Cells[0].Value        = String.Format(" {0}", Invoice.Item4);
            row4.Cells[0].StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
            row4.Cells[0].ColumnSpan   = 2;
            row5.Cells[0].Value        = String.Format(" {0}", Invoice.Item5);
            row5.Cells[0].StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
            row5.Cells[0].ColumnSpan   = 2;
            row6.Cells[0].Value        = String.Format(" {0}", Invoice.Item6);
            row6.Cells[0].StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
            row6.Cells[0].ColumnSpan   = 2;
            row7.Cells[0].Value        = String.Format(" {0}", Invoice.Item7);
            row7.Cells[0].StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
            row7.Cells[0].ColumnSpan   = 2;


            row0.Cells[2].Value                 = "Quantity";
            row0.Cells[2].StringFormat          = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            row0.Cells[2].Style.BackgroundBrush = PdfBrushes.Black;

            row1.Cells[2].Value        = String.Format("{0}", Invoice.Quantity1);
            row1.Cells[2].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            row2.Cells[2].Value        = String.Format("{0}", Invoice.Quantity2);
            row2.Cells[2].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            row3.Cells[2].Value        = String.Format("{0}", Invoice.Quantity3);
            row3.Cells[2].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            row4.Cells[2].Value        = String.Format("{0}", Invoice.Quantity4);
            row4.Cells[2].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            row5.Cells[2].Value        = String.Format("{0}", Invoice.Quantity5);
            row5.Cells[2].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            row6.Cells[2].Value        = String.Format("{0}", Invoice.Quantity6);
            row6.Cells[2].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            row7.Cells[2].Value        = String.Format("{0}", Invoice.Quantity7);
            row7.Cells[2].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);

            row0.Cells[3].Value                 = "Rate [AED]";
            row0.Cells[3].StringFormat          = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            row0.Cells[3].Style.BackgroundBrush = PdfBrushes.Black;
            //   row0.Cells[1].ColumnSpan = 3;

            row1.Cells[3].Value        = String.Format("{0}", Invoice.Rate1);
            row1.Cells[3].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            row2.Cells[3].Value        = String.Format("{0}", Invoice.Rate2);
            row2.Cells[3].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            row3.Cells[3].Value        = String.Format("{0}", Invoice.Rate3);
            row3.Cells[3].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            row4.Cells[3].Value        = String.Format("{0}", Invoice.Rate4);
            row4.Cells[3].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            row5.Cells[3].Value        = String.Format("{0}", Invoice.Rate5);
            row5.Cells[3].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            row6.Cells[3].Value        = String.Format("{0}", Invoice.Rate6);
            row6.Cells[3].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            row7.Cells[3].Value        = String.Format("{0}", Invoice.Rate7);
            row7.Cells[3].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);

            row0.Cells[4].Value = "Amount [AED]";
            //   row0.Cells[4].Style.Font = new PdfTrueTypeFont(new Font("Arial", 10f, FontStyle.Bold | FontStyle.Italic), true);
            row0.Cells[4].StringFormat          = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            row0.Cells[4].Style.BackgroundBrush = PdfBrushes.Black;

            row1.Cells[4].Value        = String.Format("{0}", Invoice.Amount1);
            row1.Cells[4].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            row2.Cells[4].Value        = String.Format("{0}", Invoice.Amount2);
            row2.Cells[4].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            row3.Cells[4].Value        = String.Format("{0}", Invoice.Amount3);
            row3.Cells[4].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            row4.Cells[4].Value        = String.Format("{0}", Invoice.Amount4);
            row4.Cells[4].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            row5.Cells[4].Value        = String.Format("{0}", Invoice.Amount5);
            row5.Cells[4].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            row6.Cells[4].Value        = String.Format("{0}", Invoice.Amount6);
            row6.Cells[4].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            row7.Cells[4].Value        = String.Format("{0}", Invoice.Amount7);
            row7.Cells[4].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);


            // row1.Cells[1].Value = "Amount [AED]";
            // row1.Cells[1].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            // row1.Cells[1].ColumnSpan = 4;


            PdfBorders border = new PdfBorders();

            border.All = new PdfPen(Color.Transparent);

            foreach (PdfGridRow pgr in grid.Rows)
            {
                foreach (PdfGridCell pgc in pgr.Cells)
                {
                    pgc.Style.Borders = border;
                }
            }

            grid.Draw(page, new PointF(2, 135));


            /*   row0.Cells[0].Value = "Item";
             * row0.Cells[0].ColumnSpan = 2;
             *
             *
             * row0.Cells[2].Value = "Quantity";
             * //     row0.Cells[2].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
             *
             *
             * row0.Cells[3].Value = "Rate [AED]";
             * //    row0.Cells[4].Style.Font = new PdfTrueTypeFont(new Font("Arial", 10f, FontStyle.Bold | FontStyle.Italic), true);
             * //    row0.Cells[3].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
             * //    row0.Cells[3].Style.BackgroundBrush = PdfBrushes.LightGreen;
             *
             *
             * row0.Cells[4].Value = "Amount [AED]";
             * //  row1.Cells[4].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
             * //  row1.Cells[4].ColumnSpan = 4;
             *
             * row1.Cells[0].Value = "This is an Item yo";
             * row1.Cells[0].ColumnSpan = 2; */


            //save the file
            doc.SaveToFile("Invoice.pdf");

/*
 *          PdfDocument destDoc = new PdfDocument();
 *          float top = 20;
 *          float bottom = 20;
 *          float left = 20;
 *          float right = 20;
 *
 *          foreach (PdfPageBase page in doc.Pages)
 *                  {
 *                  PdfPageBase newPage = destDoc.Pages.Add(page.Size, new PdfMargins(0));
 *                  newPage.Canvas.ScaleTransform((page.ActualSize.Width - left - right) / page.ActualSize.Width,
 *                      (page.ActualSize.Height - top - bottom) / page.ActualSize.Height);
 *                  newPage.Canvas.DrawTemplate(page.CreateTemplate(), new PointF(left, top));
 *                  }
 *
 *          destDoc.SaveToFile("result.pdf", FileFormat.PDF);*/



            // System.Diagnostics.Process.Start("PdfHeader.pdf");

            //let the user save it and open it and yeah
            // save the file with a unique name each time -- why? let it get over written each time np

            // return Page();
            using (var fileStream = new FileStream(Path.Combine(fileName), FileMode.Open))
            {
                await fileStream.CopyToAsync(memoryStream);
            }
            memoryStream.Position = 0;
            return(File(memoryStream, "application/pdf", fileName));
        }