diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-08-03 12:16:21 +0300 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-08-03 12:16:21 +0300 |
| commit | bd1221e36ee3e493dc25bd32559f846519fe60d0 (patch) | |
| tree | e4462d6672223b1fb43ee017e256e13301cec9f2 /Software/Visual_Studio/PPC/Tango.PPC.Shared/SQL/RemoteSqlRow.cs | |
| parent | 99cbacc067251a3841fc1aca99e029146ed11c15 (diff) | |
| download | Tango-bd1221e36ee3e493dc25bd32559f846519fe60d0.tar.gz Tango-bd1221e36ee3e493dc25bd32559f846519fe60d0.zip | |
Refactored RemoteSQL on procedures.
Fixed issue with generic types display on code editor.
Added line wrap toggle to procedure designer output.
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Shared/SQL/RemoteSqlRow.cs')
| -rw-r--r-- | Software/Visual_Studio/PPC/Tango.PPC.Shared/SQL/RemoteSqlRow.cs | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Shared/SQL/RemoteSqlRow.cs b/Software/Visual_Studio/PPC/Tango.PPC.Shared/SQL/RemoteSqlRow.cs new file mode 100644 index 000000000..bf6b0ba0c --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Shared/SQL/RemoteSqlRow.cs @@ -0,0 +1,98 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.Diagnostics; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using Tango.BL.Entities; + +namespace Tango.PPC.Shared.SQL +{ + public class RemoteSqlRow + { + private Func<String, Object> _getFuncKey; + private Func<int, Object> _getFuncIndex; + + public List<Object> Values { get; set; } + + public RemoteSqlRow() + { + Values = new List<object>(); + } + + public Object Get(String columnName) + { + return _getFuncKey.Invoke(columnName); + } + + public Object Get(int columnIndex) + { + return _getFuncIndex.Invoke(columnIndex); + } + + public T Get<T>(String columnName) + { + var value = _getFuncKey.Invoke(columnName); + + if (typeof(T) != value.GetType()) + { + return (T)Convert.ChangeType(value, typeof(T)); + } + else + { + return (T)value; + } + } + + public T Get<T>(int columnIndex) + { + var value = _getFuncIndex.Invoke(columnIndex); + + if (typeof(T) != value.GetType()) + { + return (T)Convert.ChangeType(value, typeof(T)); + } + else + { + return (T)value; + } + } + + internal void Init(Func<String, Object> getFuncKey, Func<int, Object> getFuncIndex) + { + _getFuncKey = getFuncKey; + _getFuncIndex = getFuncIndex; + } + + public override string ToString() + { + return String.Join(", ", Values); + } + + public T Map<T>() where T : class, new() + { + var obj = Activator.CreateInstance<T>(); + Map<T>(obj); + return obj; + } + + public void Map<T>(T obj) where T : class + { + foreach (var prop in typeof(T).GetPropertiesWithAttribute<ColumnAttribute>()) + { + try + { + var columnName = prop.GetCustomAttribute<ColumnAttribute>().Name; + var value = Get(columnName).ToStringSafe(); + prop.SetValue(obj, Convert.ChangeType(value, prop.PropertyType)); + } + catch (Exception ex) + { + Debug.WriteLine(ex); + } + } + } + } +} |
