1
|
|
#region Copyright
|
2
|
|
|
3
|
|
|
4
|
|
|
5
|
|
|
6
|
|
|
7
|
|
|
8
|
|
|
9
|
|
|
10
|
|
|
11
|
|
|
12
|
|
|
13
|
|
|
14
|
|
|
15
|
|
|
16
|
|
|
17
|
|
#endregion
|
18
|
|
|
19
|
|
using System;
|
20
|
|
using System.Collections;
|
21
|
|
using System.Data;
|
22
|
|
using Seasar.Extension.ADO;
|
23
|
|
|
24
|
|
namespace Seasar.Framework.Util
|
25
|
|
{
|
26
|
|
public sealed class DataTableUtil
|
27
|
|
{
|
28
|
0
|
private DataTableUtil()
|
29
|
|
{
|
30
|
|
}
|
31
|
|
|
32
|
34
|
public static bool IsPrimaryKey(DataTable table, DataColumn column)
|
33
|
|
{
|
34
|
34
|
return Array.IndexOf(table.PrimaryKey, column) != -1;
|
35
|
|
}
|
36
|
|
|
37
|
7
|
public static void SetupMetaData(IDatabaseMetaData dbMetaData, DataTable table)
|
38
|
|
{
|
39
|
7
|
IList primaryKeySet = dbMetaData.GetPrimaryKeySet(table.TableName);
|
40
|
7
|
IList columnSet = dbMetaData.GetColumnSet(table.TableName);
|
41
|
7
|
ArrayList primaryKeyList = new ArrayList();
|
42
|
7
|
foreach (DataColumn column in table.Columns)
|
43
|
|
{
|
44
|
17
|
if (primaryKeySet.Contains(column.ColumnName))
|
45
|
|
{
|
46
|
7
|
primaryKeyList.Add(column);
|
47
|
|
}
|
48
|
|
|
49
|
17
|
if (columnSet.Contains(column.ColumnName))
|
50
|
|
{
|
51
|
14
|
column.ReadOnly = false;
|
52
|
|
}
|
53
|
|
else
|
54
|
|
{
|
55
|
3
|
column.ReadOnly = true;
|
56
|
|
}
|
57
|
|
}
|
58
|
|
|
59
|
7
|
table.BeginLoadData();
|
60
|
7
|
table.PrimaryKey = (DataColumn[]) primaryKeyList.ToArray(typeof(DataColumn));
|
61
|
7
|
table.EndLoadData();
|
62
|
|
}
|
63
|
|
|
64
|
26
|
public static DataColumn GetColumn(DataTable table, string columnName)
|
65
|
|
{
|
66
|
26
|
DataColumn column = table.Columns[columnName];
|
67
|
26
|
if (column == null)
|
68
|
|
{
|
69
|
2
|
string name = columnName.Replace("_", "");
|
70
|
2
|
column = table.Columns[name];
|
71
|
|
}
|
72
|
26
|
return column;
|
73
|
|
}
|
74
|
|
}
|
75
|
|
}
|
76
|
|
|