...
This commit is contained in:
parent
8e4eeff54e
commit
eb6aaa25a6
19
ProjectAirline/Entities/Airport.cs
Normal file
19
ProjectAirline/Entities/Airport.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
namespace YourNamespace.Entities
|
||||||
|
{
|
||||||
|
public class Airport
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
public string Name { get; private set; }
|
||||||
|
public string Location { get; private set; }
|
||||||
|
|
||||||
|
public static Airport CreateEntity(int id, string name, string location)
|
||||||
|
{
|
||||||
|
return new Airport
|
||||||
|
{
|
||||||
|
Id = id,
|
||||||
|
Name = name ?? string.Empty,
|
||||||
|
Location = location ?? string.Empty
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
23
ProjectAirline/Entities/Employee.cs
Normal file
23
ProjectAirline/Entities/Employee.cs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
using YourNamespace.Entities.Enums;
|
||||||
|
|
||||||
|
namespace YourNamespace.Entities
|
||||||
|
{
|
||||||
|
public class Employee
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
public string FirstName { get; private set; }
|
||||||
|
public string LastName { get; private set; }
|
||||||
|
public EmployeePost EmployeePost { get; private set; }
|
||||||
|
|
||||||
|
public static Employee CreateEntity(int id, string firstName, string lastName, EmployeePost employeePost)
|
||||||
|
{
|
||||||
|
return new Employee
|
||||||
|
{
|
||||||
|
Id = id,
|
||||||
|
FirstName = firstName ?? string.Empty,
|
||||||
|
LastName = lastName ?? string.Empty,
|
||||||
|
EmployeePost = employeePost
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
10
ProjectAirline/Entities/Enums/EmployeePost.cs
Normal file
10
ProjectAirline/Entities/Enums/EmployeePost.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
namespace YourNamespace.Entities.Enums
|
||||||
|
{
|
||||||
|
public enum EmployeePost
|
||||||
|
{
|
||||||
|
None = 0,
|
||||||
|
Pilot = 1,
|
||||||
|
Stewardess = 2,
|
||||||
|
GroundStaff = 3
|
||||||
|
}
|
||||||
|
}
|
25
ProjectAirline/Entities/Flight.cs
Normal file
25
ProjectAirline/Entities/Flight.cs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
namespace YourNamespace.Entities
|
||||||
|
{
|
||||||
|
public class Flight
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
public int FlightNumber { get; private set; }
|
||||||
|
public DateTime DepartureDateTime { get; private set; }
|
||||||
|
public DateTime ArrivalDateTime { get; private set; }
|
||||||
|
public int PlaneId { get; private set; }
|
||||||
|
public int AirportId { get; private set; }
|
||||||
|
|
||||||
|
public static Flight CreateEntity(int id, int flightNumber, DateTime departureDateTime, DateTime arrivalDateTime, int planeId, int airportId)
|
||||||
|
{
|
||||||
|
return new Flight
|
||||||
|
{
|
||||||
|
Id = id,
|
||||||
|
FlightNumber = flightNumber,
|
||||||
|
DepartureDateTime = departureDateTime,
|
||||||
|
ArrivalDateTime = arrivalDateTime,
|
||||||
|
PlaneId = planeId,
|
||||||
|
AirportId = airportId
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
21
ProjectAirline/Entities/Passanger.cs
Normal file
21
ProjectAirline/Entities/Passanger.cs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
namespace YourNamespace.Entities
|
||||||
|
{
|
||||||
|
public class Passenger
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
public string FirstName { get; private set; }
|
||||||
|
public string LastName { get; private set; }
|
||||||
|
public string PassportNumber { get; private set; }
|
||||||
|
|
||||||
|
public static Passenger CreateEntity(int id, string firstName, string lastName, string passportNumber)
|
||||||
|
{
|
||||||
|
return new Passenger
|
||||||
|
{
|
||||||
|
Id = id,
|
||||||
|
FirstName = firstName ?? string.Empty,
|
||||||
|
LastName = lastName ?? string.Empty,
|
||||||
|
PassportNumber = passportNumber ?? string.Empty
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
19
ProjectAirline/Entities/Plane.cs
Normal file
19
ProjectAirline/Entities/Plane.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
namespace YourNamespace.Entities
|
||||||
|
{
|
||||||
|
public class Plane
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
public string Model { get; private set; }
|
||||||
|
public int Capacity { get; private set; }
|
||||||
|
|
||||||
|
public static Plane CreateEntity(int id, string model, int capacity)
|
||||||
|
{
|
||||||
|
return new Plane
|
||||||
|
{
|
||||||
|
Id = id,
|
||||||
|
Model = model ?? string.Empty,
|
||||||
|
Capacity = capacity
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
23
ProjectAirline/Entities/Ticket.cs
Normal file
23
ProjectAirline/Entities/Ticket.cs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
namespace YourNamespace.Entities
|
||||||
|
{
|
||||||
|
public class Ticket
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
public int PassengerId { get; private set; }
|
||||||
|
public int FlightId { get; private set; }
|
||||||
|
public DateTime DateBuy { get; private set; }
|
||||||
|
public int TicketPrice { get; private set; }
|
||||||
|
|
||||||
|
public static Ticket CreateEntity(int id, int passengerId, int flightId, DateTime dateBuy, int ticketPrice)
|
||||||
|
{
|
||||||
|
return new Ticket
|
||||||
|
{
|
||||||
|
Id = id,
|
||||||
|
PassengerId = passengerId,
|
||||||
|
FlightId = flightId,
|
||||||
|
DateBuy = dateBuy,
|
||||||
|
TicketPrice = ticketPrice
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
39
ProjectAirline/Form1.Designer.cs
generated
39
ProjectAirline/Form1.Designer.cs
generated
@ -1,39 +0,0 @@
|
|||||||
namespace ProjectAirline
|
|
||||||
{
|
|
||||||
partial class Form1
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Required designer variable.
|
|
||||||
/// </summary>
|
|
||||||
private System.ComponentModel.IContainer components = null;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Clean up any resources being used.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
|
||||||
protected override void Dispose(bool disposing)
|
|
||||||
{
|
|
||||||
if (disposing && (components != null))
|
|
||||||
{
|
|
||||||
components.Dispose();
|
|
||||||
}
|
|
||||||
base.Dispose(disposing);
|
|
||||||
}
|
|
||||||
|
|
||||||
#region Windows Form Designer generated code
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Required method for Designer support - do not modify
|
|
||||||
/// the contents of this method with the code editor.
|
|
||||||
/// </summary>
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
namespace ProjectAirline
|
|
||||||
{
|
|
||||||
public partial class Form1 : Form
|
|
||||||
{
|
|
||||||
public Form1()
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
118
ProjectAirline/Forms/FormAirport.Designer.cs
generated
Normal file
118
ProjectAirline/Forms/FormAirport.Designer.cs
generated
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
namespace YourNamespace.Forms
|
||||||
|
{
|
||||||
|
partial class FormAirport
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
this.labelName = new System.Windows.Forms.Label();
|
||||||
|
this.labelLocation = new System.Windows.Forms.Label();
|
||||||
|
this.textBoxName = new System.Windows.Forms.TextBox();
|
||||||
|
this.textBoxLocation = new System.Windows.Forms.TextBox();
|
||||||
|
this.buttonSave = new System.Windows.Forms.Button();
|
||||||
|
this.buttonCancel = new System.Windows.Forms.Button();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// labelName
|
||||||
|
//
|
||||||
|
this.labelName.AutoSize = true;
|
||||||
|
this.labelName.Location = new System.Drawing.Point(12, 22);
|
||||||
|
this.labelName.Name = "labelName";
|
||||||
|
this.labelName.Size = new System.Drawing.Size(57, 13);
|
||||||
|
this.labelName.TabIndex = 0;
|
||||||
|
this.labelName.Text = "Название:";
|
||||||
|
//
|
||||||
|
// labelLocation
|
||||||
|
//
|
||||||
|
this.labelLocation.AutoSize = true;
|
||||||
|
this.labelLocation.Location = new System.Drawing.Point(12, 58);
|
||||||
|
this.labelLocation.Name = "labelLocation";
|
||||||
|
this.labelLocation.Size = new System.Drawing.Size(48, 13);
|
||||||
|
this.labelLocation.TabIndex = 1;
|
||||||
|
this.labelLocation.Text = "Место:";
|
||||||
|
//
|
||||||
|
// textBoxName
|
||||||
|
//
|
||||||
|
this.textBoxName.Location = new System.Drawing.Point(111, 19);
|
||||||
|
this.textBoxName.Name = "textBoxName";
|
||||||
|
this.textBoxName.Size = new System.Drawing.Size(200, 20);
|
||||||
|
this.textBoxName.TabIndex = 2;
|
||||||
|
//
|
||||||
|
// textBoxLocation
|
||||||
|
//
|
||||||
|
this.textBoxLocation.Location = new System.Drawing.Point(111, 55);
|
||||||
|
this.textBoxLocation.Name = "textBoxLocation";
|
||||||
|
this.textBoxLocation.Size = new System.Drawing.Size(200, 20);
|
||||||
|
this.textBoxLocation.TabIndex = 3;
|
||||||
|
//
|
||||||
|
// buttonSave
|
||||||
|
//
|
||||||
|
this.buttonSave.Location = new System.Drawing.Point(155, 91);
|
||||||
|
this.buttonSave.Name = "buttonSave";
|
||||||
|
this.buttonSave.Size = new System.Drawing.Size(75, 23);
|
||||||
|
this.buttonSave.TabIndex = 4;
|
||||||
|
this.buttonSave.Text = "Сохранить";
|
||||||
|
this.buttonSave.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
|
||||||
|
//
|
||||||
|
// buttonCancel
|
||||||
|
//
|
||||||
|
this.buttonCancel.Location = new System.Drawing.Point(236, 91);
|
||||||
|
this.buttonCancel.Name = "buttonCancel";
|
||||||
|
this.buttonCancel.Size = new System.Drawing.Size(75, 23);
|
||||||
|
this.buttonCancel.TabIndex = 5;
|
||||||
|
this.buttonCancel.Text = "Отмена";
|
||||||
|
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
|
||||||
|
//
|
||||||
|
// FormAirport
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(324, 126);
|
||||||
|
this.Controls.Add(this.buttonCancel);
|
||||||
|
this.Controls.Add(this.buttonSave);
|
||||||
|
this.Controls.Add(this.textBoxLocation);
|
||||||
|
this.Controls.Add(this.textBoxName);
|
||||||
|
this.Controls.Add(this.labelLocation);
|
||||||
|
this.Controls.Add(this.labelName);
|
||||||
|
this.Name = "FormAirport";
|
||||||
|
this.Text = "Редактирование аэропорта";
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
this.PerformLayout();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private System.Windows.Forms.Label labelName;
|
||||||
|
private System.Windows.Forms.Label labelLocation;
|
||||||
|
private System.Windows.Forms.TextBox textBoxName;
|
||||||
|
private System.Windows.Forms.TextBox textBoxLocation;
|
||||||
|
private System.Windows.Forms.Button buttonSave;
|
||||||
|
private System.Windows.Forms.Button buttonCancel;
|
||||||
|
}
|
||||||
|
}
|
70
ProjectAirline/Forms/FormAirport.cs
Normal file
70
ProjectAirline/Forms/FormAirport.cs
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
using System;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using YourNamespace.Entities;
|
||||||
|
using YourNamespace.Repositories;
|
||||||
|
|
||||||
|
namespace YourNamespace.Forms
|
||||||
|
{
|
||||||
|
public partial class FormAirport : Form
|
||||||
|
{
|
||||||
|
private readonly IAirportRepository _airportRepository;
|
||||||
|
private int? _airportId;
|
||||||
|
|
||||||
|
public int Id
|
||||||
|
{
|
||||||
|
set
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var airport = _airportRepository.ReadAirportById(value);
|
||||||
|
if (airport == null)
|
||||||
|
{
|
||||||
|
throw new InvalidDataException(nameof(airport));
|
||||||
|
}
|
||||||
|
textBoxName.Text = airport.Name;
|
||||||
|
textBoxLocation.Text = airport.Location;
|
||||||
|
_airportId = value;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public FormAirport(IAirportRepository airportRepository)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_airportRepository = airportRepository ?? throw new ArgumentNullException(nameof(airportRepository));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonSave_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(textBoxName.Text) || string.IsNullOrWhiteSpace(textBoxLocation.Text))
|
||||||
|
{
|
||||||
|
throw new Exception("Имеются незаполненные поля");
|
||||||
|
}
|
||||||
|
if (_airportId.HasValue)
|
||||||
|
{
|
||||||
|
_airportRepository.UpdateAirport(CreateAirport(_airportId.Value));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_airportRepository.CreateAirport(CreateAirport(0));
|
||||||
|
}
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
|
||||||
|
|
||||||
|
private Airport CreateAirport(int id) => Airport.CreateEntity(id, textBoxName.Text, textBoxLocation.Text);
|
||||||
|
}
|
||||||
|
}
|
106
ProjectAirline/Forms/FormAirports.Designer.cs
generated
Normal file
106
ProjectAirline/Forms/FormAirports.Designer.cs
generated
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
namespace YourNamespace.Forms
|
||||||
|
{
|
||||||
|
partial class FormAirports
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
this.dataGridViewData = new System.Windows.Forms.DataGridView();
|
||||||
|
this.buttonAdd = new System.Windows.Forms.Button();
|
||||||
|
this.buttonUpd = new System.Windows.Forms.Button();
|
||||||
|
this.buttonDel = new System.Windows.Forms.Button();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.dataGridViewData)).BeginInit();
|
||||||
|
this.SuspendLayout(); // Вызов SuspendLayout
|
||||||
|
//
|
||||||
|
// dataGridViewData
|
||||||
|
//
|
||||||
|
this.dataGridViewData.AllowUserToAddRows = false;
|
||||||
|
this.dataGridViewData.AllowUserToDeleteRows = false;
|
||||||
|
this.dataGridViewData.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
|
this.dataGridViewData.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
|
this.dataGridViewData.Location = new System.Drawing.Point(0, 0);
|
||||||
|
this.dataGridViewData.MultiSelect = false;
|
||||||
|
this.dataGridViewData.Name = "dataGridViewData";
|
||||||
|
this.dataGridViewData.ReadOnly = true;
|
||||||
|
this.dataGridViewData.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
|
||||||
|
this.dataGridViewData.Size = new System.Drawing.Size(800, 450);
|
||||||
|
this.dataGridViewData.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// buttonAdd
|
||||||
|
//
|
||||||
|
this.buttonAdd.Location = new System.Drawing.Point(12, 12);
|
||||||
|
this.buttonAdd.Name = "buttonAdd";
|
||||||
|
this.buttonAdd.Size = new System.Drawing.Size(75, 23);
|
||||||
|
this.buttonAdd.TabIndex = 1;
|
||||||
|
this.buttonAdd.Text = "Добавить";
|
||||||
|
this.buttonAdd.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
|
||||||
|
//
|
||||||
|
// buttonUpd
|
||||||
|
//
|
||||||
|
this.buttonUpd.Location = new System.Drawing.Point(93, 12);
|
||||||
|
this.buttonUpd.Name = "buttonUpd";
|
||||||
|
this.buttonUpd.Size = new System.Drawing.Size(75, 23);
|
||||||
|
this.buttonUpd.TabIndex = 2;
|
||||||
|
this.buttonUpd.Text = "Изменить";
|
||||||
|
this.buttonUpd.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click);
|
||||||
|
//
|
||||||
|
// buttonDel
|
||||||
|
//
|
||||||
|
this.buttonDel.Location = new System.Drawing.Point(174, 12);
|
||||||
|
this.buttonDel.Name = "buttonDel";
|
||||||
|
this.buttonDel.Size = new System.Drawing.Size(75, 23);
|
||||||
|
this.buttonDel.TabIndex = 3;
|
||||||
|
this.buttonDel.Text = "Удалить";
|
||||||
|
this.buttonDel.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click);
|
||||||
|
//
|
||||||
|
// FormAirports
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||||
|
this.Controls.Add(this.buttonDel);
|
||||||
|
this.Controls.Add(this.buttonUpd);
|
||||||
|
this.Controls.Add(this.buttonAdd);
|
||||||
|
this.Controls.Add(this.dataGridViewData);
|
||||||
|
this.Name = "FormAirports";
|
||||||
|
this.Text = "Аэропорты";
|
||||||
|
this.Load += new System.EventHandler(this.FormAirports_Load);
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.dataGridViewData)).EndInit();
|
||||||
|
this.ResumeLayout(false); // Вызов ResumeLayout
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private System.Windows.Forms.DataGridView dataGridViewData;
|
||||||
|
private System.Windows.Forms.Button buttonAdd;
|
||||||
|
private System.Windows.Forms.Button buttonUpd;
|
||||||
|
private System.Windows.Forms.Button buttonDel;
|
||||||
|
}
|
||||||
|
}
|
99
ProjectAirline/Forms/FormAirports.cs
Normal file
99
ProjectAirline/Forms/FormAirports.cs
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
using System;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using Unity;
|
||||||
|
using YourNamespace.Repositories;
|
||||||
|
|
||||||
|
namespace YourNamespace.Forms
|
||||||
|
{
|
||||||
|
public partial class FormAirports : Form
|
||||||
|
{
|
||||||
|
private readonly IUnityContainer _container;
|
||||||
|
private readonly IAirportRepository _airportRepository;
|
||||||
|
|
||||||
|
public FormAirports(IUnityContainer container, IAirportRepository airportRepository)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_container = container ?? throw new ArgumentNullException(nameof(container));
|
||||||
|
_airportRepository = airportRepository ?? throw new ArgumentNullException(nameof(airportRepository));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FormAirports_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<FormAirport>().ShowDialog();
|
||||||
|
LoadList();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonUpd_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var form = _container.Resolve<FormAirport>();
|
||||||
|
form.Id = findId;
|
||||||
|
form.ShowDialog();
|
||||||
|
LoadList();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonDel_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_airportRepository.DeleteAirport(findId);
|
||||||
|
LoadList();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadList() => dataGridViewData.DataSource = _airportRepository.ReadAirports();
|
||||||
|
|
||||||
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
|
{
|
||||||
|
id = 0;
|
||||||
|
if (dataGridViewData.SelectedRows.Count < 1)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
id = Convert.ToInt32(dataGridViewData.SelectedRows[0].Cells["Id"].Value);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
120
ProjectAirline/Forms/FormAirports.resx
Normal file
120
ProjectAirline/Forms/FormAirports.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
141
ProjectAirline/Forms/FormEmployee.Designer.cs
generated
Normal file
141
ProjectAirline/Forms/FormEmployee.Designer.cs
generated
Normal file
@ -0,0 +1,141 @@
|
|||||||
|
namespace YourNamespace.Forms
|
||||||
|
{
|
||||||
|
partial class FormEmployee
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
this.labelFirstName = new System.Windows.Forms.Label();
|
||||||
|
this.labelLastName = new System.Windows.Forms.Label();
|
||||||
|
this.labelPost = new System.Windows.Forms.Label();
|
||||||
|
this.textBoxFirstName = new System.Windows.Forms.TextBox();
|
||||||
|
this.textBoxLastName = new System.Windows.Forms.TextBox();
|
||||||
|
this.comboBoxPost = new System.Windows.Forms.ComboBox();
|
||||||
|
this.buttonSave = new System.Windows.Forms.Button();
|
||||||
|
this.buttonCancel = new System.Windows.Forms.Button();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// labelFirstName
|
||||||
|
//
|
||||||
|
this.labelFirstName.AutoSize = true;
|
||||||
|
this.labelFirstName.Location = new System.Drawing.Point(12, 22);
|
||||||
|
this.labelFirstName.Name = "labelFirstName";
|
||||||
|
this.labelFirstName.Size = new System.Drawing.Size(32, 13);
|
||||||
|
this.labelFirstName.TabIndex = 0;
|
||||||
|
this.labelFirstName.Text = "Имя:";
|
||||||
|
//
|
||||||
|
// labelLastName
|
||||||
|
//
|
||||||
|
this.labelLastName.AutoSize = true;
|
||||||
|
this.labelLastName.Location = new System.Drawing.Point(12, 58);
|
||||||
|
this.labelLastName.Name = "labelLastName";
|
||||||
|
this.labelLastName.Size = new System.Drawing.Size(59, 13);
|
||||||
|
this.labelLastName.TabIndex = 1;
|
||||||
|
this.labelLastName.Text = "Фамилия:";
|
||||||
|
//
|
||||||
|
// labelPost
|
||||||
|
//
|
||||||
|
this.labelPost.AutoSize = true;
|
||||||
|
this.labelPost.Location = new System.Drawing.Point(12, 94);
|
||||||
|
this.labelPost.Name = "labelPost";
|
||||||
|
this.labelPost.Size = new System.Drawing.Size(65, 13);
|
||||||
|
this.labelPost.TabIndex = 2;
|
||||||
|
this.labelPost.Text = "Должность:";
|
||||||
|
//
|
||||||
|
// textBoxFirstName
|
||||||
|
//
|
||||||
|
this.textBoxFirstName.Location = new System.Drawing.Point(111, 19);
|
||||||
|
this.textBoxFirstName.Name = "textBoxFirstName";
|
||||||
|
this.textBoxFirstName.Size = new System.Drawing.Size(200, 20);
|
||||||
|
this.textBoxFirstName.TabIndex = 3;
|
||||||
|
//
|
||||||
|
// textBoxLastName
|
||||||
|
//
|
||||||
|
this.textBoxLastName.Location = new System.Drawing.Point(111, 55);
|
||||||
|
this.textBoxLastName.Name = "textBoxLastName";
|
||||||
|
this.textBoxLastName.Size = new System.Drawing.Size(200, 20);
|
||||||
|
this.textBoxLastName.TabIndex = 4;
|
||||||
|
//
|
||||||
|
// comboBoxPost
|
||||||
|
//
|
||||||
|
this.comboBoxPost.FormattingEnabled = true;
|
||||||
|
this.comboBoxPost.Location = new System.Drawing.Point(111, 91);
|
||||||
|
this.comboBoxPost.Name = "comboBoxPost";
|
||||||
|
this.comboBoxPost.Size = new System.Drawing.Size(200, 21);
|
||||||
|
this.comboBoxPost.TabIndex = 5;
|
||||||
|
//
|
||||||
|
// buttonSave
|
||||||
|
//
|
||||||
|
this.buttonSave.Location = new System.Drawing.Point(155, 128);
|
||||||
|
this.buttonSave.Name = "buttonSave";
|
||||||
|
this.buttonSave.Size = new System.Drawing.Size(75, 23);
|
||||||
|
this.buttonSave.TabIndex = 6;
|
||||||
|
this.buttonSave.Text = "Сохранить";
|
||||||
|
this.buttonSave.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
|
||||||
|
//
|
||||||
|
// buttonCancel
|
||||||
|
//
|
||||||
|
this.buttonCancel.Location = new System.Drawing.Point(236, 128);
|
||||||
|
this.buttonCancel.Name = "buttonCancel";
|
||||||
|
this.buttonCancel.Size = new System.Drawing.Size(75, 23);
|
||||||
|
this.buttonCancel.TabIndex = 7;
|
||||||
|
this.buttonCancel.Text = "Отмена";
|
||||||
|
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
|
||||||
|
//
|
||||||
|
// FormEmployee
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(324, 166);
|
||||||
|
this.Controls.Add(this.buttonCancel);
|
||||||
|
this.Controls.Add(this.buttonSave);
|
||||||
|
this.Controls.Add(this.comboBoxPost);
|
||||||
|
this.Controls.Add(this.textBoxLastName);
|
||||||
|
this.Controls.Add(this.textBoxFirstName);
|
||||||
|
this.Controls.Add(this.labelPost);
|
||||||
|
this.Controls.Add(this.labelLastName);
|
||||||
|
this.Controls.Add(this.labelFirstName);
|
||||||
|
this.Name = "FormEmployee";
|
||||||
|
this.Text = "Редактирование сотрудника";
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
this.PerformLayout();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private System.Windows.Forms.Label labelFirstName;
|
||||||
|
private System.Windows.Forms.Label labelLastName;
|
||||||
|
private System.Windows.Forms.Label labelPost;
|
||||||
|
private System.Windows.Forms.TextBox textBoxFirstName;
|
||||||
|
private System.Windows.Forms.TextBox textBoxLastName;
|
||||||
|
private System.Windows.Forms.ComboBox comboBoxPost;
|
||||||
|
private System.Windows.Forms.Button buttonSave;
|
||||||
|
private System.Windows.Forms.Button buttonCancel;
|
||||||
|
}
|
||||||
|
}
|
74
ProjectAirline/Forms/FormEmployee.cs
Normal file
74
ProjectAirline/Forms/FormEmployee.cs
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
using System;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using YourNamespace.Entities;
|
||||||
|
using YourNamespace.Entities.Enums;
|
||||||
|
using YourNamespace.Repositories;
|
||||||
|
|
||||||
|
namespace YourNamespace.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;
|
||||||
|
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) || comboBoxPost.SelectedIndex < 0)
|
||||||
|
{
|
||||||
|
throw new Exception("Имеются незаполненные поля");
|
||||||
|
}
|
||||||
|
if (_employeeId.HasValue)
|
||||||
|
{
|
||||||
|
_employeeRepository.UpdateEmployee(CreateEmployee(_employeeId.Value));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_employeeRepository.CreateEmployee(CreateEmployee(0));
|
||||||
|
}
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
|
||||||
|
|
||||||
|
private Employee CreateEmployee(int id) => Employee.CreateEntity(id, textBoxFirstName.Text, textBoxLastName.Text, (EmployeePost)comboBoxPost.SelectedItem);
|
||||||
|
}
|
||||||
|
}
|
120
ProjectAirline/Forms/FormEmployee.resx
Normal file
120
ProjectAirline/Forms/FormEmployee.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
106
ProjectAirline/Forms/FormEmployees.Designer.cs
generated
Normal file
106
ProjectAirline/Forms/FormEmployees.Designer.cs
generated
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
namespace YourNamespace.Forms
|
||||||
|
{
|
||||||
|
partial class FormEmployees
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
this.dataGridViewData = new System.Windows.Forms.DataGridView();
|
||||||
|
this.buttonAdd = new System.Windows.Forms.Button();
|
||||||
|
this.buttonUpd = new System.Windows.Forms.Button();
|
||||||
|
this.buttonDel = new System.Windows.Forms.Button();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.dataGridViewData)).BeginInit();
|
||||||
|
this.SuspendLayout(); // Вызов SuspendLayout
|
||||||
|
//
|
||||||
|
// dataGridViewData
|
||||||
|
//
|
||||||
|
this.dataGridViewData.AllowUserToAddRows = false;
|
||||||
|
this.dataGridViewData.AllowUserToDeleteRows = false;
|
||||||
|
this.dataGridViewData.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
|
this.dataGridViewData.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
|
this.dataGridViewData.Location = new System.Drawing.Point(0, 0);
|
||||||
|
this.dataGridViewData.MultiSelect = false;
|
||||||
|
this.dataGridViewData.Name = "dataGridViewData";
|
||||||
|
this.dataGridViewData.ReadOnly = true;
|
||||||
|
this.dataGridViewData.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
|
||||||
|
this.dataGridViewData.Size = new System.Drawing.Size(800, 450);
|
||||||
|
this.dataGridViewData.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// buttonAdd
|
||||||
|
//
|
||||||
|
this.buttonAdd.Location = new System.Drawing.Point(12, 12);
|
||||||
|
this.buttonAdd.Name = "buttonAdd";
|
||||||
|
this.buttonAdd.Size = new System.Drawing.Size(75, 23);
|
||||||
|
this.buttonAdd.TabIndex = 1;
|
||||||
|
this.buttonAdd.Text = "Добавить";
|
||||||
|
this.buttonAdd.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
|
||||||
|
//
|
||||||
|
// buttonUpd
|
||||||
|
//
|
||||||
|
this.buttonUpd.Location = new System.Drawing.Point(93, 12);
|
||||||
|
this.buttonUpd.Name = "buttonUpd";
|
||||||
|
this.buttonUpd.Size = new System.Drawing.Size(75, 23);
|
||||||
|
this.buttonUpd.TabIndex = 2;
|
||||||
|
this.buttonUpd.Text = "Изменить";
|
||||||
|
this.buttonUpd.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click);
|
||||||
|
//
|
||||||
|
// buttonDel
|
||||||
|
//
|
||||||
|
this.buttonDel.Location = new System.Drawing.Point(174, 12);
|
||||||
|
this.buttonDel.Name = "buttonDel";
|
||||||
|
this.buttonDel.Size = new System.Drawing.Size(75, 23);
|
||||||
|
this.buttonDel.TabIndex = 3;
|
||||||
|
this.buttonDel.Text = "Удалить";
|
||||||
|
this.buttonDel.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click);
|
||||||
|
//
|
||||||
|
// FormEmployees
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||||
|
this.Controls.Add(this.buttonDel);
|
||||||
|
this.Controls.Add(this.buttonUpd);
|
||||||
|
this.Controls.Add(this.buttonAdd);
|
||||||
|
this.Controls.Add(this.dataGridViewData);
|
||||||
|
this.Name = "FormEmployees";
|
||||||
|
this.Text = "Сотрудники";
|
||||||
|
this.Load += new System.EventHandler(this.FormEmployees_Load);
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.dataGridViewData)).EndInit();
|
||||||
|
this.ResumeLayout(false); // Вызов ResumeLayout
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private System.Windows.Forms.DataGridView dataGridViewData;
|
||||||
|
private System.Windows.Forms.Button buttonAdd;
|
||||||
|
private System.Windows.Forms.Button buttonUpd;
|
||||||
|
private System.Windows.Forms.Button buttonDel;
|
||||||
|
}
|
||||||
|
}
|
99
ProjectAirline/Forms/FormEmployees.cs
Normal file
99
ProjectAirline/Forms/FormEmployees.cs
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
using System;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using Unity;
|
||||||
|
using YourNamespace.Repositories;
|
||||||
|
|
||||||
|
namespace YourNamespace.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<FormEmployee>().ShowDialog();
|
||||||
|
LoadList();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonUpd_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var form = _container.Resolve<FormEmployee>();
|
||||||
|
form.Id = findId;
|
||||||
|
form.ShowDialog();
|
||||||
|
LoadList();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonDel_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_employeeRepository.DeleteEmployee(findId);
|
||||||
|
LoadList();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadList() => dataGridViewData.DataSource = _employeeRepository.ReadEmployees();
|
||||||
|
|
||||||
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
|
{
|
||||||
|
id = 0;
|
||||||
|
if (dataGridViewData.SelectedRows.Count < 1)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
id = Convert.ToInt32(dataGridViewData.SelectedRows[0].Cells["Id"].Value);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
120
ProjectAirline/Forms/FormEmployees.resx
Normal file
120
ProjectAirline/Forms/FormEmployees.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
188
ProjectAirline/Forms/FormFlight.Designer.cs
generated
Normal file
188
ProjectAirline/Forms/FormFlight.Designer.cs
generated
Normal file
@ -0,0 +1,188 @@
|
|||||||
|
namespace YourNamespace.Forms
|
||||||
|
{
|
||||||
|
partial class FormFlight
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
this.labelFlightNumber = new System.Windows.Forms.Label();
|
||||||
|
this.labelDepartureDateTime = new System.Windows.Forms.Label();
|
||||||
|
this.labelArrivalDateTime = new System.Windows.Forms.Label();
|
||||||
|
this.labelPlane = new System.Windows.Forms.Label();
|
||||||
|
this.labelAirport = new System.Windows.Forms.Label();
|
||||||
|
this.numericUpDownFlightNumber = new System.Windows.Forms.NumericUpDown();
|
||||||
|
this.dateTimePickerDeparture = new System.Windows.Forms.DateTimePicker();
|
||||||
|
this.dateTimePickerArrival = new System.Windows.Forms.DateTimePicker();
|
||||||
|
this.comboBoxPlane = new System.Windows.Forms.ComboBox();
|
||||||
|
this.comboBoxAirport = new System.Windows.Forms.ComboBox();
|
||||||
|
this.buttonSave = new System.Windows.Forms.Button();
|
||||||
|
this.buttonCancel = new System.Windows.Forms.Button();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.numericUpDownFlightNumber)).BeginInit();
|
||||||
|
this.SuspendLayout(); // Вызов SuspendLayout
|
||||||
|
//
|
||||||
|
// labelFlightNumber
|
||||||
|
//
|
||||||
|
this.labelFlightNumber.AutoSize = true;
|
||||||
|
this.labelFlightNumber.Location = new System.Drawing.Point(12, 22);
|
||||||
|
this.labelFlightNumber.Name = "labelFlightNumber";
|
||||||
|
this.labelFlightNumber.Size = new System.Drawing.Size(80, 13);
|
||||||
|
this.labelFlightNumber.TabIndex = 0;
|
||||||
|
this.labelFlightNumber.Text = "Номер рейса:";
|
||||||
|
//
|
||||||
|
// labelDepartureDateTime
|
||||||
|
//
|
||||||
|
this.labelDepartureDateTime.AutoSize = true;
|
||||||
|
this.labelDepartureDateTime.Location = new System.Drawing.Point(12, 58);
|
||||||
|
this.labelDepartureDateTime.Name = "labelDepartureDateTime";
|
||||||
|
this.labelDepartureDateTime.Size = new System.Drawing.Size(115, 13);
|
||||||
|
this.labelDepartureDateTime.TabIndex = 1;
|
||||||
|
this.labelDepartureDateTime.Text = "Дата и время вылета:";
|
||||||
|
//
|
||||||
|
// labelArrivalDateTime
|
||||||
|
//
|
||||||
|
this.labelArrivalDateTime.AutoSize = true;
|
||||||
|
this.labelArrivalDateTime.Location = new System.Drawing.Point(12, 94);
|
||||||
|
this.labelArrivalDateTime.Name = "labelArrivalDateTime";
|
||||||
|
this.labelArrivalDateTime.Size = new System.Drawing.Size(119, 13);
|
||||||
|
this.labelArrivalDateTime.TabIndex = 2;
|
||||||
|
this.labelArrivalDateTime.Text = "Дата и время прибытия:";
|
||||||
|
//
|
||||||
|
// labelPlane
|
||||||
|
//
|
||||||
|
this.labelPlane.AutoSize = true;
|
||||||
|
this.labelPlane.Location = new System.Drawing.Point(12, 130);
|
||||||
|
this.labelPlane.Name = "labelPlane";
|
||||||
|
this.labelPlane.Size = new System.Drawing.Size(54, 13);
|
||||||
|
this.labelPlane.TabIndex = 3;
|
||||||
|
this.labelPlane.Text = "Самолет:";
|
||||||
|
//
|
||||||
|
// labelAirport
|
||||||
|
//
|
||||||
|
this.labelAirport.AutoSize = true;
|
||||||
|
this.labelAirport.Location = new System.Drawing.Point(12, 166);
|
||||||
|
this.labelAirport.Name = "labelAirport";
|
||||||
|
this.labelAirport.Size = new System.Drawing.Size(59, 13);
|
||||||
|
this.labelAirport.TabIndex = 4;
|
||||||
|
this.labelAirport.Text = "Аэропорт:";
|
||||||
|
//
|
||||||
|
// numericUpDownFlightNumber
|
||||||
|
//
|
||||||
|
this.numericUpDownFlightNumber.Location = new System.Drawing.Point(133, 20);
|
||||||
|
this.numericUpDownFlightNumber.Name = "numericUpDownFlightNumber";
|
||||||
|
this.numericUpDownFlightNumber.Size = new System.Drawing.Size(150, 20);
|
||||||
|
this.numericUpDownFlightNumber.TabIndex = 5;
|
||||||
|
//
|
||||||
|
// dateTimePickerDeparture
|
||||||
|
//
|
||||||
|
this.dateTimePickerDeparture.Location = new System.Drawing.Point(133, 56);
|
||||||
|
this.dateTimePickerDeparture.Name = "dateTimePickerDeparture";
|
||||||
|
this.dateTimePickerDeparture.Size = new System.Drawing.Size(150, 20);
|
||||||
|
this.dateTimePickerDeparture.TabIndex = 6;
|
||||||
|
//
|
||||||
|
// dateTimePickerArrival
|
||||||
|
//
|
||||||
|
this.dateTimePickerArrival.Location = new System.Drawing.Point(133, 92);
|
||||||
|
this.dateTimePickerArrival.Name = "dateTimePickerArrival";
|
||||||
|
this.dateTimePickerArrival.Size = new System.Drawing.Size(150, 20);
|
||||||
|
this.dateTimePickerArrival.TabIndex = 7;
|
||||||
|
//
|
||||||
|
// comboBoxPlane
|
||||||
|
//
|
||||||
|
this.comboBoxPlane.FormattingEnabled = true;
|
||||||
|
this.comboBoxPlane.Location = new System.Drawing.Point(133, 128);
|
||||||
|
this.comboBoxPlane.Name = "comboBoxPlane";
|
||||||
|
this.comboBoxPlane.Size = new System.Drawing.Size(150, 21);
|
||||||
|
this.comboBoxPlane.TabIndex = 8;
|
||||||
|
//
|
||||||
|
// comboBoxAirport
|
||||||
|
//
|
||||||
|
this.comboBoxAirport.FormattingEnabled = true;
|
||||||
|
this.comboBoxAirport.Location = new System.Drawing.Point(133, 164);
|
||||||
|
this.comboBoxAirport.Name = "comboBoxAirport";
|
||||||
|
this.comboBoxAirport.Size = new System.Drawing.Size(150, 21);
|
||||||
|
this.comboBoxAirport.TabIndex = 9;
|
||||||
|
//
|
||||||
|
// buttonSave
|
||||||
|
//
|
||||||
|
this.buttonSave.Location = new System.Drawing.Point(133, 200);
|
||||||
|
this.buttonSave.Name = "buttonSave";
|
||||||
|
this.buttonSave.Size = new System.Drawing.Size(75, 23);
|
||||||
|
this.buttonSave.TabIndex = 10;
|
||||||
|
this.buttonSave.Text = "Сохранить";
|
||||||
|
this.buttonSave.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
|
||||||
|
//
|
||||||
|
// buttonCancel
|
||||||
|
//
|
||||||
|
this.buttonCancel.Location = new System.Drawing.Point(208, 200);
|
||||||
|
this.buttonCancel.Name = "buttonCancel";
|
||||||
|
this.buttonCancel.Size = new System.Drawing.Size(75, 23);
|
||||||
|
this.buttonCancel.TabIndex = 11;
|
||||||
|
this.buttonCancel.Text = "Отмена";
|
||||||
|
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
|
||||||
|
//
|
||||||
|
// FormFlight
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(304, 235);
|
||||||
|
this.Controls.Add(this.buttonCancel);
|
||||||
|
this.Controls.Add(this.buttonSave);
|
||||||
|
this.Controls.Add(this.comboBoxAirport);
|
||||||
|
this.Controls.Add(this.comboBoxPlane);
|
||||||
|
this.Controls.Add(this.dateTimePickerArrival);
|
||||||
|
this.Controls.Add(this.dateTimePickerDeparture);
|
||||||
|
this.Controls.Add(this.numericUpDownFlightNumber);
|
||||||
|
this.Controls.Add(this.labelAirport);
|
||||||
|
this.Controls.Add(this.labelPlane);
|
||||||
|
this.Controls.Add(this.labelArrivalDateTime);
|
||||||
|
this.Controls.Add(this.labelDepartureDateTime);
|
||||||
|
this.Controls.Add(this.labelFlightNumber);
|
||||||
|
this.Name = "FormFlight";
|
||||||
|
this.Text = "Редактирование рейса";
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.numericUpDownFlightNumber)).EndInit();
|
||||||
|
this.ResumeLayout(false); // Вызов ResumeLayout
|
||||||
|
this.PerformLayout(); // Вызов PerformLayout
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private System.Windows.Forms.Label labelFlightNumber;
|
||||||
|
private System.Windows.Forms.Label labelDepartureDateTime;
|
||||||
|
private System.Windows.Forms.Label labelArrivalDateTime;
|
||||||
|
private System.Windows.Forms.Label labelPlane;
|
||||||
|
private System.Windows.Forms.Label labelAirport;
|
||||||
|
private System.Windows.Forms.NumericUpDown numericUpDownFlightNumber;
|
||||||
|
private System.Windows.Forms.DateTimePicker dateTimePickerDeparture;
|
||||||
|
private System.Windows.Forms.DateTimePicker dateTimePickerArrival;
|
||||||
|
private System.Windows.Forms.ComboBox comboBoxPlane;
|
||||||
|
private System.Windows.Forms.ComboBox comboBoxAirport;
|
||||||
|
private System.Windows.Forms.Button buttonSave;
|
||||||
|
private System.Windows.Forms.Button buttonCancel;
|
||||||
|
}
|
||||||
|
}
|
85
ProjectAirline/Forms/FormFlight.cs
Normal file
85
ProjectAirline/Forms/FormFlight.cs
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
using System;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using YourNamespace.Entities;
|
||||||
|
using YourNamespace.Repositories;
|
||||||
|
|
||||||
|
namespace YourNamespace.Forms
|
||||||
|
{
|
||||||
|
public partial class FormFlight : Form
|
||||||
|
{
|
||||||
|
private readonly IFlightRepository _flightRepository;
|
||||||
|
private readonly IPlaneRepository _planeRepository;
|
||||||
|
private readonly IAirportRepository _airportRepository;
|
||||||
|
private int? _flightId;
|
||||||
|
|
||||||
|
public int Id
|
||||||
|
{
|
||||||
|
set
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var flight = _flightRepository.ReadFlightById(value);
|
||||||
|
if (flight == null)
|
||||||
|
{
|
||||||
|
throw new InvalidDataException(nameof(flight));
|
||||||
|
}
|
||||||
|
numericUpDownFlightNumber.Value = flight.FlightNumber;
|
||||||
|
dateTimePickerDeparture.Value = flight.DepartureDateTime;
|
||||||
|
dateTimePickerArrival.Value = flight.ArrivalDateTime;
|
||||||
|
comboBoxPlane.SelectedValue = flight.PlaneId;
|
||||||
|
comboBoxAirport.SelectedValue = flight.AirportId;
|
||||||
|
_flightId = value;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public FormFlight(IFlightRepository flightRepository, IPlaneRepository planeRepository, IAirportRepository airportRepository)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_flightRepository = flightRepository ?? throw new ArgumentNullException(nameof(flightRepository));
|
||||||
|
_planeRepository = planeRepository ?? throw new ArgumentNullException(nameof(planeRepository));
|
||||||
|
_airportRepository = airportRepository ?? throw new ArgumentNullException(nameof(airportRepository));
|
||||||
|
|
||||||
|
comboBoxPlane.DataSource = _planeRepository.ReadPlanes();
|
||||||
|
comboBoxPlane.DisplayMember = "Model";
|
||||||
|
comboBoxPlane.ValueMember = "Id";
|
||||||
|
|
||||||
|
comboBoxAirport.DataSource = _airportRepository.ReadAirports();
|
||||||
|
comboBoxAirport.DisplayMember = "Name";
|
||||||
|
comboBoxAirport.ValueMember = "Id";
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonSave_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (comboBoxPlane.SelectedIndex < 0 || comboBoxAirport.SelectedIndex < 0)
|
||||||
|
{
|
||||||
|
throw new Exception("Имеются незаполненные поля");
|
||||||
|
}
|
||||||
|
if (_flightId.HasValue)
|
||||||
|
{
|
||||||
|
_flightRepository.UpdateFlight(CreateFlight(_flightId.Value));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_flightRepository.CreateFlight(CreateFlight(0));
|
||||||
|
}
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
|
||||||
|
|
||||||
|
private Flight CreateFlight(int id) => Flight.CreateEntity(id, (int)numericUpDownFlightNumber.Value, dateTimePickerDeparture.Value, dateTimePickerArrival.Value, (int)comboBoxPlane.SelectedValue, (int)comboBoxAirport.SelectedValue);
|
||||||
|
}
|
||||||
|
}
|
120
ProjectAirline/Forms/FormFlight.resx
Normal file
120
ProjectAirline/Forms/FormFlight.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
106
ProjectAirline/Forms/FormFlights.Designer.cs
generated
Normal file
106
ProjectAirline/Forms/FormFlights.Designer.cs
generated
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
namespace YourNamespace.Forms
|
||||||
|
{
|
||||||
|
partial class FormFlights
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
this.dataGridViewData = new System.Windows.Forms.DataGridView();
|
||||||
|
this.buttonAdd = new System.Windows.Forms.Button();
|
||||||
|
this.buttonUpd = new System.Windows.Forms.Button();
|
||||||
|
this.buttonDel = new System.Windows.Forms.Button();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.dataGridViewData)).BeginInit();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// dataGridViewData
|
||||||
|
//
|
||||||
|
this.dataGridViewData.AllowUserToAddRows = false;
|
||||||
|
this.dataGridViewData.AllowUserToDeleteRows = false;
|
||||||
|
this.dataGridViewData.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
|
this.dataGridViewData.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
|
this.dataGridViewData.Location = new System.Drawing.Point(0, 0);
|
||||||
|
this.dataGridViewData.MultiSelect = false;
|
||||||
|
this.dataGridViewData.Name = "dataGridViewData";
|
||||||
|
this.dataGridViewData.ReadOnly = true;
|
||||||
|
this.dataGridViewData.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
|
||||||
|
this.dataGridViewData.Size = new System.Drawing.Size(800, 450);
|
||||||
|
this.dataGridViewData.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// buttonAdd
|
||||||
|
//
|
||||||
|
this.buttonAdd.Location = new System.Drawing.Point(12, 12);
|
||||||
|
this.buttonAdd.Name = "buttonAdd";
|
||||||
|
this.buttonAdd.Size = new System.Drawing.Size(75, 23);
|
||||||
|
this.buttonAdd.TabIndex = 1;
|
||||||
|
this.buttonAdd.Text = "Добавить";
|
||||||
|
this.buttonAdd.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
|
||||||
|
//
|
||||||
|
// buttonUpd
|
||||||
|
//
|
||||||
|
this.buttonUpd.Location = new System.Drawing.Point(93, 12);
|
||||||
|
this.buttonUpd.Name = "buttonUpd";
|
||||||
|
this.buttonUpd.Size = new System.Drawing.Size(75, 23);
|
||||||
|
this.buttonUpd.TabIndex = 2;
|
||||||
|
this.buttonUpd.Text = "Изменить";
|
||||||
|
this.buttonUpd.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click);
|
||||||
|
//
|
||||||
|
// buttonDel
|
||||||
|
//
|
||||||
|
this.buttonDel.Location = new System.Drawing.Point(174, 12);
|
||||||
|
this.buttonDel.Name = "buttonDel";
|
||||||
|
this.buttonDel.Size = new System.Drawing.Size(75, 23);
|
||||||
|
this.buttonDel.TabIndex = 3;
|
||||||
|
this.buttonDel.Text = "Удалить";
|
||||||
|
this.buttonDel.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click);
|
||||||
|
//
|
||||||
|
// FormFlights
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||||
|
this.Controls.Add(this.buttonDel);
|
||||||
|
this.Controls.Add(this.buttonUpd);
|
||||||
|
this.Controls.Add(this.buttonAdd);
|
||||||
|
this.Controls.Add(this.dataGridViewData);
|
||||||
|
this.Name = "FormFlights";
|
||||||
|
this.Text = "Рейсы";
|
||||||
|
this.Load += new System.EventHandler(this.FormFlights_Load);
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.dataGridViewData)).EndInit();
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private System.Windows.Forms.DataGridView dataGridViewData;
|
||||||
|
private System.Windows.Forms.Button buttonAdd;
|
||||||
|
private System.Windows.Forms.Button buttonUpd;
|
||||||
|
private System.Windows.Forms.Button buttonDel;
|
||||||
|
}
|
||||||
|
}
|
99
ProjectAirline/Forms/FormFlights.cs
Normal file
99
ProjectAirline/Forms/FormFlights.cs
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
using System;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using Unity;
|
||||||
|
using YourNamespace.Repositories;
|
||||||
|
|
||||||
|
namespace YourNamespace.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<FormFlight>().ShowDialog();
|
||||||
|
LoadList();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonUpd_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var form = _container.Resolve<FormFlight>();
|
||||||
|
form.Id = findId;
|
||||||
|
form.ShowDialog();
|
||||||
|
LoadList();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonDel_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_flightRepository.DeleteFlight(findId);
|
||||||
|
LoadList();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadList() => dataGridViewData.DataSource = _flightRepository.ReadFlights();
|
||||||
|
|
||||||
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
|
{
|
||||||
|
id = 0;
|
||||||
|
if (dataGridViewData.SelectedRows.Count < 1)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
id = Convert.ToInt32(dataGridViewData.SelectedRows[0].Cells["Id"].Value);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
120
ProjectAirline/Forms/FormFlights.resx
Normal file
120
ProjectAirline/Forms/FormFlights.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
134
ProjectAirline/Forms/FormMain.Designer.cs
generated
Normal file
134
ProjectAirline/Forms/FormMain.Designer.cs
generated
Normal file
@ -0,0 +1,134 @@
|
|||||||
|
namespace YourNamespace.Forms
|
||||||
|
{
|
||||||
|
partial class FormMain
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
this.menuStrip = new System.Windows.Forms.MenuStrip();
|
||||||
|
this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
|
this.ticketsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
|
this.passengersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
|
this.flightsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
|
this.airportsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
|
this.planesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
|
this.employeesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
|
this.menuStrip.SuspendLayout();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// menuStrip
|
||||||
|
//
|
||||||
|
this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||||
|
this.справочникиToolStripMenuItem});
|
||||||
|
this.menuStrip.Location = new System.Drawing.Point(0, 0);
|
||||||
|
this.menuStrip.Name = "menuStrip";
|
||||||
|
this.menuStrip.Size = new System.Drawing.Size(800, 24);
|
||||||
|
this.menuStrip.TabIndex = 0;
|
||||||
|
this.menuStrip.Text = "menuStrip1";
|
||||||
|
//
|
||||||
|
// справочникиToolStripMenuItem
|
||||||
|
//
|
||||||
|
this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||||
|
this.ticketsToolStripMenuItem,
|
||||||
|
this.passengersToolStripMenuItem,
|
||||||
|
this.flightsToolStripMenuItem,
|
||||||
|
this.airportsToolStripMenuItem,
|
||||||
|
this.planesToolStripMenuItem,
|
||||||
|
this.employeesToolStripMenuItem});
|
||||||
|
this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
|
||||||
|
this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(94, 20);
|
||||||
|
this.справочникиToolStripMenuItem.Text = "Справочники";
|
||||||
|
//
|
||||||
|
// ticketsToolStripMenuItem
|
||||||
|
//
|
||||||
|
this.ticketsToolStripMenuItem.Name = "ticketsToolStripMenuItem";
|
||||||
|
this.ticketsToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||||
|
this.ticketsToolStripMenuItem.Text = "Билеты";
|
||||||
|
this.ticketsToolStripMenuItem.Click += new System.EventHandler(this.TicketsToolStripMenuItem_Click);
|
||||||
|
//
|
||||||
|
// passengersToolStripMenuItem
|
||||||
|
//
|
||||||
|
this.passengersToolStripMenuItem.Name = "passengersToolStripMenuItem";
|
||||||
|
this.passengersToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||||
|
this.passengersToolStripMenuItem.Text = "Пассажиры";
|
||||||
|
this.passengersToolStripMenuItem.Click += new System.EventHandler(this.PassengersToolStripMenuItem_Click);
|
||||||
|
//
|
||||||
|
// flightsToolStripMenuItem
|
||||||
|
//
|
||||||
|
this.flightsToolStripMenuItem.Name = "flightsToolStripMenuItem";
|
||||||
|
this.flightsToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||||
|
this.flightsToolStripMenuItem.Text = "Рейсы";
|
||||||
|
this.flightsToolStripMenuItem.Click += new System.EventHandler(this.FlightsToolStripMenuItem_Click);
|
||||||
|
//
|
||||||
|
// airportsToolStripMenuItem
|
||||||
|
//
|
||||||
|
this.airportsToolStripMenuItem.Name = "airportsToolStripMenuItem";
|
||||||
|
this.airportsToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||||
|
this.airportsToolStripMenuItem.Text = "Аэропорты";
|
||||||
|
this.airportsToolStripMenuItem.Click += new System.EventHandler(this.AirportsToolStripMenuItem_Click);
|
||||||
|
//
|
||||||
|
// planesToolStripMenuItem
|
||||||
|
//
|
||||||
|
this.planesToolStripMenuItem.Name = "planesToolStripMenuItem";
|
||||||
|
this.planesToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||||
|
this.planesToolStripMenuItem.Text = "Самолеты";
|
||||||
|
this.planesToolStripMenuItem.Click += new System.EventHandler(this.PlanesToolStripMenuItem_Click);
|
||||||
|
//
|
||||||
|
// employeesToolStripMenuItem
|
||||||
|
//
|
||||||
|
this.employeesToolStripMenuItem.Name = "employeesToolStripMenuItem";
|
||||||
|
this.employeesToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||||
|
this.employeesToolStripMenuItem.Text = "Сотрудники";
|
||||||
|
this.employeesToolStripMenuItem.Click += new System.EventHandler(this.EmployeesToolStripMenuItem_Click);
|
||||||
|
//
|
||||||
|
// FormMain
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||||
|
this.Controls.Add(this.menuStrip);
|
||||||
|
this.MainMenuStrip = this.menuStrip;
|
||||||
|
this.Name = "FormMain";
|
||||||
|
this.Text = "Главная форма";
|
||||||
|
this.menuStrip.ResumeLayout(false);
|
||||||
|
this.menuStrip.PerformLayout();
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
this.PerformLayout();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private System.Windows.Forms.MenuStrip menuStrip;
|
||||||
|
private System.Windows.Forms.ToolStripMenuItem справочникиToolStripMenuItem;
|
||||||
|
private System.Windows.Forms.ToolStripMenuItem ticketsToolStripMenuItem;
|
||||||
|
private System.Windows.Forms.ToolStripMenuItem passengersToolStripMenuItem;
|
||||||
|
private System.Windows.Forms.ToolStripMenuItem flightsToolStripMenuItem;
|
||||||
|
private System.Windows.Forms.ToolStripMenuItem airportsToolStripMenuItem;
|
||||||
|
private System.Windows.Forms.ToolStripMenuItem planesToolStripMenuItem;
|
||||||
|
private System.Windows.Forms.ToolStripMenuItem employeesToolStripMenuItem;
|
||||||
|
}
|
||||||
|
}
|
89
ProjectAirline/Forms/FormMain.cs
Normal file
89
ProjectAirline/Forms/FormMain.cs
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
using System;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using Unity;
|
||||||
|
|
||||||
|
namespace YourNamespace.Forms
|
||||||
|
{
|
||||||
|
public partial class FormMain : Form
|
||||||
|
{
|
||||||
|
private readonly IUnityContainer _container;
|
||||||
|
|
||||||
|
public FormMain(IUnityContainer container)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_container = container ?? throw new ArgumentNullException(nameof(container));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PassengersToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_container.Resolve<FormPassengers>().ShowDialog();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void EmployeesToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_container.Resolve<FormEmployees>().ShowDialog();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FlightsToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_container.Resolve<FormFlights>().ShowDialog();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PlanesToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_container.Resolve<FormPlanes>().ShowDialog();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void TicketsToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_container.Resolve<FormTickets>().ShowDialog();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AirportsToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_container.Resolve<FormAirports>().ShowDialog();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
120
ProjectAirline/Forms/FormMain.resx
Normal file
120
ProjectAirline/Forms/FormMain.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
140
ProjectAirline/Forms/FormPassenger.Designer.cs
generated
Normal file
140
ProjectAirline/Forms/FormPassenger.Designer.cs
generated
Normal file
@ -0,0 +1,140 @@
|
|||||||
|
namespace YourNamespace.Forms
|
||||||
|
{
|
||||||
|
partial class FormPassenger
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
this.labelFirstName = new System.Windows.Forms.Label();
|
||||||
|
this.labelLastName = new System.Windows.Forms.Label();
|
||||||
|
this.labelPassportNumber = new System.Windows.Forms.Label();
|
||||||
|
this.textBoxFirstName = new System.Windows.Forms.TextBox();
|
||||||
|
this.textBoxLastName = new System.Windows.Forms.TextBox();
|
||||||
|
this.textBoxPassportNumber = new System.Windows.Forms.TextBox();
|
||||||
|
this.buttonSave = new System.Windows.Forms.Button();
|
||||||
|
this.buttonCancel = new System.Windows.Forms.Button();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// labelFirstName
|
||||||
|
//
|
||||||
|
this.labelFirstName.AutoSize = true;
|
||||||
|
this.labelFirstName.Location = new System.Drawing.Point(12, 22);
|
||||||
|
this.labelFirstName.Name = "labelFirstName";
|
||||||
|
this.labelFirstName.Size = new System.Drawing.Size(32, 13);
|
||||||
|
this.labelFirstName.TabIndex = 0;
|
||||||
|
this.labelFirstName.Text = "Имя:";
|
||||||
|
//
|
||||||
|
// labelLastName
|
||||||
|
//
|
||||||
|
this.labelLastName.AutoSize = true;
|
||||||
|
this.labelLastName.Location = new System.Drawing.Point(12, 58);
|
||||||
|
this.labelLastName.Name = "labelLastName";
|
||||||
|
this.labelLastName.Size = new System.Drawing.Size(59, 13);
|
||||||
|
this.labelLastName.TabIndex = 1;
|
||||||
|
this.labelLastName.Text = "Фамилия:";
|
||||||
|
//
|
||||||
|
// labelPassportNumber
|
||||||
|
//
|
||||||
|
this.labelPassportNumber.AutoSize = true;
|
||||||
|
this.labelPassportNumber.Location = new System.Drawing.Point(12, 94);
|
||||||
|
this.labelPassportNumber.Name = "labelPassportNumber";
|
||||||
|
this.labelPassportNumber.Size = new System.Drawing.Size(93, 13);
|
||||||
|
this.labelPassportNumber.TabIndex = 2;
|
||||||
|
this.labelPassportNumber.Text = "Номер паспорта:";
|
||||||
|
//
|
||||||
|
// textBoxFirstName
|
||||||
|
//
|
||||||
|
this.textBoxFirstName.Location = new System.Drawing.Point(111, 19);
|
||||||
|
this.textBoxFirstName.Name = "textBoxFirstName";
|
||||||
|
this.textBoxFirstName.Size = new System.Drawing.Size(200, 20);
|
||||||
|
this.textBoxFirstName.TabIndex = 3;
|
||||||
|
//
|
||||||
|
// textBoxLastName
|
||||||
|
//
|
||||||
|
this.textBoxLastName.Location = new System.Drawing.Point(111, 55);
|
||||||
|
this.textBoxLastName.Name = "textBoxLastName";
|
||||||
|
this.textBoxLastName.Size = new System.Drawing.Size(200, 20);
|
||||||
|
this.textBoxLastName.TabIndex = 4;
|
||||||
|
//
|
||||||
|
// textBoxPassportNumber
|
||||||
|
//
|
||||||
|
this.textBoxPassportNumber.Location = new System.Drawing.Point(111, 91);
|
||||||
|
this.textBoxPassportNumber.Name = "textBoxPassportNumber";
|
||||||
|
this.textBoxPassportNumber.Size = new System.Drawing.Size(200, 20);
|
||||||
|
this.textBoxPassportNumber.TabIndex = 5;
|
||||||
|
//
|
||||||
|
// buttonSave
|
||||||
|
//
|
||||||
|
this.buttonSave.Location = new System.Drawing.Point(155, 128);
|
||||||
|
this.buttonSave.Name = "buttonSave";
|
||||||
|
this.buttonSave.Size = new System.Drawing.Size(75, 23);
|
||||||
|
this.buttonSave.TabIndex = 6;
|
||||||
|
this.buttonSave.Text = "Сохранить";
|
||||||
|
this.buttonSave.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
|
||||||
|
//
|
||||||
|
// buttonCancel
|
||||||
|
//
|
||||||
|
this.buttonCancel.Location = new System.Drawing.Point(236, 128);
|
||||||
|
this.buttonCancel.Name = "buttonCancel";
|
||||||
|
this.buttonCancel.Size = new System.Drawing.Size(75, 23);
|
||||||
|
this.buttonCancel.TabIndex = 7;
|
||||||
|
this.buttonCancel.Text = "Отмена";
|
||||||
|
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
|
||||||
|
//
|
||||||
|
// FormPassenger
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(324, 166);
|
||||||
|
this.Controls.Add(this.buttonCancel);
|
||||||
|
this.Controls.Add(this.buttonSave);
|
||||||
|
this.Controls.Add(this.textBoxPassportNumber);
|
||||||
|
this.Controls.Add(this.textBoxLastName);
|
||||||
|
this.Controls.Add(this.textBoxFirstName);
|
||||||
|
this.Controls.Add(this.labelPassportNumber);
|
||||||
|
this.Controls.Add(this.labelLastName);
|
||||||
|
this.Controls.Add(this.labelFirstName);
|
||||||
|
this.Name = "FormPassenger";
|
||||||
|
this.Text = "Редактирование пассажира";
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
this.PerformLayout();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private System.Windows.Forms.Label labelFirstName;
|
||||||
|
private System.Windows.Forms.Label labelLastName;
|
||||||
|
private System.Windows.Forms.Label labelPassportNumber;
|
||||||
|
private System.Windows.Forms.TextBox textBoxFirstName;
|
||||||
|
private System.Windows.Forms.TextBox textBoxLastName;
|
||||||
|
private System.Windows.Forms.TextBox textBoxPassportNumber;
|
||||||
|
private System.Windows.Forms.Button buttonSave;
|
||||||
|
private System.Windows.Forms.Button buttonCancel;
|
||||||
|
}
|
||||||
|
}
|
71
ProjectAirline/Forms/FormPassenger.cs
Normal file
71
ProjectAirline/Forms/FormPassenger.cs
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
using System;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using YourNamespace.Entities;
|
||||||
|
using YourNamespace.Repositories;
|
||||||
|
|
||||||
|
namespace YourNamespace.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));
|
||||||
|
}
|
||||||
|
textBoxFirstName.Text = passenger.FirstName;
|
||||||
|
textBoxLastName.Text = passenger.LastName;
|
||||||
|
textBoxPassportNumber.Text = passenger.PassportNumber;
|
||||||
|
_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));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonSave_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(textBoxFirstName.Text) || string.IsNullOrWhiteSpace(textBoxLastName.Text) || string.IsNullOrWhiteSpace(textBoxPassportNumber.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) => Passenger.CreateEntity(id, textBoxFirstName.Text, textBoxLastName.Text, textBoxPassportNumber.Text);
|
||||||
|
}
|
||||||
|
}
|
120
ProjectAirline/Forms/FormPassenger.resx
Normal file
120
ProjectAirline/Forms/FormPassenger.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
106
ProjectAirline/Forms/FormPassengers.Designer.cs
generated
Normal file
106
ProjectAirline/Forms/FormPassengers.Designer.cs
generated
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
namespace YourNamespace.Forms
|
||||||
|
{
|
||||||
|
partial class FormPassengers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
this.dataGridViewData = new System.Windows.Forms.DataGridView();
|
||||||
|
this.buttonAdd = new System.Windows.Forms.Button();
|
||||||
|
this.buttonUpd = new System.Windows.Forms.Button();
|
||||||
|
this.buttonDel = new System.Windows.Forms.Button();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.dataGridViewData)).BeginInit();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// dataGridViewData
|
||||||
|
//
|
||||||
|
this.dataGridViewData.AllowUserToAddRows = false;
|
||||||
|
this.dataGridViewData.AllowUserToDeleteRows = false;
|
||||||
|
this.dataGridViewData.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
|
this.dataGridViewData.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
|
this.dataGridViewData.Location = new System.Drawing.Point(0, 0);
|
||||||
|
this.dataGridViewData.MultiSelect = false;
|
||||||
|
this.dataGridViewData.Name = "dataGridViewData";
|
||||||
|
this.dataGridViewData.ReadOnly = true;
|
||||||
|
this.dataGridViewData.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
|
||||||
|
this.dataGridViewData.Size = new System.Drawing.Size(800, 450);
|
||||||
|
this.dataGridViewData.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// buttonAdd
|
||||||
|
//
|
||||||
|
this.buttonAdd.Location = new System.Drawing.Point(12, 12);
|
||||||
|
this.buttonAdd.Name = "buttonAdd";
|
||||||
|
this.buttonAdd.Size = new System.Drawing.Size(75, 23);
|
||||||
|
this.buttonAdd.TabIndex = 1;
|
||||||
|
this.buttonAdd.Text = "Добавить";
|
||||||
|
this.buttonAdd.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
|
||||||
|
//
|
||||||
|
// buttonUpd
|
||||||
|
//
|
||||||
|
this.buttonUpd.Location = new System.Drawing.Point(93, 12);
|
||||||
|
this.buttonUpd.Name = "buttonUpd";
|
||||||
|
this.buttonUpd.Size = new System.Drawing.Size(75, 23);
|
||||||
|
this.buttonUpd.TabIndex = 2;
|
||||||
|
this.buttonUpd.Text = "Изменить";
|
||||||
|
this.buttonUpd.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click);
|
||||||
|
//
|
||||||
|
// buttonDel
|
||||||
|
//
|
||||||
|
this.buttonDel.Location = new System.Drawing.Point(174, 12);
|
||||||
|
this.buttonDel.Name = "buttonDel";
|
||||||
|
this.buttonDel.Size = new System.Drawing.Size(75, 23);
|
||||||
|
this.buttonDel.TabIndex = 3;
|
||||||
|
this.buttonDel.Text = "Удалить";
|
||||||
|
this.buttonDel.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click);
|
||||||
|
//
|
||||||
|
// FormPassengers
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||||
|
this.Controls.Add(this.buttonDel);
|
||||||
|
this.Controls.Add(this.buttonUpd);
|
||||||
|
this.Controls.Add(this.buttonAdd);
|
||||||
|
this.Controls.Add(this.dataGridViewData);
|
||||||
|
this.Name = "FormPassengers";
|
||||||
|
this.Text = "Пассажиры";
|
||||||
|
this.Load += new System.EventHandler(this.FormPassengers_Load);
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.dataGridViewData)).EndInit();
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private System.Windows.Forms.DataGridView dataGridViewData;
|
||||||
|
private System.Windows.Forms.Button buttonAdd;
|
||||||
|
private System.Windows.Forms.Button buttonUpd;
|
||||||
|
private System.Windows.Forms.Button buttonDel;
|
||||||
|
}
|
||||||
|
}
|
99
ProjectAirline/Forms/FormPassengers.cs
Normal file
99
ProjectAirline/Forms/FormPassengers.cs
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
using System;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using Unity;
|
||||||
|
using YourNamespace.Repositories;
|
||||||
|
|
||||||
|
namespace YourNamespace.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<FormPassenger>().ShowDialog();
|
||||||
|
LoadList();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonUpd_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var form = _container.Resolve<FormPassenger>();
|
||||||
|
form.Id = findId;
|
||||||
|
form.ShowDialog();
|
||||||
|
LoadList();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonDel_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_passengerRepository.DeletePassenger(findId);
|
||||||
|
LoadList();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadList() => dataGridViewData.DataSource = _passengerRepository.ReadPassengers();
|
||||||
|
|
||||||
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
|
{
|
||||||
|
id = 0;
|
||||||
|
if (dataGridViewData.SelectedRows.Count < 1)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
id = Convert.ToInt32(dataGridViewData.SelectedRows[0].Cells["Id"].Value);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
120
ProjectAirline/Forms/FormPassengers.resx
Normal file
120
ProjectAirline/Forms/FormPassengers.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
120
ProjectAirline/Forms/FormPlane.Designer.cs
generated
Normal file
120
ProjectAirline/Forms/FormPlane.Designer.cs
generated
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
namespace YourNamespace.Forms
|
||||||
|
{
|
||||||
|
partial class FormPlane
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
this.labelModel = new System.Windows.Forms.Label();
|
||||||
|
this.labelCapacity = new System.Windows.Forms.Label();
|
||||||
|
this.textBoxModel = new System.Windows.Forms.TextBox();
|
||||||
|
this.numericUpDownCapacity = new System.Windows.Forms.NumericUpDown();
|
||||||
|
this.buttonSave = new System.Windows.Forms.Button();
|
||||||
|
this.buttonCancel = new System.Windows.Forms.Button();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.numericUpDownCapacity)).BeginInit();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// labelModel
|
||||||
|
//
|
||||||
|
this.labelModel.AutoSize = true;
|
||||||
|
this.labelModel.Location = new System.Drawing.Point(12, 22);
|
||||||
|
this.labelModel.Name = "labelModel";
|
||||||
|
this.labelModel.Size = new System.Drawing.Size(54, 13);
|
||||||
|
this.labelModel.TabIndex = 0;
|
||||||
|
this.labelModel.Text = "Модель:";
|
||||||
|
//
|
||||||
|
// labelCapacity
|
||||||
|
//
|
||||||
|
this.labelCapacity.AutoSize = true;
|
||||||
|
this.labelCapacity.Location = new System.Drawing.Point(12, 58);
|
||||||
|
this.labelCapacity.Name = "labelCapacity";
|
||||||
|
this.labelCapacity.Size = new System.Drawing.Size(72, 13);
|
||||||
|
this.labelCapacity.TabIndex = 1;
|
||||||
|
this.labelCapacity.Text = "Вместимость:";
|
||||||
|
//
|
||||||
|
// textBoxModel
|
||||||
|
//
|
||||||
|
this.textBoxModel.Location = new System.Drawing.Point(111, 19);
|
||||||
|
this.textBoxModel.Name = "textBoxModel";
|
||||||
|
this.textBoxModel.Size = new System.Drawing.Size(200, 20);
|
||||||
|
this.textBoxModel.TabIndex = 2;
|
||||||
|
//
|
||||||
|
// numericUpDownCapacity
|
||||||
|
//
|
||||||
|
this.numericUpDownCapacity.Location = new System.Drawing.Point(111, 56);
|
||||||
|
this.numericUpDownCapacity.Name = "numericUpDownCapacity";
|
||||||
|
this.numericUpDownCapacity.Size = new System.Drawing.Size(200, 20);
|
||||||
|
this.numericUpDownCapacity.TabIndex = 3;
|
||||||
|
//
|
||||||
|
// buttonSave
|
||||||
|
//
|
||||||
|
this.buttonSave.Location = new System.Drawing.Point(155, 91);
|
||||||
|
this.buttonSave.Name = "buttonSave";
|
||||||
|
this.buttonSave.Size = new System.Drawing.Size(75, 23);
|
||||||
|
this.buttonSave.TabIndex = 4;
|
||||||
|
this.buttonSave.Text = "Сохранить";
|
||||||
|
this.buttonSave.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
|
||||||
|
//
|
||||||
|
// buttonCancel
|
||||||
|
//
|
||||||
|
this.buttonCancel.Location = new System.Drawing.Point(236, 91);
|
||||||
|
this.buttonCancel.Name = "buttonCancel";
|
||||||
|
this.buttonCancel.Size = new System.Drawing.Size(75, 23);
|
||||||
|
this.buttonCancel.TabIndex = 5;
|
||||||
|
this.buttonCancel.Text = "Отмена";
|
||||||
|
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
|
||||||
|
//
|
||||||
|
// FormPlane
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(324, 126);
|
||||||
|
this.Controls.Add(this.buttonCancel);
|
||||||
|
this.Controls.Add(this.buttonSave);
|
||||||
|
this.Controls.Add(this.numericUpDownCapacity);
|
||||||
|
this.Controls.Add(this.textBoxModel);
|
||||||
|
this.Controls.Add(this.labelCapacity);
|
||||||
|
this.Controls.Add(this.labelModel);
|
||||||
|
this.Name = "FormPlane";
|
||||||
|
this.Text = "Редактирование самолета";
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.numericUpDownCapacity)).EndInit();
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
this.PerformLayout();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private System.Windows.Forms.Label labelModel;
|
||||||
|
private System.Windows.Forms.Label labelCapacity;
|
||||||
|
private System.Windows.Forms.TextBox textBoxModel;
|
||||||
|
private System.Windows.Forms.NumericUpDown numericUpDownCapacity;
|
||||||
|
private System.Windows.Forms.Button buttonSave;
|
||||||
|
private System.Windows.Forms.Button buttonCancel;
|
||||||
|
}
|
||||||
|
}
|
70
ProjectAirline/Forms/FormPlane.cs
Normal file
70
ProjectAirline/Forms/FormPlane.cs
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
using System;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using YourNamespace.Entities;
|
||||||
|
using YourNamespace.Repositories;
|
||||||
|
|
||||||
|
namespace YourNamespace.Forms
|
||||||
|
{
|
||||||
|
public partial class FormPlane : Form
|
||||||
|
{
|
||||||
|
private readonly IPlaneRepository _planeRepository;
|
||||||
|
private int? _planeId;
|
||||||
|
|
||||||
|
public int Id
|
||||||
|
{
|
||||||
|
set
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var plane = _planeRepository.ReadPlaneById(value);
|
||||||
|
if (plane == null)
|
||||||
|
{
|
||||||
|
throw new InvalidDataException(nameof(plane));
|
||||||
|
}
|
||||||
|
textBoxModel.Text = plane.Model;
|
||||||
|
numericUpDownCapacity.Value = plane.Capacity;
|
||||||
|
_planeId = value;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public FormPlane(IPlaneRepository planeRepository)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_planeRepository = planeRepository ?? throw new ArgumentNullException(nameof(planeRepository));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonSave_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(textBoxModel.Text))
|
||||||
|
{
|
||||||
|
throw new Exception("Имеются незаполненные поля");
|
||||||
|
}
|
||||||
|
if (_planeId.HasValue)
|
||||||
|
{
|
||||||
|
_planeRepository.UpdatePlane(CreatePlane(_planeId.Value));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_planeRepository.CreatePlane(CreatePlane(0));
|
||||||
|
}
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
|
||||||
|
|
||||||
|
private Plane CreatePlane(int id) => Plane.CreateEntity(id, textBoxModel.Text, (int)numericUpDownCapacity.Value);
|
||||||
|
}
|
||||||
|
}
|
120
ProjectAirline/Forms/FormPlane.resx
Normal file
120
ProjectAirline/Forms/FormPlane.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
106
ProjectAirline/Forms/FormPlanes.Designer.cs
generated
Normal file
106
ProjectAirline/Forms/FormPlanes.Designer.cs
generated
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
namespace YourNamespace.Forms
|
||||||
|
{
|
||||||
|
partial class FormPlanes
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
this.dataGridViewData = new System.Windows.Forms.DataGridView();
|
||||||
|
this.buttonAdd = new System.Windows.Forms.Button();
|
||||||
|
this.buttonUpd = new System.Windows.Forms.Button();
|
||||||
|
this.buttonDel = new System.Windows.Forms.Button();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.dataGridViewData)).BeginInit();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// dataGridViewData
|
||||||
|
//
|
||||||
|
this.dataGridViewData.AllowUserToAddRows = false;
|
||||||
|
this.dataGridViewData.AllowUserToDeleteRows = false;
|
||||||
|
this.dataGridViewData.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
|
this.dataGridViewData.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
|
this.dataGridViewData.Location = new System.Drawing.Point(0, 0);
|
||||||
|
this.dataGridViewData.MultiSelect = false;
|
||||||
|
this.dataGridViewData.Name = "dataGridViewData";
|
||||||
|
this.dataGridViewData.ReadOnly = true;
|
||||||
|
this.dataGridViewData.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
|
||||||
|
this.dataGridViewData.Size = new System.Drawing.Size(800, 450);
|
||||||
|
this.dataGridViewData.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// buttonAdd
|
||||||
|
//
|
||||||
|
this.buttonAdd.Location = new System.Drawing.Point(12, 12);
|
||||||
|
this.buttonAdd.Name = "buttonAdd";
|
||||||
|
this.buttonAdd.Size = new System.Drawing.Size(75, 23);
|
||||||
|
this.buttonAdd.TabIndex = 1;
|
||||||
|
this.buttonAdd.Text = "Добавить";
|
||||||
|
this.buttonAdd.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
|
||||||
|
//
|
||||||
|
// buttonUpd
|
||||||
|
//
|
||||||
|
this.buttonUpd.Location = new System.Drawing.Point(93, 12);
|
||||||
|
this.buttonUpd.Name = "buttonUpd";
|
||||||
|
this.buttonUpd.Size = new System.Drawing.Size(75, 23);
|
||||||
|
this.buttonUpd.TabIndex = 2;
|
||||||
|
this.buttonUpd.Text = "Изменить";
|
||||||
|
this.buttonUpd.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click);
|
||||||
|
//
|
||||||
|
// buttonDel
|
||||||
|
//
|
||||||
|
this.buttonDel.Location = new System.Drawing.Point(174, 12);
|
||||||
|
this.buttonDel.Name = "buttonDel";
|
||||||
|
this.buttonDel.Size = new System.Drawing.Size(75, 23);
|
||||||
|
this.buttonDel.TabIndex = 3;
|
||||||
|
this.buttonDel.Text = "Удалить";
|
||||||
|
this.buttonDel.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click);
|
||||||
|
//
|
||||||
|
// FormPlanes
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||||
|
this.Controls.Add(this.buttonDel);
|
||||||
|
this.Controls.Add(this.buttonUpd);
|
||||||
|
this.Controls.Add(this.buttonAdd);
|
||||||
|
this.Controls.Add(this.dataGridViewData);
|
||||||
|
this.Name = "FormPlanes";
|
||||||
|
this.Text = "Самолеты";
|
||||||
|
this.Load += new System.EventHandler(this.FormPlanes_Load);
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.dataGridViewData)).EndInit();
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private System.Windows.Forms.DataGridView dataGridViewData;
|
||||||
|
private System.Windows.Forms.Button buttonAdd;
|
||||||
|
private System.Windows.Forms.Button buttonUpd;
|
||||||
|
private System.Windows.Forms.Button buttonDel;
|
||||||
|
}
|
||||||
|
}
|
99
ProjectAirline/Forms/FormPlanes.cs
Normal file
99
ProjectAirline/Forms/FormPlanes.cs
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
using System;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using Unity;
|
||||||
|
using YourNamespace.Repositories;
|
||||||
|
|
||||||
|
namespace YourNamespace.Forms
|
||||||
|
{
|
||||||
|
public partial class FormPlanes : Form
|
||||||
|
{
|
||||||
|
private readonly IUnityContainer _container;
|
||||||
|
private readonly IPlaneRepository _planeRepository;
|
||||||
|
|
||||||
|
public FormPlanes(IUnityContainer container, IPlaneRepository planeRepository)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_container = container ?? throw new ArgumentNullException(nameof(container));
|
||||||
|
_planeRepository = planeRepository ?? throw new ArgumentNullException(nameof(planeRepository));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FormPlanes_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<FormPlane>().ShowDialog();
|
||||||
|
LoadList();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonUpd_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var form = _container.Resolve<FormPlane>();
|
||||||
|
form.Id = findId;
|
||||||
|
form.ShowDialog();
|
||||||
|
LoadList();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonDel_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_planeRepository.DeletePlane(findId);
|
||||||
|
LoadList();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadList() => dataGridViewData.DataSource = _planeRepository.ReadPlanes();
|
||||||
|
|
||||||
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
|
{
|
||||||
|
id = 0;
|
||||||
|
if (dataGridViewData.SelectedRows.Count < 1)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
id = Convert.ToInt32(dataGridViewData.SelectedRows[0].Cells["Id"].Value);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
120
ProjectAirline/Forms/FormPlanes.resx
Normal file
120
ProjectAirline/Forms/FormPlanes.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
166
ProjectAirline/Forms/FormTicket.Designer.cs
generated
Normal file
166
ProjectAirline/Forms/FormTicket.Designer.cs
generated
Normal file
@ -0,0 +1,166 @@
|
|||||||
|
namespace YourNamespace.Forms
|
||||||
|
{
|
||||||
|
partial class FormTicket
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
this.labelPassenger = new System.Windows.Forms.Label();
|
||||||
|
this.labelFlight = new System.Windows.Forms.Label();
|
||||||
|
this.labelDateBuy = new System.Windows.Forms.Label();
|
||||||
|
this.labelTicketPrice = new System.Windows.Forms.Label();
|
||||||
|
this.comboBoxPassenger = new System.Windows.Forms.ComboBox();
|
||||||
|
this.comboBoxFlight = new System.Windows.Forms.ComboBox();
|
||||||
|
this.dateTimePickerDateBuy = new System.Windows.Forms.DateTimePicker();
|
||||||
|
this.numericUpDownTicketPrice = new System.Windows.Forms.NumericUpDown();
|
||||||
|
this.buttonSave = new System.Windows.Forms.Button();
|
||||||
|
this.buttonCancel = new System.Windows.Forms.Button();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.numericUpDownTicketPrice)).BeginInit();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// labelPassenger
|
||||||
|
//
|
||||||
|
this.labelPassenger.AutoSize = true;
|
||||||
|
this.labelPassenger.Location = new System.Drawing.Point(12, 22);
|
||||||
|
this.labelPassenger.Name = "labelPassenger";
|
||||||
|
this.labelPassenger.Size = new System.Drawing.Size(63, 13);
|
||||||
|
this.labelPassenger.TabIndex = 0;
|
||||||
|
this.labelPassenger.Text = "Пассажир:";
|
||||||
|
//
|
||||||
|
// labelFlight
|
||||||
|
//
|
||||||
|
this.labelFlight.AutoSize = true;
|
||||||
|
this.labelFlight.Location = new System.Drawing.Point(12, 58);
|
||||||
|
this.labelFlight.Name = "labelFlight";
|
||||||
|
this.labelFlight.Size = new System.Drawing.Size(37, 13);
|
||||||
|
this.labelFlight.TabIndex = 1;
|
||||||
|
this.labelFlight.Text = "Рейс:";
|
||||||
|
//
|
||||||
|
// labelDateBuy
|
||||||
|
//
|
||||||
|
this.labelDateBuy.AutoSize = true;
|
||||||
|
this.labelDateBuy.Location = new System.Drawing.Point(12, 94);
|
||||||
|
this.labelDateBuy.Name = "labelDateBuy";
|
||||||
|
this.labelDateBuy.Size = new System.Drawing.Size(80, 13);
|
||||||
|
this.labelDateBuy.TabIndex = 2;
|
||||||
|
this.labelDateBuy.Text = "Дата покупки:";
|
||||||
|
//
|
||||||
|
// labelTicketPrice
|
||||||
|
//
|
||||||
|
this.labelTicketPrice.AutoSize = true;
|
||||||
|
this.labelTicketPrice.Location = new System.Drawing.Point(12, 130);
|
||||||
|
this.labelTicketPrice.Name = "labelTicketPrice";
|
||||||
|
this.labelTicketPrice.Size = new System.Drawing.Size(74, 13);
|
||||||
|
this.labelTicketPrice.TabIndex = 3;
|
||||||
|
this.labelTicketPrice.Text = "Цена билета:";
|
||||||
|
//
|
||||||
|
// comboBoxPassenger
|
||||||
|
//
|
||||||
|
this.comboBoxPassenger.FormattingEnabled = true;
|
||||||
|
this.comboBoxPassenger.Location = new System.Drawing.Point(111, 19);
|
||||||
|
this.comboBoxPassenger.Name = "comboBoxPassenger";
|
||||||
|
this.comboBoxPassenger.Size = new System.Drawing.Size(200, 21);
|
||||||
|
this.comboBoxPassenger.TabIndex = 4;
|
||||||
|
//
|
||||||
|
// comboBoxFlight
|
||||||
|
//
|
||||||
|
this.comboBoxFlight.FormattingEnabled = true;
|
||||||
|
this.comboBoxFlight.Location = new System.Drawing.Point(111, 55);
|
||||||
|
this.comboBoxFlight.Name = "comboBoxFlight";
|
||||||
|
this.comboBoxFlight.Size = new System.Drawing.Size(200, 21);
|
||||||
|
this.comboBoxFlight.TabIndex = 5;
|
||||||
|
//
|
||||||
|
// dateTimePickerDateBuy
|
||||||
|
//
|
||||||
|
this.dateTimePickerDateBuy.Location = new System.Drawing.Point(111, 91);
|
||||||
|
this.dateTimePickerDateBuy.Name = "dateTimePickerDateBuy";
|
||||||
|
this.dateTimePickerDateBuy.Size = new System.Drawing.Size(200, 20);
|
||||||
|
this.dateTimePickerDateBuy.TabIndex = 6;
|
||||||
|
//
|
||||||
|
// numericUpDownTicketPrice
|
||||||
|
//
|
||||||
|
this.numericUpDownTicketPrice.Location = new System.Drawing.Point(111, 128);
|
||||||
|
this.numericUpDownTicketPrice.Name = "numericUpDownTicketPrice";
|
||||||
|
this.numericUpDownTicketPrice.Size = new System.Drawing.Size(200, 20);
|
||||||
|
this.numericUpDownTicketPrice.TabIndex = 7;
|
||||||
|
//
|
||||||
|
// buttonSave
|
||||||
|
//
|
||||||
|
this.buttonSave.Location = new System.Drawing.Point(155, 164);
|
||||||
|
this.buttonSave.Name = "buttonSave";
|
||||||
|
this.buttonSave.Size = new System.Drawing.Size(75, 23);
|
||||||
|
this.buttonSave.TabIndex = 8;
|
||||||
|
this.buttonSave.Text = "Сохранить";
|
||||||
|
this.buttonSave.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
|
||||||
|
//
|
||||||
|
// buttonCancel
|
||||||
|
//
|
||||||
|
this.buttonCancel.Location = new System.Drawing.Point(236, 164);
|
||||||
|
this.buttonCancel.Name = "buttonCancel";
|
||||||
|
this.buttonCancel.Size = new System.Drawing.Size(75, 23);
|
||||||
|
this.buttonCancel.TabIndex = 9;
|
||||||
|
this.buttonCancel.Text = "Отмена";
|
||||||
|
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
|
||||||
|
//
|
||||||
|
// FormTicket
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(324, 201);
|
||||||
|
this.Controls.Add(this.buttonCancel);
|
||||||
|
this.Controls.Add(this.buttonSave);
|
||||||
|
this.Controls.Add(this.numericUpDownTicketPrice);
|
||||||
|
this.Controls.Add(this.dateTimePickerDateBuy);
|
||||||
|
this.Controls.Add(this.comboBoxFlight);
|
||||||
|
this.Controls.Add(this.comboBoxPassenger);
|
||||||
|
this.Controls.Add(this.labelTicketPrice);
|
||||||
|
this.Controls.Add(this.labelDateBuy);
|
||||||
|
this.Controls.Add(this.labelFlight);
|
||||||
|
this.Controls.Add(this.labelPassenger);
|
||||||
|
this.Name = "FormTicket";
|
||||||
|
this.Text = "Редактирование билета";
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.numericUpDownTicketPrice)).EndInit();
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
this.PerformLayout();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private System.Windows.Forms.Label labelPassenger;
|
||||||
|
private System.Windows.Forms.Label labelFlight;
|
||||||
|
private System.Windows.Forms.Label labelDateBuy;
|
||||||
|
private System.Windows.Forms.Label labelTicketPrice;
|
||||||
|
private System.Windows.Forms.ComboBox comboBoxPassenger;
|
||||||
|
private System.Windows.Forms.ComboBox comboBoxFlight;
|
||||||
|
private System.Windows.Forms.DateTimePicker dateTimePickerDateBuy;
|
||||||
|
private System.Windows.Forms.NumericUpDown numericUpDownTicketPrice;
|
||||||
|
private System.Windows.Forms.Button buttonSave;
|
||||||
|
private System.Windows.Forms.Button buttonCancel;
|
||||||
|
}
|
||||||
|
}
|
84
ProjectAirline/Forms/FormTicket.cs
Normal file
84
ProjectAirline/Forms/FormTicket.cs
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
using System;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using YourNamespace.Entities;
|
||||||
|
using YourNamespace.Repositories;
|
||||||
|
|
||||||
|
namespace YourNamespace.Forms
|
||||||
|
{
|
||||||
|
public partial class FormTicket : Form
|
||||||
|
{
|
||||||
|
private readonly ITicketRepository _ticketRepository;
|
||||||
|
private readonly IPassengerRepository _passengerRepository;
|
||||||
|
private readonly IFlightRepository _flightRepository;
|
||||||
|
private int? _ticketId;
|
||||||
|
|
||||||
|
public int Id
|
||||||
|
{
|
||||||
|
set
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var ticket = _ticketRepository.ReadTicketById(value);
|
||||||
|
if (ticket == null)
|
||||||
|
{
|
||||||
|
throw new InvalidDataException(nameof(ticket));
|
||||||
|
}
|
||||||
|
comboBoxPassenger.SelectedValue = ticket.PassengerId;
|
||||||
|
comboBoxFlight.SelectedValue = ticket.FlightId;
|
||||||
|
dateTimePickerDateBuy.Value = ticket.DateBuy;
|
||||||
|
numericUpDownTicketPrice.Value = ticket.TicketPrice;
|
||||||
|
_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));
|
||||||
|
_passengerRepository = passengerRepository ?? throw new ArgumentNullException(nameof(passengerRepository));
|
||||||
|
_flightRepository = flightRepository ?? throw new ArgumentNullException(nameof(flightRepository));
|
||||||
|
|
||||||
|
comboBoxPassenger.DataSource = _passengerRepository.ReadPassengers();
|
||||||
|
comboBoxPassenger.DisplayMember = "Name";
|
||||||
|
comboBoxPassenger.ValueMember = "Id";
|
||||||
|
|
||||||
|
comboBoxFlight.DataSource = _flightRepository.ReadFlights();
|
||||||
|
comboBoxFlight.DisplayMember = "FlightNumber";
|
||||||
|
comboBoxFlight.ValueMember = "Id";
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonSave_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (comboBoxPassenger.SelectedIndex < 0 || comboBoxFlight.SelectedIndex < 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.CreateEntity(id, (int)comboBoxPassenger.SelectedValue, (int)comboBoxFlight.SelectedValue, dateTimePickerDateBuy.Value, (int)numericUpDownTicketPrice.Value);
|
||||||
|
}
|
||||||
|
}
|
120
ProjectAirline/Forms/FormTicket.resx
Normal file
120
ProjectAirline/Forms/FormTicket.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
106
ProjectAirline/Forms/FormTickets.Designer.cs
generated
Normal file
106
ProjectAirline/Forms/FormTickets.Designer.cs
generated
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
namespace YourNamespace.Forms
|
||||||
|
{
|
||||||
|
partial class FormTickets
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
this.dataGridViewData = new System.Windows.Forms.DataGridView();
|
||||||
|
this.buttonAdd = new System.Windows.Forms.Button();
|
||||||
|
this.buttonUpd = new System.Windows.Forms.Button();
|
||||||
|
this.buttonDel = new System.Windows.Forms.Button();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.dataGridViewData)).BeginInit();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// dataGridViewData
|
||||||
|
//
|
||||||
|
this.dataGridViewData.AllowUserToAddRows = false;
|
||||||
|
this.dataGridViewData.AllowUserToDeleteRows = false;
|
||||||
|
this.dataGridViewData.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
|
this.dataGridViewData.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
|
this.dataGridViewData.Location = new System.Drawing.Point(0, 0);
|
||||||
|
this.dataGridViewData.MultiSelect = false;
|
||||||
|
this.dataGridViewData.Name = "dataGridViewData";
|
||||||
|
this.dataGridViewData.ReadOnly = true;
|
||||||
|
this.dataGridViewData.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
|
||||||
|
this.dataGridViewData.Size = new System.Drawing.Size(800, 450);
|
||||||
|
this.dataGridViewData.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// buttonAdd
|
||||||
|
//
|
||||||
|
this.buttonAdd.Location = new System.Drawing.Point(12, 12);
|
||||||
|
this.buttonAdd.Name = "buttonAdd";
|
||||||
|
this.buttonAdd.Size = new System.Drawing.Size(75, 23);
|
||||||
|
this.buttonAdd.TabIndex = 1;
|
||||||
|
this.buttonAdd.Text = "Добавить";
|
||||||
|
this.buttonAdd.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
|
||||||
|
//
|
||||||
|
// buttonUpd
|
||||||
|
//
|
||||||
|
this.buttonUpd.Location = new System.Drawing.Point(93, 12);
|
||||||
|
this.buttonUpd.Name = "buttonUpd";
|
||||||
|
this.buttonUpd.Size = new System.Drawing.Size(75, 23);
|
||||||
|
this.buttonUpd.TabIndex = 2;
|
||||||
|
this.buttonUpd.Text = "Изменить";
|
||||||
|
this.buttonUpd.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click);
|
||||||
|
//
|
||||||
|
// buttonDel
|
||||||
|
//
|
||||||
|
this.buttonDel.Location = new System.Drawing.Point(174, 12);
|
||||||
|
this.buttonDel.Name = "buttonDel";
|
||||||
|
this.buttonDel.Size = new System.Drawing.Size(75, 23);
|
||||||
|
this.buttonDel.TabIndex = 3;
|
||||||
|
this.buttonDel.Text = "Удалить";
|
||||||
|
this.buttonDel.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click);
|
||||||
|
//
|
||||||
|
// FormTickets
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||||
|
this.Controls.Add(this.buttonDel);
|
||||||
|
this.Controls.Add(this.buttonUpd);
|
||||||
|
this.Controls.Add(this.buttonAdd);
|
||||||
|
this.Controls.Add(this.dataGridViewData);
|
||||||
|
this.Name = "FormTickets";
|
||||||
|
this.Text = "Билеты";
|
||||||
|
this.Load += new System.EventHandler(this.FormTickets_Load);
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.dataGridViewData)).EndInit();
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private System.Windows.Forms.DataGridView dataGridViewData;
|
||||||
|
private System.Windows.Forms.Button buttonAdd;
|
||||||
|
private System.Windows.Forms.Button buttonUpd;
|
||||||
|
private System.Windows.Forms.Button buttonDel;
|
||||||
|
}
|
||||||
|
}
|
99
ProjectAirline/Forms/FormTickets.cs
Normal file
99
ProjectAirline/Forms/FormTickets.cs
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
using System;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using Unity;
|
||||||
|
using YourNamespace.Repositories;
|
||||||
|
|
||||||
|
namespace YourNamespace.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<FormTicket>().ShowDialog();
|
||||||
|
LoadList();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonUpd_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var form = _container.Resolve<FormTicket>();
|
||||||
|
form.Id = findId;
|
||||||
|
form.ShowDialog();
|
||||||
|
LoadList();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonDel_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_ticketRepository.DeleteTicket(findId);
|
||||||
|
LoadList();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadList() => dataGridViewData.DataSource = _ticketRepository.ReadTickets();
|
||||||
|
|
||||||
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
|
{
|
||||||
|
id = 0;
|
||||||
|
if (dataGridViewData.SelectedRows.Count < 1)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
id = Convert.ToInt32(dataGridViewData.SelectedRows[0].Cells["Id"].Value);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
120
ProjectAirline/Forms/FormTickets.resx
Normal file
120
ProjectAirline/Forms/FormTickets.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
@ -1,6 +1,14 @@
|
|||||||
namespace ProjectAirline
|
using System;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using Unity;
|
||||||
|
using Unity.Lifetime;
|
||||||
|
using YourNamespace.Repositories;
|
||||||
|
using YourNamespace.Repositories.Implementations;
|
||||||
|
using YourNamespace.Forms;
|
||||||
|
|
||||||
|
namespace YourNamespace
|
||||||
{
|
{
|
||||||
internal static class Program
|
static class Program
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The main entry point for the application.
|
/// The main entry point for the application.
|
||||||
@ -8,10 +16,35 @@ namespace ProjectAirline
|
|||||||
[STAThread]
|
[STAThread]
|
||||||
static void Main()
|
static void Main()
|
||||||
{
|
{
|
||||||
// To customize application configuration such as set high DPI settings or default font,
|
Application.EnableVisualStyles();
|
||||||
// see https://aka.ms/applicationconfiguration.
|
Application.SetCompatibleTextRenderingDefault(false);
|
||||||
ApplicationConfiguration.Initialize();
|
|
||||||
Application.Run(new Form1());
|
var container = CreateContainer();
|
||||||
|
Application.Run(container.Resolve<FormMain>());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IUnityContainer CreateContainer()
|
||||||
|
{
|
||||||
|
var container = new UnityContainer();
|
||||||
|
|
||||||
|
// Ðåãèñòðàöèÿ ðåïîçèòîðèåâ
|
||||||
|
container.RegisterType<IPassengerRepository, PassengerRepository>(new TransientLifetimeManager());
|
||||||
|
container.RegisterType<ITicketRepository, TicketRepository>(new TransientLifetimeManager());
|
||||||
|
container.RegisterType<IFlightRepository, FlightRepository>(new TransientLifetimeManager());
|
||||||
|
container.RegisterType<IEmployeeRepository, EmployeeRepository>(new TransientLifetimeManager());
|
||||||
|
container.RegisterType<IPlaneRepository, PlaneRepository>(new TransientLifetimeManager());
|
||||||
|
container.RegisterType<IAirportRepository, AirportRepository>(new TransientLifetimeManager());
|
||||||
|
|
||||||
|
// Ðåãèñòðàöèÿ ôîðì
|
||||||
|
container.RegisterType<FormMain>(new ContainerControlledLifetimeManager());
|
||||||
|
container.RegisterType<FormPassenger>(new TransientLifetimeManager());
|
||||||
|
container.RegisterType<FormTicket>(new TransientLifetimeManager());
|
||||||
|
container.RegisterType<FormFlight>(new TransientLifetimeManager());
|
||||||
|
container.RegisterType<FormEmployee>(new TransientLifetimeManager());
|
||||||
|
container.RegisterType<FormPlane>(new TransientLifetimeManager());
|
||||||
|
container.RegisterType<FormAirport>(new TransientLifetimeManager());
|
||||||
|
|
||||||
|
return container;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -8,4 +8,8 @@
|
|||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Unity" Version="5.11.10" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
14
ProjectAirline/Repositories/IAirportRepository.cs
Normal file
14
ProjectAirline/Repositories/IAirportRepository.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using YourNamespace.Entities;
|
||||||
|
|
||||||
|
namespace YourNamespace.Repositories
|
||||||
|
{
|
||||||
|
public interface IAirportRepository
|
||||||
|
{
|
||||||
|
IEnumerable<Airport> ReadAirports();
|
||||||
|
Airport ReadAirportById(int id);
|
||||||
|
void CreateAirport(Airport airport);
|
||||||
|
void UpdateAirport(Airport airport);
|
||||||
|
void DeleteAirport(int id);
|
||||||
|
}
|
||||||
|
}
|
14
ProjectAirline/Repositories/IEmployeeRepository.cs
Normal file
14
ProjectAirline/Repositories/IEmployeeRepository.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using YourNamespace.Entities;
|
||||||
|
|
||||||
|
namespace YourNamespace.Repositories
|
||||||
|
{
|
||||||
|
public interface IEmployeeRepository
|
||||||
|
{
|
||||||
|
IEnumerable<Employee> ReadEmployees();
|
||||||
|
Employee ReadEmployeeById(int id);
|
||||||
|
void CreateEmployee(Employee employee);
|
||||||
|
void UpdateEmployee(Employee employee);
|
||||||
|
void DeleteEmployee(int id);
|
||||||
|
}
|
||||||
|
}
|
14
ProjectAirline/Repositories/IFlightRepository.cs
Normal file
14
ProjectAirline/Repositories/IFlightRepository.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using YourNamespace.Entities;
|
||||||
|
|
||||||
|
namespace YourNamespace.Repositories
|
||||||
|
{
|
||||||
|
public interface IFlightRepository
|
||||||
|
{
|
||||||
|
IEnumerable<Flight> ReadFlights();
|
||||||
|
Flight ReadFlightById(int id);
|
||||||
|
void CreateFlight(Flight flight);
|
||||||
|
void UpdateFlight(Flight flight);
|
||||||
|
void DeleteFlight(int id);
|
||||||
|
}
|
||||||
|
}
|
14
ProjectAirline/Repositories/IPassengerRepository.cs
Normal file
14
ProjectAirline/Repositories/IPassengerRepository.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using YourNamespace.Entities;
|
||||||
|
|
||||||
|
namespace YourNamespace.Repositories
|
||||||
|
{
|
||||||
|
public interface IPassengerRepository
|
||||||
|
{
|
||||||
|
IEnumerable<Passenger> ReadPassengers();
|
||||||
|
Passenger ReadPassengerById(int id);
|
||||||
|
void CreatePassenger(Passenger passenger);
|
||||||
|
void UpdatePassenger(Passenger passenger);
|
||||||
|
void DeletePassenger(int id);
|
||||||
|
}
|
||||||
|
}
|
14
ProjectAirline/Repositories/IPlaneRepository.cs
Normal file
14
ProjectAirline/Repositories/IPlaneRepository.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using YourNamespace.Entities;
|
||||||
|
|
||||||
|
namespace YourNamespace.Repositories
|
||||||
|
{
|
||||||
|
public interface IPlaneRepository
|
||||||
|
{
|
||||||
|
IEnumerable<Plane> ReadPlanes();
|
||||||
|
Plane ReadPlaneById(int id);
|
||||||
|
void CreatePlane(Plane plane);
|
||||||
|
void UpdatePlane(Plane plane);
|
||||||
|
void DeletePlane(int id);
|
||||||
|
}
|
||||||
|
}
|
14
ProjectAirline/Repositories/ITicketRepository.cs
Normal file
14
ProjectAirline/Repositories/ITicketRepository.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using YourNamespace.Entities;
|
||||||
|
|
||||||
|
namespace YourNamespace.Repositories
|
||||||
|
{
|
||||||
|
public interface ITicketRepository
|
||||||
|
{
|
||||||
|
IEnumerable<Ticket> ReadTickets();
|
||||||
|
Ticket ReadTicketById(int id);
|
||||||
|
void CreateTicket(Ticket ticket);
|
||||||
|
void UpdateTicket(Ticket ticket);
|
||||||
|
void DeleteTicket(int id);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,49 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using YourNamespace.Entities;
|
||||||
|
using YourNamespace.Repositories;
|
||||||
|
|
||||||
|
namespace YourNamespace.Repositories.Implementations
|
||||||
|
{
|
||||||
|
public class AirportRepository : IAirportRepository
|
||||||
|
{
|
||||||
|
private readonly List<Airport> _airports = new List<Airport>();
|
||||||
|
private int _nextId = 1;
|
||||||
|
|
||||||
|
public IEnumerable<Airport> ReadAirports()
|
||||||
|
{
|
||||||
|
return _airports;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Airport ReadAirportById(int id)
|
||||||
|
{
|
||||||
|
return _airports.FirstOrDefault(a => a.Id == id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CreateAirport(Airport airport)
|
||||||
|
{
|
||||||
|
var newAirport = Airport.CreateEntity(_nextId++, airport.Name, airport.Location);
|
||||||
|
_airports.Add(newAirport);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateAirport(Airport airport)
|
||||||
|
{
|
||||||
|
var existingAirport = _airports.FirstOrDefault(a => a.Id == airport.Id);
|
||||||
|
if (existingAirport != null)
|
||||||
|
{
|
||||||
|
var updatedAirport = Airport.CreateEntity(existingAirport.Id, airport.Name, airport.Location);
|
||||||
|
_airports.Remove(existingAirport);
|
||||||
|
_airports.Add(updatedAirport);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DeleteAirport(int id)
|
||||||
|
{
|
||||||
|
var airportToRemove = _airports.FirstOrDefault(a => a.Id == id);
|
||||||
|
if (airportToRemove != null)
|
||||||
|
{
|
||||||
|
_airports.Remove(airportToRemove);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,49 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using YourNamespace.Entities;
|
||||||
|
using YourNamespace.Repositories;
|
||||||
|
|
||||||
|
namespace YourNamespace.Repositories.Implementations
|
||||||
|
{
|
||||||
|
public class EmployeeRepository : IEmployeeRepository
|
||||||
|
{
|
||||||
|
private readonly List<Employee> _employees = new List<Employee>();
|
||||||
|
private int _nextId = 1;
|
||||||
|
|
||||||
|
public IEnumerable<Employee> ReadEmployees()
|
||||||
|
{
|
||||||
|
return _employees;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Employee ReadEmployeeById(int id)
|
||||||
|
{
|
||||||
|
return _employees.FirstOrDefault(e => e.Id == id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CreateEmployee(Employee employee)
|
||||||
|
{
|
||||||
|
var newEmployee = Employee.CreateEntity(_nextId++, employee.FirstName, employee.LastName, employee.EmployeePost);
|
||||||
|
_employees.Add(newEmployee);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateEmployee(Employee employee)
|
||||||
|
{
|
||||||
|
var existingEmployee = _employees.FirstOrDefault(e => e.Id == employee.Id);
|
||||||
|
if (existingEmployee != null)
|
||||||
|
{
|
||||||
|
var updatedEmployee = Employee.CreateEntity(existingEmployee.Id, employee.FirstName, employee.LastName, employee.EmployeePost);
|
||||||
|
_employees.Remove(existingEmployee);
|
||||||
|
_employees.Add(updatedEmployee);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DeleteEmployee(int id)
|
||||||
|
{
|
||||||
|
var employeeToRemove = _employees.FirstOrDefault(e => e.Id == id);
|
||||||
|
if (employeeToRemove != null)
|
||||||
|
{
|
||||||
|
_employees.Remove(employeeToRemove);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,49 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using YourNamespace.Entities;
|
||||||
|
using YourNamespace.Repositories;
|
||||||
|
|
||||||
|
namespace YourNamespace.Repositories.Implementations
|
||||||
|
{
|
||||||
|
public class FlightRepository : IFlightRepository
|
||||||
|
{
|
||||||
|
private readonly List<Flight> _flights = new List<Flight>();
|
||||||
|
private int _nextId = 1;
|
||||||
|
|
||||||
|
public IEnumerable<Flight> ReadFlights()
|
||||||
|
{
|
||||||
|
return _flights;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Flight ReadFlightById(int id)
|
||||||
|
{
|
||||||
|
return _flights.FirstOrDefault(f => f.Id == id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CreateFlight(Flight flight)
|
||||||
|
{
|
||||||
|
var newFlight = Flight.CreateEntity(_nextId++, flight.FlightNumber, flight.DepartureDateTime, flight.ArrivalDateTime, flight.PlaneId, flight.AirportId);
|
||||||
|
_flights.Add(newFlight);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateFlight(Flight flight)
|
||||||
|
{
|
||||||
|
var existingFlight = _flights.FirstOrDefault(f => f.Id == flight.Id);
|
||||||
|
if (existingFlight != null)
|
||||||
|
{
|
||||||
|
var updatedFlight = Flight.CreateEntity(existingFlight.Id, flight.FlightNumber, flight.DepartureDateTime, flight.ArrivalDateTime, flight.PlaneId, flight.AirportId);
|
||||||
|
_flights.Remove(existingFlight);
|
||||||
|
_flights.Add(updatedFlight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DeleteFlight(int id)
|
||||||
|
{
|
||||||
|
var flightToRemove = _flights.FirstOrDefault(f => f.Id == id);
|
||||||
|
if (flightToRemove != null)
|
||||||
|
{
|
||||||
|
_flights.Remove(flightToRemove);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,49 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using YourNamespace.Entities;
|
||||||
|
using YourNamespace.Repositories;
|
||||||
|
|
||||||
|
namespace YourNamespace.Repositories.Implementations
|
||||||
|
{
|
||||||
|
public class PassengerRepository : IPassengerRepository
|
||||||
|
{
|
||||||
|
private readonly List<Passenger> _passengers = new List<Passenger>();
|
||||||
|
private int _nextId = 1;
|
||||||
|
|
||||||
|
public IEnumerable<Passenger> ReadPassengers()
|
||||||
|
{
|
||||||
|
return _passengers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Passenger ReadPassengerById(int id)
|
||||||
|
{
|
||||||
|
return _passengers.FirstOrDefault(p => p.Id == id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CreatePassenger(Passenger passenger)
|
||||||
|
{
|
||||||
|
var newPassenger = Passenger.CreateEntity(_nextId++, passenger.FirstName, passenger.LastName, passenger.PassportNumber);
|
||||||
|
_passengers.Add(newPassenger);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdatePassenger(Passenger passenger)
|
||||||
|
{
|
||||||
|
var existingPassenger = _passengers.FirstOrDefault(p => p.Id == passenger.Id);
|
||||||
|
if (existingPassenger != null)
|
||||||
|
{
|
||||||
|
var updatedPassenger = Passenger.CreateEntity(existingPassenger.Id, passenger.FirstName, passenger.LastName, passenger.PassportNumber);
|
||||||
|
_passengers.Remove(existingPassenger);
|
||||||
|
_passengers.Add(updatedPassenger);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DeletePassenger(int id)
|
||||||
|
{
|
||||||
|
var passengerToRemove = _passengers.FirstOrDefault(p => p.Id == id);
|
||||||
|
if (passengerToRemove != null)
|
||||||
|
{
|
||||||
|
_passengers.Remove(passengerToRemove);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,49 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using YourNamespace.Entities;
|
||||||
|
using YourNamespace.Repositories;
|
||||||
|
|
||||||
|
namespace YourNamespace.Repositories.Implementations
|
||||||
|
{
|
||||||
|
public class PlaneRepository : IPlaneRepository
|
||||||
|
{
|
||||||
|
private readonly List<Plane> _planes = new List<Plane>();
|
||||||
|
private int _nextId = 1;
|
||||||
|
|
||||||
|
public IEnumerable<Plane> ReadPlanes()
|
||||||
|
{
|
||||||
|
return _planes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Plane ReadPlaneById(int id)
|
||||||
|
{
|
||||||
|
return _planes.FirstOrDefault(p => p.Id == id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CreatePlane(Plane plane)
|
||||||
|
{
|
||||||
|
var newPlane = Plane.CreateEntity(_nextId++, plane.Model, plane.Capacity);
|
||||||
|
_planes.Add(newPlane);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdatePlane(Plane plane)
|
||||||
|
{
|
||||||
|
var existingPlane = _planes.FirstOrDefault(p => p.Id == plane.Id);
|
||||||
|
if (existingPlane != null)
|
||||||
|
{
|
||||||
|
var updatedPlane = Plane.CreateEntity(existingPlane.Id, plane.Model, plane.Capacity);
|
||||||
|
_planes.Remove(existingPlane);
|
||||||
|
_planes.Add(updatedPlane);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DeletePlane(int id)
|
||||||
|
{
|
||||||
|
var planeToRemove = _planes.FirstOrDefault(p => p.Id == id);
|
||||||
|
if (planeToRemove != null)
|
||||||
|
{
|
||||||
|
_planes.Remove(planeToRemove);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,49 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using YourNamespace.Entities;
|
||||||
|
using YourNamespace.Repositories;
|
||||||
|
|
||||||
|
namespace YourNamespace.Repositories.Implementations
|
||||||
|
{
|
||||||
|
public class TicketRepository : ITicketRepository
|
||||||
|
{
|
||||||
|
private readonly List<Ticket> _tickets = new List<Ticket>();
|
||||||
|
private int _nextId = 1;
|
||||||
|
|
||||||
|
public IEnumerable<Ticket> ReadTickets()
|
||||||
|
{
|
||||||
|
return _tickets;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Ticket ReadTicketById(int id)
|
||||||
|
{
|
||||||
|
return _tickets.FirstOrDefault(t => t.Id == id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CreateTicket(Ticket ticket)
|
||||||
|
{
|
||||||
|
var newTicket = Ticket.CreateEntity(_nextId++, ticket.PassengerId, ticket.FlightId, ticket.DateBuy, ticket.TicketPrice);
|
||||||
|
_tickets.Add(newTicket);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateTicket(Ticket ticket)
|
||||||
|
{
|
||||||
|
var existingTicket = _tickets.FirstOrDefault(t => t.Id == ticket.Id);
|
||||||
|
if (existingTicket != null)
|
||||||
|
{
|
||||||
|
var updatedTicket = Ticket.CreateEntity(existingTicket.Id, ticket.PassengerId, ticket.FlightId, ticket.DateBuy, ticket.TicketPrice);
|
||||||
|
_tickets.Remove(existingTicket);
|
||||||
|
_tickets.Add(updatedTicket);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DeleteTicket(int id)
|
||||||
|
{
|
||||||
|
var ticketToRemove = _tickets.FirstOrDefault(t => t.Id == id);
|
||||||
|
if (ticketToRemove != null)
|
||||||
|
{
|
||||||
|
_tickets.Remove(ticketToRemove);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user