You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.0 KiB

using Npgsql;
using System;
8 months ago
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;
using Npgsql;
using System.Web;
8 months ago
namespace db_lab
{
public partial class DataForm : Form
{
NpgsqlConnection connection;
public DataForm(string connection)
8 months ago
{
this.connection = new NpgsqlConnection(connection);
8 months ago
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");
}
8 months ago
}
}