public static ColorDAO getInstance() { if (colorDao == null) { colorDao = new ColorDAO(); } return(colorDao); }
public List <Articulo> listaArticulos(string schema) { List <Articulo> listaArticulos = new List <Articulo>(); NpgsqlConnection conexion = null; NpgsqlCommand cmd = null; NpgsqlTransaction tran = null; NpgsqlDataReader dr = null; try { conexion = Conexion.getInstance().ConexionDB(); cmd = new NpgsqlCommand("logueo.spgetarticulos", conexion); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("parm_schema", schema); conexion.Open(); tran = conexion.BeginTransaction(); dr = cmd.ExecuteReader(); while (dr.Read()) { Articulo articulo = new Articulo(); articulo.id = Convert.ToInt32(dr["ID"].ToString()); articulo.id_modelo = Convert.ToInt32(dr["IDMODELO"].ToString()); articulo.id_talle = Convert.ToInt32(dr["IDTALLE"].ToString()); articulo.id_color = Convert.ToInt32(dr["IDCOLOR"].ToString()); articulo.precio_may = Convert.ToInt32(dr["PRECIOMAY"].ToString()); articulo.precio_min = Convert.ToInt32(dr["PRECIOMIN"].ToString()); articulo.cod_barra = dr["CODBARRA"].ToString(); articulo.es_activo = Convert.ToBoolean(dr["ESACTIVO"].ToString()); listaArticulos.Add(articulo); } dr.Close(); } catch (Exception e) { listaArticulos = null; throw (e); } finally { tran.Commit(); conexion.Close(); // proveedor List <Modelo> listaModelos = ModeloDAO.getInstance().listaModelos(schema); List <Talle> listaTalles = TalleDAO.getInstance().listaTalles(schema); List <Color> listaColores = ColorDAO.getInstance().listaColores(schema); foreach (Articulo articulo in listaArticulos) { foreach (Modelo modelo in listaModelos) { if (articulo.id_modelo == modelo.id) { articulo.modelo = modelo; break; } } foreach (Talle talle in listaTalles) { if (articulo.id_talle == talle.id) { articulo.talle = talle; break; } } foreach (Color color in listaColores) { if (articulo.id_color == color.id) { articulo.color = color; } } } } return(listaArticulos); }