public List<ProductoXAlmacen> selectAll_ProductoXAlmacen() { try { List<ProductoXAlmacen> pxas = new List<ProductoXAlmacen>(); ProductoXAlmacen pxa; 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 pxas; } SqlCommand sqlCmd = new SqlCommand("PRODUCTO_X_ALMACEN_SELECT_ALL", 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++) { pxa = Utils.productoXAlmacen_parse(rows[i]); pxas.Add(pxa); } return pxas; } catch (Exception ex) { ProductoXAlmacen prd = new ProductoXAlmacen(); LogBarabares b = new LogBarabares() { Accion = Constantes.LOG_LISTAR, Servicio = Constantes.SelectAll_ProductoXAlmacen, Input = "", Descripcion = ex.ToString(), Clase = prd.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<ProductoXAlmacen>(); } }
public static ProductoXAlmacen productoXAlmacen_parse(DataRow r) { ProductoXAlmacen pxa = new ProductoXAlmacen(); pxa.IdProductoXAlmacen = Int32.Parse(r["idProductoXAlmacen"].ToString()); pxa.Stock = Int32.Parse(r["stock"].ToString()); pxa.FechaVencimiento = DateTime.ParseExact(r["fechaCreacion"].ToString(), "M/d/yyyy h:mm:ss ttt", null); pxa.IdProducto = Int32.Parse(r["idProducto"].ToString()); pxa.IdAlmacen = Int32.Parse(r["idAlmacen"].ToString()); return pxa; }
public ResponseBD add_ProductoXAlmacen(ProductoXAlmacen pxa) { try { ResponseBD response = new ResponseBD(); string ConnString = ConfigurationManager.ConnectionStrings["barabaresConnectionString"].ConnectionString; using (SqlConnection SqlConn = new SqlConnection(ConnString)) { try { SqlConn.Open(); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); response.Flujo = Constantes.FALLA; response.Mensaje = "Error al abrir la conexión a BD"; return response; } SqlCommand sqlCmd = new SqlCommand("PRODUCTO_X_ALMACEN_INSERT", SqlConn); sqlCmd.CommandType = CommandType.StoredProcedure; SqlParameter flujo = new SqlParameter("@opsFlujo", SqlDbType.VarChar) { Direction = ParameterDirection.Output, Size = 10 }; SqlParameter mensaje = new SqlParameter("@opsMsj", SqlDbType.VarChar) { Direction = ParameterDirection.Output, Size = 100 }; sqlCmd.Parameters.Add("@ipnStock ", SqlDbType.Int).Value = pxa.Stock; sqlCmd.Parameters.Add("@ipdFechaVencimiento", SqlDbType.DateTime).Value = pxa.FechaVencimiento; sqlCmd.Parameters.Add("@ipnIdProducto", SqlDbType.Int).Value = pxa.IdProducto; sqlCmd.Parameters.Add("@ipnIdAlmacen", SqlDbType.Int).Value = pxa.IdAlmacen; sqlCmd.Parameters.Add(flujo); sqlCmd.Parameters.Add(mensaje); sqlCmd.ExecuteNonQuery(); response.Flujo = flujo.Value.ToString(); response.Mensaje = mensaje.Value.ToString(); SqlConn.Close(); } return response; } catch (Exception ex) { LogBarabares b = new LogBarabares() { Accion = Constantes.LOG_CREAR, Servicio = Constantes.Add_ProductoXAlmacen, Input = "", //TODO Descripcion = ex.ToString(), Clase = (pxa == null) ? "null" : pxa.GetType().Name, Aplicacion = Constantes.ENTORNO_SERVICIOS, Estado = Constantes.FALLA, Ip = "", IdUsuario = 1 //TODO: obtener usuario de la sesión }; Utils.add_LogBarabares(b); ResponseBD response = new ResponseBD(); response.Flujo = Constantes.FALLA; response.Mensaje = "Error al abrir la conexión a BD"; return response; } }