Menu

#1 Logeo

1.0
open
None
2013-10-19
2013-10-19
No

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Sistema_de_Almacen
{
public partial class FrmAcceso : Form
{
SqlConnection cn = new SqlConnection("DATA SOURCE=FAMILIA; Initial Catalog=BDSisAlmacen; Integrated Security=SSPI");
int cont = 0;

    public FrmAcceso()
    {
        InitializeComponent();
        CargarDatos();
    }

    private void CargarDatos(){
        SqlDataAdapter da = new SqlDataAdapter("Select * from Tipo_Usuario", cn);
        DataSet ds = new DataSet();

        da.Fill(ds);

        for (int i = 0; i < 4; i++)
        {
            //MessageBox.Show("Fila " + " " + ds.Tables[0].Rows[i][1]);
            cboTipoUs.Items.Add(ds.Tables[0].Rows[i][1]);
        }
    }

    private void BtnAceptar_Click(object sender, EventArgs e)
    {
        FrmMenu menu = new FrmMenu();

        String tipo_us = cboTipoUs.Text;
        String pwd = TxtPwd.Text;

        cn.Open();
        SqlCommand cmd = new SqlCommand("sp_login");
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Connection = cn;

        SqlParameter prm1 = new SqlParameter();
        prm1.ParameterName = "@tipo_us";
        prm1.Value = tipo_us;
        cmd.Parameters.Add(prm1);

        SqlParameter prm2 = new SqlParameter();
        prm2.ParameterName = "pwd";
        prm2.Value = pwd;
        cmd.Parameters.Add(prm2);

        SqlDataReader ejecuta = cmd.ExecuteReader();

        if (ejecuta.Read() == true)
        {
            MessageBox.Show("BIENVENIDO AL SISTEMA USUARIO: " + tipo_us.ToUpper(), "Mensaje del Sistema");
            this.Hide();
            menu.Text = "MENU PRINCIPAL (USUARIO: " + tipo_us + ")";
            menu.Show();
        }
        else
        {
            cont += 1;
            MessageBox.Show("ACCESO DENEGADO LE QUEDA(N) " + (3 - cont) + " INTENTO(S)", "Mensaje del Sistema");
            cn.Close();
        }

        if (cont == 3)
        {
            this.Close();
        }
    }

    private void BtnCancelar_Click(object sender, EventArgs e)
    {
        this.Close();
    }

Discussion


Log in to post a comment.

MongoDB Logo MongoDB