Files

51 lines
2.1 KiB
C#
Raw Permalink Normal View History

2026-07-12 16:06:18 +04:00
using System;
using System.Collections.Generic;
using System.Data.OleDb;
using System.Text;
using System.Windows.Forms;
namespace Database
{
class Plants : OleDBDataGridViewHandler
{
static OleDbCommand SelectCommand() {
string command =
"SELECT [F].[id], [PT].[data] AS [type], [L].[data] AS [location], [F].[number]" +
"FROM[plants] AS[F], [plant_types] AS[PT], [locations] AS[L]" +
"WHERE[type_id] = [PT].[id] AND[location_id] = [L].[id]";
var result = new OleDbCommand(command, OleDBHandler.Connection);
return result;
}
public Plants(DataGridView dataGridView) : base(SelectCommand(), "plants", dataGridView) { }
private bool Exists(int typeId, int locationId) {
string command = "SELECT COUNT(*) FROM [plants]" +
$"WHERE [type_id] = {typeId} AND [location_id] = {locationId};";
var result = OleDBHandler.Execute(command, OleDBHandler.ExecuteType.Scalar);
if (Convert.ToInt32(result) > 0)
return true;
return false;
}
public void Insert(int number, int typeId, int locationId) {
if (Exists(typeId, locationId) == true)
return;
(string, object) pair1 = ("type_id", typeId);
(string, object) pair2 = ("location_id", locationId);
(string, object) pair3 = ("number", number);
OleDBHandler.Insert(nameTable, pair1, pair2, pair3);
RefreshView();
}
public void Update(int number, int typeId, int locationId) {
if (Exists(typeId, locationId) == true)
return;
int id = CurrentId();
if (id < 0)
return;
(string, object) pair1 = ("type_id", typeId);
(string, object) pair2 = ("location_id", locationId);
(string, object) pair3 = ("number", number);
OleDBHandler.Update(nameTable, id, pair1, pair2, pair3);
RefreshView();
}
}
}