Добавление количественного атрибута для сущности-операции

This commit is contained in:
TikhonElli 2024-12-12 00:08:18 +04:00
parent 570615e48a
commit ffcf9d2df8
4 changed files with 48 additions and 17 deletions

View File

@ -8,11 +8,13 @@ public class AthleteAccommodation
public int AthleteId { get; private set; } public int AthleteId { get; private set; }
public decimal Price { get; private set; }
public DateTime DateStart { get; private set; } public DateTime DateStart { get; private set; }
public DateTime DateEnd { get; private set; } public DateTime DateEnd { get; private set; }
public static AthleteAccommodation CreateOpeartion(int id, int roomId, int athleteId) public static AthleteAccommodation CreateOpeartion(int id, int roomId, int athleteId, decimal price)
{ {
var dateStart = DateTime.Now; var dateStart = DateTime.Now;
return new AthleteAccommodation return new AthleteAccommodation
@ -20,6 +22,7 @@ public class AthleteAccommodation
Id = id, Id = id,
RoomId = roomId, RoomId = roomId,
AthleteId = athleteId, AthleteId = athleteId,
Price = price,
DateStart = dateStart, DateStart = dateStart,
DateEnd = dateStart.AddMonths(1) DateEnd = dateStart.AddMonths(1)
}; };

View File

@ -38,12 +38,15 @@
dateTimePickerDateEnd = new DateTimePicker(); dateTimePickerDateEnd = new DateTimePicker();
buttonSave = new Button(); buttonSave = new Button();
buttonCancel = new Button(); buttonCancel = new Button();
labelPrice = new Label();
numericUpDownPrice = new NumericUpDown();
((System.ComponentModel.ISupportInitialize)numericUpDownPrice).BeginInit();
SuspendLayout(); SuspendLayout();
// //
// labelRoom // labelRoom
// //
labelRoom.AutoSize = true; labelRoom.AutoSize = true;
labelRoom.Location = new Point(60, 27); labelRoom.Location = new Point(106, 27);
labelRoom.Name = "labelRoom"; labelRoom.Name = "labelRoom";
labelRoom.Size = new Size(45, 15); labelRoom.Size = new Size(45, 15);
labelRoom.TabIndex = 0; labelRoom.TabIndex = 0;
@ -52,7 +55,7 @@
// labelAthlete // labelAthlete
// //
labelAthlete.AutoSize = true; labelAthlete.AutoSize = true;
labelAthlete.Location = new Point(36, 60); labelAthlete.Location = new Point(82, 60);
labelAthlete.Name = "labelAthlete"; labelAthlete.Name = "labelAthlete";
labelAthlete.Size = new Size(69, 15); labelAthlete.Size = new Size(69, 15);
labelAthlete.TabIndex = 1; labelAthlete.TabIndex = 1;
@ -61,7 +64,7 @@
// labelDateStart // labelDateStart
// //
labelDateStart.AutoSize = true; labelDateStart.AutoSize = true;
labelDateStart.Location = new Point(36, 102); labelDateStart.Location = new Point(82, 128);
labelDateStart.Name = "labelDateStart"; labelDateStart.Name = "labelDateStart";
labelDateStart.Size = new Size(69, 15); labelDateStart.Size = new Size(69, 15);
labelDateStart.TabIndex = 2; labelDateStart.TabIndex = 2;
@ -70,7 +73,7 @@
// labelDateEnd // labelDateEnd
// //
labelDateEnd.AutoSize = true; labelDateEnd.AutoSize = true;
labelDateEnd.Location = new Point(32, 135); labelDateEnd.Location = new Point(78, 163);
labelDateEnd.Name = "labelDateEnd"; labelDateEnd.Name = "labelDateEnd";
labelDateEnd.Size = new Size(73, 15); labelDateEnd.Size = new Size(73, 15);
labelDateEnd.TabIndex = 3; labelDateEnd.TabIndex = 3;
@ -80,7 +83,7 @@
// //
comboBoxRoom.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxRoom.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxRoom.FormattingEnabled = true; comboBoxRoom.FormattingEnabled = true;
comboBoxRoom.Location = new Point(111, 24); comboBoxRoom.Location = new Point(157, 24);
comboBoxRoom.Name = "comboBoxRoom"; comboBoxRoom.Name = "comboBoxRoom";
comboBoxRoom.Size = new Size(200, 23); comboBoxRoom.Size = new Size(200, 23);
comboBoxRoom.TabIndex = 4; comboBoxRoom.TabIndex = 4;
@ -89,7 +92,7 @@
// //
comboBoxAthlete.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxAthlete.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxAthlete.FormattingEnabled = true; comboBoxAthlete.FormattingEnabled = true;
comboBoxAthlete.Location = new Point(111, 57); comboBoxAthlete.Location = new Point(157, 57);
comboBoxAthlete.Name = "comboBoxAthlete"; comboBoxAthlete.Name = "comboBoxAthlete";
comboBoxAthlete.Size = new Size(200, 23); comboBoxAthlete.Size = new Size(200, 23);
comboBoxAthlete.TabIndex = 5; comboBoxAthlete.TabIndex = 5;
@ -97,7 +100,7 @@
// dateTimePickerDateStart // dateTimePickerDateStart
// //
dateTimePickerDateStart.Enabled = false; dateTimePickerDateStart.Enabled = false;
dateTimePickerDateStart.Location = new Point(111, 96); dateTimePickerDateStart.Location = new Point(157, 122);
dateTimePickerDateStart.Name = "dateTimePickerDateStart"; dateTimePickerDateStart.Name = "dateTimePickerDateStart";
dateTimePickerDateStart.Size = new Size(200, 23); dateTimePickerDateStart.Size = new Size(200, 23);
dateTimePickerDateStart.TabIndex = 6; dateTimePickerDateStart.TabIndex = 6;
@ -105,16 +108,16 @@
// dateTimePickerDateEnd // dateTimePickerDateEnd
// //
dateTimePickerDateEnd.Enabled = false; dateTimePickerDateEnd.Enabled = false;
dateTimePickerDateEnd.Location = new Point(111, 129); dateTimePickerDateEnd.Location = new Point(157, 157);
dateTimePickerDateEnd.Name = "dateTimePickerDateEnd"; dateTimePickerDateEnd.Name = "dateTimePickerDateEnd";
dateTimePickerDateEnd.Size = new Size(200, 23); dateTimePickerDateEnd.Size = new Size(200, 23);
dateTimePickerDateEnd.TabIndex = 7; dateTimePickerDateEnd.TabIndex = 7;
// //
// buttonSave // buttonSave
// //
buttonSave.Location = new Point(32, 168); buttonSave.Location = new Point(18, 202);
buttonSave.Name = "buttonSave"; buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(133, 45); buttonSave.Size = new Size(159, 45);
buttonSave.TabIndex = 8; buttonSave.TabIndex = 8;
buttonSave.Text = "Сохранить"; buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true; buttonSave.UseVisualStyleBackColor = true;
@ -122,19 +125,41 @@
// //
// buttonCancel // buttonCancel
// //
buttonCancel.Location = new Point(178, 168); buttonCancel.Location = new Point(197, 202);
buttonCancel.Name = "buttonCancel"; buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(133, 45); buttonCancel.Size = new Size(160, 45);
buttonCancel.TabIndex = 9; buttonCancel.TabIndex = 9;
buttonCancel.Text = "Отмена"; buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true; buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click; buttonCancel.Click += ButtonCancel_Click;
// //
// labelPrice
//
labelPrice.AutoSize = true;
labelPrice.Location = new Point(12, 92);
labelPrice.Name = "labelPrice";
labelPrice.Size = new Size(139, 15);
labelPrice.TabIndex = 10;
labelPrice.Text = "Стоимость проживания";
//
// numericUpDownPrice
//
numericUpDownPrice.DecimalPlaces = 2;
numericUpDownPrice.Location = new Point(157, 90);
numericUpDownPrice.Maximum = new decimal(new int[] { 999999999, 0, 0, 0 });
numericUpDownPrice.Minimum = new decimal(new int[] { 1, 0, 0, 131072 });
numericUpDownPrice.Name = "numericUpDownPrice";
numericUpDownPrice.Size = new Size(200, 23);
numericUpDownPrice.TabIndex = 11;
numericUpDownPrice.Value = new decimal(new int[] { 1, 0, 0, 131072 });
//
// FormAthleteAccommodation // FormAthleteAccommodation
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(342, 225); ClientSize = new Size(380, 267);
Controls.Add(numericUpDownPrice);
Controls.Add(labelPrice);
Controls.Add(buttonCancel); Controls.Add(buttonCancel);
Controls.Add(buttonSave); Controls.Add(buttonSave);
Controls.Add(dateTimePickerDateEnd); Controls.Add(dateTimePickerDateEnd);
@ -148,6 +173,7 @@
Name = "FormAthleteAccommodation"; Name = "FormAthleteAccommodation";
StartPosition = FormStartPosition.CenterParent; StartPosition = FormStartPosition.CenterParent;
Text = "Размещение спортсмена"; Text = "Размещение спортсмена";
((System.ComponentModel.ISupportInitialize)numericUpDownPrice).EndInit();
ResumeLayout(false); ResumeLayout(false);
PerformLayout(); PerformLayout();
} }
@ -164,5 +190,7 @@
private DateTimePicker dateTimePickerDateEnd; private DateTimePicker dateTimePickerDateEnd;
private Button buttonSave; private Button buttonSave;
private Button buttonCancel; private Button buttonCancel;
private Label labelPrice;
private NumericUpDown numericUpDownPrice;
} }
} }

