コード例 #1
0
        private void button7_Click(object sender, EventArgs e)
        {
            OdbcConnection conexion = TaquillaDB.getDB();

            try
            {
                string         sql    = string.Format("SELECT * FROM USUARIO WHERE USU_USUARIO = '{0}'", Txt_loginUser.Text);
                OdbcCommand    cmd    = new OdbcCommand(sql, conexion);
                OdbcDataReader reader = cmd.ExecuteReader();
                if (reader.Read())
                {
                    conexion.Close();
                    conexion = TaquillaDB.getDB();
                    sql      = string.Format("SELECT * FROM USUARIO WHERE USU_USUARIO = '{0}' AND PASS_USUARIO = MD5('{1}');", Txt_loginUser.Text, Txt_loginPass.Text);
                    cmd      = new OdbcCommand(sql, conexion);
                    reader   = cmd.ExecuteReader();
                    if (reader.Read())
                    {
                        if (reader.GetInt32(2) == 0)
                        {
                            OdbcConnection cnx = TaquillaDB.getDB();
                            sql = string.Format("INSERT INTO BITACORA VALUES (NULL, 'LOG IN', NOW(), '{0}', USER());", Txt_loginUser.Text);
                            OdbcCommand cm = new OdbcCommand(sql, cnx);
                            cm.ExecuteNonQuery();
                            Txt_loginUser.Text = "";
                            Txt_loginPass.Text = "";
                            frm_main nuevo = new frm_main(this);
                            this.Hide();
                            nuevo.Show();
                        }
                        else
                        {
                            MessageBox.Show("Falta de privilegios!!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            Txt_loginUser.Text = "";
                            Txt_loginUser.Focus();
                        }
                    }
                    else
                    {
                        MessageBox.Show("Password incorrect!!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        Txt_loginPass.Focus();
                    }
                }
                else
                {
                    MessageBox.Show("Usuario no valido!!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Txt_loginUser.Text = "";
                    Txt_loginUser.Focus();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            Txt_loginPass.Text      = "";
            Chk_gestionPass.Checked = false;
            conexion.Close();
        }
コード例 #2
0
        //boton aceptar
        private void Btn_Aceptar_Click(object sender, EventArgs e)
        {
            OdbcConnection conexion = Conection.getDB();

            try
            {
                string         sql    = string.Format("SELECT * FROM usuarios WHERE user = '******'", Txt_loginUser.Text);
                OdbcCommand    cmd    = new OdbcCommand(sql, conexion);
                OdbcDataReader reader = cmd.ExecuteReader();
                if (reader.Read())
                {
                    if (reader.GetString(1) == Txt_loginPass.Text)
                    {
                        if (reader.GetInt32(2) == 0)
                        {
                            Txt_loginUser.Text = "";
                            Txt_loginPass.Text = "";
                            MDIPrincipal nuevo = new MDIPrincipal();
                            this.Hide();
                            nuevo.Show();
                        }
                        else
                        {
                            MessageBox.Show("Privilegios denegados", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            Txt_loginUser.Text = "";
                            Txt_loginUser.Focus();
                        }
                    }
                    else
                    {
                        MessageBox.Show("Contraseña incorrecta", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        Txt_loginPass.Focus();
                    }
                }
                else
                {
                    MessageBox.Show("Usuario no valido", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Txt_loginUser.Text = "";
                    Txt_loginUser.Focus();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            Txt_loginPass.Text      = "";
            Chk_gestionPass.Checked = false;
            conexion.Close();
        }