-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSubjectsForm.cs
55 lines (52 loc) · 1.97 KB
/
SubjectsForm.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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 Приложение_для_деканата_v1._2
{
public partial class SubjectsForm : Form
{
private readonly PGSQL pGSQL;
private bool IsExists;
public SubjectsForm(PGSQL pGSQL)
{
InitializeComponent();
this.pGSQL = pGSQL;
IsExists = true;
}
private void buttonInsert_Click(object sender, EventArgs e)
{
if (IsExists)
{
MessageBox.Show("Предмет уже существует или вы ничего не вписали в поле ввода!");
return;
}
pGSQL.InsertUpdateDeleteDB($"insert into subjects (\"name\") values (\'{textBoxSubjectsName.Text}\');");
MessageBox.Show("Предмет добавлен в базу данных!");
}
private void textBoxSubjectsName_TextChanged(object sender, EventArgs e)
{
if (textBoxSubjectsName.Text.Trim() == "" || textBoxSubjectsName.Text==null)
{
labelStatus.Text = "неизвестно";
IsExists = true;
}
else if ((bool)pGSQL.SelectDB($"SELECT EXISTS (SELECT 1 FROM subjects WHERE \"name\" = \'{textBoxSubjectsName.Text}\');").Rows[0][0])
{
labelStatus.Text = "существует";
IsExists = true;
}
else
{
labelStatus.Text = "не существует";
IsExists = false;
}
//labelStatus.Text = (bool)pGSQL.SelectDB($"SELECT EXISTS (SELECT 1 FROM subjects WHERE \"name\" = \'{textBoxSubjectsName.Text}\');").Rows[0][0] ? "существует" : "не существует";
}
}
}