View File

@ -34,7 +34,7 @@ namespace ProjectAthletesAccommodation.Forms
_athleteAccommodationRepository.CreateAthleteAccommodation _athleteAccommodationRepository.CreateAthleteAccommodation
(AthleteAccommodation.CreateOpeartion(0, (int)comboBoxRoom.SelectedValue!, (AthleteAccommodation.CreateOpeartion(0, (int)comboBoxRoom.SelectedValue!,
(int)comboBoxAthlete.SelectedValue!)); (int)comboBoxAthlete.SelectedValue!, Convert.ToDecimal(numericUpDownPrice.Value)));
Close(); Close();
} }

View File

@ -26,8 +26,8 @@ public class AthleteAccommodationRepository : IAthleteAccommodationRepository
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryInsert = var queryInsert =
@"INSERT INTO AthleteAccommodation (RoomId, AthleteId, DateStart, DateEnd) @"INSERT INTO AthleteAccommodation (RoomId, AthleteId, Price, DateStart, DateEnd)
VALUES (@RoomId, @AthleteId, @DateStart, @DateEnd)"; VALUES (@RoomId, @AthleteId, @Price, @DateStart, @DateEnd)";
connection.Execute(queryInsert, athleteAccommodation); connection.Execute(queryInsert, athleteAccommodation);
} }
catch (Exception ex) catch (Exception ex)