diff --git a/db_lab/DataForm.Designer.cs b/db_lab/DataForm.Designer.cs index 32b9b5d..ab9d1b4 100644 --- a/db_lab/DataForm.Designer.cs +++ b/db_lab/DataForm.Designer.cs @@ -28,12 +28,142 @@ /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); + this.dataGridView1 = new System.Windows.Forms.DataGridView(); + this.tableOrViewInput = new System.Windows.Forms.TextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.selectAllBtn = new System.Windows.Forms.Button(); + this.selectBuildingBtn = new System.Windows.Forms.Button(); + this.selectDepartmentBtn = new System.Windows.Forms.Button(); + this.selectAllRoomsBtn = new System.Windows.Forms.Button(); + this.selectAllEquipmentBtn = new System.Windows.Forms.Button(); + this.selectAllEquipmentArrivalDeparture = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView1 + // + this.dataGridView1.AllowUserToAddRows = false; + this.dataGridView1.AllowUserToDeleteRows = false; + this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView1.Dock = System.Windows.Forms.DockStyle.Bottom; + this.dataGridView1.Location = new System.Drawing.Point(0, 47); + this.dataGridView1.Name = "dataGridView1"; + this.dataGridView1.ReadOnly = true; + this.dataGridView1.Size = new System.Drawing.Size(800, 403); + this.dataGridView1.TabIndex = 0; + // + // tableOrViewInput + // + this.tableOrViewInput.Location = new System.Drawing.Point(12, 12); + this.tableOrViewInput.Name = "tableOrViewInput"; + this.tableOrViewInput.Size = new System.Drawing.Size(100, 20); + this.tableOrViewInput.TabIndex = 1; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(134, 18); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(67, 13); + this.label1.TabIndex = 2; + this.label1.Text = "table or view"; + // + // selectAllBtn + // + this.selectAllBtn.Location = new System.Drawing.Point(229, 12); + this.selectAllBtn.Name = "selectAllBtn"; + this.selectAllBtn.Size = new System.Drawing.Size(75, 23); + this.selectAllBtn.TabIndex = 3; + this.selectAllBtn.Text = "select all"; + this.selectAllBtn.UseVisualStyleBackColor = true; + this.selectAllBtn.Click += new System.EventHandler(this.selectAllBtn_Click); + // + // selectBuildingBtn + // + this.selectBuildingBtn.Location = new System.Drawing.Point(310, 13); + this.selectBuildingBtn.Name = "selectBuildingBtn"; + this.selectBuildingBtn.Size = new System.Drawing.Size(75, 23); + this.selectBuildingBtn.TabIndex = 4; + this.selectBuildingBtn.Text = "Здания"; + this.selectBuildingBtn.UseVisualStyleBackColor = true; + this.selectBuildingBtn.Click += new System.EventHandler(this.selectBuildingBtn_Click); + // + // selectDepartmentBtn + // + this.selectDepartmentBtn.Location = new System.Drawing.Point(391, 13); + this.selectDepartmentBtn.Name = "selectDepartmentBtn"; + this.selectDepartmentBtn.Size = new System.Drawing.Size(75, 23); + this.selectDepartmentBtn.TabIndex = 5; + this.selectDepartmentBtn.Text = "Отделы"; + this.selectDepartmentBtn.UseVisualStyleBackColor = true; + this.selectDepartmentBtn.Click += new System.EventHandler(this.selectDepartmentBtn_Click); + // + // selectAllRoomsBtn + // + this.selectAllRoomsBtn.AutoSize = true; + this.selectAllRoomsBtn.Location = new System.Drawing.Point(472, 13); + this.selectAllRoomsBtn.Name = "selectAllRoomsBtn"; + this.selectAllRoomsBtn.Size = new System.Drawing.Size(78, 23); + this.selectAllRoomsBtn.TabIndex = 6; + this.selectAllRoomsBtn.Text = "Помещения"; + this.selectAllRoomsBtn.UseVisualStyleBackColor = true; + this.selectAllRoomsBtn.Click += new System.EventHandler(this.selectAllRoomsBtn_Click); + // + // selectAllEquipmentBtn + // + this.selectAllEquipmentBtn.AutoSize = true; + this.selectAllEquipmentBtn.Location = new System.Drawing.Point(553, 13); + this.selectAllEquipmentBtn.Name = "selectAllEquipmentBtn"; + this.selectAllEquipmentBtn.Size = new System.Drawing.Size(90, 23); + this.selectAllEquipmentBtn.TabIndex = 7; + this.selectAllEquipmentBtn.Text = "Оборудование"; + this.selectAllEquipmentBtn.UseVisualStyleBackColor = true; + this.selectAllEquipmentBtn.Click += new System.EventHandler(this.selectAllEquipmentBtn_Click); + // + // selectAllEquipmentArrivalDeparture + // + this.selectAllEquipmentArrivalDeparture.AutoSize = true; + this.selectAllEquipmentArrivalDeparture.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.selectAllEquipmentArrivalDeparture.Location = new System.Drawing.Point(649, 13); + this.selectAllEquipmentArrivalDeparture.Name = "selectAllEquipmentArrivalDeparture"; + this.selectAllEquipmentArrivalDeparture.Size = new System.Drawing.Size(84, 23); + this.selectAllEquipmentArrivalDeparture.TabIndex = 8; + this.selectAllEquipmentArrivalDeparture.Text = "Приход/Уход"; + this.selectAllEquipmentArrivalDeparture.UseVisualStyleBackColor = true; + this.selectAllEquipmentArrivalDeparture.Click += new System.EventHandler(this.selectAllEquipmentArrivalDeparture_Click); + // + // DataForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.selectAllEquipmentArrivalDeparture); + this.Controls.Add(this.selectAllEquipmentBtn); + this.Controls.Add(this.selectAllRoomsBtn); + this.Controls.Add(this.selectDepartmentBtn); + this.Controls.Add(this.selectBuildingBtn); + this.Controls.Add(this.selectAllBtn); + this.Controls.Add(this.label1); + this.Controls.Add(this.tableOrViewInput); + this.Controls.Add(this.dataGridView1); + this.Name = "DataForm"; this.Text = "DataForm"; + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + } #endregion + + private System.Windows.Forms.DataGridView dataGridView1; + private System.Windows.Forms.TextBox tableOrViewInput; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Button selectAllBtn; + private System.Windows.Forms.Button selectBuildingBtn; + private System.Windows.Forms.Button selectDepartmentBtn; + private System.Windows.Forms.Button selectAllRoomsBtn; + private System.Windows.Forms.Button selectAllEquipmentBtn; + private System.Windows.Forms.Button selectAllEquipmentArrivalDeparture; } } \ No newline at end of file diff --git a/db_lab/DataForm.cs b/db_lab/DataForm.cs index 9c9ea78..6a9e6f1 100644 --- a/db_lab/DataForm.cs +++ b/db_lab/DataForm.cs @@ -1,4 +1,5 @@ -using System; +using Npgsql; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -7,14 +8,69 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using Npgsql; +using System.Web; namespace db_lab { public partial class DataForm : Form { - public DataForm() + NpgsqlConnection connection; + + public DataForm(string connection) { + this.connection = new NpgsqlConnection(connection); InitializeComponent(); } + + private void load_data(string view_or_table) + { + try + { + connection.Open(); + string sql = $"SELECT * FROM {view_or_table}"; + NpgsqlDataAdapter adapter = new NpgsqlDataAdapter(sql, this.connection); + DataSet dataset = new DataSet(); + adapter.Fill(dataset, "data"); + dataGridView1.DataSource = dataset.Tables["data"]; + connection.Close(); + } + catch (Exception ex) + { + MessageBox.Show($"Error! Log: {ex.Message}"); + connection.Close(); + } + } + + private void selectAllBtn_Click(object sender, EventArgs e) + { + var tableOrView = tableOrViewInput.Text.Trim(); + load_data(tableOrView); + } + + private void selectBuildingBtn_Click(object sender, EventArgs e) + { + load_data("Building"); + } + + private void selectDepartmentBtn_Click(object sender, EventArgs e) + { + load_data("Department"); + } + + private void selectAllRoomsBtn_Click(object sender, EventArgs e) + { + load_data("Rooms"); + } + + private void selectAllEquipmentBtn_Click(object sender, EventArgs e) + { + load_data("Equipment"); + } + + private void selectAllEquipmentArrivalDeparture_Click(object sender, EventArgs e) + { + load_data("equipment_arrival_departure"); + } } } diff --git a/db_lab/DataForm.resx b/db_lab/DataForm.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/db_lab/DataForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/db_lab/Form1.cs b/db_lab/Form1.cs index ff5e4f8..e8a5232 100644 --- a/db_lab/Form1.cs +++ b/db_lab/Form1.cs @@ -38,13 +38,13 @@ namespace db_lab private void raportBtn_Click(object sender, EventArgs e) { - RaportForm raportForm = new RaportForm(); + RaportForm raportForm = new RaportForm(connectionString); raportForm.Show(); } private void dataBtn_Click(object sender, EventArgs e) { - DataForm dataForm = new DataForm(); + DataForm dataForm = new DataForm(connectionString); dataForm.Show(); } @@ -60,6 +60,7 @@ namespace db_lab { this.connection = new NpgsqlConnection(this.connectionString); this.connection.Open(); + this.connection.Close(); MessageBox.Show("Database was successfuly connected!"); } catch (Exception ex) { diff --git a/db_lab/RaportForm.Designer.cs b/db_lab/RaportForm.Designer.cs index fc30b11..d18ad6a 100644 --- a/db_lab/RaportForm.Designer.cs +++ b/db_lab/RaportForm.Designer.cs @@ -28,12 +28,37 @@ /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); + this.dataGridView1 = new System.Windows.Forms.DataGridView(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView1 + // + this.dataGridView1.AllowUserToAddRows = false; + this.dataGridView1.AllowUserToDeleteRows = false; + this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView1.Dock = System.Windows.Forms.DockStyle.Fill; + this.dataGridView1.Location = new System.Drawing.Point(0, 0); + this.dataGridView1.Name = "dataGridView1"; + this.dataGridView1.ReadOnly = true; + this.dataGridView1.Size = new System.Drawing.Size(800, 450); + this.dataGridView1.TabIndex = 0; + // + // RaportForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.dataGridView1); + this.Name = "RaportForm"; this.Text = "RaportForm"; + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); + this.ResumeLayout(false); + } #endregion + + private System.Windows.Forms.DataGridView dataGridView1; } } \ No newline at end of file diff --git a/db_lab/RaportForm.cs b/db_lab/RaportForm.cs index bf138a2..91e7518 100644 --- a/db_lab/RaportForm.cs +++ b/db_lab/RaportForm.cs @@ -1,4 +1,5 @@ -using System; +using Npgsql; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -12,9 +13,45 @@ namespace db_lab { public partial class RaportForm : Form { - public RaportForm() + NpgsqlConnection connection; + + private void load_data() + { + try + { + connection.Open(); + string sql = @"SELECT + ead.id AS interaction_id, + e.name AS equipment_name, + r.room_name AS room_name, + d.name AS department_name, + b.address AS building_address, + ead.arrival_date, + ead.departure_date +FROM Equipment_Arrival_Departure ead +JOIN Equipment e ON ead.equipment_id = e.id +JOIN Rooms r ON e.room_id = r.id +JOIN Department d ON r.building_id = d.building_id +JOIN Building b ON d.building_id = b.id; +"; + NpgsqlDataAdapter adapter = new NpgsqlDataAdapter(sql, this.connection); + DataSet dataset = new DataSet(); + adapter.Fill(dataset, "data"); + dataGridView1.DataSource = dataset.Tables["data"]; + connection.Close(); + } + catch (Exception ex) + { + MessageBox.Show($"Error! Log: {ex.Message}"); + connection.Close(); + } + } + + public RaportForm(string connection) { + this.connection = new NpgsqlConnection(connection); InitializeComponent(); + load_data(); } } } diff --git a/db_lab/RaportForm.resx b/db_lab/RaportForm.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/db_lab/RaportForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/db_lab/bin/Debug/db_lab.exe b/db_lab/bin/Debug/db_lab.exe index 482eed0..6ed17b1 100644 Binary files a/db_lab/bin/Debug/db_lab.exe and b/db_lab/bin/Debug/db_lab.exe differ diff --git a/db_lab/bin/Debug/db_lab.pdb b/db_lab/bin/Debug/db_lab.pdb index f29d146..ffdd71d 100644 Binary files a/db_lab/bin/Debug/db_lab.pdb and b/db_lab/bin/Debug/db_lab.pdb differ diff --git a/db_lab/db_lab.csproj b/db_lab/db_lab.csproj index ef84a3b..eeb78b2 100644 --- a/db_lab/db_lab.csproj +++ b/db_lab/db_lab.csproj @@ -121,6 +121,9 @@ RaportForm.cs + + DataForm.cs + Form1.cs @@ -133,6 +136,9 @@ True Resources.resx + + RaportForm.cs + SettingsSingleFileGenerator diff --git a/db_lab/obj/Debug/db_lab.DataForm.resources b/db_lab/obj/Debug/db_lab.DataForm.resources new file mode 100644 index 0000000..6c05a97 Binary files /dev/null and b/db_lab/obj/Debug/db_lab.DataForm.resources differ diff --git a/db_lab/obj/Debug/db_lab.RaportForm.resources b/db_lab/obj/Debug/db_lab.RaportForm.resources new file mode 100644 index 0000000..6c05a97 Binary files /dev/null and b/db_lab/obj/Debug/db_lab.RaportForm.resources differ diff --git a/db_lab/obj/Debug/db_lab.csproj.FileListAbsolute.txt b/db_lab/obj/Debug/db_lab.csproj.FileListAbsolute.txt index fe09417..113a2e2 100644 --- a/db_lab/obj/Debug/db_lab.csproj.FileListAbsolute.txt +++ b/db_lab/obj/Debug/db_lab.csproj.FileListAbsolute.txt @@ -41,3 +41,5 @@ C:\Users\mit3t\source\repos\db_lab\db_lab\bin\Debug\System.Threading.Channels.xm C:\Users\mit3t\source\repos\db_lab\db_lab\bin\Debug\System.Threading.Tasks.Extensions.xml C:\Users\mit3t\source\repos\db_lab\db_lab\bin\Debug\System.ValueTuple.xml C:\Users\mit3t\source\repos\db_lab\db_lab\obj\Debug\db_lab.csproj.CopyComplete +C:\Users\mit3t\source\repos\db_lab\db_lab\obj\Debug\db_lab.DataForm.resources +C:\Users\mit3t\source\repos\db_lab\db_lab\obj\Debug\db_lab.RaportForm.resources diff --git a/db_lab/obj/Debug/db_lab.csproj.GenerateResource.cache b/db_lab/obj/Debug/db_lab.csproj.GenerateResource.cache index beb4253..733ee0f 100644 Binary files a/db_lab/obj/Debug/db_lab.csproj.GenerateResource.cache and b/db_lab/obj/Debug/db_lab.csproj.GenerateResource.cache differ diff --git a/db_lab/obj/Debug/db_lab.exe b/db_lab/obj/Debug/db_lab.exe index 482eed0..6ed17b1 100644 Binary files a/db_lab/obj/Debug/db_lab.exe and b/db_lab/obj/Debug/db_lab.exe differ diff --git a/db_lab/obj/Debug/db_lab.pdb b/db_lab/obj/Debug/db_lab.pdb index f29d146..ffdd71d 100644 Binary files a/db_lab/obj/Debug/db_lab.pdb and b/db_lab/obj/Debug/db_lab.pdb differ