From bd1221e36ee3e493dc25bd32559f846519fe60d0 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Mon, 3 Aug 2020 12:16:21 +0300 Subject: Refactored RemoteSQL on procedures. Fixed issue with generic types display on code editor. Added line wrap toggle to procedure designer output. --- .../PPC/Tango.PPC.Shared/SQL/RemoteSqlRow.cs | 98 ++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.Shared/SQL/RemoteSqlRow.cs (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Shared/SQL/RemoteSqlRow.cs') 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 _getFuncKey; + private Func _getFuncIndex; + + public List Values { get; set; } + + public RemoteSqlRow() + { + Values = new List(); + } + + public Object Get(String columnName) + { + return _getFuncKey.Invoke(columnName); + } + + public Object Get(int columnIndex) + { + return _getFuncIndex.Invoke(columnIndex); + } + + public T Get(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(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 getFuncKey, Func getFuncIndex) + { + _getFuncKey = getFuncKey; + _getFuncIndex = getFuncIndex; + } + + public override string ToString() + { + return String.Join(", ", Values); + } + + public T Map() where T : class, new() + { + var obj = Activator.CreateInstance(); + Map(obj); + return obj; + } + + public void Map(T obj) where T : class + { + foreach (var prop in typeof(T).GetPropertiesWithAttribute()) + { + try + { + var columnName = prop.GetCustomAttribute().Name; + var value = Get(columnName).ToStringSafe(); + prop.SetValue(obj, Convert.ChangeType(value, prop.PropertyType)); + } + catch (Exception ex) + { + Debug.WriteLine(ex); + } + } + } + } +} -- cgit v1.3.1