dataGridView1 ColumnHeaderMouseCli ck obj evnt if Dogs Checked comsort

 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
dataGridView1.ColumnHeaderMouseClick += (obj, evnt) =>
{
if (Dogs.Checked)
comsort = "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.name 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_opf=sides.id_f and t1.id_opf=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 ";
else
comsort = "select per as ФИО,form as ОПФ,side as Сторона, phone as Телефон,mail as e_mail from pers,sides,opf where pers.id_st=sides.id_s and opf.id_opf=sides.id_f order by ";
_stack.Push(evnt.ColumnIndex);
int columns = dataGridView1.Columns.Count;
int[] array = _stack.Distinct().ToArray();
string sort = null;
if (array.Length == 1)
{
int i = array[0];
comsort += dataGridView1.Columns[i].HeaderText;
DataGridViewColumn gridViewColumn = dataGridView1.Columns[i];
switch (gridViewColumn.HeaderCell.SortGlyphDirection)
{
case System.Windows.Forms.SortOrder.None:
case System.Windows.Forms.SortOrder.Ascending:
sort = " ASC";
break;
case System.Windows.Forms.SortOrder.Descending:
sort = " DESC";
break;
default:
throw new ArgumentOutOfRangeException();
}
comsort += sort;
}
else
for (int index = array.Length - 1; index >= 0; index--)
{
int i = array[index];
string sql = dataGridView1.Columns[i].HeaderText;
if (index >= columns)
{
break;
}
DataGridViewColumn gridViewColumn = dataGridView1.Columns[i];
switch (gridViewColumn.HeaderCell.SortGlyphDirection)
{
case System.Windows.Forms.SortOrder.None:
case System.Windows.Forms.SortOrder.Ascending:
sort = " ASC";
break;
case System.Windows.Forms.SortOrder.Descending:
sort = " DESC";
break;
default:
throw new ArgumentOutOfRangeException();
}
if (index == 0)
comsort += sql + sort;
else
comsort += sql + sort + ",";
};
comsort += ";";
dataGridView1.DataSource = q.getTable(comsort);
};