public IHttpActionResult GetCustomerBookings(BoundReportModel model) { var list = _service.GetCustomerBookings(model); if (list == null) { InternalServerError(new Exception("Нет данных")); } return(Ok(list)); }
public List <ModelCustomerBookingsView> GetCustomerBookings(BoundReportModel model) { return(context.Bookings .Include(rec => rec.Customer) .Include(rec => rec.Output) .Where(rec => rec.DateOfCreate >= model.DateFrom && rec.DateOfCreate <= model.DateTo) .Select(rec => new ModelCustomerBookingsView { CustomerName = rec.Customer.CustomerFullName, DateOfCreate = SqlFunctions.DateName("dd", rec.DateOfCreate) + " " + SqlFunctions.DateName("mm", rec.DateOfCreate) + " " + SqlFunctions.DateName("yyyy", rec.DateOfCreate), OutputName = rec.Output.OutputName, Count = rec.Count, Sum = rec.Summa, Status = rec.Status.ToString() }) .ToList()); }
public void SaveCustomerBookings(BoundReportModel model) { _service.SaveCustomerBookings(model); }
public void SaveReservesLoad(BoundReportModel model) { _service.SaveReservesLoad(model); }
public void SaveOutputPrice(BoundReportModel model) { _service.SaveOutputPrice(model); }
public void SaveOutputPrice(BoundReportModel model) { if (File.Exists(model.FileName)) { File.Delete(model.FileName); } var winword = new Microsoft.Office.Interop.Word.Application(); try { object missing = System.Reflection.Missing.Value; Microsoft.Office.Interop.Word.Document document = winword.Documents.Add(ref missing, ref missing, ref missing, ref missing); var paragraph = document.Paragraphs.Add(missing); var range = paragraph.Range; range.Text = "Прайс изделий"; var font = range.Font; font.Size = 16; font.Name = "Times New Roman"; font.Bold = 1; var paragraphFormat = range.ParagraphFormat; paragraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter; paragraphFormat.LineSpacingRule = WdLineSpacing.wdLineSpaceSingle; paragraphFormat.SpaceAfter = 10; paragraphFormat.SpaceBefore = 0; range.InsertParagraphAfter(); var Outputs = context.Outputs.ToList(); var paragraphTable = document.Paragraphs.Add(Type.Missing); var rangeTable = paragraphTable.Range; var table = document.Tables.Add(rangeTable, Outputs.Count, 2, ref missing, ref missing); font = table.Range.Font; font.Size = 14; font.Name = "Times New Roman"; var paragraphTableFormat = table.Range.ParagraphFormat; paragraphTableFormat.LineSpacingRule = WdLineSpacing.wdLineSpaceSingle; paragraphTableFormat.SpaceAfter = 0; paragraphTableFormat.SpaceBefore = 0; for (int i = 0; i < Outputs.Count; ++i) { table.Cell(i + 1, 1).Range.Text = Outputs[i].OutputName; table.Cell(i + 1, 2).Range.Text = Outputs[i].Price.ToString(); } table.Borders.InsideLineStyle = WdLineStyle.wdLineStyleInset; table.Borders.OutsideLineStyle = WdLineStyle.wdLineStyleSingle; paragraph = document.Paragraphs.Add(missing); range = paragraph.Range; range.Text = "Дата: " + DateTime.Now.ToLongDateString(); font = range.Font; font.Size = 12; font.Name = "Times New Roman"; paragraphFormat = range.ParagraphFormat; paragraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphRight; paragraphFormat.LineSpacingRule = WdLineSpacing.wdLineSpaceSingle; paragraphFormat.SpaceAfter = 10; paragraphFormat.SpaceBefore = 10; range.InsertParagraphAfter(); object fileFormat = WdSaveFormat.wdFormatXMLDocument; document.SaveAs(model.FileName, ref fileFormat, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); document.Close(ref missing, ref missing, ref missing); } catch (Exception) { throw; } finally { winword.Quit(); } }
public void SaveCustomerBookings(BoundReportModel model) { if (!File.Exists("TIMCYR.TTF")) { File.WriteAllBytes("TIMCYR.TTF", Properties.Resources.TIMCYR); } FileStream fs = new FileStream(model.FileName, FileMode.OpenOrCreate, FileAccess.Write); iTextSharp.text.Document doc = new iTextSharp.text.Document(); doc.SetMargins(0.5f, 0.5f, 0.5f, 0.5f); PdfWriter writer = PdfWriter.GetInstance(doc, fs); doc.Open(); BaseFont baseFont = BaseFont.CreateFont("TIMCYR.TTF", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); var phraseTitle = new Phrase("Заказы клиентов", new iTextSharp.text.Font(baseFont, 16, iTextSharp.text.Font.BOLD)); iTextSharp.text.Paragraph paragraph = new iTextSharp.text.Paragraph(phraseTitle) { Alignment = Element.ALIGN_CENTER, SpacingAfter = 12 }; doc.Add(paragraph); var phrasePeriod = new Phrase("c " + model.DateFrom.Value.ToShortDateString() + " по " + model.DateTo.Value.ToShortDateString(), new iTextSharp.text.Font(baseFont, 14, iTextSharp.text.Font.BOLD)); paragraph = new iTextSharp.text.Paragraph(phrasePeriod) { Alignment = Element.ALIGN_CENTER, SpacingAfter = 12 }; doc.Add(paragraph); PdfPTable table = new PdfPTable(6) { TotalWidth = 800F }; table.SetTotalWidth(new float[] { 160, 140, 160, 100, 100, 140 }); PdfPCell cell = new PdfPCell(); var fontForCellBold = new iTextSharp.text.Font(baseFont, 10, iTextSharp.text.Font.BOLD); table.AddCell(new PdfPCell(new Phrase("ФИО клиента", fontForCellBold)) { HorizontalAlignment = Element.ALIGN_CENTER }); table.AddCell(new PdfPCell(new Phrase("Дата создания", fontForCellBold)) { HorizontalAlignment = Element.ALIGN_CENTER }); table.AddCell(new PdfPCell(new Phrase("Изделие", fontForCellBold)) { HorizontalAlignment = Element.ALIGN_CENTER }); table.AddCell(new PdfPCell(new Phrase("Количество", fontForCellBold)) { HorizontalAlignment = Element.ALIGN_CENTER }); table.AddCell(new PdfPCell(new Phrase("Сумма", fontForCellBold)) { HorizontalAlignment = Element.ALIGN_CENTER }); table.AddCell(new PdfPCell(new Phrase("Статус", fontForCellBold)) { HorizontalAlignment = Element.ALIGN_CENTER }); var list = GetCustomerBookings(model); var fontForCells = new iTextSharp.text.Font(baseFont, 10); for (int i = 0; i < list.Count; i++) { cell = new PdfPCell(new Phrase(list[i].CustomerName, fontForCells)); table.AddCell(cell); cell = new PdfPCell(new Phrase(list[i].DateOfCreate, fontForCells)); table.AddCell(cell); cell = new PdfPCell(new Phrase(list[i].OutputName, fontForCells)); table.AddCell(cell); cell = new PdfPCell(new Phrase(list[i].Count.ToString(), fontForCells)); cell.HorizontalAlignment = Element.ALIGN_RIGHT; table.AddCell(cell); cell = new PdfPCell(new Phrase(list[i].Sum.ToString(), fontForCells)); cell.HorizontalAlignment = Element.ALIGN_RIGHT; table.AddCell(cell); cell = new PdfPCell(new Phrase(list[i].Status, fontForCells)); table.AddCell(cell); } cell = new PdfPCell(new Phrase("Итого:", fontForCellBold)) { HorizontalAlignment = Element.ALIGN_RIGHT, Colspan = 4, Border = 0 }; table.AddCell(cell); cell = new PdfPCell(new Phrase(list.Sum(rec => rec.Sum).ToString(), fontForCellBold)) { HorizontalAlignment = Element.ALIGN_RIGHT, Border = 0 }; table.AddCell(cell); cell = new PdfPCell(new Phrase("", fontForCellBold)) { Border = 0 }; table.AddCell(cell); doc.Add(table); doc.Close(); }
public void SaveReservesLoad(BoundReportModel model) { var excel = new Microsoft.Office.Interop.Excel.Application(); try { if (File.Exists(model.FileName)) { excel.Workbooks.Open(model.FileName, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); } else { excel.SheetsInNewWorkbook = 1; excel.Workbooks.Add(Type.Missing); excel.Workbooks[1].SaveAs(model.FileName, XlFileFormat.xlExcel8, Type.Missing, Type.Missing, false, false, XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); } Sheets excelsheets = excel.Workbooks[1].Worksheets; var excelworksheet = (Worksheet)excelsheets.get_Item(1); excelworksheet.Cells.Clear(); excelworksheet.PageSetup.Orientation = XlPageOrientation.xlLandscape; excelworksheet.PageSetup.CenterHorizontally = true; excelworksheet.PageSetup.CenterVertically = true; Microsoft.Office.Interop.Excel.Range excelcells = excelworksheet.get_Range("A1", "C1"); excelcells.Merge(Type.Missing); excelcells.Font.Bold = true; excelcells.Value2 = "Загруженность складов"; excelcells.RowHeight = 25; excelcells.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; excelcells.VerticalAlignment = Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter; excelcells.Font.Name = "Times New Roman"; excelcells.Font.Size = 14; excelcells = excelworksheet.get_Range("A2", "C2"); excelcells.Merge(Type.Missing); excelcells.Value2 = "на " + DateTime.Now.ToShortDateString(); excelcells.RowHeight = 20; excelcells.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; excelcells.VerticalAlignment = Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter; excelcells.Font.Name = "Times New Roman"; excelcells.Font.Size = 12; var dict = GetReservesLoad(); if (dict != null) { excelcells = excelworksheet.get_Range("C1", "C1"); foreach (var elem in dict) { excelcells = excelcells.get_Offset(2, -2); excelcells.ColumnWidth = 15; excelcells.Value2 = elem.ReserveName; excelcells = excelcells.get_Offset(1, 1); if (elem.Elements.Count() > 0) { var excelBorder = excelworksheet.get_Range(excelcells, excelcells.get_Offset(elem.Elements.Count() - 1, 1)); excelBorder.Borders.LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous; excelBorder.Borders.Weight = Microsoft.Office.Interop.Excel.XlBorderWeight.xlThin; excelBorder.HorizontalAlignment = Constants.xlCenter; excelBorder.VerticalAlignment = Constants.xlCenter; excelBorder.BorderAround(Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous, Microsoft.Office.Interop.Excel.XlBorderWeight.xlMedium, Microsoft.Office.Interop.Excel.XlColorIndex.xlColorIndexAutomatic, 1); foreach (var listElem in elem.Elements) { excelcells.Value2 = listElem.ElementName; excelcells.ColumnWidth = 10; excelcells.get_Offset(0, 1).Value2 = listElem.Count; excelcells = excelcells.get_Offset(1, 0); } } excelcells = excelcells.get_Offset(0, -1); excelcells.Value2 = "Итого"; excelcells.Font.Bold = true; excelcells = excelcells.get_Offset(0, 2); excelcells.Value2 = elem.TotalCount; excelcells.Font.Bold = true; } } excel.Workbooks[1].Save(); } catch (Exception) { throw; } finally { excel.Quit(); } }