diff --git a/ProjectAirline/Entities/Airplane.cs b/ProjectAirline/Entities/Airplane.cs new file mode 100644 index 0000000..ec5464f --- /dev/null +++ b/ProjectAirline/Entities/Airplane.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectAirline.Entities; + +public class Airplane +{ + public int Id { get; private set; } + public string Country { get; private set; } = string.Empty; + public string Model { get; private set; } = string.Empty; + public int Capacity { get; private set; } + + public static Airplane CreateEntity(int id, string country, string model, int capacity) + { + return new Airplane + { + Id = id, + Country = country ?? string.Empty, + Model = model ?? string.Empty, + Capacity = capacity + + }; + + } + +} diff --git a/ProjectAirline/Entities/Employee.cs b/ProjectAirline/Entities/Employee.cs new file mode 100644 index 0000000..3a3abcf --- /dev/null +++ b/ProjectAirline/Entities/Employee.cs @@ -0,0 +1,29 @@ +using ProjectAirline.Entities.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectAirline.Entities; + +public class Employee +{ + public int Id { get; private set; } + public string FirstName { get; private set; } = string.Empty; + public string LastName { get; private set; } = string.Empty; + public string ContactInformation { get; private set; } = string.Empty; + public EmployeePost EmployeePost { get; private set; } + public static Employee CreateEntity(int id, string first, string last, string contactInfo, + EmployeePost employeePost) + { + return new Employee + { + Id = id, + FirstName = first ?? string.Empty, + LastName = last ?? string.Empty, + ContactInformation = contactInfo ?? string.Empty, + EmployeePost = employeePost + }; + } +} diff --git a/ProjectAirline/Entities/EmployeeFlight.cs b/ProjectAirline/Entities/EmployeeFlight.cs new file mode 100644 index 0000000..14ab603 --- /dev/null +++ b/ProjectAirline/Entities/EmployeeFlight.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectAirline.Entities; + +public class EmployeeFlight +{ + public int Id { get; private set; } + public int EmployeeId { get; private set; } + public int FlightId { get; private set; } + public int HoursWorked { get; private set; } + public static EmployeeFlight CreateOperation(int id, int employeeId, int flightId, int hoursWorked) + { + return new EmployeeFlight + { + Id = id, + EmployeeId = employeeId, + FlightId = flightId, + HoursWorked = hoursWorked + }; + } +} diff --git a/ProjectAirline/Entities/Enums/EmployeePost.cs b/ProjectAirline/Entities/Enums/EmployeePost.cs new file mode 100644 index 0000000..ee03ae6 --- /dev/null +++ b/ProjectAirline/Entities/Enums/EmployeePost.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectAirline.Entities.Enums; + +public enum EmployeePost +{ + None = 0, + + FlightAttendant = 1, + + FlightEngineer = 2, + + Pilot = 3 +} diff --git a/ProjectAirline/Entities/Enums/FoodPreferences.cs b/ProjectAirline/Entities/Enums/FoodPreferences.cs new file mode 100644 index 0000000..9955b15 --- /dev/null +++ b/ProjectAirline/Entities/Enums/FoodPreferences.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectAirline.Entities.Enums; +[Flags] +public enum FoodPreferences +{ + None = 0, + + SpicyFood = 1, + + Meat = 2, + + Sweets = 4, + + BitterFood = 8 +} diff --git a/ProjectAirline/Entities/Flight.cs b/ProjectAirline/Entities/Flight.cs new file mode 100644 index 0000000..d909b99 --- /dev/null +++ b/ProjectAirline/Entities/Flight.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectAirline.Entities; + +public class Flight +{ + public int Id { get; private set; } + public int AirplaneID { get; private set; } + public DateTime DepartureTime { get; private set; } + public DateTime ArrivalTime { get; private set; } + public string Destination { get; private set; } = string.Empty; + public string DeparturePoint { get; private set; } = string.Empty; + public int TicketPrice { get; private set; } + public IEnumerable EmployeeFlights { get; private set; } = []; + public static Flight CreateOperation(int id, int airPlaneID, string destination, string departurePoint, int ticketPrice, + IEnumerable employeeFlights) + { + return new Flight + { + Id = id, + AirplaneID = airPlaneID, + DepartureTime = DateTime.Now, + ArrivalTime = DateTime.Now, + Destination = destination ?? string.Empty, + DeparturePoint = departurePoint ?? string.Empty, + TicketPrice = ticketPrice, + EmployeeFlights = employeeFlights + }; + } + + + +} diff --git a/ProjectAirline/Entities/Passenger.cs b/ProjectAirline/Entities/Passenger.cs new file mode 100644 index 0000000..12bbf34 --- /dev/null +++ b/ProjectAirline/Entities/Passenger.cs @@ -0,0 +1,28 @@ +using ProjectAirline.Entities.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectAirline.Entities; + +public class Passenger +{ + public int Id { get; private set; } + public FoodPreferences FoodPreferences { get; private set; } + public string FirstName { get; private set; } = string.Empty; + public string LastName { get; private set; } = string.Empty; + public DateTime DateBirth { get; private set; } + public static Passenger CreateEntity (int id, FoodPreferences foodPreferences, string first, string last) + { + return new Passenger + { + Id = id, + FoodPreferences = foodPreferences, + FirstName = first ?? string.Empty, + LastName = last ?? string.Empty, + DateBirth = DateTime.Now + }; + } +} diff --git a/ProjectAirline/Entities/Ticket.cs b/ProjectAirline/Entities/Ticket.cs new file mode 100644 index 0000000..a95a856 --- /dev/null +++ b/ProjectAirline/Entities/Ticket.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectAirline.Entities; + +public class Ticket +{ + public int Id { get; private set; } + public int FlightID { get; private set; } + public int PassengerID { get; private set; } + + public int TicketPrice { get; private set; } + public DateTime DateBuy { get; private set; } + public static Ticket CreateTicket (int id, int flightID, int passengerID, int ticketPrice) + { + return new Ticket + { + Id = id, + FlightID = flightID, + PassengerID = passengerID, + TicketPrice = ticketPrice, + DateBuy = DateTime.Now + }; + } + + +} diff --git a/ProjectAirline/Form1.Designer.cs b/ProjectAirline/Form1.Designer.cs deleted file mode 100644 index eca5924..0000000 --- a/ProjectAirline/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace ProjectAirline -{ - partial class Form1 - { - /// - /// 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() - { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; - } - - #endregion - } -} diff --git a/ProjectAirline/Form1.cs b/ProjectAirline/Form1.cs deleted file mode 100644 index c73297f..0000000 --- a/ProjectAirline/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace ProjectAirline -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} diff --git a/ProjectAirline/FormAirline.Designer.cs b/ProjectAirline/FormAirline.Designer.cs new file mode 100644 index 0000000..34c6b2b --- /dev/null +++ b/ProjectAirline/FormAirline.Designer.cs @@ -0,0 +1,138 @@ +namespace ProjectAirline +{ + partial class FormAirline + { + /// + /// 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() + { + menuStrip = new MenuStrip(); + справочникиToolStripMenuItem = new ToolStripMenuItem(); + AirplaneToolStripMenuItem = new ToolStripMenuItem(); + EmployeeToolStripMenuItem = new ToolStripMenuItem(); + PassengerToolStripMenuItem = new ToolStripMenuItem(); + операцииToolStripMenuItem = new ToolStripMenuItem(); + FlightToolStripMenuItem = new ToolStripMenuItem(); + TicketToolStripMenuItem = new ToolStripMenuItem(); + отчетыToolStripMenuItem = new ToolStripMenuItem(); + menuStrip.SuspendLayout(); + SuspendLayout(); + // + // menuStrip + // + menuStrip.ImageScalingSize = new Size(20, 20); + menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, операцииToolStripMenuItem, отчетыToolStripMenuItem }); + menuStrip.Location = new Point(0, 0); + menuStrip.Name = "menuStrip"; + menuStrip.Size = new Size(782, 28); + menuStrip.TabIndex = 0; + menuStrip.Text = "menuStrip1"; + // + // справочникиToolStripMenuItem + // + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { AirplaneToolStripMenuItem, EmployeeToolStripMenuItem, PassengerToolStripMenuItem }); + справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + справочникиToolStripMenuItem.Size = new Size(117, 24); + справочникиToolStripMenuItem.Text = "Справочники"; + // + // AirplaneToolStripMenuItem + // + AirplaneToolStripMenuItem.Name = "AirplaneToolStripMenuItem"; + AirplaneToolStripMenuItem.Size = new Size(224, 26); + AirplaneToolStripMenuItem.Text = "Самолёты"; + AirplaneToolStripMenuItem.Click += AirplaneToolStripMenuItem_Click; + // + // EmployeeToolStripMenuItem + // + EmployeeToolStripMenuItem.Name = "EmployeeToolStripMenuItem"; + EmployeeToolStripMenuItem.Size = new Size(224, 26); + EmployeeToolStripMenuItem.Text = "Работники"; + EmployeeToolStripMenuItem.Click += EmployeeToolStripMenuItem_Click; + // + // PassengerToolStripMenuItem + // + PassengerToolStripMenuItem.Name = "PassengerToolStripMenuItem"; + PassengerToolStripMenuItem.Size = new Size(224, 26); + PassengerToolStripMenuItem.Text = "Пассажиры"; + PassengerToolStripMenuItem.Click += PassengerToolStripMenuItem_Click; + // + // операцииToolStripMenuItem + // + операцииToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { FlightToolStripMenuItem, TicketToolStripMenuItem }); + операцииToolStripMenuItem.Name = "операцииToolStripMenuItem"; + операцииToolStripMenuItem.Size = new Size(95, 24); + операцииToolStripMenuItem.Text = "Операции"; + // + // FlightToolStripMenuItem + // + FlightToolStripMenuItem.Name = "FlightToolStripMenuItem"; + FlightToolStripMenuItem.Size = new Size(224, 26); + FlightToolStripMenuItem.Text = "Рейсы"; + FlightToolStripMenuItem.Click += FlightToolStripMenuItem_Click; + // + // TicketToolStripMenuItem + // + TicketToolStripMenuItem.Name = "TicketToolStripMenuItem"; + TicketToolStripMenuItem.Size = new Size(224, 26); + TicketToolStripMenuItem.Text = "Покупка билетов"; + TicketToolStripMenuItem.Click += TicketToolStripMenuItem_Click; + // + // отчетыToolStripMenuItem + // + отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; + отчетыToolStripMenuItem.Size = new Size(73, 24); + отчетыToolStripMenuItem.Text = "Отчеты"; + // + // FormAirline + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + BackgroundImage = Properties.Resources.Самолёт_Фон; + BackgroundImageLayout = ImageLayout.Stretch; + ClientSize = new Size(782, 453); + Controls.Add(menuStrip); + MainMenuStrip = menuStrip; + Name = "FormAirline"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Авиалинии"; + menuStrip.ResumeLayout(false); + menuStrip.PerformLayout(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private MenuStrip menuStrip; + private ToolStripMenuItem справочникиToolStripMenuItem; + private ToolStripMenuItem операцииToolStripMenuItem; + private ToolStripMenuItem отчетыToolStripMenuItem; + private ToolStripMenuItem AirplaneToolStripMenuItem; + private ToolStripMenuItem EmployeeToolStripMenuItem; + private ToolStripMenuItem PassengerToolStripMenuItem; + private ToolStripMenuItem FlightToolStripMenuItem; + private ToolStripMenuItem TicketToolStripMenuItem; + } +} diff --git a/ProjectAirline/FormAirline.cs b/ProjectAirline/FormAirline.cs new file mode 100644 index 0000000..ec361f7 --- /dev/null +++ b/ProjectAirline/FormAirline.cs @@ -0,0 +1,76 @@ +using ProjectAirline.Forms; +using Unity; + +namespace ProjectAirline +{ + public partial class FormAirline : Form + { + private readonly IUnityContainer _container; + + public FormAirline(IUnityContainer container) + { + InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); + } + + private void AirplaneToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void EmployeeToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void PassengerToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void FlightToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void TicketToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/ProjectAirline/FormAirline.resx b/ProjectAirline/FormAirline.resx new file mode 100644 index 0000000..6c82d08 --- /dev/null +++ b/ProjectAirline/FormAirline.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + 17, 17 + + \ No newline at end of file diff --git a/ProjectAirline/Forms/FormAirplane.Designer.cs b/ProjectAirline/Forms/FormAirplane.Designer.cs new file mode 100644 index 0000000..22eb57a --- /dev/null +++ b/ProjectAirline/Forms/FormAirplane.Designer.cs @@ -0,0 +1,142 @@ +namespace ProjectAirline.Forms +{ + partial class FormAirplane + { + /// + /// 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() + { + label1 = new Label(); + label2 = new Label(); + label3 = new Label(); + textBoxCountry = new TextBox(); + textBoxModel = new TextBox(); + numericUpDownCapacity = new NumericUpDown(); + buttonAdd = new Button(); + buttonCancel = new Button(); + ((System.ComponentModel.ISupportInitialize)numericUpDownCapacity).BeginInit(); + SuspendLayout(); + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(31, 41); + label1.Name = "label1"; + label1.Size = new Size(61, 20); + label1.TabIndex = 0; + label1.Text = "Страна:"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(31, 106); + label2.Name = "label2"; + label2.Size = new Size(66, 20); + label2.TabIndex = 1; + label2.Text = "Модель:"; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(31, 167); + label3.Name = "label3"; + label3.Size = new Size(103, 20); + label3.TabIndex = 2; + label3.Text = "Вместимость:"; + // + // textBoxCountry + // + textBoxCountry.Location = new Point(155, 41); + textBoxCountry.Name = "textBoxCountry"; + textBoxCountry.Size = new Size(150, 27); + textBoxCountry.TabIndex = 3; + // + // textBoxModel + // + textBoxModel.Location = new Point(155, 99); + textBoxModel.Name = "textBoxModel"; + textBoxModel.Size = new Size(150, 27); + textBoxModel.TabIndex = 4; + // + // numericUpDownCapacity + // + numericUpDownCapacity.Location = new Point(155, 165); + numericUpDownCapacity.Name = "numericUpDownCapacity"; + numericUpDownCapacity.Size = new Size(150, 27); + numericUpDownCapacity.TabIndex = 5; + // + // buttonAdd + // + buttonAdd.Location = new Point(45, 244); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(101, 43); + buttonAdd.TabIndex = 6; + buttonAdd.Text = "Сохранить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(177, 244); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(100, 43); + buttonCancel.TabIndex = 7; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormAirplane + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(403, 356); + Controls.Add(buttonCancel); + Controls.Add(buttonAdd); + Controls.Add(numericUpDownCapacity); + Controls.Add(textBoxModel); + Controls.Add(textBoxCountry); + Controls.Add(label3); + Controls.Add(label2); + Controls.Add(label1); + Name = "FormAirplane"; + StartPosition = FormStartPosition.CenterParent; + Text = "Самолёт"; + ((System.ComponentModel.ISupportInitialize)numericUpDownCapacity).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label label1; + private Label label2; + private Label label3; + private TextBox textBoxCountry; + private TextBox textBoxModel; + private NumericUpDown numericUpDownCapacity; + private Button buttonAdd; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/ProjectAirline/Forms/FormAirplane.cs b/ProjectAirline/Forms/FormAirplane.cs new file mode 100644 index 0000000..e145fa1 --- /dev/null +++ b/ProjectAirline/Forms/FormAirplane.cs @@ -0,0 +1,78 @@ +using ProjectAirline.Entities; +using ProjectAirline.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 ProjectAirline.Forms +{ + public partial class FormAirplane : Form + { + private readonly IAirplaneRepository _airplaneRepository; + private int? _airplaneId; + public int Id + { + set + { + try + { + var airplane = _airplaneRepository.ReadAirplaneById(value); + if (airplane == null) + { + throw new InvalidDataException(nameof(airplane)); + } + textBoxCountry.Text = airplane.Country; + textBoxModel.Text = airplane.Model; + numericUpDownCapacity.Value = airplane.Capacity; + _airplaneId = value; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + } + } + public FormAirplane(IAirplaneRepository airplaneRepository) + { + InitializeComponent(); + _airplaneRepository = airplaneRepository ?? throw new ArgumentNullException(nameof(airplaneRepository)); + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + try + { + if (string.IsNullOrWhiteSpace(textBoxCountry.Text) || string.IsNullOrWhiteSpace(textBoxModel.Text)) + { + throw new Exception("Имеются незаполненные поля"); + } + if (_airplaneId.HasValue) + { + _airplaneRepository.UpdateAirplane(CreateAirplane(_airplaneId.Value)); + } + else + { + _airplaneRepository.CreateAirplane(CreateAirplane(0)); + } + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) => Close(); + + private Airplane CreateAirplane(int id) => Airplane.CreateEntity(id, textBoxCountry.Text, + textBoxModel.Text, Convert.ToInt32(numericUpDownCapacity.Value)); + + } +} diff --git a/ProjectAirline/Form1.resx b/ProjectAirline/Forms/FormAirplane.resx similarity index 93% rename from ProjectAirline/Form1.resx rename to ProjectAirline/Forms/FormAirplane.resx index 1af7de1..af32865 100644 --- a/ProjectAirline/Form1.resx +++ b/ProjectAirline/Forms/FormAirplane.resx @@ -1,17 +1,17 @@  - diff --git a/ProjectAirline/Forms/FormAirplanes.Designer.cs b/ProjectAirline/Forms/FormAirplanes.Designer.cs new file mode 100644 index 0000000..ea1655b --- /dev/null +++ b/ProjectAirline/Forms/FormAirplanes.Designer.cs @@ -0,0 +1,130 @@ +namespace ProjectAirline.Forms +{ + partial class FormAirplanes + { + /// + /// 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() + { + panel1 = new Panel(); + buttonUpd = new Button(); + buttonDel = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // panel1 + // + panel1.Controls.Add(buttonUpd); + panel1.Controls.Add(buttonDel); + panel1.Controls.Add(buttonAdd); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(612, 0); + panel1.Name = "panel1"; + panel1.Size = new Size(187, 468); + panel1.TabIndex = 0; + // + // buttonUpd + // + buttonUpd.BackColor = SystemColors.ButtonHighlight; + buttonUpd.BackgroundImage = Properties.Resources.edit; + buttonUpd.BackgroundImageLayout = ImageLayout.Stretch; + buttonUpd.Location = new Point(57, 203); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(88, 79); + buttonUpd.TabIndex = 2; + buttonUpd.UseVisualStyleBackColor = false; + buttonUpd.Click += ButtonUpd_Click; + // + // buttonDel + // + buttonDel.BackColor = SystemColors.ButtonHighlight; + buttonDel.BackgroundImage = Properties.Resources.minus; + buttonDel.BackgroundImageLayout = ImageLayout.Stretch; + buttonDel.Location = new Point(57, 120); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(88, 77); + buttonDel.TabIndex = 1; + buttonDel.UseVisualStyleBackColor = false; + buttonDel.Click += ButtonDel_Click; + // + // buttonAdd + // + buttonAdd.BackColor = SystemColors.ButtonHighlight; + buttonAdd.BackgroundImage = Properties.Resources.plus; + buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; + buttonAdd.Location = new Point(57, 40); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(88, 74); + buttonAdd.TabIndex = 0; + buttonAdd.UseVisualStyleBackColor = false; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.AllowUserToResizeColumns = false; + dataGridView.AllowUserToResizeRows = false; + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + 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.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(612, 468); + dataGridView.TabIndex = 1; + // + // FormAirplanes + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(799, 468); + Controls.Add(dataGridView); + Controls.Add(panel1); + Name = "FormAirplanes"; + StartPosition = FormStartPosition.CenterParent; + Text = "Самолёты"; + Load += FormAirplanes_Load; + panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Panel panel1; + private Button buttonUpd; + private Button buttonDel; + private Button buttonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/ProjectAirline/Forms/FormAirplanes.cs b/ProjectAirline/Forms/FormAirplanes.cs new file mode 100644 index 0000000..44cd0a1 --- /dev/null +++ b/ProjectAirline/Forms/FormAirplanes.cs @@ -0,0 +1,106 @@ +using ProjectAirline.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 System.Xml.Linq; +using Unity; + +namespace ProjectAirline.Forms +{ + public partial class FormAirplanes : Form + { + private readonly IUnityContainer _container; + private readonly IAirplaneRepository _airplaneRepository; + + public FormAirplanes(IUnityContainer container, IAirplaneRepository airplaneRepository) + { + InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); + _airplaneRepository = airplaneRepository ?? throw new ArgumentNullException(nameof(airplaneRepository)); + } + private void FormAirplanes_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 ButtonDel_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var findId)) + { + return; + } + if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes) + { + return; + } + try + { + _airplaneRepository.DeleteAirplane(findId); + 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 = _airplaneRepository.ReadAirplanes(); + 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/ProjectAirline/Forms/FormAirplanes.resx b/ProjectAirline/Forms/FormAirplanes.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectAirline/Forms/FormAirplanes.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/ProjectAirline/Forms/FormEmployee.Designer.cs b/ProjectAirline/Forms/FormEmployee.Designer.cs new file mode 100644 index 0000000..8f77f92 --- /dev/null +++ b/ProjectAirline/Forms/FormEmployee.Designer.cs @@ -0,0 +1,163 @@ +namespace ProjectAirline.Forms +{ + partial class FormEmployee + { + /// + /// 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() + { + comboBoxPost = new ComboBox(); + label1 = new Label(); + label2 = new Label(); + label3 = new Label(); + label4 = new Label(); + textBoxContactInfo = new TextBox(); + textBoxLastName = new TextBox(); + textBoxFirstName = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // comboBoxPost + // + comboBoxPost.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxPost.FormattingEnabled = true; + comboBoxPost.Location = new Point(249, 262); + comboBoxPost.Name = "comboBoxPost"; + comboBoxPost.Size = new Size(202, 28); + comboBoxPost.TabIndex = 0; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(31, 39); + label1.Name = "label1"; + label1.Size = new Size(39, 20); + label1.TabIndex = 1; + label1.Text = "Имя"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(31, 96); + label2.Name = "label2"; + label2.Size = new Size(73, 20); + label2.TabIndex = 2; + label2.Text = "Фамилия"; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(31, 170); + label3.Name = "label3"; + label3.Size = new Size(183, 20); + label3.TabIndex = 3; + label3.Text = "Контактная информация"; + // + // label4 + // + label4.AutoSize = true; + label4.Location = new Point(31, 265); + label4.Name = "label4"; + label4.Size = new Size(86, 20); + label4.TabIndex = 4; + label4.Text = "Должность"; + // + // textBoxContactInfo + // + textBoxContactInfo.Location = new Point(249, 170); + textBoxContactInfo.Name = "textBoxContactInfo"; + textBoxContactInfo.Size = new Size(202, 27); + textBoxContactInfo.TabIndex = 5; + // + // textBoxLastName + // + textBoxLastName.Location = new Point(249, 94); + textBoxLastName.Name = "textBoxLastName"; + textBoxLastName.Size = new Size(202, 27); + textBoxLastName.TabIndex = 6; + // + // textBoxFirstName + // + textBoxFirstName.Location = new Point(249, 38); + textBoxFirstName.Name = "textBoxFirstName"; + textBoxFirstName.Size = new Size(202, 27); + textBoxFirstName.TabIndex = 7; + // + // buttonSave + // + buttonSave.Location = new Point(31, 335); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(115, 62); + buttonSave.TabIndex = 8; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(230, 335); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(116, 62); + buttonCancel.TabIndex = 9; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormEmployee + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxFirstName); + Controls.Add(textBoxLastName); + Controls.Add(textBoxContactInfo); + Controls.Add(label4); + Controls.Add(label3); + Controls.Add(label2); + Controls.Add(label1); + Controls.Add(comboBoxPost); + Name = "FormEmployee"; + Text = "Сотрудник"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private ComboBox comboBoxPost; + private Label label1; + private Label label2; + private Label label3; + private Label label4; + private TextBox textBoxContactInfo; + private TextBox textBoxLastName; + private TextBox textBoxFirstName; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/ProjectAirline/Forms/FormEmployee.cs b/ProjectAirline/Forms/FormEmployee.cs new file mode 100644 index 0000000..a445320 --- /dev/null +++ b/ProjectAirline/Forms/FormEmployee.cs @@ -0,0 +1,89 @@ +using ProjectAirline.Entities; +using ProjectAirline.Entities.Enums; +using ProjectAirline.Repositories; +using ProjectAirline.Repositories.Implementations; +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 ProjectAirline.Forms +{ + public partial class FormEmployee : Form + { + 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; + textBoxContactInfo.Text = employee.ContactInformation; + comboBoxPost.SelectedItem = employee.EmployeePost; + _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 ButtonSave_Click(object sender, EventArgs e) + { + try + { + if (string.IsNullOrWhiteSpace(textBoxFirstName.Text) || + string.IsNullOrWhiteSpace(textBoxLastName.Text) || + string.IsNullOrWhiteSpace(textBoxContactInfo.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, textBoxContactInfo.Text,(EmployeePost)comboBoxPost.SelectedItem!); + + } +} diff --git a/ProjectAirline/Forms/FormEmployee.resx b/ProjectAirline/Forms/FormEmployee.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectAirline/Forms/FormEmployee.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/ProjectAirline/Forms/FormEmployees.Designer.cs b/ProjectAirline/Forms/FormEmployees.Designer.cs new file mode 100644 index 0000000..45eed63 --- /dev/null +++ b/ProjectAirline/Forms/FormEmployees.Designer.cs @@ -0,0 +1,127 @@ +namespace ProjectAirline.Forms +{ + partial class FormEmployees + { + /// + /// 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() + { + panel1 = new Panel(); + buttonUpdate = new Button(); + buttonRemove = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // panel1 + // + panel1.Controls.Add(buttonUpdate); + panel1.Controls.Add(buttonRemove); + panel1.Controls.Add(buttonAdd); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(628, 0); + panel1.Name = "panel1"; + panel1.Size = new Size(153, 455); + panel1.TabIndex = 0; + // + // buttonUpdate + // + buttonUpdate.BackgroundImage = Properties.Resources.edit; + buttonUpdate.BackgroundImageLayout = ImageLayout.Stretch; + buttonUpdate.Location = new Point(33, 271); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(94, 82); + buttonUpdate.TabIndex = 2; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += ButtonUpdate_Click; + // + // buttonRemove + // + buttonRemove.BackgroundImage = Properties.Resources.minus; + buttonRemove.BackgroundImageLayout = ImageLayout.Stretch; + buttonRemove.Location = new Point(33, 166); + buttonRemove.Name = "buttonRemove"; + buttonRemove.Size = new Size(94, 82); + 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, 50); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(94, 82); + buttonAdd.TabIndex = 0; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.AllowUserToResizeColumns = false; + dataGridView.AllowUserToResizeRows = false; + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + 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.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(628, 455); + dataGridView.TabIndex = 1; + // + // FormEmployees + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(781, 455); + Controls.Add(dataGridView); + Controls.Add(panel1); + Name = "FormEmployees"; + StartPosition = FormStartPosition.CenterParent; + Text = "Сотрудники"; + Load += FormEmployees_Load; + panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Panel panel1; + private Button buttonUpdate; + private Button buttonRemove; + private Button buttonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/ProjectAirline/Forms/FormEmployees.cs b/ProjectAirline/Forms/FormEmployees.cs new file mode 100644 index 0000000..fb02aec --- /dev/null +++ b/ProjectAirline/Forms/FormEmployees.cs @@ -0,0 +1,118 @@ +using ProjectAirline.Repositories; +using ProjectAirline.Repositories.Implementations; +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 System.Xml.Linq; +using Unity; + +namespace ProjectAirline.Forms +{ + public partial class FormEmployees : Form + { + private readonly IUnityContainer _container; + private readonly IEmployeeRepository _employeeRepository; + public FormEmployees(IUnityContainer container, IEmployeeRepository + employeeRepository) + { + InitializeComponent(); + _container = container ?? + throw new ArgumentNullException(nameof(container)); + _employeeRepository = employeeRepository ?? + throw new + ArgumentNullException(nameof(employeeRepository)); + } + private void FormEmployees_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 + { + _employeeRepository.DeleteEmployee(findId); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при удалении", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonUpdate_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 = + _employeeRepository.ReadEmployees(); + 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/ProjectAirline/Forms/FormEmployees.resx b/ProjectAirline/Forms/FormEmployees.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectAirline/Forms/FormEmployees.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/ProjectAirline/Forms/FormFlight.Designer.cs b/ProjectAirline/Forms/FormFlight.Designer.cs new file mode 100644 index 0000000..4c1ed9a --- /dev/null +++ b/ProjectAirline/Forms/FormFlight.Designer.cs @@ -0,0 +1,273 @@ +namespace ProjectAirline.Forms +{ + partial class FormFlight + { + /// + /// 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() + { + label1 = new Label(); + label2 = new Label(); + label3 = new Label(); + label4 = new Label(); + label5 = new Label(); + label6 = new Label(); + comboBoxAirplane = new ComboBox(); + dateTimePickerDeparture = new DateTimePicker(); + dateTimePickerArrival = new DateTimePicker(); + numericUpDownPrice = new NumericUpDown(); + textBoxDestination = new TextBox(); + textBoxDeparture = new TextBox(); + groupBox1 = new GroupBox(); + dataGridView = new DataGridView(); + ColumnEmployee = new DataGridViewComboBoxColumn(); + ColumnFlight = new DataGridViewTextBoxColumn(); + ColumnHoursWork = new DataGridViewTextBoxColumn(); + buttonAdd = new Button(); + buttonCancel = new Button(); + ((System.ComponentModel.ISupportInitialize)numericUpDownPrice).BeginInit(); + groupBox1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(12, 76); + label1.Name = "label1"; + label1.Size = new Size(149, 20); + label1.TabIndex = 0; + label1.Text = "Время отправления"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(12, 125); + label2.Name = "label2"; + label2.Size = new Size(128, 20); + label2.TabIndex = 1; + label2.Text = "Время прибытия"; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(12, 172); + label3.Name = "label3"; + label3.Size = new Size(136, 20); + label3.TabIndex = 2; + label3.Text = "Пункт назначения"; + // + // label4 + // + label4.AutoSize = true; + label4.Location = new Point(12, 218); + label4.Name = "label4"; + label4.Size = new Size(144, 20); + label4.TabIndex = 3; + label4.Text = "Пункт отправления"; + // + // label5 + // + label5.AutoSize = true; + label5.Location = new Point(12, 274); + label5.Name = "label5"; + label5.Size = new Size(97, 20); + label5.TabIndex = 4; + label5.Text = "Цена билета"; + // + // label6 + // + label6.AutoSize = true; + label6.Location = new Point(41, 16); + label6.Name = "label6"; + label6.Size = new Size(68, 20); + label6.TabIndex = 5; + label6.Text = "Самолёт"; + // + // comboBoxAirplane + // + comboBoxAirplane.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxAirplane.FormattingEnabled = true; + comboBoxAirplane.Location = new Point(183, 16); + comboBoxAirplane.Name = "comboBoxAirplane"; + comboBoxAirplane.Size = new Size(231, 28); + comboBoxAirplane.TabIndex = 6; + // + // dateTimePickerDeparture + // + dateTimePickerDeparture.Location = new Point(183, 76); + dateTimePickerDeparture.Name = "dateTimePickerDeparture"; + dateTimePickerDeparture.Size = new Size(250, 27); + dateTimePickerDeparture.TabIndex = 7; + // + // dateTimePickerArrival + // + dateTimePickerArrival.Location = new Point(183, 125); + dateTimePickerArrival.Name = "dateTimePickerArrival"; + dateTimePickerArrival.Size = new Size(250, 27); + dateTimePickerArrival.TabIndex = 8; + // + // numericUpDownPrice + // + numericUpDownPrice.Location = new Point(183, 274); + numericUpDownPrice.Name = "numericUpDownPrice"; + numericUpDownPrice.Size = new Size(250, 27); + numericUpDownPrice.TabIndex = 9; + // + // textBoxDestination + // + textBoxDestination.Location = new Point(183, 171); + textBoxDestination.Name = "textBoxDestination"; + textBoxDestination.Size = new Size(250, 27); + textBoxDestination.TabIndex = 10; + // + // textBoxDeparture + // + textBoxDeparture.Location = new Point(183, 215); + textBoxDeparture.Name = "textBoxDeparture"; + textBoxDeparture.Size = new Size(250, 27); + textBoxDeparture.TabIndex = 11; + // + // groupBox1 + // + groupBox1.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + groupBox1.Controls.Add(dataGridView); + groupBox1.Location = new Point(14, 353); + groupBox1.Name = "groupBox1"; + groupBox1.Size = new Size(594, 298); + groupBox1.TabIndex = 12; + groupBox1.TabStop = false; + groupBox1.Text = "Работники"; + // + // dataGridView + // + dataGridView.AllowUserToResizeColumns = false; + dataGridView.AllowUserToResizeRows = false; + dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnEmployee, ColumnFlight, ColumnHoursWork }); + dataGridView.Location = new Point(6, 26); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 51; + dataGridView.Size = new Size(582, 266); + dataGridView.TabIndex = 0; + // + // ColumnEmployee + // + ColumnEmployee.HeaderText = "Работник"; + ColumnEmployee.MinimumWidth = 6; + ColumnEmployee.Name = "ColumnEmployee"; + ColumnEmployee.Width = 125; + // + // ColumnFlight + // + ColumnFlight.HeaderText = "Рейс"; + ColumnFlight.MinimumWidth = 6; + ColumnFlight.Name = "ColumnFlight"; + ColumnFlight.Width = 125; + // + // ColumnHoursWork + // + ColumnHoursWork.HeaderText = "Часы работы"; + ColumnHoursWork.MinimumWidth = 6; + ColumnHoursWork.Name = "ColumnHoursWork"; + ColumnHoursWork.Width = 125; + // + // buttonAdd + // + buttonAdd.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonAdd.Location = new Point(15, 670); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(94, 40); + buttonAdd.TabIndex = 13; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // buttonCancel + // + buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonCancel.Location = new Point(511, 670); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 40); + buttonCancel.TabIndex = 14; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormFlight + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(620, 722); + Controls.Add(buttonCancel); + Controls.Add(buttonAdd); + Controls.Add(groupBox1); + Controls.Add(textBoxDeparture); + Controls.Add(textBoxDestination); + Controls.Add(numericUpDownPrice); + Controls.Add(dateTimePickerArrival); + Controls.Add(dateTimePickerDeparture); + Controls.Add(comboBoxAirplane); + Controls.Add(label6); + Controls.Add(label5); + Controls.Add(label4); + Controls.Add(label3); + Controls.Add(label2); + Controls.Add(label1); + Name = "FormFlight"; + Text = "FormFlight"; + ((System.ComponentModel.ISupportInitialize)numericUpDownPrice).EndInit(); + groupBox1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label label1; + private Label label2; + private Label label3; + private Label label4; + private Label label5; + private Label label6; + private ComboBox comboBoxAirplane; + private DateTimePicker dateTimePickerDeparture; + private DateTimePicker dateTimePickerArrival; + private NumericUpDown numericUpDownPrice; + private TextBox textBoxDestination; + private TextBox textBoxDeparture; + private GroupBox groupBox1; + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonCancel; + private DataGridViewComboBoxColumn ColumnEmployee; + private DataGridViewTextBoxColumn ColumnFlight; + private DataGridViewTextBoxColumn ColumnHoursWork; + } +} \ No newline at end of file diff --git a/ProjectAirline/Forms/FormFlight.cs b/ProjectAirline/Forms/FormFlight.cs new file mode 100644 index 0000000..6b4e205 --- /dev/null +++ b/ProjectAirline/Forms/FormFlight.cs @@ -0,0 +1,71 @@ +using ProjectAirline.Entities; +using ProjectAirline.Repositories; +using ProjectAirline.Repositories.Implementations; +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 ProjectAirline.Forms +{ + public partial class FormFlight : Form + { + private readonly IFlightRepository _flightRepository; + public FormFlight(IFlightRepository flightRepository, IAirplaneRepository airplaneRepository, IEmployeeRepository employeeRepository) + { + InitializeComponent(); + _flightRepository = flightRepository ?? throw new ArgumentNullException(nameof(flightRepository)); + + comboBoxAirplane.DataSource = airplaneRepository.ReadAirplanes(); + comboBoxAirplane.DisplayMember = "Model"; + comboBoxAirplane.ValueMember = "Id"; + + ColumnEmployee.DataSource = employeeRepository.ReadEmployees(); + ColumnEmployee.DisplayMember = "FirstName"; + ColumnEmployee.ValueMember = "Id"; + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + if (dataGridView.RowCount < 1 || comboBoxAirplane.SelectedIndex < 0 || numericUpDownPrice.Value <= 0) + { + throw new Exception("Имеются незаполненны поля"); + } + try + { + _flightRepository.CreateFlight(Flight.CreateOperation(0, (int)comboBoxAirplane.SelectedValue, + textBoxDestination.Text, textBoxDeparture.Text, + (int)numericUpDownPrice.Value, CreateListFlightFromDataGrid())); + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + Close(); + } + private List CreateListFlightFromDataGrid() + { + var list = new List(); + foreach (DataGridViewRow row in dataGridView.Rows) + { + if (row.Cells["ColumnEmployee"].Value == null || row.Cells["ColumnFlight"].Value == null || row.Cells["ColumnHoursWork"].Value == null) + { + continue; + } + list.Add(EmployeeFlight.CreateOperation(0, Convert.ToInt32(row.Cells["ColumnEmployee"].Value), + Convert.ToInt32(row.Cells["ColumnFlight"].Value), Convert.ToInt32(row.Cells["ColumnHoursWork"].Value) )); + } + return list; + } + } +} diff --git a/ProjectAirline/Forms/FormFlight.resx b/ProjectAirline/Forms/FormFlight.resx new file mode 100644 index 0000000..5d2c928 --- /dev/null +++ b/ProjectAirline/Forms/FormFlight.resx @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + True + + + True + + + True + + \ No newline at end of file diff --git a/ProjectAirline/Forms/FormFlights.Designer.cs b/ProjectAirline/Forms/FormFlights.Designer.cs new file mode 100644 index 0000000..fa9cb7f --- /dev/null +++ b/ProjectAirline/Forms/FormFlights.Designer.cs @@ -0,0 +1,113 @@ +namespace ProjectAirline.Forms +{ + partial class FormFlights + { + /// + /// 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() + { + panel1 = new Panel(); + buttonRemove = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // panel1 + // + panel1.Controls.Add(buttonRemove); + panel1.Controls.Add(buttonAdd); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(653, 0); + panel1.Name = "panel1"; + panel1.Size = new Size(147, 450); + panel1.TabIndex = 0; + // + // buttonRemove + // + buttonRemove.BackgroundImage = Properties.Resources.minus; + buttonRemove.BackgroundImageLayout = ImageLayout.Stretch; + buttonRemove.Location = new Point(33, 165); + buttonRemove.Name = "buttonRemove"; + buttonRemove.Size = new Size(89, 83); + 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, 41); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(89, 83); + buttonAdd.TabIndex = 0; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.AllowUserToResizeColumns = false; + dataGridView.AllowUserToResizeRows = false; + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + 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.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(653, 450); + dataGridView.TabIndex = 1; + // + // FormFlights + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridView); + Controls.Add(panel1); + Name = "FormFlights"; + StartPosition = FormStartPosition.CenterParent; + Text = "Рейсы"; + Load += FormFlights_Load; + panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Panel panel1; + private Button buttonRemove; + private Button buttonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/ProjectAirline/Forms/FormFlights.cs b/ProjectAirline/Forms/FormFlights.cs new file mode 100644 index 0000000..41d4ad0 --- /dev/null +++ b/ProjectAirline/Forms/FormFlights.cs @@ -0,0 +1,85 @@ +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; +using ProjectAirline.Repositories; +using System.Xml.Linq; + +namespace ProjectAirline.Forms +{ + public partial class FormFlights : Form + { + private readonly IUnityContainer _container; + private readonly IFlightRepository _flightRepository; + public FormFlights(IUnityContainer container, IFlightRepository flightRepository) + { + InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); + _flightRepository = flightRepository ?? throw new ArgumentNullException(nameof(flightRepository)); + } + private void FormFlights_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 + { + _flightRepository.DeleteFlight(findId); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void LoadList() => dataGridView.DataSource = _flightRepository.ReadFlights(); + 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/ProjectAirline/Forms/FormFlights.resx b/ProjectAirline/Forms/FormFlights.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectAirline/Forms/FormFlights.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/ProjectAirline/Forms/FormPassenger.Designer.cs b/ProjectAirline/Forms/FormPassenger.Designer.cs new file mode 100644 index 0000000..4f26d34 --- /dev/null +++ b/ProjectAirline/Forms/FormPassenger.Designer.cs @@ -0,0 +1,162 @@ +namespace ProjectAirline.Forms +{ + partial class FormPassenger + { + /// + /// 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() + { + checkedListBoxType = new CheckedListBox(); + label1 = new Label(); + textBoxFirstname = new TextBox(); + textBoxLastname = new TextBox(); + label2 = new Label(); + label3 = new Label(); + label4 = new Label(); + dateTimePickerBorn = new DateTimePicker(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // checkedListBoxType + // + checkedListBoxType.FormattingEnabled = true; + checkedListBoxType.Location = new Point(173, 27); + checkedListBoxType.Name = "checkedListBoxType"; + checkedListBoxType.Size = new Size(205, 114); + checkedListBoxType.TabIndex = 0; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(39, 55); + label1.Name = "label1"; + label1.Size = new Size(115, 20); + label1.TabIndex = 2; + label1.Text = "Тип пассажира"; + // + // textBoxFirstname + // + textBoxFirstname.Location = new Point(173, 176); + textBoxFirstname.Name = "textBoxFirstname"; + textBoxFirstname.Size = new Size(205, 27); + textBoxFirstname.TabIndex = 3; + // + // textBoxLastname + // + textBoxLastname.Location = new Point(174, 234); + textBoxLastname.Name = "textBoxLastname"; + textBoxLastname.Size = new Size(210, 27); + textBoxLastname.TabIndex = 4; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(63, 180); + label2.Name = "label2"; + label2.Size = new Size(39, 20); + label2.TabIndex = 5; + label2.Text = "Имя"; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(52, 237); + label3.Name = "label3"; + label3.Size = new Size(73, 20); + label3.TabIndex = 6; + label3.Text = "Фамилия"; + // + // label4 + // + label4.AutoSize = true; + label4.Location = new Point(38, 303); + label4.Name = "label4"; + label4.Size = new Size(116, 20); + label4.TabIndex = 7; + label4.Text = "Дата рождения"; + // + // dateTimePickerBorn + // + dateTimePickerBorn.Location = new Point(173, 303); + dateTimePickerBorn.Name = "dateTimePickerBorn"; + dateTimePickerBorn.Size = new Size(224, 27); + dateTimePickerBorn.TabIndex = 8; + // + // buttonSave + // + buttonSave.Location = new Point(47, 364); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(115, 60); + buttonSave.TabIndex = 9; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(267, 365); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(111, 59); + buttonCancel.TabIndex = 10; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormPassenger + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(417, 464); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(dateTimePickerBorn); + Controls.Add(label4); + Controls.Add(label3); + Controls.Add(label2); + Controls.Add(textBoxLastname); + Controls.Add(textBoxFirstname); + Controls.Add(label1); + Controls.Add(checkedListBoxType); + Name = "FormPassenger"; + Text = "Пассажир"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private CheckedListBox checkedListBoxType; + private Label label1; + private TextBox textBoxFirstname; + private TextBox textBoxLastname; + private Label label2; + private Label label3; + private Label label4; + private DateTimePicker dateTimePickerBorn; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/ProjectAirline/Forms/FormPassenger.cs b/ProjectAirline/Forms/FormPassenger.cs new file mode 100644 index 0000000..d798951 --- /dev/null +++ b/ProjectAirline/Forms/FormPassenger.cs @@ -0,0 +1,109 @@ +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 ProjectAirline.Entities.Enums; +using ProjectAirline.Entities; +using ProjectAirline.Repositories; + + +namespace ProjectAirline.Forms; + +public partial class FormPassenger : Form +{ + private readonly IPassengerRepository _passengerRepository; + private int? _passengerId; + public int Id + { + set + { + try + { + var passenger = + _passengerRepository.ReadPassengerById(value); + if (passenger == null) + { + throw new + InvalidDataException(nameof(passenger)); + } + foreach (FoodPreferences elem in Enum.GetValues(typeof(FoodPreferences))) + { + if ((elem & passenger.FoodPreferences) != 0) + { + checkedListBoxType.SetItemChecked(checkedListBoxType.Items.IndexOf( + elem), true); + } + } + + + textBoxFirstname.Text = passenger.FirstName; + textBoxLastname.Text = passenger.LastName; + dateTimePickerBorn.Value = passenger.DateBirth; + _passengerId = value; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + } + } + public FormPassenger(IPassengerRepository passengerRepository) + { + InitializeComponent(); + _passengerRepository = passengerRepository ?? + throw new ArgumentNullException(nameof(passengerRepository)); + + foreach (var elem in Enum.GetValues(typeof(FoodPreferences))) + { + checkedListBoxType.Items.Add(elem); + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + try + { + if (checkedListBoxType.CheckedItems.Count == 0 || + string.IsNullOrWhiteSpace(textBoxFirstname.Text) || + string.IsNullOrWhiteSpace(textBoxLastname.Text) ) + { + throw new Exception("Имеются незаполненные поля"); + } + if (_passengerId.HasValue) + { + _passengerRepository.UpdatePassenger(CreatePassenger(_passengerId.Value)); + } + else + { + _passengerRepository.CreatePassenger(CreatePassenger(0)); + } + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + Close(); + } + private Passenger CreatePassenger(int id) + { + FoodPreferences foodPreferences = FoodPreferences.None; + foreach (var elem in checkedListBoxType.CheckedItems) + { + foodPreferences |= (FoodPreferences)elem; + } + + return Passenger.CreateEntity(id, foodPreferences, textBoxFirstname.Text, textBoxLastname.Text); + } +} diff --git a/ProjectAirline/Forms/FormPassenger.resx b/ProjectAirline/Forms/FormPassenger.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectAirline/Forms/FormPassenger.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/ProjectAirline/Forms/FormPassengers.Designer.cs b/ProjectAirline/Forms/FormPassengers.Designer.cs new file mode 100644 index 0000000..c632ee8 --- /dev/null +++ b/ProjectAirline/Forms/FormPassengers.Designer.cs @@ -0,0 +1,127 @@ +namespace ProjectAirline.Forms +{ + partial class FormPassengers + { + /// + /// 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() + { + panel1 = new Panel(); + buttonUpdate = new Button(); + buttonRemove = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // panel1 + // + panel1.Controls.Add(buttonUpdate); + panel1.Controls.Add(buttonRemove); + panel1.Controls.Add(buttonAdd); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(642, 0); + panel1.Name = "panel1"; + panel1.Size = new Size(158, 450); + panel1.TabIndex = 0; + // + // buttonUpdate + // + buttonUpdate.BackgroundImage = Properties.Resources.edit; + buttonUpdate.BackgroundImageLayout = ImageLayout.Stretch; + buttonUpdate.Location = new Point(36, 246); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(93, 84); + buttonUpdate.TabIndex = 2; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += ButtonUpdate_Click; + // + // buttonRemove + // + buttonRemove.BackgroundImage = Properties.Resources.minus; + buttonRemove.BackgroundImageLayout = ImageLayout.Stretch; + buttonRemove.Location = new Point(36, 144); + buttonRemove.Name = "buttonRemove"; + buttonRemove.Size = new Size(93, 84); + buttonRemove.TabIndex = 1; + buttonRemove.UseVisualStyleBackColor = true; + buttonRemove.Click += ButtonRemove_Click; + // + // buttonAdd + // + buttonAdd.BackgroundImage = Properties.Resources.plus; + buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; + buttonAdd.Location = new Point(36, 37); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(93, 84); + buttonAdd.TabIndex = 0; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.AllowUserToResizeColumns = false; + dataGridView.AllowUserToResizeRows = false; + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + 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.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(642, 450); + dataGridView.TabIndex = 1; + // + // FormPassengers + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridView); + Controls.Add(panel1); + Name = "FormPassengers"; + StartPosition = FormStartPosition.CenterParent; + Text = "Пассажиры"; + Load += FormPassengers_Load; + panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Panel panel1; + private Button buttonUpdate; + private Button buttonRemove; + private Button buttonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/ProjectAirline/Forms/FormPassengers.cs b/ProjectAirline/Forms/FormPassengers.cs new file mode 100644 index 0000000..f305909 --- /dev/null +++ b/ProjectAirline/Forms/FormPassengers.cs @@ -0,0 +1,115 @@ +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 ProjectAirline.Repositories; +using Unity; + +namespace ProjectAirline.Forms +{ + public partial class FormPassengers : Form + { + private readonly IUnityContainer _container; + private readonly IPassengerRepository _passengerRepository; + public FormPassengers(IUnityContainer container, IPassengerRepository + passengerRepository) + { + InitializeComponent(); + _container = container ?? + throw new ArgumentNullException(nameof(container)); + _passengerRepository = passengerRepository ?? + throw new ArgumentNullException(nameof(passengerRepository)); + } + + private void FormPassengers_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 + { + _passengerRepository.DeletePassenger(findId); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при удалении", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonUpdate_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 = + _passengerRepository.ReadPassengers(); + 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/ProjectAirline/Forms/FormPassengers.resx b/ProjectAirline/Forms/FormPassengers.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectAirline/Forms/FormPassengers.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/ProjectAirline/Forms/FormTicket.Designer.cs b/ProjectAirline/Forms/FormTicket.Designer.cs new file mode 100644 index 0000000..f2bc54d --- /dev/null +++ b/ProjectAirline/Forms/FormTicket.Designer.cs @@ -0,0 +1,149 @@ +namespace ProjectAirline.Forms +{ + partial class FormTicket + { + /// + /// 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() + { + label1 = new Label(); + label2 = new Label(); + label3 = new Label(); + comboBoxFlight = new ComboBox(); + comboBoxPassenger = new ComboBox(); + numericUpDownPrice = new NumericUpDown(); + buttonAdd = new Button(); + buttonCancel = new Button(); + ((System.ComponentModel.ISupportInitialize)numericUpDownPrice).BeginInit(); + SuspendLayout(); + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(49, 37); + label1.Name = "label1"; + label1.Size = new Size(41, 20); + label1.TabIndex = 0; + label1.Text = "Рейс"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(34, 122); + label2.Name = "label2"; + label2.Size = new Size(79, 20); + label2.TabIndex = 1; + label2.Text = "Пассажир"; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(12, 201); + label3.Name = "label3"; + label3.Size = new Size(135, 20); + label3.TabIndex = 2; + label3.Text = "Стоимость билета"; + // + // comboBoxFlight + // + comboBoxFlight.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxFlight.FormattingEnabled = true; + comboBoxFlight.Location = new Point(166, 37); + comboBoxFlight.Name = "comboBoxFlight"; + comboBoxFlight.Size = new Size(223, 28); + comboBoxFlight.TabIndex = 3; + // + // comboBoxPassenger + // + comboBoxPassenger.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxPassenger.FormattingEnabled = true; + comboBoxPassenger.Location = new Point(167, 122); + comboBoxPassenger.Name = "comboBoxPassenger"; + comboBoxPassenger.Size = new Size(222, 28); + comboBoxPassenger.TabIndex = 4; + // + // numericUpDownPrice + // + numericUpDownPrice.DecimalPlaces = 2; + numericUpDownPrice.Location = new Point(166, 205); + numericUpDownPrice.Maximum = new decimal(new int[] { 10000000, 0, 0, 0 }); + numericUpDownPrice.Minimum = new decimal(new int[] { 1, 0, 0, 0 }); + numericUpDownPrice.Name = "numericUpDownPrice"; + numericUpDownPrice.Size = new Size(223, 27); + numericUpDownPrice.TabIndex = 5; + numericUpDownPrice.Value = new decimal(new int[] { 1, 0, 0, 0 }); + // + // buttonAdd + // + buttonAdd.Location = new Point(60, 332); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(109, 63); + buttonAdd.TabIndex = 6; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(261, 335); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(107, 60); + buttonCancel.TabIndex = 7; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormTicket + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(440, 450); + Controls.Add(buttonCancel); + Controls.Add(buttonAdd); + Controls.Add(numericUpDownPrice); + Controls.Add(comboBoxPassenger); + Controls.Add(comboBoxFlight); + Controls.Add(label3); + Controls.Add(label2); + Controls.Add(label1); + Name = "FormTicket"; + Text = "Билет"; + ((System.ComponentModel.ISupportInitialize)numericUpDownPrice).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label label1; + private Label label2; + private Label label3; + private ComboBox comboBoxFlight; + private ComboBox comboBoxPassenger; + private NumericUpDown numericUpDownPrice; + private Button buttonAdd; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/ProjectAirline/Forms/FormTicket.cs b/ProjectAirline/Forms/FormTicket.cs new file mode 100644 index 0000000..c6216c8 --- /dev/null +++ b/ProjectAirline/Forms/FormTicket.cs @@ -0,0 +1,91 @@ +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 ProjectAirline.Repositories; +using ProjectAirline.Entities; + +namespace ProjectAirline.Forms +{ + public partial class FormTicket : Form + { + private readonly ITicketRepository _ticketRepository; + private int? _ticketId; + public int Id + { + set + { + try + { + var appointment = + _ticketRepository.ReadTicketById(value); + if (appointment == null) + { + throw new + InvalidDataException(nameof(appointment)); + } + comboBoxFlight.SelectedIndex = appointment.FlightID; + comboBoxPassenger.SelectedIndex = appointment.PassengerID; + _ticketId = value; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + } + } + public FormTicket(ITicketRepository ticketRepository, IPassengerRepository passengerRepository, IFlightRepository flightRepository) + { + InitializeComponent(); + _ticketRepository = ticketRepository ?? + throw new ArgumentNullException(nameof(ticketRepository)); + + comboBoxFlight.DataSource = flightRepository.ReadFlights(); + comboBoxFlight.DisplayMember = "AirplaneID"; + comboBoxFlight.ValueMember = "Id"; + + comboBoxPassenger.DataSource = passengerRepository.ReadPassengers(); + comboBoxPassenger.DisplayMember = "FirstName"; + comboBoxPassenger.ValueMember = "Id"; + + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + try + { + if (comboBoxPassenger.SelectedIndex < 0 || comboBoxFlight.SelectedIndex < 0 || numericUpDownPrice.Value <= 0) + { + throw new Exception("Имеются незаполненны поля"); + } + if (_ticketId.HasValue) + { + _ticketRepository.UpdateTicket(CreateTicket(_ticketId.Value)); + } + else + { + _ticketRepository.CreateTicket(CreateTicket(0)); + } + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + Close(); + } + private Ticket CreateTicket(int id) => Ticket.CreateTicket(id, comboBoxFlight.SelectedIndex, + comboBoxPassenger.SelectedIndex, (int)numericUpDownPrice.Value); + } +} diff --git a/ProjectAirline/Forms/FormTicket.resx b/ProjectAirline/Forms/FormTicket.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectAirline/Forms/FormTicket.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/ProjectAirline/Forms/FormTickets.Designer.cs b/ProjectAirline/Forms/FormTickets.Designer.cs new file mode 100644 index 0000000..3e020e9 --- /dev/null +++ b/ProjectAirline/Forms/FormTickets.Designer.cs @@ -0,0 +1,113 @@ +namespace ProjectAirline.Forms +{ + partial class FormTickets + { + /// + /// 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() + { + panel1 = new Panel(); + buttonUpdate = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // panel1 + // + panel1.Controls.Add(buttonUpdate); + panel1.Controls.Add(buttonAdd); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(658, 0); + panel1.Name = "panel1"; + panel1.Size = new Size(142, 450); + panel1.TabIndex = 0; + // + // buttonUpdate + // + buttonUpdate.BackgroundImage = Properties.Resources.edit; + buttonUpdate.BackgroundImageLayout = ImageLayout.Stretch; + buttonUpdate.Location = new Point(24, 148); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(91, 76); + buttonUpdate.TabIndex = 1; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += ButtonUpdate_Click; + // + // buttonAdd + // + buttonAdd.BackgroundImage = Properties.Resources.plus; + buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; + buttonAdd.Location = new Point(24, 46); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(91, 76); + buttonAdd.TabIndex = 0; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.AllowUserToResizeColumns = false; + dataGridView.AllowUserToResizeRows = false; + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + 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.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(658, 450); + dataGridView.TabIndex = 1; + // + // FormTickets + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridView); + Controls.Add(panel1); + Name = "FormTickets"; + StartPosition = FormStartPosition.CenterParent; + Text = "Билеты"; + Load += FormTickets_Load; + panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Panel panel1; + private Button buttonUpdate; + private Button buttonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/ProjectAirline/Forms/FormTickets.cs b/ProjectAirline/Forms/FormTickets.cs new file mode 100644 index 0000000..f3ab09a --- /dev/null +++ b/ProjectAirline/Forms/FormTickets.cs @@ -0,0 +1,83 @@ +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 System.Xml.Linq; +using ProjectAirline.Repositories; +using Unity; + +namespace ProjectAirline.Forms +{ + public partial class FormTickets : Form + { + private readonly IUnityContainer _container; + private readonly ITicketRepository _ticketRepository; + public FormTickets(IUnityContainer container, ITicketRepository ticketRepository) + { + InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); + _ticketRepository = ticketRepository ?? throw new ArgumentNullException(nameof(ticketRepository)); + } + private void FormTickets_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 ButtonUpdate_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 = _ticketRepository.ReadTickets(); + 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/ProjectAirline/Forms/FormTickets.resx b/ProjectAirline/Forms/FormTickets.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectAirline/Forms/FormTickets.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/ProjectAirline/Program.cs b/ProjectAirline/Program.cs index 4cd196a..0aff576 100644 --- a/ProjectAirline/Program.cs +++ b/ProjectAirline/Program.cs @@ -1,3 +1,6 @@ +using ProjectAirline.Repositories.Implementations; +using ProjectAirline.Repositories; +using Unity; namespace ProjectAirline { internal static class Program @@ -11,7 +14,20 @@ namespace ProjectAirline // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + Application.Run(CreateContainer().Resolve()); + } + + private static IUnityContainer CreateContainer() + { + var container = new UnityContainer(); + container.RegisterType(); + container.RegisterType(); + container.RegisterType(); + container.RegisterType(); + container.RegisterType(); + container.RegisterType(); + + return container; } } } \ No newline at end of file diff --git a/ProjectAirline/ProjectAirline.csproj b/ProjectAirline/ProjectAirline.csproj index 663fdb8..accbdf0 100644 --- a/ProjectAirline/ProjectAirline.csproj +++ b/ProjectAirline/ProjectAirline.csproj @@ -8,4 +8,23 @@ enable + + + + + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + \ No newline at end of file diff --git a/ProjectAirline/Properties/Resources.Designer.cs b/ProjectAirline/Properties/Resources.Designer.cs new file mode 100644 index 0000000..0535a93 --- /dev/null +++ b/ProjectAirline/Properties/Resources.Designer.cs @@ -0,0 +1,113 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан программой. +// Исполняемая версия:4.0.30319.42000 +// +// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае +// повторной генерации кода. +// +//------------------------------------------------------------------------------ + +namespace ProjectAirline.Properties { + using System; + + + /// + /// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д. + /// + // Этот класс создан автоматически классом StronglyTypedResourceBuilder + // с помощью такого средства, как ResGen или Visual Studio. + // Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen + // с параметром /str или перестройте свой проект VS. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ProjectAirline.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Перезаписывает свойство CurrentUICulture текущего потока для всех + /// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap edit { + get { + object obj = ResourceManager.GetObject("edit", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap minus { + get { + object obj = ResourceManager.GetObject("minus", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap plus { + get { + object obj = ResourceManager.GetObject("plus", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap plus1 { + get { + object obj = ResourceManager.GetObject("plus1", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap Самолёт_Фон { + get { + object obj = ResourceManager.GetObject("Самолёт_Фон", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + } +} diff --git a/ProjectAirline/Properties/Resources.resx b/ProjectAirline/Properties/Resources.resx new file mode 100644 index 0000000..a02f9b5 --- /dev/null +++ b/ProjectAirline/Properties/Resources.resx @@ -0,0 +1,136 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + + ..\Resources\minus.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\plus.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\plus.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\Самолёт_Фон.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\edit.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + \ No newline at end of file diff --git a/ProjectAirline/Repositories/IAirplaneRepository.cs b/ProjectAirline/Repositories/IAirplaneRepository.cs new file mode 100644 index 0000000..48312ff --- /dev/null +++ b/ProjectAirline/Repositories/IAirplaneRepository.cs @@ -0,0 +1,18 @@ +using ProjectAirline.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectAirline.Repositories; + +public interface IAirplaneRepository +{ + IEnumerable ReadAirplanes(); + Airplane ReadAirplaneById(int id); + void CreateAirplane(Airplane airplane); + void UpdateAirplane(Airplane airplane); + void DeleteAirplane(int id); + +} diff --git a/ProjectAirline/Repositories/IEmployeeFlightRepository.cs b/ProjectAirline/Repositories/IEmployeeFlightRepository.cs new file mode 100644 index 0000000..a158dce --- /dev/null +++ b/ProjectAirline/Repositories/IEmployeeFlightRepository.cs @@ -0,0 +1,15 @@ +using ProjectAirline.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectAirline.Repositories; + +public interface IEmployeeFlightRepository +{ + IEnumerable ReadEmployeeFlights(); + EmployeeFlight ReadEmployeeFlightById(int id); + void CreateEmployeeFlight(EmployeeFlight employeeFlight); +} diff --git a/ProjectAirline/Repositories/IEmployeeRepository.cs b/ProjectAirline/Repositories/IEmployeeRepository.cs new file mode 100644 index 0000000..c0b470b --- /dev/null +++ b/ProjectAirline/Repositories/IEmployeeRepository.cs @@ -0,0 +1,17 @@ +using ProjectAirline.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectAirline.Repositories; + +public interface IEmployeeRepository +{ + IEnumerable ReadEmployees(); + Employee ReadEmployeeById(int id); + void CreateEmployee(Employee employee); + void UpdateEmployee(Employee employee); + void DeleteEmployee(int id); +} diff --git a/ProjectAirline/Repositories/IFlightRepository.cs b/ProjectAirline/Repositories/IFlightRepository.cs new file mode 100644 index 0000000..3ed1bf3 --- /dev/null +++ b/ProjectAirline/Repositories/IFlightRepository.cs @@ -0,0 +1,16 @@ +using ProjectAirline.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectAirline.Repositories; + +public interface IFlightRepository +{ + IEnumerable ReadFlights(DateTime? dateForm = null, DateTime? dateTo = null, int? flightId = null, int? airplaneId = null); + Flight ReadFlightById(int flightId); + void CreateFlight(Flight flight); + void DeleteFlight(int id); +} diff --git a/ProjectAirline/Repositories/IPassengerRepository.cs b/ProjectAirline/Repositories/IPassengerRepository.cs new file mode 100644 index 0000000..e0eb88c --- /dev/null +++ b/ProjectAirline/Repositories/IPassengerRepository.cs @@ -0,0 +1,18 @@ +using ProjectAirline.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectAirline.Repositories; + +public interface IPassengerRepository +{ + IEnumerable ReadPassengers(); + Passenger ReadPassengerById(int id); + void CreatePassenger(Passenger passenger); + void UpdatePassenger(Passenger passenger); + void DeletePassenger(int id); + +} diff --git a/ProjectAirline/Repositories/ITicketRepository.cs b/ProjectAirline/Repositories/ITicketRepository.cs new file mode 100644 index 0000000..f79aa6c --- /dev/null +++ b/ProjectAirline/Repositories/ITicketRepository.cs @@ -0,0 +1,16 @@ +using ProjectAirline.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectAirline.Repositories; + +public interface ITicketRepository +{ + IEnumerable ReadTickets(); + Ticket ReadTicketById(int id); + void CreateTicket(Ticket ticket); + void UpdateTicket(Ticket ticket); +} diff --git a/ProjectAirline/Repositories/Implementations/AirplaneRepository.cs b/ProjectAirline/Repositories/Implementations/AirplaneRepository.cs new file mode 100644 index 0000000..2000b0e --- /dev/null +++ b/ProjectAirline/Repositories/Implementations/AirplaneRepository.cs @@ -0,0 +1,34 @@ +using ProjectAirline.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectAirline.Repositories.Implementations; + +public class AirplaneRepository : IAirplaneRepository +{ + public void CreateAirplane(Airplane airplane) + { + } + + public void DeleteAirplane(int id) + { + } + + public Airplane ReadAirplaneById(int id) + { + return Airplane.CreateEntity(0, string.Empty, string.Empty, 0); + } + + public IEnumerable ReadAirplanes() + { + return []; + } + + public void UpdateAirplane(Airplane airplane) + { + throw new NotImplementedException(); + } +} diff --git a/ProjectAirline/Repositories/Implementations/EmployeeFlightRepository.cs b/ProjectAirline/Repositories/Implementations/EmployeeFlightRepository.cs new file mode 100644 index 0000000..daec813 --- /dev/null +++ b/ProjectAirline/Repositories/Implementations/EmployeeFlightRepository.cs @@ -0,0 +1,25 @@ +using ProjectAirline.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectAirline.Repositories.Implementations; + +public class EmployeeFlightRepository : IEmployeeFlightRepository +{ + public void CreateEmployeeFlight(EmployeeFlight employeeFlight) + { + } + + public EmployeeFlight ReadEmployeeFlightById(int id) + { + return null; + } + + public IEnumerable ReadEmployeeFlights() + { + return []; + } +} diff --git a/ProjectAirline/Repositories/Implementations/EmployeeRepository.cs b/ProjectAirline/Repositories/Implementations/EmployeeRepository.cs new file mode 100644 index 0000000..38908b2 --- /dev/null +++ b/ProjectAirline/Repositories/Implementations/EmployeeRepository.cs @@ -0,0 +1,34 @@ +using ProjectAirline.Entities; +using ProjectAirline.Entities.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectAirline.Repositories.Implementations; + +public class EmployeeRepository : IEmployeeRepository +{ + public void CreateEmployee(Employee employee) + { + } + + public void DeleteEmployee(int id) + { + } + + public Employee ReadEmployeeById(int id) + { + return Employee.CreateEntity(0, string.Empty, string.Empty, string.Empty, EmployeePost.None); + } + + public IEnumerable ReadEmployees() + { + return []; + } + + public void UpdateEmployee(Employee employee) + { + } +} diff --git a/ProjectAirline/Repositories/Implementations/FlightRepository.cs b/ProjectAirline/Repositories/Implementations/FlightRepository.cs new file mode 100644 index 0000000..abab5e2 --- /dev/null +++ b/ProjectAirline/Repositories/Implementations/FlightRepository.cs @@ -0,0 +1,29 @@ +using ProjectAirline.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectAirline.Repositories.Implementations; + +public class FlightRepository : IFlightRepository +{ + public void CreateFlight(Flight flight) + { + } + + public void DeleteFlight(int id) + { + } + + public Flight ReadFlightById(int flightId) + { + return null; + } + + public IEnumerable ReadFlights(DateTime? dateForm = null, DateTime? dateTo = null, int? flightId = null, int? airplaneId = null) + { + return []; + } +} diff --git a/ProjectAirline/Repositories/Implementations/PassengerRepository.cs b/ProjectAirline/Repositories/Implementations/PassengerRepository.cs new file mode 100644 index 0000000..607af7a --- /dev/null +++ b/ProjectAirline/Repositories/Implementations/PassengerRepository.cs @@ -0,0 +1,33 @@ +using ProjectAirline.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectAirline.Repositories.Implementations; + +public class PassengerRepository : IPassengerRepository +{ + public void CreatePassenger(Passenger passenger) + { + } + + public void DeletePassenger(int id) + { + } + + public Passenger ReadPassengerById(int id) + { + return null; + } + + public IEnumerable ReadPassengers() + { + return []; + } + + public void UpdatePassenger(Passenger passenger) + { + } +} diff --git a/ProjectAirline/Repositories/Implementations/TicketRepository.cs b/ProjectAirline/Repositories/Implementations/TicketRepository.cs new file mode 100644 index 0000000..4db2694 --- /dev/null +++ b/ProjectAirline/Repositories/Implementations/TicketRepository.cs @@ -0,0 +1,29 @@ +using ProjectAirline.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectAirline.Repositories.Implementations; + +public class TicketRepository : ITicketRepository +{ + public void CreateTicket(Ticket ticket) + { + } + + public Ticket ReadTicketById(int id) + { + return null; + } + + public IEnumerable ReadTickets() + { + return []; + } + + public void UpdateTicket(Ticket ticket) + { + } +} diff --git a/ProjectAirline/Resources/edit.png b/ProjectAirline/Resources/edit.png new file mode 100644 index 0000000..769aabd Binary files /dev/null and b/ProjectAirline/Resources/edit.png differ diff --git a/ProjectAirline/Resources/minus.jpg b/ProjectAirline/Resources/minus.jpg new file mode 100644 index 0000000..1a42e9c Binary files /dev/null and b/ProjectAirline/Resources/minus.jpg differ diff --git a/ProjectAirline/Resources/plus.jpg b/ProjectAirline/Resources/plus.jpg new file mode 100644 index 0000000..b766719 Binary files /dev/null and b/ProjectAirline/Resources/plus.jpg differ diff --git a/ProjectAirline/Resources/plus.png b/ProjectAirline/Resources/plus.png new file mode 100644 index 0000000..cd3ffa7 Binary files /dev/null and b/ProjectAirline/Resources/plus.png differ diff --git a/ProjectAirline/Resources/Самолёт_Фон.png b/ProjectAirline/Resources/Самолёт_Фон.png new file mode 100644 index 0000000..548a7f2 Binary files /dev/null and b/ProjectAirline/Resources/Самолёт_Фон.png differ