AOIManager.cs
2.4 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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using TSA_V.Common;
namespace TSA_V
{
class AOIManager
{
public static List<string> FileList = new List<string>();
public static void LoadAOIFile(ComboBox cmbAoiFile,string DefaultName="")
{
try
{
//cmbAoiFile.Items.Clear();
FileList = new List<string>();
string appPath = Application.StartupPath;
string pathName = ConfigAppSettings.GetValue(Setting_Init.AOIFileConfig);
string filePath = appPath + pathName;
string path = Path.GetDirectoryName(filePath);
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
LogUtil.error("加载AOIFile时,创建路径:"+path);
}
// string suffix = Path.GetExtension(filePath);
string suffix = ".data";
string[] files = Directory.GetFiles(path);
foreach (string f in files)
{
if (Path.GetExtension(f).Equals(suffix))
{
string fileName = Path.GetFileName(f);
FileList.Add(fileName);
// cmbAoiFile.Items.Add(fileName);
}
}
if (String.IsNullOrEmpty(DefaultName).Equals(false)&& FileList.Contains(DefaultName))
{
FileList.Remove(DefaultName);
FileList.Insert(0, DefaultName);
}
cmbAoiFile.DataSource = null;
cmbAoiFile.DataSource = FileList;
//if (FileList.Count > 0)
//{
// cmbAoiFile.SelectedIndex = 0;
//}
int index = AOIManager.FileList.IndexOf(DefaultName);
if (index >= 0)
{
cmbAoiFile.SelectedIndex = index;
}
//else
//{
// cmbAoiFile.SelectedIndex = 0;
//}
}
catch (Exception ex)
{
LogUtil.error("加载出错:" + ex.ToString());
}
}
}
}