FrmImportSlideSelect.cs
3.29 KB
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace SunVoteARSPPT
{
public partial class FrmImportSlideSelect : Form
{
public FrmImportSlideSelect()
{
InitializeComponent();
}
private void FrmImportSlideSelect_Load(object sender, EventArgs e)
{
GlobalInfo.SysLanguage.SetLanguage(this.Name, this);
}
/// <summary>
/// 获取题目编号范围。若返回=null则为取消。若count=0则未选择。
/// 杨斌 2015-08-18
/// </summary>
/// <returns></returns>
public static List<int> GetNumRange()
{
List<int> res = null;
FrmImportSlideSelect frm = new FrmImportSlideSelect();
frm.ShowDialog();
if (frm.DialogResult == DialogResult.OK)
res = GetNumRange(frm.txtZone.Text);
return res;
}
/// <summary>
/// 从字符串表达式获取编号列表。如"1-3,5,7"={1,2,3,5,7}
/// 杨斌 2015-08-18
/// </summary>
/// <param name="range"></param>
/// <returns></returns>
public static List<int> GetNumRange(string range)
{
List<int> res = new List<int>();
if (string.IsNullOrEmpty(range))
return res;
string[] ary = range.Split(',');
if (ary.Length > 0)
{
foreach (var v in ary)
{
int num = 0;
string[] ary2 = v.Split('-');
if (ary2.Length > 1)
{
int nA = 0;
int nB = 0;
if (int.TryParse(ary2[0], out nA))
{
if (int.TryParse(ary2[1], out nB))
{
if ((nA > 0) && (nB > 0))
{
if (nA > nB)
{
num = nA;
nA = nB;
nB = num;
}
for (int i = nA; i <= nB; i++)
{
if (!res.Contains(i))
{
res.Add(i);
}
}
}
}
}
}
else
{
if (int.TryParse(v, out num))
{
if (num > 0)
{
if (!res.Contains(num))
{
res.Add(num);
}
}
}
}
}
}
return res;
}
}
}