52 lines
2.1 KiB
C#
52 lines
2.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Data.OleDb;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Database
|
|
{
|
|
class Fishes : OleDBDataGridViewHandler
|
|
{
|
|
static OleDbCommand SelectCommand() {
|
|
string command =
|
|
"SELECT [F].[id], [FT].[data] AS [type], [L].[data] AS [location], [F].[number]" +
|
|
"FROM[fishes] AS[F], [fish_types] AS[FT], [locations] AS[L]" +
|
|
"WHERE[type_id] = [FT].[id] AND[location_id] = [L].[id]";
|
|
var result = new OleDbCommand(command, OleDBHandler.Connection);
|
|
return result;
|
|
}
|
|
public Fishes(DataGridView dataGridView) : base(SelectCommand(), "fishes", dataGridView) {}
|
|
private bool Exists(int typeId, int locationId) {
|
|
string command = "SELECT COUNT(*) FROM [fishes]" +
|
|
$"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();
|
|
}
|
|
}
|
|
}
|