Initial commit

This commit is contained in:
user
2026-07-12 16:06:18 +04:00
commit 1d16eeacb2
23 changed files with 2298 additions and 0 deletions
+56
View File
@@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Database
{
abstract class OleDBDataGridViewHandler
{
protected string nameTable;
private int idIndex;
public OleDbDataAdapter select;
private DataGridView dataGridView;
protected OleDBDataGridViewHandler(OleDbCommand selectCommand, string nameTable, DataGridView dataGridView, int idIndex = 0)
{
this.nameTable = nameTable;
this.idIndex = idIndex;
select = new OleDbDataAdapter(selectCommand);
this.dataGridView = dataGridView;
this.dataGridView.DataSource = new DataTable();
RefreshView();
var lastColIndex = dataGridView.Columns.Count - 1;
var lastColumn = dataGridView.Columns[lastColIndex];
lastColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
protected OleDBDataGridViewHandler(string nameTable, DataGridView dataGridView, string fields = "*", int idIndex = 0)
: this(OleDBHandler.SelectCommand(nameTable, fields), nameTable, dataGridView, idIndex)
{ }
protected void RefreshView()
{
var dataTable = this.dataGridView.DataSource as DataTable;
dataTable.Clear();
select.Fill(dataTable);
}
protected int CurrentId()
{
if (dataGridView.SelectedCells.Count < 1)
return -1;
var selectedRowIndex = dataGridView.SelectedCells[0].RowIndex;
var value = dataGridView.Rows[selectedRowIndex].Cells[idIndex].Value;
return Convert.ToInt32(value);
}
public void Delete()
{
int id = CurrentId();
if (id < 0)
return;
OleDBHandler.Delete(nameTable, id);
RefreshView();
}
}
}