using System using System Collections Generic using System ComponentMo

  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
176
177
178
179
180
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;
using System.Data.SqlClient;
using MySql.Data.MySqlClient;
namespace MySQL_Sdelki
{
public partial class Userform : Form
{
private string connection = "datasource=localhost;" + "database=dogovors;" + "username=root;" + "password=31337;";
private MySQL q;
public Userform()
{
InitializeComponent();
q = new MySQL(connection);
foreach (var value in DogP.Controls.OfType<ComboBox>())
{
value.SelectedIndexChanged += cBoxIndexSelectedDog;
}
// foreach (var value in ExcursionPanel.Controls.OfType<ComboBox>())
// {
// value.SelectedIndexChanged += cBoxIndexSelectedExcursion;
// }
Dogs.Checked = true;
// cat.SelectedIndexChanged += cBoxIndexSelected;
}
private void button1_Click(object sender, EventArgs e)
{
string comand = "select adrs.str as Объект,dog as Название,opf.form as ОПФ_Стороны_№1, sides.side as Сторона_№1, t1.form as ОПФ_Стороны_№2, t2.side as Сторона_№2, ldate as Дата_окончания, cats.cat as Категория, t3.str as Место_хранения from dogs,sides,adrs,opf,cats inner join adrs as t3 inner join opf as t1 inner join sides as t2 where adrs.id_a=obj and opf.id_f=sides.id_f and t1.id_f=t2.id_f and sides.id_s=s1 and t2.id_s=s2 and id_cat=dogs.cat and t3.id_a=keep order by adrs.str;";
DataTable dt = new DataTable();
using (MySqlConnection con = new MySqlConnection())
{
con.ConnectionString = connection;
MySqlCommand com = new MySqlCommand(comand, con);
try
{
con.Open();
using (MySqlDataReader dr = com.ExecuteReader())
{
if (dr.HasRows)
{
dt.Load(dr);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
con.Close();
}
dataGridView1.DataSource = dt;
}
private void Back_Click(object sender, EventArgs e)
{
try
{
var startform = new Startform();
if (!startform.Created)
{
startform = new Startform();
}
startform.Show();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
this.Hide();
}
}
private void userformClosed(object sender, System.Windows.Forms.FormClosedEventArgs e)
{
Application.Exit();
}
private void Dogs_CheckedChanged(object sender, EventArgs e)
{
PerP.Visible = false;
DogP.Visible = true;
try
{
string getCat="select distinct(Cats.Cat) as Категория from Cats;";
cat.DataSource = q.getTable(getCat);
cat.DisplayMember = "Категория";
cat.SelectedIndex = -1;
string getObj = "select distinct(adrs.str) as Объект from adrs";
obj.DataSource = q.getTable(getObj);
obj.DisplayMember = "Объект";
obj.SelectedIndex = -1;
string gets1 = "select distinct(sides.side) as Сторона_№1 from sides,dogs where s1=id_s;";
s1.DataSource = q.getTable(gets1);
s1.DisplayMember = "Сторона_№1";
s1.SelectedIndex = -1;
string gets2 = "select distinct(sides.side) as Сторона_№2 from sides,dogs where s2=id_s;";
s2.DataSource = q.getTable(gets2);
s2.DisplayMember = "Сторона_№2";
s2.SelectedIndex = -1;
string getKeep = "select adrs.str as Место_хранения from adrs where id_a=1 or id_a=3";
Keep.DataSource = q.getTable(getKeep);
Keep.DisplayMember = "Место хранения";
Keep.SelectedIndex = -1;
string comand = "select adrs.str as Объект,dog as Название,opf.form as ОПФ_Стороны_№1, sides.side as Сторона_№1, t1.form as ОПФ_Стороны_№2, t2.side as Сторона_№2, ldate as Дата_окончания, cats.cat as Категория, t3.str as Место_хранения from dogs,sides,adrs,opf,cats inner join adrs as t3 inner join opf as t1 inner join sides as t2 where adrs.id_a=obj and opf.id_f=sides.id_f and t1.id_f=t2.id_f and sides.id_s=s1 and t2.id_s=s2 and id_cat=dogs.cat and t3.id_a=keep;";
dataGridView1.DataSource = q.getTable(comand);
}
catch (Exception ex)
{
MessageBox.Show("Something went wrong:" + ex.ToString());
}
}
private void Pers_CheckedChanged(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
private void Cancel_Click(object sender, EventArgs e)
{
cat.SelectedIndex = -1;
s1.SelectedIndex = -1;
s2.SelectedIndex = -1;
obj.SelectedIndex = -1;
Keep.SelectedIndex = -1;
string com = "select adrs.str as Объект,dog as Название,opf.form as ОПФ_Стороны_№1, sides.side as Сторона_№1, t1.form as ОПФ_Стороны_№2, t2.side as Сторона_№2, ldate as Дата_окончания, cats.cat as Категория, t3.str as Место_хранения from dogs,sides,adrs,opf,cats inner join adrs as t3 inner join opf as t1 inner join sides as t2 where adrs.id_a=obj and opf.id_f=sides.id_f and t1.id_f=t2.id_f and sides.id_s=s1 and t2.id_s=s2 and id_cat=dogs.cat and t3.id_a=keep;";
dataGridView1.DataSource = q.getTable(com); //отображаем таблицу заново
}
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
string s = dateTimePicker1.Value.Date.ToString("yyyy-MM-dd");
dataGridView1.DataSource = q.getTable("call getDate('" + s + "');");
}
private void cBoxIndexSelectedDog(object sender, EventArgs e)
{
try
{
List<string> mas = new List<string>();
foreach (var sBox in DogP.Controls.OfType<ComboBox>())
mas.Add(sBox.Text);
mas[0] = mas[0] != "" ? "and Cats.cat= '" + mas[0] + "'" : mas[0];
mas[1] = mas[1] != "" ? "and adrs.str= '" + mas[1] + "'" : mas[1];
mas[2] = mas[2] != "" ? "and sides.side= '" + mas[2] + "'" : mas[2];
mas[3] = mas[3] != "" ? "and sides.side= '" + mas[3] + "'" : mas[3];
mas[4] = mas[4] != "" ? "and adrs.str= '" + mas[4] + "'" : mas[4];
string com = "select adrs.str as Объект,dog as Название,opf.form as ОПФ_Стороны_№1, sides.side as Сторона_№1, t1.form as ОПФ_Стороны_№2, t2.side as Сторона_№2, ldate as Дата_окончания, cats.cat as Категория, t3.str as Место_хранения from dogs,sides,adrs,opf,cats inner join adrs as t3 inner join opf as t1 inner join sides as t2 where adrs.id_a=obj and opf.id_f=sides.id_f and t1.id_f=t2.id_f and sides.id_s=s1 and t2.id_s=s2 and id_cat=dogs.cat and t3.id_a=keep "+mas[0] + mas[1] + mas[2] + mas[3] + mas[4] + ";";
dataGridView1.DataSource = q.getTable(com);
mas.Clear();
}
catch (Exception ex)
{
MessageBox.Show("Something went wrong:\n" + ex.ToString());
}
}
}
}