private void timbrar() { Models.Configuration configuracion = new Models.Configuration(); using (configuracion) { List <Models.Configuration> config = configuracion.getConfiguration(); //Instancias del timbrado Timbrado.StampSOAP selloSOAP = new Timbrado.StampSOAP(); stamp oStamp = new stamp(); stampResponse selloResponse = new stampResponse(); //Cargas tu archivo xml XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(config[0].Ruta_factura + txtFolio.Text + ".xml"); //xmlDocument.Load(config[0].Ruta_factura + txtFolio.Text + ".xml"); //Conviertes el archivo en byte byte[] byteXmlDocument = Encoding.UTF8.GetBytes(xmlDocument.OuterXml); //Conviertes el byte resultado en base64 string stringByteXmlDocument = Convert.ToBase64String(byteXmlDocument); //Convirtes el resultado nuevamente a byte byteXmlDocument = Convert.FromBase64String(stringByteXmlDocument); //Timbras el archivo oStamp.xml = byteXmlDocument; oStamp.username = "******"; oStamp.password = "******"; //Generamos request String usuario; usuario = Environment.UserName; String url = config[0].Ruta_factura; StreamWriter XML = new StreamWriter(url + "SOAP_Request.xml"); //Direccion donde guardaremos el SOAP Envelope XmlSerializer soap = new XmlSerializer(oStamp.GetType()); //Obtenemos los datos del objeto oStamp que contiene los parámetros de envió y es de tipo stamp() soap.Serialize(XML, oStamp); XML.Close(); //Recibes la respuesta de timbrado selloResponse = selloSOAP.stamp(oStamp); try { MessageBox.Show("No se timbro el XML" + "\nCódigo de error: " + selloResponse.stampResult.Incidencias[0].CodigoError.ToString() + "\nMensaje: " + selloResponse.stampResult.Incidencias[0].MensajeIncidencia); } catch (Exception) { MessageBox.Show(selloResponse.stampResult.CodEstatus.ToString()); Models.Facturas factura = new Models.Facturas(); using (factura) { factura.Uuid = selloResponse.stampResult.UUID.ToString(); factura.Folio = Convert.ToInt32(txtFolio.Text); factura.Xml = selloResponse.stampResult.xml.ToString(); factura.update_uuid(); } StreamWriter XMLL = new StreamWriter(url + txtFolio.Text + ".xml"); XMLL.Write(selloResponse.stampResult.xml); XMLL.Close(); File.Delete(url + "SOAP_Request.xml"); } } }
private async void button1_Click(object sender, EventArgs e) { Models.Folios folios = new Models.Folios(); List <Models.Folios> folio = folios.getFolios(); Models.Facturas facturas = new Models.Facturas(); facturas.Folio = Convert.ToInt16(txtFolio.Text); facturas.Serie = folio[0].Serie; facturas.Cliente = Convert.ToInt16(txtIdCliente.Text); facturas.Subtotal = Convert.ToDouble(txtSubtotal.Text); facturas.Total = Convert.ToDouble(txtTotal.Text); facturas.Pago = txtMPago.Text; facturas.create(); Models.Det_facturas detalle_facturas = new Models.Det_facturas(); detalle_facturas.Factura = Convert.ToInt16(txtFolio.Text); foreach (DataGridViewRow row in dtProductos.Rows) { detalle_facturas.Id_producto = Convert.ToInt16(row.Cells["id_producto"].Value.ToString()); detalle_facturas.Cantidad = Convert.ToDouble(row.Cells["cantidad"].Value.ToString()); detalle_facturas.P_u = Convert.ToDouble(row.Cells["pu"].Value.ToString()); detalle_facturas.create(); } switch (cbTipo.SelectedItem.ToString()) { case "Ticket": Models.Ticket_a_facturas tic_a_fact = new Models.Ticket_a_facturas(); foreach (DataGridViewRow row in dtdocumentos.Rows) { tic_a_fact.Factura = Convert.ToInt16(txtFolio.Text); tic_a_fact.Ticket = Convert.ToInt16(row.Cells["folio"].Value.ToString()); tic_a_fact.createrelacion(); } break; case "Traspasos": Models.Traspasos_a_facturas tras_a_factura = new Models.Traspasos_a_facturas(); foreach (DataGridViewRow row in dtdocumentos.Rows) { tras_a_factura.Traspaso = Convert.ToInt16(row.Cells["folio"].Value.ToString()); tras_a_factura.Factura = Convert.ToInt16(txtFolio.Text); tras_a_factura.create_relacion(); } break; } xml2(); }