public List<Select.InventarioVehiculo> list_InventarioVehiculo() { try { List<Select.InventarioVehiculo> vehiculos = new List<Select.InventarioVehiculo>(); Select.InventarioVehiculo a; DataTable dt = new DataTable(); SqlDataAdapter sda = new SqlDataAdapter(); string ConnString = ConfigurationManager.ConnectionStrings["barabaresConnectionString"].ConnectionString; using (SqlConnection SqlConn = new SqlConnection(ConnString)) { try { SqlConn.Open(); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); return vehiculos; } SqlCommand sqlCmd = new SqlCommand("PRODUCTO_X_VEHICULO_LIST_SISTEMA", SqlConn); sqlCmd.CommandType = CommandType.StoredProcedure; sda.SelectCommand = sqlCmd; sda.Fill(dt); SqlConn.Close(); sqlCmd.Dispose(); sda.Dispose(); } DataRow[] rows = dt.Select(); for (int i = 0; i < rows.Length; i++) { a = Utils.select_inventario_vehiculo_parse(rows[i]); vehiculos.Add(a); } return vehiculos; } catch (Exception ex) { Select.InventarioVehiculo v = new Select.InventarioVehiculo(); LogBarabares b = new LogBarabares() { Accion = Constantes.LOG_LISTAR, Servicio = Constantes.List_InventarioVehiculo, Input = "", Descripcion = ex.ToString(), Clase = v.GetType().Name, Aplicacion = Constantes.ENTORNO_SERVICIOS, Estado = Constantes.FALLA, Ip = "", IdUsuario = 1 //TODO: obtener usuario de la sesión }; Utils.add_LogBarabares(b); return new List<Select.InventarioVehiculo>(); } }
public List<Select.InventarioVehiculo> search_InventarioVehiculo(Search.InventarioVehiculo veh) { try { List<Select.InventarioVehiculo> vehiculos = new List<Select.InventarioVehiculo>(); Select.InventarioVehiculo a = new Select.InventarioVehiculo(); DataTable dt = new DataTable(); SqlDataAdapter sda = new SqlDataAdapter(); string ConnString = ConfigurationManager.ConnectionStrings["barabaresConnectionString"].ConnectionString; using (SqlConnection SqlConn = new SqlConnection(ConnString)) { try { SqlConn.Open(); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); return vehiculos; } SqlCommand sqlCmd = new SqlCommand("PRODUCTO_X_VEHICULO_SEARCH", SqlConn); sqlCmd.CommandType = CommandType.StoredProcedure; sqlCmd.Parameters.Add("@ipsNombre", SqlDbType.VarChar).Value = veh.Nombre; sqlCmd.Parameters.Add("@ipnVehiculo", SqlDbType.Int).Value = veh.Vehiculo; sqlCmd.Parameters.Add("@ipnIdUnidad", SqlDbType.Int).Value = veh.Unidad; sqlCmd.Parameters.Add("@ipnPresentacion", SqlDbType.Int).Value = veh.Presentacion; sqlCmd.Parameters.Add("@ipdDesde", SqlDbType.DateTime).Value = veh.Desde; sqlCmd.Parameters.Add("@ipdHasta", SqlDbType.DateTime).Value = veh.Hasta; sqlCmd.Parameters.Add("@ipsAccion", SqlDbType.VarChar).Value = Constantes.LOG_BUSCAR; sqlCmd.Parameters.Add("@ipsClase", SqlDbType.VarChar).Value = a.GetType().Name; sqlCmd.Parameters.Add("@ipnIdUsuario", SqlDbType.Int).Value = 1; sda.SelectCommand = sqlCmd; sda.Fill(dt); SqlConn.Close(); sqlCmd.Dispose(); sda.Dispose(); } DataRow[] rows = dt.Select(); for (int i = 0; i < rows.Length; i++) { a = Utils.select_inventario_vehiculo_parse(rows[i]); vehiculos.Add(a); } return vehiculos; } catch (Exception ex) { Select.InventarioVehiculo v = new Select.InventarioVehiculo(); LogBarabares b = new LogBarabares() { Accion = Constantes.LOG_BUSCAR, Servicio = Constantes.Search_InventarioVehiculo, Input = JsonSerializer.search_InventarioVehiculo(veh), Descripcion = ex.ToString(), Clase = v.GetType().Name, Aplicacion = Constantes.ENTORNO_SERVICIOS, Estado = Constantes.FALLA, Ip = "", IdUsuario = 1 //TODO: obtener usuario de la sesión }; Utils.add_LogBarabares(b); return new List<Select.InventarioVehiculo>(); } }
public static Select.InventarioVehiculo select_inventario_vehiculo_parse(DataRow r) { Select.InventarioVehiculo p = new Select.InventarioVehiculo(); p.IdProducto = Int32.Parse(r["IdProducto"].ToString()); p.Nombre = r["Nombre"].ToString(); p.Descripcion = r["Descripcion"].ToString(); p.Tipo = r["Tipo"].ToString(); p.FechaVencimiento = DateTime.ParseExact(r["FechaVencimiento"].ToString(), "M/d/yyyy h:mm:ss ttt", null); p.Tipo = r["Tipo"].ToString(); p.Unidad = r["Unidad"].ToString(); p.Presentacion = Int32.Parse(r["Presentacion"].ToString()); p.Precio = Double.Parse(r["Precio"].ToString()); p.Activo = Boolean.Parse(r["activo"].ToString()); p.Vehiculo = r["Vehiculo"].ToString(); p.Stock = Int32.Parse(r["Stock"].ToString()); return p; }