source: BMXNET_RPMS_dotNET_UTILITIES-BMX/trunk/cs/bmx_0200scr/BMX2/BMXNet/BMXNetParameter.cs@ 1806

Last change on this file since 1806 was 815, checked in by Sam Habiel, 15 years ago

Initial commit of C# Source Code. Now to try to get it to compile.

File size: 3.0 KB
Line 
1using System;
2using System.Data;
3
4namespace IndianHealthService.BMXNet
5{
6 public class BMXNetParameter : IDataParameter
7 {
8 DbType m_dbType = DbType.Object;
9 ParameterDirection m_direction = ParameterDirection.Input;
10 bool m_fNullable = false;
11 bool m_fIsKey = false;
12 string m_sParamName;
13 string m_sSourceColumn;
14 DataRowVersion m_sourceVersion = DataRowVersion.Current;
15 object m_value;
16
17 public BMXNetParameter()
18 {
19 }
20
21 public BMXNetParameter(string parameterName, DbType type)
22 {
23 m_sParamName = parameterName;
24 m_dbType = type;
25 }
26
27 public BMXNetParameter(string parameterName, object value)
28 {
29 m_sParamName = parameterName;
30 this.Value = value;
31 // Setting the value also infers the type.
32 }
33
34 public BMXNetParameter( string parameterName, DbType dbType, string sourceColumn )
35 {
36 m_sParamName = parameterName;
37 m_dbType = dbType;
38 m_sSourceColumn = sourceColumn;
39 }
40
41 public DbType DbType
42 {
43 get { return m_dbType; }
44 set { m_dbType = value; }
45 }
46
47 public ParameterDirection Direction
48 {
49 get { return m_direction; }
50 set { m_direction = value; }
51 }
52
53 public Boolean IsKey
54 {
55 get { return m_fIsKey; }
56 set {m_fIsKey = value; }
57 }
58
59 public Boolean IsNullable
60 {
61 get { return m_fNullable; }
62 }
63
64 public String ParameterName
65 {
66 get { return m_sParamName; }
67 set { m_sParamName = value; }
68 }
69
70 public String SourceColumn
71 {
72 get { return m_sSourceColumn; }
73 set { m_sSourceColumn = value; }
74 }
75
76 public DataRowVersion SourceVersion
77 {
78 get { return m_sourceVersion; }
79 set { m_sourceVersion = value; }
80 }
81
82 public object Value
83 {
84 get
85 {
86 return m_value;
87 }
88 set
89 {
90 m_value = value;
91 m_dbType = _inferType(value);
92 }
93 }
94
95 private DbType _inferType(Object value)
96 {
97 switch (Type.GetTypeCode(value.GetType()))
98 {
99 case TypeCode.Empty:
100 throw new SystemException("Invalid data type");
101
102 case TypeCode.Object:
103 return DbType.Object;
104
105 case TypeCode.DBNull:
106 case TypeCode.Char:
107 case TypeCode.SByte:
108 case TypeCode.UInt16:
109 case TypeCode.UInt32:
110 case TypeCode.UInt64:
111 // Throw a SystemException for unsupported data types.
112 throw new SystemException("Invalid data type");
113
114 case TypeCode.Boolean:
115 return DbType.Boolean;
116
117 case TypeCode.Byte:
118 return DbType.Byte;
119
120 case TypeCode.Int16:
121 return DbType.Int16;
122
123 case TypeCode.Int32:
124 return DbType.Int32;
125
126 case TypeCode.Int64:
127 return DbType.Int64;
128
129 case TypeCode.Single:
130 return DbType.Single;
131
132 case TypeCode.Double:
133 return DbType.Double;
134
135 case TypeCode.Decimal:
136 return DbType.Decimal;
137
138 case TypeCode.DateTime:
139 return DbType.DateTime;
140
141 case TypeCode.String:
142 return DbType.String;
143
144 default:
145 throw new SystemException("Value is of unknown data type");
146 }
147 }
148 }
149}
Note: See TracBrowser for help on using the repository browser.