using Microsoft.Extensions.Configuration; using Net.Business.Entities; using Net.Business.Entities.ServicesLayer.Items; using Net.Connection; using Net.CrossCotting; using Sap.Data.Hana; using System; using System.Collections.Generic; using System.Data; using System.Net.Http; using System.Text.RegularExpressions; using System.Threading.Tasks; namespace Net.Data.WMS.Items { public class ItemsRepository : RepositoryBase, IItemsRepository { #region Variables Globales private string _aplicacionName; private string _metodoName; private readonly Regex regex = new Regex(@"<(\w+)>.*"); #endregion public ItemsRepository(IConnectionSQL context, IHttpClientFactory clientFactory, IConfiguration configuration) : base(context) { _aplicacionName = GetType().Name; } public async Task> GetStockItem() { _metodoName = regex.Match(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name).Groups[1].Value.ToString(); ResultadoTransaccion resultadoTransaccion = new ResultadoTransaccion(_metodoName, _aplicacionName); return await Task.Run(() => { try { List ListaStock = new List(); DataTable dt = new DataTable(); using (HanaConnection con = new HanaConnection(LocalData.ConnectionString)) { con.Open(); HanaCommand cmd = new HanaCommand($"CALL\"{LocalData.Schema}\".\"ITCA_WMS_SAP_GetStockConsolidado\"", con); HanaDataAdapter da = new HanaDataAdapter(cmd); if (da != null) { da.Fill(dt); } } for (int x = 0; x < dt.Rows.Count; x++) { ListaStock.Add(new BE_ItemStock() { BinCode = dt.Rows[x]["BinCode"] != DBNull.Value ? Convert.ToString(dt.Rows[x]["BinCode"]) : string.Empty, DistNumber = dt.Rows[x]["DistNumber"] != DBNull.Value ? Convert.ToString(dt.Rows[x]["DistNumber"]) : string.Empty, ExpDate = dt.Rows[x]["ExpDate"] != DBNull.Value ? Convert.ToDateTime(dt.Rows[x]["ExpDate"]) : DateTime.Now, ItemCode = dt.Rows[x]["ItemCode"] != DBNull.Value ? Convert.ToString(dt.Rows[x]["ItemCode"]) : string.Empty, ItemName = dt.Rows[x]["ItemName"] != DBNull.Value ? Convert.ToString(dt.Rows[x]["ItemName"]) : string.Empty, OnHandQty = dt.Rows[x]["OnHandQty"] != DBNull.Value ? Convert.ToDouble(dt.Rows[x]["OnHandQty"]) : 0, WhsCode = dt.Rows[x]["WhsCode"] != DBNull.Value ? Convert.ToString(dt.Rows[x]["WhsCode"]) : string.Empty, WhsName = dt.Rows[x]["WhsName"] != DBNull.Value ? Convert.ToString(dt.Rows[x]["WhsName"]) : string.Empty, AvgPrice = dt.Rows[x]["AvgPrice"] != DBNull.Value ? Convert.ToDouble(dt.Rows[x]["AvgPrice"]) : 0, }); } return resultadoTransaccion.GetInformacionResultado(0, 0, "Datos obtenidos Correctamente", ListaStock); } catch (Exception ex) { return resultadoTransaccion.GetInformacionResultado(ex.Message.ToString(), null); } }); } } }