public void GetParam(String LicName, String WinTittle, String UserName, String LogFile, String ConfFile, String AppInfo_Name, String AppInfo_Ver, String AppInfo_Cia, String InfBdFile, String DBName4Work, ref CLNBTN_IQy Obj_BaseDeDatos, String DBSectionName = "") { // Toma los parametros. String stL_Aux = ""; String stL_Mensaje1 = ""; String stL_Mensaje2 = ""; CLNBTN_IQy.inDB_Types inL_TipoBD = 0; CLNBTN_IQy.inConnect_Type inL_TipoConexion = 0; CLNBTN_Es ObjL_Encrip = null; // try { CLNBTN_Gp ObL_Lic = new CLNBTN_Gp(LicName); _st_Lic = ObL_Lic.getLicName(); if (_st_Lic.Length == 0) { MessageBox.Show("Invalid Lic To work"); } // Toma la seccion de la base de datos con la cual va a trabajar. stPr_Seccion_BaseDeDatos = DBSectionName; // Si viene vacia, toma la seccion SYS_BD_ZERO if (stPr_Seccion_BaseDeDatos.Length == 0) { stPr_Seccion_BaseDeDatos = SECCION_BD_0; } // Guarda textos originales. stPr_Servidor_Ori = cmbServidores.Text; stPr_Usuario_Ori = TxtUsuario.Text; stPr_Clave_Ori = TxtClave.Text; // inPr_NumIntentos = 0; LblMensaje.Text = ""; // this.Text = WinTittle; _st_User = UserName; _st_FileLog = LogFile; stPr_ArchivoConfigApp = ConfFile; stPr_Archivo_InfoBds = InfBdFile; stPr_NombreBd_XTrabajo = DBName4Work; // Crea instancia para la clase que maneja las configuraciones ObjPr_Conf = new CLNBTN_Cg(stPr_ArchivoConfigApp, _st_User, _st_FileLog, _st_Lic); // ObjPr_Utils = new CLNBTN_Ul(_st_User, _st_FileLog, _st_Lic); // stPr_Nombre_App = AppInfo_Name; stPr_Version_App = AppInfo_Ver; stPr_NombreEmpresa_App = AppInfo_Cia; // Coloca aplicacion y version this.LblModuloVersion.Text = stPr_Nombre_App + " " + stPr_Version_App; this.LblNombreCia.Text = stPr_NombreEmpresa_App; // La informacion de la base de datos para manejar la conexion con la base de datos. ObjPr_InfoBD = new CLNBTN_IQy(_st_Lic); ObjPr_InfoBD = Obj_BaseDeDatos; // // Ejemplo del archivo de configuracion // [SYS_BD_ZERO] //Name=Administracion //Engine=0 //Security=4 //Path= //URL= //Server= //IPAddress= //; /////////////////////////////////////////////////////////////// // Halla Informacion de la base de datos /////////////////////////////////////////////////////////////// stL_Mensaje1 = ""; // Nombre de la base de datos. stL_Aux = ""; stL_Aux = ObjPr_Conf.ReadAKeyFromSection(stPr_Seccion_BaseDeDatos, "Name"); if (stL_Aux.Length == 0) { stL_Mensaje1 = MENSAJE_1; } else { ObjPr_InfoBD.setDataBaseName(stL_Aux); } // tipo de Motor de Base de Datos stL_Aux = ""; stL_Aux = ObjPr_Conf.ReadAKeyFromSection(stPr_Seccion_BaseDeDatos, "Engine"); if (stL_Aux.Length == 0) { stL_Mensaje1 = MENSAJE_1; } else { inL_TipoBD = (CLNBTN_IQy.inDB_Types)(Convert.ToInt32(stL_Aux)); // ObjPr_InfoBD.setDataBaseEngine_Type(inL_TipoBD); } // Tipo de Conexion stL_Aux = ""; stL_Aux = ObjPr_Conf.ReadAKeyFromSection(stPr_Seccion_BaseDeDatos, "Security"); if (stL_Aux.Length == 0) { stL_Mensaje1 = MENSAJE_1; } else { inL_TipoConexion = (CLNBTN_IQy.inConnect_Type)(Convert.ToInt32(stL_Aux)); // ObjPr_InfoBD.setDataBaseConn_Type(inL_TipoConexion); } // // Path de la base de datos. stL_Aux = ""; stL_Aux = ObjPr_Conf.ReadAKeyFromSection(stPr_Seccion_BaseDeDatos, "Path"); ObjPr_InfoBD.setDataBasePath(stL_Aux); // URL stL_Aux = ""; stL_Aux = ObjPr_Conf.ReadAKeyFromSection(stPr_Seccion_BaseDeDatos, "URL"); ObjPr_InfoBD.setServer_URL(stL_Aux); // Nombre de Servidor stL_Aux = ""; stL_Aux = ObjPr_Conf.ReadAKeyFromSection(stPr_Seccion_BaseDeDatos, "Server"); if (stL_Aux.Length == 0) { //stL_Mensaje1 = MENSAJE_1; } else { ObjPr_InfoBD.setServerName(stL_Aux); } // Ip Address stL_Aux = ""; stL_Aux = ObjPr_Conf.ReadAKeyFromSection(stPr_Seccion_BaseDeDatos, "IPAddress"); ObjPr_InfoBD.setServer_IP_Address(stL_Aux); // CmdCambiarClave.Enabled = false; // switch (ObjPr_InfoBD.get_DataBaseConn_Type()) { // Inicio del switch (ObjPr_InfoBD.getTipoConexion()) // case CLNBTN_IQy.inConnect_Type.TYPE_1_CONNECT_USER_SQL: // Usuario y clave de la bd, vienen en archivo de configuraciones TxtUsuario.Text = _st_User; break; case CLNBTN_IQy.inConnect_Type.TYPE_2_CONNECT_USER_APP: // Usuario de la aplicacion, mismo usuario de la base de datos TxtUsuario.Text = _st_User; break; case CLNBTN_IQy.inConnect_Type.TYPE_3_CONNECT_USER_WIN: // Usuario Windows es el mismo usuario de la base de datos TxtUsuario.Text = _st_User; TxtUsuario.Enabled = false; GrpClave.Visible = false; TxtClave.Text = ""; CmdCambiarClave.Visible = false; break; case CLNBTN_IQy.inConnect_Type.TYPE_4_CONNECT_USER_INFO_EXT: // Conexion tipo Fenix. TxtUsuario.Text = _st_User; if (File.Exists(stPr_Archivo_InfoBds)) { ObjPr_InfoBDS_Fenix = new CLNBTN_Cg(stPr_Archivo_InfoBds, _st_User, _st_FileLog, _st_Lic); ObjL_Encrip = new CLNBTN_Es(_st_User, _st_FileLog, _st_Lic); // Halla y DesEncripta la informacion del servidor stL_Aux = ""; stL_Aux = ObjPr_InfoBDS_Fenix.ReadAKeyFromSection(SECCION_BD_CONNECT_INFO, "ServerName"); if (stL_Aux.Length != 0) { stL_Aux = ObjL_Encrip.File2Des(stL_Aux, "", "FT/yQYmins06srbyMggYjcEY/ns2slWTURobdSariTY=+-6aUVQ2SZO7QHT6kUHtr2zRbupap5KPu4jeO9GE+UMnk=", "", _st_Lic); ObjPr_InfoBD.setServerName(stL_Aux); blPr_ServidorYaDefinido = true; } // Halla y DesEncripta la informacion de la base de datos stL_Aux = ""; stL_Aux = ObjPr_InfoBDS_Fenix.ReadAKeyFromSection(SECCION_BD_CONNECT_INFO, "DBName"); if (stL_Aux.Length != 0) { stL_Aux = ObjL_Encrip.File2Des(stL_Aux, "", "FT/yQYmins06srbyMggYjcEY/ns2slWTURobdSariTY=+-6aUVQ2SZO7QHT6kUHtr2zRbupap5KPu4jeO9GE+UMnk=", "", _st_Lic); ObjPr_InfoBD.setDataBaseName(stL_Aux); } // Halla y DesEncripta la informacion del usuario stL_Aux = ""; stL_Aux = ObjPr_InfoBDS_Fenix.ReadAKeyFromSection(SECCION_BD_CONNECT_INFO, "UID"); if (stL_Aux.Length != 0) { stL_Aux = ObjL_Encrip.File2Des(stL_Aux, "", "FT/yQYmins06srbyMggYjcEY/ns2slWTURobdSariTY=+-6aUVQ2SZO7QHT6kUHtr2zRbupap5KPu4jeO9GE+UMnk=", "", _st_Lic); ObjPr_InfoBD.setDataBase_UserID(stL_Aux); } // Halla y DesEncripta la informacion de la clave stL_Aux = ""; stL_Aux = ObjPr_InfoBDS_Fenix.ReadAKeyFromSection(SECCION_BD_CONNECT_INFO, "PWDID"); if (stL_Aux.Length != 0) { stL_Aux = ObjL_Encrip.File2Des(stL_Aux, "", "FT/yQYmins06srbyMggYjcEY/ns2slWTURobdSariTY=+-6aUVQ2SZO7QHT6kUHtr2zRbupap5KPu4jeO9GE+UMnk=", "", _st_Lic); ObjPr_InfoBD.setDataBase_UserPWD(stL_Aux); } } break; default: // stL_Mensaje2 = MENSAJE_2; break; } // Fin de switch (ObjPr_InfoBD.getTipoConexion()) // if (stL_Mensaje1.Length > 0) { LblMensaje.Text = stL_Mensaje1; } if (stL_Mensaje2.Length > 0) { if (LblMensaje.Text.Length == 0) { LblMensaje.Text = stL_Mensaje2; } else { LblMensaje.Text = LblMensaje.Text + NEW_LINE + stL_Mensaje2; } } } catch (System.AccessViolationException ex_0) { CmdCancelar.Enabled = true; CLNBTN_Lg objL_Log = new CLNBTN_Lg(_st_User, _st_FileLog, _bl_OutLineConsole, _bl_OutFileLog, _bl_OutWindow); objL_Log.WriteOutErrorMessage(_st_Relac, _st_RelacSon, "GetParam. System.AccessViolationException", "", ex_0.Message.ToString()); } catch (Exception ex) { CmdCancelar.Enabled = true; CLNBTN_Lg objL_Log = new CLNBTN_Lg(_st_User, _st_FileLog, _bl_OutLineConsole, _bl_OutFileLog, _bl_OutWindow); objL_Log.WriteOutErrorMessage(_st_Relac, _st_RelacSon, "GetParam. Exception", "", ex.Message.ToString()); } }
private void HallaListaServidores() { // Halla la lista de los servidores de SQL Server. // URL de consulta : http://programandoenpuntonet.blogspot.com/2009/01/obtener-instancias-de-sql-server-y.html // Creamos una lista para que sea el origen de datos del combobox List <String> LstServidores = new List <String>(); Boolean blL_EstadoCombo = false; Boolean blL_EstadoUsuario = false; Boolean blL_EstacoClave = false; // CLNBTN_Qy Query = null; CLNBTN_Sg ObjL_Secur = null; Boolean blL_Conectar = true; Boolean blL_Se_Conecto = false; Boolean blL_Definio_Servidor = false; // try { // Guarda los estados de los controles blL_EstadoCombo = cmbServidores.Enabled; blL_EstadoUsuario = TxtUsuario.Enabled; blL_EstacoClave = TxtClave.Enabled; // Los Coloca en false, mientras halla la lista de los servidores cmbServidores.Enabled = false; TxtUsuario.Enabled = false; TxtClave.Enabled = false; CmdCancelar.Enabled = false; // LblMensaje.Text = MENSAJE_23 + NEW_LINE + MENSAJE_24; Application.DoEvents(); Application.DoEvents(); // if (ObjPr_InfoBD.getDataBaseEngine_Type() == CLNBTN_IQy.inDB_Types.DB_TYPE_SQLSERVER) { // del if (ObjPr_InfoBD.getTipoBD() == CLNBTN_IQy.inDB_Types.DB_TYPE_SQLSERVER) // if (ObjPr_InfoBD.get_DataBaseConn_Type() == CLNBTN_IQy.inConnect_Type.TYPE_4_CONNECT_USER_INFO_EXT) { if (blPr_ServidorYaDefinido) { // Inicio del if (blPr_ServidorYaDefinido) // Asigna el Servior, que tiene la BD if (ObjPr_InfoBD.getServerName().Length > 0) { LstServidores.Add(ObjPr_InfoBD.getServerName()); this.cmbServidores.DataSource = LstServidores; //this.cmbServidores.Enabled = false; blL_EstadoCombo = false; } } // fin del if (blPr_ServidorYaDefinido) else // del if (blPr_ServidorYaDefinido) { // Inicio del else if (blPr_ServidorYaDefinido) // Prueba Conexion LblMensaje.Text = MENSAJE_25 + NEW_LINE + MENSAJE_24; Application.DoEvents(); // Asigna informacion Query = new CLNBTN_Qy(_st_User, _st_FileLog, _st_Lic); // ObjPr_InfoBD.setServerName(cmbServidores.Text); ObjL_Secur = new CLNBTN_Sg(_st_User, _st_FileLog, stPr_ArchivoConfigApp, stPr_Nombre_App, stPr_Version_App, stPr_NombreEmpresa_App, stPr_Archivo_InfoBds, stPr_NombreBd_XTrabajo, _st_Lic); ObjL_Secur.Is_A_Valid_DB_Conn(ref blL_Definio_Servidor, ref blL_Conectar, ref blL_Se_Conecto, ref ObjPr_InfoBD, ObjPr_Conf, TxtUsuario.Text, TxtClave.Text, stPr_Seccion_BaseDeDatos); // if (blL_Definio_Servidor) { // Si definio el servidor lo coloca en la lista y deshabilita el combobox // Asigna el Servior, que tiene la BD LstServidores.Add(ObjPr_InfoBD.getServerName()); this.cmbServidores.DataSource = LstServidores; // blL_EstadoCombo = false; } else { // Prende bandera para ocultar la forma y salir de la forma del login. blPr_EscondeForma = true; } // } // Fin de if (blPr_ServidorYaDefinido) } else { SqlDataSourceEnumerator servidores; System.Data.DataTable tablaServidores; //String servidor; // servidores = SqlDataSourceEnumerator.Instance; tablaServidores = new DataTable(); // // Comprobamos que no se haya cargado ya el combobox if (tablaServidores.Rows.Count == 0) { // Obtenemos un dataTable con la información sobre las instancias visibles // de SQL Server 2000 y 2005 tablaServidores = servidores.GetDataSources(); // Recorremos el dataTable y añadimos un valor nuevo a la lista con cada fila foreach (DataRow rowServidor in tablaServidores.Rows) { // La instancia de SQL Server puede tener nombre de instancia //o únicamente el nombre del servidor, comprobamos si hay //nombre de instancia para mostrarlo if (String.IsNullOrEmpty(rowServidor["InstanceName"].ToString())) { LstServidores.Add(rowServidor["ServerName"].ToString()); } else { LstServidores.Add(rowServidor["ServerName"] + "\\" + rowServidor["InstanceName"]); } } // Asignamos al origen de datos del combobox la lista con // las instancias de servidores if (LstServidores.Count == 0) { // Asigna el Servior, que tiene la BD LstServidores.Add(ObjPr_InfoBD.getServerName()); } this.cmbServidores.DataSource = LstServidores; } // //SqlDataSourceEnumerator instance = SqlDataSourceEnumerator.Instance; //System.Data.DataTable table = instance.GetDataSources(); // //foreach (System.Data.DataRow row in table.Rows) //{ // foreach (System.Data.DataColumn col in table.Columns) // { // Console.WriteLine("{0} = {1}", col.ColumnName, row[col]); // } //} // } } // del if (ObjPr_InfoBD.getTipoBD() == CLNBTN_IQy.inDB_Types.DB_TYPE_SQLSERVER) else // del if (ObjPr_InfoBD.getTipoBD() == CLNBTN_IQy.inDB_Types.DB_TYPE_SQLSERVER) { // del else del if (ObjPr_InfoBD.getTipoBD() == CLNBTN_IQy.inDB_Types.DB_TYPE_SQLSERVER) // Para los otros tipos de servidores. // Asigna el Servior, que tiene la BD LstServidores.Add(ObjPr_InfoBD.getServerName()); // Asignamos la lista al combo this.cmbServidores.DataSource = LstServidores; } // del if (ObjPr_InfoBD.getTipoBD() == CLNBTN_IQy.inDB_Types.DB_TYPE_SQLSERVER) // Limpia mensaje y deja los controles con el estado que estaban originalmente LblMensaje.Text = ""; // cmbServidores.Enabled = blL_EstadoCombo; TxtUsuario.Enabled = blL_EstadoUsuario; TxtClave.Enabled = blL_EstacoClave; // CmdCancelar.Enabled = true; // Application.DoEvents(); Application.DoEvents(); // } catch (System.AccessViolationException ex_0) { CmdCancelar.Enabled = true; CLNBTN_Lg objL_Log = new CLNBTN_Lg(_st_User, _st_FileLog, _bl_OutLineConsole, _bl_OutFileLog, _bl_OutWindow); objL_Log.WriteOutErrorMessage(_st_Relac, _st_RelacSon, "FrmLogin(3). System.AccessViolationException", "", ex_0.Message.ToString()); } catch (Exception ex) { CmdCancelar.Enabled = true; CLNBTN_Lg objL_Log = new CLNBTN_Lg(_st_User, _st_FileLog, _bl_OutLineConsole, _bl_OutFileLog, _bl_OutWindow); objL_Log.WriteOutErrorMessage(_st_Relac, _st_RelacSon, "FrmLogin(3). Exception", "", ex.Message.ToString()); } }
private void CmdAceptar_Click(object sender, EventArgs e) { CLNBTN_Qy Query = null; CLNBTN_Es Encrip = new CLNBTN_Es(_st_User, _st_FileLog, _st_Lic); CLNBTN_Ul Utils = new CLNBTN_Ul(_st_User, _st_FileLog, _st_Lic); Boolean blL_ValidaClave = false; String stL_Encrip = ""; int inL_DiasClave = 0; try { // LblMensaje.Text = ""; inPr_NumIntentos = inPr_NumIntentos + 1; if (inPr_NumIntentos > MAX_INTENTOS) { LblMensaje.Text = MENSAJE_3; } else { // switch (ObjPr_InfoBD.get_DataBaseConn_Type()) { case CLNBTN_IQy.inConnect_Type.TYPE_1_CONNECT_USER_SQL: // blL_ValidaClave = true; break; case CLNBTN_IQy.inConnect_Type.TYPE_4_CONNECT_USER_INFO_EXT: // blL_ValidaClave = true; break; } if (blL_ValidaClave) { // del if ( blL_ValidaClave ) // Asigna informacion Query = new CLNBTN_Qy(_st_User, _st_FileLog, _st_Lic); // // Hace la conexion Query.setDataBaseInfo(ObjPr_InfoBD); Query.ConnectDataBase(); // if (Query.getIs_Connected()) { blL_ValidaClave = false; if (ObjPr_InfoBD.getUserApp_PWD().Length == 0) { blL_ValidaClave = true; } else { if (ObjPr_InfoBD.getUserApp_PWD() == TxtClave.Text) { blL_ValidaClave = true; } else { LblMensaje.Text = MENSAJE_18; } } if (blL_ValidaClave) { blL_ValidaClave = false; if (TxtClave1.Text == TxtClave2.Text) { if (TxtClave.Text == TxtClave1.Text) { LblMensaje.Text = MENSAJE_20; } else { blL_ValidaClave = true; } } else { LblMensaje.Text = MENSAJE_19; } } if (blL_ValidaClave) { // Define DataTable, para los Datos del Query DataTable DatTable = null; // Query.ToDo_SELECT("*"); Query.ToDo_FROM("t00usuarios"); Query.ToDo_WHERE("A00USUARIOWIN", "'" + ObjPr_InfoBD.getUser() + "'"); Query.ToDo_EXECUTE_SQL(ref DatTable); if (DatTable != null) { // del if (Query.Rs.State != 0) for (int inL_Row = 0; inL_Row < DatTable.Rows.Count; inL_Row++) { // Toma la informacion de la fila DataRow Info_Fila = DatTable.Rows[inL_Row]; inL_DiasClave = 0; //if (!DBNull.Value.Equals(Info_Fila["A00DIAS_CLAVE"].ToString())) //{ if (Info_Fila["A00DIAS_CLAVE"].ToString().Length > 0) { inL_DiasClave = Convert.ToInt16(Info_Fila["A00DIAS_CLAVE"].ToString()); } //} } } Query.ToDo_CLOSE(); // stL_Encrip = Encrip.File2Es(TxtClave1.Text.Trim(), "", "FT/yQYmins06srbyMggYjcEY/ns2slWTURobdSariTY=+-6aUVQ2SZO7QHT6kUHtr2zRbupap5KPu4jeO9GE+UMnk=", "", _st_Lic); Query.ToDo_UPDATE("t00usuarios"); Query.ToDo_SET("A00ESTADO", ESTADO_ACTIVO); Query.ToDo_SET("A00CLAVE", stL_Encrip); Query.ToDo_SET("A00FECHA_CLAVE", Utils.BringMeServerDate(ObjPr_InfoBD, true)); if (inL_DiasClave == 0) { Query.ToDo_SET("A00DIAS_CLAVE", "30"); } Query.ToDo_WHERE("A00USUARIOWIN", " '" + ObjPr_InfoBD.getUser() + "' "); Query.ToDo_EXECUTE_SQL(); if (Query.getSuccessQueryExecution()) { ObjPr_InfoBD.setUserApp_PWD(TxtClave1.Text); ObjPr_InfoBD.setUserApp_PWD_Enc(stL_Encrip); MessageBox.Show(MENSAJE_21, MENSAJE_5); } Query.ToDo_CLOSE(); // blPr_AceptoInformacion = true; // Cierra la forma this.Hide(); } } } // del if ( blL_ValidaClave ) } } catch (System.AccessViolationException ex_0) { CLNBTN_Lg objL_Log = new CLNBTN_Lg(_st_User, _st_FileLog, _bl_OutLineConsole, _bl_OutFileLog, _bl_OutWindow); objL_Log.WriteOutErrorMessage(_st_Relac, _st_RelacSon, "FrmChgPwd(2). System.AccessViolationException", "", ex_0.Message.ToString()); } catch (Exception ex) { CLNBTN_Lg objL_Log = new CLNBTN_Lg(_st_User, _st_FileLog, _bl_OutLineConsole, _bl_OutFileLog, _bl_OutWindow); objL_Log.WriteOutErrorMessage(_st_Relac, _st_RelacSon, "FrmChgPwd(2). Exception", "", ex.Message.ToString()); } }