diff --git a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Entities/Bus.cs b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Entities/Bus.cs index d82eb47..c9d4d87 100644 --- a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Entities/Bus.cs +++ b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Entities/Bus.cs @@ -1,4 +1,5 @@ -using System; +using PIbd_24_EredavkinRA_BusBusiness.Entities.Enums; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -9,17 +10,17 @@ namespace PIbd_24_EredavkinRA_BusBusiness.Entities; public class Bus { public int Id { get; private set; } - public string Model { get; private set; } = string.Empty; + public ModelType ModelType { get; private set; } public string N_Z { get; private set; } = string.Empty; public int Capacity { get; private set; } - public int Bus_mileage { get; private set; } + public double Bus_mileage { get; private set; } - public static Bus CreateEntity(int id, string model, string n_z, int capacity, int bus_mileage) + public static Bus CreateEntity(int id, ModelType modeltype, string n_z, double bus_mileage, int capacity) { return new Bus { Id = id, - Model = model ?? string.Empty, + ModelType = modeltype, N_Z = n_z ?? string.Empty, Capacity = capacity, Bus_mileage = bus_mileage diff --git a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Entities/RoutSheet.cs b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Entities/RoutSheet.cs index 5c67661..d6057f0 100644 --- a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Entities/RoutSheet.cs +++ b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Entities/RoutSheet.cs @@ -9,23 +9,23 @@ namespace PIbd_24_EredavkinRA_BusBusiness.Entities; public class RoutSheet { public int Id { get; private set; } - - public int RoutId { get; private set; } - - public IEnumerable RoutSheetBuses { get; private set; } = []; public int DriverId { get; private set; } public int ConductorId { get; private set; } + public int RoutId { get; private set; } + + public IEnumerable RoutSheetBus { get; private set; } = []; + public DateTime BusDate { get; private set; } - public static RoutSheet CreatOpeartion(int id, int routid, int driverid, int conductorid, IEnumerable RoutSheetBuses) + public static RoutSheet CreatOpeartion(int id, int driverid, int conductorid, int routid, DateTime busDate, IEnumerable RoutSheetBus) { return new RoutSheet { Id = id, - RoutId = routid, - RoutSheetBuses = RoutSheetBuses, DriverId = driverid, ConductorId = conductorid, - BusDate = DateTime.Now + RoutId = routid, + RoutSheetBus = RoutSheetBus, + BusDate = busDate, }; } } diff --git a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Entities/Staff.cs b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Entities/Staff.cs index efbc6cd..3b39291 100644 --- a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Entities/Staff.cs +++ b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Entities/Staff.cs @@ -14,7 +14,7 @@ public class Staff public string LastName { get; private set; } = string.Empty; public EmployeePost EmployeePost { get; private set; } - public static Staff CreatEntity(int id, string first, string last, EmployeePost employeePost) + public static Staff CreatEntity(int id, string first, string last, EmployeePost employeePost) { return new Staff { diff --git a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Entities/To.cs b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Entities/To.cs index aacd57f..7ebadad 100644 --- a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Entities/To.cs +++ b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Entities/To.cs @@ -12,22 +12,22 @@ public class To { public int Id { get; private set; } public int BusID { get; private set; } - public int MechanicID { get; private set; } - public string Description { get; private set; } = string.Empty; + public int StaffID { get; private set; } + public string Discription { get; private set; } = string.Empty; - public int Cost { get; private set; } + public double Cost { get; private set; } public DateTime DateTo { get; private set; } - public static To CreatOperation(int id, string description, int cost, int busid, int mechanicid) + public static To CreatOperation(int id, string discription, double cost, DateTime dateTo, int busid, int staffid) { return new To() { Id = id, - Description = description ?? string.Empty, + Discription = discription ?? string.Empty, Cost = cost, - DateTo = DateTime.Now, + DateTo = dateTo, BusID = busid, - MechanicID = mechanicid + StaffID = staffid }; } diff --git a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Forms/FormBus.Designer.cs b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Forms/FormBus.Designer.cs index 185a714..68ec267 100644 --- a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Forms/FormBus.Designer.cs +++ b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Forms/FormBus.Designer.cs @@ -33,13 +33,13 @@ labelMileage = new Label(); labelCpacity = new Label(); textBoxNZ = new TextBox(); - Mileage = new NumericUpDown(); numericUpDownCapacity = new NumericUpDown(); + Mileage = new NumericUpDown(); buttonSave = new Button(); buttonleave = new Button(); comboBoxBus = new ComboBox(); - ((System.ComponentModel.ISupportInitialize)Mileage).BeginInit(); ((System.ComponentModel.ISupportInitialize)numericUpDownCapacity).BeginInit(); + ((System.ComponentModel.ISupportInitialize)Mileage).BeginInit(); SuspendLayout(); // // labelModel @@ -85,22 +85,22 @@ textBoxNZ.Size = new Size(386, 23); textBoxNZ.TabIndex = 5; // - // Mileage - // - Mileage.Location = new Point(182, 99); - Mileage.Maximum = new decimal(new int[] { 2000000, 0, 0, 0 }); - Mileage.Name = "Mileage"; - Mileage.Size = new Size(199, 23); - Mileage.TabIndex = 6; - // // numericUpDownCapacity // - numericUpDownCapacity.DecimalPlaces = 2; - numericUpDownCapacity.Location = new Point(267, 145); - numericUpDownCapacity.Maximum = new decimal(new int[] { 1000, 0, 0, 0 }); + numericUpDownCapacity.Location = new Point(253, 147); + numericUpDownCapacity.Maximum = new decimal(new int[] { 2000000, 0, 0, 0 }); numericUpDownCapacity.Name = "numericUpDownCapacity"; - numericUpDownCapacity.Size = new Size(131, 23); - numericUpDownCapacity.TabIndex = 7; + numericUpDownCapacity.Size = new Size(199, 23); + numericUpDownCapacity.TabIndex = 6; + // + // Mileage + // + Mileage.DecimalPlaces = 2; + Mileage.Location = new Point(182, 105); + Mileage.Maximum = new decimal(new int[] { 1000000, 0, 0, 0 }); + Mileage.Name = "Mileage"; + Mileage.Size = new Size(131, 23); + Mileage.TabIndex = 7; // // buttonSave // @@ -139,8 +139,8 @@ Controls.Add(comboBoxBus); Controls.Add(buttonleave); Controls.Add(buttonSave); - Controls.Add(numericUpDownCapacity); Controls.Add(Mileage); + Controls.Add(numericUpDownCapacity); Controls.Add(textBoxNZ); Controls.Add(labelCpacity); Controls.Add(labelMileage); @@ -149,8 +149,8 @@ Name = "FormBus"; StartPosition = FormStartPosition.CenterParent; Text = "Автобусы"; - ((System.ComponentModel.ISupportInitialize)Mileage).EndInit(); ((System.ComponentModel.ISupportInitialize)numericUpDownCapacity).EndInit(); + ((System.ComponentModel.ISupportInitialize)Mileage).EndInit(); ResumeLayout(false); PerformLayout(); } @@ -162,8 +162,8 @@ private Label labelMileage; private Label labelCpacity; private TextBox textBoxNZ; - private NumericUpDown Mileage; private NumericUpDown numericUpDownCapacity; + private NumericUpDown Mileage; private Button buttonSave; private Button buttonleave; private ComboBox comboBoxBus; diff --git a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Forms/FormBus.cs b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Forms/FormBus.cs index ab1d7e2..888089c 100644 --- a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Forms/FormBus.cs +++ b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Forms/FormBus.cs @@ -1,4 +1,5 @@ using PIbd_24_EredavkinRA_BusBusiness.Entities; +using PIbd_24_EredavkinRA_BusBusiness.Entities.Enums; using PIbd_24_EredavkinRA_BusBusiness.Repositories; using PIbd_24_EredavkinRA_BusBusiness.Repositories.Implementations; using System; @@ -28,9 +29,9 @@ public partial class FormBus : Form { throw new InvalidDataException(nameof(bus)); } - comboBoxBus.Text = bus.Model; + comboBoxBus.SelectedItem = bus.ModelType; textBoxNZ.Text = bus.N_Z; - Mileage.Value = bus.Bus_mileage; + Mileage.Value = (decimal)bus.Bus_mileage; numericUpDownCapacity.Value = bus.Capacity; _busId = bus.Id; } @@ -48,13 +49,14 @@ public partial class FormBus : Form InitializeComponent(); _busRepository = busRepository ?? throw new ArgumentNullException(nameof(busRepository)); + comboBoxBus.DataSource = Enum.GetValues(typeof(ModelType)); } private void buttonSave_Click(object sender, EventArgs e) { try { - if (string.IsNullOrWhiteSpace(comboBoxBus.Text) ||string.IsNullOrWhiteSpace(textBoxNZ.Text)) + if (comboBoxBus.SelectedIndex < 1 || string.IsNullOrWhiteSpace(textBoxNZ.Text)) { throw new Exception("Имеются незаполненные поля"); } @@ -78,10 +80,11 @@ public partial class FormBus : Form private void buttonleave_Click(object sender, EventArgs e) => Close(); private Bus CreateBus(int id) => Bus.CreateEntity(id, - comboBoxBus.Text, + (ModelType)comboBoxBus.SelectedItem!, textBoxNZ.Text, - Convert.ToInt32(Mileage.Value), + Convert.ToDouble(Mileage.Value), Convert.ToInt32(numericUpDownCapacity.Value)); + } diff --git a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Forms/FormRoutSheet.Designer.cs b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Forms/FormRoutSheet.Designer.cs index bed79d9..aff1e70 100644 --- a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Forms/FormRoutSheet.Designer.cs +++ b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Forms/FormRoutSheet.Designer.cs @@ -39,13 +39,15 @@ comboBoxDriver = new ComboBox(); comboBoxConductor = new ComboBox(); comboBoxRout = new ComboBox(); + dateTimePicker1 = new DateTimePicker(); + npgsqlDataAdapter1 = new Npgsql.NpgsqlDataAdapter(); groupBox1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridViewRoutSheet).BeginInit(); SuspendLayout(); // // buttonSave // - buttonSave.Location = new Point(21, 538); + buttonSave.Location = new Point(12, 604); buttonSave.Name = "buttonSave"; buttonSave.Size = new Size(81, 35); buttonSave.TabIndex = 8; @@ -55,7 +57,7 @@ // // buttonLeave // - buttonLeave.Location = new Point(179, 538); + buttonLeave.Location = new Point(179, 604); buttonLeave.Name = "buttonLeave"; buttonLeave.Size = new Size(92, 35); buttonLeave.TabIndex = 9; @@ -66,7 +68,7 @@ // groupBox1 // groupBox1.Controls.Add(dataGridViewRoutSheet); - groupBox1.Location = new Point(21, 145); + groupBox1.Location = new Point(21, 211); groupBox1.Name = "groupBox1"; groupBox1.Size = new Size(250, 387); groupBox1.TabIndex = 10; @@ -92,7 +94,6 @@ ColumnBus.HeaderText = "Автобус"; ColumnBus.Name = "ColumnBus"; ColumnBus.Resizable = DataGridViewTriState.True; - ColumnBus.Sorted = true; // // label1 // @@ -148,11 +149,26 @@ comboBoxRout.Size = new Size(188, 23); comboBoxRout.TabIndex = 17; // + // dateTimePicker1 + // + dateTimePicker1.Location = new Point(12, 141); + dateTimePicker1.Name = "dateTimePicker1"; + dateTimePicker1.Size = new Size(256, 23); + dateTimePicker1.TabIndex = 18; + // + // npgsqlDataAdapter1 + // + npgsqlDataAdapter1.DeleteCommand = null; + npgsqlDataAdapter1.InsertCommand = null; + npgsqlDataAdapter1.SelectCommand = null; + npgsqlDataAdapter1.UpdateCommand = null; + // // FormRoutSheet // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(310, 582); + ClientSize = new Size(292, 651); + Controls.Add(dateTimePicker1); Controls.Add(comboBoxRout); Controls.Add(comboBoxConductor); Controls.Add(comboBoxDriver); @@ -182,5 +198,7 @@ private ComboBox comboBoxConductor; private ComboBox comboBoxRout; private DataGridViewComboBoxColumn ColumnBus; + private DateTimePicker dateTimePicker1; + private Npgsql.NpgsqlDataAdapter npgsqlDataAdapter1; } } \ No newline at end of file diff --git a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Forms/FormRoutSheet.cs b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Forms/FormRoutSheet.cs index 4986afe..4c0651f 100644 --- a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Forms/FormRoutSheet.cs +++ b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Forms/FormRoutSheet.cs @@ -13,17 +13,20 @@ public partial class FormRoutSheet : Form _routSheetRepository = routSheetRepository ?? throw new ArgumentNullException(nameof(routSheetRepository)); comboBoxDriver.DataSource = staffRepositories.ReadStaff(); - comboBoxDriver.DisplayMember = "FirstName"; - comboBoxDriver.DisplayMember = "Id"; + comboBoxDriver.DisplayMember = "LastName"; + comboBoxDriver.ValueMember = "Id"; comboBoxConductor.DataSource = staffRepositories.ReadStaff(); - comboBoxConductor.DisplayMember = "FirstName"; - comboBoxConductor.DisplayMember = "Id"; + comboBoxConductor.DisplayMember = "LastName"; + comboBoxConductor.ValueMember = "Id"; comboBoxRout.DataSource = routRepositories.ReadRout(); comboBoxRout.DisplayMember = "NumberRout"; - comboBoxRout.DisplayMember = "Id"; + comboBoxRout.ValueMember = "Id"; + ColumnBus.DataSource = busRepository.ReadBus(); + ColumnBus.DisplayMember = "N_Z"; + ColumnBus.ValueMember = "Id"; @@ -33,15 +36,15 @@ public partial class FormRoutSheet : Form { try { - if (dataGridViewRoutSheet.RowCount < 0 || comboBoxDriver.SelectedIndex < 0 || comboBoxRout.SelectedIndex < 0) + if (dataGridViewRoutSheet.RowCount < 1 || comboBoxDriver.SelectedIndex < 0 || comboBoxRout.SelectedIndex < 0) { throw new Exception("Имеются не заполненые поля"); } _routSheetRepository.CreateRoutSheet(RoutSheet.CreatOpeartion(0, (int)comboBoxDriver.SelectedValue!, (int)comboBoxConductor.SelectedValue!, - (int)comboBoxRout.SelectedValue!, CreateListRoudSheetBusFromDataGrid())); + (int)comboBoxRout.SelectedValue!, dateTimePicker1.Value, CreateListRoudSheetBusFromDataGrid())); Close(); } - catch(Exception ex) + catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); } @@ -60,12 +63,11 @@ public partial class FormRoutSheet : Form { continue; } - list.Add(RoutSheetBus.CreateElement(0, - Convert.ToInt32(row.Cells["ColumnBus"].Value))); + list.Add(RoutSheetBus.CreateElement(0, Convert.ToInt32( row.Cells["ColumnBus"].Value))); } - + return list; } - + } diff --git a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Forms/FormRoutSheet.resx b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Forms/FormRoutSheet.resx index cc1fdd9..30170d3 100644 --- a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Forms/FormRoutSheet.resx +++ b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Forms/FormRoutSheet.resx @@ -120,4 +120,7 @@ True + + 17, 17 + \ No newline at end of file diff --git a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Forms/FormRoutes.cs b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Forms/FormRoutes.cs index 14a05e7..831706f 100644 --- a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Forms/FormRoutes.cs +++ b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Forms/FormRoutes.cs @@ -61,7 +61,7 @@ public partial class FormRoutes : Form } try { - var form = _container.Resolve(); + var form = _container.Resolve(); form.Id = findId; form.ShowDialog(); LoadList(); diff --git a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Forms/FormStaff.Designer.cs b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Forms/FormStaff.Designer.cs index 18c243b..82881e1 100644 --- a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Forms/FormStaff.Designer.cs +++ b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Forms/FormStaff.Designer.cs @@ -40,14 +40,14 @@ // // textBoxLastName // - textBoxLastName.Location = new Point(132, 12); + textBoxLastName.Location = new Point(132, 65); textBoxLastName.Name = "textBoxLastName"; textBoxLastName.Size = new Size(228, 23); textBoxLastName.TabIndex = 1; // // textBoxFirstName // - textBoxFirstName.Location = new Point(132, 65); + textBoxFirstName.Location = new Point(132, 15); textBoxFirstName.Name = "textBoxFirstName"; textBoxFirstName.Size = new Size(228, 23); textBoxFirstName.TabIndex = 2; diff --git a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Forms/FormStaff.cs b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Forms/FormStaff.cs index 727ff62..a39e811 100644 --- a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Forms/FormStaff.cs +++ b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Forms/FormStaff.cs @@ -57,7 +57,7 @@ public partial class FormStaff : Form { try { - if (string.IsNullOrWhiteSpace(textBoxFirstName.Text) ||string.IsNullOrWhiteSpace(textBoxLastName.Text) || checkedListBoxStaff.CheckedItems.Count == 1) + if (string.IsNullOrWhiteSpace(textBoxFirstName.Text) ||string.IsNullOrWhiteSpace(textBoxLastName.Text) || checkedListBoxStaff.CheckedItems.Count == 0) { throw new Exception("Имеются незаполненныеполя"); } diff --git a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Forms/FormStaffes.cs b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Forms/FormStaffes.cs index 8537c53..a966f36 100644 --- a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Forms/FormStaffes.cs +++ b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Forms/FormStaffes.cs @@ -51,7 +51,7 @@ namespace PIbd_24_EredavkinRA_BusBusiness.Forms } try { - var form = _container.Resolve(); + var form = _container.Resolve(); form.Id = findId; form.ShowDialog(); LoadList(); diff --git a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Forms/FormTO.Designer.cs b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Forms/FormTO.Designer.cs index c340667..c5e8f1e 100644 --- a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Forms/FormTO.Designer.cs +++ b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Forms/FormTO.Designer.cs @@ -118,6 +118,7 @@ // numericUpDownCost.DecimalPlaces = 2; numericUpDownCost.Location = new Point(105, 334); + numericUpDownCost.Maximum = new decimal(new int[] { 1000000, 0, 0, 0 }); numericUpDownCost.Name = "numericUpDownCost"; numericUpDownCost.Size = new Size(238, 23); numericUpDownCost.TabIndex = 16; diff --git a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Forms/FormTO.cs b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Forms/FormTO.cs index 0c66a83..e2a56a0 100644 --- a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Forms/FormTO.cs +++ b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Forms/FormTO.cs @@ -15,7 +15,7 @@ public partial class FormTO : Form _toRepository = toRepository ?? throw new ArgumentNullException(nameof(toRepository)); comboBoxStaff.DataSource = staffRepositories.ReadStaff(); - comboBoxStaff.DisplayMember = "FirstName"; + comboBoxStaff.DisplayMember = "LastName"; comboBoxStaff.ValueMember = "Id"; comboBoxBus.DataSource = busRepository.ReadBus(); @@ -31,7 +31,7 @@ public partial class FormTO : Form { throw new Exception("Имеются не заполненые поля"); } - _toRepository.CreateTo(To.CreatOperation(0, textBoxDescription.Text, Convert.ToInt32(numericUpDownCost.Value), (int)comboBoxBus.SelectedValue!, + _toRepository.CreateTo(To.CreatOperation(0, textBoxDescription.Text, Convert.ToDouble(numericUpDownCost.Value), dateTimePicker1.Value, (int)comboBoxBus.SelectedValue!, (int)comboBoxStaff.SelectedValue!)); Close(); } diff --git a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness.csproj b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness.csproj index e83911a..4bc2224 100644 --- a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness.csproj +++ b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness.csproj @@ -10,7 +10,18 @@ + + + + + + + + + + + diff --git a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Program.cs b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Program.cs index 0657312..2aee0c3 100644 --- a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Program.cs +++ b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Program.cs @@ -1,6 +1,11 @@ +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; using PIbd_24_EredavkinRA_BusBusiness.Repositories; using PIbd_24_EredavkinRA_BusBusiness.Repositories.Implementations; +using Serilog; using Unity; +using Unity.Lifetime; +using Unity.Microsoft.Logging; namespace PIbd_24_EredavkinRA_BusBusiness { @@ -21,12 +26,26 @@ namespace PIbd_24_EredavkinRA_BusBusiness private static IUnityContainer CreateContainer() { var container = new UnityContainer(); - container.RegisterType(); - container.RegisterType(); - container.RegisterType(); - container.RegisterType(); - container.RegisterType(); + container.AddExtension(new LoggingExtension(CreateLoggerFactory())); + container.RegisterType(new TransientLifetimeManager()); + container.RegisterType(new TransientLifetimeManager()); + container.RegisterType(new TransientLifetimeManager()); + container.RegisterType(new TransientLifetimeManager()); + container.RegisterType(new TransientLifetimeManager()); + + container.RegisterType(new SingletonLifetimeManager()); return container; } + private static LoggerFactory CreateLoggerFactory() + { + var loggerFactory = new LoggerFactory(); + loggerFactory.AddSerilog(new LoggerConfiguration() + .ReadFrom.Configuration(new ConfigurationBuilder() + .SetBasePath(Directory.GetCurrentDirectory()) + .AddJsonFile("appsettings.json") + .Build()) + .CreateLogger()); + return loggerFactory; + } } } \ No newline at end of file diff --git a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Repositories/IConnectionString.cs b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Repositories/IConnectionString.cs new file mode 100644 index 0000000..e3ae94f --- /dev/null +++ b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Repositories/IConnectionString.cs @@ -0,0 +1,7 @@ + +namespace PIbd_24_EredavkinRA_BusBusiness.Repositories; + +public interface IConnectionString +{ + public string ConnectionString { get; } +} diff --git a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Repositories/IRoutSheetRepository.cs b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Repositories/IRoutSheetRepository.cs index 52d6e5e..774cf87 100644 --- a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Repositories/IRoutSheetRepository.cs +++ b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Repositories/IRoutSheetRepository.cs @@ -11,5 +11,5 @@ public interface IRoutSheetRepository { IEnumerable ReadRoutSheet(DateTime? dateForm = null, DateTime? dateTo = null, int? routId = null, int? busid = null, int? driverid = null, int? conductorid = null); void CreateRoutSheet(RoutSheet routsheet); - void DeleteRoutSheet(int id); + } diff --git a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Repositories/Implementations/BusRepository.cs b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Repositories/Implementations/BusRepository.cs index 0b9fbfc..0c60e75 100644 --- a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Repositories/Implementations/BusRepository.cs +++ b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Repositories/Implementations/BusRepository.cs @@ -1,4 +1,8 @@ -using PIbd_24_EredavkinRA_BusBusiness.Entities; +using Dapper; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using Npgsql; +using PIbd_24_EredavkinRA_BusBusiness.Entities; using System; using System.Collections.Generic; using System.Linq; @@ -10,28 +14,114 @@ namespace PIbd_24_EredavkinRA_BusBusiness.Repositories.Implementations; public class BusRepository : IBusRepository { + private readonly IConnectionString _connectionString; + + private readonly ILogger _logger; + + public BusRepository(IConnectionString connectionString, ILogger logger) + { + _connectionString = connectionString; + _logger = logger; + } public void CreateBus(Bus bus) { - + _logger.LogInformation("Добавление объекта"); + _logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(bus)); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var queryInsert = @" + INSERT INTO Bus (ModelType, N_Z, Capacity, Bus_mileage) + VALUES (@ModelType, @N_Z, @Capacity, @Bus_mileage)"; + connection.Execute(queryInsert, bus); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при добавлении объекта"); + throw; + } + } + public void UpdateBus(Bus bus) + { + _logger.LogInformation("Редактирование объекта"); + _logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(bus)); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var queryUpdate = @" + UPDATE Bus + SET + ModelType=@ModelType, + N_Z=@N_Z, + Capacity=@Capacity, + Bus_mileage=@Bus_mileage + WHERE Id=@Id"; + connection.Execute(queryUpdate, bus); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при редактировании объекта"); + throw; + } } - public void DeleteBus(int id) { - + _logger.LogInformation("Удаление объекта"); + _logger.LogDebug("Объект: {id}", id); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var queryDelete = @" + DELETE FROM Bus + WHERE Id=@id"; + connection.Execute(queryDelete, new { id }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при удалении объекта"); + throw; + } + } + public Bus ReadBusByID(int id) + { + _logger.LogInformation("Получение объекта по идентификатору"); + _logger.LogDebug("Объект: {id}", id); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var querySelect = @" + SELECT * FROM Bus + WHERE Id=@id"; + var bus = connection.QueryFirst(querySelect, new { id }); + _logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(bus)); + return bus; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при поиске объекта"); + throw; + } } public IEnumerable ReadBus() { - return []; + _logger.LogInformation("Получение всех объектов"); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var querySelect = "SELECT * FROM Bus"; + var bus = connection.Query(querySelect); + _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(bus)); + return bus; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при чтении объектов"); + throw; + } } - public Bus ReadBusByID(int id) - { - return Bus.CreateEntity(0, string.Empty, string.Empty, 0, 0); - } + - public void UpdateBus(Bus bus) - { - - } + } diff --git a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Repositories/Implementations/ConnectionString.cs b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Repositories/Implementations/ConnectionString.cs new file mode 100644 index 0000000..1c8d034 --- /dev/null +++ b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Repositories/Implementations/ConnectionString.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PIbd_24_EredavkinRA_BusBusiness.Repositories.Implementations; + +internal class ConnectionString : IConnectionString +{ + string IConnectionString.ConnectionString => "Host=127.0.0.1:5432;Database=basdetebus;Username=postgres;Password=postgres; Include Error Detail=true;"; +} \ No newline at end of file diff --git a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Repositories/Implementations/RoutRepositories.cs b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Repositories/Implementations/RoutRepositories.cs index 641dd1e..a0c9598 100644 --- a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Repositories/Implementations/RoutRepositories.cs +++ b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Repositories/Implementations/RoutRepositories.cs @@ -1,4 +1,8 @@ -using PIbd_24_EredavkinRA_BusBusiness.Entities; +using Dapper; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using Npgsql; +using PIbd_24_EredavkinRA_BusBusiness.Entities; using System; using System.Collections.Generic; using System.Linq; @@ -9,28 +13,113 @@ namespace PIbd_24_EredavkinRA_BusBusiness.Repositories.Implementations; public class RoutRepositories : IRoutRepositories { + private readonly IConnectionString _connectionString; + + private readonly ILogger _logger; + + public RoutRepositories(IConnectionString connectionString, ILogger logger) + { + _connectionString = connectionString; + _logger = logger; + } public void CreateRout(Rout rout) { - - } + _logger.LogInformation("Добавление объекта"); + _logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(rout)); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var queryInsert = @" + INSERT INTO Rout (StartStop, EndStop, NumberRout) + VALUES (@StartStop, @EndStop, @NumberRout)"; + connection.Execute(queryInsert, rout); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при добавлении объекта"); + throw; + } - public void DeleteRout(int id) - { - } - - public IEnumerable ReadRout() - { - return []; - } - - public Rout ReadRoutByID(int id) - { - return Rout.CreateEntity(0, string.Empty, string.Empty, 0); - } - public void UpdateRout(Rout rout) { - + _logger.LogInformation("Редактирование объекта"); + _logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(rout)); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var queryUpdate = @" + UPDATE Rout + SET + StartStop=@StartStop, + EndStop=@EndStop, + NumberRout=@NumberRout + WHERE Id=@Id"; + connection.Execute(queryUpdate, rout); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при редактировании объекта"); + throw; + } } + public void DeleteRout(int id) + { + _logger.LogInformation("Удаление объекта"); + _logger.LogDebug("Объект: {id}", id); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var queryDelete = @" + DELETE FROM Rout + WHERE Id=@id"; + connection.Execute(queryDelete, new { id }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при удалении объекта"); + throw; + } + } + public Rout ReadRoutByID(int id) + { + _logger.LogInformation("Получение объекта по идентификатору"); + _logger.LogDebug("Объект: {id}", id); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var querySelect = @" + SELECT * FROM Rout + WHERE Id=@id"; + var rout = connection.QueryFirst(querySelect, new { id }); + _logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(rout)); + return rout; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при поиске объекта"); + throw; + } + } + public IEnumerable ReadRout() + { + _logger.LogInformation("Получение всех объектов"); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var querySelect = "SELECT * FROM Rout"; + var rout = connection.Query(querySelect); + _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(rout)); + return rout; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при чтении объектов"); + throw; + } + } + + + + } diff --git a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Repositories/Implementations/RoutSheetRepository.cs b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Repositories/Implementations/RoutSheetRepository.cs index 559f3ed..f689175 100644 --- a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Repositories/Implementations/RoutSheetRepository.cs +++ b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Repositories/Implementations/RoutSheetRepository.cs @@ -1,26 +1,72 @@ -using PIbd_24_EredavkinRA_BusBusiness.Entities; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using Dapper; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using Npgsql; +using PIbd_24_EredavkinRA_BusBusiness.Entities; + namespace PIbd_24_EredavkinRA_BusBusiness.Repositories.Implementations; public class RoutSheetRepository : IRoutSheetRepository { + private readonly IConnectionString _connectionString; + + private readonly ILogger _logger; + + public RoutSheetRepository(IConnectionString connectionString, ILogger logger) + { + _connectionString = connectionString; + _logger = logger; + } public void CreateRoutSheet(RoutSheet routsheet) { - + _logger.LogInformation("Добавление объекта"); + _logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(routsheet)); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + connection.Open(); + using var transaction = connection.BeginTransaction(); + var queryInsert = @" + INSERT INTO RoutSheet (RoutId, DriverId, ConductorId, BusDate) + VALUES (@RoutId, @DriverId, @ConductorID, @BusDate); + SELECT MAX(Id) FROM RoutSheet"; + var routsheetId = connection.QueryFirst(queryInsert, routsheet, transaction); + + var querySubInsert = @" + INSERT INTO RoutSheetBus (RoutSheetId, BusId) + VALUES (@RoutSheetId, @BusId)"; + foreach (var elem in routsheet.RoutSheetBus) + { + connection.Execute(querySubInsert, new { routsheetId, elem.BusID }, transaction); + } + + transaction.Commit(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при добавлении объекта"); + throw; + } } - public void DeleteRoutSheet(int id) - { - - } + - public IEnumerable ReadRoutSheet(DateTime? dateForm = null, DateTime? dateTo = null, int? routId = null, int? busid = null, int? driverid = null, int? conductorid = null) + public IEnumerable ReadRoutSheet(DateTime? dateForm = null, DateTime? dateBus = null, int? routId = null, int? busid = null, int? driverid = null, int? conductorid = null) { - return []; + _logger.LogInformation("Получение всех объектов"); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var querySelect = "SELECT * FROM RoutSheet"; + var routsheet = connection.Query(querySelect); + _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(routsheet)); + return routsheet; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при чтении объектов"); + throw; + } } } diff --git a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Repositories/Implementations/StaffRepository.cs b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Repositories/Implementations/StaffRepository.cs index 73e5e52..7124b1a 100644 --- a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Repositories/Implementations/StaffRepository.cs +++ b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Repositories/Implementations/StaffRepository.cs @@ -1,4 +1,8 @@ -using PIbd_24_EredavkinRA_BusBusiness.Entities; +using Dapper; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using Npgsql; +using PIbd_24_EredavkinRA_BusBusiness.Entities; using PIbd_24_EredavkinRA_BusBusiness.Entities.Enums; using System; using System.Collections.Generic; @@ -10,28 +14,112 @@ namespace PIbd_24_EredavkinRA_BusBusiness.Repositories.Implementations; internal class StaffRepository : IStaffRepositories { + private readonly IConnectionString _connectionString; + + private readonly ILogger _logger; + public StaffRepository(IConnectionString connectionString, ILogger logger) + { + _connectionString = connectionString; + _logger = logger; + } public void CreateStaff(Staff staff) { + _logger.LogInformation("Добавление объекта"); + _logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(staff)); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var queryInsert = @" + INSERT INTO Staff (FirstName, LastName, EmployeePost) + VALUES (@FirstName, @LastName, @EmployeePost)"; + connection.Execute(queryInsert, staff); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при добавлении объекта"); + throw; + } + } + public void UpdateStaff(Staff staff) + { + _logger.LogInformation("Редактирование объекта"); + _logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(staff)); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var queryUpdate = @" + UPDATE Staff + SET + FirstName=@FirstName, + LastName=@LastName, + EmployeePost=@EmployeePost + WHERE Id=@Id"; + connection.Execute(queryUpdate, staff); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при редактировании объекта"); + throw; + } } - public void DeleteStaff(int id) { - + _logger.LogInformation("Удаление объекта"); + _logger.LogDebug("Объект: {id}", id); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var queryDelete = @" + DELETE FROM Staff + WHERE Id=@id"; + connection.Execute(queryDelete, new { id }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при удалении объекта"); + throw; + } + } + public Staff ReadStaffByID(int id) + { + _logger.LogInformation("Получение объекта по идентификатору"); + _logger.LogDebug("Объект: {id}", id); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var querySelect = @" + SELECT * FROM Staff + WHERE Id=@id"; + var staff = connection.QueryFirst(querySelect, new { id }); + _logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(staff)); + return staff; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при поиске объекта"); + throw; + } } public IEnumerable ReadStaff() { - return []; + _logger.LogInformation("Получение всех объектов"); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var querySelect = "SELECT * FROM Staff"; + var staff = connection.Query(querySelect); + _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(staff)); + return staff; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при чтении объектов"); + throw; + } } - public Staff ReadStaffByID(int id) - { - return Staff.CreatEntity(0, string.Empty, string.Empty, EmployeePost.None); - } - public void UpdateStaff(Staff staff) - { - - } + } diff --git a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Repositories/Implementations/ToRepository.cs b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Repositories/Implementations/ToRepository.cs index 74a60c9..e94bded 100644 --- a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Repositories/Implementations/ToRepository.cs +++ b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Repositories/Implementations/ToRepository.cs @@ -1,4 +1,8 @@ -using PIbd_24_EredavkinRA_BusBusiness.Entities; +using Dapper; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using Npgsql; +using PIbd_24_EredavkinRA_BusBusiness.Entities; using System; using System.Collections.Generic; using System.Linq; @@ -9,19 +13,69 @@ namespace PIbd_24_EredavkinRA_BusBusiness.Repositories.Implementations; public class ToRepository : IToRepository { + private readonly IConnectionString _connectionString; + + private readonly ILogger _logger; + + public ToRepository(IConnectionString connectionString, ILogger logger) + { + _connectionString = connectionString; + _logger = logger; + } public void CreateTo(To to) { - + _logger.LogInformation("Добавление объекта"); + _logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(to)); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var queryInsert = @" + INSERT INTO TOs (BusId, StaffId, Discription, Cost, DateTo) + VALUES (@BusId, @StaffId, @Discription, @Cost, @DateTo)"; + connection.Execute(queryInsert, to); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при добавлении объекта"); + throw; + } } public void DeleteTo(int id) { - + _logger.LogInformation("Удаление объекта"); + _logger.LogDebug("Объект: {id}", id); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var queryDelete = @" + DELETE FROM TOs + WHERE Id=@id"; + connection.Execute(queryDelete, new { id }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при удалении объекта"); + throw; + } } - public IEnumerable ReadTo(DateTime? dateForm = null, DateTime? dateTo = null, int? mechanicid = null, int? busid = null) + public IEnumerable ReadTo(DateTime? dateForm = null, DateTime? dateTo = null, int? staffid = null, int? busid = null) { - return []; + _logger.LogInformation("Получение всех объектов"); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var querySelect = "SELECT * FROM TOs"; + var compilingSchedules = connection.Query(querySelect); + _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(compilingSchedules)); + return compilingSchedules; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при чтении объектов"); + throw; + } } } diff --git a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/appsettings.json b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/appsettings.json new file mode 100644 index 0000000..e79876b --- /dev/null +++ b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/appsettings.json @@ -0,0 +1,15 @@ +{ + "Serilog": { + "Using": [ "Serilog.Sinks.File" ], + "MinimumLevel": "Debug", + "WriteTo": [ + { + "Name": "File", + "Args": { + "path": "Logs/schedule_log.txt", + "rollingInterval": "Day" + } + } + ] + } +} \ No newline at end of file diff --git a/test/test.sln b/test/test.sln new file mode 100644 index 0000000..0f5c40e --- /dev/null +++ b/test/test.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.9.34728.123 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test", "test\test.vcxproj", "{F77B0358-2B48-4BD7-8CCD-1AD9C73D1BCB}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F77B0358-2B48-4BD7-8CCD-1AD9C73D1BCB}.Debug|x64.ActiveCfg = Debug|x64 + {F77B0358-2B48-4BD7-8CCD-1AD9C73D1BCB}.Debug|x64.Build.0 = Debug|x64 + {F77B0358-2B48-4BD7-8CCD-1AD9C73D1BCB}.Debug|x86.ActiveCfg = Debug|Win32 + {F77B0358-2B48-4BD7-8CCD-1AD9C73D1BCB}.Debug|x86.Build.0 = Debug|Win32 + {F77B0358-2B48-4BD7-8CCD-1AD9C73D1BCB}.Release|x64.ActiveCfg = Release|x64 + {F77B0358-2B48-4BD7-8CCD-1AD9C73D1BCB}.Release|x64.Build.0 = Release|x64 + {F77B0358-2B48-4BD7-8CCD-1AD9C73D1BCB}.Release|x86.ActiveCfg = Release|Win32 + {F77B0358-2B48-4BD7-8CCD-1AD9C73D1BCB}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {0CC34090-EEB4-4546-B06A-461C6A4A843F} + EndGlobalSection +EndGlobal diff --git a/test/test/test.cpp b/test/test/test.cpp new file mode 100644 index 0000000..fbd1aef --- /dev/null +++ b/test/test/test.cpp @@ -0,0 +1,34 @@ +#include +#include + +using namespace std; + +int main() { + int n; + cin >> n; + + + int power_of_2 = 0; + int power_of_5 = 0; + + + while (n % 2 == 0) { + n /= 2; + power_of_2++; + } + + while (n % 5 == 0) { + n /= 5; + power_of_5++; + } + + if (n > 1) { + cout << "No" << endl; + } + else { + + cout << max(power_of_2, power_of_5) << endl; + } + + return 0; +} diff --git a/test/test/test.vcxproj b/test/test/test.vcxproj new file mode 100644 index 0000000..128ea27 --- /dev/null +++ b/test/test/test.vcxproj @@ -0,0 +1,135 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {f77b0358-2b48-4bd7-8ccd-1ad9c73d1bcb} + test + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + \ No newline at end of file diff --git a/test/test/test.vcxproj.filters b/test/test/test.vcxproj.filters new file mode 100644 index 0000000..8e368b1 --- /dev/null +++ b/test/test/test.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Исходные файлы + + + \ No newline at end of file