lab2 done
This commit is contained in:
parent
1a50d8d5c4
commit
adc93488c9
@ -10,6 +10,7 @@ public class AthletePlacingAthlete
|
|||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
public int AthleteId { get; private set; }
|
public int AthleteId { get; private set; }
|
||||||
|
public int PlacingAthleteId{ get; private set; }
|
||||||
public int LengthOfStay { get; private set; }
|
public int LengthOfStay { get; private set; }
|
||||||
public static AthletePlacingAthlete CreateElement(int id, int athleteId, int lengthOfStay)
|
public static AthletePlacingAthlete CreateElement(int id, int athleteId, int lengthOfStay)
|
||||||
{
|
{
|
||||||
|
@ -10,16 +10,16 @@ public class Hotel
|
|||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
public string Name { get; private set; } = string.Empty;
|
public string Name { get; private set; } = string.Empty;
|
||||||
public string Adress { get; private set; } = string.Empty;
|
public string Address { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
|
||||||
public static Hotel CreateEntity(int id, string name, string adress)
|
public static Hotel CreateEntity(int id, string name, string address)
|
||||||
{
|
{
|
||||||
return new Hotel
|
return new Hotel
|
||||||
{
|
{
|
||||||
Id = id,
|
Id = id,
|
||||||
Name = name,
|
Name = name,
|
||||||
Adress = adress
|
Address = address
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -111,9 +111,9 @@
|
|||||||
private Label label1;
|
private Label label1;
|
||||||
private Label label2;
|
private Label label2;
|
||||||
private TextBox textBoxHotelName;
|
private TextBox textBoxHotelName;
|
||||||
private TextBox textBoxHotelAdress;
|
private TextBox textBoxHotelAddress;
|
||||||
private Button buttonSave;
|
private Button buttonSave;
|
||||||
private Button buttonCancel;
|
private Button buttonCancel;
|
||||||
private TextBox textBoxHotelAddress;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -31,8 +31,8 @@ public partial class FormHotel : Form
|
|||||||
InvalidDataException(nameof(hotel));
|
InvalidDataException(nameof(hotel));
|
||||||
}
|
}
|
||||||
textBoxHotelName.Text = hotel.Name;
|
textBoxHotelName.Text = hotel.Name;
|
||||||
textBoxHotelAdress.Text =
|
textBoxHotelAddress.Text =
|
||||||
hotel.Adress;
|
hotel.Address;
|
||||||
|
|
||||||
_hotelId = value;
|
_hotelId = value;
|
||||||
}
|
}
|
||||||
@ -77,7 +77,7 @@ public partial class FormHotel : Form
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
|
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
|
||||||
private Hotel CreateHotel(int id) => Hotel.CreateEntity(id, textBoxHotelName.Text, textBoxHotelAdress.Text);
|
private Hotel CreateHotel(int id) => Hotel.CreateEntity(id, textBoxHotelName.Text, textBoxHotelAddress.Text);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -36,8 +36,8 @@
|
|||||||
comboBoxRoom = new ComboBox();
|
comboBoxRoom = new ComboBox();
|
||||||
groupBox1 = new GroupBox();
|
groupBox1 = new GroupBox();
|
||||||
dataGridView = new DataGridView();
|
dataGridView = new DataGridView();
|
||||||
ColumnAthlete = new DataGridViewComboBoxColumn();
|
|
||||||
ColumnLengthOfStay = new DataGridViewTextBoxColumn();
|
ColumnLengthOfStay = new DataGridViewTextBoxColumn();
|
||||||
|
ColumnAthlete = new DataGridViewComboBoxColumn();
|
||||||
groupBox1.SuspendLayout();
|
groupBox1.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
@ -119,18 +119,18 @@
|
|||||||
dataGridView.Size = new Size(485, 307);
|
dataGridView.Size = new Size(485, 307);
|
||||||
dataGridView.TabIndex = 0;
|
dataGridView.TabIndex = 0;
|
||||||
//
|
//
|
||||||
|
// ColumnLengthOfStay
|
||||||
|
//
|
||||||
|
ColumnLengthOfStay.HeaderText = "Длительность проживания";
|
||||||
|
ColumnLengthOfStay.Name = "ColumnLengthOfStay";
|
||||||
|
//
|
||||||
// ColumnAthlete
|
// ColumnAthlete
|
||||||
//
|
//
|
||||||
ColumnAthlete.DisplayStyle = DataGridViewComboBoxDisplayStyle.ComboBox;
|
ColumnAthlete.DisplayStyle = DataGridViewComboBoxDisplayStyle.ComboBox;
|
||||||
ColumnAthlete.HeaderText = "Спортсмен";
|
ColumnAthlete.HeaderText = "Спортсмен";
|
||||||
ColumnAthlete.Name = "ColumnAthlete";
|
ColumnAthlete.Name = "ColumnAthlete";
|
||||||
//
|
//
|
||||||
// ColumnLengthOfStay
|
// FormPlacingAthlete
|
||||||
//
|
|
||||||
ColumnLengthOfStay.HeaderText = "Длительность проживания";
|
|
||||||
ColumnLengthOfStay.Name = "ColumnLengthOfStay";
|
|
||||||
//
|
|
||||||
// FormAthletePlacingAthlete
|
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
@ -141,7 +141,7 @@
|
|||||||
Controls.Add(buttonSave);
|
Controls.Add(buttonSave);
|
||||||
Controls.Add(label2);
|
Controls.Add(label2);
|
||||||
Controls.Add(label1);
|
Controls.Add(label1);
|
||||||
Name = "FormAthletePlacingAthlete";
|
Name = "FormPlacingAthlete";
|
||||||
StartPosition = FormStartPosition.CenterParent;
|
StartPosition = FormStartPosition.CenterParent;
|
||||||
Text = "Размещение спортсмена";
|
Text = "Размещение спортсмена";
|
||||||
groupBox1.ResumeLayout(false);
|
groupBox1.ResumeLayout(false);
|
||||||
|
@ -50,14 +50,13 @@ public partial class FormPlacingAthlete : Form
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
|
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
|
||||||
private List<AthletePlacingAthlete>
|
private List<AthletePlacingAthlete> CreateListAthletePlacingAthleteFromDataGrid()
|
||||||
CreateListAthletePlacingAthleteFromDataGrid()
|
|
||||||
{
|
{
|
||||||
var list = new List<AthletePlacingAthlete>();
|
var list = new List<AthletePlacingAthlete>();
|
||||||
foreach (DataGridViewRow row in dataGridView.Rows)
|
foreach (DataGridViewRow row in dataGridView.Rows)
|
||||||
{
|
{
|
||||||
if (row.Cells["ColumnFeed"].Value == null ||
|
if (row.Cells["ColumnAthlete"].Value == null ||
|
||||||
row.Cells["ColumnCount"].Value == null)
|
row.Cells["ColumnLengthOfStay"].Value == null)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -84,8 +84,26 @@ internal class HotelRepository : IHotelRepository
|
|||||||
}
|
}
|
||||||
public void UpdateHotel(Hotel hotel)
|
public void UpdateHotel(Hotel hotel)
|
||||||
{
|
{
|
||||||
|
_logger.LogInformation("Редактирование объекта");
|
||||||
|
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(hotel));
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryUpdate = @"
|
||||||
|
UPDATE Hotels
|
||||||
|
SET Name = @Name, Address = @Address
|
||||||
|
WHERE Id = @Id;
|
||||||
|
";
|
||||||
|
connection.Execute(queryUpdate, hotel);
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при редактировании объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void DeleteHotel(int id)
|
public void DeleteHotel(int id)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Удаление объекта");
|
_logger.LogInformation("Удаление объекта");
|
||||||
|
@ -6,6 +6,7 @@ using ProjectHotel.Entities;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.SqlClient;
|
using System.Data.SqlClient;
|
||||||
|
using System.Diagnostics.Contracts;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -32,20 +33,23 @@ internal class PlacingAthleteRepository : IPlacingAthleteRepository
|
|||||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
connection.Open();
|
connection.Open();
|
||||||
using var transaction = connection.BeginTransaction();
|
using var transaction = connection.BeginTransaction();
|
||||||
var queryInsert = @"INSERT INTO PlacingAthlete (RoomId, PlacingDate) VALUES (@RoomId, @PlacingDate) RETURNING Id";
|
|
||||||
|
|
||||||
|
var queryInsert = @"
|
||||||
|
INSERT INTO PlacingAthlete (RoomId, PlacingDate)
|
||||||
|
VALUES (@RoomId, @PlacingDate);
|
||||||
|
SELECT MAX(Id) FROM PlacingAthlete;
|
||||||
|
";
|
||||||
var placingAthleteId = connection.QueryFirst<int>(queryInsert, placingAthlete, transaction);
|
var placingAthleteId = connection.QueryFirst<int>(queryInsert, placingAthlete, transaction);
|
||||||
var querySubInsert = @"INSERT INTO AthletePlacingAthlete (PlacingAthleteId, AthleteId, LengthOfStay) VALUES (@PlacingAthleteId, @AthleteId, @LengthOfStay)";
|
|
||||||
|
|
||||||
|
var querySubInsert = @"
|
||||||
|
INSERT INTO AthletePlacingAthlete (AthleteId, PlacingAthleteId, LengthOfStay)
|
||||||
|
VALUES (@AthleteId, @PlacingAthleteId, @LengthOfStay);
|
||||||
|
";
|
||||||
foreach (var elem in placingAthlete.AthletePlacingAthletes)
|
foreach (var elem in placingAthlete.AthletePlacingAthletes)
|
||||||
{
|
{
|
||||||
connection.Execute(querySubInsert, new
|
connection.Execute(querySubInsert, new { elem.AthleteId, placingAthleteId , elem.LengthOfStay }, transaction);
|
||||||
{
|
|
||||||
PlacingAthleteId = placingAthleteId,
|
|
||||||
elem.AthleteId,
|
|
||||||
elem.LengthOfStay,
|
|
||||||
}, transaction);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
transaction.Commit();
|
transaction.Commit();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user