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
115
116
117
| public partial class Form1 : Form
{
SqlConnection SqlConnection;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
const string V = @"Data Source= BAZA";
string BAZA = V;
SqlConnection = new
SqlConnection(BAZA);
SqlConnection.Open();
listBox1.Items.Clear();
SqlDataReader SqlReader = null;
SqlCommand command = new SqlCommand("SELECT * From [med_pokaz]", SqlConnection);
try
{
SqlReader = command.ExecuteReader();
while (SqlReader.Read())
{
listBox1.Items.Add(" Код МКХ: " + Convert.ToString(SqlReader["mkh"]) + " Розділ: " + Convert.ToString(SqlReader["rozdil"]) + " Пункт:" + Convert.ToString(SqlReader["punkt"]) + " Підпункт" + Convert.ToString(SqlReader["pidpunkt"]) );
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString(), ex.Source.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
if (SqlReader != null)
SqlReader.Close();
}
}
private void button1_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(mkh.Text) &&
!string.IsNullOrEmpty(rozdil.Text) &&
!string.IsNullOrEmpty(punkt.Text) &&
!string.IsNullOrEmpty(pidpunkt.Text))
{
SqlCommand command = new SqlCommand("INSERT INTO [med_pokaz] (mkh, rozdil, punkt, pidpunkt)Values(@mkh, @rozdil, @punkt , @pidpunkt)", SqlConnection);
command.Parameters.AddWithValue("mkh", mkh.Text);
command.Parameters.AddWithValue("rozdil", rozdil.Text);
command.Parameters.AddWithValue("punkt", punkt.Text);
command.Parameters.AddWithValue("pidpunkt", pidpunkt.Text);
command.ExecuteNonQuery();
listBox1.Items.Clear();
SqlDataReader SqlReader = null;
SqlCommand comand = new SqlCommand("SELECT * From [med_pokaz]", SqlConnection);
try
{
SqlReader = comand.ExecuteReader();
while (SqlReader.Read())
{
listBox1.Items.Add(" Код МКХ: "+Convert.ToString(SqlReader["mkh"]) + " Розділ: " + Convert.ToString(SqlReader["rozdil"]) + " Пункт: " + Convert.ToString(SqlReader["punkt"]) + " Підпункт: " + Convert.ToString(SqlReader["pidpunkt"]));
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString(), ex.Source.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
if (SqlReader != null)
SqlReader.Close();
}
}
else
{
label1.Visible = true;
label1.Text = "Поля не заполнены";
}
mkh.Clear();
rozdil.Clear();
punkt.Clear();
pidpunkt.Clear();
}
private void label2_Click(object sender, EventArgs e)
{
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (MessageBox.Show(this, "Ви бажаєте закрити додаток?", "Закрыть додаток", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
e.Cancel = true;
}
else
{
//close app code
}
}
private void label1_Click(object sender, EventArgs e)
{
}
private void List_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
} |