PIbd-22. Stroev V.M. Lab Work 04 #4
@ -95,6 +95,7 @@
|
||||
компонентыПоРаботамToolStripMenuItem.Name = "компонентыПоРаботамToolStripMenuItem";
|
||||
компонентыПоРаботамToolStripMenuItem.Size = new Size(268, 26);
|
||||
компонентыПоРаботамToolStripMenuItem.Text = "Компоненты по работам";
|
||||
компонентыПоРаботамToolStripMenuItem.Click += компонентыПоРаботамToolStripMenuItem_Click;
|
||||
//
|
||||
// списокЗаказовToolStripMenuItem
|
||||
//
|
||||
|
@ -204,5 +204,14 @@ namespace PlumbingRepairView
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void компонентыПоРаботамToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormReportWorkComponents));
|
||||
if (service is FormReportWorkComponents form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -74,6 +74,7 @@
|
||||
button1.TabIndex = 1;
|
||||
button1.Text = "Сохранить в Excel";
|
||||
button1.UseVisualStyleBackColor = true;
|
||||
button1.Click += ButtonSaveToExcel_Click;
|
||||
//
|
||||
// FormReportWorkComponents
|
||||
//
|
||||
@ -84,6 +85,7 @@
|
||||
Controls.Add(dataGridView);
|
||||
Name = "FormReportWorkComponents";
|
||||
Text = "FormReportWorkComponent";
|
||||
Load += FormReportProductComponents_Load;
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
@ -28,14 +28,14 @@ namespace PlumbingRepairView
|
||||
{
|
||||
try
|
||||
{
|
||||
var dict = _logic.GetProductComponent();
|
||||
var dict = _logic.GetWorkComponent();
|
||||
if (dict != null)
|
||||
{
|
||||
dataGridView.Rows.Clear();
|
||||
foreach (var elem in dict)
|
||||
{
|
||||
dataGridView.Rows.Add(new object[] { elem.ComponentName, "", "" });
|
||||
foreach (var listElem in elem.Works)
|
||||
dataGridView.Rows.Add(new object[] { elem.WorkName, "", "" });
|
||||
foreach (var listElem in elem.Components)
|
||||
{
|
||||
dataGridView.Rows.Add(new object[] { "", listElem.Item1, listElem.Item2 });
|
||||
}
|
||||
@ -64,7 +64,7 @@ namespace PlumbingRepairView
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.SaveProductComponentToExcelFile(new ReportBindingModel
|
||||
_logic.SaveWorkComponentToExcelFile(new ReportBindingModel
|
||||
{
|
||||
FileName = dialog.FileName
|
||||
});
|
||||
|
@ -126,13 +126,4 @@
|
||||
<metadata name="Count.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="ComponentName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="WorkName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="Count.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
</root>
|
@ -2,6 +2,8 @@ using PlumbingRepairContracts.BusinessLogicsContracts;
|
||||
using PlumbingRepairBusinessLogic.OfficePackage.Implements;
|
||||
using PlumbingRepairBusinessLogic.OfficePackage;
|
||||
using PlumbingRepairContracts.StoragesContracts;
|
||||
using PlumbingRepairBusinessLogic.OfficePackage.Implements;
|
||||
using PlumbingRepairBusinessLogic.OfficePackage;
|
||||
using PlumbingRepairDataBaseImplement.Implements;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
@ -33,15 +33,15 @@
|
||||
<DataField>Sum</DataField>
|
||||
<rd:TypeName>System.Decimal</rd:TypeName>
|
||||
</Field>
|
||||
<Field Name="Status">
|
||||
<DataField>Status</DataField>
|
||||
<rd:TypeName>PlumbingRepairDataModels.Status</rd:TypeName>
|
||||
<Field Name="OrderStatus">
|
||||
<DataField>OrderStatus</DataField>
|
||||
<rd:TypeName>PlumbingRepairDataModels.OrderStatus</rd:TypeName>
|
||||
</Field>
|
||||
</Fields>
|
||||
<rd:DataSetInfo>
|
||||
<rd:DataSetName>PlumbingRepairContracts.ViewModels</rd:DataSetName>
|
||||
<rd:TableName>ReportOrderViewModel</rd:TableName>
|
||||
<rd:ObjectDataSourceType>PlumbingRepairContracts.ViewModels.ReportOrderViewModel, PlumbingRepairContracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</rd:ObjectDataSourceType>
|
||||
<rd:TableName>ReportOrdersViewModel</rd:TableName>
|
||||
<rd:ObjectDataSourceType>PlumbingRepairContracts.ViewModels.ReportOrdersViewModel, PlumbingRepairContracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</rd:ObjectDataSourceType>
|
||||
</rd:DataSetInfo>
|
||||
</DataSet>
|
||||
</DataSets>
|
||||
@ -398,21 +398,21 @@
|
||||
</TablixCell>
|
||||
<TablixCell>
|
||||
<CellContents>
|
||||
<Textbox Name="Status">
|
||||
<Textbox Name="OrderStatus">
|
||||
<CanGrow>true</CanGrow>
|
||||
<KeepTogether>true</KeepTogether>
|
||||
<Paragraphs>
|
||||
<Paragraph>
|
||||
<TextRuns>
|
||||
<TextRun>
|
||||
<Value>=Fields!Status.Value</Value>
|
||||
<Value>=Fields!OrderStatus.Value</Value>
|
||||
<Style />
|
||||
</TextRun>
|
||||
</TextRuns>
|
||||
<Style />
|
||||
</Paragraph>
|
||||
</Paragraphs>
|
||||
<rd:DefaultName>Status</rd:DefaultName>
|
||||
<rd:DefaultName>OrderStatus</rd:DefaultName>
|
||||
<Style>
|
||||
<Border>
|
||||
<Color>LightGrey</Color>
|
||||
|
@ -15,7 +15,6 @@ namespace PlumbingRepairBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class ReportLogic : IReportLogic
|
||||
{
|
||||
private readonly IComponentStorage _componentStorage;
|
||||
private readonly IWorkStorage _workStorage;
|
||||
private readonly IOrderStorage _orderStorage;
|
||||
private readonly AbstractSaveToExcel _saveToExcel;
|
||||
@ -27,72 +26,66 @@ namespace PlumbingRepairBusinessLogic.BusinessLogics
|
||||
AbstractSaveToPdf saveToPdf)
|
||||
{
|
||||
_workStorage = workStorage;
|
||||
_componentStorage = componentStorage;
|
||||
_orderStorage = orderStorage;
|
||||
|
||||
_saveToExcel = saveToExcel;
|
||||
_saveToWord = saveToWord;
|
||||
_saveToPdf = saveToPdf;
|
||||
}
|
||||
public List<ReportWorkComponentViewModel> GetProductComponent()
|
||||
public List<ReportWorkComponentViewModel> GetWorkComponent()
|
||||
{
|
||||
var components = _componentStorage.GetFullList();
|
||||
var products = _workStorage.GetFullList();
|
||||
var Works = _workStorage.GetFullList();
|
||||
|
||||
var list = new List<ReportWorkComponentViewModel>();
|
||||
foreach (var component in components)
|
||||
|
||||
foreach (var work in Works)
|
||||
{
|
||||
var record = new ReportWorkComponentViewModel
|
||||
{
|
||||
ComponentName = component.ComponentName,
|
||||
Works = new List<Tuple<string, int>>(),
|
||||
TotalCount = 0
|
||||
WorkName = work.WorkName,
|
||||
Components = new List<(string Component, int Count)>(),
|
||||
TotalCount = 0,
|
||||
};
|
||||
foreach (var product in products)
|
||||
foreach (var component in work.WorkComponents)
|
||||
{
|
||||
if (product.WorkComponents.ContainsKey(component.Id))
|
||||
{
|
||||
record.Works.Add(new Tuple<string,
|
||||
int>(product.WorkName, product.WorkComponents[component.Id].Item2));
|
||||
record.TotalCount +=
|
||||
product.WorkComponents[component.Id].Item2;
|
||||
}
|
||||
record.Components.Add(new(component.Value.Item1.ComponentName, component.Value.Item2));
|
||||
record.TotalCount += component.Value.Item2;
|
||||
}
|
||||
|
||||
list.Add(record);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
public List<ReportOrdersViewModel> GetOrders(ReportBindingModel model)
|
||||
{
|
||||
return _orderStorage.GetFilteredList(new OrderSearchModel
|
||||
{
|
||||
DateFrom
|
||||
= model.DateFrom,
|
||||
DateTo = model.DateTo
|
||||
})
|
||||
.Select(x => new ReportOrdersViewModel
|
||||
{
|
||||
Id = x.Id,
|
||||
DateCreate = x.DateCreate,
|
||||
WorkName = x.WorkName,
|
||||
Sum = x.Sum
|
||||
})
|
||||
.ToList();
|
||||
return _orderStorage.GetFilteredList(new OrderSearchModel { DateFrom = model.DateFrom, DateTo = model.DateTo })
|
||||
.Select(x => new ReportOrdersViewModel
|
||||
{
|
||||
Id = x.Id,
|
||||
DateCreate = x.DateCreate,
|
||||
WorkName = x.WorkName,
|
||||
OrderStatus = x.Status.ToString(),
|
||||
Sum = x.Sum
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
public void SaveComponentsToWordFile(ReportBindingModel model)
|
||||
public void SaveWorksToWordFile(ReportBindingModel model)
|
||||
{
|
||||
_saveToWord.CreateDoc(new WordInfo
|
||||
{
|
||||
FileName = model.FileName,
|
||||
Title = "Список компонент",
|
||||
Components = _componentStorage.GetFullList()
|
||||
Works = _workStorage.GetFullList()
|
||||
});
|
||||
}
|
||||
public void SaveProductComponentToExcelFile(ReportBindingModel model)
|
||||
public void SaveWorkComponentToExcelFile(ReportBindingModel model)
|
||||
{
|
||||
_saveToExcel.CreateReport(new ExcelInfo
|
||||
{
|
||||
FileName = model.FileName,
|
||||
Title = "Список компонент",
|
||||
WorkComponents = GetProductComponent()
|
||||
WorkComponents = GetWorkComponent()
|
||||
});
|
||||
}
|
||||
public void SaveOrdersToPdfFile(ReportBindingModel model)
|
||||
|
@ -26,23 +26,23 @@ namespace PlumbingRepairBusinessLogic.OfficePackage
|
||||
CellToName = "C1"
|
||||
});
|
||||
uint rowIndex = 2;
|
||||
foreach (var pc in info.WorkComponents)
|
||||
foreach (var wk in info.WorkComponents)
|
||||
{
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "A",
|
||||
RowIndex = rowIndex,
|
||||
Text = pc.ComponentName,
|
||||
Text = wk.WorkName,
|
||||
StyleInfo = ExcelStyleInfoType.Text
|
||||
});
|
||||
rowIndex++;
|
||||
foreach (var product in pc.Works)
|
||||
foreach (var (Component, Count) in wk.Components)
|
||||
{
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "B",
|
||||
RowIndex = rowIndex,
|
||||
Text = product.Item1,
|
||||
Text = Component,
|
||||
StyleInfo =
|
||||
ExcelStyleInfoType.TextWithBroder
|
||||
});
|
||||
@ -50,7 +50,7 @@ namespace PlumbingRepairBusinessLogic.OfficePackage
|
||||
{
|
||||
ColumnName = "C",
|
||||
RowIndex = rowIndex,
|
||||
Text = product.Item2.ToString(),
|
||||
Text = Count.ToString(),
|
||||
StyleInfo =
|
||||
ExcelStyleInfoType.TextWithBroder
|
||||
});
|
||||
@ -67,7 +67,7 @@ namespace PlumbingRepairBusinessLogic.OfficePackage
|
||||
{
|
||||
ColumnName = "C",
|
||||
RowIndex = rowIndex,
|
||||
Text = pc.TotalCount.ToString(),
|
||||
Text = wk.TotalCount.ToString(),
|
||||
StyleInfo = ExcelStyleInfoType.Text
|
||||
});
|
||||
rowIndex++;
|
||||
|
@ -23,12 +23,12 @@ WordTextProperties { Bold = true, Size = "24", }) },
|
||||
JustificationType = WordJustificationType.Center
|
||||
}
|
||||
});
|
||||
foreach (var component in info.Components)
|
||||
foreach (var work in info.Works)
|
||||
{
|
||||
CreateParagraph(new WordParagraph
|
||||
{
|
||||
Texts = new List<(string, WordTextProperties)> {
|
||||
(component.ComponentName, new WordTextProperties { Size = "24", }) },
|
||||
(work.WorkName, new WordTextProperties { Size = "24", }) },
|
||||
TextProperties = new WordTextProperties
|
||||
{
|
||||
Size = "24",
|
||||
|
@ -11,6 +11,6 @@ namespace PlumbingRepairBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
public string Title { get; set; } = string.Empty;
|
||||
public List<ComponentViewModel> Components { get; set; } = new();
|
||||
public List<WorkViewModel> Works { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ namespace PlumbingRepairContracts.BindingModels
|
||||
public class ReportBindingModel
|
||||
{
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
public DateTime? DateFrom { get; set; }
|
||||
public DateTime? DateFrom { get; set; } = DateTime.SpecifyKind(, DateTimeKind.Utc);
|
||||
public DateTime? DateTo { get; set; }
|
||||
|
||||
}
|
||||
|
@ -10,10 +10,10 @@ namespace PlumbingRepairContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IReportLogic
|
||||
{
|
||||
List<ReportWorkComponentViewModel> GetProductComponent();
|
||||
List<ReportWorkComponentViewModel> GetWorkComponent();
|
||||
List<ReportOrdersViewModel> GetOrders(ReportBindingModel model);
|
||||
void SaveComponentsToWordFile(ReportBindingModel model);
|
||||
void SaveProductComponentToExcelFile(ReportBindingModel model);
|
||||
void SaveWorksToWordFile(ReportBindingModel model);
|
||||
void SaveWorkComponentToExcelFile(ReportBindingModel model);
|
||||
void SaveOrdersToPdfFile(ReportBindingModel model);
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ namespace PlumbingRepairContracts.ViewModels
|
||||
[DisplayName("Статус")]
|
||||
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
|
||||
[DisplayName("Дата создания")]
|
||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||
public DateTime DateCreate { get; set; } = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
|
||||
[DisplayName("Дата выполнения")]
|
||||
public DateTime? DateImplement { get; set; }
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ namespace PlumbingRepairContracts.ViewModels
|
||||
public int Id { get; set; }
|
||||
public DateTime DateCreate { get; set; }
|
||||
public string WorkName { get; set; } = string.Empty;
|
||||
public string OrderStatus { get; set; } = string.Empty;
|
||||
public double Sum { get; set; }
|
||||
|
||||
}
|
||||
|
@ -8,8 +8,8 @@ namespace PlumbingRepairContracts.ViewModels
|
||||
{
|
||||
public class ReportWorkComponentViewModel
|
||||
{
|
||||
public string ComponentName { get; set; } = string.Empty;
|
||||
public string WorkName { get; set; } = string.Empty;
|
||||
public int TotalCount { get; set; }
|
||||
public List<Tuple<string, int>> Works { get; set; } = new();
|
||||
public List<(string Component, int Count)> Components { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using PlumbingRepairContracts.BindingModels;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PlumbingRepairContracts.BindingModels;
|
||||
using PlumbingRepairContracts.SearchModels;
|
||||
using PlumbingRepairContracts.StoragesContracts;
|
||||
using PlumbingRepairContracts.ViewModels;
|
||||
@ -22,13 +23,22 @@ namespace PlumbingRepairDataBaseImplement.Implements
|
||||
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
if (!model.Id.HasValue && !model.DateFrom.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
|
||||
using var context = new PlumbingRepairDataBase();
|
||||
|
||||
if (model.DateFrom.HasValue)
|
||||
{
|
||||
return context.Orders
|
||||
.Include(x => x.Work)
|
||||
.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return context.Orders.Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@ namespace PlumbingRepairDataBaseImplement.Models
|
||||
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
|
||||
|
||||
[Required]
|
||||
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
||||
public DateTime DateCreate { get; private set; } = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
|
||||
|
||||
public DateTime? DateImplement { get; private set; }
|
||||
|
||||
|
@ -27,7 +27,7 @@ namespace PlumbingRepairFileImplement.Implements
|
||||
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
if (!model.Id.HasValue && !model.DateFrom.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ namespace PlumbingRepairFileImplement.Models
|
||||
public int Count { get; private set; }
|
||||
public double Sum { get; private set; }
|
||||
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
|
||||
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
||||
public DateTime DateCreate { get; private set; } = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
|
||||
public DateTime? DateImplement { get; private set; }
|
||||
|
||||
public static Order? Create(OrderBindingModel? model)
|
||||
|
@ -18,7 +18,7 @@ namespace PlumbingRepairListImplement.Models
|
||||
public int Count { get; private set; }
|
||||
public double Sum { get; private set; }
|
||||
public OrderStatus Status { get; private set; }
|
||||
public DateTime DateCreate { get; private set; }
|
||||
public DateTime DateCreate { get; private set; } = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
|
||||
public DateTime? DateImplement { get; private set; }
|
||||
public static Order? Create(OrderBindingModel? model)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user