diff --git a/ITServiceManager/ITServiceManager/Entities/Order.cs b/ITServiceManager/ITServiceManager/Entities/Order.cs index 2fee510..44ea53a 100644 --- a/ITServiceManager/ITServiceManager/Entities/Order.cs +++ b/ITServiceManager/ITServiceManager/Entities/Order.cs @@ -8,10 +8,8 @@ public class Order public decimal OrderPrice { get; private set; } public IEnumerable OrderService { get; private set; } = []; - public IEnumerable Appointments { get; private set; } = []; - public static Order CreateOperation(int id, int companyId, decimal orderPrice, IEnumerable orderService, - IEnumerable appointments) + public static Order CreateOperation(int id, int companyId, decimal orderPrice, IEnumerable orderService) { return new Order { @@ -19,8 +17,7 @@ public class Order CompanyId = companyId, OrderDate = DateTime.Now, OrderPrice = orderPrice, - OrderService = orderService, - Appointments = appointments + OrderService = orderService }; } } diff --git a/ITServiceManager/ITServiceManager/Entities/OrderService.cs b/ITServiceManager/ITServiceManager/Entities/OrderService.cs index f2ef394..68457f1 100644 --- a/ITServiceManager/ITServiceManager/Entities/OrderService.cs +++ b/ITServiceManager/ITServiceManager/Entities/OrderService.cs @@ -15,6 +15,7 @@ public class OrderService Id = id, OrderId = orderId, ServiceId = serviceId, + Quantity = serviceQuantity, ExecutionDate = executionDate }; } diff --git a/ITServiceManager/ITServiceManager/Entities/Service.cs b/ITServiceManager/ITServiceManager/Entities/Service.cs index cdf7d3c..b017541 100644 --- a/ITServiceManager/ITServiceManager/Entities/Service.cs +++ b/ITServiceManager/ITServiceManager/Entities/Service.cs @@ -6,15 +6,12 @@ public class Service public string Name { get; private set; } = string.Empty; public string Description { get; private set; } = string.Empty; - public IEnumerable OrderService { get; private set; } = []; - - public static Service CreateEntity(int id, string serviceName, IEnumerable orderService, string description) + public static Service CreateEntity(int id, string serviceName, string description) { return new Service { Id = id, Name = serviceName, - OrderService = orderService, Description = description }; } diff --git a/ITServiceManager/ITServiceManager/FormItCompany.Designer.cs b/ITServiceManager/ITServiceManager/FormItCompany.Designer.cs index 1555d98..fac54ef 100644 --- a/ITServiceManager/ITServiceManager/FormItCompany.Designer.cs +++ b/ITServiceManager/ITServiceManager/FormItCompany.Designer.cs @@ -30,13 +30,13 @@ { menuStrip1 = new MenuStrip(); справочникиToolStripMenuItem = new ToolStripMenuItem(); - операцииToolStripMenuItem = new ToolStripMenuItem(); - отчетыToolStripMenuItem = new ToolStripMenuItem(); компанииToolStripMenuItem = new ToolStripMenuItem(); сотрудникиToolStripMenuItem = new ToolStripMenuItem(); услугиToolStripMenuItem = new ToolStripMenuItem(); + операцииToolStripMenuItem = new ToolStripMenuItem(); заказыToolStripMenuItem = new ToolStripMenuItem(); назначениеСотрудниковToolStripMenuItem = new ToolStripMenuItem(); + отчетыToolStripMenuItem = new ToolStripMenuItem(); menuStrip1.SuspendLayout(); SuspendLayout(); // @@ -56,6 +56,27 @@ справочникиToolStripMenuItem.Size = new Size(94, 20); справочникиToolStripMenuItem.Text = "Справочники"; // + // компанииToolStripMenuItem + // + компанииToolStripMenuItem.Name = "компанииToolStripMenuItem"; + компанииToolStripMenuItem.Size = new Size(180, 22); + компанииToolStripMenuItem.Text = "Компании"; + компанииToolStripMenuItem.Click += CompaniesToolStripMenuItem_Click; + // + // сотрудникиToolStripMenuItem + // + сотрудникиToolStripMenuItem.Name = "сотрудникиToolStripMenuItem"; + сотрудникиToolStripMenuItem.Size = new Size(180, 22); + сотрудникиToolStripMenuItem.Text = "Сотрудники"; + сотрудникиToolStripMenuItem.Click += EmployeesToolStripMenuItem_Click; + // + // услугиToolStripMenuItem + // + услугиToolStripMenuItem.Name = "услугиToolStripMenuItem"; + услугиToolStripMenuItem.Size = new Size(180, 22); + услугиToolStripMenuItem.Text = "Услуги"; + услугиToolStripMenuItem.Click += ServicesToolStripMenuItem_Click; + // // операцииToolStripMenuItem // операцииToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { заказыToolStripMenuItem, назначениеСотрудниковToolStripMenuItem }); @@ -63,41 +84,25 @@ операцииToolStripMenuItem.Size = new Size(75, 20); операцииToolStripMenuItem.Text = "Операции"; // - // отчетыToolStripMenuItem - // - отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; - отчетыToolStripMenuItem.Size = new Size(60, 20); - отчетыToolStripMenuItem.Text = "Отчеты"; - // - // компанииToolStripMenuItem - // - компанииToolStripMenuItem.Name = "компанииToolStripMenuItem"; - компанииToolStripMenuItem.Size = new Size(180, 22); - компанииToolStripMenuItem.Text = "Компании"; - // - // сотрудникиToolStripMenuItem - // - сотрудникиToolStripMenuItem.Name = "сотрудникиToolStripMenuItem"; - сотрудникиToolStripMenuItem.Size = new Size(180, 22); - сотрудникиToolStripMenuItem.Text = "Сотрудники"; - // - // услугиToolStripMenuItem - // - услугиToolStripMenuItem.Name = "услугиToolStripMenuItem"; - услугиToolStripMenuItem.Size = new Size(180, 22); - услугиToolStripMenuItem.Text = "Услуги"; - // // заказыToolStripMenuItem // заказыToolStripMenuItem.Name = "заказыToolStripMenuItem"; заказыToolStripMenuItem.Size = new Size(213, 22); заказыToolStripMenuItem.Text = "Заказы"; + заказыToolStripMenuItem.Click += OrdersToolStripMenuItem_Click; // // назначениеСотрудниковToolStripMenuItem // назначениеСотрудниковToolStripMenuItem.Name = "назначениеСотрудниковToolStripMenuItem"; назначениеСотрудниковToolStripMenuItem.Size = new Size(213, 22); назначениеСотрудниковToolStripMenuItem.Text = "Назначение сотрудников"; + назначениеСотрудниковToolStripMenuItem.Click += AppointmentsToolStripMenuItem_Click; + // + // отчетыToolStripMenuItem + // + отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; + отчетыToolStripMenuItem.Size = new Size(60, 20); + отчетыToolStripMenuItem.Text = "Отчеты"; // // FormItCompany // diff --git a/ITServiceManager/ITServiceManager/FormItCompany.cs b/ITServiceManager/ITServiceManager/FormItCompany.cs index 2a82df0..f2eb569 100644 --- a/ITServiceManager/ITServiceManager/FormItCompany.cs +++ b/ITServiceManager/ITServiceManager/FormItCompany.cs @@ -1,10 +1,76 @@ +using ITServiceManager.Forms; +using Unity; + namespace ITServiceManager { public partial class FormItCompany : Form { - public FormItCompany() + private readonly IUnityContainer _container; + public FormItCompany(IUnityContainer container) { InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); + } + + private void CompaniesToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void EmployeesToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ServicesToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } + + private void OrdersToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void AppointmentsToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } } } } diff --git a/ITServiceManager/ITServiceManager/Forms/FormAppointment.Designer.cs b/ITServiceManager/ITServiceManager/Forms/FormAppointment.Designer.cs index 221c805..b76d94c 100644 --- a/ITServiceManager/ITServiceManager/Forms/FormAppointment.Designer.cs +++ b/ITServiceManager/ITServiceManager/Forms/FormAppointment.Designer.cs @@ -28,12 +28,140 @@ /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "FormAppointment"; + label1 = new Label(); + label2 = new Label(); + comboBoxEmployee = new ComboBox(); + comboBoxOrder = new ComboBox(); + dateTimePickerStart = new DateTimePicker(); + label3 = new Label(); + label4 = new Label(); + buttonCancel = new Button(); + buttonAdd = new Button(); + dateTimePickerEnd = new DateTimePicker(); + SuspendLayout(); + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(46, 46); + label1.Name = "label1"; + label1.Size = new Size(40, 15); + label1.TabIndex = 0; + label1.Text = "Заказ:"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(46, 141); + label2.Name = "label2"; + label2.Size = new Size(69, 15); + label2.TabIndex = 1; + label2.Text = "Сотрудник:"; + // + // comboBoxEmployee + // + comboBoxEmployee.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxEmployee.FormattingEnabled = true; + comboBoxEmployee.Location = new Point(214, 138); + comboBoxEmployee.Name = "comboBoxEmployee"; + comboBoxEmployee.Size = new Size(207, 23); + comboBoxEmployee.TabIndex = 2; + // + // comboBoxOrder + // + comboBoxOrder.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxOrder.FormattingEnabled = true; + comboBoxOrder.Location = new Point(214, 46); + comboBoxOrder.Name = "comboBoxOrder"; + comboBoxOrder.Size = new Size(207, 23); + comboBoxOrder.TabIndex = 3; + // + // dateTimePickerStart + // + dateTimePickerStart.ImeMode = ImeMode.Disable; + dateTimePickerStart.Location = new Point(214, 228); + dateTimePickerStart.Name = "dateTimePickerStart"; + dateTimePickerStart.Size = new Size(207, 23); + dateTimePickerStart.TabIndex = 4; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(46, 234); + label3.Name = "label3"; + label3.Size = new Size(149, 15); + label3.TabIndex = 5; + label3.Text = "Дата назначения на заказ:"; + // + // label4 + // + label4.AutoSize = true; + label4.Location = new Point(46, 328); + label4.Name = "label4"; + label4.Size = new Size(95, 15); + label4.TabIndex = 6; + label4.Text = "Дата окончания"; + // + // buttonCancel + // + buttonCancel.Location = new Point(285, 442); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(112, 28); + buttonCancel.TabIndex = 9; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // buttonAdd + // + buttonAdd.Location = new Point(59, 442); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(112, 28); + buttonAdd.TabIndex = 8; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dateTimePickerEnd + // + dateTimePickerEnd.ImeMode = ImeMode.Disable; + dateTimePickerEnd.Location = new Point(214, 328); + dateTimePickerEnd.Name = "dateTimePickerEnd"; + dateTimePickerEnd.Size = new Size(207, 23); + dateTimePickerEnd.TabIndex = 10; + // + // FormAppointment + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(476, 505); + Controls.Add(dateTimePickerEnd); + Controls.Add(buttonCancel); + Controls.Add(buttonAdd); + Controls.Add(label4); + Controls.Add(label3); + Controls.Add(dateTimePickerStart); + Controls.Add(comboBoxOrder); + Controls.Add(comboBoxEmployee); + Controls.Add(label2); + Controls.Add(label1); + Name = "FormAppointment"; + Text = "Назначение"; + ResumeLayout(false); + PerformLayout(); } #endregion + + private Label label1; + private Label label2; + private ComboBox comboBoxEmployee; + private ComboBox comboBoxOrder; + private DateTimePicker dateTimePickerStart; + private Label label3; + private Label label4; + private Button buttonCancel; + private Button buttonAdd; + private DateTimePicker dateTimePickerEnd; } } \ No newline at end of file diff --git a/ITServiceManager/ITServiceManager/Forms/FormAppointment.cs b/ITServiceManager/ITServiceManager/Forms/FormAppointment.cs index 6b7bf54..879aa55 100644 --- a/ITServiceManager/ITServiceManager/Forms/FormAppointment.cs +++ b/ITServiceManager/ITServiceManager/Forms/FormAppointment.cs @@ -1,4 +1,7 @@ -using System; +using ITServiceManager.Entities; +using ITServiceManager.Repositories; +using ITServiceManager.Repositories.Implementations; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -12,9 +15,72 @@ namespace ITServiceManager.Forms { public partial class FormAppointment : Form { - public FormAppointment() + private readonly IAppointmentRepository _appointmentRepository; + private int? _appointmentId; + public int Id + { + set + { + try + { + var appointment = + _appointmentRepository.ReadAppointmentById(value); + if (appointment == null) + { + throw new + InvalidDataException(nameof(appointment)); + } + comboBoxEmployee.SelectedIndex = appointment.EmployeeId; + comboBoxOrder.SelectedIndex = appointment.OrderId; + _appointmentId = value; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + } + } + public FormAppointment(IAppointmentRepository appointmentRepository, IEmployeeRepository employeeRepository, IOrderRepository orderRepository) { InitializeComponent(); + _appointmentRepository = appointmentRepository ?? + throw new ArgumentNullException(nameof(appointmentRepository)); + + comboBoxOrder.DataSource = orderRepository.ReadOrders(); + comboBoxOrder.DisplayMember = "Name"; + comboBoxOrder.ValueMember = "Id"; + + comboBoxEmployee.DataSource = employeeRepository.ReadEmployees(); + comboBoxEmployee.DisplayMember = "Name"; + comboBoxEmployee.ValueMember = "Id"; } + private void ButtonAdd_Click(object sender, EventArgs e) + { + try + { + if (comboBoxEmployee.SelectedIndex < 0 || comboBoxOrder.SelectedIndex < 0 || dateTimePickerStart.CustomFormat != " ") + { + throw new Exception("Имеются незаполненные поля"); + } + if (_appointmentId.HasValue) + { + _appointmentRepository.UpdateAppointment(CreateAppointment(_appointmentId.Value)); + } + else + { + _appointmentRepository.CreateAppointment(CreateAppointment(0)); + } + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonCancel_Click(object sender, EventArgs e) => Close(); + private Appointment CreateAppointment(int id) => Appointment.CreateOperation(id, comboBoxOrder.SelectedIndex, comboBoxEmployee.SelectedIndex, Convert.ToDateTime(dateTimePickerStart) , + Convert.ToDateTime(dateTimePickerEnd)); } } diff --git a/ITServiceManager/ITServiceManager/Forms/FormAppointment.resx b/ITServiceManager/ITServiceManager/Forms/FormAppointment.resx index 1af7de1..af32865 100644 --- a/ITServiceManager/ITServiceManager/Forms/FormAppointment.resx +++ b/ITServiceManager/ITServiceManager/Forms/FormAppointment.resx @@ -1,17 +1,17 @@  - diff --git a/ITServiceManager/ITServiceManager/Forms/FormAppointments.Designer.cs b/ITServiceManager/ITServiceManager/Forms/FormAppointments.Designer.cs new file mode 100644 index 0000000..1bf330d --- /dev/null +++ b/ITServiceManager/ITServiceManager/Forms/FormAppointments.Designer.cs @@ -0,0 +1,112 @@ +namespace ITServiceManager.Forms +{ + partial class FormAppointments + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridView = new DataGridView(); + panel = new Panel(); + buttonUpdate = new Button(); + buttonAdd = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + panel.SuspendLayout(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.AllowUserToResizeColumns = false; + dataGridView.AllowUserToResizeRows = false; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Fill; + dataGridView.Location = new Point(0, 0); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 25; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(652, 450); + dataGridView.TabIndex = 2; + // + // panel + // + panel.Controls.Add(buttonUpdate); + panel.Controls.Add(buttonAdd); + panel.Dock = DockStyle.Right; + panel.Location = new Point(652, 0); + panel.Name = "panel"; + panel.Size = new Size(148, 450); + panel.TabIndex = 3; + // + // buttonUpdate + // + buttonUpdate.BackgroundImage = Properties.Resources.edit; + buttonUpdate.BackgroundImageLayout = ImageLayout.Stretch; + buttonUpdate.Location = new Point(33, 269); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(81, 80); + buttonUpdate.TabIndex = 2; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += ButtonUpd_Click; + // + // buttonAdd + // + buttonAdd.BackgroundImage = Properties.Resources.plus; + buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; + buttonAdd.Location = new Point(33, 43); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(81, 71); + buttonAdd.TabIndex = 0; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // FormAppointments + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridView); + Controls.Add(panel); + Name = "FormAppointments"; + Text = "Назначения"; + Load += FormAppointments_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + panel.ResumeLayout(false); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Panel panel; + private Button buttonUpdate; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/ITServiceManager/ITServiceManager/Forms/FormAppointments.cs b/ITServiceManager/ITServiceManager/Forms/FormAppointments.cs new file mode 100644 index 0000000..974dfc7 --- /dev/null +++ b/ITServiceManager/ITServiceManager/Forms/FormAppointments.cs @@ -0,0 +1,81 @@ +using ITServiceManager.Repositories; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using Unity; + +namespace ITServiceManager.Forms +{ + public partial class FormAppointments : Form + { + private readonly IUnityContainer _container; + private readonly IAppointmentRepository _appointmentRepository; + public FormAppointments(IUnityContainer container, IAppointmentRepository appointmentRepository) + { + InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); + _appointmentRepository = appointmentRepository ?? throw new ArgumentNullException(nameof(appointmentRepository)); + } + private void FormAppointments_Load(object sender, EventArgs e) + { + try + { + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var findId)) + { + return; + } + try + { + var form = _container.Resolve(); + form.Id = findId; + form.ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при изменении", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void LoadList() => dataGridView.DataSource = _appointmentRepository.ReadAppointments(); + private bool TryGetIdentifierFromSelectedRow(out int id) + { + id = 0; + if (dataGridView.SelectedRows.Count < 1) + { + MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + return true; + } + } +} + diff --git a/ITServiceManager/ITServiceManager/Forms/FormAppointments.resx b/ITServiceManager/ITServiceManager/Forms/FormAppointments.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ITServiceManager/ITServiceManager/Forms/FormAppointments.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ITServiceManager/ITServiceManager/Forms/FormCompany.Designer.cs b/ITServiceManager/ITServiceManager/Forms/FormCompany.Designer.cs index ba3471a..746c07f 100644 --- a/ITServiceManager/ITServiceManager/Forms/FormCompany.Designer.cs +++ b/ITServiceManager/ITServiceManager/Forms/FormCompany.Designer.cs @@ -39,27 +39,25 @@ // labelName // labelName.AutoSize = true; - labelName.Location = new Point(102, 135); + labelName.Location = new Point(89, 101); labelName.Name = "labelName"; - labelName.Size = new Size(152, 20); + labelName.Size = new Size(118, 15); labelName.TabIndex = 0; labelName.Text = "Название компании"; // // textBoxName // - textBoxName.Location = new Point(306, 131); - textBoxName.Margin = new Padding(3, 4, 3, 4); + textBoxName.Location = new Point(268, 98); textBoxName.Name = "textBoxName"; - textBoxName.Size = new Size(201, 27); + textBoxName.Size = new Size(200, 23); textBoxName.TabIndex = 1; textBoxName.TextChanged += textBoxName_TextChanged; // // buttonAdd // - buttonAdd.Location = new Point(109, 317); - buttonAdd.Margin = new Padding(3, 4, 3, 4); + buttonAdd.Location = new Point(95, 238); buttonAdd.Name = "buttonAdd"; - buttonAdd.Size = new Size(128, 37); + buttonAdd.Size = new Size(112, 28); buttonAdd.TabIndex = 2; buttonAdd.Text = "Добавить"; buttonAdd.UseVisualStyleBackColor = true; @@ -67,10 +65,9 @@ // // buttonCancel // - buttonCancel.Location = new Point(367, 317); - buttonCancel.Margin = new Padding(3, 4, 3, 4); + buttonCancel.Location = new Point(321, 238); buttonCancel.Name = "buttonCancel"; - buttonCancel.Size = new Size(128, 37); + buttonCancel.Size = new Size(112, 28); buttonCancel.TabIndex = 3; buttonCancel.Text = "Отмена"; buttonCancel.UseVisualStyleBackColor = true; @@ -79,32 +76,30 @@ // labelAddres // labelAddres.AutoSize = true; - labelAddres.Location = new Point(121, 195); + labelAddres.Location = new Point(106, 146); labelAddres.Name = "labelAddres"; - labelAddres.Size = new Size(133, 20); + labelAddres.Size = new Size(105, 15); labelAddres.TabIndex = 4; labelAddres.Text = "Адресс компании"; // // textBoxAddress // - textBoxAddress.Location = new Point(306, 188); - textBoxAddress.Margin = new Padding(3, 4, 3, 4); + textBoxAddress.Location = new Point(268, 141); textBoxAddress.Name = "textBoxAddress"; - textBoxAddress.Size = new Size(201, 27); + textBoxAddress.Size = new Size(200, 23); textBoxAddress.TabIndex = 5; // // FormCompany // - AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(613, 408); + ClientSize = new Size(570, 306); Controls.Add(textBoxAddress); Controls.Add(labelAddres); Controls.Add(buttonCancel); Controls.Add(buttonAdd); Controls.Add(textBoxName); Controls.Add(labelName); - Margin = new Padding(3, 4, 3, 4); Name = "FormCompany"; StartPosition = FormStartPosition.CenterParent; Text = "Компания"; diff --git a/ITServiceManager/ITServiceManager/Forms/FormEmployee.Designer.cs b/ITServiceManager/ITServiceManager/Forms/FormEmployee.Designer.cs index 2898a3c..b4c05ec 100644 --- a/ITServiceManager/ITServiceManager/Forms/FormEmployee.Designer.cs +++ b/ITServiceManager/ITServiceManager/Forms/FormEmployee.Designer.cs @@ -46,6 +46,7 @@ buttonCancel.TabIndex = 7; buttonCancel.Text = "Отмена"; buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; // // buttonAdd // @@ -122,7 +123,7 @@ Controls.Add(labelFirstName); Name = "FormEmployee"; StartPosition = FormStartPosition.CenterScreen; - Text = "FormEmployee"; + Text = "Сотрудник"; ResumeLayout(false); PerformLayout(); } diff --git a/ITServiceManager/ITServiceManager/Forms/FormEmployee.cs b/ITServiceManager/ITServiceManager/Forms/FormEmployee.cs index bae3410..6383220 100644 --- a/ITServiceManager/ITServiceManager/Forms/FormEmployee.cs +++ b/ITServiceManager/ITServiceManager/Forms/FormEmployee.cs @@ -1,86 +1,74 @@ using ITServiceManager.Entities; using ITServiceManager.Entities.Enums; using ITServiceManager.Repositories; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; +namespace ITServiceManager.Forms; -namespace ITServiceManager.Forms +public partial class FormEmployee : Form { - public partial class FormEmployee : Form + private readonly IEmployeeRepository _employeeRepository; + private int? _employeeId; + public int Id { - private readonly IEmployeeRepository _employeeRepository; - private int? _employeeId; - public int Id - { - set - { - try - { - var employee = - _employeeRepository.ReadEmployeeById(value); - if (employee == null) - { - throw new - InvalidDataException(nameof(employee)); - } - textBoxFirstName.Text = employee.FirstName; - textBoxLastName.Text = employee.LastName; - comboBoxPost.SelectedItem = - employee.Position; - _employeeId = value; - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - } - } - public FormEmployee(IEmployeeRepository employeeRepository) - { - InitializeComponent(); - _employeeRepository = employeeRepository ?? - throw new - ArgumentNullException(nameof(employeeRepository)); - comboBoxPost.DataSource = - Enum.GetValues(typeof(EmployeePost)); - } - private void ButtonAdd_Click(object sender, EventArgs e) + set { try { - if (string.IsNullOrWhiteSpace(textBoxFirstName.Text) || - string.IsNullOrWhiteSpace(textBoxLastName.Text) - || - comboBoxPost.SelectedIndex < 1) + var employee = + _employeeRepository.ReadEmployeeById(value); + if (employee == null) { - throw new Exception("Имеются незаполненные поля"); + throw new + InvalidDataException(nameof(employee)); } - if (_employeeId.HasValue) - { - _employeeRepository.UpdateEmployee(CreateEmployee(_employeeId.Value)); - } - else - { - _employeeRepository.CreateEmployee(CreateEmployee(0)); - } - Close(); + textBoxFirstName.Text = employee.FirstName; + textBoxLastName.Text = employee.LastName; + comboBoxPost.SelectedItem = + employee.Position; + _employeeId = value; } catch (Exception ex) { - MessageBox.Show(ex.Message, "Ошибка при сохранении", - MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; } } - private void ButtonCancel_Click(object sender, EventArgs e) => Close(); - private Employee CreateEmployee(int id) => Employee.CreateEntity(id, textBoxFirstName.Text, textBoxLastName.Text, (EmployeePost)comboBoxPost.SelectedItem!); } - + public FormEmployee(IEmployeeRepository employeeRepository) + { + InitializeComponent(); + _employeeRepository = employeeRepository ?? + throw new + ArgumentNullException(nameof(employeeRepository)); + comboBoxPost.DataSource = + Enum.GetValues(typeof(EmployeePost)); + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + try + { + if (string.IsNullOrWhiteSpace(textBoxFirstName.Text) || + string.IsNullOrWhiteSpace(textBoxLastName.Text) + || + comboBoxPost.SelectedIndex < 1) + { + throw new Exception("Имеются незаполненные поля"); + } + if (_employeeId.HasValue) + { + _employeeRepository.UpdateEmployee(CreateEmployee(_employeeId.Value)); + } + else + { + _employeeRepository.CreateEmployee(CreateEmployee(0)); + } + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonCancel_Click(object sender, EventArgs e) => Close(); + private Employee CreateEmployee(int id) => Employee.CreateEntity(id, textBoxFirstName.Text, textBoxLastName.Text, (EmployeePost)comboBoxPost.SelectedItem!); } diff --git a/ITServiceManager/ITServiceManager/Forms/FormEmployees.Designer.cs b/ITServiceManager/ITServiceManager/Forms/FormEmployees.Designer.cs index 8936c74..9dc53e0 100644 --- a/ITServiceManager/ITServiceManager/Forms/FormEmployees.Designer.cs +++ b/ITServiceManager/ITServiceManager/Forms/FormEmployees.Designer.cs @@ -43,44 +43,43 @@ panel.Controls.Add(buttonRemove); panel.Controls.Add(buttonAdd); panel.Dock = DockStyle.Right; - panel.Location = new Point(745, 0); - panel.Margin = new Padding(3, 4, 3, 4); + panel.Location = new Point(652, 0); panel.Name = "panel"; - panel.Size = new Size(169, 600); + panel.Size = new Size(148, 450); panel.TabIndex = 2; // // buttonUpdate // buttonUpdate.BackgroundImage = Properties.Resources.edit; buttonUpdate.BackgroundImageLayout = ImageLayout.Stretch; - buttonUpdate.Location = new Point(41, 332); - buttonUpdate.Margin = new Padding(3, 4, 3, 4); + buttonUpdate.Location = new Point(36, 249); buttonUpdate.Name = "buttonUpdate"; - buttonUpdate.Size = new Size(89, 107); + buttonUpdate.Size = new Size(78, 80); buttonUpdate.TabIndex = 2; buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += ButtonUpd_Click; // // buttonRemove // buttonRemove.BackgroundImage = Properties.Resources.minus; buttonRemove.BackgroundImageLayout = ImageLayout.Stretch; - buttonRemove.Location = new Point(41, 188); - buttonRemove.Margin = new Padding(3, 4, 3, 4); + buttonRemove.Location = new Point(36, 141); buttonRemove.Name = "buttonRemove"; - buttonRemove.Size = new Size(86, 101); + buttonRemove.Size = new Size(75, 76); buttonRemove.TabIndex = 1; buttonRemove.UseVisualStyleBackColor = true; + buttonRemove.Click += ButtonDel_Click; // // buttonAdd // buttonAdd.BackgroundImage = Properties.Resources.plus; buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; - buttonAdd.Location = new Point(38, 57); - buttonAdd.Margin = new Padding(3, 4, 3, 4); + buttonAdd.Location = new Point(33, 43); buttonAdd.Name = "buttonAdd"; - buttonAdd.Size = new Size(93, 95); + buttonAdd.Size = new Size(81, 71); buttonAdd.TabIndex = 0; buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; // // dataGridView // @@ -91,7 +90,6 @@ dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridView.Dock = DockStyle.Fill; dataGridView.Location = new Point(0, 0); - dataGridView.Margin = new Padding(3, 4, 3, 4); dataGridView.MultiSelect = false; dataGridView.Name = "dataGridView"; dataGridView.ReadOnly = true; @@ -99,19 +97,21 @@ dataGridView.RowHeadersWidth = 51; dataGridView.RowTemplate.Height = 25; dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; - dataGridView.Size = new Size(745, 600); + dataGridView.Size = new Size(652, 450); dataGridView.TabIndex = 3; // // FormEmployees // - AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(914, 600); + ClientSize = new Size(800, 450); Controls.Add(dataGridView); Controls.Add(panel); + Margin = new Padding(3, 2, 3, 2); Name = "FormEmployees"; StartPosition = FormStartPosition.CenterScreen; - Text = "FormEmployees"; + Text = "Сотрудники"; + Load += FormEmployees_Load; panel.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ResumeLayout(false); diff --git a/ITServiceManager/ITServiceManager/Forms/FormOrder.Designer.cs b/ITServiceManager/ITServiceManager/Forms/FormOrder.Designer.cs index 0f3cbed..060f37b 100644 --- a/ITServiceManager/ITServiceManager/Forms/FormOrder.Designer.cs +++ b/ITServiceManager/ITServiceManager/Forms/FormOrder.Designer.cs @@ -28,12 +28,146 @@ /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "FormOrder"; + DataGridViewCellStyle dataGridViewCellStyle1 = new DataGridViewCellStyle(); + dataGridView = new DataGridView(); + ColumnService = new DataGridViewComboBoxColumn(); + ColumnQuantity = new DataGridViewTextBoxColumn(); + ColumnExecutionDate = new DataGridViewTextBoxColumn(); + buttonCancel = new Button(); + buttonAdd = new Button(); + label1 = new Label(); + comboBoxCompany = new ComboBox(); + label2 = new Label(); + numericUpDownPrice = new NumericUpDown(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownPrice).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnService, ColumnQuantity, ColumnExecutionDate }); + dataGridView.Location = new Point(12, 232); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(492, 263); + dataGridView.TabIndex = 1; + // + // ColumnService + // + ColumnService.HeaderText = "Услуга"; + ColumnService.Name = "ColumnService"; + ColumnService.ReadOnly = true; + // + // ColumnQuantity + // + ColumnQuantity.HeaderText = "Количество"; + ColumnQuantity.Name = "ColumnQuantity"; + ColumnQuantity.ReadOnly = true; + // + // ColumnExecutionDate + // + dataGridViewCellStyle1.Format = "F"; + dataGridViewCellStyle1.NullValue = null; + ColumnExecutionDate.DefaultCellStyle = dataGridViewCellStyle1; + ColumnExecutionDate.HeaderText = "Срок"; + ColumnExecutionDate.Name = "ColumnExecutionDate"; + ColumnExecutionDate.ReadOnly = true; + // + // buttonCancel + // + buttonCancel.Location = new Point(320, 514); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(112, 28); + buttonCancel.TabIndex = 9; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // buttonAdd + // + buttonAdd.Location = new Point(64, 514); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(112, 28); + buttonAdd.TabIndex = 8; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(52, 45); + label1.Name = "label1"; + label1.Size = new Size(63, 15); + label1.TabIndex = 10; + label1.Text = "Компания"; + // + // comboBoxCompany + // + comboBoxCompany.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxCompany.FormattingEnabled = true; + comboBoxCompany.Location = new Point(181, 42); + comboBoxCompany.Name = "comboBoxCompany"; + comboBoxCompany.Size = new Size(240, 23); + comboBoxCompany.TabIndex = 11; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(52, 123); + label2.Name = "label2"; + label2.Size = new Size(99, 15); + label2.TabIndex = 12; + label2.Text = "Сумма договора"; + // + // numericUpDownPrice + // + numericUpDownPrice.DecimalPlaces = 2; + numericUpDownPrice.Location = new Point(181, 121); + numericUpDownPrice.Maximum = new decimal(new int[] { 1000000, 0, 0, 0 }); + numericUpDownPrice.Name = "numericUpDownPrice"; + numericUpDownPrice.Size = new Size(240, 23); + numericUpDownPrice.TabIndex = 13; + // + // FormOrder + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(516, 576); + Controls.Add(numericUpDownPrice); + Controls.Add(label2); + Controls.Add(comboBoxCompany); + Controls.Add(label1); + Controls.Add(buttonCancel); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormOrder"; + Text = "Заказ"; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownPrice).EndInit(); + ResumeLayout(false); + PerformLayout(); } #endregion + + private Label label1; + private DataGridView dataGridView; + private DataGridViewComboBoxColumn ColumnProducts; + private DataGridViewTextBoxColumn ColumnCount; + private Button buttonCancel; + private Button buttonAdd; + private ComboBox comboBoxCompany; + private Label label2; + private NumericUpDown numericUpDownPrice; + private DataGridViewComboBoxColumn ColumnService; + private DataGridViewTextBoxColumn ColumnQuantity; + private DataGridViewTextBoxColumn ColumnExecutionDate; } } \ No newline at end of file diff --git a/ITServiceManager/ITServiceManager/Forms/FormOrder.cs b/ITServiceManager/ITServiceManager/Forms/FormOrder.cs index 5a47428..25ea8c7 100644 --- a/ITServiceManager/ITServiceManager/Forms/FormOrder.cs +++ b/ITServiceManager/ITServiceManager/Forms/FormOrder.cs @@ -1,4 +1,6 @@ -using System; +using ITServiceManager.Entities; +using ITServiceManager.Repositories; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -7,14 +9,56 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using System.Windows.Forms.VisualStyles; namespace ITServiceManager.Forms { public partial class FormOrder : Form { - public FormOrder() + private readonly IOrderRepository _orderRepository; + public FormOrder(IOrderRepository orderRepository, IServiceRepository serviceRepository, ICompanyRepository companyRepository) { InitializeComponent(); + _orderRepository = orderRepository ?? throw new ArgumentNullException(nameof(orderRepository)); + + comboBoxCompany.DataSource = companyRepository.ReadCompanies(); + comboBoxCompany.DisplayMember = "Name"; + comboBoxCompany.ValueMember = "Id"; + + ColumnService.DataSource = serviceRepository.ReadServices(); + ColumnService.DisplayMember = "Name"; + ColumnService.ValueMember = "Id"; + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + if (dataGridView.RowCount < 1 || comboBoxCompany.SelectedIndex < 0 || numericUpDownPrice.Value <= 0) + { + throw new Exception("Имеются незаполненны поля"); + } + try + { + _orderRepository.CreateOrder(Order.CreateOperation(0, comboBoxCompany.SelectedIndex, numericUpDownPrice.Value, CreateListProductFromDataGrid())); + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonCancel_Click(object sender, EventArgs e) => Close(); + private List CreateListProductFromDataGrid() + { + var list = new List(); + foreach (DataGridViewRow row in dataGridView.Rows) + { + if (row.Cells["ColumService"].Value == null || row.Cells["ColumQuantity"].Value == null || row.Cells["ColumnExecutionDate"].Value == null) + { + continue; + } + list.Add(OrderService.CreateOperation(0, 0, Convert.ToInt32(row.Cells["ColumnServices"].Value), Convert.ToInt32(row.Cells["ColumnQuantity"].Value), Convert.ToDateTime(row.Cells["ColumnExecutionDate"].Value))); + } + return list; } } } + diff --git a/ITServiceManager/ITServiceManager/Forms/FormOrder.resx b/ITServiceManager/ITServiceManager/Forms/FormOrder.resx index 1af7de1..3d8c384 100644 --- a/ITServiceManager/ITServiceManager/Forms/FormOrder.resx +++ b/ITServiceManager/ITServiceManager/Forms/FormOrder.resx @@ -1,17 +1,17 @@  - @@ -117,4 +117,13 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + True + + + True + + + True + \ No newline at end of file diff --git a/ITServiceManager/ITServiceManager/Forms/FormOrders.Designer.cs b/ITServiceManager/ITServiceManager/Forms/FormOrders.Designer.cs new file mode 100644 index 0000000..4638caa --- /dev/null +++ b/ITServiceManager/ITServiceManager/Forms/FormOrders.Designer.cs @@ -0,0 +1,113 @@ +namespace ITServiceManager.Forms +{ + partial class FormOrders + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + panel = new Panel(); + buttonRemove = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + panel.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // panel + // + panel.Controls.Add(buttonRemove); + panel.Controls.Add(buttonAdd); + panel.Dock = DockStyle.Right; + panel.Location = new Point(652, 0); + panel.Name = "panel"; + panel.Size = new Size(148, 450); + panel.TabIndex = 4; + // + // buttonRemove + // + buttonRemove.BackgroundImage = Properties.Resources.minus; + buttonRemove.BackgroundImageLayout = ImageLayout.Stretch; + buttonRemove.Location = new Point(39, 265); + buttonRemove.Name = "buttonRemove"; + buttonRemove.Size = new Size(75, 76); + buttonRemove.TabIndex = 1; + buttonRemove.UseVisualStyleBackColor = true; + buttonRemove.Click += ButtonRemove_Click; + // + // buttonAdd + // + buttonAdd.BackgroundImage = Properties.Resources.plus; + buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; + buttonAdd.Location = new Point(33, 92); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(81, 71); + buttonAdd.TabIndex = 0; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.AllowUserToResizeColumns = false; + dataGridView.AllowUserToResizeRows = false; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Fill; + dataGridView.Location = new Point(0, 0); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 25; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(652, 450); + dataGridView.TabIndex = 5; + // + // FormOrders + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridView); + Controls.Add(panel); + Name = "FormOrders"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Заказы"; + Load += FormOrders_Load; + panel.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Panel panel; + private Button buttonRemove; + private Button buttonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/ITServiceManager/ITServiceManager/Forms/FormOrders.cs b/ITServiceManager/ITServiceManager/Forms/FormOrders.cs new file mode 100644 index 0000000..16300b5 --- /dev/null +++ b/ITServiceManager/ITServiceManager/Forms/FormOrders.cs @@ -0,0 +1,81 @@ +using ITServiceManager.Repositories; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using Unity; + +namespace ITServiceManager.Forms +{ + public partial class FormOrders : Form + { + private readonly IUnityContainer _container; + private readonly IOrderRepository _orderRepository; + public FormOrders(IUnityContainer container, IOrderRepository orderRepository) + { + InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); + _orderRepository = orderRepository ?? throw new ArgumentNullException(nameof(orderRepository)); + } + private void FormOrders_Load(object sender, EventArgs e) + { + try + { + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonRemove_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var findId)) + { + return; + } + if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes) + { + return; + } + try + { + _orderRepository.DeleteOrder(findId); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void LoadList() => dataGridView.DataSource = _orderRepository.ReadOrders(); + private bool TryGetIdentifierFromSelectedRow(out int id) + { + id = 0; + if (dataGridView.SelectedRows.Count < 1) + { + MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + return true; + } + } +} diff --git a/ITServiceManager/ITServiceManager/Forms/FormOrders.resx b/ITServiceManager/ITServiceManager/Forms/FormOrders.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ITServiceManager/ITServiceManager/Forms/FormOrders.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ITServiceManager/ITServiceManager/Forms/FormService.Designer.cs b/ITServiceManager/ITServiceManager/Forms/FormService.Designer.cs index d1ced0d..506e6e8 100644 --- a/ITServiceManager/ITServiceManager/Forms/FormService.Designer.cs +++ b/ITServiceManager/ITServiceManager/Forms/FormService.Designer.cs @@ -31,78 +31,102 @@ buttonCancel = new Button(); buttonAdd = new Button(); textBoxName = new TextBox(); - labelName = new Label(); labelDescription = new Label(); richTextBoxDescription = new RichTextBox(); + label1 = new Label(); + label2 = new Label(); + labelName = new Label(); SuspendLayout(); // // buttonCancel // - buttonCancel.Location = new Point(463, 300); - buttonCancel.Margin = new Padding(3, 4, 3, 4); + buttonCancel.Location = new Point(313, 275); buttonCancel.Name = "buttonCancel"; - buttonCancel.Size = new Size(128, 37); + buttonCancel.Size = new Size(112, 28); buttonCancel.TabIndex = 7; buttonCancel.Text = "Отмена"; buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; // // buttonAdd // - buttonAdd.Location = new Point(205, 300); - buttonAdd.Margin = new Padding(3, 4, 3, 4); + buttonAdd.Location = new Point(87, 275); buttonAdd.Name = "buttonAdd"; - buttonAdd.Size = new Size(128, 37); + buttonAdd.Size = new Size(112, 28); buttonAdd.TabIndex = 6; buttonAdd.Text = "Добавить"; buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; // // textBoxName // - textBoxName.Location = new Point(402, 114); - textBoxName.Margin = new Padding(3, 4, 3, 4); + textBoxName.Location = new Point(243, 22); textBoxName.Name = "textBoxName"; - textBoxName.Size = new Size(264, 27); + textBoxName.Size = new Size(232, 23); textBoxName.TabIndex = 5; // - // labelName - // - labelName.AutoSize = true; - labelName.Location = new Point(132, 117); - labelName.Name = "labelName"; - labelName.Size = new Size(125, 20); - labelName.TabIndex = 4; - labelName.Text = "Название услуги"; - // // labelDescription // labelDescription.AutoSize = true; - labelDescription.Location = new Point(132, 193); + labelDescription.Location = new Point(21, 134); labelDescription.Name = "labelDescription"; - labelDescription.Size = new Size(127, 20); + labelDescription.Size = new Size(102, 15); labelDescription.TabIndex = 8; labelDescription.Text = "Описание услуги"; // // richTextBoxDescription // - richTextBoxDescription.Location = new Point(402, 161); + richTextBoxDescription.Location = new Point(243, 106); + richTextBoxDescription.Margin = new Padding(3, 2, 3, 2); richTextBoxDescription.Name = "richTextBoxDescription"; - richTextBoxDescription.Size = new Size(264, 120); + richTextBoxDescription.Size = new Size(232, 132); richTextBoxDescription.TabIndex = 9; richTextBoxDescription.Text = ""; // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(24, 25); + label1.Name = "label1"; + label1.Size = new Size(99, 15); + label1.TabIndex = 4; + label1.Text = "Название услуги"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(24, 134); + label2.Name = "label2"; + label2.Size = new Size(102, 15); + label2.TabIndex = 8; + label2.Text = "Описание услуги"; + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(21, 22); + labelName.Name = "labelName"; + labelName.Size = new Size(99, 15); + labelName.TabIndex = 4; + labelName.Text = "Название услуги"; + // // FormService // - AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(800, 450); + ClientSize = new Size(511, 338); Controls.Add(richTextBoxDescription); + Controls.Add(label2); Controls.Add(labelDescription); Controls.Add(buttonCancel); Controls.Add(buttonAdd); Controls.Add(textBoxName); + Controls.Add(label1); Controls.Add(labelName); + Margin = new Padding(3, 2, 3, 2); Name = "FormService"; - Text = "FormService"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Услуга"; ResumeLayout(false); PerformLayout(); } @@ -112,8 +136,10 @@ private Button buttonCancel; private Button buttonAdd; private TextBox textBoxName; - private Label labelName; private Label labelDescription; private RichTextBox richTextBoxDescription; + private Label label1; + private Label label2; + private Label labelName; } } \ No newline at end of file diff --git a/ITServiceManager/ITServiceManager/Forms/FormService.cs b/ITServiceManager/ITServiceManager/Forms/FormService.cs index beb78ce..9db7e24 100644 --- a/ITServiceManager/ITServiceManager/Forms/FormService.cs +++ b/ITServiceManager/ITServiceManager/Forms/FormService.cs @@ -1,20 +1,68 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; +using ITServiceManager.Entities.Enums; +using ITServiceManager.Entities; +using ITServiceManager.Repositories; -namespace ITServiceManager.Forms +namespace ITServiceManager.Forms; + +public partial class FormService : Form { - public partial class FormService : Form + private readonly IServiceRepository _serviceRepository; + private int? _serviceId; + public int Id { - public FormService() + set { - InitializeComponent(); + try + { + var service = + _serviceRepository.ReadServiceById(value); + if (service == null) + { + throw new + InvalidDataException(nameof(service)); + } + textBoxName.Text = service.Name; + richTextBoxDescription.Text = service.Description; + _serviceId = value; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } } } + public FormService(IServiceRepository serviceRepository) + { + InitializeComponent(); + _serviceRepository = serviceRepository ?? + throw new ArgumentNullException(nameof(serviceRepository)); + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + try + { + if (string.IsNullOrWhiteSpace(textBoxName.Text) || + string.IsNullOrWhiteSpace(richTextBoxDescription.Text)) + { + throw new Exception("Имеются незаполненные поля"); + } + if (_serviceId.HasValue) + { + _serviceRepository.UpdateService(CreateService(_serviceId.Value)); + } + else + { + _serviceRepository.CreateService(CreateService(0)); + } + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonCancel_Click(object sender, EventArgs e) => Close(); + private Service CreateService(int id) => Service.CreateEntity(id, textBoxName.Text, richTextBoxDescription.Text); } diff --git a/ITServiceManager/ITServiceManager/Forms/FormServices.Designer.cs b/ITServiceManager/ITServiceManager/Forms/FormServices.Designer.cs new file mode 100644 index 0000000..74444b4 --- /dev/null +++ b/ITServiceManager/ITServiceManager/Forms/FormServices.Designer.cs @@ -0,0 +1,127 @@ +namespace ITServiceManager.Forms +{ + partial class FormServices + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + panel = new Panel(); + buttonUpdate = new Button(); + buttonRemove = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + panel.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // panel + // + panel.Controls.Add(buttonUpdate); + panel.Controls.Add(buttonRemove); + panel.Controls.Add(buttonAdd); + panel.Dock = DockStyle.Right; + panel.Location = new Point(652, 0); + panel.Name = "panel"; + panel.Size = new Size(148, 450); + panel.TabIndex = 3; + // + // buttonUpdate + // + buttonUpdate.BackgroundImage = Properties.Resources.edit; + buttonUpdate.BackgroundImageLayout = ImageLayout.Stretch; + buttonUpdate.Location = new Point(36, 249); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(78, 80); + buttonUpdate.TabIndex = 2; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += ButtonUpd_Click; + // + // buttonRemove + // + buttonRemove.BackgroundImage = Properties.Resources.minus; + buttonRemove.BackgroundImageLayout = ImageLayout.Stretch; + buttonRemove.Location = new Point(36, 141); + buttonRemove.Name = "buttonRemove"; + buttonRemove.Size = new Size(75, 76); + buttonRemove.TabIndex = 1; + buttonRemove.UseVisualStyleBackColor = true; + buttonRemove.Click += ButtonDel_Click; + // + // buttonAdd + // + buttonAdd.BackgroundImage = Properties.Resources.plus; + buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; + buttonAdd.Location = new Point(33, 43); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(81, 71); + buttonAdd.TabIndex = 0; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.AllowUserToResizeColumns = false; + dataGridView.AllowUserToResizeRows = false; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Fill; + dataGridView.Location = new Point(0, 0); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 25; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(652, 450); + dataGridView.TabIndex = 4; + // + // FormServices + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridView); + Controls.Add(panel); + Name = "FormServices"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Услуги"; + Load += FormServices_Load; + panel.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Panel panel; + private Button buttonUpdate; + private Button buttonRemove; + private Button buttonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/ITServiceManager/ITServiceManager/Forms/FormServices.cs b/ITServiceManager/ITServiceManager/Forms/FormServices.cs new file mode 100644 index 0000000..d468018 --- /dev/null +++ b/ITServiceManager/ITServiceManager/Forms/FormServices.cs @@ -0,0 +1,118 @@ +using ITServiceManager.Repositories; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using Unity; + +namespace ITServiceManager.Forms +{ + public partial class FormServices : Form + { + private readonly IUnityContainer _container; + private readonly IServiceRepository _serviceRepository; + public FormServices(IUnityContainer container, IServiceRepository + serviceRepository) + { + InitializeComponent(); + _container = container ?? + throw new ArgumentNullException(nameof(container)); + _serviceRepository = serviceRepository ?? + throw new + ArgumentNullException(nameof(serviceRepository)); + } + private void FormServices_Load(object sender, EventArgs e) + { + try + { + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при добавлении", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var findId)) + { + return; + } + try + { + var form = _container.Resolve(); + form.Id = findId; + form.ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при изменении", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonDel_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var findId)) + { + return; + } + if (MessageBox.Show("Удалить запись?", "Удаление", + MessageBoxButtons.YesNo) != DialogResult.Yes) + { + return; + } + try + { + _serviceRepository.DeleteService(findId); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при удалении", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void LoadList() => dataGridView.DataSource = + _serviceRepository.ReadServices(); + private bool TryGetIdentifierFromSelectedRow(out int id) + { + id = 0; + if (dataGridView.SelectedRows.Count < 1) + { + MessageBox.Show("Нет выбранной записи", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + return true; + } + + + + } +} + diff --git a/ITServiceManager/ITServiceManager/Forms/FormServices.resx b/ITServiceManager/ITServiceManager/Forms/FormServices.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ITServiceManager/ITServiceManager/Forms/FormServices.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file