private void SFbwConsultaPorcentajesGasolina_DoWork(object sender, DoWorkEventArgs e) { DataTable dtProductos; using (Generales modGen = new Generales()) { dtProductos = modGen.ObtenerProductosGasolina(); } e.Result = dtProductos; }
//Get Vendor Pass public JsonVndrPass GetVndrPassREST(string strRfc) { JsonVndrPass retorno = new JsonVndrPass(); string VndrPassEn = string.Empty; VndrPassEn = Generales.GetVndrPass(strRfc); retorno.RFC = strRfc; retorno.VNDRPASS = biSafe.clsRijndael.Decrypt(VndrPassEn); /*Return*/ return(retorno); }
//Genera Referncias public RestResponse GenerarReferenciaREST(string SOURCE_REQ, int ID_SEQ_NUM, string DOCUMENT_ID, int DAYS_DURATION, decimal AMOUNT) { RestResponse data = new RestResponse(); if (!string.IsNullOrEmpty(DOCUMENT_ID)) { string UAG_BNK_ID_REF = Generales.CalculateReference(ID_SEQ_NUM, DOCUMENT_ID.ToInteger(), DateTime.Now.AddDays(DAYS_DURATION), AMOUNT); DateTime END_DATE = DateTime.Now.AddDays(DAYS_DURATION); PRDUAGPKEntities context = new PRDUAGPKEntities(); PS_UAG_REF_BNK_TBL log = new PS_UAG_REF_BNK_TBL { GUID = Guid.NewGuid().ToString(), AMOUNT = AMOUNT, SOURCE_REQ = SOURCE_REQ, ID_SEQ_NUM = ID_SEQ_NUM, DOCUMENT_ID = DOCUMENT_ID.ToString(), DAYS_DURATION = DAYS_DURATION, UAG_BNK_ID_REF = UAG_BNK_ID_REF, END_DATE = END_DATE, CREATE_DATE = DateTime.Now }; context.PS_UAG_REF_BNK_TBL.Add(log); context.SaveChanges(); data = new RestResponse() { response = true, message = "Referencia generada correctamente", ID_SEQ_NUM = ID_SEQ_NUM, DOCUMENT_ID = DOCUMENT_ID, DAYS_DURATION = DAYS_DURATION, AMOUNT = AMOUNT, END_DATE = string.Format("{0:yyyy-MM-dd}", END_DATE), UAG_BNK_ID_REF = UAG_BNK_ID_REF }; } else { data = new RestResponse() { response = false, message = "El parametro DOCUMENT_ID no tiene un formato correcto" }; } return(data); }
void NodoAgregadoEventHandler(NodosXbee e) { if (e.TipoDispositivo == XbeeUtils.Enumeraciones.TipoDispositivo.Dispensador) { DataTable dtCaras; using (Generales modGEN = new Generales()) { dtCaras = modGEN.GetTable("select DISTINCT numPosicion FROM posicion WHERE idXbee = " + e.IdXbee); } if (dtCaras != null && dtCaras.Rows.Count > 0) { foreach (DataRow row in dtCaras.Rows) { if (ListadoObjetosCaras == null) { ListadoObjetosCaras = new List <ctrCara>(); } ctrCara newCara1 = new ctrCara(); newCara1.NumCara = Convert.ToInt32(row[0]); newCara1.EstadoCara = EnumEstadoCara.Normal; newCara1.NombreCara = "Cara " + newCara1.NumCara.ToString(); newCara1.idXbee = e.IdXbee; newCara1.NombreNodo = e.Nombre; FloatPanelDispositivos.Controls.Add(newCara1); ListadoObjetosCaras.Add(newCara1); } } } else if (e.TipoDispositivo == XbeeUtils.Enumeraciones.TipoDispositivo.moduloPOS) { using (Generales modGEN = new Generales()) { DataTable dtPOS = modGEN.GetTable("select nomXbee FROM xbee WHERE idXbee = " + e.IdXbee); if (dtPOS != null && dtPOS.Rows.Count > 0) { ctrPOS newPOS = new ctrPOS(); newPOS.NombrePOS = dtPOS.Rows[0][0].ToString(); newPOS.idXbee = e.IdXbee; FloatPanelDispositivos.Controls.Add(newPOS); newPOS.Dock = DockStyle.Fill; newPOS.EstableceColor(); } } } }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); MySqlConnection xConnection = new MySqlConnection(); xConnection.ConnectionString = "Server=localhost;Database=you_li;Uid=root;Pwd=ml336013;"; Generales xGen = new Generales(); if (xGen.ConectarDB(ref xConnection)) { Application.Run(new Main(xConnection)); if (!xGen.DesconectarDB(ref xConnection)) { MessageBox.Show(xGen.sLastError); } } else { MessageBox.Show(xGen.sLastError); } }
public ActionResult StartRecovery(RecoveryViewModel model) { try { if (!ModelState.IsValid) { return(View(model)); } string token = Generales.GetSha256(Guid.NewGuid().ToString()); using (Models.LateOSEntities db = new Models.LateOSEntities()) { var oUser = db.V_Usuarios.Where(d => d.clte_Correo == model.Email).FirstOrDefault(); if (oUser != null) { tbUsuarios tbUser = db.tbUsuarios.Where(x => x.usu_Id == oUser.usu_Id).FirstOrDefault(); if (tbUser != null) { tbUser.usu_Token = token; db.Entry(tbUser).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } //enviar mail Generales.SendEmail(oUser.clte_Correo, token); } } ViewBag.Message = "El correo se envió correctamente"; return(View()); } catch (Exception ex) { ViewBag.Error = "Se produjo un error"; return(View()); } }
public APCFull UsingXMLDocument(XmlDocument xmlDoc) { XmlNodeList ItemNodes = xmlDoc.SelectNodes("//Resultado"); APCFull APC = new APCFull(); Generales[] arrayG = new Generales[1]; Resumen[] arrayR = new Resumen[1]; Detalle[] arrayD = new Detalle[1]; ReferenciasCanceladas[] arrayRC = new ReferenciasCanceladas[1]; Movimientos[] arrayM = new Movimientos[1]; // Validacion foreach (XmlNode ItemNode in ItemNodes) { //TextBox1.Text = ItemNode.Name + " " + ItemNode.InnerXml; foreach (XmlNode Item in ItemNode.SelectSingleNode("Validacion")) { APC.Valido = Item.InnerText; } } if (APC.Valido == "0") { APC.Mensaje = "Error en Web Service de APC"; return(APC); } // Estatus foreach (XmlNode ItemNode in ItemNodes) { //TextBox1.Text = ItemNode.Name + " " + ItemNode.InnerXml; foreach (XmlNode Item in ItemNode.SelectSingleNode("Estatus")) { APC.Estatus = Item.InnerText; } } if (APC.Estatus == "0") { APC.Mensaje = "Cliente no existe"; return(APC); } APC.Mensaje = "Ok"; // Generales int i = 0; foreach (XmlNode ItemNode in ItemNodes) { //TextBox1.Text = ItemNode.Name + " " + ItemNode.InnerXml; if (ItemNode.SelectSingleNode("Generales") != null) { foreach (XmlNode Item in ItemNode.SelectSingleNode("Generales")) { Generales g = new Generales(); foreach (XmlNode Item2 in Item) { switch (Item2.Name) { case "NOMBRE": g.NOMBRE = APCEncrypt.ScorePlusEncrypt.DecryptString(Item2.InnerText); break; case "APELLIDO": g.APELLIDO = APCEncrypt.ScorePlusEncrypt.DecryptString(Item2.InnerText); break; case "IDENT_CLIE": g.IDENT_CLIE = APCEncrypt.ScorePlusEncrypt.DecryptString(Item2.InnerText); break; case "FEC_CREACION": g.FEC_CREACION = Item2.InnerText.Length > 0 ? APCEncrypt.ScorePlusEncrypt.DecryptString(Item2.InnerText) : ""; break; case "NOM_ASOC": g.NOM_ASOC = APCEncrypt.ScorePlusEncrypt.DecryptString(Item2.InnerText); break; case "FEC_DEFUNCION": g.FEC_DEFUNCION = Item2.InnerText.Length > 0 ? APCEncrypt.ScorePlusEncrypt.DecryptString(Item2.InnerText) : ""; break; } } arrayG[i] = g; i++; Array.Resize <Generales>(ref arrayG, i); } } } APC.GEN = arrayG; // Resumen i = 0; foreach (XmlNode ItemNode in ItemNodes) { //TextBox1.Text = ItemNode.Name + " " + ItemNode.InnerXml; if (ItemNode.SelectSingleNode("Resumen") != null) { foreach (XmlNode Item in ItemNode.SelectSingleNode("Resumen")) { Resumen g = new Resumen(); foreach (XmlNode Item2 in Item) { switch (Item2.Name) { case "RELACION": g.RELACION = APCEncrypt.ScorePlusEncrypt.DecryptString(Item2.InnerText); break; case "CANTIDAD": g.CANTIDAD = APCEncrypt.ScorePlusEncrypt.DecryptString(Item2.InnerText); break; case "MONTO": g.MONTO = APCEncrypt.ScorePlusEncrypt.DecryptString(Item2.InnerText); break; case "SALDO_ACTUAL": g.SALDO_ACTUAL = APCEncrypt.ScorePlusEncrypt.DecryptString(Item2.InnerText); break; } } arrayR[i] = g; i++; Array.Resize <Resumen>(ref arrayR, i + 1); } } } APC.RES = arrayR; // Detalle i = 0; foreach (XmlNode ItemNode in ItemNodes) { //TextBox1.Text = ItemNode.Name + " " + ItemNode.InnerXml; if (ItemNode.SelectSingleNode("Detalle") != null) { foreach (XmlNode Item in ItemNode.SelectSingleNode("Detalle")) { Detalle g = new Detalle(); foreach (XmlNode Item2 in Item) { switch (Item2.Name) { case "NOM_ASOC": g.NOM_ASOC = APCEncrypt.ScorePlusEncrypt.DecryptString(Item2.InnerText); break; case "DESCR_CORTA_RELA": g.DESCR_CORTA_RELA = APCEncrypt.ScorePlusEncrypt.DecryptString(Item2.InnerText); break; case "FEC_INICIO_REL": g.FEC_INICIO_REL = APCEncrypt.ScorePlusEncrypt.DecryptString(Item2.InnerText); break; case "FEC_FIN_REL": g.FEC_FIN_REL = Item2.InnerText.Length > 0 ? APCEncrypt.ScorePlusEncrypt.DecryptString(Item2.InnerText) : ""; break; case "MONTO_ORIGINAL": g.MONTO_ORIGINAL = APCEncrypt.ScorePlusEncrypt.DecryptString(Item2.InnerText); break; case "NUM_PAGOS": g.NUM_PAGOS = APCEncrypt.ScorePlusEncrypt.DecryptString(Item2.InnerText); break; case "DESCR_FORMA_PAGO": g.DESCR_FORMA_PAGO = APCEncrypt.ScorePlusEncrypt.DecryptString(Item2.InnerText); break; case "IMPORTE_PAGO": g.IMPORTE_PAGO = APCEncrypt.ScorePlusEncrypt.DecryptString(Item2.InnerText); break; case "FEC_ULTIMO_PAGO": g.FEC_ULTIMO_PAGO = Item2.InnerText.Length > 0 ? APCEncrypt.ScorePlusEncrypt.DecryptString(Item2.InnerText) : ""; break; case "MONTO_ULTIMO_PAGO": g.MONTO_ULTIMO_PAGO = APCEncrypt.ScorePlusEncrypt.DecryptString(Item2.InnerText); break; case "DESCR_OBS_CORTA": g.DESCR_OBS_CORTA = APCEncrypt.ScorePlusEncrypt.DecryptString(Item2.InnerText); break; case "SALDO_ACTUAL": g.SALDO_ACTUAL = APCEncrypt.ScorePlusEncrypt.DecryptString(Item2.InnerText); break; case "NUM_DIAS_ATRASO": g.NUM_DIAS_ATRASO = APCEncrypt.ScorePlusEncrypt.DecryptString(Item2.InnerText); break; case "HISTORIA": g.HISTORIA = APCEncrypt.ScorePlusEncrypt.DecryptString(Item2.InnerText); break; case "MONTO_CODIFICADO": g.MONTO_CODIFICADO = APCEncrypt.ScorePlusEncrypt.DecryptString(Item2.InnerText); break; case "FEC_ACTUALIZACION": g.FEC_ACTUALIZACION = APCEncrypt.ScorePlusEncrypt.DecryptString(Item2.InnerText); break; case "COD_GRUPO_ECON": g.COD_GRUPO_ECON = APCEncrypt.ScorePlusEncrypt.DecryptString(Item2.InnerText); break; case "TIPO_ASOC": g.TIPO_ASOC = APCEncrypt.ScorePlusEncrypt.DecryptString(Item2.InnerText); break; case "NUM_REFER": g.NUM_REFER = APCEncrypt.ScorePlusEncrypt.DecryptString(Item2.InnerText); break; } } arrayD[i] = g; i++; Array.Resize <Detalle>(ref arrayD, i + 1); } } } APC.DET = arrayD; // ReferenciasCanceladas i = 0; foreach (XmlNode ItemNode in ItemNodes) { //TextBox1.Text = ItemNode.Name + " " + ItemNode.InnerXml; if (ItemNode.SelectSingleNode("ReferenciasCanceladas") != null) { foreach (XmlNode Item in ItemNode.SelectSingleNode("ReferenciasCanceladas")) { ReferenciasCanceladas g = new ReferenciasCanceladas(); foreach (XmlNode Item2 in Item) { switch (Item2.Name) { case "NOM_ASOC": g.NOM_ASOC = APCEncrypt.ScorePlusEncrypt.DecryptString(Item2.InnerText); break; case "DESCR_CORTA_RELA": g.DESCR_CORTA_RELA = APCEncrypt.ScorePlusEncrypt.DecryptString(Item2.InnerText); break; case "FEC_INICIO_REL": g.FEC_INICIO_REL = APCEncrypt.ScorePlusEncrypt.DecryptString(Item2.InnerText); break; case "FEC_FIN_REL": g.FEC_FIN_REL = Item2.InnerText.Length > 0 ? APCEncrypt.ScorePlusEncrypt.DecryptString(Item2.InnerText) : ""; break; case "MONTO_ORIGINAL": APCEncrypt.ScorePlusEncrypt.DecryptString(Item2.InnerText); break; case "FEC_LIQUIDACION": g.FEC_LIQUIDACION = APCEncrypt.ScorePlusEncrypt.DecryptString(Item2.InnerText); break; case "HISTORIA": g.HISTORIA = APCEncrypt.ScorePlusEncrypt.DecryptString(Item2.InnerText); break; case "DESCR_OBS_CORTA": g.DESCR_OBS_CORTA = APCEncrypt.ScorePlusEncrypt.DecryptString(Item2.InnerText); break; case "MONTO_CODIFICADO": g.MONTO_CODIFICADO = APCEncrypt.ScorePlusEncrypt.DecryptString(Item2.InnerText); break; case "NUM_REFER": g.NUM_REFER = APCEncrypt.ScorePlusEncrypt.DecryptString(Item2.InnerText); break; case "COD_GRUPO_ECON": g.COD_GRUPO_ECON = APCEncrypt.ScorePlusEncrypt.DecryptString(Item2.InnerText); break; case "TIPO_ASOC": g.TIPO_ASOC = APCEncrypt.ScorePlusEncrypt.DecryptString(Item2.InnerText); break; } } arrayRC[i] = g; i++; Array.Resize <ReferenciasCanceladas>(ref arrayRC, i + 1); } } } APC.REF = arrayRC; // Movimientos i = 0; foreach (XmlNode ItemNode in ItemNodes) { //TextBox1.Text = ItemNode.Name + " " + ItemNode.InnerXml; if (ItemNode.SelectSingleNode("Movimientos") != null) { foreach (XmlNode Item in ItemNode.SelectSingleNode("Movimientos")) { Movimientos m = new Movimientos(); foreach (XmlNode Item2 in Item) { switch (Item2.Name) { case "NOM_ASOC": m.NOM_ASOC = APCEncrypt.ScorePlusEncrypt.DecryptString(Item2.InnerText); break; case "FEC1": m.FEC1 = APCEncrypt.ScorePlusEncrypt.DecryptString(Item2.InnerText); break; case "IDENT_CLIE": m.IDENT_CLIE = APCEncrypt.ScorePlusEncrypt.DecryptString(Item2.InnerText); break; } } arrayM[i] = m; i++; Array.Resize <Movimientos>(ref arrayM, i + 1); } } } APC.MOV = arrayM; // Score Score gsc = new Score(); foreach (XmlNode ItemNode in ItemNodes) { //TextBox1.Text = ItemNode.Name + " " + ItemNode.InnerXml; if (ItemNode.SelectSingleNode("Score") == null) { //gsc.SCORE = "-1"; //gsc.PI = "-1"; //gsc.EXCLUSION = ""; //APC.SC = gsc; return(APC); } foreach (XmlNode Item in ItemNode.SelectSingleNode("Score")) { foreach (XmlNode Item2 in Item) { switch (Item2.Name) { case "SCORE": gsc.SCORE = APCEncrypt.ScorePlusEncrypt.DecryptString(Item2.InnerText); break; case "PI": gsc.PI = APCEncrypt.ScorePlusEncrypt.DecryptString(Item2.InnerText); break; case "EXCLUSION": gsc.EXCLUSION = APCEncrypt.ScorePlusEncrypt.DecryptString(Item2.InnerText); break; } } } } APC.SC = gsc; return(APC); }
// Procesar Invoice XML public SfJsonInvoiceXML ProcesarInvoiceXMLREST(string strcarpeta, string strsource) { //produccion PRNFACTEntities contextoCFDI = new PRNFACTEntities(); string source = strsource; SfJsonInvoiceXML retorno = new SfJsonInvoiceXML(); retorno.PreExistentes = 0; retorno.Procesados = 0; retorno.CfdiError = new List <CfdiError>(); CfdiError operacionError = new CfdiError(); bool ExisteError = true; string uuid; decimal total; string strerror = string.Empty; string strLocalUrl = ConfigurationManager.AppSettings["LocalUrl"]; string strSolucionFactibleUsuario = ConfigurationManager.AppSettings["SolucionFactibleUsuario"]; string strSolucionFactiblePassword = ConfigurationManager.AppSettings["SolucionFactiblePassword"]; PRNFACTEntities contextUAG = new PRNFACTEntities(); PRDUAGPKEntities contextFSCM = new PRDUAGPKEntities(); string ip = Dns.GetHostName(); string[] filenames = new string[] { }; string host = HttpContext.Current.Request.Url.Host.ToLower(); try //Path { if (host == "localhost") { /*Local Host*/ string LocalPath = System.Environment.CurrentDirectory; filenames = Directory.GetFiles(strLocalUrl + strcarpeta + "/"); } else { filenames = Directory.GetFiles(HttpContext.Current.Server.MapPath("~/CFDI/" + strcarpeta + "/")); } } catch (IOException ex) { strerror = ex.GetType().Name + " Message " + ex.Message; } if (filenames.Any()) { foreach (string filename in filenames) { List <string> mensajesRel = new List <string>(); List <string> mensajesForm = new List <string>(); //HCR por cada uno de los XML que se lean de la Carpeta sumo un Complemento retorno.Invoice++; //Flag si existe un Error por cada uno de los archivos ExisteError = false; try { byte[] archivoXML = File.ReadAllBytes(filename); //mensajesForm = Generales.ValidateForm(archivoXML); DateTime fechatemp = DateTime.Today; //DateTime fecha1 = new DateTime(fechatemp.Year, fechatemp.Month, 1); DateTime fecha1 = new DateTime(fechatemp.Year - 1, 1, 1); DateTime fecha2; if (fechatemp.Month + 1 < 13) { fecha2 = new DateTime(fechatemp.Year, fechatemp.Month + 1, 1).AddDays(-1); } else { fecha2 = new DateTime(fechatemp.Year + 1, 1, 1).AddDays(-1); } /* DateTime openFromDate = fecha1; * DateTime openToDate = fecha2; * int OYF = 2019; * int OYT = 2020; * string UagfRFC = "UAG7806127I8";*/ /*Get Config from PS*/ string BUSSINES_UNIT = "UAG01"; DateTime openFromDate = (DateTime)contextFSCM.PS_UAG_CFDI_CNFG_V.Where(l => l.BUSINESS_UNIT == BUSSINES_UNIT).Select(l => l.OPEN_FROM_DATE).FirstOrDefault().Value.AbsoluteStart(); DateTime openToDate = (DateTime)contextFSCM.PS_UAG_CFDI_CNFG_V.Where(l => l.BUSINESS_UNIT == BUSSINES_UNIT).Select(l => l.OPEN_TO_DATE).FirstOrDefault().Value.AbsoluteEnd(); int OYF = (int)contextFSCM.PS_UAG_CFDI_CNFG_V.Where(l => l.BUSINESS_UNIT == BUSSINES_UNIT).Select(l => l.OPEN_YEAR_FROM).FirstOrDefault(); int OYT = (int)contextFSCM.PS_UAG_CFDI_CNFG_V.Where(l => l.BUSINESS_UNIT == BUSSINES_UNIT).Select(l => l.OPEN_YEAR_TO).FirstOrDefault(); string UagfRFC = (string)contextFSCM.PS_UAG_CFDI_CNFG_V.Where(l => l.BUSINESS_UNIT == BUSSINES_UNIT).Select(l => l.UAG_CFDI_RECEPTRFC).FirstOrDefault(); string userid = (string)contextFSCM.PS_UAG_CFDI_CNFG_V.Where(l => l.BUSINESS_UNIT == BUSSINES_UNIT).Select(l => l.FO_USERID).FirstOrDefault(); string pw = (string)contextFSCM.PS_UAG_CFDI_CNFG_V.Where(l => l.BUSINESS_UNIT == BUSSINES_UNIT).Select(l => l.FO_PASSWORD).FirstOrDefault(); Invoice validation = new Invoice(archivoXML, openFromDate, openToDate, OYF, OYT, UagfRFC); mensajes = validation.getValidationMessages(); if (mensajes.Count == 0 || mensajes[0].Equals("No se permiten facturas fuera del mes en curso.")) { if (!Generales.ValidateExistenceXML(archivoXML)) { //Procesa CDFI RecibeCFDPortType ws = new RecibeCFDPortTypeClient("RecibeCFDHttpsSoap12Endpoint"); recibeCFDRequest request = new recibeCFDRequest(); request.usuario = strSolucionFactibleUsuario; request.password = strSolucionFactiblePassword; request.cfd = archivoXML; recibeCFDResponse response = ws.recibeCFD(request); if ([email protected] == "OK" || ([email protected] == "ERROR" && (Generales.ValidateMessage([email protected]) ) ) ) { SaveFromXML custom = new SaveFromXML(archivoXML, source); string impuestos = Generales.getImpuestos(archivoXML, custom.UUID); string descuentos = Generales.getDescuentos(archivoXML, custom.UUID); string tipoCambio = Generales.getTipoCambio(archivoXML, custom.UUID); string subTotal = Generales.getSubtotal(archivoXML, custom.UUID); if (!impuestos.Equals("")) { Generales.DeleteUUID(custom.UUID); mensajes.Add(impuestos); } else if (!descuentos.Equals("")) { Generales.DeleteUUID(custom.UUID); mensajes.Add(descuentos); } else if (!tipoCambio.Equals("")) { Generales.DeleteUUID(custom.UUID); mensajes.Add(tipoCambio); } else if (!subTotal.Equals("")) { Generales.DeleteUUID(custom.UUID); mensajes.Add(subTotal); } else { uuid = custom.UUID; total = custom.TOTAL; UAG_LOG log = new UAG_LOG(); log.UAG_LOG_USER = UagfRFC; log.UAG_LOG_DESCR = "Se cargo una factura con UUID:" + custom.UUID; log.UAG_LOG_ACT = "Agregar"; log.UAG_LOG_URL = HttpContext.Current.Request.Url.AbsolutePath.Replace(".aspx", string.Empty); log.UAG_LOG_FEC = DateTime.Now; log.UAG_LOG_IP = host; contextoCFDI.UAG_LOG.Add(log); contextoCFDI.SaveChanges(); UAG_UUID_LOG log2 = new UAG_UUID_LOG(); log2.SOURCE = source; log2.UAG_CFDI_UUID = custom.UUID; log2.UAG_LOG_FEC = DateTime.Now; log2.UAG_LOG_ACCCION = "A"; log2.UAG_LOG_DESCR = "Save XML"; log2.UAG_LOG_IP = host; contextoCFDI.UAG_UUID_LOG.Add(log2); contextoCFDI.SaveChanges(); mensajes.Add("Factura cargada correctamente"); } } } } else { string errores = ""; foreach (string mensaje in mensajes) { errores += mensaje + "<br>"; } operacionError.FileName = System.IO.Path.GetFileName(filename); operacionError.Detalle = errores; retorno.CfdiError.Add(operacionError); ExisteError = true; } } catch (System.Exception) { //retorno.Errores++; //retorno.DetallesErrores.Add(aux); //response.Error = true; } if (ExisteError) { retorno.ConErrores++; } } } else { // No se Encontraron Archivos en la Carpeta } return(retorno); }
// ProcesarComplementos public SfJsonComplementos ProcesarComplementosREST(string carpeta) { SfJsonComplementos retorno = new SfJsonComplementos(); retorno.PreExistentes = 0; retorno.Procesados = 0; retorno.ComplementoError = new List <ComplementoError>(); ComplementoError operacionError = new ComplementoError(); bool ExisteError = true; string LocalUrl = ConfigurationManager.AppSettings["LocalUrl"]; string strLocalUrl = ConfigurationManager.AppSettings["LocalUrl"]; string strerror = string.Empty; OperacionComplemento aux = null; PRNFACTEntities contextUAG = new PRNFACTEntities(); string ip = Dns.GetHostName(); string RFC = "XAXX010101000"; string[] filenames = new string[] { }; string host = HttpContext.Current.Request.Url.Host.ToLower(); try { if (host == "localhost") { /*Local Host*/ string LocalPath = System.Environment.CurrentDirectory; filenames = Directory.GetFiles(strLocalUrl + carpeta + "/"); } else { filenames = Directory.GetFiles(HttpContext.Current.Server.MapPath("~/Complementos/" + carpeta + "/")); } } catch (IOException ex) { strerror = ex.GetType().Name + " Message " + ex.Message; } if (filenames.Any()) { foreach (string filename in filenames) { List <string> mensajesRel = new List <string>(); List <string> mensajesForm = new List <string>(); //HCR por cada uno de los XML que se lean de la Carpeta sumo un Complemento retorno.Complementos++; //Flag si existe un Error por cada uno de los archivos ExisteError = false; try { byte[] archivoXML = File.ReadAllBytes(filename); mensajesForm = Generales.ValidateForm(archivoXML); if (mensajesForm.Count == 0) { if (!Generales.ValidateExistenceXMLCompag(archivoXML)) { if (mensajesRel.Count == 0) { string uuid = string.Empty; SaveCompag custom = new SaveCompag(archivoXML, "COM", ref uuid, System.IO.Path.GetFileName(filename), out aux); //Solo si se procesa el CFDI sumo a procesados retorno.Procesados++; //response.Detalle += "Archivo:" + System.IO.Path.GetFileName(filename) + " UUID:" + uuid + "<br />"; UAG_LOG log = new UAG_LOG(); log.UAG_LOG_USER = RFC; log.UAG_LOG_DESCR = "Se cargo un complemento de pago con UUID:" + uuid; log.UAG_LOG_ACT = "Agregar"; log.UAG_LOG_URL = HttpContext.Current.Request.Url.AbsolutePath.Replace(".aspx", string.Empty); log.UAG_LOG_FEC = DateTime.Now; log.UAG_LOG_IP = ip; contextUAG.UAG_LOG.Add(log); contextUAG.SaveChanges(); UAG_UUID_LOG log2 = new UAG_UUID_LOG(); log2.SOURCE = "COM"; log2.UAG_CFDI_UUID = uuid; log2.UAG_LOG_FEC = DateTime.Now; log2.UAG_LOG_ACCCION = "a"; log2.UAG_LOG_DESCR = "Save XML"; log2.UAG_LOG_IP = ip; contextUAG.UAG_UUID_LOG.Add(log2); contextUAG.SaveChanges(); } else { string errores = ""; foreach (string mensaje in mensajesRel) { errores += mensaje + "<br>"; } } } else { //Por cada complemento ya existente que se trato de cargar le sumo uno retorno.PreExistentes++; UAG_LOG log = new UAG_LOG(); log.UAG_LOG_USER = RFC; log.UAG_LOG_DESCR = "Se trato de cargar un complemento ya cargado"; log.UAG_LOG_ACT = "Error"; log.UAG_LOG_URL = HttpContext.Current.Request.Url.AbsolutePath.Replace(".aspx", string.Empty); log.UAG_LOG_FEC = DateTime.Now; log.UAG_LOG_IP = ip; contextUAG.UAG_LOG.Add(log); contextUAG.SaveChanges(); } } else { string errores = ""; foreach (string mensaje in mensajesForm) { errores += mensaje; } operacionError.FileName = System.IO.Path.GetFileName(filename); operacionError.Detalle = errores; retorno.ComplementoError.Add(operacionError); ExisteError = true; } } catch (System.Exception) { //retorno.Errores++; //retorno.DetallesErrores.Add(aux); //response.Error = true; } if (ExisteError) { retorno.ConErrores++; } } } else { //retorno.Detalle += "<br />No se encontraron archivos en la carpeta indicada"; } return(retorno); }