List<MaterialModel> materials = new List<MaterialModel>();
using (var conn = new NpgsqlConnection(connectionString))
using (var cmd = conn.CreateCommand())
{
conn.Open();
cmd.CommandText = "SELECT * FROM AllInformationConsumables";
cmd.Connection = conn;
using (var reader = cmd.ExecuteReader())
{
while(reader.Read())
{
MaterialModel material = new MaterialModel();
material.Consumables = new List<ConsumableModel>(); //Vi hämtar data härifrån fast det är null, need to fix.
material.Name = reader.GetString(0);
for(int i = 1; i <= reader.FieldCount-1; i++)
{
ConsumableModel con = new ConsumableModel();
con.Name = reader.GetName(i); //DENNA FUCKAR ALLT, var off by one error :D
string[] valueUnit = reader.GetString(i).Split(" ");
con.Value = Convert.ToDouble(valueUnit[0]);
con.Unit = valueUnit[1];
//MessageBox.Show(con.ToString());
material.AddConsumable(con);
}
materials.Add(material);
}
}
}
return materials;
}