-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTable.cs
More file actions
272 lines (240 loc) · 7.57 KB
/
Table.cs
File metadata and controls
272 lines (240 loc) · 7.57 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
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
//
// Copyright 2010 Thaddeus L Ryker
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Dynamics Nav is a registered trademark of the Microsoft Corporation
//
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Runtime.InteropServices;
using Org.Edgerunner.Dynamics.Nav.CSide.Exceptions;
using Org.Edgerunner.Dynamics.Nav.CSide.Interfaces;
namespace Org.Edgerunner.Dynamics.Nav.CSide
{
/// <summary>
/// Represents a table in a Dynamics Nav client instance.
/// </summary>
public class Table : IDisposable
{
#region Non-Public Fields (4)
private string _Name;
private Int32 _TableID;
internal Client _Client;
internal INSTable _Table;
#endregion Non-Public Fields
#region Properties (4)
/// <summary>
/// Gets and sets the culture to use for the table
/// </summary>
public CultureInfo Culture { get; set; }
/// <summary>
/// Gets the fields.
/// </summary>
/// <value>The fields.</value>
public Dictionary<Int32, Field> Fields
{
get
{
FetchBackingTableIfNeeded();
CallbackEnumerator cbEnum = new CallbackEnumerator(this);
_Table.EnumFields(cbEnum, Culture.LCID);
return cbEnum.Fields;
}
}
/// <summary>
/// Gets the filters.
/// </summary>
/// <value>The filters.</value>
public Dictionary<Int32, Filter> Filters
{
get
{
FetchBackingTableIfNeeded();
CallbackEnumerator cbEnum = new CallbackEnumerator(this);
_Table.EnumFilters(cbEnum);
return cbEnum.Filters;
}
}
/// <summary>
/// Gets the name.
/// </summary>
/// <value>The name.</value>
public string Name
{
get { return _Name; }
}
/// <summary>
/// Gets the table ID.
/// </summary>
/// <value>The table ID.</value>
public Int32 TableID
{
get { return _TableID; }
}
#endregion Properties
#region Constructors/Deconstructors (2)
/// <summary>
/// Initializes a new instance of the Table class.
/// </summary>
/// <param name="tableNo"></param>
/// <param name="name"></param>
/// <param name="client"></param>
public Table(Int32 tableNo, string name, Client client)
{
Culture = CultureInfo.CurrentCulture;
_Name = name;
_Client = client;
_TableID = tableNo;
}
/// <summary>
/// Releases unmanaged resources and performs other cleanup operations before the
/// <see cref="Table"/> is reclaimed by garbage collection.
/// </summary>
~Table()
{
Dispose(false);
}
#endregion Constructors/Deconstructors
#region Methods (7)
// Private Methods (1)
/// <summary>
/// Fetches the backing table if needed.
/// </summary>
private void FetchBackingTableIfNeeded()
{
if (_Table == null)
_Table = _Client.GetTableInternal(TableID);
}
// Internal Methods (1)
/// <summary>
/// Sets the backing table.
/// </summary>
/// <param name="table">The table.</param>
internal void SetBackingTable(INSTable table)
{
_Table = table;
}
// Public Methods (5)
/// <summary>
/// Deletes the record.
/// </summary>
/// <param name="record">The record.</param>
public void DeleteRecord(Record record)
{
FetchBackingTableIfNeeded();
_Table.Delete(record._Record);
}
/// <summary>
/// Initializes the record.
/// </summary>
/// <param name="record">The record.</param>
public void InitRecord(Record record)
{
FetchBackingTableIfNeeded();
_Table.Init(out record._Record);
}
/// <summary>
/// Inserts the record.
/// </summary>
/// <param name="record">The record.</param>
public void InsertRecord(Record record)
{
FetchBackingTableIfNeeded();
_Table.Insert(record._Record);
}
/// <summary>
/// Modifies the record.
/// </summary>
/// <param name="record">The record.</param>
public void ModifyRecord(Record record)
{
FetchBackingTableIfNeeded();
_Table.Modify(record._Record);
}
/// <summary>
/// Sets the filter.
/// </summary>
/// <param name="fieldNo">The field no.</param>
/// <param name="filterValue">The filter value.</param>
public void SetFilter(Int32 fieldNo, string filterValue)
{
FetchBackingTableIfNeeded();
int result = _Table.SetFilter(fieldNo, filterValue);
if (result != 0)
throw CSideException.GetException(result);
}
/// <summary>
/// Finds the specified record.
/// </summary>
/// <param name="record">The record.</param>
public void Find(Record record)
{
int result = _Table.Find(record._Record);
if (result != 0)
throw CSideException.GetException(result);
}
/// <summary>
/// Fetches the records in this instance.
/// </summary>
/// <returns></returns>
public List<Record> FetchRecords()
{
FetchBackingTableIfNeeded();
CallbackEnumerator cbEnum = new CallbackEnumerator(this);
_Table.EnumRecords(cbEnum);
return cbEnum.Records;
}
/// <summary>
/// The purpose of this method is unknown. Hopefully someone will discover and document it.
/// </summary>
/// <returns>Unknown</returns>
public int Proc13()
{
lock (_Client.GetSyncObject())
{
int value;
int result = _Table.Proc13(out value);
if (result != 0)
throw CSideException.GetException(result);
return value;
}
}
#endregion Methods
#region IDisposable Members
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
/// <summary>
/// Releases unmanaged and - optionally - managed resources
/// </summary>
/// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
// no managed resources to free
}
// free unmanaged resources
if (_Table != null)
Marshal.ReleaseComObject(_Table);
}
#endregion
}
}