-
Notifications
You must be signed in to change notification settings - Fork 0
/
ByCenter.cs
103 lines (95 loc) · 3.33 KB
/
ByCenter.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
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;
using MySql.Data.MySqlClient;
namespace OCC
{
public partial class ByCenter : Form
{
public ByCenter()
{
InitializeComponent();
}
private void fillCenterType()
{
if (cmbtype.Items.Count > 0)
cmbtype.Items.Clear();
if (cmbname.Items.Count > 0)
cmbname.Items.Clear();
var connectionString = DbConnect.conString;
using (var connection = new MySqlConnection(connectionString))
{
connection.Open();
var query = "SELECT CenterType FROM centerType";
cmbtype.Items.Add("--CENTER TYPE--");
cmbname.Items.Add("--CENTER NAME--");
using (var command = new MySqlCommand(query, connection))
{
using (var reader = command.ExecuteReader())
{
//Iterate through the rows and add it to the combobox's items
while (reader.Read())
{
string name = reader.GetString("CenterType");
if (!cmbtype.Items.Contains(name))
cmbtype.Items.Add(name);
}
}
}
cmbtype.SelectedIndex = 0;
cmbname.SelectedIndex = 0;
}
}
private void fillCenterName()
{
if (cmbname.Items.Count > 0)
cmbname.Items.Clear();
var connectionString = DbConnect.conString;
using (var connection = new MySqlConnection(connectionString))
{
connection.Open();
var query = "SELECT CenterName FROM Centers WHERE CenterType='" + cmbtype.Text + "'";
cmbname.Items.Add("--CENTER NAME--");
using (var command = new MySqlCommand(query, connection))
{
using (var reader = command.ExecuteReader())
{
//Iterate through the rows and add it to the combobox's items
while (reader.Read())
{
string name = reader.GetString("CenterName");
if (!cmbname.Items.Contains(name))
cmbname.Items.Add(name);
}
}
}
cmbname.SelectedIndex = 0;
}
}
private void cmbtype_SelectedIndexChanged(object sender, EventArgs e)
{
if (cmbtype.SelectedIndex != 0)
fillCenterName();
}
private void ByCenter_Load(object sender, EventArgs e)
{
fillCenterType();
}
private void cmbname_SelectedIndexChanged(object sender, EventArgs e)
{
}
public string getQuery()
{
return cmbtype.Text + ":" + cmbname.Text;
}
private void button1_Click(object sender, EventArgs e)
{
this.Hide();
}
}
}