コード例 #1
0
 private string FabricarFacturaObjeto(Orden orden)
 {
     if (MessageBox.Show(this, "Desea crear factura?", "", MessageBoxButtons.YesNo) == DialogResult.Yes)
     {
         try
         {
             SaveFileDialog sfd = new SaveFileDialog();
             sfd.Filter = "Text File | *.txt";
             sfd.ShowDialog();
             string filename = sfd.FileName;
             using (var stream = new FileStream(filename, FileMode.OpenOrCreate))
             {
                 IGeneradorFactura generadorFactura = new GeneradorFactura();
                 StreamWriter      sw      = new StreamWriter(stream);
                 FacturaXML        factura = generadorFactura.CrearFacturaObjeto(orden, _articulos);
                 string            xml     = SerializadorXml.CrearXml(factura);
                 sw.WriteLine(xml);
                 sw.Close();
                 return(xml);
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(this, "Ocurrio un error mostrar factura");
             return(null);
         }
     }
     return(null);
 }
コード例 #2
0
        public void TestDeserializar()
        {
            string direccion = AppDomain.CurrentDomain.BaseDirectory;
            SerializadorXml <List <Docente> > ser = new SerializadorXml <List <Docente> >();
            List <Docente> aux;

            Assert.IsFalse(ser.Leer(direccion + "\\Docentes.xml", out aux));
        }
コード例 #3
0
        public void TestSerializar()
        {
            Alumno a = new Alumno(2, "Roberto", "Juarez", 45, 12234456, "Corrientes 200");
            SerializadorXml <Alumno> ser = new SerializadorXml <Alumno>();
            bool resultado = ser.Guardar("Test", a);

            Assert.IsTrue(resultado);
        }
コード例 #4
0
 private void MostrarInformacion <T>(IMostrar <T> elemento)
 {
     if (elemento != null && (elemento is Paquete || elemento is Correo))
     {
         richTextBox.Text = elemento.MostrarDatos(elemento);
         GuardaString.Guardar(elemento.MostrarDatos(elemento), "salida.txt");
         SerializadorXml <Correo> .GuardarXml("salida.xml", (Correo)elemento);
     }
 }
コード例 #5
0
        public void SerializarTest()
        {
            var usuarioSerializado = SerializadorXml.Instancia().Serializar(new UsuarioSerializarTest {
                Apellido = "Simpson"
            });

            Assert.AreEqual("<?xml version=\"1.0\"?>\r\n<UsuarioSerializarTest xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\r\n  <Apellido>Simpson</Apellido>\r\n</UsuarioSerializarTest>", usuarioSerializado);

            Assert.AreEqual("", SerializadorXml.Instancia().Serializar(null));
        }
コード例 #6
0
        public void DeserealizarTest()
        {
            var xml = "<?xml version=\"1.0\"?>\r\n<UsuarioSerializarTest xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\r\n  <Apellido>Simpson</Apellido>\r\n</UsuarioSerializarTest>";

            var actual = SerializadorXml.Instancia().Deserealizar <UsuarioSerializarTest>(xml);

            Assert.IsNotNull(actual);
            Assert.AreEqual("Simpson", actual.Apellido);
            Assert.IsInstanceOfType(actual, typeof(UsuarioSerializarTest));

            Assert.IsNull(SerializadorXml.Instancia().Deserealizar <Object>(""));
        }
コード例 #7
0
 private void DeserializarXml()
 {
     try
     {
         string ruta = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\Prueba.xml";
         SerializadorXml <Persona> serializadorXml = new SerializadorXml <Persona>(ruta);
         Persona persona = serializadorXml.Leer();
         richTextBoxPersona.Text = persona.ToString();
     }
     catch (Exception)
     {
         MessageBox.Show("Ocurrió un error inesperado.", "ERROR",
                         MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
コード例 #8
0
 private void SerializarXml()
 {
     try
     {
         string ruta = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\Prueba.xml";
         SerializadorXml <Persona> serializadorXml = new SerializadorXml <Persona>(ruta);
         Persona persona = new Persona(textBoxApellido.Text, textBoxNombre.Text);
         serializadorXml.Guardar(persona);
         MessageBox.Show("Serializado correctamente.", "EXITO",
                         MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     catch (Exception)
     {
         MessageBox.Show("Ocurrió un error inesperado.", "ERROR",
                         MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
コード例 #9
0
        private void DeserializarXml()
        {
            try
            {
                Persona persona        = null;                                                                          //Que quiero serializar??
                string  rutaEscritorio = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\Prueba.xml"; //Donde?
                SerializadorXml <Persona> serializadorXml = new SerializadorXml <Persona>(rutaEscritorio);              //Como?

                persona         = serializadorXml.Leer();                                                               //Deserializo
                rtbPersona.Text = persona.ToString();                                                                   //Lo muestro en el richTextBox
            }
            catch (Exception)
            {
                MessageBox.Show("Ocurrió un error inesperado", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #10
0
        private void SeleccionarFactura(object sender, object e)
        {
            if (e == null)
            {
                MessageBox.Show("Debe agregar factura");
            }

            try
            {
                var factura    = e as FacturaDTO;
                var facturaXml = SerializadorXml.LeerXml <FacturaXML>(factura.texto);
                new FormularioPresentarFactura(facturaXml).ShowDialog(this);
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, "Ocurrio un error generando factura");
            }
        }
コード例 #11
0
        //METODOS SERIALIZACION

        private void SerializarXml()
        {
            try
            {
                Persona persona        = new Persona(txtNombre.Text, txtApellido.Text);                                 //Que quiero serializar??
                string  rutaEscritorio = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\Prueba.xml"; //Donde?
                SerializadorXml <Persona> serializadorXml = new SerializadorXml <Persona>(rutaEscritorio);              //Como?

                serializadorXml.Guardar(persona);                                                                       //Serializo

                MessageBox.Show("Serializado a XML correctamente.", "Informacion",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);//Informo
            }
            catch (Exception)
            {
                MessageBox.Show("Ocurrió un error inesperado", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #12
0
        /// <summary>
        /// Deserealiza la lista de docentes
        /// </summary>
        /// <returns></returns>
        public List <Docente> LeerXml()
        {
            try
            {
                string direccion = AppDomain.CurrentDomain.BaseDirectory;
                //Llamo a la clase SerializadorXml
                SerializadorXml <List <Docente> > ser = new SerializadorXml <List <Docente> >();
                List <Docente> aux;
                if (ser.Leer(direccion + "\\Docentes.xml", out aux))
                {
                    docentes = aux;
                    return(aux);
                }

                return(null);
            }

            catch (ArchivosException e)
            {
                throw e;
            }
        }
コード例 #13
0
        /// <summary>
        /// Serializador
        /// </summary>
        /// <param name="ev"></param>
        /// <returns></returns>
        public void Serializar(Evaluaciones eval)
        {
            //+ "\\SegundoParcialUtn\\JardinUtn\\Serializaciones\\Aprobados\\"
            //+ "\\SegundoParcialUtn\\JardinUtn\\Serializaciones\\Desaprobados\\"

            //string pathA = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + alum;
            //string pathD = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + alum;
            try
            {
                SerializadorXml <Evaluaciones> ser = new SerializadorXml <Evaluaciones>();
                if (eval.NotaFinal >= 4)
                {
                    //if (!Directory.Exists(pathA))
                    //{
                    //    DirectoryInfo dApr = Directory.CreateDirectory(pathA);
                    //}
                    //LLama al método de Entidades
                    ser.Guardar(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + alum, eval);
                }

                else
                {
                    //if (!Directory.Exists(pathD))
                    //{
                    //    DirectoryInfo dDes = Directory.CreateDirectory(pathD);
                    //}
                    ser.Guardar(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + alum, eval);
                }
            }

            catch (Exception e)
            {
                string direccion = AppDomain.CurrentDomain.BaseDirectory;
                Texto  texto     = new Texto();
                texto.Guardar(direccion + "\\log.txt", "Error en la serialización");
                MessageBox.Show(e.Message);
            }
        }