Repository navigation
Expand file tree
/
Copy pathForm1.cs
More file actions
114 lines (89 loc) · 3.36 KB
/
Copy pathForm1.cs
File metadata and controls
114 lines (89 loc) · 3.36 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
using MySql.Data.MySqlClient;
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 ProjectAvtoMoika
{
public partial class AvtoMoika : Form
{
public AvtoMoika()
{
InitializeComponent();
LoginField.Text = "Введите имя:";
Nums.Text = "Введите номер авто:";
}
private void AddClient_Click(object sender, EventArgs e)
{
if (LoginField.Text == "Введите имя:")
{
MessageBox.Show("Введите Имя!");
return;
}
if (Nums.Text == "Введите номер авто:")
{
MessageBox.Show("Введите Номер авто!");
return;
}
bool userExists = checkUser();
if (checkUser())
{
DB dB = new DB();
MySqlCommand command = new MySqlCommand("INSERT INTO `clients` (`Nums`, `Client`) VALUES (@Nums,@Client);", dB.GetConnection());
command.Parameters.Add("@Nums", MySqlDbType.VarChar).Value = Nums.Text;
command.Parameters.Add("@Client", MySqlDbType.VarChar).Value = LoginField.Text;
dB.OpenCon();
if (command.ExecuteNonQuery() == 1)
MessageBox.Show("Клиент добавлен");
else
MessageBox.Show("Клиент не был добавлен");
dB.CloseCon();
}
}
private void LoginField_Enter(object sender, EventArgs e)
{
if (LoginField.Text == "Введите имя:")
LoginField.Text = "";
}
private void LoginField_Leave(object sender, EventArgs e)
{
if (LoginField.Text == "")
LoginField.Text = "Введите имя:";
}
private void Nums_TextChanged(object sender, EventArgs e)
{
}
private void Nums_Enter(object sender, EventArgs e)
{
if (Nums.Text == "Введите номер авто:")
Nums.Text = "";
}
private void Nums_Leave(object sender, EventArgs e)
{
if (Nums.Text == "")
Nums.Text = "Введите номер авто:";
}
public Boolean checkUser()
{
DB db = new DB();
DataTable dataTable = new DataTable();
MySqlDataAdapter adapter = new MySqlDataAdapter();
MySqlCommand cmd = new MySqlCommand("SELECT * FROM `clients` WHERE `Client` = @ul AND `Nums` = @nomer", db.GetConnection());
cmd.Parameters.Add("@ul", MySqlDbType.VarChar).Value = LoginField.Text;
cmd.Parameters.Add("@nomer", MySqlDbType.VarChar).Value = Nums.Text;
adapter.SelectCommand = cmd;
adapter.Fill(dataTable);
if(dataTable.Rows.Count > 0)
{
MessageBox.Show("Такой логин и номер уже есть, но вы можете продолжить.");
return false;
}
return true;
}
}
}