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![]()

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
