WIP ПИбд-23. Максимов А.П. Лабораторная работа №2 #2
@ -9,13 +9,13 @@ namespace ProjectTourismCompany.Entities;
|
||||
public class Check
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public string Title { get; private set; } = string.Empty;
|
||||
//public string TripTitle { get; private set; } = string.Empty;
|
||||
public DateTime PurchaseDate { get; private set; }
|
||||
public int Price { get; private set; }
|
||||
public int TripId { get; private set; }
|
||||
public int ClientId { get; private set; }
|
||||
public static Check CreateCheck(int id, DateTime purchaseDate, int price, int tripId, int clientId)
|
||||
public static Check CreateCheck(int id, DateTime purchaseDate, int price, int tripId, int clientId)//string triptitle,
|
||||
{
|
||||
return new Check() { Id = id, PurchaseDate = purchaseDate, Price = price, TripId = tripId, ClientId = clientId };
|
||||
return new Check() { Id = id, PurchaseDate = purchaseDate, Price = price, TripId = tripId, ClientId = clientId };//TripTitle = triptitle,
|
||||
}
|
||||
}
|
||||
|
@ -10,15 +10,15 @@ public class CompanyTrip
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public int CompanyId { get; private set; }
|
||||
public int TripId { get; private set; }
|
||||
//public int TripId { get; private set; }
|
||||
public int AdditionalPrice { get; private set; }
|
||||
public static CompanyTrip CreateCompanyTrip(int id, int companyId, int tripId, int additionalPrice)
|
||||
public static CompanyTrip CreateCompanyTrip(int id, int companyId , int additionalPrice)//int tripId,
|
||||
{
|
||||
return new CompanyTrip()
|
||||
{
|
||||
Id = id,
|
||||
CompanyId = companyId,
|
||||
TripId = tripId,
|
||||
//TripId = tripId,
|
||||
AdditionalPrice = additionalPrice
|
||||
};
|
||||
}
|
||||
|
@ -17,7 +17,6 @@ public class Trip
|
||||
public DateTime EndDate { get; private set;}
|
||||
public string StartCity { get; private set; }=string.Empty;
|
||||
public string EndCity { get; private set;} =string.Empty;
|
||||
public int CompanyId { get; private set; }
|
||||
public TravelType TravelType { get; private set; }
|
||||
|
||||
public IEnumerable<CompanyTrip> CompanyTrip
|
||||
|
@ -37,7 +37,7 @@
|
||||
label2 = new Label();
|
||||
label4 = new Label();
|
||||
comboBoxClient = new ComboBox();
|
||||
comboBoxTrip = new ComboBox();
|
||||
comboBoxTripId = new ComboBox();
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownPrice).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
@ -125,21 +125,21 @@
|
||||
comboBoxClient.Size = new Size(217, 28);
|
||||
comboBoxClient.TabIndex = 41;
|
||||
//
|
||||
// comboBoxTrip
|
||||
// comboBoxTripId
|
||||
//
|
||||
comboBoxTrip.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxTrip.FormattingEnabled = true;
|
||||
comboBoxTrip.Location = new Point(281, 155);
|
||||
comboBoxTrip.Name = "comboBoxTrip";
|
||||
comboBoxTrip.Size = new Size(217, 28);
|
||||
comboBoxTrip.TabIndex = 42;
|
||||
comboBoxTripId.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxTripId.FormattingEnabled = true;
|
||||
comboBoxTripId.Location = new Point(281, 155);
|
||||
comboBoxTripId.Name = "comboBoxTripId";
|
||||
comboBoxTripId.Size = new Size(217, 28);
|
||||
comboBoxTripId.TabIndex = 42;
|
||||
//
|
||||
// FormCheck
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(513, 272);
|
||||
Controls.Add(comboBoxTrip);
|
||||
ClientSize = new Size(516, 281);
|
||||
Controls.Add(comboBoxTripId);
|
||||
Controls.Add(comboBoxClient);
|
||||
Controls.Add(label4);
|
||||
Controls.Add(label2);
|
||||
@ -168,6 +168,6 @@
|
||||
private Label label2;
|
||||
private Label label4;
|
||||
private ComboBox comboBoxClient;
|
||||
private ComboBox comboBoxTrip;
|
||||
private ComboBox comboBoxTripId;
|
||||
}
|
||||
}
|
@ -32,11 +32,6 @@ public partial class FormCheck : Form
|
||||
}
|
||||
dateTimePickerPurchaseDate.Value = check.PurchaseDate;
|
||||
numericUpDownPrice.Value = check.Price;
|
||||
|
||||
comboBoxTrip.SelectedItem = check.Title;
|
||||
|
||||
|
||||
comboBoxTrip.SelectedItem = check.TripId;
|
||||
_checkId = value;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -54,24 +49,25 @@ public partial class FormCheck : Form
|
||||
comboBoxClient.DataSource = clientRepository.ReadClients();
|
||||
comboBoxClient.DisplayMember = "Name";
|
||||
comboBoxClient.ValueMember = "Id";
|
||||
|
||||
comboBoxTrip.DisplayMember = "Title";
|
||||
comboBoxTrip.ValueMember = "Id";
|
||||
comboBoxTrip.DataSource = tripRepository.ReadTrips();
|
||||
|
||||
comboBoxTripId.DataSource = tripRepository.ReadTrips();
|
||||
comboBoxTripId.DisplayMember = "Title";
|
||||
comboBoxTripId.ValueMember = "Id";
|
||||
|
||||
|
||||
}
|
||||
private void buttonSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (comboBoxTrip.SelectedIndex < 0 ||
|
||||
if (comboBoxTripId.SelectedIndex < 0 ||
|
||||
comboBoxClient.SelectedIndex < 0)
|
||||
{
|
||||
throw new Exception("Имеются незаполненные поля");
|
||||
}
|
||||
_checkRepository.CreateCheck(Check.CreateCheck(_checkId, dateTimePickerPurchaseDate.Value,
|
||||
(int)numericUpDownPrice.Value, (int)comboBoxTrip.SelectedIndex!,
|
||||
(int)comboBoxClient.SelectedIndex!));
|
||||
_checkRepository.CreateCheck(Check.CreateCheck(_checkId , dateTimePickerPurchaseDate.Value,
|
||||
(int)numericUpDownPrice.Value, (int)comboBoxTripId.SelectedValue!,
|
||||
(int)comboBoxClient.SelectedValue!));
|
||||
Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -52,7 +52,7 @@
|
||||
dataGridViewChecks.RowHeadersVisible = false;
|
||||
dataGridViewChecks.RowHeadersWidth = 51;
|
||||
dataGridViewChecks.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||
dataGridViewChecks.Size = new Size(800, 450);
|
||||
dataGridViewChecks.Size = new Size(643, 450);
|
||||
dataGridViewChecks.TabIndex = 0;
|
||||
//
|
||||
// panel1
|
||||
@ -92,8 +92,8 @@
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 450);
|
||||
Controls.Add(panel1);
|
||||
Controls.Add(dataGridViewChecks);
|
||||
Controls.Add(panel1);
|
||||
Name = "FormChecks";
|
||||
Text = "Чеки";
|
||||
Load += FormChecks_Load;
|
||||
|
@ -33,6 +33,7 @@ public partial class FormCompany : Form
|
||||
|
||||
textBoxName.Text = client.Name;
|
||||
comboBoxCountry.SelectedItem = client.CountryId;
|
||||
comboBoxCountry.SelectedValue = client.CountryId;
|
||||
_companyId = value;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -57,6 +58,7 @@ public partial class FormCompany : Form
|
||||
comboBoxCountry.DataSource = countryRepository.ReadCountries();
|
||||
comboBoxCountry.DisplayMember = "CountryName";
|
||||
comboBoxCountry.ValueMember = "Id";
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -64,11 +66,18 @@ public partial class FormCompany : Form
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(textBoxName.Text))
|
||||
if (string.IsNullOrWhiteSpace(textBoxName.Text))
|
||||
{
|
||||
throw new Exception("Имеются незаполненные поля");
|
||||
throw new Exception("Имеются незаполненные поля");
|
||||
}
|
||||
if (_companyId.HasValue)
|
||||
{
|
||||
_companyRepository.UpdateCompany(CreateCompany(_companyId.Value));
|
||||
}
|
||||
else
|
||||
{
|
||||
_companyRepository.CreateCompany(CreateCompany(0));
|
||||
}
|
||||
_companyRepository.CreateCompany(Company.CreateCompany(0, textBoxName.Text, (int)comboBoxCountry.SelectedItem!));
|
||||
Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -76,8 +85,15 @@ public partial class FormCompany : Form
|
||||
MessageBox.Show(ex.Message, "Ошибка при сохранении",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
}
|
||||
private void ButtonCancel_Click(object sender, EventArgs e) =>
|
||||
Close();
|
||||
|
||||
|
||||
|
||||
|
||||
private Company CreateCompany(int id)
|
||||
{
|
||||
return Company.CreateCompany(id, textBoxName.Text, (int)comboBoxCountry.SelectedValue!);
|
||||
}
|
||||
}
|
||||
|
@ -237,7 +237,6 @@
|
||||
dataGridView1.Location = new Point(3, 23);
|
||||
dataGridView1.MultiSelect = false;
|
||||
dataGridView1.Name = "dataGridView1";
|
||||
dataGridView1.ReadOnly = true;
|
||||
dataGridView1.RowHeadersVisible = false;
|
||||
dataGridView1.RowHeadersWidth = 51;
|
||||
dataGridView1.Size = new Size(426, 450);
|
||||
@ -248,14 +247,12 @@
|
||||
columnCompanyName.HeaderText = "Название компании";
|
||||
columnCompanyName.MinimumWidth = 6;
|
||||
columnCompanyName.Name = "columnCompanyName";
|
||||
columnCompanyName.ReadOnly = true;
|
||||
//
|
||||
// ColumnAdditionalPrice
|
||||
//
|
||||
ColumnAdditionalPrice.HeaderText = "Добавочная стоимость";
|
||||
ColumnAdditionalPrice.MinimumWidth = 6;
|
||||
ColumnAdditionalPrice.Name = "ColumnAdditionalPrice";
|
||||
ColumnAdditionalPrice.ReadOnly = true;
|
||||
ColumnAdditionalPrice.Resizable = DataGridViewTriState.True;
|
||||
ColumnAdditionalPrice.SortMode = DataGridViewColumnSortMode.NotSortable;
|
||||
//
|
||||
|
@ -74,19 +74,11 @@ Enum.GetValues(typeof(TravelType)))
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(textBoxStartCity.Text) ||
|
||||
string.IsNullOrWhiteSpace(textBoxEndCity.Text) || dataGridView1.RowCount < 1)
|
||||
string.IsNullOrWhiteSpace(textBoxEndCity.Text) || dataGridView1.RowCount < 1 || dateTimePickerStartDate.Value > dateTimePickerEndDate.Value)
|
||||
{
|
||||
throw new Exception("Имеются незаполненные поля");
|
||||
}
|
||||
|
||||
if (_tripId.HasValue)
|
||||
{
|
||||
_tripRepository.CreateTrip(CreateTrip(_tripId.Value));
|
||||
}
|
||||
else
|
||||
{
|
||||
_tripRepository.CreateTrip(CreateTrip(0));
|
||||
throw new Exception("Имеются незаполненные или некорректно заполненные поля");
|
||||
}
|
||||
_tripRepository.CreateTrip(CreateTrip(0));
|
||||
|
||||
Close();
|
||||
}
|
||||
@ -122,7 +114,7 @@ Enum.GetValues(typeof(TravelType)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
list.Add(CompanyTrip.CreateCompanyTrip(0, 0,
|
||||
list.Add(CompanyTrip.CreateCompanyTrip(0,
|
||||
Convert.ToInt32(row.Cells["ColumnCompanyName"].Value),
|
||||
Convert.ToInt32(row.Cells["ColumnAdditionalPrice"].Value)));
|
||||
}
|
||||
|
@ -48,6 +48,7 @@
|
||||
dataGridView1.MultiSelect = false;
|
||||
dataGridView1.Name = "dataGridView1";
|
||||
dataGridView1.ReadOnly = true;
|
||||
dataGridView1.RowHeadersVisible = false;
|
||||
dataGridView1.RowHeadersWidth = 51;
|
||||
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||
dataGridView1.Size = new Size(645, 450);
|
||||
|
@ -33,8 +33,8 @@ internal class CheckRepository : ICheckRepository
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryInsert = @"
|
||||
INSERT INTO Receipt (Title, PurchaseDate, Price, TripId, ClientId)
|
||||
VALUES (@Title, @PurchaseDate, @Price, @TripId, @ClientId)";
|
||||
INSERT INTO Receipt (PurchaseDate, Price, TripId, ClientId)
|
||||
VALUES (@PurchaseDate, @Price, @TripId, @ClientId)";
|
||||
connection.Execute(queryInsert, check);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -9,6 +9,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Unity;
|
||||
|
||||
namespace ProjectTourismCompany.Repositories.Implementations;
|
||||
|
||||
@ -33,35 +34,18 @@ internal class CompanyRepository : ICompanyRepository
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
NpgsqlConnection(_connectionString.ConnectionString);
|
||||
connection.Open();
|
||||
using var transaction = connection.BeginTransaction();
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryInsert = @"
|
||||
INSERT INTO Company (Name, CountryId)
|
||||
VALUES (@Name, @CountryId);
|
||||
SELECT MAX(Id) FROM Company";
|
||||
var companyId =
|
||||
connection.QueryFirst<int>(queryInsert, company, transaction);
|
||||
var querySubInsert = @"
|
||||
INSERT INTO CompanyTrip (CompanyId, TripId, AdditionalPrice)
|
||||
VALUES (@CompanyId, @TripId, @AdditionalPrice)";
|
||||
foreach (var elem in company.CompanyTrip)
|
||||
{
|
||||
connection.Execute(querySubInsert, new
|
||||
{
|
||||
companyId,
|
||||
elem.TripId,
|
||||
elem.AdditionalPrice
|
||||
}, transaction);
|
||||
}
|
||||
transaction.Commit();
|
||||
VALUES (@Name, @CountryId)";
|
||||
connection.Execute(queryInsert, company);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void DeleteCompany(int id)
|
||||
|
@ -27,20 +27,38 @@ internal class TripRepository : ITripRepository
|
||||
{
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(trip));
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
using var connection = new
|
||||
NpgsqlConnection(_connectionString.ConnectionString);
|
||||
connection.Open();
|
||||
using var transaction = connection.BeginTransaction();
|
||||
var queryInsert = @"
|
||||
INSERT INTO Trip (Title, Price, HumanCapacity, StartDate, EndDate, StartCity, EndCity, CompanyId, TravelType)
|
||||
VALUES (@Title, @Price, @HumanCapacity, @StartDate, @EndDate, @StartCity, @EndCity, @CompanyId, @TravelType)";
|
||||
connection.Execute(queryInsert, trip);
|
||||
INSERT INTO Trip (Title, Price, HumanCapacity, StartDate, EndDate, StartCity, EndCity, TravelType)
|
||||
VALUES (@Title, @Price, @HumanCapacity, @StartDate, @EndDate, @StartCity, @EndCity, @TravelType);
|
||||
SELECT MAX(Id) FROM Trip";
|
||||
var companyTripId =
|
||||
connection.QueryFirst<int>(queryInsert, trip, transaction);
|
||||
var querySubInsert = @"
|
||||
INSERT INTO CompanyTrip (CompanyId, AdditionalPrice)
|
||||
VALUES (@CompanyId, @AdditionalPrice)";
|
||||
foreach (var elem in trip.CompanyTrip)
|
||||
{
|
||||
connection.Execute(querySubInsert, new
|
||||
{
|
||||
companyTripId,
|
||||
elem.CompanyId,
|
||||
elem.AdditionalPrice
|
||||
}, transaction);
|
||||
}
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Trip ReadTripById(int id)
|
||||
|
Loading…
x
Reference in New Issue
Block a user