From c2be31edef9df668971549b469131e8afc95b983 Mon Sep 17 00:00:00 2001 From: Timourka Date: Tue, 26 Mar 2024 21:17:45 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B8=D0=BB=20=D1=80=D0=B0?= =?UTF-8?q?=D0=B1=D0=BE=D1=82=D1=83=20=D1=81=20=D0=B1=D0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SUBD_Car_rent/Forms/FormMain.Designer.cs | 90 +++++++++---- SUBD_Car_rent/Forms/FormMain.cs | 27 +++- SUBD_Car_rent/Forms/FormMain.resx | 3 + .../databaseAbstractions/Abstractions.cs | 14 ++ .../databaseAbstractions/Implementation.cs | 120 ++++++++++++++++++ SUBD_Car_rent/databaseAbstractions/models.cs | 20 ++- 6 files changed, 243 insertions(+), 31 deletions(-) diff --git a/SUBD_Car_rent/Forms/FormMain.Designer.cs b/SUBD_Car_rent/Forms/FormMain.Designer.cs index 27eae93..f2f3772 100644 --- a/SUBD_Car_rent/Forms/FormMain.Designer.cs +++ b/SUBD_Car_rent/Forms/FormMain.Designer.cs @@ -28,46 +28,90 @@ /// private void InitializeComponent() { - button1 = new Button(); - dataGridView1 = new DataGridView(); - ((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit(); + menuStrip1 = new MenuStrip(); + tablesToolStripMenuItem = new ToolStripMenuItem(); + carModelToolStripMenuItem = new ToolStripMenuItem(); + carToolStripMenuItem = new ToolStripMenuItem(); + branchToolStripMenuItem = new ToolStripMenuItem(); + clientToolStripMenuItem = new ToolStripMenuItem(); + rentalToolStripMenuItem = new ToolStripMenuItem(); + menuStrip1.SuspendLayout(); SuspendLayout(); // - // button1 + // menuStrip1 // - button1.Location = new Point(12, 12); - button1.Name = "button1"; - button1.Size = new Size(75, 23); - button1.TabIndex = 0; - button1.Text = "button1"; - button1.UseVisualStyleBackColor = true; - button1.Click += button1_Click; + menuStrip1.Items.AddRange(new ToolStripItem[] { tablesToolStripMenuItem }); + menuStrip1.Location = new Point(0, 0); + menuStrip1.Name = "menuStrip1"; + menuStrip1.Size = new Size(800, 24); + menuStrip1.TabIndex = 0; + menuStrip1.Text = "menuStrip1"; // - // dataGridView1 + // tablesToolStripMenuItem // - dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView1.Location = new Point(12, 41); - dataGridView1.Name = "dataGridView1"; - dataGridView1.RowTemplate.Height = 25; - dataGridView1.Size = new Size(776, 397); - dataGridView1.TabIndex = 1; + tablesToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { carModelToolStripMenuItem, carToolStripMenuItem, branchToolStripMenuItem, clientToolStripMenuItem, rentalToolStripMenuItem }); + tablesToolStripMenuItem.Name = "tablesToolStripMenuItem"; + tablesToolStripMenuItem.Size = new Size(50, 20); + tablesToolStripMenuItem.Text = "tables"; + // + // carModelToolStripMenuItem + // + carModelToolStripMenuItem.Name = "carModelToolStripMenuItem"; + carModelToolStripMenuItem.Size = new Size(180, 22); + carModelToolStripMenuItem.Text = "car model"; + carModelToolStripMenuItem.Click += carModelToolStripMenuItem_Click; + // + // carToolStripMenuItem + // + carToolStripMenuItem.Name = "carToolStripMenuItem"; + carToolStripMenuItem.Size = new Size(180, 22); + carToolStripMenuItem.Text = "car"; + carToolStripMenuItem.Click += carToolStripMenuItem_Click; + // + // branchToolStripMenuItem + // + branchToolStripMenuItem.Name = "branchToolStripMenuItem"; + branchToolStripMenuItem.Size = new Size(180, 22); + branchToolStripMenuItem.Text = "branch"; + branchToolStripMenuItem.Click += branchToolStripMenuItem_Click; + // + // clientToolStripMenuItem + // + clientToolStripMenuItem.Name = "clientToolStripMenuItem"; + clientToolStripMenuItem.Size = new Size(180, 22); + clientToolStripMenuItem.Text = "client"; + clientToolStripMenuItem.Click += clientToolStripMenuItem_Click; + // + // rentalToolStripMenuItem + // + rentalToolStripMenuItem.Name = "rentalToolStripMenuItem"; + rentalToolStripMenuItem.Size = new Size(180, 22); + rentalToolStripMenuItem.Text = "rental"; + rentalToolStripMenuItem.Click += rentalToolStripMenuItem_Click; // // FormMain // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(800, 450); - Controls.Add(dataGridView1); - Controls.Add(button1); + Controls.Add(menuStrip1); + MainMenuStrip = menuStrip1; Name = "FormMain"; Text = "FormMain"; - ((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit(); + menuStrip1.ResumeLayout(false); + menuStrip1.PerformLayout(); ResumeLayout(false); + PerformLayout(); } #endregion - private Button button1; - private DataGridView dataGridView1; + private MenuStrip menuStrip1; + private ToolStripMenuItem tablesToolStripMenuItem; + private ToolStripMenuItem carModelToolStripMenuItem; + private ToolStripMenuItem carToolStripMenuItem; + private ToolStripMenuItem branchToolStripMenuItem; + private ToolStripMenuItem clientToolStripMenuItem; + private ToolStripMenuItem rentalToolStripMenuItem; } } \ No newline at end of file diff --git a/SUBD_Car_rent/Forms/FormMain.cs b/SUBD_Car_rent/Forms/FormMain.cs index bc81e5a..3c52181 100644 --- a/SUBD_Car_rent/Forms/FormMain.cs +++ b/SUBD_Car_rent/Forms/FormMain.cs @@ -4,12 +4,37 @@ namespace Forms { public partial class FormMain : Form { - + public FormMain() { InitializeComponent(); } + private void carModelToolStripMenuItem_Click(object sender, EventArgs e) + { + + } + + private void carToolStripMenuItem_Click(object sender, EventArgs e) + { + + } + + private void branchToolStripMenuItem_Click(object sender, EventArgs e) + { + + } + + private void clientToolStripMenuItem_Click(object sender, EventArgs e) + { + + } + + private void rentalToolStripMenuItem_Click(object sender, EventArgs e) + { + + } + /* private Abstractions bd = new Implementation(); private void button1_Click(object sender, EventArgs e) diff --git a/SUBD_Car_rent/Forms/FormMain.resx b/SUBD_Car_rent/Forms/FormMain.resx index af32865..a0623c8 100644 --- a/SUBD_Car_rent/Forms/FormMain.resx +++ b/SUBD_Car_rent/Forms/FormMain.resx @@ -117,4 +117,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + \ No newline at end of file diff --git a/SUBD_Car_rent/databaseAbstractions/Abstractions.cs b/SUBD_Car_rent/databaseAbstractions/Abstractions.cs index 8b961df..74dedff 100644 --- a/SUBD_Car_rent/databaseAbstractions/Abstractions.cs +++ b/SUBD_Car_rent/databaseAbstractions/Abstractions.cs @@ -39,5 +39,19 @@ public abstract List GetBranches(); public abstract void UpdateBranch(Branch branch); public abstract void DeleteBranch(int id); + + // Status + public abstract void AddStatus(Status status); + public abstract List GetStatuses(); + public abstract Status GetStatusById(int id); + public abstract void UpdateStatus(Status status); + public abstract void DeleteStatus(int id); + + // BodyType + public abstract void AddBodyType(BodyType bodyType); + public abstract List GetBodyTypes(); + public abstract BodyType GetBodyTypeById(int id); + public abstract void UpdateBodyType(BodyType bodyType); + public abstract void DeleteBodyType(int id); } } diff --git a/SUBD_Car_rent/databaseAbstractions/Implementation.cs b/SUBD_Car_rent/databaseAbstractions/Implementation.cs index bb03394..261e0f8 100644 --- a/SUBD_Car_rent/databaseAbstractions/Implementation.cs +++ b/SUBD_Car_rent/databaseAbstractions/Implementation.cs @@ -347,5 +347,125 @@ namespace database using var cmd = new NpgsqlCommand($"DELETE FROM branch WHERE id = {id}", conn); cmd.ExecuteNonQuery(); } + + // Status + public override void AddStatus(Status status) + { + using var conn = GetConnection(); + conn.Open(); + using var cmd = new NpgsqlCommand($"INSERT INTO status (id, title) VALUES ({status.Id}, '{status.Title}')", conn); + cmd.ExecuteNonQuery(); + } + + public override List GetStatuses() + { + var statuses = new List(); + using var conn = GetConnection(); + conn.Open(); + using var cmd = new NpgsqlCommand("SELECT * FROM status", conn); + using var reader = cmd.ExecuteReader(); + while (reader.Read()) + { + statuses.Add(new Status + { + Id = reader.GetInt32(0), + Title = reader.GetString(1) + }); + } + return statuses; + } + + public override Status GetStatusById(int id) + { + using var conn = GetConnection(); + conn.Open(); + using var cmd = new NpgsqlCommand($"SELECT * FROM status WHERE id = {id}", conn); + using var reader = cmd.ExecuteReader(); + if (reader.Read()) + { + return new Status + { + Id = reader.GetInt32(0), + Title = reader.GetString(1) + }; + } + return null; + } + + public override void UpdateStatus(Status status) + { + using var conn = GetConnection(); + conn.Open(); + using var cmd = new NpgsqlCommand($"UPDATE status SET title = '{status.Title}' WHERE id = {status.Id}", conn); + cmd.ExecuteNonQuery(); + } + + public override void DeleteStatus(int id) + { + using var conn = GetConnection(); + conn.Open(); + using var cmd = new NpgsqlCommand($"DELETE FROM status WHERE id = {id}", conn); + cmd.ExecuteNonQuery(); + } + + // BodyType + public override void AddBodyType(BodyType bodyType) + { + using var conn = GetConnection(); + conn.Open(); + using var cmd = new NpgsqlCommand($"INSERT INTO body_type (id, title) VALUES ({bodyType.Id}, '{bodyType.Title}')", conn); + cmd.ExecuteNonQuery(); + } + + public override List GetBodyTypes() + { + var bodyTypes = new List(); + using var conn = GetConnection(); + conn.Open(); + using var cmd = new NpgsqlCommand("SELECT * FROM body_type", conn); + using var reader = cmd.ExecuteReader(); + while (reader.Read()) + { + bodyTypes.Add(new BodyType + { + Id = reader.GetInt32(0), + Title = reader.GetString(1) + }); + } + return bodyTypes; + } + + public override BodyType GetBodyTypeById(int id) + { + using var conn = GetConnection(); + conn.Open(); + using var cmd = new NpgsqlCommand($"SELECT * FROM body_type WHERE id = {id}", conn); + using var reader = cmd.ExecuteReader(); + if (reader.Read()) + { + return new BodyType + { + Id = reader.GetInt32(0), + Title = reader.GetString(1) + }; + } + return null; + } + + public override void UpdateBodyType(BodyType bodyType) + { + using var conn = GetConnection(); + conn.Open(); + using var cmd = new NpgsqlCommand($"UPDATE body_type SET title = '{bodyType.Title}' WHERE id = {bodyType.Id}", conn); + cmd.ExecuteNonQuery(); + } + + public override void DeleteBodyType(int id) + { + using var conn = GetConnection(); + conn.Open(); + using var cmd = new NpgsqlCommand($"DELETE FROM body_type WHERE id = {id}", conn); + cmd.ExecuteNonQuery(); + } } } diff --git a/SUBD_Car_rent/databaseAbstractions/models.cs b/SUBD_Car_rent/databaseAbstractions/models.cs index 959eb24..6600cee 100644 --- a/SUBD_Car_rent/databaseAbstractions/models.cs +++ b/SUBD_Car_rent/databaseAbstractions/models.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace database +namespace database { // Определение моделей данных @@ -56,4 +50,16 @@ namespace database public string Phone { get; set; } public string WorkingHours { get; set; } } + + public class Status + { + public int Id { get; set; } + public string Title { get; set; } + } + + public class BodyType + { + public int Id { get; set; } + public string Title { get; set; } + } }