123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Data.OleDb;
- using Tofly.Data.General;
- using System.Data.Common;
- namespace Tofly.Data.ADO
- {
-
-
-
- public class AdoDataReader : IDataReader
- {
- private DbDataReader pReader;
- private IRow pRow;
- private IWorkspace workspace = null;
- public AdoDataReader(DbDataReader pReader,IWorkspace workspace)
- {
- if (pReader == null)
- throw new Exception();
- if (workspace == null)
- throw new Exception();
- this.pReader = pReader;
- this.workspace = workspace;
- }
-
-
-
- public IRow Row
- {
- get
- {
- return pRow;
- }
- }
-
-
-
-
- public bool Read()
- {
- if (pReader.Read())
- {
- pRow = new RowBase();
- Dictionary<string, object> oValue = new Dictionary<string, object>();
- Type type;
- object temp = null;
- for (int i = 0; i < pReader.FieldCount; i++)
- {
- type = pReader.GetFieldType(i);
- string sss = pReader.GetName(i);
- if (type == typeof(System.DateTime) && workspace.WorkspaceType == WorkspaceType.SqlLite)
- {
- temp = null;
- if (!pReader.IsDBNull(i))
- {
- temp = pReader.GetString(i);
- DateTime time;
- bool success = DateTime.TryParse(temp.ToString(), out time);
- if (success)
- temp = time;
- else
- temp = null;
- }
- oValue.Add(pReader.GetName(i).ToUpper().Trim(), temp);
- }
- else
- oValue.Add(pReader.GetName(i).ToUpper().Trim(), pReader.GetValue(i));
- }
- pRow.OriginalObjects = oValue;
- return true;
- }
- else
- {
- return false;
- }
- }
- #region IDisposable
- private bool disposed = false;
- public void Dispose()
- {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
- private void Dispose(bool disposing)
- {
- if (!this.disposed)
- {
- pReader.Dispose();
- pReader = null;
- }
- disposed = true;
- }
- ~AdoDataReader()
- {
- Dispose(false);
- }
- #endregion
- }
- }
|