public static string MostrarEstante(Estante e) // recorre el estante mostrado todo su contenido { StringBuilder sb = new StringBuilder(); sb.AppendLine("Capacidad: " + e._capacidad); foreach (Producto item in e._productos) { sb.AppendLine(item.ToString());//llama a la sobrecarga ToString de cada producto } return(sb.ToString()); }
public static bool GuardarEstante(Estante e)//intento archivo txt { bool aux = true; if (aux == true) { using (StreamWriter arch = new StreamWriter("D:\\MiEstante.txt", true)) //Guarda en la ubicacion D: //using (StreamWriter arch = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + "\\MiEstante.txt", true)) //guarda en \bin\Debug //using (StreamWriter arch = new StreamWriter(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\MiEstante.txt", true)) //Guarda en la carpeta que quiero { //arch.WriteLine(e.ToString());MostrarEstante(Estante e) arch.WriteLine(MostrarEstante(e)); } } return(aux); }
public static bool Serializar(Estante e)//intento XML { bool aux = true; if (aux == true) { //using (XmlTextWriter archivo = new XmlTextWriter(AppDomain.CurrentDomain.BaseDirectory + "\\MiEstanteXML.xml", System.Text.Encoding.UTF8)) // using (StreamReader arch = new StreamReader(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\MiEstanteXML.xml")) //using (XmlTextWriter archivo = new XmlTextWriter(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\MiEstanteXML.xml", System.Text.Encoding.UTF8)) using (XmlTextWriter arc = new XmlTextWriter(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\MiEstanteXML.xml", System.Text.Encoding.UTF8)) { XmlSerializer serializador = new XmlSerializer(typeof(Estante)); serializador.Serialize(arc, e); } } return(aux); }