Example #1
0
        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());
            }
        }
Example #2
0
        private void CmdCambiarClave_Click(object sender, EventArgs e)
        {
            CLNBTN_Qy Query                = null;
            CLNBTN_Sg ObjL_Secur           = null;
            Boolean   blL_Conectar         = true;
            Boolean   blL_AceptoDatos      = false;
            Boolean   blL_Se_Conecto       = false;
            String    stL_MensajeValidaUso = "";
            Boolean   blL_PideCambioClave  = false;
            Boolean   blL_Definio_Servidor = false;

            try
            {
                //
                LblMensaje.Text  = "";
                inPr_NumIntentos = inPr_NumIntentos + 1;
                if (inPr_NumIntentos > MAX_INTENTOS)
                {
                    LblMensaje.Text = MENSAJE_3;
                }
                else
                {
                    // 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
                        List <String> LstServidores = new List <String>();
                        // Asigna el Servior, que tiene la BD
                        LstServidores.Add(ObjPr_InfoBD.getServerName());
                        this.cmbServidores.DataSource = LstServidores;
                        cmbServidores.Enabled         = false;
                    }
                    //
                    // Hace la conexion
                    Query.setDataBaseInfo(ObjPr_InfoBD);
                    if (blL_Conectar)
                    { // del if (blL_Conectar)
                        Query.ConnectDataBase();
                        //
                        if (Query.getIs_Connected())
                        {
                            blL_Se_Conecto = true;
                        }
                    } // del if (blL_Conectar)
                    //
                    if (blL_Se_Conecto)
                    {
                        // Valida el usuario
                        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_User_Access(ref blL_AceptoDatos, ref stL_MensajeValidaUso, ref blL_PideCambioClave, ref ObjPr_InfoBD, true);
                        //
                        // Presenta el mensaje del usuario
                        LblMensaje.Text = stL_MensajeValidaUso;
                        //
                        if (blL_PideCambioClave)
                        {
                            // Presenta ventana para cambio de clave
                            //
                            ObjL_Secur.Let_ShowFrmChPwd(ref blL_AceptoDatos, ref ObjPr_InfoBD);
                            if (blL_AceptoDatos)
                            {
                                blPr_AceptoInformacion = true;
                                // Cierra la forma
                                this.Hide();
                            }
                        }
                        else
                        {
                            if (blL_AceptoDatos)
                            {
                                blPr_AceptoInformacion = true;
                                // Cierra la forma
                                this.Hide();
                            }
                        }
                    }
                }
            }
            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(10). 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(10). Exception", "", ex.Message.ToString());
            }
        }
Example #3
0
        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());
            }
        }