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.

80 lines
2.2 KiB

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.");
}
}
}
}