осталось сдать

This commit is contained in:
maxnes3 2023-03-14 10:57:29 +04:00
parent a8cd32adeb
commit 358a4a70ea
6 changed files with 14 additions and 13 deletions

View File

@ -102,8 +102,8 @@ namespace ComputersShopBusinessLogic.BusinessLogics
{ {
FileName = model.FileName, FileName = model.FileName,
Title = "Список заказов", Title = "Список заказов",
DateFrom = model.DateFrom!.Value, DateFrom = DateTime.SpecifyKind(model.DateFrom!.Value, DateTimeKind.Utc),
DateTo = model.DateTo!.Value, DateTo = DateTime.SpecifyKind(model.DateTo!.Value, DateTimeKind.Utc),
Orders = GetOrders(model) Orders = GetOrders(model)
}); });
} }

View File

@ -45,14 +45,14 @@ namespace ComputersShopDataBaseImplement.Implements
public List<OrderViewModel> GetFilteredList(OrderSearchModel model) public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{ {
if (!model.Id.HasValue) if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue)
{ {
return new(); return new();
} }
using var context = new ComputersShopDataBase(); using var context = new ComputersShopDataBase();
return context.Orders.Where(x => x.Id == model.Id).Select(x => GetViewModel(x)).ToList(); return context.Orders.Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo).Select(x => GetViewModel(x)).ToList();
} }
public List<OrderViewModel> GetFullList() public List<OrderViewModel> GetFullList()

View File

@ -31,11 +31,11 @@ namespace ComputersShopFileImplement.Implements
public List<OrderViewModel> GetFilteredList(OrderSearchModel model) public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{ {
if (!model.Id.HasValue) if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue)
{ {
return new(); return new();
} }
return source.Orders.Where(x => x.Id == model.Id).Select(x => GetViewModel(x)).ToList(); return source.Orders.Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo).Select(x => GetViewModel(x)).ToList();
} }
public List<OrderViewModel> GetFullList() public List<OrderViewModel> GetFullList()

View File

@ -37,7 +37,7 @@ namespace OrdersShopListImplement.Implements
} }
foreach (var Order in _source.Orders) foreach (var Order in _source.Orders)
{ {
if (Order.Id == model.Id) if (Order.Id == model.Id || model.DateFrom <= Order.DateCreate && Order.DateCreate <= model.DateTo)
{ {
result.Add(GetViewModel(Order)); result.Add(GetViewModel(Order));
} }

View File

@ -18,6 +18,7 @@
<PackageReference Include="NLog" Version="5.1.1" /> <PackageReference Include="NLog" Version="5.1.1" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.1" /> <PackageReference Include="NLog.Extensions.Logging" Version="5.2.1" />
<PackageReference Include="ReportViewerCore.WinForms" Version="15.1.17" /> <PackageReference Include="ReportViewerCore.WinForms" Version="15.1.17" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="7.0.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -8,7 +8,6 @@ using System.ComponentModel;
using System.Data; using System.Data;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
@ -31,7 +30,7 @@ namespace ComputersShopView
{ {
Dock = DockStyle.Fill Dock = DockStyle.Fill
}; };
reportViewer.LocalReport.LoadReportDefinition(new FileStream("ReportOrders.rdlc", FileMode.Open)); reportViewer.LocalReport.LoadReportDefinition(new FileStream(@"D:\Учёба\РПП\PIbd-22_Bondarenko_M.S._ComputersShop\ComputersShop\ComputersShopView\ReportOrders.rdlc", FileMode.Open));
Controls.Clear(); Controls.Clear();
Controls.Add(reportViewer); Controls.Add(reportViewer);
Controls.Add(panel); Controls.Add(panel);
@ -48,8 +47,8 @@ namespace ComputersShopView
{ {
var dataSource = _logic.GetOrders(new ReportBindingModel var dataSource = _logic.GetOrders(new ReportBindingModel
{ {
DateFrom = dateTimePickerFrom.Value, DateFrom = DateTime.SpecifyKind(dateTimePickerFrom.Value, DateTimeKind.Utc),
DateTo = dateTimePickerTo.Value DateTo = DateTime.SpecifyKind(dateTimePickerTo.Value, DateTimeKind.Utc)
}); });
var source = new ReportDataSource("DataSetOrders", dataSource); var source = new ReportDataSource("DataSetOrders", dataSource);
reportViewer.LocalReport.DataSources.Clear(); reportViewer.LocalReport.DataSources.Clear();
@ -70,6 +69,7 @@ namespace ComputersShopView
private void ButtonToPdf_Click(object sender, EventArgs e) private void ButtonToPdf_Click(object sender, EventArgs e)
{ {
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
if (dateTimePickerFrom.Value.Date >= dateTimePickerTo.Value.Date) if (dateTimePickerFrom.Value.Date >= dateTimePickerTo.Value.Date)
{ {
MessageBox.Show("Дата начала должна быть меньше даты окончания", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("Дата начала должна быть меньше даты окончания", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
@ -83,8 +83,8 @@ namespace ComputersShopView
_logic.SaveOrdersToPdfFile(new ReportBindingModel _logic.SaveOrdersToPdfFile(new ReportBindingModel
{ {
FileName = dialog.FileName, FileName = dialog.FileName,
DateFrom = dateTimePickerFrom.Value, DateFrom = DateTime.SpecifyKind(dateTimePickerFrom.Value, DateTimeKind.Utc),
DateTo = dateTimePickerTo.Value DateTo = DateTime.SpecifyKind(dateTimePickerTo.Value, DateTimeKind.Utc)
}); });
_logger.LogInformation("Сохранение списка заказов на период {From}-{To}", dateTimePickerFrom.Value.ToShortDateString(), dateTimePickerTo.Value.ToShortDateString()); _logger.LogInformation("Сохранение списка заказов на период {From}-{To}", dateTimePickerFrom.Value.ToShortDateString(), dateTimePickerTo.Value.ToShortDateString());
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);