From c1d186328c94275aa1d4d2f746f8c9493609aefd Mon Sep 17 00:00:00 2001 From: F1rsTTeaM Date: Sun, 17 Nov 2024 17:43:43 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D1=84=D0=BE=D1=80=D0=BC=D1=8B=20=D0=BF=D0=BE=D0=B5?= =?UTF-8?q?=D0=B7=D0=B4=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Forms/FormTrip.Designer.cs | 241 ++++++++++++++++++ .../FuelAndLubricants/Forms/FormTrip.cs | 48 ++++ .../FuelAndLubricants/Forms/FormTrip.resx | 120 +++++++++ 3 files changed, 409 insertions(+) create mode 100644 FuelAndLubricants/FuelAndLubricants/Forms/FormTrip.Designer.cs create mode 100644 FuelAndLubricants/FuelAndLubricants/Forms/FormTrip.cs create mode 100644 FuelAndLubricants/FuelAndLubricants/Forms/FormTrip.resx diff --git a/FuelAndLubricants/FuelAndLubricants/Forms/FormTrip.Designer.cs b/FuelAndLubricants/FuelAndLubricants/Forms/FormTrip.Designer.cs new file mode 100644 index 0000000..dd45466 --- /dev/null +++ b/FuelAndLubricants/FuelAndLubricants/Forms/FormTrip.Designer.cs @@ -0,0 +1,241 @@ +namespace FuelAndLubricants.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() + { + label5 = new Label(); + numericUpDownConsumptionRate = new NumericUpDown(); + label4 = new Label(); + comboBoxShift = new ComboBox(); + buttonCancel = new Button(); + buttonTripSave = new Button(); + label6 = new Label(); + dateTimePickerStartDate = new DateTimePicker(); + label1 = new Label(); + dateTimePickerEndDate = new DateTimePicker(); + label3 = new Label(); + comboBoxCarID = new ComboBox(); + comboBoxDriverID = new ComboBox(); + label2 = new Label(); + comboBoxRouteID = new ComboBox(); + label7 = new Label(); + ((System.ComponentModel.ISupportInitialize)numericUpDownConsumptionRate).BeginInit(); + SuspendLayout(); + // + // label5 + // + label5.AutoSize = true; + label5.Location = new Point(9, 100); + label5.Name = "label5"; + label5.Size = new Size(93, 15); + label5.TabIndex = 33; + label5.Text = "Расход топлива"; + // + // numericUpDownConsumptionRate + // + numericUpDownConsumptionRate.DecimalPlaces = 2; + numericUpDownConsumptionRate.Location = new Point(107, 98); + numericUpDownConsumptionRate.Maximum = new decimal(new int[] { 10000, 0, 0, 0 }); + numericUpDownConsumptionRate.Minimum = new decimal(new int[] { 1, 0, 0, 131072 }); + numericUpDownConsumptionRate.Name = "numericUpDownConsumptionRate"; + numericUpDownConsumptionRate.Size = new Size(140, 23); + numericUpDownConsumptionRate.TabIndex = 32; + numericUpDownConsumptionRate.Value = new decimal(new int[] { 1, 0, 0, 131072 }); + // + // label4 + // + label4.AutoSize = true; + label4.Location = new Point(9, 73); + label4.Name = "label4"; + label4.Size = new Size(43, 15); + label4.TabIndex = 31; + label4.Text = "Смена"; + // + // comboBoxShift + // + comboBoxShift.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxShift.FormattingEnabled = true; + comboBoxShift.Location = new Point(107, 70); + comboBoxShift.Name = "comboBoxShift"; + comboBoxShift.Size = new Size(140, 23); + comboBoxShift.TabIndex = 30; + // + // buttonCancel + // + buttonCancel.Location = new Point(172, 226); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 28; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // buttonTripSave + // + buttonTripSave.Location = new Point(9, 226); + buttonTripSave.Name = "buttonTripSave"; + buttonTripSave.Size = new Size(75, 23); + buttonTripSave.TabIndex = 27; + buttonTripSave.Text = "Сохранить"; + buttonTripSave.UseVisualStyleBackColor = true; + buttonTripSave.Click += ButtonSave_Click; + // + // label6 + // + label6.AutoSize = true; + label6.Location = new Point(9, 18); + label6.Name = "label6"; + label6.Size = new Size(74, 15); + label6.TabIndex = 37; + label6.Text = "Дата начала"; + // + // dateTimePickerStartDate + // + dateTimePickerStartDate.Location = new Point(107, 12); + dateTimePickerStartDate.Name = "dateTimePickerStartDate"; + dateTimePickerStartDate.Size = new Size(140, 23); + dateTimePickerStartDate.TabIndex = 36; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(9, 47); + label1.Name = "label1"; + label1.Size = new Size(68, 15); + label1.TabIndex = 39; + label1.Text = "Дата конца"; + // + // dateTimePickerEndDate + // + dateTimePickerEndDate.Location = new Point(107, 41); + dateTimePickerEndDate.Name = "dateTimePickerEndDate"; + dateTimePickerEndDate.Size = new Size(140, 23); + dateTimePickerEndDate.TabIndex = 38; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(9, 130); + label3.Name = "label3"; + label3.Size = new Size(55, 15); + label3.TabIndex = 42; + label3.Text = "Машина"; + // + // comboBoxCarID + // + comboBoxCarID.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxCarID.FormattingEnabled = true; + comboBoxCarID.Location = new Point(107, 127); + comboBoxCarID.Name = "comboBoxCarID"; + comboBoxCarID.Size = new Size(140, 23); + comboBoxCarID.TabIndex = 41; + // + // comboBoxDriverID + // + comboBoxDriverID.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxDriverID.FormattingEnabled = true; + comboBoxDriverID.Location = new Point(107, 157); + comboBoxDriverID.Name = "comboBoxDriverID"; + comboBoxDriverID.Size = new Size(140, 23); + comboBoxDriverID.TabIndex = 46; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(9, 189); + label2.Name = "label2"; + label2.Size = new Size(60, 15); + label2.TabIndex = 45; + label2.Text = "Маршрут"; + // + // comboBoxRouteID + // + comboBoxRouteID.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxRouteID.FormattingEnabled = true; + comboBoxRouteID.Location = new Point(107, 186); + comboBoxRouteID.Name = "comboBoxRouteID"; + comboBoxRouteID.Size = new Size(140, 23); + comboBoxRouteID.TabIndex = 44; + // + // label7 + // + label7.AutoSize = true; + label7.Location = new Point(9, 160); + label7.Name = "label7"; + label7.Size = new Size(58, 15); + label7.TabIndex = 43; + label7.Text = "Водитель"; + // + // FormTrip + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(259, 266); + Controls.Add(comboBoxDriverID); + Controls.Add(label2); + Controls.Add(comboBoxRouteID); + Controls.Add(label7); + Controls.Add(label3); + Controls.Add(comboBoxCarID); + Controls.Add(label1); + Controls.Add(dateTimePickerEndDate); + Controls.Add(label6); + Controls.Add(dateTimePickerStartDate); + Controls.Add(label5); + Controls.Add(numericUpDownConsumptionRate); + Controls.Add(label4); + Controls.Add(comboBoxShift); + Controls.Add(buttonCancel); + Controls.Add(buttonTripSave); + Name = "FormTrip"; + Text = "FormTrip"; + ((System.ComponentModel.ISupportInitialize)numericUpDownConsumptionRate).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label label5; + private NumericUpDown numericUpDownConsumptionRate; + private Label label4; + private ComboBox comboBoxShift; + private Button buttonCancel; + private Button buttonTripSave; + private Label label6; + private DateTimePicker dateTimePickerStartDate; + private Label label1; + private DateTimePicker dateTimePickerEndDate; + private Label label3; + private ComboBox comboBoxCarID; + private ComboBox comboBoxDriverID; + private Label label2; + private ComboBox comboBoxRouteID; + private Label label7; + } +} \ No newline at end of file diff --git a/FuelAndLubricants/FuelAndLubricants/Forms/FormTrip.cs b/FuelAndLubricants/FuelAndLubricants/Forms/FormTrip.cs new file mode 100644 index 0000000..fe5800e --- /dev/null +++ b/FuelAndLubricants/FuelAndLubricants/Forms/FormTrip.cs @@ -0,0 +1,48 @@ +using FuelAndLubricants.Entities; +using FuelAndLubricants.Entities.Enums; +using FuelAndLubricants.Repositories; + +namespace FuelAndLubricants.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"; + + comboBoxRouteID.DataSource = tripRepository.ReadTrips(); + comboBoxRouteID.DisplayMember = "Route_Length"; + comboBoxRouteID.ValueMember = "Route_ID"; + } + private void ButtonSave_Click(object sender, EventArgs e) + { + try + { + if (comboBoxCarID.SelectedIndex < 0 || comboBoxDriverID.SelectedIndex < 0 || comboBoxRouteID.SelectedIndex < 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!, (int)comboBoxRouteID.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/FuelAndLubricants/FuelAndLubricants/Forms/FormTrip.resx b/FuelAndLubricants/FuelAndLubricants/Forms/FormTrip.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/FuelAndLubricants/FuelAndLubricants/Forms/FormTrip.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