A group code about sort after move.
These codes is to introduce some item sort after any selected items move to one perticular item.
For example: move the 1th,3th,8th,10th line to the 5th line.
1
using System;
2
using System.Data;
3
using System.Configuration;
4
using System.Web;
5
using System.Web.Security;
6
using System.Web.UI;
7
using System.Web.UI.WebControls;
8
using System.Web.UI.WebControls.WebParts;
9
using System.Web.UI.HtmlControls;
10![]()
11
/// <summary>
12
/// Summary description for Sort
13
/// </summary>
14
public class Sort
15
{
16
public DataSet SortFunction()
17
{
18
DataSet dataSet = CreateDataSet();
19![]()
20
string[] CheckedArray = GetChecked().Split(',');
21
int MovePos = Convert.ToInt32(GetMovePos());
22
int LessInfo = 0;
23
int GrateInfo = 1;
24![]()
25
for (int i = 0; i < dataSet.Tables[0].Rows.Count; i++)
26
{
27
if (IsChecked((i+1).ToString(), CheckedArray))
28
{
29
if ((i+1) < MovePos)
30
{
31
dataSet.Tables[0].Rows[i]["Sequence"] = MovePos+1 - GetLessCount(MovePos.ToString(), CheckedArray) + LessInfo;
32
LessInfo++;
33
}
34
else if ((i + 1) == MovePos)
35
{
36![]()
37
}
38
else
39
{
40
dataSet.Tables[0].Rows[i]["Sequence"] = MovePos + GrateInfo;
41
GrateInfo++;
42
}
43
}
44
else
45
{
46
if ((i+1) < MovePos)
47
{
48
dataSet.Tables[0].Rows[i]["Sequence"] = Convert.ToInt32(dataSet.Tables[0].Rows[i]["Sequence"].ToString())
49
- GetLessCount((i+1).ToString(), CheckedArray);
50
}
51
else if ((i + 1) == MovePos)
52
{
53
//dataSet.Tables[0].Rows[i]["Sequence"] = MovePos - GetLessCount(((int)(i + 1)).ToString(), CheckedArray);
54
}
55
else
56
{
57
dataSet.Tables[0].Rows[i]["Sequence"] = Convert.ToInt32(dataSet.Tables[0].Rows[i]["Sequence"].ToString())
58
+ GetGreateCount(MovePos.ToString(), CheckedArray) - GetLessCount((i + 1).ToString(),MovePos.ToString(), CheckedArray);
59
}
60
}
61
}
62
return dataSet;
63
}
64
private DataSet CreateDataSet()
65
{
66
DataSet dataSet = new DataSet();
67
dataSet.Tables.Add();
68
dataSet.Tables[0].Columns.Add("Text");
69
dataSet.Tables[0].Columns.Add("Sequence");
70![]()
71
for (int i = 0; i < 10; i++)
72
{
73
DataRow dataRow = dataSet.Tables[0].NewRow();
74
dataRow["Text"] = i+1;
75
dataRow["Sequence"] = i+1;
76
dataSet.Tables[0].Rows.Add(dataRow);
77
}
78
return dataSet;
79
}
80
private string GetChecked()
81
{
82
string Checked = "1,3,8,10";
83
return Checked;
84
}
85
private string GetMovePos()
86
{
87
string MovePos = "5";
88
return MovePos;
89
}
90
private bool IsChecked(string value, string[] array)
91
{
92
bool Checked = true;
93
for (int i = 0; i < array.Length; i++)
94
{
95
if (array[i] == value)
96
{
97
return Checked;
98
}
99
}
100
Checked = false;
101
return Checked;
102
}
103
private int GetGreateCount(string value, string[] array)
104
{
105
int count = 0;
106
for (int i = 0; i < array.Length; i++)
107
{
108
if (Convert.ToInt32(array[i]) > Convert.ToInt32(value))
109
{
110
count++;
111
}
112
}
113
return count;
114
}
115
private int GetLessCount(string value, string[] array)
116
{
117
int count = 0;
118
for (int i = 0; i < array.Length; i++)
119
{
120
if (Convert.ToInt32(array[i]) <= Convert.ToInt32(value))
121
{
122
count++;
123
}
124
}
125
return count;
126
}
127
private int GetLessCount(string MaxValue, string MinValue,string[] array)
128
{
129
int count = 0;
130
for (int i = 0; i < array.Length; i++)
131
{
132
if (Convert.ToInt32(array[i]) < Convert.ToInt32(MaxValue) && Convert.ToInt32(array[i]) > Convert.ToInt32(MinValue))
133
{
134
count++;
135
}
136
}
137
return count;
138
}
139![]()
140
}
141![]()
using System;2
using System.Data;3
using System.Configuration;4
using System.Web;5
using System.Web.Security;6
using System.Web.UI;7
using System.Web.UI.WebControls;8
using System.Web.UI.WebControls.WebParts;9
using System.Web.UI.HtmlControls;10

