public static XmlDocument CountryToXML(Country country) { StringBuilder sb = new StringBuilder(); XmlWriter writer = XmlWriter.Create(sb); writer.WriteStartDocument(); writer.WriteStartElement("country"); writer.WriteStartElement("field"); writer.WriteAttributeString("zero_x", country.field.zero_x.ToString()); writer.WriteAttributeString("zero_y", country.field.zero_y.ToString()); writer.WriteAttributeString("size_x", country.field.size_x.ToString()); writer.WriteAttributeString("size_y", country.field.size_y.ToString()); foreach (VegetableOnField veg in country.field.vegetables) { writer.WriteStartElement(veg.VegetableNameID.ToString()); writer.WriteAttributeString("id", veg.id.ToString()); writer.WriteAttributeString("x", veg.x.ToString()); writer.WriteAttributeString("y", veg.y.ToString()); writer.WriteAttributeString("growstage", veg.growstage.ToString()); writer.WriteEndElement(); } writer.WriteEndElement(); writer.WriteEndElement(); writer.WriteEndDocument(); writer.Flush(); XmlDocument xmlDocument = new XmlDocument(); xmlDocument.LoadXml(sb.ToString()); return xmlDocument; }
public static Country GetCountry(int FieldID) { Country country = new Country(); Field field = new Field(); SqlParameter paramFieldID = CreateSqlParam(SqlQueriesConst.ParamFieldID, DBNull.Value, SqlDbType.Int); paramFieldID.Value = 1; DataTable dt = GetSqlQueryDataTable(Connection, Queries.GetField, new SqlParameter[] { paramFieldID }); if (dt != null && dt.Rows.Count > 0) { field.Populate(dt.Rows[0]); } field.vegetables = GetAllVegetablesOnField(FieldID); country.field = field; return country; }