Esempio n. 1
0
        private void BtnGenerate_Click(object sender, RoutedEventArgs e)
        {
            var currentSales = AppData.context.Sales.ToList();

            if (PickerStart.SelectedDate.HasValue == true)
            {
                currentSales = currentSales.Where(p => p.DateOfSale >= PickerStart.SelectedDate.Value).ToList();
            }
            if (PickerEnd.SelectedDate.HasValue == true)
            {
                currentSales = currentSales.Where(p => p.DateOfSale <= PickerEnd.SelectedDate.Value).ToList();
            }

            var result = new StringBuilder();


            result.Append("<html>");
            result.Append("<meta charset='utf-8'/>");
            result.Append("<body>");


            result.Append("<p align='center'> <b>Отчет по продажам</b> </p>");


            result.Append("<table width=100% border=1 bordercolor=#000 style='border-collapse:collapse;'>");


            result.Append("<tr>");

            result.Append("<td align=center><b>Код продажи</b></td>");
            result.Append("<td align=center><b>Клиент</b></td>");
            result.Append("<td align=center><b>Товар</b></td>");
            result.Append("<td align=center><b>Дата продажи</b></td>");
            result.Append("<td align=center><b>Количество</b></td>");
            result.Append("<td align=center><b>Цена</b></td>");
            result.Append("</tr>");


            foreach (var item in currentSales)
            {
                result.Append("<tr>");

                result.Append($"<td align=center>{item.idSale}</td>");
                result.Append($"<td align=center>{item.Client}</td>");
                result.Append($"<td align=center>{item.Product.Name}</td>");
                result.Append($"<td align=center>{item.DateOfSale.ToString("dd.MM.yyyy")}</td>");
                result.Append($"<td align=center>{item.Quantity}</td>");
                result.Append($"<td align=center>{item.Price} руб.</td>");
                result.Append("</tr>");
            }


            result.Append("</table>");
            result.Append("</body>");
            result.Append("</html>");


            BrowserReport.NavigateToString(result.ToString());
        }
        public PrintServicesPage()
        {
            InitializeComponent();
            var listOfWorkers = AppData.Context.Workers.ToList();
            var result        = new StringBuilder();

            // Основные теги перед генерацией таблицы.
            result.Append("<html>");
            result.Append("<meta charset='utf-8'/>");
            result.Append("<body>");
            // Заголовок отчета.
            result.Append("<p align='center'> <b>Отчет по сотрудникам сайта</b> </p>");
            // Тег с параметрами таблицы.
            result.Append("<table width=100% border=1 bordercolor=#000 style='border-collapse:collapse;'>");
            // Настройка строк и столбцов внутри. tr - строка, td - столбец.
            result.Append("<tr>");
            // Необходимые заголовки таблицы.
            result.Append("<td align=center><b>Код</b></td>");
            result.Append("<td align=center><b>Фамилия Имя Отчество</b></td>");
            result.Append("<td align=center><b>Дата</b></td>");
            result.Append("<td align=center><b>Время</b></td>");
            result.Append("<td align=center><b>Должность</b></td>");
            result.Append("<td align=center><b>Зарплата</b></td>");
            result.Append("</tr>");
            // Генерация содержимого через цикл.
            foreach (var item in listOfWorkers)
            {
                // Настройка строк и столбцов внутри. tr - строка, td - столбец.
                result.Append("<tr>");
                // Обращение к переменной item и получение необходимого свойства в соответствии с заголовком.
                result.Append($"<td align=center>{item.Id_Worker}</td>");
                result.Append($"<td align=center>{item.FIO}</td>");
                result.Append($"<td align=center>{item.DateOfBirth.ToString("dd.MM.yyyy")}</td>");
                result.Append($"<td align=center>{item.TimeOfBirth.ToString()} руб.</td>");
                result.Append($"<td align=center>{item.WorkersPosition.PositionName}</td>");
                result.Append($"<td align=center>{item.Salary}</td>");
                result.Append("</tr>");
            }
            // Закрытие основных тегов.
            result.Append("</table>");
            result.Append("</body>");
            result.Append("</html>");
            // Загрузка отчета в WebBrowser.
            BrowserReport.NavigateToString(result.ToString());
        }