11
/// <summary>12
/// Summary description for Sort13
/// </summary>14
public class Sort15
{16
public DataSet SortFunction()17
{18
DataSet dataSet = CreateDataSet();19

20
string[] CheckedArray = GetChecked().Split(',');21
int MovePos = Convert.ToInt32(GetMovePos());22
int LessInfo = 0;23
int GrateInfo = 1;24

25
for (int i = 0; i < dataSet.Tables[0].Rows.Count; i++)26
{27
if (IsChecked((i+1).ToString(), CheckedArray))28
{29
if ((i+1) < MovePos)30
{31
dataSet.Tables[0].Rows[i]["Sequence"] = MovePos+1 - GetLessCount(MovePos.ToString(), CheckedArray) + LessInfo;32
LessInfo++;33
}34
else if ((i + 1) == MovePos)35
{36

37
}38
else39
{40
dataSet.Tables[0].Rows[i]["Sequence"] = MovePos + GrateInfo;41
GrateInfo++; 42
}43
}44
else45
{46
if ((i+1) < MovePos)47
{48
dataSet.Tables[0].Rows[i]["Sequence"] = Convert.ToInt32(dataSet.Tables[0].Rows[i]["Sequence"].ToString()) 49
- GetLessCount((i+1).ToString(), CheckedArray);50
}51
else if ((i + 1) == MovePos)52
{53
//dataSet.Tables[0].Rows[i]["Sequence"] = MovePos - GetLessCount(((int)(i + 1)).ToString(), CheckedArray);54
}55
else56
{57
dataSet.Tables[0].Rows[i]["Sequence"] = Convert.ToInt32(dataSet.Tables[0].Rows[i]["Sequence"].ToString())58
+ GetGreateCount(MovePos.ToString(), CheckedArray) - GetLessCount((i + 1).ToString(),MovePos.ToString(), CheckedArray); 59
}60
}61
}62
return dataSet;63
}64
private DataSet CreateDataSet()65
{66
DataSet dataSet = new DataSet();67
dataSet.Tables.Add();68
dataSet.Tables[0].Columns.Add("Text");69
dataSet.Tables[0].Columns.Add("Sequence");70

71
for (int i = 0; i < 10; i++)72
{73
DataRow dataRow = dataSet.Tables[0].NewRow();74
dataRow["Text"] = i+1;75
dataRow["Sequence"] = i+1;76
dataSet.Tables[0].Rows.Add(dataRow);77
}78
return dataSet;79
}80
private string GetChecked()81
{82
string Checked = "1,3,8,10";83
return Checked;84
}85
private string GetMovePos()86
{87
string MovePos = "5";88
return MovePos;89
}90
private bool IsChecked(string value, string[] array)91
{92
bool Checked = true;93
for (int i = 0; i < array.Length; i++)94
{95
if (array[i] == value)96
{97
return Checked;98
}99
}100
Checked = false;101
return Checked;102
}103
private int GetGreateCount(string value, string[] array)104
{105
int count = 0;106
for (int i = 0; i < array.Length; i++)107
{108
if (Convert.ToInt32(array[i]) > Convert.ToInt32(value))109
{110
count++;111
}112
}113
return count;114
}115
private int GetLessCount(string value, string[] array)116
{117
int count = 0;118
for (int i = 0; i < array.Length; i++)119
{120
if (Convert.ToInt32(array[i]) <= Convert.ToInt32(value))121
{122
count++;123
}124
}125
return count;126
}127
private int GetLessCount(string MaxValue, string MinValue,string[] array)128
{129
int count = 0;130
for (int i = 0; i < array.Length; i++)131
{132
if (Convert.ToInt32(array[i]) < Convert.ToInt32(MaxValue) && Convert.ToInt32(array[i]) > Convert.ToInt32(MinValue))133
{134
count++;135
}136
}137
return count;138
}139

140
}141



浙公网安备 33010602011771号