diff --git a/TravelCompany/ImplementationExtensions/TravelCompanyContracts.dll b/TravelCompany/ImplementationExtensions/TravelCompanyContracts.dll new file mode 100644 index 0000000..4817eb1 Binary files /dev/null and b/TravelCompany/ImplementationExtensions/TravelCompanyContracts.dll differ diff --git a/TravelCompany/ImplementationExtensions/TravelCompanyDataModels.dll b/TravelCompany/ImplementationExtensions/TravelCompanyDataModels.dll new file mode 100644 index 0000000..cc8d889 Binary files /dev/null and b/TravelCompany/ImplementationExtensions/TravelCompanyDataModels.dll differ diff --git a/TravelCompany/ImplementationExtensions/TravelCompanyDatabaseImplement.dll b/TravelCompany/ImplementationExtensions/TravelCompanyDatabaseImplement.dll new file mode 100644 index 0000000..85163ef Binary files /dev/null and b/TravelCompany/ImplementationExtensions/TravelCompanyDatabaseImplement.dll differ diff --git a/TravelCompany/ImplementationExtensions/TravelCompanyFileImplement.dll b/TravelCompany/ImplementationExtensions/TravelCompanyFileImplement.dll new file mode 100644 index 0000000..d397f85 Binary files /dev/null and b/TravelCompany/ImplementationExtensions/TravelCompanyFileImplement.dll differ diff --git a/TravelCompany/ImplementationExtensions/TravelCompanyListImplement.dll b/TravelCompany/ImplementationExtensions/TravelCompanyListImplement.dll new file mode 100644 index 0000000..8931e15 Binary files /dev/null and b/TravelCompany/ImplementationExtensions/TravelCompanyListImplement.dll differ diff --git a/TravelCompany/TravelCompany/DataGridViewExtension.cs b/TravelCompany/TravelCompany/DataGridViewExtension.cs new file mode 100644 index 0000000..2e6919a --- /dev/null +++ b/TravelCompany/TravelCompany/DataGridViewExtension.cs @@ -0,0 +1,46 @@ +using TravelCompanyContracts.Attributes; + +namespace TravelCompany.Forms +{ + internal static class DataGridViewExtension + { + public static void FillAndConfigGrid(this DataGridView grid, List? data) + { + if (data == null) + { + return; + } + grid.DataSource = data; + + var type = typeof(T); + var properties = type.GetProperties(); + foreach (DataGridViewColumn column in grid.Columns) + { + var property = properties.FirstOrDefault(x => x.Name == column.Name); + if (property == null) + { + throw new InvalidOperationException($"В типе {type.Name} не найдено свойство с именем {column.Name}"); + } + var attribute = property.GetCustomAttributes(typeof(ColumnAttribute), true)?.SingleOrDefault(); + if (attribute == null) + { + throw new InvalidOperationException($"Не найден атрибут типа ColumnAttribute для свойства {property.Name}"); + } + + if (attribute is ColumnAttribute columnAttr) + { + column.HeaderText = columnAttr.Title; + column.Visible = columnAttr.Visible; + if (columnAttr.IsUseAutoSize) + { + column.AutoSizeMode = (DataGridViewAutoSizeColumnMode)Enum.Parse(typeof(DataGridViewAutoSizeColumnMode), columnAttr.GridViewAutoSize.ToString()); + } + else + { + column.Width = columnAttr.Width; + } + } + } + } + } +} diff --git a/TravelCompany/TravelCompany/FormClients.cs b/TravelCompany/TravelCompany/FormClients.cs index 5e4c35e..b3c7a34 100644 --- a/TravelCompany/TravelCompany/FormClients.cs +++ b/TravelCompany/TravelCompany/FormClients.cs @@ -28,18 +28,7 @@ namespace TravelCompany.Forms { try { - var list = _logic.ReadList(null); - if (list != null) - { - DataGridView.DataSource = list; - DataGridView.Columns["Id"].Visible = false; - DataGridView.Columns["ClientFIO"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - DataGridView.Columns["Email"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - DataGridView.Columns["Password"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - } + DataGridView.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка клиентов"); } catch (Exception ex) diff --git a/TravelCompany/TravelCompany/FormComponents.cs b/TravelCompany/TravelCompany/FormComponents.cs index 6fc3a44..39eafdd 100644 --- a/TravelCompany/TravelCompany/FormComponents.cs +++ b/TravelCompany/TravelCompany/FormComponents.cs @@ -10,6 +10,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using TravelCompanyContracts.DI; namespace TravelCompany.Forms { @@ -51,13 +52,10 @@ namespace TravelCompany.Forms private void buttonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); - if (service is FormComponent form) + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } @@ -65,14 +63,12 @@ namespace TravelCompany.Forms { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); - if (service is FormComponent form) + var form = DependencyManager.Instance.Resolve(); + + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) { - form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } } diff --git a/TravelCompany/TravelCompany/FormMain.Designer.cs b/TravelCompany/TravelCompany/FormMain.Designer.cs index 2f74bf1..77600c2 100644 --- a/TravelCompany/TravelCompany/FormMain.Designer.cs +++ b/TravelCompany/TravelCompany/FormMain.Designer.cs @@ -40,13 +40,14 @@ компонентыПоПутёвкамToolStripMenuItem = new ToolStripMenuItem(); списокЗаказовToolStripMenuItem = new ToolStripMenuItem(); запускРаботToolStripMenuItem = new ToolStripMenuItem(); + почтаToolStripMenuItem = new ToolStripMenuItem(); buttonCreateOrder = new Button(); buttonTakeOrderInWork = new Button(); buttonOrderReady = new Button(); buttonIssuedOrder = new Button(); buttonRef = new Button(); dataGridView = new DataGridView(); - почтаToolStripMenuItem = new ToolStripMenuItem(); + создатьБекапToolStripMenuItem = new ToolStripMenuItem(); toolStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); @@ -54,7 +55,7 @@ // toolStrip1 // toolStrip1.ImageScalingSize = new Size(20, 20); - toolStrip1.Items.AddRange(new ToolStripItem[] { toolStripDropDownButton1, отчетыToolStripMenuItem, запускРаботToolStripMenuItem, почтаToolStripMenuItem }); + toolStrip1.Items.AddRange(new ToolStripItem[] { toolStripDropDownButton1, отчетыToolStripMenuItem, запускРаботToolStripMenuItem, почтаToolStripMenuItem, создатьБекапToolStripMenuItem }); toolStrip1.Location = new Point(0, 0); toolStrip1.Name = "toolStrip1"; toolStrip1.Size = new Size(969, 25); @@ -74,28 +75,28 @@ // компонентыToolStripMenuItem // компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - компонентыToolStripMenuItem.Size = new Size(180, 22); + компонентыToolStripMenuItem.Size = new Size(174, 22); компонентыToolStripMenuItem.Text = "Компоненты"; компонентыToolStripMenuItem.Click += компонентыToolStripMenuItem_Click; // // ПутёвкиToolStripMenuItem // ПутёвкиToolStripMenuItem.Name = "ПутёвкиToolStripMenuItem"; - ПутёвкиToolStripMenuItem.Size = new Size(180, 22); + ПутёвкиToolStripMenuItem.Size = new Size(174, 22); ПутёвкиToolStripMenuItem.Text = "Туристич. путёвки"; ПутёвкиToolStripMenuItem.Click += консервыToolStripMenuItem_Click; // // клиентыToolStripMenuItem // клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; - клиентыToolStripMenuItem.Size = new Size(180, 22); + клиентыToolStripMenuItem.Size = new Size(174, 22); клиентыToolStripMenuItem.Text = "Клиенты"; клиентыToolStripMenuItem.Click += клиентыToolStripMenuItem_Click; // // исполнителиToolStripMenuItem // исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem"; - исполнителиToolStripMenuItem.Size = new Size(180, 22); + исполнителиToolStripMenuItem.Size = new Size(174, 22); исполнителиToolStripMenuItem.Text = "Исполнители"; исполнителиToolStripMenuItem.Click += исполнителиToolStripMenuItem_Click; // @@ -134,6 +135,13 @@ запускРаботToolStripMenuItem.Text = "Запуск работ"; запускРаботToolStripMenuItem.Click += запускРаботToolStripMenuItem_Click; // + // почтаToolStripMenuItem + // + почтаToolStripMenuItem.Name = "почтаToolStripMenuItem"; + почтаToolStripMenuItem.Size = new Size(53, 25); + почтаToolStripMenuItem.Text = "Почта"; + почтаToolStripMenuItem.Click += почтаToolStripMenuItem_Click; + // // buttonCreateOrder // buttonCreateOrder.Location = new Point(800, 56); @@ -196,12 +204,12 @@ dataGridView.Size = new Size(763, 435); dataGridView.TabIndex = 6; // - // почтаToolStripMenuItem + // создатьБекапToolStripMenuItem // - почтаToolStripMenuItem.Name = "почтаToolStripMenuItem"; - почтаToolStripMenuItem.Size = new Size(53, 25); - почтаToolStripMenuItem.Text = "Почта"; - почтаToolStripMenuItem.Click += почтаToolStripMenuItem_Click; + создатьБекапToolStripMenuItem.Name = "создатьБекапToolStripMenuItem"; + создатьБекапToolStripMenuItem.Size = new Size(97, 25); + создатьБекапToolStripMenuItem.Text = "Создать Бекап"; + создатьБекапToolStripMenuItem.Click += createBackUpToolStripMenuItem_Click; // // FormMain // @@ -245,5 +253,6 @@ private ToolStripMenuItem запускРаботToolStripMenuItem; private ToolStripMenuItem исполнителиToolStripMenuItem; private ToolStripMenuItem почтаToolStripMenuItem; + private ToolStripMenuItem создатьБекапToolStripMenuItem; } } \ No newline at end of file diff --git a/TravelCompany/TravelCompany/FormMain.cs b/TravelCompany/TravelCompany/FormMain.cs index a2e0865..69e7485 100644 --- a/TravelCompany/TravelCompany/FormMain.cs +++ b/TravelCompany/TravelCompany/FormMain.cs @@ -11,6 +11,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using TravelCompanyBusinessLogic.BusinessLogic; +using TravelCompanyContracts.DI; namespace TravelCompany.Forms { @@ -20,13 +21,17 @@ namespace TravelCompany.Forms private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; private readonly IWorkProcess _workProcess; - public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess) + private readonly IBackUpLogic _backUpLogic; + + public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess, IBackUpLogic backUpLogic) { InitializeComponent(); _logger = logger; _orderLogic = orderLogic; _reportLogic = reportLogic; _workProcess = workProcess; + _backUpLogic = backUpLogic; + } private void FormMain_Load(object sender, EventArgs e) { @@ -34,52 +39,32 @@ namespace TravelCompany.Forms } private void LoadData() { - _logger.LogInformation("Загрузка заказов"); try { - var list = _orderLogic.ReadList(null); - - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["TravelId"].Visible = false; - dataGridView.Columns["ClientId"].Visible = false; - dataGridView.Columns["ImplementerId"].Visible = false; - dataGridView.Columns["TravelName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - + dataGridView.FillAndConfigGrid(_orderLogic.ReadList(null)); _logger.LogInformation("Загрузка заказов"); } catch (Exception ex) { _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void компонентыToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); - if (service is FormComponents form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void консервыToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormTravels)); - - if (service is FormTravels form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void buttonCreateOrder_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); - if (service is FormCreateOrder form) - { - form.ShowDialog(); - LoadData(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + LoadData(); } private void buttonTakeOrderInWork_Click(object sender, EventArgs e) { @@ -164,72 +149,71 @@ namespace TravelCompany.Forms using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; if (dialog.ShowDialog() == DialogResult.OK) { - _reportLogic.SaveTravelsToWordFile(new ReportBindingModel - { - FileName = dialog.FileName - }); - MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, - MessageBoxIcon.Information); + _reportLogic.SaveTravelsToWordFile(new ReportBindingModel { FileName = dialog.FileName }); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); } } private void компонентыПоПутёвкамToolStripMenuItem_Click(object sender, EventArgs e) { - var service = -Program.ServiceProvider?.GetService(typeof(FormReportTravelComponents)); - if (service is FormReportTravelComponents form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void списокЗаказовToolStripMenuItem_Click(object sender, EventArgs e) { - var service = -Program.ServiceProvider?.GetService(typeof(FormReportOrders)); - if (service is FormReportOrders form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void клиентыToolStripMenuItem_Click(object sender, EventArgs e) { - var service = -Program.ServiceProvider?.GetService(typeof(FormClients)); - if (service is FormClients form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void запускРаботToolStripMenuItem_Click(object sender, EventArgs e) { - _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic -)) as IImplementerLogic)!, _orderLogic); - MessageBox.Show("Процесс обработки запущен", "Сообщение", - MessageBoxButtons.OK, MessageBoxIcon.Information); + _workProcess.DoWork(DependencyManager.Instance.Resolve(), _orderLogic); + MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); } private void исполнителиToolStripMenuItem_Click(object sender, EventArgs e) { - var service = -Program.ServiceProvider?.GetService(typeof(ImplementersForm)); - if (service is ImplementersForm form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void почтаToolStripMenuItem_Click(object sender, EventArgs e) { - var service = -Program.ServiceProvider?.GetService(typeof(FormViewMail)); - if (service is FormViewMail form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } + + private void createBackUpToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + if (_backUpLogic != null) + { + var fbd = new FolderBrowserDialog(); + if (fbd.ShowDialog() == DialogResult.OK) + { + _backUpLogic.CreateBackUp(new BackUpSaveBinidngModel + { + FolderName = fbd.SelectedPath + }); + MessageBox.Show("Бекап создан", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка создания бэкапа", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } } } diff --git a/TravelCompany/TravelCompany/FormTravel.cs b/TravelCompany/TravelCompany/FormTravel.cs index 2dd37b9..6b26778 100644 --- a/TravelCompany/TravelCompany/FormTravel.cs +++ b/TravelCompany/TravelCompany/FormTravel.cs @@ -12,6 +12,8 @@ using System.Windows.Forms; using TravelCompanyContracts.BusinessLogicsContracts; using TravelCompanyContracts.SearchModels; using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.DI; +using TravelCompanyDatabaseImplement.Models; namespace TravelCompany.Forms { @@ -20,14 +22,14 @@ namespace TravelCompany.Forms private readonly ILogger _logger; private readonly ITravelLogic _logic; private int? _id; - private Dictionary _productComponents; + private Dictionary _travelComponents; public int Id { set { _id = value; } } public FormTravel(ILogger logger, ITravelLogic logic) { InitializeComponent(); _logger = logger; _logic = logic; - _productComponents = new Dictionary(); + _travelComponents = new Dictionary(); } private void FormTravel_Load(object sender, EventArgs e) { @@ -44,7 +46,7 @@ namespace TravelCompany.Forms { textBoxName.Text = view.TravelName; textBoxPrice.Text = view.Price.ToString(); - _productComponents = view.TravelComponents ?? new Dictionary(); + _travelComponents = view.TravelComponents ?? new Dictionary(); LoadData(); } } @@ -59,10 +61,10 @@ namespace TravelCompany.Forms _logger.LogInformation("Загрузка компонент изделия"); try { - if (_productComponents != null) + if (_travelComponents != null) { dataGridView.Rows.Clear(); - foreach (var pc in _productComponents) + foreach (var pc in _travelComponents) { dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 }); } @@ -76,51 +78,44 @@ namespace TravelCompany.Forms } private void buttonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormTravelComponent)); - if (service is FormTravelComponent form) + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) { + return; + } + _logger.LogInformation("Добавление нового ингридиента:{ ComponentName}-{ Count}", form.ComponentModel.ComponentName, form.Count); + if (_travelComponents.ContainsKey(form.Id)) + { + _travelComponents[form.Id] = (form.ComponentModel, + form.Count); + } + else + { + _travelComponents.Add(form.Id, (form.ComponentModel, + form.Count)); + } + LoadData(); + } + private void buttonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var form = DependencyManager.Instance.Resolve(); + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _travelComponents[id].Item2; if (form.ShowDialog() == DialogResult.OK) { if (form.ComponentModel == null) { return; } - _logger.LogInformation("Добавление нового компонента: { ComponentName} - { Count} ", form.ComponentModel.ComponentName, form.Count); - if (_productComponents.ContainsKey(form.Id)) - { - _productComponents[form.Id] = (form.ComponentModel, form.Count); - } - else - { - _productComponents.Add(form.Id, (form.ComponentModel, form.Count)); - } + _logger.LogInformation("Изменение ингридиента:{ ComponentName}-{ Count}", form.ComponentModel.ComponentName, form.Count); + _travelComponents[form.Id] = (form.ComponentModel, form.Count); LoadData(); } } } - private void buttonUpd_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - var service = Program.ServiceProvider?.GetService(typeof(FormTravelComponent)); - if (service is FormTravelComponent form) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); - form.Id = id; - form.Count = _productComponents[id].Item2; - if (form.ShowDialog() == DialogResult.OK) - { - if (form.ComponentModel == null) - { - return; - } - _logger.LogInformation("Изменение компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); - _productComponents[form.Id] = (form.ComponentModel, form.Count); - LoadData(); - } - } - } - } private void buttonDel_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) @@ -130,7 +125,7 @@ namespace TravelCompany.Forms try { _logger.LogInformation("Удаление компонента: { ComponentName} - { Count}", dataGridView.SelectedRows[0].Cells[1].Value); - _productComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); + _travelComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); } catch (Exception ex) { @@ -156,7 +151,7 @@ namespace TravelCompany.Forms MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - if (_productComponents == null || _productComponents.Count == 0) + if (_travelComponents == null || _travelComponents.Count == 0) { MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; @@ -169,7 +164,7 @@ namespace TravelCompany.Forms Id = _id ?? 0, TravelName = textBoxName.Text, Price = Convert.ToDouble(textBoxPrice.Text), - TravelComponents = _productComponents + TravelComponents = _travelComponents }; var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); if (!operationResult) @@ -195,7 +190,7 @@ namespace TravelCompany.Forms private double CalcPrice() { double price = 0; - foreach (var elem in _productComponents) + foreach (var elem in _travelComponents) { price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); } diff --git a/TravelCompany/TravelCompany/FormTravels.cs b/TravelCompany/TravelCompany/FormTravels.cs index b772ffd..cbf0703 100644 --- a/TravelCompany/TravelCompany/FormTravels.cs +++ b/TravelCompany/TravelCompany/FormTravels.cs @@ -11,6 +11,7 @@ using TravelCompany; using TravelCompanyContracts.BindingModels; using TravelCompanyContracts.BusinessLogicsContracts; using Microsoft.Extensions.Logging; +using TravelCompanyContracts.DI; namespace TravelCompany.Forms { @@ -34,14 +35,7 @@ namespace TravelCompany.Forms { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["TravelComponents"].Visible = false; - dataGridView.Columns["TravelName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка путёвок"); } catch (Exception ex) @@ -52,13 +46,10 @@ namespace TravelCompany.Forms private void buttonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormTravel)); - if (service is FormTravel form) + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } @@ -66,14 +57,11 @@ namespace TravelCompany.Forms { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormTravel)); - if (service is FormTravel form) + var form = DependencyManager.Instance.Resolve(); + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) { - form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } } diff --git a/TravelCompany/TravelCompany/FormViewMail.cs b/TravelCompany/TravelCompany/FormViewMail.cs index 278477b..9862810 100644 --- a/TravelCompany/TravelCompany/FormViewMail.cs +++ b/TravelCompany/TravelCompany/FormViewMail.cs @@ -27,15 +27,8 @@ namespace TravelCompany.Forms { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["ClientId"].Visible = false; - dataGridView.Columns["MessageId"].Visible = false; - dataGridView.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка списка писем"); + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка списка писем"); } catch (Exception ex) { diff --git a/TravelCompany/TravelCompany/ImplementersForm.cs b/TravelCompany/TravelCompany/ImplementersForm.cs index bcef90a..f5d947e 100644 --- a/TravelCompany/TravelCompany/ImplementersForm.cs +++ b/TravelCompany/TravelCompany/ImplementersForm.cs @@ -33,22 +33,9 @@ namespace TravelCompany.Forms { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView1.DataSource = list; - dataGridView1.Columns["Id"].Visible = false; - dataGridView1.Columns["ImplementerFIO"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - dataGridView1.Columns["Password"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - dataGridView1.Columns["Qualification"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - dataGridView1.Columns["WorkExperience"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка компонентов"); - } + dataGridView1.FillAndConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка исполнителей"); + } catch (Exception ex) { _logger.LogError(ex, "Ошибка загрузки исполнителей"); diff --git a/TravelCompany/TravelCompany/Program.cs b/TravelCompany/TravelCompany/Program.cs index 44b00a9..53b2ffc 100644 --- a/TravelCompany/TravelCompany/Program.cs +++ b/TravelCompany/TravelCompany/Program.cs @@ -9,6 +9,8 @@ using TravelCompanyBusinessLogic.OfficePackage.Implements; using TravelCompanyBusinessLogic.OfficePackage; using TravelCompanyBusinessLogic.MailWorker; using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.DI; + namespace TravelCompany.Forms @@ -26,86 +28,69 @@ namespace TravelCompany.Forms // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - var services = new ServiceCollection(); - ConfigureServices(services); - _serviceProvider = services.BuildServiceProvider(); + InitDependency(); try { - var mailSender = - _serviceProvider.GetService(); + var mailSender = DependencyManager.Instance.Resolve(); mailSender?.MailConfig(new MailConfigBindingModel { - MailLogin = - System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? - string.Empty, - MailPassword = - System.Configuration.ConfigurationManager.AppSettings["MailPassword"] ?? - string.Empty, - SmtpClientHost = - System.Configuration.ConfigurationManager.AppSettings["SmtpClientHost"] ?? - string.Empty, - SmtpClientPort = - Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SmtpClientPort"]), - PopHost = - System.Configuration.ConfigurationManager.AppSettings["PopHost"] ?? string.Empty, - PopPort = - Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["PopPort"]) + MailLogin = System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? string.Empty, + MailPassword = System.Configuration.ConfigurationManager.AppSettings["MailPassword"] ?? string.Empty, + SmtpClientHost = System.Configuration.ConfigurationManager.AppSettings["SmtpClientHost"] ?? string.Empty, + SmtpClientPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SmtpClientPort"]), + PopHost = System.Configuration.ConfigurationManager.AppSettings["PopHost"] ?? string.Empty, + PopPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["PopPort"]) }); - // - var timer = new System.Threading.Timer(new - TimerCallback(MailCheck!), null, 0, 100000); + + var timer = new System.Threading.Timer(new TimerCallback(MailCheck!), null, 0, 100000); } catch (Exception ex) { - var logger = _serviceProvider.GetService(); - logger?.LogError(ex, " "); + var logger = DependencyManager.Instance.Resolve(); + logger?.LogError(ex, "Mails Problem"); } - - Application.Run(_serviceProvider.GetRequiredService()); + Application.Run(DependencyManager.Instance.Resolve()); } - private static void ConfigureServices(ServiceCollection services) + private static void InitDependency() { - services.AddLogging(option => + DependencyManager.InitDependency(); + + DependencyManager.Instance.AddLogging(option => { option.SetMinimumLevel(LogLevel.Information); option.AddNLog("nlog.config"); }); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddSingleton(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); } - private static void MailCheck(object obj) => -ServiceProvider?.GetService()?.MailCheck(); + private static void MailCheck(object obj) => DependencyManager.Instance.Resolve()?.MailCheck(); } } \ No newline at end of file diff --git a/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/BackUpLogic.cs b/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/BackUpLogic.cs new file mode 100644 index 0000000..6c07060 --- /dev/null +++ b/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/BackUpLogic.cs @@ -0,0 +1,97 @@ +using Microsoft.Extensions.Logging; +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.BusinessLogicsContracts; +using TravelCompanyContracts.StoragesContracts; +using TravelCompanyDataModels; +using System.IO.Compression; +using System.Reflection; +using System.Runtime.Serialization.Json; + +namespace TravelCompanyBusinessLogic.BusinessLogic +{ + public class BackUpLogic : IBackUpLogic + { + private readonly ILogger _logger; + + private readonly IBackUpInfo _backUpInfo; + + public BackUpLogic(ILogger logger, IBackUpInfo backUpInfo) + { + _logger = logger; + _backUpInfo = backUpInfo; + } + + public void CreateBackUp(BackUpSaveBinidngModel model) + { + if (_backUpInfo == null) + { + return; + } + try + { + _logger.LogDebug("Clear folder"); + var dirInfo = new DirectoryInfo(model.FolderName); + if (dirInfo.Exists) + { + foreach (var file in dirInfo.GetFiles()) + { + file.Delete(); + } + } + _logger.LogDebug("Delete archive"); + string fileName = $"{model.FolderName}.zip"; + if (File.Exists(fileName)) + { + File.Delete(fileName); + } + // берем метод для сохранения + _logger.LogDebug("Get assembly"); + var typeIId = typeof(IId); + var assembly = typeIId.Assembly; + if (assembly == null) + { + throw new ArgumentNullException("Сборка не найдена", nameof(assembly)); + } + var types = assembly.GetTypes(); + var method = GetType().GetMethod("SaveToFile", BindingFlags.NonPublic | BindingFlags.Instance); + _logger.LogDebug("Find {count} types", types.Length); + foreach (var type in types) + { + if (type.IsInterface && type.GetInterface(typeIId.Name) != null) + { + var modelType = _backUpInfo.GetTypeByModelInterface(type.Name); + if (modelType == null) + { + throw new InvalidOperationException($"Не найден класс-модель для {type.Name}"); + } + _logger.LogDebug("Call SaveToFile method for {name} type", type.Name); + // вызываем метод на выполнение + method?.MakeGenericMethod(modelType).Invoke(this, new object[] { model.FolderName }); + } + } + _logger.LogDebug("Create zip and remove folder"); + // архивируем + ZipFile.CreateFromDirectory(model.FolderName, fileName); + // удаляем папку + dirInfo.Delete(true); + } + catch (Exception) + { + throw; + } + } + + private void SaveToFile(string folderName) where T : class, new() + { + var records = _backUpInfo.GetList(); + if (records == null) + { + _logger.LogWarning("{type} type get null list", typeof(T).Name); + return; + } + var jsonFormatter = new DataContractJsonSerializer(typeof(List)); + using var fs = new FileStream(string.Format("{0}/{1}.json", folderName, typeof(T).Name), FileMode.OpenOrCreate); + jsonFormatter.WriteObject(fs, records); + } + } +} diff --git a/TravelCompany/TravelCompanyContracts/Attributes/ColumnAttribute.cs b/TravelCompany/TravelCompanyContracts/Attributes/ColumnAttribute.cs new file mode 100644 index 0000000..7f23069 --- /dev/null +++ b/TravelCompany/TravelCompanyContracts/Attributes/ColumnAttribute.cs @@ -0,0 +1,25 @@ +namespace TravelCompanyContracts.Attributes +{ + [AttributeUsage(AttributeTargets.Property)] + public class ColumnAttribute : Attribute + { + public string Title { get; private set; } + + public bool Visible { get; private set; } + + public int Width { get; private set; } + + public GridViewAutoSize GridViewAutoSize { get; private set; } + + public bool IsUseAutoSize { get; private set; } + + public ColumnAttribute(string title = "", bool visible = true, int width = 0, GridViewAutoSize gridViewAutoSize = GridViewAutoSize.None, bool isUseAutoSize = false) + { + Title = title; + Visible = visible; + Width = width; + GridViewAutoSize = gridViewAutoSize; + IsUseAutoSize = isUseAutoSize; + } + } +} diff --git a/TravelCompany/TravelCompanyContracts/Attributes/GridViewAutoSize.cs b/TravelCompany/TravelCompanyContracts/Attributes/GridViewAutoSize.cs new file mode 100644 index 0000000..832915e --- /dev/null +++ b/TravelCompany/TravelCompanyContracts/Attributes/GridViewAutoSize.cs @@ -0,0 +1,21 @@ +namespace TravelCompanyContracts.Attributes +{ + public enum GridViewAutoSize + { + NotSet = 0, + + None = 1, + + ColumnHeader = 2, + + AllCellsExceptHeader = 4, + + AllCells = 6, + + DisplayedCellsExceptHeader = 8, + + DisplayedCells = 10, + + Fill = 16 + } +} diff --git a/TravelCompany/TravelCompanyContracts/BindingModels/BackUpSaveBinidngModel.cs b/TravelCompany/TravelCompanyContracts/BindingModels/BackUpSaveBinidngModel.cs new file mode 100644 index 0000000..8773e78 --- /dev/null +++ b/TravelCompany/TravelCompanyContracts/BindingModels/BackUpSaveBinidngModel.cs @@ -0,0 +1,7 @@ +namespace TravelCompanyContracts.BindingModels +{ + public class BackUpSaveBinidngModel + { + public string FolderName { get; set; } = string.Empty; + } +} diff --git a/TravelCompany/TravelCompanyContracts/BindingModels/MessageInfoBindingModel.cs b/TravelCompany/TravelCompanyContracts/BindingModels/MessageInfoBindingModel.cs index 875253e..fcac675 100644 --- a/TravelCompany/TravelCompanyContracts/BindingModels/MessageInfoBindingModel.cs +++ b/TravelCompany/TravelCompanyContracts/BindingModels/MessageInfoBindingModel.cs @@ -20,5 +20,7 @@ namespace TravelCompanyContracts.BindingModels public string Body { get; set; } = string.Empty; public DateTime DateDelivery { get; set; } - } + public int Id => throw new NotImplementedException(); + + } } diff --git a/TravelCompany/TravelCompanyContracts/BusinessLogicsContracts/IBackUpLogic.cs b/TravelCompany/TravelCompanyContracts/BusinessLogicsContracts/IBackUpLogic.cs new file mode 100644 index 0000000..ad3dd56 --- /dev/null +++ b/TravelCompany/TravelCompanyContracts/BusinessLogicsContracts/IBackUpLogic.cs @@ -0,0 +1,9 @@ +using TravelCompanyContracts.BindingModels; + +namespace TravelCompanyContracts.BusinessLogicsContracts +{ + public interface IBackUpLogic + { + void CreateBackUp(BackUpSaveBinidngModel model); + } +} diff --git a/TravelCompany/TravelCompanyContracts/DI/DependencyManager.cs b/TravelCompany/TravelCompanyContracts/DI/DependencyManager.cs new file mode 100644 index 0000000..65eab9b --- /dev/null +++ b/TravelCompany/TravelCompanyContracts/DI/DependencyManager.cs @@ -0,0 +1,61 @@ +using Microsoft.Extensions.Logging; + +namespace TravelCompanyContracts.DI +{ + public class DependencyManager + { + private readonly IDependencyContainer _dependencyManager; + + private static DependencyManager? _manager; + + private static readonly object _locjObject = new(); + + private DependencyManager() + { + _dependencyManager = new ServiceDependencyContainer(); + } + + public static DependencyManager Instance { get { if (_manager == null) { lock (_locjObject) { _manager = new DependencyManager(); } } return _manager; } } + + /// + /// Иницализация библиотек, в которых идут установки зависомстей + /// + public static void InitDependency() + { + var ext = ServiceProviderLoader.GetImplementationExtensions(); + if (ext == null) + { + throw new ArgumentNullException("Отсутствуют компоненты для загрузки зависимостей по модулям"); + } + // регистрируем зависимости + ext.RegisterServices(); + } + + /// + /// Регистрация логгера + /// + /// + public void AddLogging(Action configure) => _dependencyManager.AddLogging(configure); + + /// + /// Добавление зависимости + /// + /// + /// + public void RegisterType(bool isSingle = false) where U : class, T where T : class => _dependencyManager.RegisterType(isSingle); + + /// + /// Добавление зависимости + /// + /// + /// + public void RegisterType(bool isSingle = false) where T : class => _dependencyManager.RegisterType(isSingle); + + /// + /// Получение класса со всеми зависмостями + /// + /// + /// + public T Resolve() => _dependencyManager.Resolve(); + } +} diff --git a/TravelCompany/TravelCompanyContracts/DI/IDependencyContainer.cs b/TravelCompany/TravelCompanyContracts/DI/IDependencyContainer.cs new file mode 100644 index 0000000..65458cd --- /dev/null +++ b/TravelCompany/TravelCompanyContracts/DI/IDependencyContainer.cs @@ -0,0 +1,35 @@ +using Microsoft.Extensions.Logging; + +namespace TravelCompanyContracts.DI +{ + public interface IDependencyContainer + { + /// + /// Регистрация логгера + /// + /// + void AddLogging(Action configure); + + /// + /// Добавление зависимости + /// + /// + /// + /// + void RegisterType(bool isSingle) where U : class, T where T : class; + + /// + /// Добавление зависимости + /// + /// + /// + void RegisterType(bool isSingle) where T : class; + + /// + /// Получение класса со всеми зависмостями + /// + /// + /// + T Resolve(); + } +} diff --git a/TravelCompany/TravelCompanyContracts/DI/IImplementationExtension.cs b/TravelCompany/TravelCompanyContracts/DI/IImplementationExtension.cs new file mode 100644 index 0000000..d9e9ace --- /dev/null +++ b/TravelCompany/TravelCompanyContracts/DI/IImplementationExtension.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyContracts.DI +{ + public interface IImplementationExtension + { + public int Priority { get; } + /// + /// Регистрация сервисов + /// + public void RegisterServices(); + } +} diff --git a/TravelCompany/TravelCompanyContracts/DI/ServiceDependencyContainer.cs b/TravelCompany/TravelCompanyContracts/DI/ServiceDependencyContainer.cs new file mode 100644 index 0000000..910ec3c --- /dev/null +++ b/TravelCompany/TravelCompanyContracts/DI/ServiceDependencyContainer.cs @@ -0,0 +1,57 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; + +namespace TravelCompanyContracts.DI +{ + public class ServiceDependencyContainer : IDependencyContainer + { + private ServiceProvider? _serviceProvider; + + private readonly ServiceCollection _serviceCollection; + + public ServiceDependencyContainer() + { + _serviceCollection = new ServiceCollection(); + } + + public void AddLogging(Action configure) + { + _serviceCollection.AddLogging(configure); + } + + public void RegisterType(bool isSingle) where U : class, T where T : class + { + if (isSingle) + { + _serviceCollection.AddSingleton(); + } + else + { + _serviceCollection.AddTransient(); + } + _serviceProvider = null; + } + + public void RegisterType(bool isSingle) where T : class + { + if (isSingle) + { + _serviceCollection.AddSingleton(); + } + else + { + _serviceCollection.AddTransient(); + } + _serviceProvider = null; + } + + public T Resolve() + { + if (_serviceProvider == null) + { + _serviceProvider = _serviceCollection.BuildServiceProvider(); + } + return _serviceProvider.GetService()!; + } + } +} diff --git a/TravelCompany/TravelCompanyContracts/DI/ServiceProviderLoader.cs b/TravelCompany/TravelCompanyContracts/DI/ServiceProviderLoader.cs new file mode 100644 index 0000000..3394796 --- /dev/null +++ b/TravelCompany/TravelCompanyContracts/DI/ServiceProviderLoader.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyContracts.DI +{ + public class ServiceProviderLoader + { + /// + /// Загрузка всех классов-реализаций IImplementationExtension + /// + /// + public static IImplementationExtension? GetImplementationExtensions() + { + IImplementationExtension? source = null; + var files = Directory.GetFiles(TryGetImplementationExtensionsFolder(), "*.dll", SearchOption.AllDirectories); + foreach (var file in files.Distinct()) + { + Assembly asm = Assembly.LoadFrom(file); + foreach (var t in asm.GetExportedTypes()) + { + if (t.IsClass && typeof(IImplementationExtension).IsAssignableFrom(t)) + { + if (source == null) + { + source = (IImplementationExtension)Activator.CreateInstance(t)!; + } + else + { + var newSource = (IImplementationExtension)Activator.CreateInstance(t)!; + if (newSource.Priority > source.Priority) + { + source = newSource; + } + } + } + } + } + return source; + } + + private static string TryGetImplementationExtensionsFolder() + { + var directory = new DirectoryInfo(Directory.GetCurrentDirectory()); + while (directory != null && !directory.GetDirectories("ImplementationExtensions", SearchOption.AllDirectories).Any(x => x.Name == "ImplementationExtensions")) + { + directory = directory.Parent; + } + return $"{directory?.FullName}\\ImplementationExtensions"; + } + } +} diff --git a/TravelCompany/TravelCompanyContracts/StoragesContracts/IBackUpInfo.cs b/TravelCompany/TravelCompanyContracts/StoragesContracts/IBackUpInfo.cs new file mode 100644 index 0000000..127a04c --- /dev/null +++ b/TravelCompany/TravelCompanyContracts/StoragesContracts/IBackUpInfo.cs @@ -0,0 +1,9 @@ +namespace TravelCompanyContracts.StoragesContracts +{ + public interface IBackUpInfo + { + List? GetList() where T : class, new(); + + Type? GetTypeByModelInterface(string modelInterfaceName); + } +} diff --git a/TravelCompany/TravelCompanyContracts/ViewModels/ClientViewModel.cs b/TravelCompany/TravelCompanyContracts/ViewModels/ClientViewModel.cs index 43324d1..d56ef4f 100644 --- a/TravelCompany/TravelCompanyContracts/ViewModels/ClientViewModel.cs +++ b/TravelCompany/TravelCompanyContracts/ViewModels/ClientViewModel.cs @@ -1,16 +1,19 @@ using TravelCompanyDataModels.Models; using System.ComponentModel; +using TravelCompanyContracts.Attributes; + namespace TravelCompanyContracts.ViewModels { public class ClientViewModel : IClientModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("ФИО клиента")] + [Column(title: "ФИО клиента", width: 150)] public string ClientFIO { get; set; } = string.Empty; - [DisplayName("Логин (эл. почта)")] + [Column(title: "Логин (эл. почта)", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string Email { get; set; } = string.Empty; - [DisplayName("Пароль")] + [Column(title: "Пароль", width: 150)] public string Password { get; set; } = string.Empty; } } diff --git a/TravelCompany/TravelCompanyContracts/ViewModels/ComponentViewModel.cs b/TravelCompany/TravelCompanyContracts/ViewModels/ComponentViewModel.cs index f865958..65f9a4c 100644 --- a/TravelCompany/TravelCompanyContracts/ViewModels/ComponentViewModel.cs +++ b/TravelCompany/TravelCompanyContracts/ViewModels/ComponentViewModel.cs @@ -5,15 +5,18 @@ using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; +using TravelCompanyContracts.Attributes; + namespace TravelCompanyContracts.ViewModels { public class ComponentViewModel : IComponentModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("Название компонента")] + [Column(title: "Название компонента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ComponentName { get; set; } = string.Empty; - [DisplayName("Цена")] + [Column(title: "Цена", width: 150)] public double Cost { get; set; } } } diff --git a/TravelCompany/TravelCompanyContracts/ViewModels/ImplementerViewModel.cs b/TravelCompany/TravelCompanyContracts/ViewModels/ImplementerViewModel.cs index f4fa3a2..7987235 100644 --- a/TravelCompany/TravelCompanyContracts/ViewModels/ImplementerViewModel.cs +++ b/TravelCompany/TravelCompanyContracts/ViewModels/ImplementerViewModel.cs @@ -5,19 +5,22 @@ using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; +using TravelCompanyContracts.Attributes; + namespace TravelCompanyContracts.ViewModels { public class ImplementerViewModel : IImplementerModel { - public int Id { get; set; } - [DisplayName("ФИО исполнителя")] - public string ImplementerFIO { get; set; } = string.Empty; - [DisplayName("Стаж работы")] - public int WorkExperience { get; set; } = 0; - [DisplayName("Квалификация")] - public int Qualification { get; set; } = 0; - [DisplayName("Пароль")] - public string Password { get; set; } = string.Empty; + [Column(visible: false)] + public int Id { get; set; } + [Column(title: "ФИО исполнителя", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string ImplementerFIO { get; set; } = string.Empty; + [Column(title: "Стаж работы", width: 60)] + public int WorkExperience { get; set; } = 0; + [Column(title: "Квалификация", width: 60)] + public int Qualification { get; set; } = 0; + [Column(title: "Пароль", width: 100)] + public string Password { get; set; } = string.Empty; } } diff --git a/TravelCompany/TravelCompanyContracts/ViewModels/MessageInfoViewModel.cs b/TravelCompany/TravelCompanyContracts/ViewModels/MessageInfoViewModel.cs index 9f211c5..f564c6d 100644 --- a/TravelCompany/TravelCompanyContracts/ViewModels/MessageInfoViewModel.cs +++ b/TravelCompany/TravelCompanyContracts/ViewModels/MessageInfoViewModel.cs @@ -1,24 +1,25 @@ using TravelCompanyDataModels.Models; using System.ComponentModel; +using TravelCompanyContracts.Attributes; + namespace TravelCompanyContracts.ViewModels { public class MessageInfoViewModel : IMessageInfoModel { - public string MessageId { get; set; } = string.Empty; - - public int? ClientId { get; set; } - - [DisplayName("Отправитель")] - public string SenderName { get; set; } = string.Empty; - - [DisplayName("Дата письма")] - public DateTime DateDelivery { get; set; } - - [DisplayName("Заголовок")] - public string Subject { get; set; } = string.Empty; - - [DisplayName("Текст")] - public string Body { get; set; } = string.Empty; + [Column(visible: false)] + public int Id { get; set; } + [Column(visible: false)] + public string MessageId { get; set; } = string.Empty; + [Column(visible: false)] + public int? ClientId { get; set; } + [Column(title: "Отправитель", width: 150)] + public string SenderName { get; set; } = string.Empty; + [Column(title: "Дата письма", width: 120)] + public DateTime DateDelivery { get; set; } + [Column(title: "Заголовок", width: 120)] + public string Subject { get; set; } = string.Empty; + [Column(title: "Текст", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string Body { get; set; } = string.Empty; } } \ No newline at end of file diff --git a/TravelCompany/TravelCompanyContracts/ViewModels/OrderViewModel.cs b/TravelCompany/TravelCompanyContracts/ViewModels/OrderViewModel.cs index 652ff88..4e63e8d 100644 --- a/TravelCompany/TravelCompanyContracts/ViewModels/OrderViewModel.cs +++ b/TravelCompany/TravelCompanyContracts/ViewModels/OrderViewModel.cs @@ -1,39 +1,36 @@ -using TravelCompanyDataModels; -using TravelCompanyDataModels.Enums; +using TravelCompanyDataModels.Enums; using TravelCompanyDataModels.Models; -using System; -using System.Collections.Generic; using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using TravelCompanyDataModels.Enums; -using TravelCompanyDataModels.Models; +using TravelCompanyContracts.Attributes; + namespace TravelCompanyContracts.ViewModels { public class OrderViewModel : IOrderModel { - [DisplayName("Номер")] + [Column(title: "Номер", width: 90)] public int Id { get; set; } + [Column(visible: false)] public int TravelId { get; set; } + [Column(visible: false)] public int ClientId { get; set; } + [Column(visible: false)] public int? ImplementerId { get; set; } = null; - [DisplayName("Клиент")] + [Column(title: "Клиент", width: 190)] public string ClientFIO { get; set; } = string.Empty; - [DisplayName("Путёвка")] + [Column(title: "Путёвка", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string TravelName { get; set; } = string.Empty; - [DisplayName("Исполнитель")] + [Column(title: "Исполнитель", width: 150)] public string ImplementerFIO { get; set; } = string.Empty; - [DisplayName("Количество")] + [Column(title: "Количество", width: 100)] public int Count { get; set; } - [DisplayName("Сумма")] + [Column(title: "Сумма", width: 120)] public double Sum { get; set; } - [DisplayName("Статус")] + [Column(title: "Статус", width: 70)] public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; - [DisplayName("Дата создания")] + [Column(title: "Дата создания", width: 120)] public DateTime DateCreate { get; set; } = DateTime.Now; - [DisplayName("Дата выполнения")] + [Column(title: "Дата выполнения", width: 120)] public DateTime? DateImplement { get; set; } } } diff --git a/TravelCompany/TravelCompanyContracts/ViewModels/ReportOrdersViewModel.cs b/TravelCompany/TravelCompanyContracts/ViewModels/ReportOrdersViewModel.cs index 01d230a..b131b0d 100644 --- a/TravelCompany/TravelCompanyContracts/ViewModels/ReportOrdersViewModel.cs +++ b/TravelCompany/TravelCompanyContracts/ViewModels/ReportOrdersViewModel.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; + namespace TravelCompanyContracts.ViewModels { public class ReportOrdersViewModel diff --git a/TravelCompany/TravelCompanyContracts/ViewModels/TravelViewModel.cs b/TravelCompany/TravelCompanyContracts/ViewModels/TravelViewModel.cs index d8c1e55..f20fa26 100644 --- a/TravelCompany/TravelCompanyContracts/ViewModels/TravelViewModel.cs +++ b/TravelCompany/TravelCompanyContracts/ViewModels/TravelViewModel.cs @@ -5,16 +5,20 @@ using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; +using TravelCompanyContracts.Attributes; + namespace TravelCompanyContracts.ViewModels { public class TravelViewModel : ITravelModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("Название изделия")] + [Column(title: "Название изделия", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string TravelName { get; set; } - [DisplayName("Цена")] + [Column(title: "Цена", width: 70)] public double Price { get; set; } + [Column(visible: false)] public Dictionary TravelComponents { get; set; } = new(); } diff --git a/TravelCompany/TravelCompanyDataModels/Models/IImplementerModel.cs b/TravelCompany/TravelCompanyDataModels/Models/IImplementerModel.cs index 28258f8..eed3b30 100644 --- a/TravelCompany/TravelCompanyDataModels/Models/IImplementerModel.cs +++ b/TravelCompany/TravelCompanyDataModels/Models/IImplementerModel.cs @@ -6,8 +6,8 @@ using System.Threading.Tasks; namespace TravelCompanyDataModels { - public interface IImplementerModel - { + public interface IImplementerModel : IId + { string ImplementerFIO { get; } string Password { get; } int WorkExperience { get; } diff --git a/TravelCompany/TravelCompanyDataModels/Models/IMessageInfoModel.cs b/TravelCompany/TravelCompanyDataModels/Models/IMessageInfoModel.cs index 329a26f..810775b 100644 --- a/TravelCompany/TravelCompanyDataModels/Models/IMessageInfoModel.cs +++ b/TravelCompany/TravelCompanyDataModels/Models/IMessageInfoModel.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace TravelCompanyDataModels.Models { - public interface IMessageInfoModel + public interface IMessageInfoModel : IId { string MessageId { get; } int? ClientId { get; } diff --git a/TravelCompany/TravelCompanyDatabaseImplement/ImplementationExtension.cs b/TravelCompany/TravelCompanyDatabaseImplement/ImplementationExtension.cs new file mode 100644 index 0000000..06943c8 --- /dev/null +++ b/TravelCompany/TravelCompanyDatabaseImplement/ImplementationExtension.cs @@ -0,0 +1,22 @@ +using TravelCompanyContracts.DI; +using TravelCompanyContracts.StoragesContracts; +using TravelCompanyDatabaseImplement.Implements; + +namespace TravelCompanyDatabaseImplement +{ + public class ImplementationExtension : IImplementationExtension + { + public int Priority => 3; + + public void RegisterServices() + { + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } + } +} diff --git a/TravelCompany/TravelCompanyDatabaseImplement/Implements/BackUpInfo.cs b/TravelCompany/TravelCompanyDatabaseImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..7304985 --- /dev/null +++ b/TravelCompany/TravelCompanyDatabaseImplement/Implements/BackUpInfo.cs @@ -0,0 +1,27 @@ +using TravelCompanyContracts.StoragesContracts; + +namespace TravelCompanyDatabaseImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + using var context = new TravelCompanyDataBase(); + return context.Set().ToList(); + } + + public Type? GetTypeByModelInterface(string modelInterfaceName) + { + var assembly = typeof(BackUpInfo).Assembly; + var types = assembly.GetTypes(); + foreach (var type in types) + { + if (type.IsClass && type.GetInterface(modelInterfaceName) != null) + { + return type; + } + } + return null; + } + } +} diff --git a/TravelCompany/TravelCompanyDatabaseImplement/Models/Client.cs b/TravelCompany/TravelCompanyDatabaseImplement/Models/Client.cs index 81a719f..d0de4bb 100644 --- a/TravelCompany/TravelCompanyDatabaseImplement/Models/Client.cs +++ b/TravelCompany/TravelCompanyDatabaseImplement/Models/Client.cs @@ -5,21 +5,28 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Runtime.Serialization; + namespace TravelCompanyDatabaseImplement.Models { - public class Client : IClientModel - { - public int Id { get; private set; } + [DataContract] - [Required] + public class Client : IClientModel + { + [DataMember] + public int Id { get; private set; } + + [DataMember] + [Required] public string ClientFIO { get; set; } = string.Empty; - [Required] + + [DataMember] + [Required] public string Email { get; set; } = string.Empty; - [Required] + + [DataMember] + [Required] public string Password { get; set; } = string.Empty; [ForeignKey("ClientId")] diff --git a/TravelCompany/TravelCompanyDatabaseImplement/Models/Component.cs b/TravelCompany/TravelCompanyDatabaseImplement/Models/Component.cs index 81fc7a6..275f3eb 100644 --- a/TravelCompany/TravelCompanyDatabaseImplement/Models/Component.cs +++ b/TravelCompany/TravelCompanyDatabaseImplement/Models/Component.cs @@ -8,16 +8,24 @@ using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Runtime.Serialization; namespace TravelCompanyDatabaseImplement.Models { + [DataContract] public class Component : IComponentModel { + [DataMember] public int Id { get; private set; } + + [DataMember] [Required] public string ComponentName { get; private set; } = string.Empty; + + [DataMember] [Required] public double Cost { get; set; } + [ForeignKey("ComponentId")] public virtual List TravelComponents { get; set; } = new(); diff --git a/TravelCompany/TravelCompanyDatabaseImplement/Models/Implementer.cs b/TravelCompany/TravelCompanyDatabaseImplement/Models/Implementer.cs index 246f216..3263a05 100644 --- a/TravelCompany/TravelCompanyDatabaseImplement/Models/Implementer.cs +++ b/TravelCompany/TravelCompanyDatabaseImplement/Models/Implementer.cs @@ -8,19 +8,30 @@ using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Runtime.Serialization; namespace TravelCompanyDatabaseImplement.Models { - public class Implementer : IImplementerModel + [DataContract] + public class Implementer : IImplementerModel { - public int Id { get; private set; } - [Required] + [DataMember] + public int Id { get; private set; } + + [DataMember] + [Required] public string ImplementerFIO { get; private set; } = string.Empty; - [Required] + + [DataMember] + [Required] public string Password { get; set; } = string.Empty; - [Required] + + [DataMember] + [Required] public int Qualification { get; set; } = 0; - [Required] + + [DataMember] + [Required] public int WorkExperience { get; set; } = 0; [ForeignKey("ImplementerId")] public virtual List Orders { get; set; } = diff --git a/TravelCompany/TravelCompanyDatabaseImplement/Models/MessageInfo.cs b/TravelCompany/TravelCompanyDatabaseImplement/Models/MessageInfo.cs index 043b74b..e3c00cb 100644 --- a/TravelCompany/TravelCompanyDatabaseImplement/Models/MessageInfo.cs +++ b/TravelCompany/TravelCompanyDatabaseImplement/Models/MessageInfo.cs @@ -2,23 +2,39 @@ using TravelCompanyContracts.ViewModels; using TravelCompanyDataModels.Models; using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; namespace TravelCompanyDatabaseImplement.Models { public class MessageInfo : IMessageInfoModel { - [Key] - public string MessageId { get; private set; } = string.Empty; + [NotMapped] + public int Id { get; private set; } - public int? ClientId { get; private set; } + [DataMember] + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.None)] + public string MessageId { get; private set; } = string.Empty; - public string SenderName { get; private set; } = string.Empty; + [DataMember] + public int? ClientId { get; private set; } - public DateTime DateDelivery { get; private set; } = DateTime.Now; + [DataMember] + [Required] + public string SenderName { get; private set; } = string.Empty; - public string Subject { get; private set; } = string.Empty; + [DataMember] + [Required] + public DateTime DateDelivery { get; private set; } = DateTime.Now; - public string Body { get; private set; } = string.Empty; + [DataMember] + [Required] + public string Subject { get; private set; } = string.Empty; + + [DataMember] + [Required] + public string Body { get; private set; } = string.Empty; public Client? Client { get; private set; } diff --git a/TravelCompany/TravelCompanyDatabaseImplement/Models/Order.cs b/TravelCompany/TravelCompanyDatabaseImplement/Models/Order.cs index bc0085c..ab6593d 100644 --- a/TravelCompany/TravelCompanyDatabaseImplement/Models/Order.cs +++ b/TravelCompany/TravelCompanyDatabaseImplement/Models/Order.cs @@ -5,27 +5,46 @@ using TravelCompanyDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; namespace TravelCompanyDatabaseImplement.Models { + [DataContract] public class Order : IOrderModel { + [DataMember] public int Id { get; private set; } + + [DataMember] [Required] public int Count { get; private set; } + + [DataMember] [Required] public double Sum { get; private set; } + + [DataMember] [Required] public OrderStatus Status { get; private set; } + + [DataMember] [Required] public DateTime DateCreate { get; private set; } + + [DataMember] public DateTime? DateImplement { get; private set; } + + [DataMember] [Required] public int TravelId { get; private set; } public virtual Travel Travel { get; private set; } + + [DataMember] [Required] public int ClientId { get; private set; } public virtual Client Client { get; private set; } + + [DataMember] public int? ImplementerId { get; private set; } = null; public virtual Implementer? Implementer { get; private set; } public static Order? Create(TravelCompanyDataBase context, OrderBindingModel model) diff --git a/TravelCompany/TravelCompanyDatabaseImplement/Models/Travel.cs b/TravelCompany/TravelCompanyDatabaseImplement/Models/Travel.cs index 88ffaa3..cfb229f 100644 --- a/TravelCompany/TravelCompanyDatabaseImplement/Models/Travel.cs +++ b/TravelCompany/TravelCompanyDatabaseImplement/Models/Travel.cs @@ -8,18 +8,28 @@ using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Runtime.Serialization; namespace TravelCompanyDatabaseImplement.Models { + [DataContract] public class Travel : ITravelModel { + + [DataMember] public int Id { get; set; } + + [DataMember] [Required] public string TravelName { get; set; } = string.Empty; + + [DataMember] [Required] public double Price { get; set; } - private Dictionary? _TravelComponents = - null; + + private Dictionary? _TravelComponents = null; + + [DataMember] [NotMapped] public Dictionary TravelComponents { diff --git a/TravelCompany/TravelCompanyDatabaseImplement/TravelCompanyDatabaseImplement.csproj b/TravelCompany/TravelCompanyDatabaseImplement/TravelCompanyDatabaseImplement.csproj index f023f35..196f97c 100644 --- a/TravelCompany/TravelCompanyDatabaseImplement/TravelCompanyDatabaseImplement.csproj +++ b/TravelCompany/TravelCompanyDatabaseImplement/TravelCompanyDatabaseImplement.csproj @@ -19,4 +19,8 @@ + + + + diff --git a/TravelCompany/TravelCompanyFileImplement/DataFileSingleton.cs b/TravelCompany/TravelCompanyFileImplement/DataFileSingleton.cs index d38f67d..eecd3a9 100644 --- a/TravelCompany/TravelCompanyFileImplement/DataFileSingleton.cs +++ b/TravelCompany/TravelCompanyFileImplement/DataFileSingleton.cs @@ -25,6 +25,7 @@ namespace TravelCompanyFileImplement public List Implementers { get; private set; } public List Messages { get; private set; } + public static DataFileSingleton GetInstance() { if (instance == null) @@ -53,7 +54,6 @@ namespace TravelCompanyFileImplement Implementer.Create(x)!)!; Messages = LoadData(MessageInfoFileName, "MessageInfo", x => MessageInfo.Create(x)!)!; - } private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) { diff --git a/TravelCompany/TravelCompanyFileImplement/ImplementationExtension.cs b/TravelCompany/TravelCompanyFileImplement/ImplementationExtension.cs new file mode 100644 index 0000000..a9d45d9 --- /dev/null +++ b/TravelCompany/TravelCompanyFileImplement/ImplementationExtension.cs @@ -0,0 +1,22 @@ +using TravelCompanyContracts.DI; +using TravelCompanyContracts.StoragesContracts; +using TravelCompanyFileImplement.Implements; + +namespace TravelCompanyFileImplement +{ + public class ImplementationExtension : IImplementationExtension + { + public int Priority => 1; + + public void RegisterServices() + { + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } + } +} diff --git a/TravelCompany/TravelCompanyFileImplement/Implements/BackUpInfo.cs b/TravelCompany/TravelCompanyFileImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..d9d396f --- /dev/null +++ b/TravelCompany/TravelCompanyFileImplement/Implements/BackUpInfo.cs @@ -0,0 +1,39 @@ +using TravelCompanyContracts.StoragesContracts; +using System.Reflection; + +namespace TravelCompanyFileImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + private readonly DataFileSingleton source; + private readonly PropertyInfo[] sourceProperties; + + public BackUpInfo() + { + source = DataFileSingleton.GetInstance(); + sourceProperties = source.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public); + } + + public List? GetList() where T : class, new() + { + var requredType = typeof(T); + return (List?)sourceProperties.FirstOrDefault(x => x.PropertyType.IsGenericType && x.PropertyType.GetGenericArguments()[0] == requredType) + ?.GetValue(source); + + } + + public Type? GetTypeByModelInterface(string modelInterfaceName) + { + var assembly = typeof(BackUpInfo).Assembly; + var types = assembly.GetTypes(); + foreach (var type in types) + { + if (type.IsClass && type.GetInterface(modelInterfaceName) != null) + { + return type; + } + } + return null; + } + } +} diff --git a/TravelCompany/TravelCompanyFileImplement/Models/Client.cs b/TravelCompany/TravelCompanyFileImplement/Models/Client.cs index 226b29d..1e93e22 100644 --- a/TravelCompany/TravelCompanyFileImplement/Models/Client.cs +++ b/TravelCompany/TravelCompanyFileImplement/Models/Client.cs @@ -9,14 +9,21 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; +using System.Runtime.Serialization; namespace TravelCompanyFileImplement.Models { + [DataContract] + public class Client : IClientModel { + [DataMember] public int Id { get; private set; } + [DataMember] public string ClientFIO { get; private set; } = string.Empty; + [DataMember] public string Email { get; set; } = string.Empty; + [DataMember] public string Password { get; set; } = string.Empty; public static Client? Create(ClientBindingModel model) { diff --git a/TravelCompany/TravelCompanyFileImplement/Models/Component.cs b/TravelCompany/TravelCompanyFileImplement/Models/Component.cs index 0a39648..4d778b1 100644 --- a/TravelCompany/TravelCompanyFileImplement/Models/Component.cs +++ b/TravelCompany/TravelCompanyFileImplement/Models/Component.cs @@ -7,13 +7,18 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; +using System.Runtime.Serialization; namespace TravelCompanyFileImplement.Models { + [DataContract] public class Component : IComponentModel { + [DataMember] public int Id { get; private set; } + [DataMember] public string ComponentName { get; private set; } = string.Empty; + [DataMember] public double Cost { get; set; } public static Component? Create(ComponentBindingModel model) { diff --git a/TravelCompany/TravelCompanyFileImplement/Models/Implementer.cs b/TravelCompany/TravelCompanyFileImplement/Models/Implementer.cs index f08719d..5b70e68 100644 --- a/TravelCompany/TravelCompanyFileImplement/Models/Implementer.cs +++ b/TravelCompany/TravelCompanyFileImplement/Models/Implementer.cs @@ -7,17 +7,24 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; +using System.Runtime.Serialization; namespace TravelCompanyFileImplement.Models { - public class Implementer : IImplementerModel + [DataContract] + public class Implementer : IImplementerModel { - public int Id { get; private set; } - public string ImplementerFIO { get; private set; } = string.Empty; - public string Password { get; set; } = string.Empty; - public int Qualification { get; set; } = 0; - public int WorkExperience { get; set; } = 0; - public static Implementer? Create(ImplementerBindingModel model) + [DataMember] + public int Id { get; private set; } + [DataMember] + public string ImplementerFIO { get; private set; } = string.Empty; + [DataMember] + public string Password { get; set; } = string.Empty; + [DataMember] + public int Qualification { get; set; } = 0; + [DataMember] + public int WorkExperience { get; set; } = 0; + public static Implementer? Create(ImplementerBindingModel model) { if (model == null) { diff --git a/TravelCompany/TravelCompanyFileImplement/Models/MessageInfo.cs b/TravelCompany/TravelCompanyFileImplement/Models/MessageInfo.cs index c0d8a62..9be812f 100644 --- a/TravelCompany/TravelCompanyFileImplement/Models/MessageInfo.cs +++ b/TravelCompany/TravelCompanyFileImplement/Models/MessageInfo.cs @@ -4,24 +4,35 @@ using TravelCompanyDataModels.Models; using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; namespace TravelCompanyFileImplement.Models { + [DataContract] public class MessageInfo : IMessageInfoModel { + [DataMember] + public int Id { get; private set; } + + [DataMember] public string MessageId { get; private set; } = string.Empty; + [DataMember] public int? ClientId { get; private set; } + [DataMember] public string SenderName { get; private set; } = string.Empty; + [DataMember] public DateTime DateDelivery { get; private set; } = DateTime.Now; + [DataMember] public string Subject { get; private set; } = string.Empty; + [DataMember] public string Body { get; private set; } = string.Empty; public static MessageInfo? Create(MessageInfoBindingModel model) diff --git a/TravelCompany/TravelCompanyFileImplement/Models/Order.cs b/TravelCompany/TravelCompanyFileImplement/Models/Order.cs index 1bfed3e..51ce9ed 100644 --- a/TravelCompany/TravelCompanyFileImplement/Models/Order.cs +++ b/TravelCompany/TravelCompanyFileImplement/Models/Order.cs @@ -8,23 +8,34 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; +using System.Runtime.Serialization; namespace TravelCompanyFileImplement.Models { + [DataContract] public class Order : IOrderModel { + [DataMember] public int TravelId { get; private set; } + [DataMember] public int ClientId { get; private set; } + [DataMember] public int? ImplementerId { get; private set; } = null; + [DataMember] public int Count { get; private set; } + [DataMember] public double Sum { get; private set; } + [DataMember] - public OrderStatus Status { get; private set; } + public OrderStatus Status { get; private set; } + [DataMember] public DateTime DateCreate { get; private set; } + [DataMember] public DateTime? DateImplement { get; private set; } + [DataMember] public int Id { get; private set; } diff --git a/TravelCompany/TravelCompanyFileImplement/Models/Travel.cs b/TravelCompany/TravelCompanyFileImplement/Models/Travel.cs index a493ee4..14d2ea8 100644 --- a/TravelCompany/TravelCompanyFileImplement/Models/Travel.cs +++ b/TravelCompany/TravelCompanyFileImplement/Models/Travel.cs @@ -7,13 +7,18 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; +using System.Runtime.Serialization; namespace TravelCompanyFileImplement.Models { + [DataContract] public class Travel : ITravelModel { + [DataMember] public int Id { get; private set; } + [DataMember] public string TravelName { get; private set; } = string.Empty; + [DataMember] public double Price { get; private set; } public Dictionary Components { get; private set; } = new(); private Dictionary? _TravelComponents = null; diff --git a/TravelCompany/TravelCompanyFileImplement/TravelCompanyFileImplement.csproj b/TravelCompany/TravelCompanyFileImplement/TravelCompanyFileImplement.csproj index 2cf28e6..0953b62 100644 --- a/TravelCompany/TravelCompanyFileImplement/TravelCompanyFileImplement.csproj +++ b/TravelCompany/TravelCompanyFileImplement/TravelCompanyFileImplement.csproj @@ -11,4 +11,7 @@ + + + diff --git a/TravelCompany/TravelCompanyListImplement/DataListSingleton.cs b/TravelCompany/TravelCompanyListImplement/DataListSingleton.cs index e24c406..cebcc42 100644 --- a/TravelCompany/TravelCompanyListImplement/DataListSingleton.cs +++ b/TravelCompany/TravelCompanyListImplement/DataListSingleton.cs @@ -1,4 +1,9 @@ using TravelCompanyListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; namespace TravelCompanyListImplement { @@ -21,6 +26,8 @@ namespace TravelCompanyListImplement Clients = new List(); Implementers = new List(); Messages = new List(); + + } public static DataListSingleton GetInstance() { diff --git a/TravelCompany/TravelCompanyListImplement/ImplementationExtension.cs b/TravelCompany/TravelCompanyListImplement/ImplementationExtension.cs new file mode 100644 index 0000000..95dcb49 --- /dev/null +++ b/TravelCompany/TravelCompanyListImplement/ImplementationExtension.cs @@ -0,0 +1,27 @@ +using TravelCompanyContracts.DI; +using TravelCompanyContracts.StoragesContracts; +using TravelCompanyListImplement.Implements; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyListImplement +{ + internal class ImplementationExtension : IImplementationExtension + { + public int Priority => 0; + + public void RegisterServices() + { + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } + } +} diff --git a/TravelCompany/TravelCompanyListImplement/Implements/BackUpInfo.cs b/TravelCompany/TravelCompanyListImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..f7a7223 --- /dev/null +++ b/TravelCompany/TravelCompanyListImplement/Implements/BackUpInfo.cs @@ -0,0 +1,22 @@ +using TravelCompanyContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyListImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + throw new NotImplementedException(); + } + + public Type? GetTypeByModelInterface(string modelInterfaceName) + { + throw new NotImplementedException(); + } + } +} diff --git a/TravelCompany/TravelCompanyListImplement/Models/MessageInfo.cs b/TravelCompany/TravelCompanyListImplement/Models/MessageInfo.cs index 4ed93a1..13ba2f7 100644 --- a/TravelCompany/TravelCompanyListImplement/Models/MessageInfo.cs +++ b/TravelCompany/TravelCompanyListImplement/Models/MessageInfo.cs @@ -23,6 +23,8 @@ namespace TravelCompanyListImplement.Models public string Body { get; private set; } = string.Empty; + public int Id => throw new NotImplementedException(); + public static MessageInfo? Create(MessageInfoBindingModel model) { if (model == null) diff --git a/TravelCompany/TravelCompanyListImplement/TravelCompanyListImplement.csproj b/TravelCompany/TravelCompanyListImplement/TravelCompanyListImplement.csproj index 9ba85b1..fc03212 100644 --- a/TravelCompany/TravelCompanyListImplement/TravelCompanyListImplement.csproj +++ b/TravelCompany/TravelCompanyListImplement/TravelCompanyListImplement.csproj @@ -11,4 +11,7 @@ + + +