diff --git a/SUBD_Car_rent/Forms/FormCarModel.Designer.cs b/SUBD_Car_rent/Forms/FormCarModel.Designer.cs index 10ec0ee..046213e 100644 --- a/SUBD_Car_rent/Forms/FormCarModel.Designer.cs +++ b/SUBD_Car_rent/Forms/FormCarModel.Designer.cs @@ -28,12 +28,186 @@ /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "FormCarModel"; + dataGridView = new DataGridView(); + label1 = new Label(); + label2 = new Label(); + label3 = new Label(); + label4 = new Label(); + label5 = new Label(); + textBoxBrand = new TextBox(); + textBoxModel = new TextBox(); + textBoxYear = new TextBox(); + textBoxSeats = new TextBox(); + comboBoxBodyType = new ComboBox(); + buttonCreate = new Button(); + buttonUpdate = new Button(); + buttonDelete = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(12, 12); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(603, 426); + dataGridView.TabIndex = 0; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(621, 12); + label1.Name = "label1"; + label1.Size = new Size(38, 15); + label1.TabIndex = 1; + label1.Text = "Brand"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(621, 41); + label2.Name = "label2"; + label2.Size = new Size(41, 15); + label2.TabIndex = 2; + label2.Text = "Model"; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(621, 70); + label3.Name = "label3"; + label3.Size = new Size(29, 15); + label3.TabIndex = 3; + label3.Text = "Year"; + // + // label4 + // + label4.AutoSize = true; + label4.Location = new Point(621, 99); + label4.Name = "label4"; + label4.Size = new Size(60, 15); + label4.TabIndex = 4; + label4.Text = "Body type"; + // + // label5 + // + label5.AutoSize = true; + label5.Location = new Point(621, 128); + label5.Name = "label5"; + label5.Size = new Size(34, 15); + label5.TabIndex = 5; + label5.Text = "Seats"; + // + // textBoxBrand + // + textBoxBrand.Location = new Point(687, 9); + textBoxBrand.Name = "textBoxBrand"; + textBoxBrand.Size = new Size(100, 23); + textBoxBrand.TabIndex = 6; + // + // textBoxModel + // + textBoxModel.Location = new Point(687, 38); + textBoxModel.Name = "textBoxModel"; + textBoxModel.Size = new Size(100, 23); + textBoxModel.TabIndex = 7; + // + // textBoxYear + // + textBoxYear.Location = new Point(687, 67); + textBoxYear.Name = "textBoxYear"; + textBoxYear.Size = new Size(100, 23); + textBoxYear.TabIndex = 8; + // + // textBoxSeats + // + textBoxSeats.Location = new Point(687, 125); + textBoxSeats.Name = "textBoxSeats"; + textBoxSeats.Size = new Size(100, 23); + textBoxSeats.TabIndex = 10; + // + // comboBoxBodyType + // + comboBoxBodyType.FormattingEnabled = true; + comboBoxBodyType.Location = new Point(687, 96); + comboBoxBodyType.Name = "comboBoxBodyType"; + comboBoxBodyType.Size = new Size(100, 23); + comboBoxBodyType.TabIndex = 11; + // + // buttonCreate + // + buttonCreate.Location = new Point(687, 154); + buttonCreate.Name = "buttonCreate"; + buttonCreate.Size = new Size(75, 23); + buttonCreate.TabIndex = 12; + buttonCreate.Text = "create"; + buttonCreate.UseVisualStyleBackColor = true; + buttonCreate.Click += buttonCreate_Click; + // + // buttonUpdate + // + buttonUpdate.Location = new Point(687, 183); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(75, 23); + buttonUpdate.TabIndex = 13; + buttonUpdate.Text = "update"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += buttonUpdate_Click; + // + // buttonDelete + // + buttonDelete.Location = new Point(687, 212); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(75, 23); + buttonDelete.TabIndex = 14; + buttonDelete.Text = "delete"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += buttonDelete_Click; + // + // FormCarModel + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(buttonDelete); + Controls.Add(buttonUpdate); + Controls.Add(buttonCreate); + Controls.Add(comboBoxBodyType); + Controls.Add(textBoxSeats); + Controls.Add(textBoxYear); + Controls.Add(textBoxModel); + Controls.Add(textBoxBrand); + Controls.Add(label5); + Controls.Add(label4); + Controls.Add(label3); + Controls.Add(label2); + Controls.Add(label1); + Controls.Add(dataGridView); + Name = "FormCarModel"; + Text = "FormCarModel"; + Load += FormCarModel_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); } #endregion + + private DataGridView dataGridView; + private Label label1; + private Label label2; + private Label label3; + private Label label4; + private Label label5; + private TextBox textBoxBrand; + private TextBox textBoxModel; + private TextBox textBoxYear; + private TextBox textBoxSeats; + private ComboBox comboBoxBodyType; + private Button buttonCreate; + private Button buttonUpdate; + private Button buttonDelete; } } \ No newline at end of file diff --git a/SUBD_Car_rent/Forms/FormCarModel.cs b/SUBD_Car_rent/Forms/FormCarModel.cs index 867cd93..8bc0d8a 100644 --- a/SUBD_Car_rent/Forms/FormCarModel.cs +++ b/SUBD_Car_rent/Forms/FormCarModel.cs @@ -1,4 +1,5 @@ using database; +using System.Windows.Forms; namespace Forms { @@ -10,5 +11,50 @@ namespace Forms InitializeComponent(); bd = _bd; } + + private void loadData() + { + List carModels = bd.GetCarModels(); + + // Очищаем dataGridView перед заполнением новыми данными + dataGridView.Rows.Clear(); + + // Предварительно определяем столбцы, если это не было сделано ранее + if (dataGridView.ColumnCount == 0) + { + dataGridView.Columns.Add("Id", "ID"); + dataGridView.Columns.Add("Brand", "Brand"); + dataGridView.Columns.Add("Model", "Model"); + dataGridView.Columns.Add("Year", "Year"); + dataGridView.Columns.Add("BodyType", "Body type"); + dataGridView.Columns.Add("Seats", "Seats"); + } + + // Заполняем dataGridView данными из списка моделей автомобилей + foreach (CarModel carModel in carModels) + { + dataGridView.Rows.Add(carModel.Id, carModel.Brand, carModel.Model, carModel.Year, bd.GetBodyTypeById(carModel.BodyTypeId).Title, carModel.Seats); + } + } + + private void buttonCreate_Click(object sender, EventArgs e) + { + + } + + private void buttonUpdate_Click(object sender, EventArgs e) + { + + } + + private void buttonDelete_Click(object sender, EventArgs e) + { + + } + + private void FormCarModel_Load(object sender, EventArgs e) + { + loadData(); + } } } diff --git a/SUBD_Car_rent/Forms/FormCarModel.resx b/SUBD_Car_rent/Forms/FormCarModel.resx index 1af7de1..af32865 100644 --- a/SUBD_Car_rent/Forms/FormCarModel.resx +++ b/SUBD_Car_rent/Forms/FormCarModel.resx @@ -1,17 +1,17 @@  - diff --git a/SUBD_Car_rent/Forms/Forms.csproj b/SUBD_Car_rent/Forms/Forms.csproj index d97ca3c..f648db7 100644 --- a/SUBD_Car_rent/Forms/Forms.csproj +++ b/SUBD_Car_rent/Forms/Forms.csproj @@ -13,7 +13,7 @@ - + \ No newline at end of file diff --git a/SUBD_Car_rent/SUBD_Car_rent.sln b/SUBD_Car_rent/SUBD_Car_rent.sln index fcf9603..329a72b 100644 --- a/SUBD_Car_rent/SUBD_Car_rent.sln +++ b/SUBD_Car_rent/SUBD_Car_rent.sln @@ -3,9 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.8.34309.116 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "database", "databaseAbstractions\database.csproj", "{874A3D9B-6051-4823-9A3B-725C71FDC245}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Forms", "Forms\Forms.csproj", "{318E26AF-A4DC-4863-B829-DBD4B63DC0D7}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Forms", "Forms\Forms.csproj", "{318E26AF-A4DC-4863-B829-DBD4B63DC0D7}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "database", "database\database.csproj", "{4CD0F569-0037-400E-B6CB-5F553650C6DA}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -13,14 +13,14 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {874A3D9B-6051-4823-9A3B-725C71FDC245}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {874A3D9B-6051-4823-9A3B-725C71FDC245}.Debug|Any CPU.Build.0 = Debug|Any CPU - {874A3D9B-6051-4823-9A3B-725C71FDC245}.Release|Any CPU.ActiveCfg = Release|Any CPU - {874A3D9B-6051-4823-9A3B-725C71FDC245}.Release|Any CPU.Build.0 = Release|Any CPU {318E26AF-A4DC-4863-B829-DBD4B63DC0D7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {318E26AF-A4DC-4863-B829-DBD4B63DC0D7}.Debug|Any CPU.Build.0 = Debug|Any CPU {318E26AF-A4DC-4863-B829-DBD4B63DC0D7}.Release|Any CPU.ActiveCfg = Release|Any CPU {318E26AF-A4DC-4863-B829-DBD4B63DC0D7}.Release|Any CPU.Build.0 = Release|Any CPU + {4CD0F569-0037-400E-B6CB-5F553650C6DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4CD0F569-0037-400E-B6CB-5F553650C6DA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4CD0F569-0037-400E-B6CB-5F553650C6DA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4CD0F569-0037-400E-B6CB-5F553650C6DA}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/SUBD_Car_rent/databaseAbstractions/Abstractions.cs b/SUBD_Car_rent/database/Abstractions.cs similarity index 100% rename from SUBD_Car_rent/databaseAbstractions/Abstractions.cs rename to SUBD_Car_rent/database/Abstractions.cs diff --git a/SUBD_Car_rent/databaseAbstractions/Implementation.cs b/SUBD_Car_rent/database/Implementation.cs similarity index 94% rename from SUBD_Car_rent/databaseAbstractions/Implementation.cs rename to SUBD_Car_rent/database/Implementation.cs index 261e0f8..03deef4 100644 --- a/SUBD_Car_rent/databaseAbstractions/Implementation.cs +++ b/SUBD_Car_rent/database/Implementation.cs @@ -16,7 +16,7 @@ namespace database { using var conn = GetConnection(); conn.Open(); - using var cmd = new NpgsqlCommand($"INSERT INTO car (id, model_id, branch_id, year, mileage, status_id) VALUES ({car.Id}, {car.ModelId}, {car.BranchId}, {car.Year}, {car.Mileage}, {car.StatusId})", conn); + using var cmd = new NpgsqlCommand($"INSERT INTO car (model_id, branch_id, year, mileage, status_id) VALUES ({car.ModelId}, {car.BranchId}, {car.Year}, {car.Mileage}, {car.StatusId})", conn); cmd.ExecuteNonQuery(); } @@ -84,7 +84,7 @@ namespace database { using var conn = GetConnection(); conn.Open(); - using var cmd = new NpgsqlCommand($"INSERT INTO client (id, name, surname, address, phone, email) VALUES ({client.Id}, '{client.Name}', '{client.Surname}', '{client.Address}', '{client.Phone}', '{client.Email}')", conn); + using var cmd = new NpgsqlCommand($"INSERT INTO client (name, surname, address, phone, email) VALUES ('{client.Name}', '{client.Surname}', '{client.Address}', '{client.Phone}', '{client.Email}')", conn); cmd.ExecuteNonQuery(); } @@ -152,7 +152,7 @@ namespace database { using var conn = GetConnection(); conn.Open(); - using var cmd = new NpgsqlCommand($"INSERT INTO rental (id, car_id, client_id, start_date, end_date, cost) VALUES ({rental.Id}, {rental.CarId}, {rental.ClientId}, '{rental.StartDate}', '{rental.EndDate}', {rental.Cost})", conn); + using var cmd = new NpgsqlCommand($"INSERT INTO rental (car_id, client_id, start_date, end_date, cost) VALUES ({rental.CarId}, {rental.ClientId}, '{rental.StartDate}', '{rental.EndDate}', {rental.Cost})", conn); cmd.ExecuteNonQuery(); } @@ -220,7 +220,7 @@ namespace database { using var conn = GetConnection(); conn.Open(); - using var cmd = new NpgsqlCommand($"INSERT INTO car_model (id, brand, model, year, body_type_id, seats) VALUES ({carModel.Id}, '{carModel.Brand}', '{carModel.Model}', {carModel.Year}, {carModel.BodyTypeId}, {carModel.Seats})", conn); + using var cmd = new NpgsqlCommand($"INSERT INTO car_model (brand, model, year, body_type_id, seats) VALUES ('{carModel.Brand}', '{carModel.Model}', {carModel.Year}, {carModel.BodyTypeId}, {carModel.Seats})", conn); cmd.ExecuteNonQuery(); } @@ -287,7 +287,7 @@ namespace database { using var conn = GetConnection(); conn.Open(); - using var cmd = new NpgsqlCommand($"INSERT INTO branch (id, name, address, phone, working_hours) VALUES ({branch.Id}, '{branch.Name}', '{branch.Address}', '{branch.Phone}', '{branch.WorkingHours}')", conn); + using var cmd = new NpgsqlCommand($"INSERT INTO branch (name, address, phone, working_hours) VALUES ('{branch.Name}', '{branch.Address}', '{branch.Phone}', '{branch.WorkingHours}')", conn); cmd.ExecuteNonQuery(); } @@ -353,7 +353,7 @@ namespace database { using var conn = GetConnection(); conn.Open(); - using var cmd = new NpgsqlCommand($"INSERT INTO status (id, title) VALUES ({status.Id}, '{status.Title}')", conn); + using var cmd = new NpgsqlCommand($"INSERT INTO status (title) VALUES ('{status.Title}')", conn); cmd.ExecuteNonQuery(); } @@ -413,7 +413,7 @@ namespace database { using var conn = GetConnection(); conn.Open(); - using var cmd = new NpgsqlCommand($"INSERT INTO body_type (id, title) VALUES ({bodyType.Id}, '{bodyType.Title}')", conn); + using var cmd = new NpgsqlCommand($"INSERT INTO body_type (title) VALUES ('{bodyType.Title}')", conn); cmd.ExecuteNonQuery(); } diff --git a/SUBD_Car_rent/databaseAbstractions/database.csproj b/SUBD_Car_rent/database/database.csproj similarity index 100% rename from SUBD_Car_rent/databaseAbstractions/database.csproj rename to SUBD_Car_rent/database/database.csproj diff --git a/SUBD_Car_rent/databaseAbstractions/models.cs b/SUBD_Car_rent/database/models.cs similarity index 100% rename from SUBD_Car_rent/databaseAbstractions/models.cs rename to SUBD_Car_rent/database/models.cs