-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ticket.cs
175 lines (159 loc) · 7.15 KB
/
Ticket.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
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Theater
{
public partial class Ticket : Form
{
public Ticket()
{
InitializeComponent();
}
public Tickets fTickets;
public String ID;
private void dataLoad()
{
SqlServerFull _sqlServerSpectacle = new SqlServerFull();
DataSet _dataSetSpectacle = new DataSet();
_sqlServerSpectacle.SelectSqlCommand = "SELECT * FROM spectacle";
if (_sqlServerSpectacle.ExecuteFill(_dataSetSpectacle, "spectacle"))
{
comboBox1.DataSource = _dataSetSpectacle.Tables["spectacle"];
comboBox1.DisplayMember = "spectacle_id";
}
else MessageBox.Show("Произошла ошибка загрузки данных о спектаклях.");
SqlServerFull _sqlServerPlaces = new SqlServerFull();
DataSet _dataSetPlaces = new DataSet();
_sqlServerPlaces.SelectSqlCommand = "SELECT * FROM places";
if (_sqlServerPlaces.ExecuteFill(_dataSetPlaces, "places"))
{
comboBox2.DataSource = _dataSetPlaces.Tables["places"];
comboBox2.DisplayMember = "places_id";
}
else MessageBox.Show("Произошла ошибка загрузки данных о местах.");
if (this.Text == "Изменить билет.")
{
SqlServerFull _sqlServerTicket = new SqlServerFull();
DataSet _dataSetTicket = new DataSet();
_sqlServerTicket.SelectSqlCommand = "SELECT * FROM ticket WHERE (ticket_id = " + ID.ToString() + ")";
if (_sqlServerTicket.ExecuteFill(_dataSetTicket, "ticket"))
{
comboBox1.Text = _dataSetTicket.Tables["ticket"].Rows[0]["ticket_spectacle"].ToString();
comboBox2.Text = _dataSetTicket.Tables["ticket"].Rows[0]["ticket_place"].ToString();
comboBox3.Text = _dataSetTicket.Tables["ticket"].Rows[0]["ticket_order"].ToString();
comboBox4.Text = _dataSetTicket.Tables["ticket"].Rows[0]["ticket_subscription"].ToString();
}
else MessageBox.Show("Произошла ошибка открытия данных о выбраном билете.");
}
}
private void dataSave()
{
if (this.Text == "Создать билет.")
{
SqlServerShort _sqlServerShort = new SqlServerShort();
_sqlServerShort.SqlCommand = "INSERT INTO ticket (ticket_spectacle, ticket_place, ticket_order, ticket_subscription) "+
"VALUES (" + comboBox1.Text + ", " + comboBox2.Text + ", " + comboBox3.Text + ", " + comboBox4.Text + ")";
if (_sqlServerShort.ExecuteNonQuery())
{
try
{
fTickets.TableUpdate();
this.Close();
}
catch
{
this.Close();
}
}
else MessageBox.Show("Произошла ошибка сохранения новых данных.");
}
if (this.Text == "Изменить билет.")
{
SqlServerShort _sqlServerShort = new SqlServerShort();
_sqlServerShort.SqlCommand = "UPDATE ticket SET ticket_spectacle = " + comboBox1.Text +
", ticket_place = " + comboBox2.Text +
", ticket_order = " + comboBox3.Text +
", ticket_subscription = " + comboBox4.Text +
" WHERE (ticket_id = " + ID.ToString() + ")";
if (_sqlServerShort.ExecuteNonQuery())
{
try
{
fTickets.TableUpdate();
this.Close();
}
catch
{
this.Close();
}
}
else MessageBox.Show("Произошла ошибка сохранения изменённых данных.");
}
}
private void Ticket_Load(object sender, EventArgs e)
{
dataLoad();
}
private void button2_Click(object sender, EventArgs e)
{
Close();
}
private void button1_Click(object sender, EventArgs e)
{
dataSave();
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox1.Text != "System.Data.DataRowView")
{
SqlServerFull _sqlServerSpectacle = new SqlServerFull();
DataSet _dataSetSpectacle = new DataSet();
_sqlServerSpectacle.SelectSqlCommand = "SELECT * FROM spectacle WHERE (spectacle_id = " + comboBox1.Text + ")";
if (_sqlServerSpectacle.ExecuteFill(_dataSetSpectacle, "spectacle"))
{
label2.Text = "(" + _dataSetSpectacle.Tables["spectacle"].Rows[0]["spectacle_name"].ToString() + ")";
}
else MessageBox.Show("Произошла ошибка загрузки данных о спектаклях.");
}
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox2.Text != "System.Data.DataRowView")
{
SqlServerFull _sqlServerPlaces = new SqlServerFull();
DataSet _dataSetPlaces = new DataSet();
_sqlServerPlaces.SelectSqlCommand = "SELECT * FROM places WHERE (places_id = " + comboBox2.Text + ")";
if (_sqlServerPlaces.ExecuteFill(_dataSetPlaces, "places"))
{
label4.Text = "(Ряд: " + _dataSetPlaces.Tables["places"].Rows[0]["places_series"].ToString() +
" Место: " + _dataSetPlaces.Tables["places"].Rows[0]["places_place"].ToString() +
" Цена: " + _dataSetPlaces.Tables["places"].Rows[0]["places_price"].ToString() + ")";
}
else MessageBox.Show("Произошла ошибка загрузки данных о местах.");
}
}
private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox3.Text != "System.Data.DataRowView")
{
if (comboBox3.Text == "0")
label6.Text = "(нет)";
else label6.Text = "(да)";
}
}
private void comboBox4_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox4.Text != "System.Data.DataRowView")
{
if (comboBox4.Text == "0")
label8.Text = "(нет)";
else label8.Text = "(да)";
}
}
}
}