public MaterialMatrix GetAvailibilityMatrix() { if (close_after_request) { conn = new MySqlConnection(connStr); conn.Open(); } try { MaterialMatrix mat = new MaterialMatrix(); for (int px = 0; px < MaterialMatrix.SIZE_X; px++) { for (int py = 0; py < MaterialMatrix.SIZE_Y; py++) { string type = MaterialMatrix.LabelMatX[px].Replace(' ', '_') + "_" + MaterialMatrix.LabelMatY[py].Replace(' ', '_'); string sql = "SELECT count FROM lager WHERE type='" + type + "'"; var cmd = new MySqlCommand(sql, conn); MySqlDataReader rdr = cmd.ExecuteReader(); try { if (rdr.Read()) { if (!mat.IsInactive(px, py)) { mat[px, py] = (int)rdr[0]; } } } finally { rdr.Close(); } } } return(mat); } finally { if (close_after_request) { conn.Close(); } } }
public void SetAvailibilityMatrix(MaterialMatrix mat) { if (close_after_request) { conn = new MySqlConnection(connStr); conn.Open(); } try { MySqlCommand cmd = new MySqlCommand("DELETE FROM lager", conn); cmd.ExecuteNonQuery(); for (int px = 0; px < MaterialMatrix.SIZE_X; px++) { for (int py = 0; py < MaterialMatrix.SIZE_Y; py++) { if (!mat.IsInactive(px, py)) { int count = mat[px, py]; string type = MaterialMatrix.LabelMatX[px].Replace(' ', '_') + "_" + MaterialMatrix.LabelMatY[py].Replace(' ', '_'); int hash = type.GetHashCode(); string sql = "INSERT INTO lager (dbkey,type,count) VALUES (" + hash + ",'" + type + "'," + count + ")"; cmd = new MySqlCommand(sql, conn); cmd.ExecuteNonQuery(); } } } } finally { if (close_after_request) { conn.Close(); } } }