diff --git a/ProjectFuel/Entities/Car.cs b/ProjectFuel/Entities/Car.cs new file mode 100644 index 0000000..a698b23 --- /dev/null +++ b/ProjectFuel/Entities/Car.cs @@ -0,0 +1,27 @@ +using ProjectFuel.Entities.Enums; +using ProjectFuel.Entities.Enums; + +namespace ProjectFuel.Entities; + +public class Car +{ + public int Car_ID { get; private set; } + public string Car_Mark { get; private set; } = string.Empty; + public string Car_Model { get; private set; } = string.Empty; + public Car_Type Car_Type { get; private set; } + public Driver_License License { get; private set; } + public float Consumption_Rate { get; private set; } + + public static Car CreateEntity(int car_ID, string car_mark, string car_model, Car_Type car_type, Driver_License license, float consumption) + { + return new Car + { + Car_ID = car_ID, + Car_Mark = car_mark ?? string.Empty, + Car_Model = car_model ?? string.Empty, + Car_Type = car_type, + License = license, + Consumption_Rate = consumption + }; + } +} diff --git a/ProjectFuel/Entities/Driver.cs b/ProjectFuel/Entities/Driver.cs new file mode 100644 index 0000000..b288a3b --- /dev/null +++ b/ProjectFuel/Entities/Driver.cs @@ -0,0 +1,23 @@ +using ProjectFuel.Entities.Enums; +using ProjectFuel.Entities.Enums; + +namespace ProjectFuel.Entities; + +public class Driver +{ + public int Driver_ID { get; private set; } + public string Firstname { get; private set; } = string.Empty; + public string Secondname { get; private set; } = string.Empty; + public Driver_License Driver_License { get; private set; } + + public static Driver CreateEntity(int driver_ID, string firstname, string secondname, Driver_License license) + { + return new Driver + { + Driver_ID = driver_ID, + Firstname = firstname ?? string.Empty, + Secondname = secondname ?? string.Empty, + Driver_License = license + }; + } +} diff --git a/ProjectFuel/Entities/Enums/Driver_License.cs b/ProjectFuel/Entities/Enums/Driver_License.cs new file mode 100644 index 0000000..3b1529e --- /dev/null +++ b/ProjectFuel/Entities/Enums/Driver_License.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectFuel.Entities.Enums; + +[Flags] +public enum Driver_License +{ + None = 0, + A = 1, + B = 2, + C = 4, + D = 8, + BE = 16, + CE = 32 +} diff --git a/ProjectFuel/Entities/Enums/FuelType.cs b/ProjectFuel/Entities/Enums/FuelType.cs new file mode 100644 index 0000000..070aa23 --- /dev/null +++ b/ProjectFuel/Entities/Enums/FuelType.cs @@ -0,0 +1,10 @@ +namespace ProjectFuel.Entities.Enums; + +public enum Fuel_Type +{ + None = 0, + + Petrol = 1, + + Diesel = 2 +} diff --git a/ProjectFuel/Entities/Enums/Shift.cs b/ProjectFuel/Entities/Enums/Shift.cs new file mode 100644 index 0000000..95e32c3 --- /dev/null +++ b/ProjectFuel/Entities/Enums/Shift.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectFuel.Entities.Enums; + +public enum Shift +{ + None = 0, + Day = 1, + Night = 2 +} diff --git a/ProjectFuel/Entities/Enums/TypeOfCar.cs b/ProjectFuel/Entities/Enums/TypeOfCar.cs new file mode 100644 index 0000000..2a231e3 --- /dev/null +++ b/ProjectFuel/Entities/Enums/TypeOfCar.cs @@ -0,0 +1,9 @@ +namespace ProjectFuel.Entities.Enums; + +public enum Car_Type +{ + None = 0, + Passenger = 1, + Cargo = 2, + Bus = 3 +} diff --git a/ProjectFuel/Entities/Fuel.cs b/ProjectFuel/Entities/Fuel.cs new file mode 100644 index 0000000..c60e8a3 --- /dev/null +++ b/ProjectFuel/Entities/Fuel.cs @@ -0,0 +1,22 @@ +using ProjectFuel.Entities.Enums; + +namespace ProjectFuel.Entities; + +public class Fuel +{ + public int Fuel_ID { get; private set; } + public Fuel_Type Fuel_Type { get; private set; } + public float Price_Per_Liter { get; private set; } + public float Amount { get; private set; } + + public static Fuel CreateEntity(int fuel_id, Fuel_Type type, float price, float amount) + { + return new Fuel + { + Fuel_ID = fuel_id, + Fuel_Type = type, + Price_Per_Liter = price, + Amount = amount + }; + } +} diff --git a/ProjectFuel/Entities/Refill.cs b/ProjectFuel/Entities/Refill.cs new file mode 100644 index 0000000..035b0cc --- /dev/null +++ b/ProjectFuel/Entities/Refill.cs @@ -0,0 +1,22 @@ +namespace ProjectFuel.Entities; + +public class Refill +{ + public int Refill_ID { get; private set; } + public DateTime Refill_Date { get; private set; } + public float Refill_Amount { get; private set; } + public int Fuel_ID { get; private set; } + public int Car_ID { get; private set; } + + public static Refill CreateOperation(int refill_ID, DateTime refill_date, float refill_amount, int fuel_id, int car_id) + { + return new Refill + { + Refill_ID = refill_ID, + Refill_Date = refill_date, + Refill_Amount = refill_amount, + Fuel_ID = fuel_id, + Car_ID = car_id + }; + } +} diff --git a/ProjectFuel/Entities/Route.cs b/ProjectFuel/Entities/Route.cs new file mode 100644 index 0000000..bd68200 --- /dev/null +++ b/ProjectFuel/Entities/Route.cs @@ -0,0 +1,20 @@ +namespace ProjectFuel.Entities; + +public class Route +{ + public int Route_ID { get; private set; } + public string Start_Point { get; private set; } = string.Empty; + public string End_Point { get; private set; } = string.Empty; + public float Route_Length { get; private set; } + + public static Route CreateEntity(int route_id, string start_point, string end_point, float length) + { + return new Route + { + Route_ID = route_id, + Start_Point = start_point ?? string.Empty, + End_Point = end_point ?? string.Empty, + Route_Length = length + }; + } +} diff --git a/ProjectFuel/Entities/Trip.cs b/ProjectFuel/Entities/Trip.cs new file mode 100644 index 0000000..d108fee --- /dev/null +++ b/ProjectFuel/Entities/Trip.cs @@ -0,0 +1,32 @@ +using ProjectFuel.Entities.Enums; +using ProjectFuel.Entities.Enums; +using ProjectFuel.Entities; + +namespace ProjectFuel.Entities; + +public class Trip +{ + public int Trip_ID { get; private set; } + public DateTime Start_Date { get; private set; } + public DateTime End_Date { get; private set; } + public Shift Shift { get; private set; } + public float Fuel_Consumption { get; private set; } + public int Car_ID { get; private set; } + public int Driver_ID { get; private set; } + public IEnumerable Routes { get; private set; } = new List(); + + public static Trip CreateOperation(int trip_id, DateTime start_date, DateTime end_date, Shift shift, float consumption, int car_id, int driver_id, IEnumerable routes) + { + return new Trip + { + Trip_ID = trip_id, + Start_Date = start_date, + End_Date = end_date, + Shift = shift, + Fuel_Consumption = consumption, + Car_ID = car_id, + Driver_ID = driver_id, + Routes = routes + }; + } +} diff --git a/ProjectFuel/Form1.Designer.cs b/ProjectFuel/Form1.Designer.cs deleted file mode 100644 index 37dafb3..0000000 --- a/ProjectFuel/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace ProjectFuel -{ - partial class Form1 - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; - } - - #endregion - } -} \ No newline at end of file diff --git a/ProjectFuel/Form1.cs b/ProjectFuel/Form1.cs deleted file mode 100644 index 5f6efb8..0000000 --- a/ProjectFuel/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace ProjectFuel -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/ProjectFuel/FormFuel.Designer.cs b/ProjectFuel/FormFuel.Designer.cs new file mode 100644 index 0000000..5fae35a --- /dev/null +++ b/ProjectFuel/FormFuel.Designer.cs @@ -0,0 +1,147 @@ +namespace ProjectFuel +{ + partial class FormFuel + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + menuStrip1 = new MenuStrip(); + справочникиToolStripMenuItem = new ToolStripMenuItem(); + CarsToolStripMenuItem = new ToolStripMenuItem(); + DriversToolStripMenuItem = new ToolStripMenuItem(); + FuelToolStripMenuItem = new ToolStripMenuItem(); + RoutesToolStripMenuItem = new ToolStripMenuItem(); + операцииToolStripMenuItem = new ToolStripMenuItem(); + RefillToolStripMenuItem = new ToolStripMenuItem(); + TripToolStripMenuItem = new ToolStripMenuItem(); + отчетыToolStripMenuItem = new ToolStripMenuItem(); + menuStrip1.SuspendLayout(); + SuspendLayout(); + // + // menuStrip1 + // + menuStrip1.ImageScalingSize = new Size(32, 32); + menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, операцииToolStripMenuItem, отчетыToolStripMenuItem }); + menuStrip1.Location = new Point(0, 0); + menuStrip1.Name = "menuStrip1"; + menuStrip1.Size = new Size(800, 42); + menuStrip1.TabIndex = 0; + menuStrip1.Text = "menuStrip1"; + // + // справочникиToolStripMenuItem + // + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { CarsToolStripMenuItem, DriversToolStripMenuItem, FuelToolStripMenuItem, RoutesToolStripMenuItem }); + справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + справочникиToolStripMenuItem.Size = new Size(184, 38); + справочникиToolStripMenuItem.Text = "Справочники"; + // + // CarsToolStripMenuItem + // + CarsToolStripMenuItem.Name = "CarsToolStripMenuItem"; + CarsToolStripMenuItem.Size = new Size(359, 44); + CarsToolStripMenuItem.Text = "Машины"; + CarsToolStripMenuItem.Click += CarsToolStripMenuItem_Click; + // + // DriversToolStripMenuItem + // + DriversToolStripMenuItem.Name = "DriversToolStripMenuItem"; + DriversToolStripMenuItem.Size = new Size(359, 44); + DriversToolStripMenuItem.Text = "Водители"; + DriversToolStripMenuItem.Click += DriversToolStripMenuItem_Click; + // + // FuelToolStripMenuItem + // + FuelToolStripMenuItem.Name = "FuelToolStripMenuItem"; + FuelToolStripMenuItem.Size = new Size(359, 44); + FuelToolStripMenuItem.Text = "Топливо"; + FuelToolStripMenuItem.Click += FuelToolStripMenuItem_Click; + // + // RoutesToolStripMenuItem + // + RoutesToolStripMenuItem.Name = "RoutesToolStripMenuItem"; + RoutesToolStripMenuItem.Size = new Size(359, 44); + RoutesToolStripMenuItem.Text = "Маршруты"; + RoutesToolStripMenuItem.Click += RoutesToolStripMenuItem_Click; + // + // операцииToolStripMenuItem + // + операцииToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { RefillToolStripMenuItem, TripToolStripMenuItem }); + операцииToolStripMenuItem.Name = "операцииToolStripMenuItem"; + операцииToolStripMenuItem.Size = new Size(147, 38); + операцииToolStripMenuItem.Text = "Операции"; + // + // RefillToolStripMenuItem + // + RefillToolStripMenuItem.Name = "RefillToolStripMenuItem"; + RefillToolStripMenuItem.Size = new Size(359, 44); + RefillToolStripMenuItem.Text = "Заправка"; + RefillToolStripMenuItem.Click += RefillToolStripMenuItem_Click; + // + // TripToolStripMenuItem + // + TripToolStripMenuItem.Name = "TripToolStripMenuItem"; + TripToolStripMenuItem.Size = new Size(359, 44); + TripToolStripMenuItem.Text = "Поездка"; + TripToolStripMenuItem.Click += TripToolStripMenuItem_Click; + // + // отчетыToolStripMenuItem + // + отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; + отчетыToolStripMenuItem.Size = new Size(116, 38); + отчетыToolStripMenuItem.Text = "Отчеты"; + // + // FormFuel + // + AutoScaleDimensions = new SizeF(13F, 32F); + AutoScaleMode = AutoScaleMode.Font; + BackgroundImage = Properties.Resources.топливо; + BackgroundImageLayout = ImageLayout.Stretch; + ClientSize = new Size(800, 450); + Controls.Add(menuStrip1); + MainMenuStrip = menuStrip1; + Name = "FormFuel"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Перевозка топлива"; + menuStrip1.ResumeLayout(false); + menuStrip1.PerformLayout(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private MenuStrip menuStrip1; + private ToolStripMenuItem справочникиToolStripMenuItem; + private ToolStripMenuItem CarsToolStripMenuItem; + private ToolStripMenuItem DriversToolStripMenuItem; + private ToolStripMenuItem FuelToolStripMenuItem; + private ToolStripMenuItem RoutesToolStripMenuItem; + private ToolStripMenuItem операцииToolStripMenuItem; + private ToolStripMenuItem отчетыToolStripMenuItem; + private ToolStripMenuItem RefillToolStripMenuItem; + private ToolStripMenuItem TripToolStripMenuItem; + } +} \ No newline at end of file diff --git a/ProjectFuel/FormFuel.cs b/ProjectFuel/FormFuel.cs new file mode 100644 index 0000000..6484beb --- /dev/null +++ b/ProjectFuel/FormFuel.cs @@ -0,0 +1,98 @@ +using ProjectFuel.Forms_; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using Unity; + +namespace ProjectFuel +{ + public partial class FormFuel : Form + { + private readonly IUnityContainer _container; + public FormFuel(IUnityContainer container) + { + InitializeComponent(); + _container = container ?? + throw new ArgumentNullException(nameof(container)); + } + + private void CarsToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void DriversToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void FuelToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void RoutesToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void RefillToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void TripToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/ProjectFuel/FormFuel.resx b/ProjectFuel/FormFuel.resx new file mode 100644 index 0000000..b48baf1 --- /dev/null +++ b/ProjectFuel/FormFuel.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/ProjectFuel/Forms_/FormCar.Designer.cs b/ProjectFuel/Forms_/FormCar.Designer.cs new file mode 100644 index 0000000..f8f65f6 --- /dev/null +++ b/ProjectFuel/Forms_/FormCar.Designer.cs @@ -0,0 +1,188 @@ +namespace ProjectFuel.Forms_ +{ + partial class FormCar + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + label1 = new Label(); + label2 = new Label(); + label3 = new Label(); + label4 = new Label(); + label5 = new Label(); + textBoxCarMark = new TextBox(); + textBoxCarModel = new TextBox(); + comboBoxCarType = new ComboBox(); + checkedListBoxDriverLicense = new CheckedListBox(); + numericUpDownConsumptionRate = new NumericUpDown(); + buttonCarSave = new Button(); + buttonCancel = new Button(); + ((System.ComponentModel.ISupportInitialize)numericUpDownConsumptionRate).BeginInit(); + SuspendLayout(); + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(48, 70); + label1.Name = "label1"; + label1.Size = new Size(86, 32); + label1.TabIndex = 0; + label1.Text = "Марка"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(50, 138); + label2.Name = "label2"; + label2.Size = new Size(101, 32); + label2.TabIndex = 1; + label2.Text = "Модель"; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(48, 323); + label3.Name = "label3"; + label3.Size = new Size(186, 32); + label3.TabIndex = 2; + label3.Text = "Категория прав"; + // + // label4 + // + label4.AutoSize = true; + label4.Location = new Point(48, 247); + label4.Name = "label4"; + label4.Size = new Size(155, 32); + label4.TabIndex = 3; + label4.Text = "Тип машины"; + // + // label5 + // + label5.AutoSize = true; + label5.Location = new Point(48, 428); + label5.Name = "label5"; + label5.Size = new Size(185, 32); + label5.TabIndex = 4; + label5.Text = "Расход топлива"; + // + // textBoxCarMark + // + textBoxCarMark.Location = new Point(282, 73); + textBoxCarMark.Name = "textBoxCarMark"; + textBoxCarMark.Size = new Size(200, 39); + textBoxCarMark.TabIndex = 5; + // + // textBoxCarModel + // + textBoxCarModel.Location = new Point(269, 147); + textBoxCarModel.Name = "textBoxCarModel"; + textBoxCarModel.Size = new Size(200, 39); + textBoxCarModel.TabIndex = 6; + // + // comboBoxCarType + // + comboBoxCarType.FormattingEnabled = true; + comboBoxCarType.Location = new Point(301, 248); + comboBoxCarType.Name = "comboBoxCarType"; + comboBoxCarType.Size = new Size(242, 40); + comboBoxCarType.TabIndex = 7; + // + // checkedListBoxDriverLicense + // + checkedListBoxDriverLicense.FormattingEnabled = true; + checkedListBoxDriverLicense.Location = new Point(305, 321); + checkedListBoxDriverLicense.Name = "checkedListBoxDriverLicense"; + checkedListBoxDriverLicense.Size = new Size(240, 76); + checkedListBoxDriverLicense.TabIndex = 8; + // + // numericUpDownConsumptionRate + // + numericUpDownConsumptionRate.Location = new Point(295, 443); + numericUpDownConsumptionRate.Name = "numericUpDownConsumptionRate"; + numericUpDownConsumptionRate.Size = new Size(240, 39); + numericUpDownConsumptionRate.TabIndex = 9; + // + // buttonCarSave + // + buttonCarSave.Location = new Point(75, 543); + buttonCarSave.Name = "buttonCarSave"; + buttonCarSave.Size = new Size(150, 46); + buttonCarSave.TabIndex = 10; + buttonCarSave.Text = "Сохранить"; + buttonCarSave.UseVisualStyleBackColor = true; + buttonCarSave.Click += ButtonCarSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(341, 543); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(150, 46); + buttonCancel.TabIndex = 11; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormCar + // + AutoScaleDimensions = new SizeF(13F, 32F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(905, 627); + Controls.Add(buttonCancel); + Controls.Add(buttonCarSave); + Controls.Add(numericUpDownConsumptionRate); + Controls.Add(checkedListBoxDriverLicense); + Controls.Add(comboBoxCarType); + Controls.Add(textBoxCarModel); + Controls.Add(textBoxCarMark); + Controls.Add(label5); + Controls.Add(label4); + Controls.Add(label3); + Controls.Add(label2); + Controls.Add(label1); + Name = "FormCar"; + StartPosition = FormStartPosition.CenterParent; + Text = "FormCar"; + ((System.ComponentModel.ISupportInitialize)numericUpDownConsumptionRate).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label label1; + private Label label2; + private Label label3; + private Label label4; + private Label label5; + private TextBox textBoxCarMark; + private TextBox textBoxCarModel; + private ComboBox comboBoxCarType; + private CheckedListBox checkedListBoxDriverLicense; + private NumericUpDown numericUpDownConsumptionRate; + private Button buttonCarSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/ProjectFuel/Forms_/FormCar.cs b/ProjectFuel/Forms_/FormCar.cs new file mode 100644 index 0000000..b3c9ca0 --- /dev/null +++ b/ProjectFuel/Forms_/FormCar.cs @@ -0,0 +1,96 @@ +using ProjectFuel.Entities; +using ProjectFuel.Entities.Enums; +using ProjectFuel.Repositories; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ProjectFuel.Forms_ +{ + public partial class FormCar : Form + { + private readonly ICarRepository _carRepository; + + private int? _carId; + + public int Id + { + set + { + try + { + var car = _carRepository.ReadCarByID(value); + if (car == null) + throw new InvalidOperationException(nameof(car)); + + foreach (Driver_License elem in Enum.GetValues(typeof(Driver_License))) + { + if ((elem & car.License) != 0) + { + checkedListBoxDriverLicense.SetItemChecked(checkedListBoxDriverLicense.Items.IndexOf(elem), true); + } + } + textBoxCarMark.Text = car.Car_Mark; + textBoxCarModel.Text = car.Car_Model; + comboBoxCarType.SelectedItem = car.Car_Type; + numericUpDownConsumptionRate.Value = (decimal)car.Consumption_Rate; + + _carId = value; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + } + } + public FormCar(ICarRepository carRepository) + { + InitializeComponent(); + _carRepository = carRepository ?? + throw new ArgumentNullException(nameof(carRepository)); + + foreach (var elem in Enum.GetValues(typeof(Driver_License))) + checkedListBoxDriverLicense.Items.Add(elem); + + comboBoxCarType.DataSource = Enum.GetValues(typeof(Car_Type)); + } + private void ButtonCarSave_Click(object sender, EventArgs e) + { + try + { + if (string.IsNullOrWhiteSpace(textBoxCarMark.Text) || string.IsNullOrWhiteSpace(textBoxCarModel.Text) || comboBoxCarType.SelectedIndex < 1 || checkedListBoxDriverLicense.CheckedItems.Count == 0) + throw new Exception("Имеются незаполненные поля"); + + if (_carId.HasValue) + _carRepository.UpdateCar(CreateCar(_carId.Value)); + else + _carRepository.CreateCar(CreateCar(0)); + + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonCancel_Click(object sender, EventArgs e) => Close(); + + private Car CreateCar(int id) + { + Driver_License driver_License = Driver_License.None; + foreach (var elem in checkedListBoxDriverLicense.CheckedItems) + { + driver_License |= (Driver_License)elem; + } + + return Car.CreateEntity(id, textBoxCarMark.Text, textBoxCarModel.Text, (Car_Type)comboBoxCarType.SelectedItem!, driver_License, (float)numericUpDownConsumptionRate.Value); + } + } +} diff --git a/ProjectFuel/Form1.resx b/ProjectFuel/Forms_/FormCar.resx similarity index 92% rename from ProjectFuel/Form1.resx rename to ProjectFuel/Forms_/FormCar.resx index 1af7de1..8b2ff64 100644 --- a/ProjectFuel/Form1.resx +++ b/ProjectFuel/Forms_/FormCar.resx @@ -1,17 +1,17 @@  - diff --git a/ProjectFuel/Forms_/FormCars.Designer.cs b/ProjectFuel/Forms_/FormCars.Designer.cs new file mode 100644 index 0000000..b6cdd4f --- /dev/null +++ b/ProjectFuel/Forms_/FormCars.Designer.cs @@ -0,0 +1,128 @@ +namespace ProjectFuel.Forms_ +{ + partial class FormCars + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + panel1 = new Panel(); + buttonDel = new Button(); + buttonUpd = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // panel1 + // + panel1.Controls.Add(buttonDel); + panel1.Controls.Add(buttonUpd); + panel1.Controls.Add(buttonAdd); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(624, 0); + panel1.Name = "panel1"; + panel1.Size = new Size(334, 577); + panel1.TabIndex = 0; + // + // buttonDel + // + buttonDel.BackgroundImage = Properties.Resources.удалять; + buttonDel.BackgroundImageLayout = ImageLayout.Stretch; + buttonDel.Location = new Point(94, 349); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(158, 120); + buttonDel.TabIndex = 2; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // buttonUpd + // + buttonUpd.BackgroundImage = Properties.Resources.ред; + buttonUpd.BackgroundImageLayout = ImageLayout.Stretch; + buttonUpd.Location = new Point(94, 201); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(158, 118); + buttonUpd.TabIndex = 1; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += ButtonUpd_Click; + // + // buttonAdd + // + buttonAdd.BackgroundImage = Properties.Resources._; + buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; + buttonAdd.Location = new Point(94, 64); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(158, 114); + buttonAdd.TabIndex = 0; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.AllowUserToResizeColumns = false; + dataGridView.AllowUserToResizeRows = false; + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Fill; + dataGridView.Location = new Point(0, 0); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 82; + dataGridView.RowTemplate.Height = 41; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(624, 577); + dataGridView.TabIndex = 1; + // + // FormCars + // + AutoScaleDimensions = new SizeF(13F, 32F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(958, 577); + Controls.Add(dataGridView); + Controls.Add(panel1); + Name = "FormCars"; + StartPosition = FormStartPosition.CenterParent; + Text = "Машины"; + Load += FormCars_Load; + panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Panel panel1; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/ProjectFuel/Forms_/FormCars.cs b/ProjectFuel/Forms_/FormCars.cs new file mode 100644 index 0000000..09d127a --- /dev/null +++ b/ProjectFuel/Forms_/FormCars.cs @@ -0,0 +1,103 @@ +using ProjectFuel.Repositories; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using Unity; + +namespace ProjectFuel.Forms_ +{ + public partial class FormCars : Form + { + private readonly IUnityContainer _container; + + private readonly ICarRepository _carRepository; + public FormCars(IUnityContainer container, ICarRepository carRepository) + { + InitializeComponent(); + _container = container ?? + throw new ArgumentNullException(nameof(container)); + _carRepository = carRepository ?? + throw new ArgumentNullException(nameof(carRepository)); + } + private void FormCars_Load(object sender, EventArgs e) + { + try + { + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } + private void ButtonDel_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var findId)) + return; + + if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes) + return; + + try + { + _carRepository.DeleteCar(findId); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var findId)) + return; + + try + { + var form = _container.Resolve(); + form.Id = findId; + form.ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при изменении", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void LoadList() => dataGridView.DataSource = _carRepository.ReadCars(); + private bool TryGetIdentifierFromSelectedRow(out int id) + { + id = 0; + if (dataGridView.SelectedRows.Count < 1) + { + MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Car_ID"].Value); + return true; + } + } +} + diff --git a/ProjectFuel/Forms_/FormCars.resx b/ProjectFuel/Forms_/FormCars.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/ProjectFuel/Forms_/FormCars.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ProjectFuel/Forms_/FormDriver.Designer.cs b/ProjectFuel/Forms_/FormDriver.Designer.cs new file mode 100644 index 0000000..77796e7 --- /dev/null +++ b/ProjectFuel/Forms_/FormDriver.Designer.cs @@ -0,0 +1,141 @@ +namespace ProjectFuel.Forms_ +{ + partial class FormDriver + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + label1 = new Label(); + label2 = new Label(); + label3 = new Label(); + textBoxDriverFirstname = new TextBox(); + textBoxDriverSecondname = new TextBox(); + checkedListBoxDriverLicense = new CheckedListBox(); + buttonDriverSave = new Button(); + buttonDriverCancel = new Button(); + SuspendLayout(); + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(31, 35); + label1.Name = "label1"; + label1.Size = new Size(61, 32); + label1.TabIndex = 0; + label1.Text = "Имя"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(31, 108); + label2.Name = "label2"; + label2.Size = new Size(113, 32); + label2.TabIndex = 1; + label2.Text = "Фамилия"; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(31, 192); + label3.Name = "label3"; + label3.Size = new Size(281, 32); + label3.TabIndex = 2; + label3.Text = "Водительская категория"; + // + // textBoxDriverFirstname + // + textBoxDriverFirstname.Location = new Point(282, 28); + textBoxDriverFirstname.Name = "textBoxDriverFirstname"; + textBoxDriverFirstname.Size = new Size(200, 39); + textBoxDriverFirstname.TabIndex = 3; + // + // textBoxDriverSecondname + // + textBoxDriverSecondname.Location = new Point(285, 105); + textBoxDriverSecondname.Name = "textBoxDriverSecondname"; + textBoxDriverSecondname.Size = new Size(200, 39); + textBoxDriverSecondname.TabIndex = 4; + // + // checkedListBoxDriverLicense + // + checkedListBoxDriverLicense.FormattingEnabled = true; + checkedListBoxDriverLicense.Location = new Point(352, 199); + checkedListBoxDriverLicense.Name = "checkedListBoxDriverLicense"; + checkedListBoxDriverLicense.Size = new Size(240, 76); + checkedListBoxDriverLicense.TabIndex = 5; + // + // buttonDriverSave + // + buttonDriverSave.Location = new Point(66, 359); + buttonDriverSave.Name = "buttonDriverSave"; + buttonDriverSave.Size = new Size(150, 46); + buttonDriverSave.TabIndex = 6; + buttonDriverSave.Text = "Сохранить"; + buttonDriverSave.UseVisualStyleBackColor = true; + buttonDriverSave.Click += ButtonDriverSave_Click; + // + // buttonDriverCancel + // + buttonDriverCancel.Location = new Point(364, 356); + buttonDriverCancel.Name = "buttonDriverCancel"; + buttonDriverCancel.Size = new Size(150, 46); + buttonDriverCancel.TabIndex = 7; + buttonDriverCancel.Text = "Отмена"; + buttonDriverCancel.UseVisualStyleBackColor = true; + buttonDriverCancel.Click += ButtonDriverCancel_Click; + // + // FormDriver + // + AutoScaleDimensions = new SizeF(13F, 32F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(buttonDriverCancel); + Controls.Add(buttonDriverSave); + Controls.Add(checkedListBoxDriverLicense); + Controls.Add(textBoxDriverSecondname); + Controls.Add(textBoxDriverFirstname); + Controls.Add(label3); + Controls.Add(label2); + Controls.Add(label1); + Name = "FormDriver"; + StartPosition = FormStartPosition.CenterParent; + Text = "Водитель"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label label1; + private Label label2; + private Label label3; + private TextBox textBoxDriverFirstname; + private TextBox textBoxDriverSecondname; + private CheckedListBox checkedListBoxDriverLicense; + private Button buttonDriverSave; + private Button buttonDriverCancel; + } +} \ No newline at end of file diff --git a/ProjectFuel/Forms_/FormDriver.cs b/ProjectFuel/Forms_/FormDriver.cs new file mode 100644 index 0000000..517c7c5 --- /dev/null +++ b/ProjectFuel/Forms_/FormDriver.cs @@ -0,0 +1,93 @@ +using ProjectFuel.Entities; +using ProjectFuel.Entities.Enums; +using ProjectFuel.Repositories; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ProjectFuel.Forms_ +{ + public partial class FormDriver : Form + { + private readonly IDriverRepository _driverRepository; + + private int? _driverId; + public int Id + { + set + { + try + { + var driver = _driverRepository.ReadDriverByID(value); + if (driver == null) + throw new InvalidOperationException(nameof(driver)); + + foreach (Driver_License elem in Enum.GetValues(typeof(Driver_License))) + { + if ((elem & driver.Driver_License) != 0) + { + checkedListBoxDriverLicense.SetItemChecked(checkedListBoxDriverLicense.Items.IndexOf(elem), true); + } + } + + + textBoxDriverFirstname.Text = driver.Firstname; + textBoxDriverSecondname.Text = driver.Secondname; + _driverId = value; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + } + } + public FormDriver(IDriverRepository driverRepository) + { + InitializeComponent(); + _driverRepository = driverRepository ?? + throw new ArgumentNullException(nameof(driverRepository)); + + foreach (var elem in Enum.GetValues(typeof(Driver_License))) + checkedListBoxDriverLicense.Items.Add(elem); + } + private void ButtonDriverSave_Click(object sender, EventArgs e) + { + try + { + if (string.IsNullOrWhiteSpace(textBoxDriverFirstname.Text) || string.IsNullOrWhiteSpace(textBoxDriverSecondname.Text) || checkedListBoxDriverLicense.CheckedItems.Count == 0) + throw new Exception("Имеются незаполненные поля"); + + if (_driverId.HasValue) + _driverRepository.UpdateDriver(CreateDriver(_driverId.Value)); + else + _driverRepository.CreateDriver(CreateDriver(0)); + + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonDriverCancel_Click(object sender, EventArgs e) => Close(); + + private Driver CreateDriver(int id) + { + Driver_License driver_License = Driver_License.None; + foreach (var elem in checkedListBoxDriverLicense.CheckedItems) + { + driver_License |= (Driver_License)elem; + } + + return Driver.CreateEntity(id, textBoxDriverFirstname.Text, textBoxDriverSecondname.Text, driver_License); + } + } +} + diff --git a/ProjectFuel/Forms_/FormDriver.resx b/ProjectFuel/Forms_/FormDriver.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/ProjectFuel/Forms_/FormDriver.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ProjectFuel/Forms_/FormDrivers.Designer.cs b/ProjectFuel/Forms_/FormDrivers.Designer.cs new file mode 100644 index 0000000..7fcfa30 --- /dev/null +++ b/ProjectFuel/Forms_/FormDrivers.Designer.cs @@ -0,0 +1,128 @@ +namespace ProjectFuel.Forms_ +{ + partial class FormDrivers + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + panel1 = new Panel(); + buttonDel = new Button(); + buttonUpd = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // panel1 + // + panel1.Controls.Add(buttonDel); + panel1.Controls.Add(buttonUpd); + panel1.Controls.Add(buttonAdd); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(819, 0); + panel1.Name = "panel1"; + panel1.Size = new Size(242, 569); + panel1.TabIndex = 0; + // + // buttonDel + // + buttonDel.BackgroundImage = Properties.Resources.удалять; + buttonDel.BackgroundImageLayout = ImageLayout.Stretch; + buttonDel.Location = new Point(67, 400); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(151, 126); + buttonDel.TabIndex = 2; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // buttonUpd + // + buttonUpd.BackgroundImage = Properties.Resources.ред; + buttonUpd.BackgroundImageLayout = ImageLayout.Stretch; + buttonUpd.Location = new Point(67, 224); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(152, 115); + buttonUpd.TabIndex = 1; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += ButtonUpd_Click; + // + // buttonAdd + // + buttonAdd.BackgroundImage = Properties.Resources._; + buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; + buttonAdd.Location = new Point(68, 52); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(151, 131); + buttonAdd.TabIndex = 0; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.AllowUserToResizeColumns = false; + dataGridView.AllowUserToResizeRows = false; + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Fill; + dataGridView.Location = new Point(0, 0); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 82; + dataGridView.RowTemplate.Height = 41; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(819, 569); + dataGridView.TabIndex = 1; + // + // FormDrivers + // + AutoScaleDimensions = new SizeF(13F, 32F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1061, 569); + Controls.Add(dataGridView); + Controls.Add(panel1); + Name = "FormDrivers"; + StartPosition = FormStartPosition.CenterParent; + Text = "Водители"; + Load += FormDrivers_Load; + panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Panel panel1; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/ProjectFuel/Forms_/FormDrivers.cs b/ProjectFuel/Forms_/FormDrivers.cs new file mode 100644 index 0000000..eb1e9f6 --- /dev/null +++ b/ProjectFuel/Forms_/FormDrivers.cs @@ -0,0 +1,104 @@ +using ProjectFuel.Repositories; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using Unity; + +namespace ProjectFuel.Forms_ +{ + public partial class FormDrivers : Form + { + private readonly IUnityContainer _container; + + private readonly IDriverRepository _driverRepository; + public FormDrivers(IUnityContainer container, IDriverRepository driverRepository) + { + InitializeComponent(); + _container = container ?? + throw new ArgumentNullException(nameof(container)); + _driverRepository = driverRepository ?? + throw new ArgumentNullException(nameof(driverRepository)); + } + private void FormDrivers_Load(object sender, EventArgs e) + { + try + { + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var findId)) + return; + + try + { + var form = _container.Resolve(); + form.Id = findId; + form.ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при изменении", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } + private void ButtonDel_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var findId)) + return; + + if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes) + return; + + try + { + _driverRepository.DeleteDriver(findId); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } + private void LoadList() => dataGridView.DataSource = _driverRepository.ReadDrivers(); + + private bool TryGetIdentifierFromSelectedRow(out int id) + { + id = 0; + if (dataGridView.SelectedRows.Count < 1) + { + MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Driver_ID"].Value); + return true; + } + } +} diff --git a/ProjectFuel/Forms_/FormDrivers.resx b/ProjectFuel/Forms_/FormDrivers.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/ProjectFuel/Forms_/FormDrivers.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ProjectFuel/Forms_/FormFuel.Designer.cs b/ProjectFuel/Forms_/FormFuel.Designer.cs new file mode 100644 index 0000000..471349b --- /dev/null +++ b/ProjectFuel/Forms_/FormFuel.Designer.cs @@ -0,0 +1,148 @@ +namespace ProjectFuel.Forms_ +{ + partial class FormFuel + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + label1 = new Label(); + label2 = new Label(); + label3 = new Label(); + buttonFuelSave = new Button(); + buttonCancel = new Button(); + comboBoxFuelType = new ComboBox(); + numericUpDownPrice = new NumericUpDown(); + numericUpDownAmount = new NumericUpDown(); + ((System.ComponentModel.ISupportInitialize)numericUpDownPrice).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownAmount).BeginInit(); + SuspendLayout(); + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(41, 58); + label1.Name = "label1"; + label1.Size = new Size(152, 32); + label1.TabIndex = 0; + label1.Text = "Вид топлива"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(47, 126); + label2.Name = "label2"; + label2.Size = new Size(159, 32); + label2.TabIndex = 1; + label2.Text = "Цена за литр"; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(52, 198); + label3.Name = "label3"; + label3.Size = new Size(144, 32); + label3.TabIndex = 2; + label3.Text = "Количество"; + // + // buttonFuelSave + // + buttonFuelSave.Location = new Point(71, 338); + buttonFuelSave.Name = "buttonFuelSave"; + buttonFuelSave.Size = new Size(150, 46); + buttonFuelSave.TabIndex = 3; + buttonFuelSave.Text = "Сохранить"; + buttonFuelSave.UseVisualStyleBackColor = true; + buttonFuelSave.Click += ButtonFuelSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(306, 338); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(150, 46); + buttonCancel.TabIndex = 4; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // comboBoxFuelType + // + comboBoxFuelType.FormattingEnabled = true; + comboBoxFuelType.Location = new Point(272, 65); + comboBoxFuelType.Name = "comboBoxFuelType"; + comboBoxFuelType.Size = new Size(242, 40); + comboBoxFuelType.TabIndex = 5; + // + // numericUpDownPrice + // + numericUpDownPrice.DecimalPlaces = 2; + numericUpDownPrice.InterceptArrowKeys = false; + numericUpDownPrice.Location = new Point(271, 129); + numericUpDownPrice.Name = "numericUpDownPrice"; + numericUpDownPrice.Size = new Size(240, 39); + numericUpDownPrice.TabIndex = 6; + // + // numericUpDownAmount + // + numericUpDownAmount.DecimalPlaces = 2; + numericUpDownAmount.Location = new Point(268, 203); + numericUpDownAmount.Name = "numericUpDownAmount"; + numericUpDownAmount.Size = new Size(240, 39); + numericUpDownAmount.TabIndex = 7; + // + // FormFuel + // + AutoScaleDimensions = new SizeF(13F, 32F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(numericUpDownAmount); + Controls.Add(numericUpDownPrice); + Controls.Add(comboBoxFuelType); + Controls.Add(buttonCancel); + Controls.Add(buttonFuelSave); + Controls.Add(label3); + Controls.Add(label2); + Controls.Add(label1); + Name = "FormFuel"; + StartPosition = FormStartPosition.CenterParent; + Text = "FormFuel"; + ((System.ComponentModel.ISupportInitialize)numericUpDownPrice).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownAmount).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label label1; + private Label label2; + private Label label3; + private Button buttonFuelSave; + private Button buttonCancel; + private ComboBox comboBoxFuelType; + private NumericUpDown numericUpDownPrice; + private NumericUpDown numericUpDownAmount; + } +} \ No newline at end of file diff --git a/ProjectFuel/Forms_/FormFuel.cs b/ProjectFuel/Forms_/FormFuel.cs new file mode 100644 index 0000000..3cc92f3 --- /dev/null +++ b/ProjectFuel/Forms_/FormFuel.cs @@ -0,0 +1,79 @@ +using ProjectFuel.Entities; +using ProjectFuel.Entities.Enums; +using ProjectFuel.Repositories; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ProjectFuel.Forms_ +{ + public partial class FormFuel : Form + { + private readonly IFuelRepository _fuelRepository; + + private int? _fuelId; + public int Id + { + set + { + try + { + var fuel = _fuelRepository.ReadFuelByID(value); + if (fuel == null) + throw new InvalidOperationException(nameof(fuel)); + + comboBoxFuelType.SelectedItem = fuel.Fuel_Type; + numericUpDownPrice.Value = (decimal)fuel.Price_Per_Liter; + numericUpDownAmount.Value = (decimal)fuel.Amount; + + _fuelId = value; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + } + } + public FormFuel(IFuelRepository fuelRepository) + { + InitializeComponent(); + _fuelRepository = fuelRepository ?? + throw new ArgumentNullException(nameof(fuelRepository)); + + comboBoxFuelType.DataSource = Enum.GetValues(typeof(Fuel_Type)); + } + private void ButtonFuelSave_Click(object sender, EventArgs e) + { + try + { + if (comboBoxFuelType.SelectedIndex < 1) + throw new Exception("Имеются незаполненные поля"); + + if (_fuelId.HasValue) + _fuelRepository.UpdateFuel(CreateFuel(_fuelId.Value)); + else + _fuelRepository.CreateFuel(CreateFuel(0)); + + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonCancel_Click(object sender, EventArgs e) => Close(); + + private Fuel CreateFuel(int id) + { + return Fuel.CreateEntity(id, (Fuel_Type)comboBoxFuelType.SelectedItem!, (float)numericUpDownPrice.Value, (float)numericUpDownAmount.Value); + } + } +} + diff --git a/ProjectFuel/Forms_/FormFuel.resx b/ProjectFuel/Forms_/FormFuel.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/ProjectFuel/Forms_/FormFuel.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ProjectFuel/Forms_/FormFuels.Designer.cs b/ProjectFuel/Forms_/FormFuels.Designer.cs new file mode 100644 index 0000000..0062175 --- /dev/null +++ b/ProjectFuel/Forms_/FormFuels.Designer.cs @@ -0,0 +1,128 @@ +namespace ProjectFuel.Forms_ +{ + partial class FormFuels + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + panel1 = new Panel(); + buttonAdd = new Button(); + buttonUpd = new Button(); + buttonDel = new Button(); + dataGridView = new DataGridView(); + panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // panel1 + // + panel1.Controls.Add(buttonAdd); + panel1.Controls.Add(buttonUpd); + panel1.Controls.Add(buttonDel); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(836, 0); + panel1.Name = "panel1"; + panel1.Size = new Size(230, 618); + panel1.TabIndex = 0; + // + // buttonAdd + // + buttonAdd.BackgroundImage = Properties.Resources._; + buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; + buttonAdd.Location = new Point(59, 64); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(151, 131); + buttonAdd.TabIndex = 5; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // buttonUpd + // + buttonUpd.BackgroundImage = Properties.Resources.ред; + buttonUpd.BackgroundImageLayout = ImageLayout.Stretch; + buttonUpd.Location = new Point(58, 246); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(152, 115); + buttonUpd.TabIndex = 4; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += ButtonUpd_Click; + // + // buttonDel + // + buttonDel.BackgroundImage = Properties.Resources.удалять; + buttonDel.BackgroundImageLayout = ImageLayout.Stretch; + buttonDel.Location = new Point(58, 422); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(151, 126); + buttonDel.TabIndex = 3; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.AllowUserToResizeColumns = false; + dataGridView.AllowUserToResizeRows = false; + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Fill; + dataGridView.Location = new Point(0, 0); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 82; + dataGridView.RowTemplate.Height = 41; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(836, 618); + dataGridView.TabIndex = 1; + // + // FormFuels + // + AutoScaleDimensions = new SizeF(13F, 32F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1066, 618); + Controls.Add(dataGridView); + Controls.Add(panel1); + Name = "FormFuels"; + StartPosition = FormStartPosition.CenterParent; + Text = "Топлива"; + Load += FormFuels_Load; + panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Panel panel1; + private DataGridView dataGridView; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/ProjectFuel/Forms_/FormFuels.cs b/ProjectFuel/Forms_/FormFuels.cs new file mode 100644 index 0000000..637c89c --- /dev/null +++ b/ProjectFuel/Forms_/FormFuels.cs @@ -0,0 +1,104 @@ +using ProjectFuel.Repositories; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using Unity; + +namespace ProjectFuel.Forms_ +{ + public partial class FormFuels : Form + { + private readonly IUnityContainer _container; + + private readonly IFuelRepository _fuelRepository; + public FormFuels(IUnityContainer container, IFuelRepository fuelRepository) + { + InitializeComponent(); + _container = container ?? + throw new ArgumentNullException(nameof(container)); + _fuelRepository = fuelRepository ?? + throw new ArgumentNullException(nameof(fuelRepository)); + } + private void FormFuels_Load(object sender, EventArgs e) + { + try + { + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var findId)) + return; + + try + { + var form = _container.Resolve(); + form.Id = findId; + form.ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при изменении", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } + private void ButtonDel_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var findId)) + return; + + if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes) + return; + + try + { + _fuelRepository.DeleteFuel(findId); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void LoadList() => dataGridView.DataSource = _fuelRepository.ReadFuels(); + + private bool TryGetIdentifierFromSelectedRow(out int id) + { + id = 0; + if (dataGridView.SelectedRows.Count < 1) + { + MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Fuel_ID"].Value); + return true; + } + + } +} diff --git a/ProjectFuel/Forms_/FormFuels.resx b/ProjectFuel/Forms_/FormFuels.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/ProjectFuel/Forms_/FormFuels.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ProjectFuel/Forms_/FormRefill.Designer.cs b/ProjectFuel/Forms_/FormRefill.Designer.cs new file mode 100644 index 0000000..63c79f4 --- /dev/null +++ b/ProjectFuel/Forms_/FormRefill.Designer.cs @@ -0,0 +1,169 @@ +namespace ProjectFuel.Forms_ +{ + partial class FormRefill + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + label1 = new Label(); + label2 = new Label(); + label3 = new Label(); + label4 = new Label(); + dateTimePickerRefillDate = new DateTimePicker(); + numericUpDownRefillAmount = new NumericUpDown(); + comboBoxFuelID = new ComboBox(); + comboBoxCarID = new ComboBox(); + buttonRefillSave = new Button(); + buttonCancel = new Button(); + ((System.ComponentModel.ISupportInitialize)numericUpDownRefillAmount).BeginInit(); + SuspendLayout(); + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(44, 49); + label1.Name = "label1"; + label1.Size = new Size(174, 32); + label1.TabIndex = 0; + label1.Text = "Дата заправки"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(48, 112); + label2.Name = "label2"; + label2.Size = new Size(144, 32); + label2.TabIndex = 1; + label2.Text = "Количество"; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(50, 179); + label3.Name = "label3"; + label3.Size = new Size(109, 32); + label3.TabIndex = 2; + label3.Text = "Топливо"; + // + // label4 + // + label4.AutoSize = true; + label4.Location = new Point(57, 250); + label4.Name = "label4"; + label4.Size = new Size(107, 32); + label4.TabIndex = 3; + label4.Text = "Машина"; + // + // dateTimePickerRefillDate + // + dateTimePickerRefillDate.Location = new Point(291, 42); + dateTimePickerRefillDate.Name = "dateTimePickerRefillDate"; + dateTimePickerRefillDate.Size = new Size(400, 39); + dateTimePickerRefillDate.TabIndex = 4; + // + // numericUpDownRefillAmount + // + numericUpDownRefillAmount.DecimalPlaces = 2; + numericUpDownRefillAmount.Location = new Point(281, 114); + numericUpDownRefillAmount.Name = "numericUpDownRefillAmount"; + numericUpDownRefillAmount.Size = new Size(240, 39); + numericUpDownRefillAmount.TabIndex = 5; + // + // comboBoxFuelID + // + comboBoxFuelID.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxFuelID.FormattingEnabled = true; + comboBoxFuelID.Location = new Point(282, 180); + comboBoxFuelID.Name = "comboBoxFuelID"; + comboBoxFuelID.Size = new Size(242, 40); + comboBoxFuelID.TabIndex = 6; + // + // comboBoxCarID + // + comboBoxCarID.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxCarID.FormattingEnabled = true; + comboBoxCarID.Location = new Point(277, 256); + comboBoxCarID.Name = "comboBoxCarID"; + comboBoxCarID.Size = new Size(242, 40); + comboBoxCarID.TabIndex = 7; + // + // buttonRefillSave + // + buttonRefillSave.Location = new Point(57, 367); + buttonRefillSave.Name = "buttonRefillSave"; + buttonRefillSave.Size = new Size(150, 46); + buttonRefillSave.TabIndex = 8; + buttonRefillSave.Text = "Сохранить"; + buttonRefillSave.UseVisualStyleBackColor = true; + buttonRefillSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(315, 368); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(150, 46); + buttonCancel.TabIndex = 9; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormRefill + // + AutoScaleDimensions = new SizeF(13F, 32F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(buttonCancel); + Controls.Add(buttonRefillSave); + Controls.Add(comboBoxCarID); + Controls.Add(comboBoxFuelID); + Controls.Add(numericUpDownRefillAmount); + Controls.Add(dateTimePickerRefillDate); + Controls.Add(label4); + Controls.Add(label3); + Controls.Add(label2); + Controls.Add(label1); + Name = "FormRefill"; + StartPosition = FormStartPosition.CenterParent; + Text = "FormRefill"; + ((System.ComponentModel.ISupportInitialize)numericUpDownRefillAmount).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label label1; + private Label label2; + private Label label3; + private Label label4; + private DateTimePicker dateTimePickerRefillDate; + private NumericUpDown numericUpDownRefillAmount; + private ComboBox comboBoxFuelID; + private ComboBox comboBoxCarID; + private Button buttonRefillSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/ProjectFuel/Forms_/FormRefill.cs b/ProjectFuel/Forms_/FormRefill.cs new file mode 100644 index 0000000..1c92b53 --- /dev/null +++ b/ProjectFuel/Forms_/FormRefill.cs @@ -0,0 +1,51 @@ +using ProjectFuel.Entities; +using ProjectFuel.Repositories; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ProjectFuel.Forms_ +{ + public partial class FormRefill : Form + { + private readonly IRefillRepository _refillRepository; + public FormRefill(IRefillRepository refillRepository, IFuelRepository fuelRepository, ICarRepository carRepository) + { + InitializeComponent(); + _refillRepository = refillRepository ?? + throw new ArgumentNullException(nameof(refillRepository)); + + comboBoxFuelID.DataSource = fuelRepository.ReadFuels(); + comboBoxFuelID.DisplayMember = "Fuel_Type"; + comboBoxFuelID.ValueMember = "Fuel_ID"; + + comboBoxCarID.DataSource = carRepository.ReadCars(); + comboBoxCarID.DisplayMember = "Car_Mark"; + comboBoxCarID.ValueMember = "Car_ID"; + } + private void ButtonSave_Click(object sender, EventArgs e) + { + try + { + if (comboBoxFuelID.SelectedIndex < 0 || comboBoxCarID.SelectedIndex < 0) + throw new Exception("Имеются незаполненные поля"); + + _refillRepository.CreateRefill(Refill.CreateOperation(0, dateTimePickerRefillDate.Value, (float)numericUpDownRefillAmount.Value, (int)comboBoxFuelID.SelectedValue!, (int)comboBoxCarID.SelectedValue!)); + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonCancel_Click(object sender, EventArgs e) => Close(); + } +} + diff --git a/ProjectFuel/Forms_/FormRefill.resx b/ProjectFuel/Forms_/FormRefill.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/ProjectFuel/Forms_/FormRefill.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ProjectFuel/Forms_/FormRefills.Designer.cs b/ProjectFuel/Forms_/FormRefills.Designer.cs new file mode 100644 index 0000000..94a9e74 --- /dev/null +++ b/ProjectFuel/Forms_/FormRefills.Designer.cs @@ -0,0 +1,100 @@ +namespace ProjectFuel.Forms_ +{ + partial class FormRefills + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + panel1 = new Panel(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // panel1 + // + panel1.Controls.Add(buttonAdd); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(824, 0); + panel1.Name = "panel1"; + panel1.Size = new Size(266, 634); + panel1.TabIndex = 0; + // + // buttonAdd + // + buttonAdd.BackgroundImage = Properties.Resources._; + buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; + buttonAdd.Location = new Point(72, 74); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(151, 131); + buttonAdd.TabIndex = 6; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.AllowUserToResizeColumns = false; + dataGridView.AllowUserToResizeRows = false; + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Fill; + dataGridView.Location = new Point(0, 0); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 82; + dataGridView.RowTemplate.Height = 41; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(824, 634); + dataGridView.TabIndex = 1; + // + // FormRefills + // + AutoScaleDimensions = new SizeF(13F, 32F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1090, 634); + Controls.Add(dataGridView); + Controls.Add(panel1); + Name = "FormRefills"; + StartPosition = FormStartPosition.CenterParent; + Text = "Заправки"; + Load += FormRefills_Load; + panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Panel panel1; + private DataGridView dataGridView; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/ProjectFuel/Forms_/FormRefills.cs b/ProjectFuel/Forms_/FormRefills.cs new file mode 100644 index 0000000..f5fa5c0 --- /dev/null +++ b/ProjectFuel/Forms_/FormRefills.cs @@ -0,0 +1,64 @@ +using ProjectFuel.Entities; +using ProjectFuel.Repositories; +using ProjectFuel.Repositories.Implementations; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using Unity; + +namespace ProjectFuel.Forms_ +{ + public partial class FormRefills : Form + { + private readonly IUnityContainer _container; + + private readonly IRefillRepository _refillRepository; + public FormRefills(IUnityContainer container, IRefillRepository refillRepository) + { + InitializeComponent(); + _container = container ?? + throw new ArgumentNullException(nameof(container)); + + _refillRepository = refillRepository ?? + throw new ArgumentNullException(nameof(refillRepository)); + } + private void FormRefills_Load(object sender, EventArgs e) + { + try + { + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при добавлении", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + + + private void LoadList() => dataGridView.DataSource = _refillRepository.ReadRefills(); + + + } +} + diff --git a/ProjectFuel/Forms_/FormRefills.resx b/ProjectFuel/Forms_/FormRefills.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/ProjectFuel/Forms_/FormRefills.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ProjectFuel/Forms_/FormRoute.Designer.cs b/ProjectFuel/Forms_/FormRoute.Designer.cs new file mode 100644 index 0000000..9b84e37 --- /dev/null +++ b/ProjectFuel/Forms_/FormRoute.Designer.cs @@ -0,0 +1,143 @@ +namespace ProjectFuel.Forms_ +{ + partial class FormRoute + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + label1 = new Label(); + label2 = new Label(); + label3 = new Label(); + buttonRouteSave = new Button(); + buttonCancel = new Button(); + textBoxStartPoint = new TextBox(); + textBoxEndPoint = new TextBox(); + numericUpDownLength = new NumericUpDown(); + ((System.ComponentModel.ISupportInitialize)numericUpDownLength).BeginInit(); + SuspendLayout(); + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(38, 56); + label1.Name = "label1"; + label1.Size = new Size(201, 32); + label1.TabIndex = 0; + label1.Text = "Начальная точка"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(42, 130); + label2.Name = "label2"; + label2.Size = new Size(190, 32); + label2.TabIndex = 1; + label2.Text = "Конечная точка"; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(47, 207); + label3.Name = "label3"; + label3.Size = new Size(201, 32); + label3.TabIndex = 2; + label3.Text = "Длина маршрута"; + // + // buttonRouteSave + // + buttonRouteSave.Location = new Point(66, 337); + buttonRouteSave.Name = "buttonRouteSave"; + buttonRouteSave.Size = new Size(150, 46); + buttonRouteSave.TabIndex = 3; + buttonRouteSave.Text = "Сохранить"; + buttonRouteSave.UseVisualStyleBackColor = true; + buttonRouteSave.Click += ButtonRouteSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(367, 342); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(150, 46); + buttonCancel.TabIndex = 4; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // textBoxStartPoint + // + textBoxStartPoint.Location = new Point(307, 60); + textBoxStartPoint.Name = "textBoxStartPoint"; + textBoxStartPoint.Size = new Size(200, 39); + textBoxStartPoint.TabIndex = 5; + // + // textBoxEndPoint + // + textBoxEndPoint.Location = new Point(311, 130); + textBoxEndPoint.Name = "textBoxEndPoint"; + textBoxEndPoint.Size = new Size(200, 39); + textBoxEndPoint.TabIndex = 6; + // + // numericUpDownLength + // + numericUpDownLength.DecimalPlaces = 2; + numericUpDownLength.Location = new Point(308, 207); + numericUpDownLength.Name = "numericUpDownLength"; + numericUpDownLength.Size = new Size(240, 39); + numericUpDownLength.TabIndex = 7; + // + // FormRoute + // + AutoScaleDimensions = new SizeF(13F, 32F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(numericUpDownLength); + Controls.Add(textBoxEndPoint); + Controls.Add(textBoxStartPoint); + Controls.Add(buttonCancel); + Controls.Add(buttonRouteSave); + Controls.Add(label3); + Controls.Add(label2); + Controls.Add(label1); + Name = "FormRoute"; + StartPosition = FormStartPosition.CenterParent; + Text = "Маршрут"; + ((System.ComponentModel.ISupportInitialize)numericUpDownLength).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label label1; + private Label label2; + private Label label3; + private Button buttonRouteSave; + private Button buttonCancel; + private TextBox textBoxStartPoint; + private TextBox textBoxEndPoint; + private NumericUpDown numericUpDownLength; + } +} \ No newline at end of file diff --git a/ProjectFuel/Forms_/FormRoute.cs b/ProjectFuel/Forms_/FormRoute.cs new file mode 100644 index 0000000..2373827 --- /dev/null +++ b/ProjectFuel/Forms_/FormRoute.cs @@ -0,0 +1,76 @@ +using ProjectFuel.Entities; +using ProjectFuel.Repositories; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ProjectFuel.Forms_ +{ + public partial class FormRoute : Form + { + private readonly IRouteRepository _routeRepository; + + private int? _routeId; + + public int Id + { + set + { + try + { + var route = _routeRepository.ReadRouteByID(value); + if (route == null) + throw new InvalidOperationException(nameof(route)); + + textBoxStartPoint.Text = route.Start_Point; + textBoxEndPoint.Text = route.End_Point; + numericUpDownLength.Value = (decimal)route.Route_Length; + + _routeId = value; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + } + } + public FormRoute(IRouteRepository routeRepository) + { + InitializeComponent(); + _routeRepository = routeRepository ?? + throw new ArgumentNullException(nameof(routeRepository)); + } + private void ButtonRouteSave_Click(object sender, EventArgs e) + { + try + { + if (string.IsNullOrWhiteSpace(textBoxStartPoint.Text) || string.IsNullOrWhiteSpace(textBoxEndPoint.Text)) + throw new Exception("Имеются незаполненные поля"); + + if (_routeId.HasValue) + _routeRepository.UpdateRoute(CreateRoute(_routeId.Value)); + else + _routeRepository.CreateRoute(CreateRoute(0)); + + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonCancel_Click(object sender, EventArgs e) => Close(); + + private Route CreateRoute(int id) + { + return Route.CreateEntity(id, textBoxStartPoint.Text, textBoxEndPoint.Text, (float)numericUpDownLength.Value); + } + } +} diff --git a/ProjectFuel/Forms_/FormRoute.resx b/ProjectFuel/Forms_/FormRoute.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/ProjectFuel/Forms_/FormRoute.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ProjectFuel/Forms_/FormRoutes.Designer.cs b/ProjectFuel/Forms_/FormRoutes.Designer.cs new file mode 100644 index 0000000..a94341b --- /dev/null +++ b/ProjectFuel/Forms_/FormRoutes.Designer.cs @@ -0,0 +1,128 @@ +namespace ProjectFuel.Forms_ +{ + partial class FormRoutes + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + panel1 = new Panel(); + buttonDel = new Button(); + buttonUpd = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // panel1 + // + panel1.Controls.Add(buttonDel); + panel1.Controls.Add(buttonUpd); + panel1.Controls.Add(buttonAdd); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(583, 0); + panel1.Name = "panel1"; + panel1.Size = new Size(217, 450); + panel1.TabIndex = 0; + // + // buttonDel + // + buttonDel.BackgroundImage = Properties.Resources.удалять; + buttonDel.BackgroundImageLayout = ImageLayout.Stretch; + buttonDel.Location = new Point(41, 312); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(151, 126); + buttonDel.TabIndex = 9; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // buttonUpd + // + buttonUpd.BackgroundImage = Properties.Resources.ред; + buttonUpd.BackgroundImageLayout = ImageLayout.Stretch; + buttonUpd.Location = new Point(40, 184); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(152, 115); + buttonUpd.TabIndex = 8; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += ButtonUpd_Click; + // + // buttonAdd + // + buttonAdd.BackgroundImage = Properties.Resources._; + buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; + buttonAdd.Location = new Point(40, 33); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(151, 131); + buttonAdd.TabIndex = 7; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.AllowUserToResizeColumns = false; + dataGridView.AllowUserToResizeRows = false; + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Fill; + dataGridView.Location = new Point(0, 0); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 82; + dataGridView.RowTemplate.Height = 41; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(583, 450); + dataGridView.TabIndex = 1; + // + // FormRoutes + // + AutoScaleDimensions = new SizeF(13F, 32F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridView); + Controls.Add(panel1); + Name = "FormRoutes"; + StartPosition = FormStartPosition.CenterParent; + Text = "Маршруты"; + Load += FormRoutes_Load; + panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Panel panel1; + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonUpd; + private Button buttonDel; + } +} \ No newline at end of file diff --git a/ProjectFuel/Forms_/FormRoutes.cs b/ProjectFuel/Forms_/FormRoutes.cs new file mode 100644 index 0000000..5ed0e21 --- /dev/null +++ b/ProjectFuel/Forms_/FormRoutes.cs @@ -0,0 +1,103 @@ +using ProjectFuel.Repositories; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using Unity; + +namespace ProjectFuel.Forms_ +{ + public partial class FormRoutes : Form + { + private readonly IUnityContainer _container; + + private readonly IRouteRepository _routeRepository; + public FormRoutes(IUnityContainer container, IRouteRepository routeRepository) + { + InitializeComponent(); + _container = container ?? + throw new ArgumentNullException(nameof(container)); + _routeRepository = routeRepository ?? + throw new ArgumentNullException(nameof(routeRepository)); + } + private void FormRoutes_Load(object sender, EventArgs e) + { + try + { + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var findId)) + return; + + try + { + var form = _container.Resolve(); + form.Id = findId; + form.ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при изменении", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } + private void ButtonDel_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var findId)) + return; + + if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes) + return; + + try + { + _routeRepository.DeleteRoute(findId); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void LoadList() => dataGridView.DataSource = _routeRepository.ReadRoutes(); + + private bool TryGetIdentifierFromSelectedRow(out int id) + { + id = 0; + if (dataGridView.SelectedRows.Count < 1) + { + MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Route_ID"].Value); + return true; + } + } +} diff --git a/ProjectFuel/Forms_/FormRoutes.resx b/ProjectFuel/Forms_/FormRoutes.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/ProjectFuel/Forms_/FormRoutes.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ProjectFuel/Forms_/FormTrip.Designer.cs b/ProjectFuel/Forms_/FormTrip.Designer.cs new file mode 100644 index 0000000..eda1a4f --- /dev/null +++ b/ProjectFuel/Forms_/FormTrip.Designer.cs @@ -0,0 +1,265 @@ +namespace ProjectFuel.Forms_ +{ + partial class FormTrip + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + label1 = new Label(); + label2 = new Label(); + label3 = new Label(); + label4 = new Label(); + label5 = new Label(); + label6 = new Label(); + dateTimePickerStartDate = new DateTimePicker(); + dateTimePickerEndDate = new DateTimePicker(); + comboBoxShift = new ComboBox(); + numericUpDownConsumptionRate = new NumericUpDown(); + comboBoxCarID = new ComboBox(); + comboBoxDriverID = new ComboBox(); + buttonTripSave = new Button(); + buttonCancel = new Button(); + groupBox = new GroupBox(); + dataGridViewRoutes = new DataGridView(); + ColumnRoute = new DataGridViewComboBoxColumn(); + ColumnEndPoint = new DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)numericUpDownConsumptionRate).BeginInit(); + groupBox.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridViewRoutes).BeginInit(); + SuspendLayout(); + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(52, 38); + label1.Name = "label1"; + label1.Size = new Size(149, 32); + label1.TabIndex = 0; + label1.Text = "Дата начала"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(61, 104); + label2.Name = "label2"; + label2.Size = new Size(138, 32); + label2.TabIndex = 1; + label2.Text = "Дата конца"; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(62, 163); + label3.Name = "label3"; + label3.Size = new Size(85, 32); + label3.TabIndex = 2; + label3.Text = "Смена"; + // + // label4 + // + label4.AutoSize = true; + label4.Location = new Point(59, 219); + label4.Name = "label4"; + label4.Size = new Size(185, 32); + label4.TabIndex = 3; + label4.Text = "Расход топлива"; + // + // label5 + // + label5.AutoSize = true; + label5.Location = new Point(55, 276); + label5.Name = "label5"; + label5.Size = new Size(107, 32); + label5.TabIndex = 4; + label5.Text = "Машина"; + // + // label6 + // + label6.AutoSize = true; + label6.Location = new Point(61, 339); + label6.Name = "label6"; + label6.Size = new Size(117, 32); + label6.TabIndex = 5; + label6.Text = "Водитель"; + // + // dateTimePickerStartDate + // + dateTimePickerStartDate.Location = new Point(303, 31); + dateTimePickerStartDate.Name = "dateTimePickerStartDate"; + dateTimePickerStartDate.Size = new Size(400, 39); + dateTimePickerStartDate.TabIndex = 6; + // + // dateTimePickerEndDate + // + dateTimePickerEndDate.Location = new Point(295, 106); + dateTimePickerEndDate.Name = "dateTimePickerEndDate"; + dateTimePickerEndDate.Size = new Size(400, 39); + dateTimePickerEndDate.TabIndex = 7; + // + // comboBoxShift + // + comboBoxShift.FormattingEnabled = true; + comboBoxShift.Location = new Point(292, 171); + comboBoxShift.Name = "comboBoxShift"; + comboBoxShift.Size = new Size(242, 40); + comboBoxShift.TabIndex = 8; + // + // numericUpDownConsumptionRate + // + numericUpDownConsumptionRate.Location = new Point(288, 232); + numericUpDownConsumptionRate.Name = "numericUpDownConsumptionRate"; + numericUpDownConsumptionRate.Size = new Size(240, 39); + numericUpDownConsumptionRate.TabIndex = 9; + // + // comboBoxCarID + // + comboBoxCarID.FormattingEnabled = true; + comboBoxCarID.Location = new Point(281, 288); + comboBoxCarID.Name = "comboBoxCarID"; + comboBoxCarID.Size = new Size(242, 40); + comboBoxCarID.TabIndex = 10; + // + // comboBoxDriverID + // + comboBoxDriverID.FormattingEnabled = true; + comboBoxDriverID.Location = new Point(274, 348); + comboBoxDriverID.Name = "comboBoxDriverID"; + comboBoxDriverID.Size = new Size(242, 40); + comboBoxDriverID.TabIndex = 11; + // + // buttonTripSave + // + buttonTripSave.Location = new Point(79, 649); + buttonTripSave.Name = "buttonTripSave"; + buttonTripSave.Size = new Size(150, 46); + buttonTripSave.TabIndex = 14; + buttonTripSave.Text = "Сохранить"; + buttonTripSave.UseVisualStyleBackColor = true; + buttonTripSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(346, 649); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(150, 46); + buttonCancel.TabIndex = 15; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // groupBox + // + groupBox.Controls.Add(dataGridViewRoutes); + groupBox.Location = new Point(52, 421); + groupBox.Name = "groupBox"; + groupBox.Size = new Size(410, 222); + groupBox.TabIndex = 16; + groupBox.TabStop = false; + groupBox.Text = "Маршруты"; + // + // dataGridViewRoutes + // + dataGridViewRoutes.AllowUserToResizeColumns = false; + dataGridViewRoutes.AllowUserToResizeRows = false; + dataGridViewRoutes.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewRoutes.Columns.AddRange(new DataGridViewColumn[] { ColumnRoute, ColumnEndPoint }); + dataGridViewRoutes.Dock = DockStyle.Fill; + dataGridViewRoutes.Location = new Point(3, 35); + dataGridViewRoutes.Margin = new Padding(5); + dataGridViewRoutes.MultiSelect = false; + dataGridViewRoutes.Name = "dataGridViewRoutes"; + dataGridViewRoutes.RowHeadersVisible = false; + dataGridViewRoutes.RowHeadersWidth = 51; + dataGridViewRoutes.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridViewRoutes.Size = new Size(404, 184); + dataGridViewRoutes.TabIndex = 1; + // + // ColumnRoute + // + ColumnRoute.HeaderText = "Маршрут"; + ColumnRoute.MinimumWidth = 6; + ColumnRoute.Name = "ColumnRoute"; + ColumnRoute.Width = 125; + // + // ColumnEndPoint + // + ColumnEndPoint.HeaderText = "Конечная точка"; + ColumnEndPoint.MinimumWidth = 6; + ColumnEndPoint.Name = "ColumnEndPoint"; + ColumnEndPoint.Width = 125; + // + // FormTrip + // + AutoScaleDimensions = new SizeF(13F, 32F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(843, 745); + Controls.Add(groupBox); + Controls.Add(buttonCancel); + Controls.Add(buttonTripSave); + Controls.Add(comboBoxDriverID); + Controls.Add(comboBoxCarID); + Controls.Add(numericUpDownConsumptionRate); + Controls.Add(comboBoxShift); + Controls.Add(dateTimePickerEndDate); + Controls.Add(dateTimePickerStartDate); + Controls.Add(label6); + Controls.Add(label5); + Controls.Add(label4); + Controls.Add(label3); + Controls.Add(label2); + Controls.Add(label1); + Name = "FormTrip"; + StartPosition = FormStartPosition.CenterParent; + Text = "FormTrip"; + ((System.ComponentModel.ISupportInitialize)numericUpDownConsumptionRate).EndInit(); + groupBox.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridViewRoutes).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label label1; + private Label label2; + private Label label3; + private Label label4; + private Label label5; + private Label label6; + private DateTimePicker dateTimePickerStartDate; + private DateTimePicker dateTimePickerEndDate; + private ComboBox comboBoxShift; + private NumericUpDown numericUpDownConsumptionRate; + private ComboBox comboBoxCarID; + private ComboBox comboBoxDriverID; + private Button buttonTripSave; + private Button buttonCancel; + private GroupBox groupBox; + private DataGridView dataGridViewRoutes; + private DataGridViewComboBoxColumn ColumnRoute; + private DataGridViewTextBoxColumn ColumnEndPoint; + } +} \ No newline at end of file diff --git a/ProjectFuel/Forms_/FormTrip.cs b/ProjectFuel/Forms_/FormTrip.cs new file mode 100644 index 0000000..32b1327 --- /dev/null +++ b/ProjectFuel/Forms_/FormTrip.cs @@ -0,0 +1,76 @@ +using ProjectFuel.Entities.Enums; +using ProjectFuel.Entities; +using ProjectFuel.Repositories; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using ProjectFuel.Repositories.Implementations; + +namespace ProjectFuel.Forms_ +{ + public partial class FormTrip : Form + { + private readonly ITripRepository _tripRepository; + + + public FormTrip(ITripRepository tripRepository, ICarRepository carRepository, IDriverRepository driverRepository, IRouteRepository routeRepository) + { + InitializeComponent(); + _tripRepository = tripRepository ?? + throw new ArgumentNullException(nameof(tripRepository)); + + comboBoxCarID.DataSource = tripRepository.ReadTrips(); + comboBoxCarID.DisplayMember = "Car_Mark"; + comboBoxCarID.ValueMember = "Car_ID"; + + comboBoxDriverID.DataSource = tripRepository.ReadTrips(); + comboBoxDriverID.DisplayMember = "Firstname"; + comboBoxDriverID.ValueMember = "Driver_ID"; + + ColumnRoute.DataSource = routeRepository.ReadRoutes(); + ColumnRoute.DisplayMember = "Start_Point"; + ColumnRoute.ValueMember = "Route_ID"; + + + + } + private void ButtonSave_Click(object sender, EventArgs e) + { + try + { + if (comboBoxCarID.SelectedIndex < 0 || comboBoxDriverID.SelectedIndex < 0 || dataGridViewRoutes.RowCount < 0) + throw new Exception("Имеются незаполненные поля"); + + _tripRepository.CreateTrip(Trip.CreateOperation(0, dateTimePickerStartDate.Value, dateTimePickerEndDate.Value, (Shift)comboBoxShift.SelectedItem!, (float)numericUpDownConsumptionRate.Value, (int)comboBoxCarID.SelectedValue!, (int)comboBoxDriverID.SelectedValue!, CreateListDriversFromDataGrid())); + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } + + private void ButtonCancel_Click(object sender, EventArgs e) => Close(); + private List CreateListDriversFromDataGrid() + { + var list = new List(); + foreach (DataGridViewRow row in dataGridViewRoutes.Rows) + { + if (row.Cells["ColumnRoute"].Value == null || row.Cells["ColumnEndPoint"].Value == null) + continue; + + list.Add(Route.CreateEntity(0, (string)row.Cells["ColumnRoute"].Value, (string)row.Cells["ColumnEndPoint"].Value, 0)); + } + return list; + } + + } +} diff --git a/ProjectFuel/Forms_/FormTrip.resx b/ProjectFuel/Forms_/FormTrip.resx new file mode 100644 index 0000000..ceabb79 --- /dev/null +++ b/ProjectFuel/Forms_/FormTrip.resx @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + True + + + True + + \ No newline at end of file diff --git a/ProjectFuel/Forms_/FormTrips.Designer.cs b/ProjectFuel/Forms_/FormTrips.Designer.cs new file mode 100644 index 0000000..08a484e --- /dev/null +++ b/ProjectFuel/Forms_/FormTrips.Designer.cs @@ -0,0 +1,100 @@ +namespace ProjectFuel.Forms_ +{ + partial class FormTrips + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + panel1 = new Panel(); + buttonAdd = new Button(); + dataGridViewTrips = new DataGridView(); + panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridViewTrips).BeginInit(); + SuspendLayout(); + // + // panel1 + // + panel1.Controls.Add(buttonAdd); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(545, 0); + panel1.Name = "panel1"; + panel1.Size = new Size(255, 450); + panel1.TabIndex = 0; + // + // buttonAdd + // + buttonAdd.BackgroundImage = Properties.Resources._; + buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; + buttonAdd.Location = new Point(45, 42); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(151, 131); + buttonAdd.TabIndex = 8; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridViewTrips + // + dataGridViewTrips.AllowUserToAddRows = false; + dataGridViewTrips.AllowUserToDeleteRows = false; + dataGridViewTrips.AllowUserToResizeColumns = false; + dataGridViewTrips.AllowUserToResizeRows = false; + dataGridViewTrips.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridViewTrips.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewTrips.Dock = DockStyle.Fill; + dataGridViewTrips.Location = new Point(0, 0); + dataGridViewTrips.MultiSelect = false; + dataGridViewTrips.Name = "dataGridViewTrips"; + dataGridViewTrips.ReadOnly = true; + dataGridViewTrips.RowHeadersVisible = false; + dataGridViewTrips.RowHeadersWidth = 82; + dataGridViewTrips.RowTemplate.Height = 41; + dataGridViewTrips.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridViewTrips.Size = new Size(545, 450); + dataGridViewTrips.TabIndex = 1; + // + // FormTrips + // + AutoScaleDimensions = new SizeF(13F, 32F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridViewTrips); + Controls.Add(panel1); + Name = "FormTrips"; + StartPosition = FormStartPosition.CenterParent; + Text = " Поездки"; + Load += FormTrips_Load; + panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridViewTrips).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Panel panel1; + private DataGridView dataGridViewTrips; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/ProjectFuel/Forms_/FormTrips.cs b/ProjectFuel/Forms_/FormTrips.cs new file mode 100644 index 0000000..8a375d1 --- /dev/null +++ b/ProjectFuel/Forms_/FormTrips.cs @@ -0,0 +1,57 @@ +using ProjectFuel.Repositories; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using Unity; + +namespace ProjectFuel.Forms_ +{ + public partial class FormTrips : Form + + { + private readonly IUnityContainer _container; + + private readonly ITripRepository _tripRepository; + public FormTrips(IUnityContainer container, ITripRepository tripRepository) + { + InitializeComponent(); + _container = container ?? + throw new ArgumentNullException(nameof(container)); + + _tripRepository = tripRepository ?? + throw new ArgumentNullException(nameof(tripRepository)); + } + private void FormTrips_Load(object sender, EventArgs e) + { + try + { + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при добавлении", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void LoadList() => dataGridViewTrips.DataSource = _tripRepository.ReadTrips(); + } +} diff --git a/ProjectFuel/Forms_/FormTrips.resx b/ProjectFuel/Forms_/FormTrips.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/ProjectFuel/Forms_/FormTrips.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ProjectFuel/Program.cs b/ProjectFuel/Program.cs index 3a4d952..6bd336e 100644 --- a/ProjectFuel/Program.cs +++ b/ProjectFuel/Program.cs @@ -1,3 +1,7 @@ +using ProjectFuel.Repositories.Implementations; +using ProjectFuel.Repositories; +using Unity; + namespace ProjectFuel { internal static class Program @@ -11,7 +15,20 @@ namespace ProjectFuel // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + Application.Run(CreateContainer().Resolve()); + } + private static UnityContainer CreateContainer() + { + var container = new UnityContainer(); + + container.RegisterType(); + container.RegisterType(); + container.RegisterType(); + container.RegisterType(); + container.RegisterType(); + container.RegisterType(); + + return container; } } } \ No newline at end of file diff --git a/ProjectFuel/ProjectFuel.csproj b/ProjectFuel/ProjectFuel.csproj index e1a0735..e32799a 100644 --- a/ProjectFuel/ProjectFuel.csproj +++ b/ProjectFuel/ProjectFuel.csproj @@ -8,4 +8,23 @@ enable + + + + + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + \ No newline at end of file diff --git a/ProjectFuel/Properties/Resources.Designer.cs b/ProjectFuel/Properties/Resources.Designer.cs new file mode 100644 index 0000000..6727fd2 --- /dev/null +++ b/ProjectFuel/Properties/Resources.Designer.cs @@ -0,0 +1,113 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан программой. +// Исполняемая версия:4.0.30319.42000 +// +// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае +// повторной генерации кода. +// +//------------------------------------------------------------------------------ + +namespace ProjectFuel.Properties { + using System; + + + /// + /// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д. + /// + // Этот класс создан автоматически классом StronglyTypedResourceBuilder + // с помощью такого средства, как ResGen или Visual Studio. + // Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen + // с параметром /str или перестройте свой проект VS. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ProjectFuel.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Перезаписывает свойство CurrentUICulture текущего потока для всех + /// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap _ { + get { + object obj = ResourceManager.GetObject("+", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap плюс { + get { + object obj = ResourceManager.GetObject("плюс", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap ред { + get { + object obj = ResourceManager.GetObject("ред", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap топливо { + get { + object obj = ResourceManager.GetObject("топливо", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap удалять { + get { + object obj = ResourceManager.GetObject("удалять", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + } +} diff --git a/ProjectFuel/Properties/Resources.resx b/ProjectFuel/Properties/Resources.resx new file mode 100644 index 0000000..6e3c36e --- /dev/null +++ b/ProjectFuel/Properties/Resources.resx @@ -0,0 +1,136 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + ..\Resources\+.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\удалять.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\плюс.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\топливо.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\ред.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + \ No newline at end of file diff --git a/ProjectFuel/Properties/launchSettings.json b/ProjectFuel/Properties/launchSettings.json new file mode 100644 index 0000000..a37f626 --- /dev/null +++ b/ProjectFuel/Properties/launchSettings.json @@ -0,0 +1,8 @@ +{ + "profiles": { + "ProjectFuel": { + "commandName": "Project", + "workingDirectory": "C:\\Users\\annny\\OneDrive\\Рабочий стол\\ОТП" + } + } +} \ No newline at end of file diff --git a/ProjectFuel/Repositories/ICarRepository.cs b/ProjectFuel/Repositories/ICarRepository.cs new file mode 100644 index 0000000..6a64ce9 --- /dev/null +++ b/ProjectFuel/Repositories/ICarRepository.cs @@ -0,0 +1,17 @@ +using ProjectFuel.Entities; +using ProjectFuel.Entities; + +namespace ProjectFuel.Repositories; + +public interface ICarRepository +{ + IEnumerable ReadCars(); + + Car ReadCarByID(int id); + + void CreateCar(Car car); + + void UpdateCar(Car car); + + void DeleteCar(int id); +} diff --git a/ProjectFuel/Repositories/IDriverRepository.cs b/ProjectFuel/Repositories/IDriverRepository.cs new file mode 100644 index 0000000..f79ebe6 --- /dev/null +++ b/ProjectFuel/Repositories/IDriverRepository.cs @@ -0,0 +1,17 @@ +using ProjectFuel.Entities; +using ProjectFuel.Entities; + +namespace ProjectFuel.Repositories; + +public interface IDriverRepository +{ + IEnumerable ReadDrivers(); + + Driver ReadDriverByID(int id); + + void CreateDriver(Driver driver); + + void UpdateDriver(Driver driver); + + void DeleteDriver(int id); +} diff --git a/ProjectFuel/Repositories/IFuelRepository.cs b/ProjectFuel/Repositories/IFuelRepository.cs new file mode 100644 index 0000000..3a975db --- /dev/null +++ b/ProjectFuel/Repositories/IFuelRepository.cs @@ -0,0 +1,16 @@ +using ProjectFuel.Entities; + +namespace ProjectFuel.Repositories; + +public interface IFuelRepository +{ + IEnumerable ReadFuels(); + + Fuel ReadFuelByID(int id); + + void CreateFuel(Fuel fuel); + + void UpdateFuel(Fuel fuel); + + void DeleteFuel(int id); +} diff --git a/ProjectFuel/Repositories/IRefillRepository.cs b/ProjectFuel/Repositories/IRefillRepository.cs new file mode 100644 index 0000000..6a40239 --- /dev/null +++ b/ProjectFuel/Repositories/IRefillRepository.cs @@ -0,0 +1,11 @@ +using ProjectFuel.Entities; +using ProjectFuel.Entities; + +namespace ProjectFuel.Repositories; + +public interface IRefillRepository +{ + IEnumerable ReadRefills(DateTime? dateFrom = null, DateTime? dateTo = null, int? fuelId = null, int? carId = null); + + void CreateRefill(Refill refill); +} diff --git a/ProjectFuel/Repositories/IRouteRepository.cs b/ProjectFuel/Repositories/IRouteRepository.cs new file mode 100644 index 0000000..784dfb2 --- /dev/null +++ b/ProjectFuel/Repositories/IRouteRepository.cs @@ -0,0 +1,17 @@ +using ProjectFuel.Entities; +using ProjectFuel.Entities; + +namespace ProjectFuel.Repositories; + +public interface IRouteRepository +{ + IEnumerable ReadRoutes(); + + Route ReadRouteByID(int id); + + void CreateRoute(Route route); + + void UpdateRoute(Route route); + + void DeleteRoute(int id); +} diff --git a/ProjectFuel/Repositories/ITripRepository.cs b/ProjectFuel/Repositories/ITripRepository.cs new file mode 100644 index 0000000..dfff4a2 --- /dev/null +++ b/ProjectFuel/Repositories/ITripRepository.cs @@ -0,0 +1,11 @@ +using ProjectFuel.Entities; +using ProjectFuel.Entities; + +namespace ProjectFuel.Repositories; + +public interface ITripRepository +{ + IEnumerable ReadTrips(DateTime? dateFrom = null, DateTime? dateTo = null, int? carId = null, int? driverId = null, int? routeId = null); + + void CreateTrip(Trip trip); +} diff --git a/ProjectFuel/Repositories/Implementations/CarRepository.cs b/ProjectFuel/Repositories/Implementations/CarRepository.cs new file mode 100644 index 0000000..dbf7c09 --- /dev/null +++ b/ProjectFuel/Repositories/Implementations/CarRepository.cs @@ -0,0 +1,30 @@ +using ProjectFuel.Entities; +using ProjectFuel.Entities; +using ProjectFuel.Repositories; + +namespace ProjectFuel.Repositories.Implementations; + +public class CarRepository : ICarRepository +{ + public void CreateCar(Car car) + { + } + + public void DeleteCar(int id) + { + } + + public Car ReadCarByID(int id) + { + return Car.CreateEntity(0, string.Empty, string.Empty, 0, 0, 0); + } + + public IEnumerable ReadCars() + { + return new List(); + } + + public void UpdateCar(Car car) + { + } +} diff --git a/ProjectFuel/Repositories/Implementations/DriverRepository.cs b/ProjectFuel/Repositories/Implementations/DriverRepository.cs new file mode 100644 index 0000000..e2b2280 --- /dev/null +++ b/ProjectFuel/Repositories/Implementations/DriverRepository.cs @@ -0,0 +1,30 @@ +using ProjectFuel.Entities; +using ProjectFuel.Entities; +using ProjectFuel.Repositories; + +namespace ProjectFuel.Repositories.Implementations; + +public class DriverRepository : IDriverRepository +{ + public void CreateDriver(Driver driver) + { + } + + public void DeleteDriver(int id) + { + } + + public Driver ReadDriverByID(int id) + { + return Driver.CreateEntity(0, string.Empty, string.Empty, 0); + } + + public IEnumerable ReadDrivers() + { + return new List(); + } + + public void UpdateDriver(Driver driver) + { + } +} diff --git a/ProjectFuel/Repositories/Implementations/FuelRepository.cs b/ProjectFuel/Repositories/Implementations/FuelRepository.cs new file mode 100644 index 0000000..0cafe71 --- /dev/null +++ b/ProjectFuel/Repositories/Implementations/FuelRepository.cs @@ -0,0 +1,29 @@ +using ProjectFuel.Entities; +using ProjectFuel.Repositories; + +namespace ProjectFuel.Repositories.Implementations; + +public class FuelRepository : IFuelRepository +{ + public void CreateFuel(Fuel fuel) + { + } + + public void DeleteFuel(int id) + { + } + + public Fuel ReadFuelByID(int id) + { + return Fuel.CreateEntity(0, 0, 0, 0); + } + + public IEnumerable ReadFuels() + { + return new List(); + } + + public void UpdateFuel(Fuel fuel) + { + } +} diff --git a/ProjectFuel/Repositories/Implementations/RefillRepository.cs b/ProjectFuel/Repositories/Implementations/RefillRepository.cs new file mode 100644 index 0000000..557c24b --- /dev/null +++ b/ProjectFuel/Repositories/Implementations/RefillRepository.cs @@ -0,0 +1,17 @@ +using ProjectFuel.Entities; +using ProjectFuel.Entities; +using ProjectFuel.Repositories; + +namespace ProjectFuel.Repositories.Implementations; + +public class RefillRepository : IRefillRepository +{ + public void CreateRefill(Refill refill) + { + } + + public IEnumerable ReadRefills(DateTime? dateFrom = null, DateTime? dateTo = null, int? fuelId = null, int? carId = null) + { + return new List(); + } +} diff --git a/ProjectFuel/Repositories/Implementations/RouteRepository.cs b/ProjectFuel/Repositories/Implementations/RouteRepository.cs new file mode 100644 index 0000000..7d070b5 --- /dev/null +++ b/ProjectFuel/Repositories/Implementations/RouteRepository.cs @@ -0,0 +1,30 @@ +using ProjectFuel.Entities; +using ProjectFuel.Entities; +using ProjectFuel.Repositories; + +namespace ProjectFuel.Repositories.Implementations; + +public class RouteRepository : IRouteRepository +{ + public void CreateRoute(Route route) + { + } + + public void DeleteRoute(int id) + { + } + + public Route ReadRouteByID(int id) + { + return Route.CreateEntity(0, string.Empty, string.Empty, 0); + } + + public IEnumerable ReadRoutes() + { + return new List(); + } + + public void UpdateRoute(Route route) + { + } +} diff --git a/ProjectFuel/Repositories/Implementations/TripRepository.cs b/ProjectFuel/Repositories/Implementations/TripRepository.cs new file mode 100644 index 0000000..6b6333e --- /dev/null +++ b/ProjectFuel/Repositories/Implementations/TripRepository.cs @@ -0,0 +1,17 @@ +using ProjectFuel.Entities; +using ProjectFuel.Entities; +using ProjectFuel.Repositories; + +namespace ProjectFuel.Repositories.Implementations; + +public class TripRepository : ITripRepository +{ + public void CreateTrip(Trip trip) + { + } + + public IEnumerable ReadTrips(DateTime? dateFrom = null, DateTime? dateTo = null, int? carId = null, int? driverId = null, int? routeId = null) + { + return new List(); + } +} diff --git a/ProjectFuel/Resources/+.jpg b/ProjectFuel/Resources/+.jpg new file mode 100644 index 0000000..54a98ea Binary files /dev/null and b/ProjectFuel/Resources/+.jpg differ diff --git a/ProjectFuel/Resources/плюс.png b/ProjectFuel/Resources/плюс.png new file mode 100644 index 0000000..95bb2f3 Binary files /dev/null and b/ProjectFuel/Resources/плюс.png differ diff --git a/ProjectFuel/Resources/ред.png b/ProjectFuel/Resources/ред.png new file mode 100644 index 0000000..e40366a Binary files /dev/null and b/ProjectFuel/Resources/ред.png differ diff --git a/ProjectFuel/Resources/топливо.jpg b/ProjectFuel/Resources/топливо.jpg new file mode 100644 index 0000000..52d3bc1 Binary files /dev/null and b/ProjectFuel/Resources/топливо.jpg differ diff --git a/ProjectFuel/Resources/удалять.png b/ProjectFuel/Resources/удалять.png new file mode 100644 index 0000000..6fa7988 Binary files /dev/null and b/ProjectFuel/Resources/удалять.png differ