//Función para verificar si el acceso fue correcto. public bool isIDLogCorrect(string idacceso) { webservFacturas.conexion.conector Conexion = new webservFacturas.conexion.conector(); string sql = "SELECT * FROM clientesprepago WHERE iidacceso = '" + idacceso + "' AND iactivo = 1"; int cantidad = 0; DataTable dt = new DataTable(); dt = webservFacturas.conexion.conector.Consultasql(sql); cantidad = Convert.ToInt16(dt.Rows.Count.ToString()); if (cantidad == 0) return false; else return true; }
//Función para Guardar el Registro de errorres en Base de Datos. public bool SaveErrorLog(string UUID, string codigoerror, string msg, string IID) { webservFacturas.conexion.conector conexion = new webservFacturas.conexion.conector(); string sql = "INSERT INTO TmpSol_Intentos_Validaciones(vchuuid,vchcodError,vchmsgError,iid) VALUES('" + UUID + "','" + codigoerror + "','" + msg + "', '"+ IID +"')"; /* string sql = "UPDATE TmpSol_Intentos_Validaciones SET (vchuuid, vchcodError, vchmsgError,iid ) values('" + UUID + "','" + codigoerror + "','" + msg + "','" + IID + "')"; */ return conexion.InsertaSql(sql); }
//Función para Insertar Registro de Acceso a la Base de Datos. public void Inserta_LogAcceso(string xml, string UUID, string msgadd) { //Se obtiene la direccion IP del cliente. IPAddress ip = Dns.GetHostAddresses(Dns.GetHostName()).Where(address => address.AddressFamily == AddressFamily.InterNetwork).First(); webservFacturas.conexion.conector conexion = new webservFacturas.conexion.conector(); string sql = "INSERT INTO WebService (vchIP, vchUUIDAcceso, vchXML ) values('" +ip+ "','" + UUID + "','" + xml + "')"; conexion.InsertaSql(sql); /* string sql = "" + "INSERT INTO WebService " + "(vchUUIDAcceso )" + "VALUES" + "('" + UUID + "')"; conexion.InsertaSql(sql);*/ }
//Función para insertar Petición. public string Inserta_FirstPeticion(string xml, string UUID, string idacceso,string msgadd, string versionp) { webservFacturas.conexion.conector conexion = new webservFacturas.conexion.conector(); string pstrClientAddress = HttpContext.Current.Request.UserHostAddress; //Creamos el XMLDocument. XmlDocument doc2 = new XmlDocument(); //Cargamos el XML doc2.LoadXml(xml); //Inicializamos las variables. string total = ""; string version = ""; string tagcomprobante = ""; string tagemisor = ""; string tagreceptor = ""; //Verificamos si la versión es 2.0 o 2.2 y asignamos los tags correspondientes. if ((versionp == "2.0") || (versionp == "2.2")) { tagcomprobante = "Comprobante"; tagemisor = "Emisor"; tagreceptor = "Receptor"; } //Verificamos si la versión es 3.0 o 3.2 y asignamos los tags correspondientes. if ((versionp == "3.0") || (versionp == "3.2")) { tagcomprobante = "cfdi:Comprobante"; tagemisor = "cfdi:Emisor"; tagreceptor = "cfdi:Receptor"; } //Leemos el nodo "Comprobante". XmlNodeList elemList = doc2.GetElementsByTagName(tagcomprobante); for (int i = 0; i < elemList.Count; i++) { //Asignamos los atributos a variables. total = elemList[i].Attributes["total"].Value; version = elemList[i].Attributes["version"].Value; } //Inicializamos las variables. string RFC = ""; string razon_emisor = ""; //Leemos el Nodo Emisor. XmlNodeList EmisorList = doc2.GetElementsByTagName(tagemisor); for (int i = 0; i < EmisorList.Count; i++) { //Asignamos los atributos a variables. RFC = EmisorList[i].Attributes["rfc"].Value; razon_emisor = EmisorList[i].Attributes["nombre"].Value; } //Inicializamos las variables string rfc_receptor = ""; string razon_receptor = ""; //Leemos el nodo receptor. XmlNodeList ReceptorList = doc2.GetElementsByTagName(tagreceptor); for (int i = 0; i < ReceptorList.Count; i++) { //Asignamos los atributos a variables. rfc_receptor = ReceptorList[i].Attributes["rfc"].Value; razon_receptor = ReceptorList[i].Attributes["nombre"].Value; } string sql = ""+ "INSERT INTO TmpSol_Intentos_Validaciones"+ "(iidacceso, vchip, vchuuid, dfecha_ingreso, vchXML_cfd, vchRFC_emite, vchmsg, vchRazonEmite, vchRfc_receptor, vchRazon_receptor, total, vchversion )" + "VALUES"+ "('" + idacceso + "','" + pstrClientAddress + "', '" + UUID + "', GETDATE(), '" + xml + "', @vchRFC_emite,'" + msgadd + "', @vchRazonEmite, @vchRfc_receptor, @vchRazon_receptor,'" + total + "', '" + version + "')"; SqlCommand command = new SqlCommand(sql, webservFacturas.conexion.conector.ConexionSQL()); command.Parameters.Add("@vchRFC_emite", SqlDbType.VarChar); command.Parameters["@vchRFC_emite"].Value = RFC; command.Parameters.Add("@vchRazonEmite", SqlDbType.VarChar); command.Parameters["@vchRazonEmite"].Value = razon_emisor; command.Parameters.Add("@vchRfc_receptor", SqlDbType.VarChar); command.Parameters["@vchRfc_receptor"].Value = rfc_receptor; command.Parameters.Add("@vchRazon_receptor", SqlDbType.VarChar); command.Parameters["@vchRazon_receptor"].Value = razon_receptor; command.ExecuteNonQuery(); conexion.InsertaSql(sql); //Obtenemos el código insertado. sql=" SELECT top 1 iid FROM TmpSol_Intentos_Validaciones WHERE iidacceso = '"+idacceso+"' AND vchuuid = '"+UUID+"' ORDER BY dfecha_ingreso DESC "; DataTable data = new DataTable(); data = webservFacturas.conexion.conector.Consultasql(sql); string IID = data.Rows[0]["iid"].ToString(); return IID; }
//Función para guardar el XML en la Base de Datos public bool GuardaCFDI(string xml, string UUID, string IID) { string correctString = xml.Replace(" schemaLocation", " xsi:schemaLocation"); webservFacturas.conexion.conector conexion = new webservFacturas.conexion.conector(); string sql = "UPDATE TmpSol_Intentos_Validaciones SET vchXML_cfdi = @vchXML_cfdi, iCorrecto=1, dfecha_salida=GETDATE() WHERE vchuuid = '" + UUID + "' AND iid = " + IID; //return conexion.InsertaSql(sql); SqlCommand command = new SqlCommand(sql, webservFacturas.conexion.conector.ConexionSQL()); command.Parameters.Add("@vchXML_cfdi", SqlDbType.VarChar); command.Parameters["@vchXML_cfdi"].Value = correctString;// ////////////////// try { command.ExecuteNonQuery(); return true; } catch (Exception exp) { return false; } }
//Función para Guardar el Registro de errorres en Base de Datos. public bool SaveErrorLog(string UUID, string codigoerror, string msg, string IID) { webservFacturas.conexion.conector conexion = new webservFacturas.conexion.conector(); string sql = "UPDATE TmpSol_Intentos_Validaciones SET vchcodError = '"+codigoerror+"', vchmsgError = '"+msg+"', dfecha_salida = GETDATE() "+ " WHERE vchuuid = '" + UUID + "' AND iid = " + IID; return conexion.InsertaSql(sql); }
//Función para Insertar Registro de Acceso a la Base de Datos. public void Inserta_LogAcceso(string xml, string UUID, string msgadd) { webservFacturas.conexion.conector conexion = new webservFacturas.conexion.conector(); string sql = "" + "INSERT INTO WebService " + "(dfecha, vchLocation, vchUsuario, vchMensaje )" + "VALUES" + "(GETDATE(), 'WSValida','" + UUID + "','-" + xml + "')"; conexion.InsertaSql(sql); }