bool GenericReadRecord(string xCaller, int iODBCID, string ySQL, string xTABLE, string xWHERE, string[] RecordReturn, bool bUserNotification) { bool RC = true; RSLib_String.MyStringArrayEmpty(RecordReturn); string xSQL = ySQL; if (ySQL.Length == 0) { xSQL = "SELECT * FROM " + xTABLE; if (xWHERE.Length > 0) { xSQL += " WHERE " + xWHERE; } } if (iODBCID != -1) { UseODBCString(iODBCID); } else { RSLib_ODBC.IsxStrConnect = false; // Force Use the Deafult } if (!RSLib_ODBC.ReadSQL(xSQL, bUserNotification)) { if (bUserNotification) { RSLib_CriticalError.NonCriticalErrorHandler(xCaller, "Err-xxx", "No Record found for Table: " + xTABLE + " WHERE " + xWHERE, "Registro no encontrado!\n\nTABLA: " + xTABLE + "\n\nDONDE: " + xWHERE + "\n\nFavor de verificar la Bitácora!", "Error de lectura", xSQL); } RC = false; } else { RSLib_String.MyStringArrayCopy(RSLib_ODBC.GlobalReturnValue, RecordReturn, RSLib_ODBC.nGlobalReturnValue); } return(RC); }
private void ShowLastUpdateValue() { dLastUSDValue = 0; // Load latest USD Exchange Rate string xSQL = "declare @xMaxFecha Date=(select MAX(FECHA) Fecha from FORTALEZA_PRD.dbo.CF_VALOR_DOLAR); \n" + "select @xMaxFecha dMaxFecha, VALOR fUSD from FORTALEZA_PRD.dbo.CF_VALOR_DOLAR where FECHA=@xMaxFecha; \n"; if (RSLib_ODBC.ReadSQL(xSQL, false)) { if (!DateTime.TryParse(RSLib_ODBC.GlobalReturnValue[0], out xLastUpdate)) { xLastUpdate = new DateTime(2012, 1, 1); } dLastUSDValue = RSLib_String.AToF(RSLib_ODBC.GlobalReturnValue[1]); lblLastUpdate.Text = "$" + dLastUSDValue.ToString("#,##0.0000") + " al " + xLastUpdate.ToString("dd/MM/yyyy"); lblLastUpdate.Visible = true; } else { RSLib_CriticalError.CriticalErrorHandler("Form Load on RS DOF ExchangeRate", "Err-xxx", "Failure Reading last Update Rate", "Falla leyendo el último Tipo de Cambio", "RS DOF ExhangeRate", xSQL); } }
private void Form1_Load(object sender, EventArgs e) { setNow(); lblDate.Visible = true; RegistryRead(); WhatIsMyIP = ReadIPAddress(); if (WhatIsMyIP.Length == 0) { this.Close(); return; } //WhatIsMyPublicIP = ReadPublicIPAddress(1); // DB Connection ODBCStringConn[(int)zConnID.RS_DB] = RSLib_ODBC.StrConnect; RSGbl_Variable.CheckedDB = true; if (!RSLib_ODBC.RunLOG("Msg-000", "Start Application -> " + RSGbl_Variable.APPName + " Ver:" + RSGbl_Variable.APPVersion)) { if (RSLib_ODBC.LastODBCError.IndexOf("No se encuentra el nombre del origen de datos y no se especificó ningún controlador predeterminado") != -1) { // There is No ODBC Connector, lets create it. if (RSLib_Registry.SetODBCForMSSQL( RSLib_String.MyStringProvider(RSLib_ODBC.StrConnect, "DSN=", ";"), RSServer, RSLib_String.MyStringProvider(RSLib_ODBC.StrConnect, "UID=", ";"))) { // Chack again if it worked if (!RSLib_ODBC.RunLOG("Msg-000", "Start Application -> " + RSGbl_Variable.APPName + " Ver:" + RSGbl_Variable.APPVersion)) { if (RSLib_ODBC.LastODBCError.IndexOf("No existe el servidor SQL Server o se ha denegado el acceso al mismo.") != -1) { DBDisconnected(); // UPS NO CONNECTION MessageBox.Show("La Conexión con el Servidor SIMBANK no se pudo establecer!\n\nAsegure Conexión VPN y vuelva a intentar esta aplicación\n\n\nNo se puede continuar.", "Error de Conexión VPN", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); return; } DBDisconnected(); //ForceODBCConfig(); return; } // Continue... it is connected MessageBox.Show("Conector ODBC creado con exito y conectado a la base de datos.\n\nLa aplicación se continuara ejecutando normalmente.", "Información"); } else { DBDisconnected(); //ForceODBCConfig(); return; } } if (RSLib_ODBC.LastODBCError.IndexOf("No existe el servidor SQL Server o se ha denegado el acceso al mismo.") != -1) { DBDisconnected(); // UPS NO CONNECTION MessageBox.Show("Conexión con el Servidor SIMBANK no se pudo establecer!\n\nAsegure Conexión VPN y vuelva a intentar esta aplicación\n\n\nNo se puede continuar.", "Error de Conexión VPN", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); return; } } this.Text = RSGbl_Variable.APPName + " Ver: " + RSGbl_Variable.APPVersion; if (!ReadGlobalParameters()) { RSLib_CriticalError.CriticalErrorHandler( "RSFaMFReport_Load", "Err-xxx", "Fatal error, failure to read RSFaMFGlobalParameters", "Thereie is an error reading Global Parameters", "Error", ""); ShutDown("No Global Parameters"); return; } RSGbl_Variable.RootDirectory = RSGbl_Variable.DataPath + @"\Temp"; ShowLastUpdateValue(); timer1.Start(); }
private void RegistryRead() { string LastVersion = RSLib_Registry.MyGetRegistry(RSGbl_Variable.APPName, "Version", "0"); if (LastVersion != RSGbl_Variable.APPVersion) { RSLib_Registry.MySaveRegistry(RSGbl_Variable.APPName, "FirstTime", "0"); } RSLib_Registry.MySaveRegistry(RSGbl_Variable.APPName, "Version", RSGbl_Variable.APPVersion); int FirstTime = RSLib_String.AToI(RSLib_Registry.MyGetRegistry(RSGbl_Variable.APPName, "FirstTime", "0")); int x = RSLib_String.AToI(RSLib_Registry.MyGetRegistry(RSGbl_Variable.APPName, "X", this.Location.X.ToString())); int y = RSLib_String.AToI(RSLib_Registry.MyGetRegistry(RSGbl_Variable.APPName, "Y", this.Location.Y.ToString())); int w = RSLib_String.AToI(RSLib_Registry.MyGetRegistry(RSGbl_Variable.APPName, "W", this.Size.Width.ToString())); int h = RSLib_String.AToI(RSLib_Registry.MyGetRegistry(RSGbl_Variable.APPName, "H", this.Size.Height.ToString())); RSGbl_Variable.DataPath = Environment.GetEnvironmentVariable("APPDATA") + "\\RuisenorSW\\" + RSGbl_Variable.APPGroup; RSLib_File.CheckDirectoryIfNotExistCreateIt(RSGbl_Variable.DataPath); if (FirstTime == 0) { RSLib_Registry.MySaveRegistry(RSGbl_Variable.APPName, "ApplicationPath", RSGbl_Variable.ApplicationPath); RSLib_Registry.MySaveRegistry(RSGbl_Variable.APPName, "FirstTime", "1"); if (LastVersion == "0") // This is really the first time { // DO Something } } RSGbl_Variable.ApplicationPath = RSLib_Registry.MyGetRegistry(RSGbl_Variable.APPName, "ApplicationPath", RSGbl_Variable.ApplicationPath); RSLib_ODBC.StrConnect = RSLib_Registry.MyGetRegistry(RSGbl_Variable.APPName, "ODBC Connect", RSLib_ODBC.StrConnect); RSLib_ODBC.StrConnect = RSLib_Encrypt.DesEncryptString(RSLib_ODBC.StrConnect); RSLib_ODBC.LevelLogs = Convert.ToInt32(RSLib_Registry.MyGetRegistry(RSGbl_Variable.APPName, "Level Logs", RSLib_ODBC.LevelLogs.ToString())); RSLib_SendMail.SMTP_Host = RSLib_Registry.MyGetRegistry(RSGbl_Variable.APPName, "SMTP Host", RSLib_SendMail.SMTP_Host); RSLib_SendMail.SMTP_Port = Convert.ToInt32(RSLib_Registry.MyGetRegistry(RSGbl_Variable.APPName, "SMTP Port", RSLib_SendMail.SMTP_Port.ToString())); RSLib_SendMail.SMTP_SSL = ( RSLib_Registry.MyGetRegistry(RSGbl_Variable.APPName, "SMTP SSL", RSLib_SendMail.SMTP_SSL.ToString()) == "True" ? true : false); RSLib_SendMail.SMTP_USER = RSLib_Registry.MyGetRegistry(RSGbl_Variable.APPName, "SMTP USER", RSLib_SendMail.SMTP_USER); RSLib_SendMail.SMTP_PWD = RSLib_Registry.MyGetRegistry(RSGbl_Variable.APPName, "SMTP PWD", RSLib_SendMail.SMTP_PWD); RSLib_SendMail.SMTP_PWD = RSLib_Encrypt.DesEncryptString(RSLib_SendMail.SMTP_PWD); RSLib_SendMail.SMTP_From = RSLib_Registry.MyGetRegistry(RSGbl_Variable.APPName, "SMTP From", RSLib_SendMail.SMTP_From); //WhatIsCustomerServiceMail = RSLib_Registry.MyGetRegistry(RSGbl_Variable.APPName, "NEW Customer Service eMail", WhatIsCustomerServiceMail); RSGbl_Variable.LastUser = RSLib_Registry.MyGetRegistry(RSGbl_Variable.APPName, "LastUser", System.Environment.UserName); RSLib_ODBC.iSQLTimeOutGlobal = RSLib_String.AToI(RSLib_Registry.MyGetRegistry(RSGbl_Variable.APPName, "SQL Time Out", RSLib_ODBC.iSQLTimeOutGlobal.ToString())); if (RSLib_ODBC.iSQLTimeOutGlobal == -1) { RSLib_ODBC.iSQLTimeOutGlobal = 90; } // Copia LOGO Si no existe string SourcePath = RSGbl_Variable.ApplicationPath; string TargetPath = RSGbl_Variable.DataPath + @"\Image"; RSLib_File.CheckDirectoryIfNotExistCreateIt(TargetPath); string xPNGFile = "zRSFaMFSmall"; if (!File.Exists(Path.Combine(TargetPath, xPNGFile + ".png"))) { if (File.Exists(Path.Combine(SourcePath, xPNGFile + ".png"))) { RSLib_File.MyBasicMoveOrCopyFile( Path.Combine(SourcePath, xPNGFile + ".png"), Path.Combine(TargetPath, xPNGFile + ".png"), true ); } } CheckIfNoEmailSettingsThenOverride(); RSGbl_Variable.GlobalUII = System.Environment.MachineName; this.Location = new Point(x, y); this.Size = new System.Drawing.Size(w, h); }
private void UpdateFromDOF() { string xProvider = "http://dof.gob.mx/indicadores.xml"; WebRequest SendReq = HttpWebRequest.Create(xProvider); WebResponse GetRes = SendReq.GetResponse(); System.IO.Stream StreamRes = GetRes.GetResponseStream(); StreamReader ResStrmRdr = new StreamReader(StreamRes, Encoding.UTF8); string xDOFOriginal = ResStrmRdr.ReadToEnd(); StreamRes.Close(); GetRes.Close(); string xDOF = RSLib_String.MyStringProvider(xDOFOriginal, "<title>DOLAR</title>", "</item>"); xDOF = xDOF.Replace("\n", ""); xDOF = xDOF.Replace("\t", ""); xDOF = xDOF.Replace(" ", ""); string xValue = RSLib_String.MyStringProvider(xDOF, "<description>", "</description>"); string xDate = RSLib_String.MyStringProvider(xDOF, "<valueDate>", "</valueDate>"); double fValue = RSLib_String.AToF(xValue); DateTime xLocalClock = DateTime.Now; string xSQL = ""; if (!DateTime.TryParse(xDate, out xLocalClock) || fValue == 0) { xLocalClock = DateTime.Now; xSQL = "select distinct CONVERT(date,FECHA_FESTIVO) Festivo \n" + "from FORTALEZA_PRD.dbo.CF_DIAS_FESTIVOS \n" + "where FECHA_FESTIVO='" + xLocalClock.ToString(WhatIsDateFormat) + "' \n" + "; \n"; if (!RSLib_ODBC.ReadSQL(xSQL, false)) { if (xLocalClock.DayOfWeek == DayOfWeek.Saturday || xLocalClock.DayOfWeek == DayOfWeek.Sunday) { // IT is Saturday or Sunday - Nothing 2 save, then use the latest fValue = dLastUSDValue; xLocalClock = DateTime.Now; } else { // No Es feriado: Ignore RSLib_CriticalError.CriticalErrorHandler("Form UpdateFromDOF on RS DOF ExchangeRate", "Err-xxx", "Failure Getting Update Rate from DOF", "Falla leyendo el WebService", "RS DOF ExhangeRate", xDOFOriginal); return; } } else { // IT is feriado - Nothing 2 save, then use the latest fValue = dLastUSDValue; xLocalClock = DateTime.Now; } } xSQL = "insert into FORTALEZA_PRD.dbo.CF_VALOR_DOLAR (COD_EMPRESA,FECHA,VALOR) VALUES('00030','" + xLocalClock.ToString(WhatIsDateFormat) + "','" + fValue.ToString() + "'); \n"; if (!RSLib_ODBC.RunSQL(xSQL)) { RSLib_CriticalError.CriticalErrorHandler("Form UpdateFromDOF on RS DOF ExchangeRate", "Err-xxx", "Failure Updating Table", "Falla actualizando tabla", "RS DOF ExhangeRate", xSQL); } else { // Show ShowLastUpdateValue(); // Send eMail Notificaciones string xMessage = "Fecha: \t" + xLocalClock.ToString(WhatIsDateFormat) + "\n" + "Valor Tipo de Cambio: \t" + fValue.ToString("#,##0.0000") + "\n"; RSLib_ODBC.RunLOG("PLD-001", "Exchange Rate Updated -> " + xMessage.Replace("\n", " ").Replace("\t", "-")); string xBody = RSFormaTable(xMessage, "Tipo de Cambio - Sistema PLD", true, true, false, true, true); if (!RSLib_SendMail.SendMailMessage(RSLib_SendMail.SMTP_From, "Oficial.Cumplimiento" + WhatIsDomain, "", "Help.Desk" + WhatIsDomain, "[Tipo de Cambio] " + xLocalClock.ToString(WhatIsDateFormat), xBody, true)) { RSLib_CriticalError.CriticalErrorHandler("Form UpdateFromDOF on RS DOF ExchangeRate", "Err-xxx", "Failure sending email Notificacion", "Falla enviando correo de notificacion", "RS DOF ExhangeRate", ""); } } }