diff --git a/db_lab/BuildingRepository.Designer.cs b/db_lab/BuildingRepository.Designer.cs
new file mode 100644
index 0000000..9c30805
--- /dev/null
+++ b/db_lab/BuildingRepository.Designer.cs
@@ -0,0 +1,39 @@
+namespace db_lab
+{
+ partial class BuildingRepository
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ 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 = "BuildingRepository";
+ }
+
+ #endregion
+ }
+}
\ No newline at end of file
diff --git a/db_lab/BuildingRepository.cs b/db_lab/BuildingRepository.cs
new file mode 100644
index 0000000..c530300
--- /dev/null
+++ b/db_lab/BuildingRepository.cs
@@ -0,0 +1,85 @@
+using Npgsql;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace db_lab
+{
+ public partial class BuildingRepository : Form
+ {
+ private NpgsqlConnection connection;
+
+ public BuildingRepository(string connectionString)
+ {
+ this.connection = new NpgsqlConnection(connectionString);
+ }
+
+ public DataTable ReadBuildings(int pageSize, int pageNumber)
+ {
+ string query = $"SELECT * FROM Building ORDER BY id LIMIT {pageSize} OFFSET {(pageNumber - 1) * pageSize}";
+ NpgsqlDataAdapter da = new NpgsqlDataAdapter(query, connection);
+ DataTable dt = new DataTable();
+ da.Fill(dt);
+ return dt;
+ }
+
+ public void DeleteBuilding(int id)
+ {
+ string query = $"DELETE FROM Building WHERE id = {id}";
+ using (var cmd = new NpgsqlCommand(query, connection))
+ {
+ connection.Open();
+ cmd.ExecuteNonQuery();
+ connection.Close();
+ }
+ }
+
+ public void AddBuilding(int floorCount, string address, int creatingUserId, string buildingType)
+ {
+ string query = "INSERT INTO Building (floor_count, address, creating_user_id, building_type) VALUES (@floor_count, @address, @creating_user_id, @building_type)";
+ using (var cmd = new NpgsqlCommand(query, connection))
+ {
+ cmd.Parameters.AddWithValue("floor_count", floorCount);
+ cmd.Parameters.AddWithValue("address", address);
+ cmd.Parameters.AddWithValue("creating_user_id", creatingUserId);
+ cmd.Parameters.AddWithValue("building_type", buildingType);
+
+ connection.Open();
+ cmd.ExecuteNonQuery();
+ connection.Close();
+ }
+ }
+
+ public void UpdateBuilding(int id, int floorCount, string address, int creatingUserId, string buildingType)
+ {
+ string query = "UPDATE Building SET floor_count = @floor_count, address = @address, creating_user_id = @creating_user_id, building_type = @building_type WHERE id = @id";
+ using (var cmd = new NpgsqlCommand(query, connection))
+ {
+ cmd.Parameters.AddWithValue("floor_count", floorCount);
+ cmd.Parameters.AddWithValue("address", address);
+ cmd.Parameters.AddWithValue("creating_user_id", creatingUserId);
+ cmd.Parameters.AddWithValue("building_type", buildingType);
+ cmd.Parameters.AddWithValue("id", id);
+
+ connection.Open();
+ cmd.ExecuteNonQuery();
+ connection.Close();
+ }
+ }
+
+ public DataRow GetBuildingById(int id)
+ {
+ string query = $"SELECT * FROM Building WHERE id = {id}";
+ NpgsqlDataAdapter da = new NpgsqlDataAdapter(query, connection);
+ DataTable dt = new DataTable();
+ da.Fill(dt);
+ return dt.Rows.Count > 0 ? dt.Rows[0] : null;
+ }
+ }
+}
diff --git a/db_lab/CRUDForm.Designer.cs b/db_lab/CRUDForm.Designer.cs
new file mode 100644
index 0000000..eac88e9
--- /dev/null
+++ b/db_lab/CRUDForm.Designer.cs
@@ -0,0 +1,221 @@
+namespace db_lab
+{
+ partial class CRUDForm
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel();
+ this.buildingBtn = new System.Windows.Forms.Button();
+ this.DepartmentBtn = new System.Windows.Forms.Button();
+ this.RoomsBtn = new System.Windows.Forms.Button();
+ this.EquipmentBtn = new System.Windows.Forms.Button();
+ this.dataGridView1 = new System.Windows.Forms.DataGridView();
+ this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
+ this.flowLayoutPanel2 = new System.Windows.Forms.FlowLayoutPanel();
+ this.button1 = new System.Windows.Forms.Button();
+ this.button2 = new System.Windows.Forms.Button();
+ this.button3 = new System.Windows.Forms.Button();
+ this.button4 = new System.Windows.Forms.Button();
+ this.button5 = new System.Windows.Forms.Button();
+ this.flowLayoutPanel1.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
+ this.tableLayoutPanel1.SuspendLayout();
+ this.flowLayoutPanel2.SuspendLayout();
+ this.SuspendLayout();
+ //
+ // flowLayoutPanel1
+ //
+ this.flowLayoutPanel1.Controls.Add(this.buildingBtn);
+ this.flowLayoutPanel1.Controls.Add(this.DepartmentBtn);
+ this.flowLayoutPanel1.Controls.Add(this.RoomsBtn);
+ this.flowLayoutPanel1.Controls.Add(this.EquipmentBtn);
+ this.flowLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Left;
+ this.flowLayoutPanel1.Location = new System.Drawing.Point(0, 0);
+ this.flowLayoutPanel1.Name = "flowLayoutPanel1";
+ this.flowLayoutPanel1.Size = new System.Drawing.Size(200, 450);
+ this.flowLayoutPanel1.TabIndex = 0;
+ //
+ // buildingBtn
+ //
+ this.buildingBtn.Location = new System.Drawing.Point(3, 3);
+ this.buildingBtn.Name = "buildingBtn";
+ this.buildingBtn.Size = new System.Drawing.Size(75, 23);
+ this.buildingBtn.TabIndex = 0;
+ this.buildingBtn.Text = "Building";
+ this.buildingBtn.UseVisualStyleBackColor = true;
+ this.buildingBtn.Click += new System.EventHandler(this.buildingBtn_Click);
+ //
+ // DepartmentBtn
+ //
+ this.DepartmentBtn.Location = new System.Drawing.Point(84, 3);
+ this.DepartmentBtn.Name = "DepartmentBtn";
+ this.DepartmentBtn.Size = new System.Drawing.Size(75, 23);
+ this.DepartmentBtn.TabIndex = 1;
+ this.DepartmentBtn.Text = "Department";
+ this.DepartmentBtn.UseVisualStyleBackColor = true;
+ this.DepartmentBtn.Click += new System.EventHandler(this.DepartmentBtn_Click);
+ //
+ // RoomsBtn
+ //
+ this.RoomsBtn.Location = new System.Drawing.Point(3, 32);
+ this.RoomsBtn.Name = "RoomsBtn";
+ this.RoomsBtn.Size = new System.Drawing.Size(75, 23);
+ this.RoomsBtn.TabIndex = 2;
+ this.RoomsBtn.Text = "Rooms";
+ this.RoomsBtn.UseVisualStyleBackColor = true;
+ this.RoomsBtn.Click += new System.EventHandler(this.RoomsBtn_Click);
+ //
+ // EquipmentBtn
+ //
+ this.EquipmentBtn.Location = new System.Drawing.Point(84, 32);
+ this.EquipmentBtn.Name = "EquipmentBtn";
+ this.EquipmentBtn.Size = new System.Drawing.Size(75, 23);
+ this.EquipmentBtn.TabIndex = 3;
+ this.EquipmentBtn.Text = "Equipment";
+ this.EquipmentBtn.UseVisualStyleBackColor = true;
+ this.EquipmentBtn.Click += new System.EventHandler(this.EquipmentBtn_Click);
+ //
+ // dataGridView1
+ //
+ this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.dataGridView1.Location = new System.Drawing.Point(3, 3);
+ this.dataGridView1.Name = "dataGridView1";
+ this.dataGridView1.Size = new System.Drawing.Size(511, 411);
+ this.dataGridView1.TabIndex = 4;
+ //
+ // tableLayoutPanel1
+ //
+ this.tableLayoutPanel1.ColumnCount = 2;
+ this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 86.16666F));
+ this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 13.83333F));
+ this.tableLayoutPanel1.Controls.Add(this.dataGridView1, 0, 0);
+ this.tableLayoutPanel1.Controls.Add(this.flowLayoutPanel2, 1, 0);
+ this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.tableLayoutPanel1.Location = new System.Drawing.Point(200, 0);
+ this.tableLayoutPanel1.Name = "tableLayoutPanel1";
+ this.tableLayoutPanel1.RowCount = 2;
+ this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 92.88889F));
+ this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 7.111111F));
+ this.tableLayoutPanel1.Size = new System.Drawing.Size(600, 450);
+ this.tableLayoutPanel1.TabIndex = 1;
+ //
+ // flowLayoutPanel2
+ //
+ this.flowLayoutPanel2.Controls.Add(this.button1);
+ this.flowLayoutPanel2.Controls.Add(this.button2);
+ this.flowLayoutPanel2.Controls.Add(this.button3);
+ this.flowLayoutPanel2.Controls.Add(this.button4);
+ this.flowLayoutPanel2.Controls.Add(this.button5);
+ this.flowLayoutPanel2.Location = new System.Drawing.Point(520, 3);
+ this.flowLayoutPanel2.Name = "flowLayoutPanel2";
+ this.flowLayoutPanel2.Size = new System.Drawing.Size(77, 411);
+ this.flowLayoutPanel2.TabIndex = 6;
+ //
+ // button1
+ //
+ this.button1.Location = new System.Drawing.Point(3, 3);
+ this.button1.Name = "button1";
+ this.button1.Size = new System.Drawing.Size(75, 23);
+ this.button1.TabIndex = 5;
+ this.button1.Text = "Next";
+ this.button1.UseVisualStyleBackColor = true;
+ this.button1.Click += new System.EventHandler(this.btnNext_Click);
+ //
+ // button2
+ //
+ this.button2.Location = new System.Drawing.Point(3, 32);
+ this.button2.Name = "button2";
+ this.button2.Size = new System.Drawing.Size(75, 23);
+ this.button2.TabIndex = 6;
+ this.button2.Text = "Prev";
+ this.button2.UseVisualStyleBackColor = true;
+ this.button2.Click += new System.EventHandler(this.btnPrev_Click);
+ //
+ // button3
+ //
+ this.button3.Location = new System.Drawing.Point(3, 61);
+ this.button3.Name = "button3";
+ this.button3.Size = new System.Drawing.Size(75, 23);
+ this.button3.TabIndex = 7;
+ this.button3.Text = "Delete";
+ this.button3.UseVisualStyleBackColor = true;
+ this.button3.Click += new System.EventHandler(this.btnDelete_Click);
+ //
+ // button4
+ //
+ this.button4.Location = new System.Drawing.Point(3, 90);
+ this.button4.Name = "button4";
+ this.button4.Size = new System.Drawing.Size(75, 23);
+ this.button4.TabIndex = 8;
+ this.button4.Text = "Add";
+ this.button4.UseVisualStyleBackColor = true;
+ this.button4.Click += new System.EventHandler(this.btnAdd_Click);
+ //
+ // button5
+ //
+ this.button5.Location = new System.Drawing.Point(3, 119);
+ this.button5.Name = "button5";
+ this.button5.Size = new System.Drawing.Size(75, 23);
+ this.button5.TabIndex = 9;
+ this.button5.Text = "Edit";
+ this.button5.UseVisualStyleBackColor = true;
+ this.button5.Click += new System.EventHandler(this.btnEdit_Click);
+ //
+ // CRUDForm
+ //
+ 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.tableLayoutPanel1);
+ this.Controls.Add(this.flowLayoutPanel1);
+ this.Name = "CRUDForm";
+ this.Text = "CRUDForm";
+ this.flowLayoutPanel1.ResumeLayout(false);
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
+ this.tableLayoutPanel1.ResumeLayout(false);
+ this.flowLayoutPanel2.ResumeLayout(false);
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+
+ private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1;
+ private System.Windows.Forms.Button buildingBtn;
+ private System.Windows.Forms.Button DepartmentBtn;
+ private System.Windows.Forms.Button RoomsBtn;
+ private System.Windows.Forms.Button EquipmentBtn;
+ private System.Windows.Forms.DataGridView dataGridView1;
+ private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
+ private System.Windows.Forms.Button button1;
+ private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel2;
+ private System.Windows.Forms.Button button2;
+ private System.Windows.Forms.Button button3;
+ private System.Windows.Forms.Button button4;
+ private System.Windows.Forms.Button button5;
+ }
+}
\ No newline at end of file
diff --git a/db_lab/CRUDForm.cs b/db_lab/CRUDForm.cs
new file mode 100644
index 0000000..3e3aab3
--- /dev/null
+++ b/db_lab/CRUDForm.cs
@@ -0,0 +1,107 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace db_lab
+{
+ public partial class CRUDForm : Form
+ {
+ private BuildingRepository buildingRepository;
+ private int pageSize = 10;
+ private int currentPage = 1;
+ private string connectionString;
+
+ public CRUDForm(string connectionString)
+ {
+ InitializeComponent();
+ this.connectionString = connectionString;
+ buildingRepository = new BuildingRepository(connectionString); // Инициализация BuildingRepository
+ LoadData();
+ }
+
+ private void LoadData()
+ {
+ DataTable dt = buildingRepository.ReadBuildings(pageSize, currentPage);
+ dataGridView1.DataSource = dt;
+ }
+
+ private void btnNext_Click(object sender, EventArgs e)
+ {
+ currentPage++;
+ LoadData();
+ }
+
+ private void btnPrev_Click(object sender, EventArgs e)
+ {
+ if (currentPage > 1)
+ {
+ currentPage--;
+ LoadData();
+ }
+ }
+
+ private void btnDelete_Click(object sender, EventArgs e)
+ {
+ foreach (DataGridViewRow row in dataGridView1.SelectedRows)
+ {
+ int id = Convert.ToInt32(row.Cells["id"].Value);
+ buildingRepository.DeleteBuilding(id);
+ }
+ LoadData();
+ }
+
+ private void btnAdd_Click(object sender, EventArgs e)
+ {
+ EditFormBuilding editForm = new EditFormBuilding(buildingRepository);
+ editForm.ShowDialog();
+ LoadData();
+ }
+
+ private void btnEdit_Click(object sender, EventArgs e)
+ {
+ if (dataGridView1.SelectedRows.Count == 1)
+ {
+ int id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["id"].Value);
+ EditFormBuilding editForm = new EditFormBuilding(buildingRepository, id);
+ editForm.ShowDialog();
+ LoadData();
+ }
+ else
+ {
+ MessageBox.Show("Please select a single row to edit.");
+ }
+ }
+
+ // another
+
+ private void buildingBtn_Click(object sender, EventArgs e)
+ {
+ var crudForm = new CRUDForm(this.connectionString);
+ crudForm.Show();
+ }
+
+ private void DepartmentBtn_Click(object sender, EventArgs e)
+ {
+ var form = new DepartmentForm(this.connectionString);
+ form.Show();
+ }
+
+ private void RoomsBtn_Click(object sender, EventArgs e)
+ {
+ var form = new RoomForm(this.connectionString);
+ form.Show();
+ }
+
+ private void EquipmentBtn_Click(object sender, EventArgs e)
+ {
+ var form = new EquipmentForm(this.connectionString);
+ form.Show();
+ }
+ }
+}
diff --git a/db_lab/CRUDForm.resx b/db_lab/CRUDForm.resx
new file mode 100644
index 0000000..1af7de1
--- /dev/null
+++ b/db_lab/CRUDForm.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/DepartmentForm.Designer.cs b/db_lab/DepartmentForm.Designer.cs
new file mode 100644
index 0000000..237e9e9
--- /dev/null
+++ b/db_lab/DepartmentForm.Designer.cs
@@ -0,0 +1,137 @@
+namespace db_lab
+{
+ partial class DepartmentForm
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel();
+ this.button1 = new System.Windows.Forms.Button();
+ this.button2 = new System.Windows.Forms.Button();
+ this.button3 = new System.Windows.Forms.Button();
+ this.button4 = new System.Windows.Forms.Button();
+ this.button5 = new System.Windows.Forms.Button();
+ this.dataGridView1 = new System.Windows.Forms.DataGridView();
+ this.flowLayoutPanel1.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
+ this.SuspendLayout();
+ //
+ // flowLayoutPanel1
+ //
+ this.flowLayoutPanel1.Controls.Add(this.button1);
+ this.flowLayoutPanel1.Controls.Add(this.button2);
+ this.flowLayoutPanel1.Controls.Add(this.button3);
+ this.flowLayoutPanel1.Controls.Add(this.button4);
+ this.flowLayoutPanel1.Controls.Add(this.button5);
+ this.flowLayoutPanel1.Location = new System.Drawing.Point(588, 12);
+ this.flowLayoutPanel1.Name = "flowLayoutPanel1";
+ this.flowLayoutPanel1.Size = new System.Drawing.Size(200, 426);
+ this.flowLayoutPanel1.TabIndex = 0;
+ //
+ // button1
+ //
+ this.button1.Location = new System.Drawing.Point(3, 3);
+ this.button1.Name = "button1";
+ this.button1.Size = new System.Drawing.Size(75, 23);
+ this.button1.TabIndex = 0;
+ this.button1.Text = "Next";
+ this.button1.UseVisualStyleBackColor = true;
+ this.button1.Click += new System.EventHandler(this.btnNext_Click);
+ //
+ // button2
+ //
+ this.button2.Location = new System.Drawing.Point(84, 3);
+ this.button2.Name = "button2";
+ this.button2.Size = new System.Drawing.Size(75, 23);
+ this.button2.TabIndex = 1;
+ this.button2.Text = "Prev";
+ this.button2.UseVisualStyleBackColor = true;
+ this.button2.Click += new System.EventHandler(this.btnPrev_Click);
+ //
+ // button3
+ //
+ this.button3.Location = new System.Drawing.Point(3, 32);
+ this.button3.Name = "button3";
+ this.button3.Size = new System.Drawing.Size(75, 23);
+ this.button3.TabIndex = 2;
+ this.button3.Text = "Delete";
+ this.button3.UseVisualStyleBackColor = true;
+ this.button3.Click += new System.EventHandler(this.btnDelete_Click);
+ //
+ // button4
+ //
+ this.button4.Location = new System.Drawing.Point(84, 32);
+ this.button4.Name = "button4";
+ this.button4.Size = new System.Drawing.Size(75, 23);
+ this.button4.TabIndex = 3;
+ this.button4.Text = "Add";
+ this.button4.UseVisualStyleBackColor = true;
+ this.button4.Click += new System.EventHandler(this.btnAdd_Click);
+ //
+ // button5
+ //
+ this.button5.Location = new System.Drawing.Point(3, 61);
+ this.button5.Name = "button5";
+ this.button5.Size = new System.Drawing.Size(75, 23);
+ this.button5.TabIndex = 4;
+ this.button5.Text = "Edit";
+ this.button5.UseVisualStyleBackColor = true;
+ this.button5.Click += new System.EventHandler(this.btnEdit_Click);
+ //
+ // dataGridView1
+ //
+ this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.dataGridView1.Location = new System.Drawing.Point(12, 12);
+ this.dataGridView1.Name = "dataGridView1";
+ this.dataGridView1.Size = new System.Drawing.Size(570, 426);
+ this.dataGridView1.TabIndex = 1;
+ //
+ // DepartmentForm
+ //
+ 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.Controls.Add(this.flowLayoutPanel1);
+ this.Name = "DepartmentForm";
+ this.Text = "DepartmentForm";
+ this.flowLayoutPanel1.ResumeLayout(false);
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+
+ private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1;
+ private System.Windows.Forms.Button button1;
+ private System.Windows.Forms.Button button2;
+ private System.Windows.Forms.Button button3;
+ private System.Windows.Forms.Button button4;
+ private System.Windows.Forms.Button button5;
+ private System.Windows.Forms.DataGridView dataGridView1;
+ }
+}
\ No newline at end of file
diff --git a/db_lab/DepartmentForm.cs b/db_lab/DepartmentForm.cs
new file mode 100644
index 0000000..7f1a6f3
--- /dev/null
+++ b/db_lab/DepartmentForm.cs
@@ -0,0 +1,79 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace db_lab
+{
+ public partial class DepartmentForm : Form
+ {
+ private DepartmentRepository departmentRepository;
+ private int pageSize = 10;
+ private int currentPage = 1;
+
+ public DepartmentForm(string connectionString)
+ {
+ InitializeComponent();
+ departmentRepository = new DepartmentRepository(connectionString);
+ LoadData();
+ }
+
+ private void LoadData()
+ {
+ DataTable dt = departmentRepository.ReadDepartments(pageSize, currentPage);
+ dataGridView1.DataSource = dt;
+ }
+
+ private void btnNext_Click(object sender, EventArgs e)
+ {
+ currentPage++;
+ LoadData();
+ }
+
+ private void btnPrev_Click(object sender, EventArgs e)
+ {
+ if (currentPage > 1)
+ {
+ currentPage--;
+ LoadData();
+ }
+ }
+
+ private void btnDelete_Click(object sender, EventArgs e)
+ {
+ foreach (DataGridViewRow row in dataGridView1.SelectedRows)
+ {
+ int code = Convert.ToInt32(row.Cells["code"].Value);
+ departmentRepository.DeleteDepartment(code);
+ }
+ LoadData();
+ }
+
+ private void btnAdd_Click(object sender, EventArgs e)
+ {
+ EditDepartmentForm editForm = new EditDepartmentForm(departmentRepository);
+ editForm.ShowDialog();
+ LoadData();
+ }
+
+ private void btnEdit_Click(object sender, EventArgs e)
+ {
+ if (dataGridView1.SelectedRows.Count == 1)
+ {
+ int code = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["code"].Value);
+ EditDepartmentForm editForm = new EditDepartmentForm(departmentRepository, code);
+ editForm.ShowDialog();
+ LoadData();
+ }
+ else
+ {
+ MessageBox.Show("Please select a single row to edit.");
+ }
+ }
+ }
+}
diff --git a/db_lab/DepartmentForm.resx b/db_lab/DepartmentForm.resx
new file mode 100644
index 0000000..1af7de1
--- /dev/null
+++ b/db_lab/DepartmentForm.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/DepartmentRepository.cs b/db_lab/DepartmentRepository.cs
new file mode 100644
index 0000000..d2c26ca
--- /dev/null
+++ b/db_lab/DepartmentRepository.cs
@@ -0,0 +1,84 @@
+using Npgsql;
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.Linq;
+using System.Text;
+using Npgsql;
+using System.Threading.Tasks;
+
+namespace db_lab
+{
+ public class DepartmentRepository
+ {
+ private NpgsqlConnection connection;
+
+ public DepartmentRepository(string connectionString)
+ {
+ this.connection = new NpgsqlConnection(connectionString);
+ }
+
+ public DataTable ReadDepartments(int pageSize, int pageNumber)
+ {
+ string query = $"SELECT * FROM Department ORDER BY code LIMIT {pageSize} OFFSET {(pageNumber - 1) * pageSize}";
+ NpgsqlDataAdapter da = new NpgsqlDataAdapter(query, connection);
+ DataTable dt = new DataTable();
+ da.Fill(dt);
+ return dt;
+ }
+
+ public void DeleteDepartment(int code)
+ {
+ string query = $"DELETE FROM Department WHERE code = {code}";
+ using (var cmd = new NpgsqlCommand(query, connection))
+ {
+ connection.Open();
+ cmd.ExecuteNonQuery();
+ connection.Close();
+ }
+ }
+
+ public void AddDepartment(int code, string name, int floor, int creatingUserId, int buildingId)
+ {
+ string query = "INSERT INTO Department (code, name, floor, creating_user_id, building_id) VALUES (@code, @name, @floor, @creating_user_id, @building_id)";
+ using (var cmd = new NpgsqlCommand(query, connection))
+ {
+ cmd.Parameters.AddWithValue("code", code);
+ cmd.Parameters.AddWithValue("name", name);
+ cmd.Parameters.AddWithValue("floor", floor);
+ cmd.Parameters.AddWithValue("creating_user_id", creatingUserId);
+ cmd.Parameters.AddWithValue("building_id", buildingId);
+
+ connection.Open();
+ cmd.ExecuteNonQuery();
+ connection.Close();
+ }
+ }
+
+ public void UpdateDepartment(int code, string name, int floor, int creatingUserId, int buildingId)
+ {
+ string query = "UPDATE Department SET name = @name, floor = @floor, creating_user_id = @creating_user_id, building_id = @building_id WHERE code = @code";
+ using (var cmd = new NpgsqlCommand(query, connection))
+ {
+ cmd.Parameters.AddWithValue("code", code);
+ cmd.Parameters.AddWithValue("name", name);
+ cmd.Parameters.AddWithValue("floor", floor);
+ cmd.Parameters.AddWithValue("creating_user_id", creatingUserId);
+ cmd.Parameters.AddWithValue("building_id", buildingId);
+
+ connection.Open();
+ cmd.ExecuteNonQuery();
+ connection.Close();
+ }
+ }
+
+ public DataRow GetDepartmentByCode(int code)
+ {
+ string query = $"SELECT * FROM Department WHERE code = {code}";
+ NpgsqlDataAdapter da = new NpgsqlDataAdapter(query, connection);
+ DataTable dt = new DataTable();
+ da.Fill(dt);
+ return dt.Rows.Count > 0 ? dt.Rows[0] : null;
+ }
+ }
+}
diff --git a/db_lab/EditDepartmentForm.Designer.cs b/db_lab/EditDepartmentForm.Designer.cs
new file mode 100644
index 0000000..6f5f5e6
--- /dev/null
+++ b/db_lab/EditDepartmentForm.Designer.cs
@@ -0,0 +1,171 @@
+namespace db_lab
+{
+ partial class EditDepartmentForm
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.textBoxCode = new System.Windows.Forms.TextBox();
+ this.label1 = new System.Windows.Forms.Label();
+ this.textBoxName = new System.Windows.Forms.TextBox();
+ this.label2 = new System.Windows.Forms.Label();
+ this.textBoxFloor = new System.Windows.Forms.TextBox();
+ this.label3 = new System.Windows.Forms.Label();
+ this.textBoxCreatingUserId = new System.Windows.Forms.TextBox();
+ this.label4 = new System.Windows.Forms.Label();
+ this.textBoxBuildingId = new System.Windows.Forms.TextBox();
+ this.label5 = new System.Windows.Forms.Label();
+ this.button1 = new System.Windows.Forms.Button();
+ this.SuspendLayout();
+ //
+ // textBoxCode
+ //
+ this.textBoxCode.Location = new System.Drawing.Point(13, 13);
+ this.textBoxCode.Name = "textBoxCode";
+ this.textBoxCode.Size = new System.Drawing.Size(100, 20);
+ this.textBoxCode.TabIndex = 0;
+ //
+ // label1
+ //
+ this.label1.AutoSize = true;
+ this.label1.Location = new System.Drawing.Point(129, 19);
+ this.label1.Name = "label1";
+ this.label1.Size = new System.Drawing.Size(67, 13);
+ this.label1.TabIndex = 1;
+ this.label1.Text = "textBoxCode";
+ //
+ // textBoxName
+ //
+ this.textBoxName.Location = new System.Drawing.Point(13, 40);
+ this.textBoxName.Name = "textBoxName";
+ this.textBoxName.Size = new System.Drawing.Size(100, 20);
+ this.textBoxName.TabIndex = 2;
+ //
+ // label2
+ //
+ this.label2.AutoSize = true;
+ this.label2.Location = new System.Drawing.Point(132, 46);
+ this.label2.Name = "label2";
+ this.label2.Size = new System.Drawing.Size(70, 13);
+ this.label2.TabIndex = 3;
+ this.label2.Text = "textBoxName";
+ //
+ // textBoxFloor
+ //
+ this.textBoxFloor.Location = new System.Drawing.Point(13, 67);
+ this.textBoxFloor.Name = "textBoxFloor";
+ this.textBoxFloor.Size = new System.Drawing.Size(100, 20);
+ this.textBoxFloor.TabIndex = 4;
+ //
+ // label3
+ //
+ this.label3.AutoSize = true;
+ this.label3.Location = new System.Drawing.Point(132, 73);
+ this.label3.Name = "label3";
+ this.label3.Size = new System.Drawing.Size(65, 13);
+ this.label3.TabIndex = 5;
+ this.label3.Text = "textBoxFloor";
+ //
+ // textBoxCreatingUserId
+ //
+ this.textBoxCreatingUserId.Location = new System.Drawing.Point(13, 94);
+ this.textBoxCreatingUserId.Name = "textBoxCreatingUserId";
+ this.textBoxCreatingUserId.Size = new System.Drawing.Size(100, 20);
+ this.textBoxCreatingUserId.TabIndex = 6;
+ //
+ // label4
+ //
+ this.label4.AutoSize = true;
+ this.label4.Location = new System.Drawing.Point(135, 100);
+ this.label4.Name = "label4";
+ this.label4.Size = new System.Drawing.Size(112, 13);
+ this.label4.TabIndex = 7;
+ this.label4.Text = "textBoxCreatingUserId";
+ //
+ // textBoxBuildingId
+ //
+ this.textBoxBuildingId.Location = new System.Drawing.Point(13, 121);
+ this.textBoxBuildingId.Name = "textBoxBuildingId";
+ this.textBoxBuildingId.Size = new System.Drawing.Size(100, 20);
+ this.textBoxBuildingId.TabIndex = 8;
+ //
+ // label5
+ //
+ this.label5.AutoSize = true;
+ this.label5.Location = new System.Drawing.Point(132, 127);
+ this.label5.Name = "label5";
+ this.label5.Size = new System.Drawing.Size(88, 13);
+ this.label5.TabIndex = 9;
+ this.label5.Text = "textBoxBuildingId";
+ //
+ // button1
+ //
+ this.button1.Location = new System.Drawing.Point(13, 148);
+ this.button1.Name = "button1";
+ this.button1.Size = new System.Drawing.Size(234, 62);
+ this.button1.TabIndex = 10;
+ this.button1.Text = "Save";
+ this.button1.UseVisualStyleBackColor = true;
+ this.button1.Click += new System.EventHandler(this.btnSave_Click);
+ //
+ // EditDepartmentForm
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(256, 218);
+ this.Controls.Add(this.button1);
+ this.Controls.Add(this.label5);
+ this.Controls.Add(this.textBoxBuildingId);
+ this.Controls.Add(this.label4);
+ this.Controls.Add(this.textBoxCreatingUserId);
+ this.Controls.Add(this.label3);
+ this.Controls.Add(this.textBoxFloor);
+ this.Controls.Add(this.label2);
+ this.Controls.Add(this.textBoxName);
+ this.Controls.Add(this.label1);
+ this.Controls.Add(this.textBoxCode);
+ this.Name = "EditDepartmentForm";
+ this.Text = "EditDepartmentForm";
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private System.Windows.Forms.TextBox textBoxCode;
+ private System.Windows.Forms.Label label1;
+ private System.Windows.Forms.TextBox textBoxName;
+ private System.Windows.Forms.Label label2;
+ private System.Windows.Forms.TextBox textBoxFloor;
+ private System.Windows.Forms.Label label3;
+ private System.Windows.Forms.TextBox textBoxCreatingUserId;
+ private System.Windows.Forms.Label label4;
+ private System.Windows.Forms.TextBox textBoxBuildingId;
+ private System.Windows.Forms.Label label5;
+ private System.Windows.Forms.Button button1;
+ }
+}
\ No newline at end of file
diff --git a/db_lab/EditDepartmentForm.cs b/db_lab/EditDepartmentForm.cs
new file mode 100644
index 0000000..bf66eab
--- /dev/null
+++ b/db_lab/EditDepartmentForm.cs
@@ -0,0 +1,61 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace db_lab
+{
+ public partial class EditDepartmentForm : Form
+ {
+ private DepartmentRepository departmentRepository;
+ private int? departmentCode;
+
+ public EditDepartmentForm(DepartmentRepository departmentRepository, int? departmentCode = null)
+ {
+ InitializeComponent();
+ this.departmentRepository = departmentRepository;
+ this.departmentCode = departmentCode;
+ if (departmentCode.HasValue)
+ {
+ LoadRecordData(departmentCode.Value);
+ }
+ }
+
+ private void LoadRecordData(int code)
+ {
+ DataRow row = departmentRepository.GetDepartmentByCode(code);
+ if (row != null)
+ {
+ textBoxCode.Text = row["code"].ToString();
+ textBoxName.Text = row["name"].ToString();
+ textBoxFloor.Text = row["floor"].ToString();
+ textBoxCreatingUserId.Text = row["creating_user_id"].ToString();
+ textBoxBuildingId.Text = row["building_id"].ToString();
+ }
+ }
+
+ private void btnSave_Click(object sender, EventArgs e)
+ {
+ int code = int.Parse(textBoxCode.Text);
+ string name = textBoxName.Text;
+ int floor = int.Parse(textBoxFloor.Text);
+ int creatingUserId = int.Parse(textBoxCreatingUserId.Text);
+ int buildingId = int.Parse(textBoxBuildingId.Text);
+
+ if (departmentCode.HasValue)
+ {
+ departmentRepository.UpdateDepartment(code, name, floor, creatingUserId, buildingId);
+ }
+ else
+ {
+ departmentRepository.AddDepartment(code, name, floor, creatingUserId, buildingId);
+ }
+ this.Close();
+ }
+ }
+}
diff --git a/db_lab/EditDepartmentForm.resx b/db_lab/EditDepartmentForm.resx
new file mode 100644
index 0000000..1af7de1
--- /dev/null
+++ b/db_lab/EditDepartmentForm.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/EditEquipmentForm.Designer.cs b/db_lab/EditEquipmentForm.Designer.cs
new file mode 100644
index 0000000..1b42c85
--- /dev/null
+++ b/db_lab/EditEquipmentForm.Designer.cs
@@ -0,0 +1,149 @@
+namespace db_lab
+{
+ partial class EditEquipmentForm
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.textBoxIpAddress = new System.Windows.Forms.TextBox();
+ this.label1 = new System.Windows.Forms.Label();
+ this.textBoxSshSettings = new System.Windows.Forms.TextBox();
+ this.label2 = new System.Windows.Forms.Label();
+ this.textBoxName = new System.Windows.Forms.TextBox();
+ this.label3 = new System.Windows.Forms.Label();
+ this.textBoxRoomId = new System.Windows.Forms.TextBox();
+ this.label4 = new System.Windows.Forms.Label();
+ this.button1 = new System.Windows.Forms.Button();
+ this.SuspendLayout();
+ //
+ // textBoxIpAddress
+ //
+ this.textBoxIpAddress.Location = new System.Drawing.Point(12, 12);
+ this.textBoxIpAddress.Name = "textBoxIpAddress";
+ this.textBoxIpAddress.Size = new System.Drawing.Size(100, 20);
+ this.textBoxIpAddress.TabIndex = 0;
+ //
+ // label1
+ //
+ this.label1.AutoSize = true;
+ this.label1.Location = new System.Drawing.Point(128, 18);
+ this.label1.Name = "label1";
+ this.label1.Size = new System.Drawing.Size(89, 13);
+ this.label1.TabIndex = 1;
+ this.label1.Text = "textBoxIpAddress";
+ //
+ // textBoxSshSettings
+ //
+ this.textBoxSshSettings.Location = new System.Drawing.Point(13, 39);
+ this.textBoxSshSettings.Name = "textBoxSshSettings";
+ this.textBoxSshSettings.Size = new System.Drawing.Size(100, 20);
+ this.textBoxSshSettings.TabIndex = 2;
+ //
+ // label2
+ //
+ this.label2.AutoSize = true;
+ this.label2.Location = new System.Drawing.Point(131, 45);
+ this.label2.Name = "label2";
+ this.label2.Size = new System.Drawing.Size(98, 13);
+ this.label2.TabIndex = 3;
+ this.label2.Text = "textBoxSshSettings";
+ //
+ // textBoxName
+ //
+ this.textBoxName.Location = new System.Drawing.Point(13, 66);
+ this.textBoxName.Name = "textBoxName";
+ this.textBoxName.Size = new System.Drawing.Size(100, 20);
+ this.textBoxName.TabIndex = 4;
+ //
+ // label3
+ //
+ this.label3.AutoSize = true;
+ this.label3.Location = new System.Drawing.Point(134, 72);
+ this.label3.Name = "label3";
+ this.label3.Size = new System.Drawing.Size(70, 13);
+ this.label3.TabIndex = 5;
+ this.label3.Text = "textBoxName";
+ //
+ // textBoxRoomId
+ //
+ this.textBoxRoomId.Location = new System.Drawing.Point(12, 93);
+ this.textBoxRoomId.Name = "textBoxRoomId";
+ this.textBoxRoomId.Size = new System.Drawing.Size(100, 20);
+ this.textBoxRoomId.TabIndex = 6;
+ //
+ // label4
+ //
+ this.label4.AutoSize = true;
+ this.label4.Location = new System.Drawing.Point(134, 99);
+ this.label4.Name = "label4";
+ this.label4.Size = new System.Drawing.Size(79, 13);
+ this.label4.TabIndex = 7;
+ this.label4.Text = "textBoxRoomId";
+ //
+ // button1
+ //
+ this.button1.Location = new System.Drawing.Point(13, 120);
+ this.button1.Name = "button1";
+ this.button1.Size = new System.Drawing.Size(216, 58);
+ this.button1.TabIndex = 8;
+ this.button1.Text = "Save";
+ this.button1.UseVisualStyleBackColor = true;
+ this.button1.Click += new System.EventHandler(this.btnSave_Click);
+ //
+ // EditEquipmentForm
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(229, 183);
+ this.Controls.Add(this.button1);
+ this.Controls.Add(this.label4);
+ this.Controls.Add(this.textBoxRoomId);
+ this.Controls.Add(this.label3);
+ this.Controls.Add(this.textBoxName);
+ this.Controls.Add(this.label2);
+ this.Controls.Add(this.textBoxSshSettings);
+ this.Controls.Add(this.label1);
+ this.Controls.Add(this.textBoxIpAddress);
+ this.Name = "EditEquipmentForm";
+ this.Text = "EditEquipmentForm";
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private System.Windows.Forms.TextBox textBoxIpAddress;
+ private System.Windows.Forms.Label label1;
+ private System.Windows.Forms.TextBox textBoxSshSettings;
+ private System.Windows.Forms.Label label2;
+ private System.Windows.Forms.TextBox textBoxName;
+ private System.Windows.Forms.Label label3;
+ private System.Windows.Forms.TextBox textBoxRoomId;
+ private System.Windows.Forms.Label label4;
+ private System.Windows.Forms.Button button1;
+ }
+}
\ No newline at end of file
diff --git a/db_lab/EditEquipmentForm.cs b/db_lab/EditEquipmentForm.cs
new file mode 100644
index 0000000..1a4dc35
--- /dev/null
+++ b/db_lab/EditEquipmentForm.cs
@@ -0,0 +1,59 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace db_lab
+{
+ public partial class EditEquipmentForm : Form
+ {
+ private EquipmentRepository equipmentRepository;
+ private int? equipmentId;
+
+ public EditEquipmentForm(EquipmentRepository equipmentRepository, int? equipmentId = null)
+ {
+ InitializeComponent();
+ this.equipmentRepository = equipmentRepository;
+ this.equipmentId = equipmentId;
+ if (equipmentId.HasValue)
+ {
+ LoadRecordData(equipmentId.Value);
+ }
+ }
+
+ private void LoadRecordData(int id)
+ {
+ DataRow row = equipmentRepository.GetEquipmentById(id);
+ if (row != null)
+ {
+ textBoxIpAddress.Text = row["ip_address"].ToString();
+ textBoxSshSettings.Text = row["ssh_settings"].ToString();
+ textBoxName.Text = row["name"].ToString();
+ textBoxRoomId.Text = row["room_id"].ToString();
+ }
+ }
+
+ private void btnSave_Click(object sender, EventArgs e)
+ {
+ string ipAddress = textBoxIpAddress.Text;
+ string sshSettings = textBoxSshSettings.Text;
+ string name = textBoxName.Text;
+ int roomId = int.Parse(textBoxRoomId.Text);
+
+ if (equipmentId.HasValue)
+ {
+ equipmentRepository.UpdateEquipment(equipmentId.Value, ipAddress, sshSettings, name, roomId);
+ }
+ else
+ {
+ equipmentRepository.AddEquipment(ipAddress, sshSettings, name, roomId);
+ }
+ this.Close();
+ }
+ }
+}
diff --git a/db_lab/EditEquipmentForm.resx b/db_lab/EditEquipmentForm.resx
new file mode 100644
index 0000000..1af7de1
--- /dev/null
+++ b/db_lab/EditEquipmentForm.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/EditFormBuilding.Designer.cs b/db_lab/EditFormBuilding.Designer.cs
new file mode 100644
index 0000000..39881dc
--- /dev/null
+++ b/db_lab/EditFormBuilding.Designer.cs
@@ -0,0 +1,149 @@
+namespace db_lab
+{
+ partial class EditFormBuilding
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.textBoxFloorCount = new System.Windows.Forms.TextBox();
+ this.label1 = new System.Windows.Forms.Label();
+ this.textBoxAddress = new System.Windows.Forms.TextBox();
+ this.label2 = new System.Windows.Forms.Label();
+ this.textBoxCreatingUserId = new System.Windows.Forms.TextBox();
+ this.label3 = new System.Windows.Forms.Label();
+ this.textBoxBuildingType = new System.Windows.Forms.TextBox();
+ this.label4 = new System.Windows.Forms.Label();
+ this.button1 = new System.Windows.Forms.Button();
+ this.SuspendLayout();
+ //
+ // textBoxFloorCount
+ //
+ this.textBoxFloorCount.Location = new System.Drawing.Point(12, 12);
+ this.textBoxFloorCount.Name = "textBoxFloorCount";
+ this.textBoxFloorCount.Size = new System.Drawing.Size(100, 20);
+ this.textBoxFloorCount.TabIndex = 0;
+ //
+ // label1
+ //
+ this.label1.AutoSize = true;
+ this.label1.Location = new System.Drawing.Point(133, 18);
+ this.label1.Name = "label1";
+ this.label1.Size = new System.Drawing.Size(93, 13);
+ this.label1.TabIndex = 1;
+ this.label1.Text = "textBoxFloorCount";
+ //
+ // textBoxAddress
+ //
+ this.textBoxAddress.Location = new System.Drawing.Point(13, 39);
+ this.textBoxAddress.Name = "textBoxAddress";
+ this.textBoxAddress.Size = new System.Drawing.Size(100, 20);
+ this.textBoxAddress.TabIndex = 2;
+ //
+ // label2
+ //
+ this.label2.AutoSize = true;
+ this.label2.Location = new System.Drawing.Point(136, 45);
+ this.label2.Name = "label2";
+ this.label2.Size = new System.Drawing.Size(80, 13);
+ this.label2.TabIndex = 3;
+ this.label2.Text = "textBoxAddress";
+ //
+ // textBoxCreatingUserId
+ //
+ this.textBoxCreatingUserId.Location = new System.Drawing.Point(13, 66);
+ this.textBoxCreatingUserId.Name = "textBoxCreatingUserId";
+ this.textBoxCreatingUserId.Size = new System.Drawing.Size(100, 20);
+ this.textBoxCreatingUserId.TabIndex = 4;
+ //
+ // label3
+ //
+ this.label3.AutoSize = true;
+ this.label3.Location = new System.Drawing.Point(139, 72);
+ this.label3.Name = "label3";
+ this.label3.Size = new System.Drawing.Size(112, 13);
+ this.label3.TabIndex = 5;
+ this.label3.Text = "textBoxCreatingUserId";
+ //
+ // textBoxBuildingType
+ //
+ this.textBoxBuildingType.Location = new System.Drawing.Point(13, 93);
+ this.textBoxBuildingType.Name = "textBoxBuildingType";
+ this.textBoxBuildingType.Size = new System.Drawing.Size(100, 20);
+ this.textBoxBuildingType.TabIndex = 6;
+ //
+ // label4
+ //
+ this.label4.AutoSize = true;
+ this.label4.Location = new System.Drawing.Point(139, 99);
+ this.label4.Name = "label4";
+ this.label4.Size = new System.Drawing.Size(103, 13);
+ this.label4.TabIndex = 7;
+ this.label4.Text = "textBoxBuildingType";
+ //
+ // button1
+ //
+ this.button1.Location = new System.Drawing.Point(13, 120);
+ this.button1.Name = "button1";
+ this.button1.Size = new System.Drawing.Size(238, 80);
+ this.button1.TabIndex = 8;
+ this.button1.Text = "Save";
+ this.button1.UseVisualStyleBackColor = true;
+ this.button1.Click += new System.EventHandler(this.btnSave_Click);
+ //
+ // EditFormBuilding
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(263, 214);
+ this.Controls.Add(this.button1);
+ this.Controls.Add(this.label4);
+ this.Controls.Add(this.textBoxBuildingType);
+ this.Controls.Add(this.label3);
+ this.Controls.Add(this.textBoxCreatingUserId);
+ this.Controls.Add(this.label2);
+ this.Controls.Add(this.textBoxAddress);
+ this.Controls.Add(this.label1);
+ this.Controls.Add(this.textBoxFloorCount);
+ this.Name = "EditFormBuilding";
+ this.Text = "EditFormBuilding";
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private System.Windows.Forms.TextBox textBoxFloorCount;
+ private System.Windows.Forms.Label label1;
+ private System.Windows.Forms.TextBox textBoxAddress;
+ private System.Windows.Forms.Label label2;
+ private System.Windows.Forms.TextBox textBoxCreatingUserId;
+ private System.Windows.Forms.Label label3;
+ private System.Windows.Forms.TextBox textBoxBuildingType;
+ private System.Windows.Forms.Label label4;
+ private System.Windows.Forms.Button button1;
+ }
+}
\ No newline at end of file
diff --git a/db_lab/EditFormBuilding.cs b/db_lab/EditFormBuilding.cs
new file mode 100644
index 0000000..da501e0
--- /dev/null
+++ b/db_lab/EditFormBuilding.cs
@@ -0,0 +1,59 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace db_lab
+{
+ public partial class EditFormBuilding : Form
+ {
+ private BuildingRepository buildingRepository;
+ private int? recordId;
+
+ public EditFormBuilding(BuildingRepository buildingRepository, int? recordId = null)
+ {
+ this.buildingRepository = buildingRepository;
+ this.recordId = recordId;
+ InitializeComponent();
+ if (recordId.HasValue)
+ {
+ LoadRecordData(recordId.Value);
+ }
+ }
+
+ private void LoadRecordData(int id)
+ {
+ DataRow row = buildingRepository.GetBuildingById(id);
+ if (row != null)
+ {
+ textBoxFloorCount.Text = row["floor_count"].ToString();
+ textBoxAddress.Text = row["address"].ToString();
+ textBoxCreatingUserId.Text = row["creating_user_id"].ToString();
+ textBoxBuildingType.Text = row["building_type"].ToString();
+ }
+ }
+
+ private void btnSave_Click(object sender, EventArgs e)
+ {
+ int floorCount = int.Parse(textBoxFloorCount.Text);
+ string address = textBoxAddress.Text;
+ int creatingUserId = int.Parse(textBoxCreatingUserId.Text);
+ string buildingType = textBoxBuildingType.Text;
+
+ if (recordId.HasValue)
+ {
+ buildingRepository.UpdateBuilding(recordId.Value, floorCount, address, creatingUserId, buildingType);
+ }
+ else
+ {
+ buildingRepository.AddBuilding(floorCount, address, creatingUserId, buildingType);
+ }
+ this.Close();
+ }
+ }
+}
diff --git a/db_lab/EditFormBuilding.resx b/db_lab/EditFormBuilding.resx
new file mode 100644
index 0000000..1af7de1
--- /dev/null
+++ b/db_lab/EditFormBuilding.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/EditRoomForm.Designer.cs b/db_lab/EditRoomForm.Designer.cs
new file mode 100644
index 0000000..b8f4318
--- /dev/null
+++ b/db_lab/EditRoomForm.Designer.cs
@@ -0,0 +1,193 @@
+namespace db_lab
+{
+ partial class EditRoomForm
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.textBoxRoomType = new System.Windows.Forms.TextBox();
+ this.label1 = new System.Windows.Forms.Label();
+ this.textBoxRoomNumber = new System.Windows.Forms.TextBox();
+ this.label2 = new System.Windows.Forms.Label();
+ this.textBoxFloor = new System.Windows.Forms.TextBox();
+ this.label3 = new System.Windows.Forms.Label();
+ this.textBoxCreatingUserId = new System.Windows.Forms.TextBox();
+ this.label4 = new System.Windows.Forms.Label();
+ this.textBoxBuildingId = new System.Windows.Forms.TextBox();
+ this.label5 = new System.Windows.Forms.Label();
+ this.textBoxRoomName = new System.Windows.Forms.TextBox();
+ this.label6 = new System.Windows.Forms.Label();
+ this.button1 = new System.Windows.Forms.Button();
+ this.SuspendLayout();
+ //
+ // textBoxRoomType
+ //
+ this.textBoxRoomType.Location = new System.Drawing.Point(13, 13);
+ this.textBoxRoomType.Name = "textBoxRoomType";
+ this.textBoxRoomType.Size = new System.Drawing.Size(100, 20);
+ this.textBoxRoomType.TabIndex = 0;
+ //
+ // label1
+ //
+ this.label1.AutoSize = true;
+ this.label1.Location = new System.Drawing.Point(131, 19);
+ this.label1.Name = "label1";
+ this.label1.Size = new System.Drawing.Size(94, 13);
+ this.label1.TabIndex = 1;
+ this.label1.Text = "textBoxRoomType";
+ //
+ // textBoxRoomNumber
+ //
+ this.textBoxRoomNumber.Location = new System.Drawing.Point(13, 40);
+ this.textBoxRoomNumber.Name = "textBoxRoomNumber";
+ this.textBoxRoomNumber.Size = new System.Drawing.Size(100, 20);
+ this.textBoxRoomNumber.TabIndex = 2;
+ //
+ // label2
+ //
+ this.label2.AutoSize = true;
+ this.label2.Location = new System.Drawing.Point(134, 46);
+ this.label2.Name = "label2";
+ this.label2.Size = new System.Drawing.Size(107, 13);
+ this.label2.TabIndex = 3;
+ this.label2.Text = "textBoxRoomNumber";
+ //
+ // textBoxFloor
+ //
+ this.textBoxFloor.Location = new System.Drawing.Point(13, 67);
+ this.textBoxFloor.Name = "textBoxFloor";
+ this.textBoxFloor.Size = new System.Drawing.Size(100, 20);
+ this.textBoxFloor.TabIndex = 4;
+ //
+ // label3
+ //
+ this.label3.AutoSize = true;
+ this.label3.Location = new System.Drawing.Point(137, 73);
+ this.label3.Name = "label3";
+ this.label3.Size = new System.Drawing.Size(65, 13);
+ this.label3.TabIndex = 5;
+ this.label3.Text = "textBoxFloor";
+ //
+ // textBoxCreatingUserId
+ //
+ this.textBoxCreatingUserId.Location = new System.Drawing.Point(13, 94);
+ this.textBoxCreatingUserId.Name = "textBoxCreatingUserId";
+ this.textBoxCreatingUserId.Size = new System.Drawing.Size(100, 20);
+ this.textBoxCreatingUserId.TabIndex = 6;
+ //
+ // label4
+ //
+ this.label4.AutoSize = true;
+ this.label4.Location = new System.Drawing.Point(134, 100);
+ this.label4.Name = "label4";
+ this.label4.Size = new System.Drawing.Size(112, 13);
+ this.label4.TabIndex = 7;
+ this.label4.Text = "textBoxCreatingUserId";
+ //
+ // textBoxBuildingId
+ //
+ this.textBoxBuildingId.Location = new System.Drawing.Point(13, 121);
+ this.textBoxBuildingId.Name = "textBoxBuildingId";
+ this.textBoxBuildingId.Size = new System.Drawing.Size(100, 20);
+ this.textBoxBuildingId.TabIndex = 8;
+ //
+ // label5
+ //
+ this.label5.AutoSize = true;
+ this.label5.Location = new System.Drawing.Point(134, 127);
+ this.label5.Name = "label5";
+ this.label5.Size = new System.Drawing.Size(88, 13);
+ this.label5.TabIndex = 9;
+ this.label5.Text = "textBoxBuildingId";
+ //
+ // textBoxRoomName
+ //
+ this.textBoxRoomName.Location = new System.Drawing.Point(13, 148);
+ this.textBoxRoomName.Name = "textBoxRoomName";
+ this.textBoxRoomName.Size = new System.Drawing.Size(100, 20);
+ this.textBoxRoomName.TabIndex = 10;
+ //
+ // label6
+ //
+ this.label6.AutoSize = true;
+ this.label6.Location = new System.Drawing.Point(137, 154);
+ this.label6.Name = "label6";
+ this.label6.Size = new System.Drawing.Size(98, 13);
+ this.label6.TabIndex = 11;
+ this.label6.Text = "textBoxRoomName";
+ //
+ // button1
+ //
+ this.button1.Location = new System.Drawing.Point(13, 175);
+ this.button1.Name = "button1";
+ this.button1.Size = new System.Drawing.Size(233, 58);
+ this.button1.TabIndex = 12;
+ this.button1.Text = "Save";
+ this.button1.UseVisualStyleBackColor = true;
+ this.button1.Click += new System.EventHandler(this.btnSave_Click);
+ //
+ // EditRoomForm
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(263, 242);
+ this.Controls.Add(this.button1);
+ this.Controls.Add(this.label6);
+ this.Controls.Add(this.textBoxRoomName);
+ this.Controls.Add(this.label5);
+ this.Controls.Add(this.textBoxBuildingId);
+ this.Controls.Add(this.label4);
+ this.Controls.Add(this.textBoxCreatingUserId);
+ this.Controls.Add(this.label3);
+ this.Controls.Add(this.textBoxFloor);
+ this.Controls.Add(this.label2);
+ this.Controls.Add(this.textBoxRoomNumber);
+ this.Controls.Add(this.label1);
+ this.Controls.Add(this.textBoxRoomType);
+ this.Name = "EditRoomForm";
+ this.Text = "EditRoomForm";
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private System.Windows.Forms.TextBox textBoxRoomType;
+ private System.Windows.Forms.Label label1;
+ private System.Windows.Forms.TextBox textBoxRoomNumber;
+ private System.Windows.Forms.Label label2;
+ private System.Windows.Forms.TextBox textBoxFloor;
+ private System.Windows.Forms.Label label3;
+ private System.Windows.Forms.TextBox textBoxCreatingUserId;
+ private System.Windows.Forms.Label label4;
+ private System.Windows.Forms.TextBox textBoxBuildingId;
+ private System.Windows.Forms.Label label5;
+ private System.Windows.Forms.TextBox textBoxRoomName;
+ private System.Windows.Forms.Label label6;
+ private System.Windows.Forms.Button button1;
+ }
+}
\ No newline at end of file
diff --git a/db_lab/EditRoomForm.cs b/db_lab/EditRoomForm.cs
new file mode 100644
index 0000000..13ecd3f
--- /dev/null
+++ b/db_lab/EditRoomForm.cs
@@ -0,0 +1,63 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace db_lab
+{
+ public partial class EditRoomForm : Form
+ {
+ private RoomRepository roomRepository;
+ private int? roomId;
+
+ public EditRoomForm(RoomRepository roomRepository, int? roomId = null)
+ {
+ InitializeComponent();
+ this.roomRepository = roomRepository;
+ this.roomId = roomId;
+ if (roomId.HasValue)
+ {
+ LoadRecordData(roomId.Value);
+ }
+ }
+
+ private void LoadRecordData(int id)
+ {
+ DataRow row = roomRepository.GetRoomById(id);
+ if (row != null)
+ {
+ textBoxRoomType.Text = row["room_type"].ToString();
+ textBoxRoomNumber.Text = row["room_number"].ToString();
+ textBoxFloor.Text = row["floor"].ToString();
+ textBoxCreatingUserId.Text = row["creating_user_id"].ToString();
+ textBoxBuildingId.Text = row["building_id"].ToString();
+ textBoxRoomName.Text = row["room_name"].ToString();
+ }
+ }
+
+ private void btnSave_Click(object sender, EventArgs e)
+ {
+ string roomType = textBoxRoomType.Text;
+ int roomNumber = int.Parse(textBoxRoomNumber.Text);
+ int floor = int.Parse(textBoxFloor.Text);
+ int creatingUserId = int.Parse(textBoxCreatingUserId.Text);
+ int buildingId = int.Parse(textBoxBuildingId.Text);
+ string roomName = textBoxRoomName.Text;
+
+ if (roomId.HasValue)
+ {
+ roomRepository.UpdateRoom(roomId.Value, roomType, roomNumber, floor, creatingUserId, buildingId, roomName);
+ }
+ else
+ {
+ roomRepository.AddRoom(roomType, roomNumber, floor, creatingUserId, buildingId, roomName);
+ }
+ this.Close();
+ }
+ }
+}
diff --git a/db_lab/EditRoomForm.resx b/db_lab/EditRoomForm.resx
new file mode 100644
index 0000000..1af7de1
--- /dev/null
+++ b/db_lab/EditRoomForm.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/EquipmentForm.Designer.cs b/db_lab/EquipmentForm.Designer.cs
new file mode 100644
index 0000000..c383f41
--- /dev/null
+++ b/db_lab/EquipmentForm.Designer.cs
@@ -0,0 +1,137 @@
+namespace db_lab
+{
+ partial class EquipmentForm
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel();
+ this.dataGridView1 = new System.Windows.Forms.DataGridView();
+ this.button1 = new System.Windows.Forms.Button();
+ this.button2 = new System.Windows.Forms.Button();
+ this.button3 = new System.Windows.Forms.Button();
+ this.button4 = new System.Windows.Forms.Button();
+ this.button5 = new System.Windows.Forms.Button();
+ this.flowLayoutPanel1.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
+ this.SuspendLayout();
+ //
+ // flowLayoutPanel1
+ //
+ this.flowLayoutPanel1.Controls.Add(this.button1);
+ this.flowLayoutPanel1.Controls.Add(this.button2);
+ this.flowLayoutPanel1.Controls.Add(this.button3);
+ this.flowLayoutPanel1.Controls.Add(this.button4);
+ this.flowLayoutPanel1.Controls.Add(this.button5);
+ this.flowLayoutPanel1.Location = new System.Drawing.Point(688, 12);
+ this.flowLayoutPanel1.Name = "flowLayoutPanel1";
+ this.flowLayoutPanel1.Size = new System.Drawing.Size(100, 426);
+ this.flowLayoutPanel1.TabIndex = 0;
+ //
+ // dataGridView1
+ //
+ this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.dataGridView1.Location = new System.Drawing.Point(13, 13);
+ this.dataGridView1.Name = "dataGridView1";
+ this.dataGridView1.Size = new System.Drawing.Size(655, 425);
+ this.dataGridView1.TabIndex = 1;
+ //
+ // button1
+ //
+ this.button1.Location = new System.Drawing.Point(3, 3);
+ this.button1.Name = "button1";
+ this.button1.Size = new System.Drawing.Size(75, 23);
+ this.button1.TabIndex = 0;
+ this.button1.Text = "Next";
+ this.button1.UseVisualStyleBackColor = true;
+ this.button1.Click += new System.EventHandler(this.btnNext_Click);
+ //
+ // button2
+ //
+ this.button2.Location = new System.Drawing.Point(3, 32);
+ this.button2.Name = "button2";
+ this.button2.Size = new System.Drawing.Size(75, 23);
+ this.button2.TabIndex = 1;
+ this.button2.Text = "Prev";
+ this.button2.UseVisualStyleBackColor = true;
+ this.button2.Click += new System.EventHandler(this.btnPrev_Click);
+ //
+ // button3
+ //
+ this.button3.Location = new System.Drawing.Point(3, 61);
+ this.button3.Name = "button3";
+ this.button3.Size = new System.Drawing.Size(75, 23);
+ this.button3.TabIndex = 2;
+ this.button3.Text = "Delete";
+ this.button3.UseVisualStyleBackColor = true;
+ this.button3.Click += new System.EventHandler(this.btnDelete_Click);
+ //
+ // button4
+ //
+ this.button4.Location = new System.Drawing.Point(3, 90);
+ this.button4.Name = "button4";
+ this.button4.Size = new System.Drawing.Size(75, 23);
+ this.button4.TabIndex = 3;
+ this.button4.Text = "Add";
+ this.button4.UseVisualStyleBackColor = true;
+ this.button4.Click += new System.EventHandler(this.btnAdd_Click);
+ //
+ // button5
+ //
+ this.button5.Location = new System.Drawing.Point(3, 119);
+ this.button5.Name = "button5";
+ this.button5.Size = new System.Drawing.Size(75, 23);
+ this.button5.TabIndex = 4;
+ this.button5.Text = "Edit";
+ this.button5.UseVisualStyleBackColor = true;
+ this.button5.Click += new System.EventHandler(this.btnEdit_Click);
+ //
+ // EquipmentForm
+ //
+ 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.Controls.Add(this.flowLayoutPanel1);
+ this.Name = "EquipmentForm";
+ this.Text = "EquipmentForm";
+ this.flowLayoutPanel1.ResumeLayout(false);
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+
+ private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1;
+ private System.Windows.Forms.DataGridView dataGridView1;
+ private System.Windows.Forms.Button button1;
+ private System.Windows.Forms.Button button2;
+ private System.Windows.Forms.Button button3;
+ private System.Windows.Forms.Button button4;
+ private System.Windows.Forms.Button button5;
+ }
+}
\ No newline at end of file
diff --git a/db_lab/EquipmentForm.cs b/db_lab/EquipmentForm.cs
new file mode 100644
index 0000000..7dcecad
--- /dev/null
+++ b/db_lab/EquipmentForm.cs
@@ -0,0 +1,79 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace db_lab
+{
+ public partial class EquipmentForm : Form
+ {
+ private EquipmentRepository equipmentRepository;
+ private int pageSize = 10;
+ private int currentPage = 1;
+
+ public EquipmentForm(string connectionString)
+ {
+ InitializeComponent();
+ equipmentRepository = new EquipmentRepository(connectionString);
+ LoadData();
+ }
+
+ private void LoadData()
+ {
+ DataTable dt = equipmentRepository.ReadEquipments(pageSize, currentPage);
+ dataGridView1.DataSource = dt;
+ }
+
+ private void btnNext_Click(object sender, EventArgs e)
+ {
+ currentPage++;
+ LoadData();
+ }
+
+ private void btnPrev_Click(object sender, EventArgs e)
+ {
+ if (currentPage > 1)
+ {
+ currentPage--;
+ LoadData();
+ }
+ }
+
+ private void btnDelete_Click(object sender, EventArgs e)
+ {
+ foreach (DataGridViewRow row in dataGridView1.SelectedRows)
+ {
+ int id = Convert.ToInt32(row.Cells["id"].Value);
+ equipmentRepository.DeleteEquipment(id);
+ }
+ LoadData();
+ }
+
+ private void btnAdd_Click(object sender, EventArgs e)
+ {
+ EditEquipmentForm editForm = new EditEquipmentForm(equipmentRepository);
+ editForm.ShowDialog();
+ LoadData();
+ }
+
+ private void btnEdit_Click(object sender, EventArgs e)
+ {
+ if (dataGridView1.SelectedRows.Count == 1)
+ {
+ int id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["id"].Value);
+ EditEquipmentForm editForm = new EditEquipmentForm(equipmentRepository, id);
+ editForm.ShowDialog();
+ LoadData();
+ }
+ else
+ {
+ MessageBox.Show("Please select a single row to edit.");
+ }
+ }
+ }
+}
diff --git a/db_lab/EquipmentForm.resx b/db_lab/EquipmentForm.resx
new file mode 100644
index 0000000..1af7de1
--- /dev/null
+++ b/db_lab/EquipmentForm.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/EquipmentRepository.cs b/db_lab/EquipmentRepository.cs
new file mode 100644
index 0000000..d01cd1d
--- /dev/null
+++ b/db_lab/EquipmentRepository.cs
@@ -0,0 +1,82 @@
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Npgsql;
+
+namespace db_lab
+{
+ public class EquipmentRepository
+ {
+ private NpgsqlConnection connection;
+
+ public EquipmentRepository(string connectionString)
+ {
+ this.connection = new NpgsqlConnection(connectionString);
+ }
+
+ public DataTable ReadEquipments(int pageSize, int pageNumber)
+ {
+ string query = $"SELECT * FROM Equipment ORDER BY id LIMIT {pageSize} OFFSET {(pageNumber - 1) * pageSize}";
+ NpgsqlDataAdapter da = new NpgsqlDataAdapter(query, connection);
+ DataTable dt = new DataTable();
+ da.Fill(dt);
+ return dt;
+ }
+
+ public void DeleteEquipment(int id)
+ {
+ string query = $"DELETE FROM Equipment WHERE id = {id}";
+ using (var cmd = new NpgsqlCommand(query, connection))
+ {
+ connection.Open();
+ cmd.ExecuteNonQuery();
+ connection.Close();
+ }
+ }
+
+ public void AddEquipment(string ipAddress, string sshSettings, string name, int roomId)
+ {
+ string query = "INSERT INTO Equipment (ip_address, ssh_settings, name, room_id) VALUES (@ip_address, @ssh_settings, @name, @room_id)";
+ using (var cmd = new NpgsqlCommand(query, connection))
+ {
+ cmd.Parameters.AddWithValue("ip_address", ipAddress);
+ cmd.Parameters.AddWithValue("ssh_settings", sshSettings ?? (object)DBNull.Value);
+ cmd.Parameters.AddWithValue("name", name);
+ cmd.Parameters.AddWithValue("room_id", roomId);
+
+ connection.Open();
+ cmd.ExecuteNonQuery();
+ connection.Close();
+ }
+ }
+
+ public void UpdateEquipment(int id, string ipAddress, string sshSettings, string name, int roomId)
+ {
+ string query = "UPDATE Equipment SET ip_address = @ip_address, ssh_settings = @ssh_settings, name = @name, room_id = @room_id WHERE id = @id";
+ using (var cmd = new NpgsqlCommand(query, connection))
+ {
+ cmd.Parameters.AddWithValue("ip_address", ipAddress);
+ cmd.Parameters.AddWithValue("ssh_settings", sshSettings ?? (object)DBNull.Value);
+ cmd.Parameters.AddWithValue("name", name);
+ cmd.Parameters.AddWithValue("room_id", roomId);
+ cmd.Parameters.AddWithValue("id", id);
+
+ connection.Open();
+ cmd.ExecuteNonQuery();
+ connection.Close();
+ }
+ }
+
+ public DataRow GetEquipmentById(int id)
+ {
+ string query = $"SELECT * FROM Equipment WHERE id = {id}";
+ NpgsqlDataAdapter da = new NpgsqlDataAdapter(query, connection);
+ DataTable dt = new DataTable();
+ da.Fill(dt);
+ return dt.Rows.Count > 0 ? dt.Rows[0] : null;
+ }
+ }
+}
diff --git a/db_lab/Form1.Designer.cs b/db_lab/Form1.Designer.cs
index 92a7230..eb0dcae 100644
--- a/db_lab/Form1.Designer.cs
+++ b/db_lab/Form1.Designer.cs
@@ -33,8 +33,10 @@
this.dataBtn = new System.Windows.Forms.Button();
this.raportBtn = new System.Windows.Forms.Button();
this.aboutBtn = new System.Windows.Forms.Button();
- this.exitBtn = new System.Windows.Forms.Button();
this.dbConnectBtn = new System.Windows.Forms.Button();
+ this.exitBtn = new System.Windows.Forms.Button();
+ this.buildingButton = new System.Windows.Forms.Button();
+ this.button1 = new System.Windows.Forms.Button();
this.flowLayoutPanel1.SuspendLayout();
this.SuspendLayout();
//
@@ -47,6 +49,8 @@
this.flowLayoutPanel1.Controls.Add(this.aboutBtn);
this.flowLayoutPanel1.Controls.Add(this.dbConnectBtn);
this.flowLayoutPanel1.Controls.Add(this.exitBtn);
+ this.flowLayoutPanel1.Controls.Add(this.buildingButton);
+ this.flowLayoutPanel1.Controls.Add(this.button1);
this.flowLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.flowLayoutPanel1.Location = new System.Drawing.Point(0, 0);
this.flowLayoutPanel1.Name = "flowLayoutPanel1";
@@ -93,16 +97,6 @@
this.aboutBtn.UseVisualStyleBackColor = true;
this.aboutBtn.Click += new System.EventHandler(this.aboutBtn_Click);
//
- // exitBtn
- //
- this.exitBtn.Location = new System.Drawing.Point(528, 3);
- this.exitBtn.Name = "exitBtn";
- this.exitBtn.Size = new System.Drawing.Size(75, 23);
- this.exitBtn.TabIndex = 4;
- this.exitBtn.Text = "Выход";
- this.exitBtn.UseVisualStyleBackColor = true;
- this.exitBtn.Click += new System.EventHandler(this.exitBtn_Click);
- //
// dbConnectBtn
//
this.dbConnectBtn.AutoSize = true;
@@ -115,6 +109,36 @@
this.dbConnectBtn.UseVisualStyleBackColor = true;
this.dbConnectBtn.Click += new System.EventHandler(this.dbConnectBtn_Click);
//
+ // exitBtn
+ //
+ this.exitBtn.Location = new System.Drawing.Point(528, 3);
+ this.exitBtn.Name = "exitBtn";
+ this.exitBtn.Size = new System.Drawing.Size(75, 23);
+ this.exitBtn.TabIndex = 4;
+ this.exitBtn.Text = "Выход";
+ this.exitBtn.UseVisualStyleBackColor = true;
+ this.exitBtn.Click += new System.EventHandler(this.exitBtn_Click);
+ //
+ // buildingButton
+ //
+ this.buildingButton.Location = new System.Drawing.Point(609, 3);
+ this.buildingButton.Name = "buildingButton";
+ this.buildingButton.Size = new System.Drawing.Size(75, 23);
+ this.buildingButton.TabIndex = 6;
+ this.buildingButton.Text = "CRUD";
+ this.buildingButton.UseVisualStyleBackColor = true;
+ this.buildingButton.Click += new System.EventHandler(this.buildingButton_Click);
+ this.buildingButton.MouseClick += new System.Windows.Forms.MouseEventHandler(this.buildingButton_MouseClick);
+ //
+ // button1
+ //
+ this.button1.Location = new System.Drawing.Point(690, 3);
+ this.button1.Name = "button1";
+ this.button1.Size = new System.Drawing.Size(75, 23);
+ this.button1.TabIndex = 7;
+ this.button1.Text = "Экспорт";
+ this.button1.UseVisualStyleBackColor = true;
+ //
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@@ -139,6 +163,8 @@
private System.Windows.Forms.Button aboutBtn;
private System.Windows.Forms.Button exitBtn;
private System.Windows.Forms.Button dbConnectBtn;
+ private System.Windows.Forms.Button buildingButton;
+ private System.Windows.Forms.Button button1;
}
}
diff --git a/db_lab/Form1.cs b/db_lab/Form1.cs
index e8a5232..c26b39d 100644
--- a/db_lab/Form1.cs
+++ b/db_lab/Form1.cs
@@ -13,7 +13,7 @@ namespace db_lab
{
public partial class Form1 : Form
{
- string connectionString = "Server=192.168.1.218;Port=5432;UserId=postgres;Password=postgres;Database=SQL_Servers;";
+ string connectionString = "Server=172.27.128.1;Port=5432;UserId=postgres;Password=postgres;Database=SQL_Servers;";
NpgsqlConnection connection;
public Form1()
@@ -67,5 +67,17 @@ namespace db_lab
MessageBox.Show($"Error! Db connection was fatal! Log: {ex.Message}");
}
}
+
+ private void buildingButton_MouseClick(object sender, MouseEventArgs e)
+ {
+ var crudForm = new CRUDForm(this.connectionString);
+ crudForm.Show();
+ }
+
+ private void buildingButton_Click(object sender, EventArgs e)
+ {
+ var crudForm = new CRUDForm(this.connectionString);
+ crudForm.Show();
+ }
}
}
diff --git a/db_lab/RoomForm.Designer.cs b/db_lab/RoomForm.Designer.cs
new file mode 100644
index 0000000..72d9d0f
--- /dev/null
+++ b/db_lab/RoomForm.Designer.cs
@@ -0,0 +1,137 @@
+namespace db_lab
+{
+ partial class RoomForm
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.dataGridView1 = new System.Windows.Forms.DataGridView();
+ this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel();
+ this.button1 = new System.Windows.Forms.Button();
+ this.button2 = new System.Windows.Forms.Button();
+ this.button3 = new System.Windows.Forms.Button();
+ this.button4 = new System.Windows.Forms.Button();
+ this.button5 = new System.Windows.Forms.Button();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
+ this.flowLayoutPanel1.SuspendLayout();
+ this.SuspendLayout();
+ //
+ // dataGridView1
+ //
+ this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.dataGridView1.Location = new System.Drawing.Point(12, 12);
+ this.dataGridView1.Name = "dataGridView1";
+ this.dataGridView1.Size = new System.Drawing.Size(677, 431);
+ this.dataGridView1.TabIndex = 0;
+ //
+ // flowLayoutPanel1
+ //
+ this.flowLayoutPanel1.Controls.Add(this.button1);
+ this.flowLayoutPanel1.Controls.Add(this.button2);
+ this.flowLayoutPanel1.Controls.Add(this.button3);
+ this.flowLayoutPanel1.Controls.Add(this.button4);
+ this.flowLayoutPanel1.Controls.Add(this.button5);
+ this.flowLayoutPanel1.Location = new System.Drawing.Point(695, 12);
+ this.flowLayoutPanel1.Name = "flowLayoutPanel1";
+ this.flowLayoutPanel1.Size = new System.Drawing.Size(93, 431);
+ this.flowLayoutPanel1.TabIndex = 1;
+ //
+ // button1
+ //
+ this.button1.Location = new System.Drawing.Point(3, 3);
+ this.button1.Name = "button1";
+ this.button1.Size = new System.Drawing.Size(75, 23);
+ this.button1.TabIndex = 0;
+ this.button1.Text = "Next";
+ this.button1.UseVisualStyleBackColor = true;
+ this.button1.Click += new System.EventHandler(this.btnNext_Click);
+ //
+ // button2
+ //
+ this.button2.Location = new System.Drawing.Point(3, 32);
+ this.button2.Name = "button2";
+ this.button2.Size = new System.Drawing.Size(75, 23);
+ this.button2.TabIndex = 1;
+ this.button2.Text = "Prev";
+ this.button2.UseVisualStyleBackColor = true;
+ this.button2.Click += new System.EventHandler(this.btnPrev_Click);
+ //
+ // button3
+ //
+ this.button3.Location = new System.Drawing.Point(3, 61);
+ this.button3.Name = "button3";
+ this.button3.Size = new System.Drawing.Size(75, 23);
+ this.button3.TabIndex = 2;
+ this.button3.Text = "Delete";
+ this.button3.UseVisualStyleBackColor = true;
+ this.button3.Click += new System.EventHandler(this.btnDelete_Click);
+ //
+ // button4
+ //
+ this.button4.Location = new System.Drawing.Point(3, 90);
+ this.button4.Name = "button4";
+ this.button4.Size = new System.Drawing.Size(75, 23);
+ this.button4.TabIndex = 3;
+ this.button4.Text = "Add";
+ this.button4.UseVisualStyleBackColor = true;
+ this.button4.Click += new System.EventHandler(this.btnAdd_Click);
+ //
+ // button5
+ //
+ this.button5.Location = new System.Drawing.Point(3, 119);
+ this.button5.Name = "button5";
+ this.button5.Size = new System.Drawing.Size(75, 23);
+ this.button5.TabIndex = 4;
+ this.button5.Text = "Edit";
+ this.button5.UseVisualStyleBackColor = true;
+ this.button5.Click += new System.EventHandler(this.btnEdit_Click);
+ //
+ // RoomForm
+ //
+ 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.flowLayoutPanel1);
+ this.Controls.Add(this.dataGridView1);
+ this.Name = "RoomForm";
+ this.Text = "RoomForm";
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
+ this.flowLayoutPanel1.ResumeLayout(false);
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+
+ private System.Windows.Forms.DataGridView dataGridView1;
+ private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1;
+ private System.Windows.Forms.Button button1;
+ private System.Windows.Forms.Button button2;
+ private System.Windows.Forms.Button button3;
+ private System.Windows.Forms.Button button4;
+ private System.Windows.Forms.Button button5;
+ }
+}
\ No newline at end of file
diff --git a/db_lab/RoomForm.cs b/db_lab/RoomForm.cs
new file mode 100644
index 0000000..16bf08a
--- /dev/null
+++ b/db_lab/RoomForm.cs
@@ -0,0 +1,79 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace db_lab
+{
+ public partial class RoomForm : Form
+ {
+ private RoomRepository roomRepository;
+ private int pageSize = 10;
+ private int currentPage = 1;
+
+ public RoomForm(string connectionString)
+ {
+ InitializeComponent();
+ roomRepository = new RoomRepository(connectionString);
+ LoadData();
+ }
+
+ private void LoadData()
+ {
+ DataTable dt = roomRepository.ReadRooms(pageSize, currentPage);
+ dataGridView1.DataSource = dt;
+ }
+
+ private void btnNext_Click(object sender, EventArgs e)
+ {
+ currentPage++;
+ LoadData();
+ }
+
+ private void btnPrev_Click(object sender, EventArgs e)
+ {
+ if (currentPage > 1)
+ {
+ currentPage--;
+ LoadData();
+ }
+ }
+
+ private void btnDelete_Click(object sender, EventArgs e)
+ {
+ foreach (DataGridViewRow row in dataGridView1.SelectedRows)
+ {
+ int id = Convert.ToInt32(row.Cells["id"].Value);
+ roomRepository.DeleteRoom(id);
+ }
+ LoadData();
+ }
+
+ private void btnAdd_Click(object sender, EventArgs e)
+ {
+ EditRoomForm editForm = new EditRoomForm(roomRepository);
+ editForm.ShowDialog();
+ LoadData();
+ }
+
+ private void btnEdit_Click(object sender, EventArgs e)
+ {
+ if (dataGridView1.SelectedRows.Count == 1)
+ {
+ int id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["id"].Value);
+ EditRoomForm editForm = new EditRoomForm(roomRepository, id);
+ editForm.ShowDialog();
+ LoadData();
+ }
+ else
+ {
+ MessageBox.Show("Please select a single row to edit.");
+ }
+ }
+ }
+}
diff --git a/db_lab/RoomForm.resx b/db_lab/RoomForm.resx
new file mode 100644
index 0000000..1af7de1
--- /dev/null
+++ b/db_lab/RoomForm.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/RoomRepository.cs b/db_lab/RoomRepository.cs
new file mode 100644
index 0000000..f2653ca
--- /dev/null
+++ b/db_lab/RoomRepository.cs
@@ -0,0 +1,86 @@
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Npgsql;
+
+namespace db_lab
+{
+ public class RoomRepository
+ {
+ private NpgsqlConnection connection;
+
+ public RoomRepository(string connectionString)
+ {
+ this.connection = new NpgsqlConnection(connectionString);
+ }
+
+ public DataTable ReadRooms(int pageSize, int pageNumber)
+ {
+ string query = $"SELECT * FROM Rooms ORDER BY id LIMIT {pageSize} OFFSET {(pageNumber - 1) * pageSize}";
+ NpgsqlDataAdapter da = new NpgsqlDataAdapter(query, connection);
+ DataTable dt = new DataTable();
+ da.Fill(dt);
+ return dt;
+ }
+
+ public void DeleteRoom(int id)
+ {
+ string query = $"DELETE FROM Rooms WHERE id = {id}";
+ using (var cmd = new NpgsqlCommand(query, connection))
+ {
+ connection.Open();
+ cmd.ExecuteNonQuery();
+ connection.Close();
+ }
+ }
+
+ public void AddRoom(string roomType, int roomNumber, int floor, int creatingUserId, int buildingId, string roomName)
+ {
+ string query = "INSERT INTO Rooms (room_type, room_number, floor, creating_user_id, building_id, room_name) VALUES (@room_type, @room_number, @floor, @creating_user_id, @building_id, @room_name)";
+ using (var cmd = new NpgsqlCommand(query, connection))
+ {
+ cmd.Parameters.AddWithValue("room_type", roomType);
+ cmd.Parameters.AddWithValue("room_number", roomNumber);
+ cmd.Parameters.AddWithValue("floor", floor);
+ cmd.Parameters.AddWithValue("creating_user_id", creatingUserId);
+ cmd.Parameters.AddWithValue("building_id", buildingId);
+ cmd.Parameters.AddWithValue("room_name", roomName);
+
+ connection.Open();
+ cmd.ExecuteNonQuery();
+ connection.Close();
+ }
+ }
+
+ public void UpdateRoom(int id, string roomType, int roomNumber, int floor, int creatingUserId, int buildingId, string roomName)
+ {
+ string query = "UPDATE Rooms SET room_type = @room_type, room_number = @room_number, floor = @floor, creating_user_id = @creating_user_id, building_id = @building_id, room_name = @room_name WHERE id = @id";
+ using (var cmd = new NpgsqlCommand(query, connection))
+ {
+ cmd.Parameters.AddWithValue("room_type", roomType);
+ cmd.Parameters.AddWithValue("room_number", roomNumber);
+ cmd.Parameters.AddWithValue("floor", floor);
+ cmd.Parameters.AddWithValue("creating_user_id", creatingUserId);
+ cmd.Parameters.AddWithValue("building_id", buildingId);
+ cmd.Parameters.AddWithValue("room_name", roomName);
+ cmd.Parameters.AddWithValue("id", id);
+
+ connection.Open();
+ cmd.ExecuteNonQuery();
+ connection.Close();
+ }
+ }
+
+ public DataRow GetRoomById(int id)
+ {
+ string query = $"SELECT * FROM Rooms WHERE id = {id}";
+ NpgsqlDataAdapter da = new NpgsqlDataAdapter(query, connection);
+ DataTable dt = new DataTable();
+ da.Fill(dt);
+ return dt.Rows.Count > 0 ? dt.Rows[0] : null;
+ }
+ }
+}
diff --git a/db_lab/bin/Debug/db_lab.exe b/db_lab/bin/Debug/db_lab.exe
index 6ed17b1..4be2479 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 ffdd71d..4b313fe 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 eeb78b2..d135228 100644
--- a/db_lab/db_lab.csproj
+++ b/db_lab/db_lab.csproj
@@ -95,12 +95,62 @@
+
+ Form
+
+
+ BuildingRepository.cs
+
+
+ Form
+
+
+ CRUDForm.cs
+
Form
DataForm.cs
+
+ Form
+
+
+ DepartmentForm.cs
+
+
+
+ Form
+
+
+ EditDepartmentForm.cs
+
+
+ Form
+
+
+ EditEquipmentForm.cs
+
+
+ Form
+
+
+ EditFormBuilding.cs
+
+
+ Form
+
+
+ EditRoomForm.cs
+
+
+ Form
+
+
+ EquipmentForm.cs
+
+
Form
@@ -121,9 +171,37 @@
RaportForm.cs
+
+ Form
+
+
+ RoomForm.cs
+
+
+
+ CRUDForm.cs
+
DataForm.cs
+
+ DepartmentForm.cs
+
+
+ EditDepartmentForm.cs
+
+
+ EditEquipmentForm.cs
+
+
+ EditFormBuilding.cs
+
+
+ EditRoomForm.cs
+
+
+ EquipmentForm.cs
+
Form1.cs
@@ -139,6 +217,9 @@
RaportForm.cs
+
+ RoomForm.cs
+
SettingsSingleFileGenerator
diff --git a/db_lab/obj/Debug/db_lab.CRUDForm.resources b/db_lab/obj/Debug/db_lab.CRUDForm.resources
new file mode 100644
index 0000000..6c05a97
Binary files /dev/null and b/db_lab/obj/Debug/db_lab.CRUDForm.resources differ
diff --git a/db_lab/obj/Debug/db_lab.DepartmentForm.resources b/db_lab/obj/Debug/db_lab.DepartmentForm.resources
new file mode 100644
index 0000000..6c05a97
Binary files /dev/null and b/db_lab/obj/Debug/db_lab.DepartmentForm.resources differ
diff --git a/db_lab/obj/Debug/db_lab.EditDepartmentForm.resources b/db_lab/obj/Debug/db_lab.EditDepartmentForm.resources
new file mode 100644
index 0000000..6c05a97
Binary files /dev/null and b/db_lab/obj/Debug/db_lab.EditDepartmentForm.resources differ
diff --git a/db_lab/obj/Debug/db_lab.EditEquipmentForm.resources b/db_lab/obj/Debug/db_lab.EditEquipmentForm.resources
new file mode 100644
index 0000000..6c05a97
Binary files /dev/null and b/db_lab/obj/Debug/db_lab.EditEquipmentForm.resources differ
diff --git a/db_lab/obj/Debug/db_lab.EditFormBuilding.resources b/db_lab/obj/Debug/db_lab.EditFormBuilding.resources
new file mode 100644
index 0000000..6c05a97
Binary files /dev/null and b/db_lab/obj/Debug/db_lab.EditFormBuilding.resources differ
diff --git a/db_lab/obj/Debug/db_lab.EditRoomForm.resources b/db_lab/obj/Debug/db_lab.EditRoomForm.resources
new file mode 100644
index 0000000..6c05a97
Binary files /dev/null and b/db_lab/obj/Debug/db_lab.EditRoomForm.resources differ
diff --git a/db_lab/obj/Debug/db_lab.EquipmentForm.resources b/db_lab/obj/Debug/db_lab.EquipmentForm.resources
new file mode 100644
index 0000000..6c05a97
Binary files /dev/null and b/db_lab/obj/Debug/db_lab.EquipmentForm.resources differ
diff --git a/db_lab/obj/Debug/db_lab.RoomForm.resources b/db_lab/obj/Debug/db_lab.RoomForm.resources
new file mode 100644
index 0000000..6c05a97
Binary files /dev/null and b/db_lab/obj/Debug/db_lab.RoomForm.resources differ
diff --git a/db_lab/obj/Debug/db_lab.csproj.CoreCompileInputs.cache b/db_lab/obj/Debug/db_lab.csproj.CoreCompileInputs.cache
index 8112610..43c87d4 100644
--- a/db_lab/obj/Debug/db_lab.csproj.CoreCompileInputs.cache
+++ b/db_lab/obj/Debug/db_lab.csproj.CoreCompileInputs.cache
@@ -1 +1 @@
-6cfe98626599e0585a6a4cbde9575a47698b081aa3748f1df4309e2ac8c0a680
+944491e2b148661396206da4f57aa1e690b8d9c434e41ee7e94081a5ed9feabd
diff --git a/db_lab/obj/Debug/db_lab.csproj.FileListAbsolute.txt b/db_lab/obj/Debug/db_lab.csproj.FileListAbsolute.txt
index 113a2e2..d3bb7d0 100644
--- a/db_lab/obj/Debug/db_lab.csproj.FileListAbsolute.txt
+++ b/db_lab/obj/Debug/db_lab.csproj.FileListAbsolute.txt
@@ -43,3 +43,11 @@ 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
+C:\Users\mit3t\source\repos\db_lab\db_lab\obj\Debug\db_lab.CRUDForm.resources
+C:\Users\mit3t\source\repos\db_lab\db_lab\obj\Debug\db_lab.EditFormBuilding.resources
+C:\Users\mit3t\source\repos\db_lab\db_lab\obj\Debug\db_lab.DepartmentForm.resources
+C:\Users\mit3t\source\repos\db_lab\db_lab\obj\Debug\db_lab.EditDepartmentForm.resources
+C:\Users\mit3t\source\repos\db_lab\db_lab\obj\Debug\db_lab.EditRoomForm.resources
+C:\Users\mit3t\source\repos\db_lab\db_lab\obj\Debug\db_lab.RoomForm.resources
+C:\Users\mit3t\source\repos\db_lab\db_lab\obj\Debug\db_lab.EditEquipmentForm.resources
+C:\Users\mit3t\source\repos\db_lab\db_lab\obj\Debug\db_lab.EquipmentForm.resources
diff --git a/db_lab/obj/Debug/db_lab.csproj.GenerateResource.cache b/db_lab/obj/Debug/db_lab.csproj.GenerateResource.cache
index 733ee0f..d135320 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 6ed17b1..4be2479 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 ffdd71d..4b313fe 100644
Binary files a/db_lab/obj/Debug/db_lab.pdb and b/db_lab/obj/Debug/db_lab.pdb differ