Example #1
0
          public Factura leerFactura()
        {
            doc = new XmlDocument();
            Factura factura = new Factura();
            doc.Load(ruta);
            XmlNodeList nodeList = doc.GetElementsByTagName("factura");

            foreach (XmlNode p in nodeList)
            {
                factura = new Factura();
                factura.Numero = Convert.ToInt32(p["cabecera"]["numero"].InnerText);
                factura.CodClient = p["cabecera"]["codClient"].InnerText;
                factura.NameClient = p["cabecera"]["nameClient"].InnerText;
                factura.DirClient = p["cabecera"]["dirClient"].InnerText;
                factura.TlfClient = Convert.ToInt32(p["cabecera"]["tlfClient"].InnerText);
                factura.Fecha = Convert.ToDateTime(p["cabecera"]["fecha"].InnerText);

                foreach(XmlNode n in p["detalles"].GetElementsByTagName("producto"))
                {
                    Producto prod = new Producto();
                    prod.Item = Convert.ToInt32(n["item"].InnerText);
                    prod.Codigo = n["codigo"].InnerText;
                    prod.Descripcion = n["descripcion"].InnerText;
                    prod.Cantidad = Convert.ToInt32(n["cantidad"].InnerText);
                    prod.Precio = Convert.ToDecimal(n["precio"].InnerText);
                    prod.Total = Convert.ToDecimal(n["precio"].InnerText);
                    factura.Products.Add(prod);
                }
                
            }return factura;
        }
Example #2
0
        public void saveFacturaXML(Factura factura)
        {
            XmlDeclaration xmlDeclaration = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
            doc.AppendChild(xmlDeclaration);
            XmlElement raiz= doc.DocumentElement;
            doc.AppendChild(raiz);

            XmlNode fact = doc.CreateElement("factura");
            XmlNode cabecera = doc.CreateElement("cabecera");

            XmlNode numero = doc.CreateElement("numero");
            numero.InnerText = factura.Numero.ToString();
            cabecera.AppendChild(numero);

            XmlNode codClient = doc.CreateElement("codClient");
            codClient.InnerText = factura.CodClient.ToString();
            cabecera.AppendChild(codClient);

            XmlNode nameClient = doc.CreateElement("nameClient");
            nameClient.InnerText = factura.NameClient.ToString();
            cabecera.AppendChild(nameClient);

            XmlNode dirClient = doc.CreateElement("dirClient");
            dirClient.InnerText = factura.DirClient.ToString();
            cabecera.AppendChild(dirClient);

            XmlNode tlfClient = doc.CreateElement("tlfClient");
            tlfClient.InnerText = factura.TlfClient.ToString();
            cabecera.AppendChild(tlfClient);

            XmlNode fecha = doc.CreateElement("fecha");
            fecha.InnerText = factura.Fecha.ToString();
            cabecera.AppendChild(fecha);

            XmlNode detalles = doc.CreateElement("detalles");            

            foreach (Producto p in factura.Products)
            {
                detalles.InsertAfter(CrearNodosdetalle(p), detalles.LastChild);
            }

            fact.AppendChild(cabecera);
            fact.AppendChild(detalles);
            doc.AppendChild(fact);
            doc.Save(this.ruta);
        }
Example #3
0
        private void guardarToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (txbTelefono.Text != "" && txbTelefono.Text != "" && txbCodigo.Text != "" && txbNombre.Text != "" && txbDireccion.Text != "" && txbNumero.Text != "" && txbTelefono.Text != "")
            {
                if (Int32.Parse(txbTelefono.Text)>0 && Int32.Parse(txbNumero.Text)>0)
                {
                    ruta = Application.StartupPath + "\\data\\factura_" + txbNumero.Text + ".xml";
                    Factura fact = new Factura(Convert.ToInt32(txbNumero.Text), txbCodigo.Text, txbNombre.Text, txbDireccion.Text, Convert.ToInt32(txbTelefono.Text), BindingLista.ToList(), dtp.Value);
                    FicheroXml fich = new FicheroXml(ruta);
                    fich.saveFacturaXML(fact);
                }
                else
                {
                    MessageBox.Show("Por favor introduce valores númericos en Nº de factura y en el teléfono");
                }
            }
            else
            {
                MessageBox.Show("Algunos elementos del formulario están en blanco. por favor complétalos");
            }

        }