Beispiel #1
0
        public void GenerarArchivosXml()
        {
            //splashScreenManager1.ShowWaitForm();
            try
            {
                foreach (var item in listado_cbtes_info)
                {
                    string sIdCbteFact = "";
                    //item.CbteFactura.infoTributaria = new infoTributaria();


                    // si es factura
                    if (item.TipoCbte == eTipoComprobante.Factura)
                    {
                        try
                        {
                            sIdCbteFact = item.CbteFactura.infoTributaria.razonSocial.Substring(0, 3) + "-" + eTipoCodComprobante.FAC + "-" + item.CbteFactura.infoTributaria.estab + "-" + item.CbteFactura.infoTributaria.ptoEmi + "-" + item.CbteFactura.infoTributaria.secuencial;
                            XmlSerializerNamespaces NamespaceObject = new XmlSerializerNamespaces();
                            NamespaceObject.Add("", "");
                            XmlSerializer mySerializer = new XmlSerializer(typeof(factura));

                            myWriter = new StreamWriter(Efirm.Properties.Settings.Default.PatchXml + sIdCbteFact + ".xml");


                            mySerializer.Serialize(myWriter, item.CbteFactura, NamespaceObject);
                            myWriter.Close();
                            // GRABAR COMP
                            ObuscComp = new fx_Comprobantes_generados_Bus();
                            fx_Comprobante_generados_Info comprobante = new fx_Comprobante_generados_Info();
                            comprobante.IdRegistro = sIdCbteFact;
                            comprobante.Estado     = "A";
                            ObuscComp.GuardarComprobantes_generados_FX(comprobante);
                        }
                        catch (Exception ex) { }
                    }
                    // si es retencion
                    else if (item.TipoCbte == eTipoComprobante.Retencion)
                    {
                        try
                        {
                            sIdCbteFact = item.cbteRet.infoTributaria.razonSocial.Substring(0, 3) + "-" + eTipoCodComprobante.RET + "-" + item.cbteRet.infoTributaria.estab + "-" + item.cbteRet.infoTributaria.ptoEmi + "-" + item.cbteRet.infoTributaria.secuencial;
                            XmlSerializerNamespaces NamespaceObject = new XmlSerializerNamespaces();
                            NamespaceObject.Add("", "");
                            XmlSerializer mySerializer = new XmlSerializer(typeof(comprobanteRetencion));


                            myWriter = new StreamWriter(Efirm.Properties.Settings.Default.PatchXml + sIdCbteFact + ".xml");
                            mySerializer.Serialize(myWriter, item.cbteRet, NamespaceObject);
                            myWriter.Close();
                            // GRABAR COMP
                            ObuscComp = new fx_Comprobantes_generados_Bus();
                            fx_Comprobante_generados_Info comprobante = new fx_Comprobante_generados_Info();
                            comprobante.IdRegistro = sIdCbteFact;
                            comprobante.Estado     = "A";
                            ObuscComp.GuardarComprobantes_generados_FX(comprobante);
                        }
                        catch (Exception ex) { }
                    }
                    // si es nota de credito
                    else if (item.TipoCbte == eTipoComprobante.NotaCred)
                    {
                        try
                        {
                            sIdCbteFact = item.cbteNC.infoTributaria.razonSocial.Substring(0, 3) + "-" + eTipoCodComprobante.NTC + "-" + item.cbteNC.infoTributaria.estab + "-" + item.cbteNC.infoTributaria.ptoEmi + "-" + item.cbteNC.infoTributaria.secuencial;
                            XmlSerializerNamespaces NamespaceObject = new XmlSerializerNamespaces();
                            NamespaceObject.Add("", "");
                            XmlSerializer mySerializer = new XmlSerializer(typeof(notaCredito));


                            myWriter = new StreamWriter(Efirm.Properties.Settings.Default.PatchXml + sIdCbteFact + ".xml");

                            mySerializer.Serialize(myWriter, item.cbteNC, NamespaceObject);
                            myWriter.Close();
                            // GRABAR COMP
                            ObuscComp = new fx_Comprobantes_generados_Bus();
                            fx_Comprobante_generados_Info comprobante = new fx_Comprobante_generados_Info();
                            comprobante.IdRegistro = sIdCbteFact;
                            comprobante.Estado     = "A";
                            ObuscComp.GuardarComprobantes_generados_FX(comprobante);
                        }
                        catch (Exception ex) {  }
                    }

                    // si es guia de remision
                    else if (item.TipoCbte == eTipoComprobante.Guia)
                    {
                        try
                        {
                            sIdCbteFact = sIdCbteFact = item.cbtGR.infoTributaria.razonSocial.Substring(0, 3) + "-" + eTipoCodComprobante.GUI + "-" + item.cbtGR.infoTributaria.estab + "-" + item.cbtGR.infoTributaria.ptoEmi + "-" + item.cbtGR.infoTributaria.secuencial;
                            XmlSerializerNamespaces NamespaceObject = new XmlSerializerNamespaces();
                            NamespaceObject.Add("", "");
                            XmlSerializer mySerializer = new XmlSerializer(typeof(guiaRemision));


                            myWriter = new StreamWriter(Efirm.Properties.Settings.Default.PatchXml + sIdCbteFact + ".xml");
                            mySerializer.Serialize(myWriter, item.cbtGR, NamespaceObject);
                            myWriter.Close();
                            // GRABAR COMP
                            ObuscComp = new fx_Comprobantes_generados_Bus();
                            fx_Comprobante_generados_Info comprobante = new fx_Comprobante_generados_Info();
                            comprobante.IdRegistro = sIdCbteFact;
                            comprobante.Estado     = "A";
                            ObuscComp.GuardarComprobantes_generados_FX(comprobante);
                        }
                        catch (Exception ex) { }
                    }
                    // si es nota debito
                    else if (item.TipoCbte == eTipoComprobante.NotaDeb)
                    {
                        try
                        {
                            sIdCbteFact = sIdCbteFact = item.cbteDeb.infoTributaria.razonSocial.Substring(0, 3) + "-" + eTipoCodComprobante.NTD + "-" + item.cbteDeb.infoTributaria.estab + "-" + item.cbteDeb.infoTributaria.ptoEmi + "-" + item.cbteDeb.infoTributaria.secuencial;
                            XmlSerializerNamespaces NamespaceObject = new XmlSerializerNamespaces();
                            NamespaceObject.Add("", "");
                            XmlSerializer mySerializer = new XmlSerializer(typeof(notaDebito));
                            myWriter = new StreamWriter(Efirm.Properties.Settings.Default.PatchXml + sIdCbteFact + ".xml");
                            mySerializer.Serialize(myWriter, item.cbteDeb, NamespaceObject);
                            myWriter.Close();
                            // GRABAR COMP
                            ObuscComp = new fx_Comprobantes_generados_Bus();
                            fx_Comprobante_generados_Info comprobante = new fx_Comprobante_generados_Info();
                            comprobante.IdRegistro = sIdCbteFact;
                            comprobante.Estado     = "A";
                            ObuscComp.GuardarComprobantes_generados_FX(comprobante);
                        }
                        catch (Exception ex) {  }
                    }
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
            }
        }
        public void GenerarArchivosXml()
        {
            gridControlCbtes.RefreshDataSource();
            //splashScreenManager1.ShowWaitForm();
            try
            {
                foreach (var item in listado_cbtes_info)
                {
                    string sIdCbteFact = "";
                    //item.CbteFactura.infoTributaria = new infoTributaria();


                    if (item.Checked == true)
                    { // si es factura
                        if (item.TipoCbte == eTipoComprobante.Factura)
                        {
                            try
                            {
                                sIdCbteFact = item.CbteFactura.infoTributaria.razonSocial.Substring(0, 3) + "-" + eTipoCodComprobante.FAC + "-" + item.CbteFactura.infoTributaria.estab + "-" + item.CbteFactura.infoTributaria.ptoEmi + "-" + item.CbteFactura.infoTributaria.secuencial;

                                XmlSerializerNamespaces NamespaceObject = new XmlSerializerNamespaces();
                                NamespaceObject.Add("", "");
                                XmlSerializer mySerializer = new XmlSerializer(typeof(factura));

                                myWriter = new StreamWriter(txtRuta.Text + sIdCbteFact + ".xml");


                                mySerializer.Serialize(myWriter, item.CbteFactura, NamespaceObject);
                                myWriter.Close();
                                // GRABAR COMP
                                ObuscComp = new fx_Comprobantes_generados_Bus();
                                fx_Comprobante_generados_Info comprobante = new fx_Comprobante_generados_Info();
                                comprobante.IdRegistro  = sIdCbteFact;
                                comprobante.FECHA_CARGA = DateTime.Now;
                                comprobante.Estado      = "A";
                                ObuscComp.GuardarComprobantes_generados_AX(comprobante, ConexionDbcliente);
                            }
                            catch (Exception ex) { MessageBox.Show(ex.Message); }
                        }
                        // si es retencion
                        else if (item.TipoCbte == eTipoComprobante.Retencion)
                        {
                            try
                            {
                                sIdCbteFact = item.cbteRet.infoTributaria.razonSocial.Substring(0, 3) + "-" + eTipoCodComprobante.RET + "-" + item.cbteRet.infoTributaria.estab + "-" + item.cbteRet.infoTributaria.ptoEmi + "-" + item.cbteRet.infoTributaria.secuencial;
                                XmlSerializerNamespaces NamespaceObject = new XmlSerializerNamespaces();
                                NamespaceObject.Add("", "");
                                XmlSerializer mySerializer = new XmlSerializer(typeof(comprobanteRetencion));


                                myWriter = new StreamWriter(txtRuta.Text + sIdCbteFact + ".xml");
                                //StreamWriter myWriter = new StreamWriter(txtRuta.Text + sIdCbteFact + ".xml");
                                mySerializer.Serialize(myWriter, item.cbteRet, NamespaceObject);
                                myWriter.Close();
                                // GRABAR COMP
                                ObuscComp = new fx_Comprobantes_generados_Bus();
                                fx_Comprobante_generados_Info comprobante = new fx_Comprobante_generados_Info();
                                comprobante.IdRegistro  = sIdCbteFact;
                                comprobante.FECHA_CARGA = DateTime.Now;
                                comprobante.Estado      = "A";
                                ObuscComp.GuardarComprobantes_generados_AX(comprobante, ConexionDbcliente);
                            }
                            catch (Exception ex) { MessageBox.Show(ex.Message); }
                        }
                        // si es nota de credito
                        else if (item.TipoCbte == eTipoComprobante.NotaCred)
                        {
                            try
                            {
                                sIdCbteFact = item.cbteNC.infoTributaria.razonSocial.Substring(0, 3) + "-" + eTipoCodComprobante.NTC + "-" + item.cbteNC.infoTributaria.estab + "-" + item.cbteNC.infoTributaria.ptoEmi + "-" + item.cbteNC.infoTributaria.secuencial;
                                XmlSerializerNamespaces NamespaceObject = new XmlSerializerNamespaces();
                                NamespaceObject.Add("", "");
                                XmlSerializer mySerializer = new XmlSerializer(typeof(notaCredito));


                                myWriter = new StreamWriter(txtRuta.Text + sIdCbteFact + ".xml");

                                mySerializer.Serialize(myWriter, item.cbteNC, NamespaceObject);
                                myWriter.Close();
                                // GRABAR COMP
                                ObuscComp = new fx_Comprobantes_generados_Bus();
                                fx_Comprobante_generados_Info comprobante = new fx_Comprobante_generados_Info();
                                comprobante.IdRegistro  = sIdCbteFact;
                                comprobante.FECHA_CARGA = DateTime.Now;
                                comprobante.Estado      = "A";
                                ObuscComp.GuardarComprobantes_generados_AX(comprobante, ConexionDbcliente);
                            }
                            catch (Exception ex) { MessageBox.Show(ex.Message); }
                        }

                        // si es guia de remision
                        else if (item.TipoCbte == eTipoComprobante.Guia)
                        {
                            try
                            {
                                sIdCbteFact = sIdCbteFact = item.cbtGR.infoTributaria.razonSocial.Substring(0, 3) + "-" + eTipoCodComprobante.GUI + "-" + item.cbtGR.infoTributaria.estab + "-" + item.cbtGR.infoTributaria.ptoEmi + "-" + item.cbtGR.infoTributaria.secuencial;
                                XmlSerializerNamespaces NamespaceObject = new XmlSerializerNamespaces();
                                NamespaceObject.Add("", "");
                                XmlSerializer mySerializer = new XmlSerializer(typeof(guiaRemision));


                                myWriter = new StreamWriter(txtRuta.Text + sIdCbteFact + ".xml");



                                //StreamWriter myWriter = new StreamWriter(txtRuta.Text + sIdCbteFact + ".xml");
                                mySerializer.Serialize(myWriter, item.cbtGR, NamespaceObject);
                                myWriter.Close();
                                // GRABAR COMP
                                ObuscComp = new fx_Comprobantes_generados_Bus();
                                fx_Comprobante_generados_Info comprobante = new fx_Comprobante_generados_Info();
                                comprobante.IdRegistro  = sIdCbteFact;
                                comprobante.FECHA_CARGA = DateTime.Now;
                                comprobante.Estado      = "A";
                                ObuscComp.GuardarComprobantes_generados_AX(comprobante, ConexionDbcliente);
                            }
                            catch (Exception ex) { MessageBox.Show(ex.Message); }
                        }
                        // si es nota debito
                        else if (item.TipoCbte == eTipoComprobante.NotaDeb)
                        {
                            try
                            {
                                sIdCbteFact = sIdCbteFact = item.cbteDeb.infoTributaria.razonSocial.Substring(0, 3) + "-" + eTipoCodComprobante.NTD + "-" + item.cbteDeb.infoTributaria.estab + "-" + item.cbteDeb.infoTributaria.ptoEmi + "-" + item.cbteDeb.infoTributaria.secuencial;
                                XmlSerializerNamespaces NamespaceObject = new XmlSerializerNamespaces();
                                NamespaceObject.Add("", "");
                                XmlSerializer mySerializer = new XmlSerializer(typeof(notaDebito));

                                myWriter = new StreamWriter(txtRuta.Text + sIdCbteFact + ".xml");



                                //StreamWriter myWriter = new StreamWriter(txtRuta.Text + sIdCbteFact + ".xml");
                                mySerializer.Serialize(myWriter, item.cbteDeb, NamespaceObject);
                                myWriter.Close();
                                // GRABAR COMP
                                ObuscComp = new fx_Comprobantes_generados_Bus();
                                fx_Comprobante_generados_Info comprobante = new fx_Comprobante_generados_Info();
                                comprobante.IdRegistro  = sIdCbteFact;
                                comprobante.FECHA_CARGA = DateTime.Now;
                                comprobante.Estado      = "A";
                                ObuscComp.GuardarComprobantes_generados_AX(comprobante, ConexionDbcliente);
                            }
                            catch (Exception ex) { MessageBox.Show(ex.Message); }
                        }
                    }
                }

                refresh_archivos();
            }
            catch (Exception ex)
            {
            }
            finally
            {
            }
        }