Reports.xaml.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using Namordnik.Class;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Navigation;
  15. using System.Windows.Shapes;
  16. using Word = Microsoft.Office.Interop.Word;
  17. namespace Namordnik.Pages
  18. {
  19. /// <summary>
  20. /// Логика взаимодействия для Reports.xaml
  21. /// </summary>
  22. public partial class Reports : Page
  23. {
  24. public Reports()
  25. {
  26. InitializeComponent();
  27. }
  28. private void BtnRepProd_Click(object sender, RoutedEventArgs e)
  29. {
  30. List<Product> PR = BaseClass.Base.Product.ToList();
  31. var application = new Word.Application();
  32. Word.Document document = application.Documents.Add();
  33. foreach(var product in PR)
  34. {
  35. Word.Paragraph prodParagraf = document.Paragraphs.Add();
  36. Word.Range prodTitleRange = prodParagraf.Range;
  37. prodTitleRange.Text = product.Title;
  38. prodTitleRange.InsertParagraphAfter();
  39. Word.Paragraph paragraphTable = document.Paragraphs.Add();
  40. Word.Range rangeTable = paragraphTable.Range;
  41. Word.Table paymentsTable = document.Tables.Add(rangeTable, 2,3);
  42. paymentsTable.Borders.InsideLineStyle = paymentsTable.Borders.OutsideLineStyle = Word.WdLineStyle.wdLineStyleSingle;
  43. paymentsTable.Range.Cells.VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
  44. Word.Range cellRange;
  45. cellRange = paymentsTable.Cell(1, 1).Range;
  46. cellRange.Text = "Изображение продукции";
  47. cellRange = paymentsTable.Cell(1, 2).Range;
  48. cellRange.Text = "Тип продукции";
  49. cellRange = paymentsTable.Cell(1, 3).Range;
  50. cellRange.Text = "Артикул";
  51. paymentsTable.Rows[1].Range.Bold = 1;
  52. paymentsTable.Rows[1].Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
  53. string path = "/Resources/picture.png";
  54. cellRange = paymentsTable.Cell(2, 1).Range;
  55. if (product.Image != null)
  56. {
  57. Word.InlineShape ImageShape = cellRange.InlineShapes.AddPicture(AppDomain.CurrentDomain.BaseDirectory + "..\\.." + product.Image);
  58. cellRange.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
  59. ImageShape.Width = ImageShape.Height = 50;
  60. }
  61. else
  62. {
  63. Word.InlineShape ImageShape = cellRange.InlineShapes.AddPicture(AppDomain.CurrentDomain.BaseDirectory + "..\\.." + path);
  64. cellRange.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
  65. ImageShape.Width = ImageShape.Height = 50;
  66. }
  67. cellRange = paymentsTable.Cell(2, 2).Range;
  68. cellRange.Text = product.ProductType.Title;
  69. cellRange = paymentsTable.Cell(2, 3).Range;
  70. cellRange.Text = product.ArticleNumber;
  71. }
  72. application.Visible = true;
  73. //document.SaveAs2(@"\\main\RDP\43П\мелузовна\Desktop\Практика\Test.docx");
  74. }
  75. private void BtnRepMat_Click(object sender, RoutedEventArgs e)
  76. {
  77. }
  78. }
  79. }