List int sortList new List int dataGridView1 ColumnHeaderMouseCli ck o

 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
List<int> sortList = new List<int>();
dataGridView1.ColumnHeaderMouseClick += (obj, evnt) => // это пишется в public Form1()
{
_stack.Push(evnt.ColumnIndex);
string comsort = radioButton2.Checked ? "select exhibits.name as Произведение, hall.name as Зал, join_date as Поступление, authors.name as Имя, authors.secondName as Фамилия, authors.patronomyc as Отчество, material.name as Материал, technique.name as Техника from exhibits, hall, material, authors, technique where author = authors.id and hall_id = hall.id and material = material.id and tech = technique.id order by " : "select graphic as График, st_time as Время, start as Начало, end as Конец, cost as Цена, personal.name as Имя, personal.secondName as Фамилия, personal.patronomyc as Отчество, personal.post as Должность from excursion, personal where personal.id = ic order by ";
sortList.Add(evnt.ColumnIndex);
int columns = dataGridView1.Columns.Count;
int[] array = _stack.Distinct().ToArray();
string result_sort = null;
for (int index = array.Length - 1; index >= 0; index--)
{
string sort = " asc";
int i = array[index];
string sql = dataGridView1.Columns[i].HeaderText;
if (index >= columns)
{
break;
}
int tmp = 0;
for (int j = 0; j < sortList.Count; j++)
if (sortList[j] == dataGridView1.Columns[i].Index)
tmp++;
if (tmp % 2 == 0 && tmp != 0)
sort = " desc";
if (index == 0)
{
comsort += sql + sort;
result_sort += sql + sort;
}
else
{
comsort += sql + sort + ",";
result_sort += sql + sort + ", ";
}
}
comsort += ";";
Console.WriteLine(result_sort);
dataGridView1.DataSource = querry.getTable(comsort);
};