コード例 #1
0
ファイル: Fabrica.cs プロジェクト: corsa144/TPs_Laboratorio2
        /// <summary>
        /// guarda en xml
        /// </summary>
        /// <returns></returns>
        public bool GuardarXml()
        {
            List <Celular> celulares = new List <Celular>();

            foreach (Producto p in this.Productos)
            {
                if (p is Celular)
                {
                    celulares.Add((Celular)p);
                }
            }
            try
            {
                string ruta = Directory.GetCurrentDirectory() + @"\Celulares.xml";
                ArchivosXml <List <Celular> > stockXml = new ArchivosXml <List <Celular> >();

                if (stockXml.Guardar(ruta, celulares))
                {
                    return(true);
                }
            }catch (Exception)
            {
                throw new ArchivosException("Error al guardar en xml");
            }

            return(false);
        }
コード例 #2
0
ファイル: Fabrica.cs プロジェクト: corsa144/TPs_Laboratorio2
        /// <summary>
        /// lee un archivo xml
        /// </summary>
        /// <returns></returns>
        public Fabrica LeerXml()
        {
            string         ruta      = Directory.GetCurrentDirectory() + @"\Celulares.xml";
            List <Celular> celulares = new List <Celular>();

            try
            {
                Fabrica fabrica = GetFabrica(this.AlmacenDeProductos);
                ArchivosXml <List <Celular> > archivoXml = new ArchivosXml <List <Celular> >();
                archivoXml.Leer(ruta, out celulares);
            }
            catch (Exception)
            {
                throw new ArchivosException("Error al intentar leer el archivo!");
            }
            foreach (Celular c in celulares)
            {
                fabrica.Productos.Add(c);
            }

            return(fabrica);
        }