private void Button_Click(object sender, RoutedEventArgs e)
        {
            usuarioBLL ub = new usuarioBLL();

            bool nombre    = true;
            bool apellido  = true;
            bool rut       = true;
            bool rol       = true;
            bool fono      = true;
            bool direccion = true;
            bool clave     = true;
            bool estado    = true;

            if (coc.IsSelected || bart.IsSelected || Admin.IsSelected || Gar.IsSelected || fina.IsSelected || caja.IsSelected || bodega.IsSelected)
            {
                rol = true;
            }
            else
            {
                rol         = false;
                lb2.Content = "Ingrese un rol";
            }
            if (txt_Contrasena.Text == "")
            {
                clave       = false;
                lb7.Content = "Ingrese una contraseña";
            }
            if (txt_apellido.Text == "")
            {
                nombre      = false;
                lb4.Content = "Ingrese un apellido";
            }

            if (txt_nombre.Text == "")
            {
                apellido    = false;
                lb3.Content = "Ingrese un nombre";
            }

            if (txt_rut.Text == "")
            {
                rut         = false;
                lb1.Content = "Ingrese un rut";
            }

            if (txt_direccion.Text == "")
            {
                direccion   = false;
                lb6.Content = "Ingrese una dirección";
            }

            if (txt_fono.Text == "")
            {
                fono        = false;
                lb5.Content = "Ingrese un número";
            }


            if (clave == true && nombre == true && rut == true && apellido == true && rol == true && fono == true && direccion == true && estado == true)
            {
                bool existe = ub.GetUserByRut(Int32.Parse(txt_rut.Text));
                if (existe)
                {
                    if (existe == true)
                    {
                        ub.id_usuario = Int32.Parse(txt_rut.Text);
                    }
                    string roll = "";
                    if (coc.IsSelected)
                    {
                        roll = "Cocinero";
                    }
                    else if (bart.IsSelected)
                    {
                        roll = "Bartender";
                    }
                    else if (Gar.IsSelected)
                    {
                        roll = "Garzón";
                    }
                    else if (fina.IsSelected)
                    {
                        roll = "Finanzas";
                    }
                    else if (Admin.IsSelected)
                    {
                        roll = "Administrador";
                    }
                    else if (caja.IsSelected)
                    {
                        roll = "caja";
                    }
                    else if (bodega.IsSelected)
                    {
                        roll = "Bodeguero";
                    }
                    else
                    {
                        lb2.Content = "Debe seleccionar un rol";
                    }

                    ub.rol              = roll;
                    ub.nom_usuario      = txt_nombre.Text;
                    ub.apellido_usuario = txt_apellido.Text;
                    ub.fono             = Int32.Parse(txt_fono.Text);
                    ub.direccion        = txt_direccion.Text;
                    ub.rut              = Int32.Parse(txt_rut.Text);
                    ub.clave            = txt_Contrasena.Text;
                    string[] partesnom = txt_nombre.Text.Split(' ');
                    string[] partesape = txt_apellido.Text.Split(' ');
                    string   primera   = partesnom[0];
                    string   segunda   = partesape[0];

                    string nick      = (primera + "." + segunda).ToString();
                    bool   nickexist = ub.Getnick(nick);
                    string namefinal = "";
                    if (nickexist)
                    {
                        namefinal = nick;
                    }
                    else
                    {
                        namefinal = nick;
                    }

                    string habilitado = "";
                    if (rdb_habilitar.IsChecked == true)
                    {
                        habilitado = "Si";
                    }
                    else
                    {
                        habilitado = lb_estado.Content.ToString();
                    }
                    int    rutt = Int32.Parse(txt_rut.Text);
                    string nom  = namefinal;
                    string pass = txt_Contrasena.Text;
                    ub.AlterInfoUser(ub);
                    ub.AlterUser(rutt, namefinal, roll, pass, habilitado);
                    PopupNotifier popup = new PopupNotifier();
                    popup.TitleText         = "Aviso";
                    popup.Image             = Properties.Resources.add;
                    popup.ContentText       = "El usuario con RUT: " + txt_rut.Text + " Fue modificado de forma exitosa";
                    popup.AnimationDuration = 1000;
                    popup.Delay             = 1500;
                    popup.Popup();
                    txt_rut.Text             = "";
                    txt_nombre.Text          = "";
                    txt_apellido.Text        = "";
                    cbb_rol.SelectedIndex    = -1;
                    txt_fono.Text            = "";
                    txt_direccion.Text       = "";
                    txt_Contrasena.Text      = "";
                    rdb_habilitar.IsEnabled  = false;
                    txt_nombre.IsEnabled     = false;
                    txt_apellido.IsEnabled   = false;
                    cbb_rol.IsEnabled        = false;
                    txt_fono.IsEnabled       = false;
                    txt_direccion.IsEnabled  = false;
                    txt_Contrasena.IsEnabled = false;
                    rdb_habilitar.IsChecked  = false;
                }
                else
                {
                    lb1.Content = "Este rut no está registrado en el sistema";
                }
            }
            else
            {
            }
        }
Ejemplo n.º 2
0
        private void Btn_adduser_Click(object sender, RoutedEventArgs e)
        {
            usuarioBLL ub = new usuarioBLL();
            Generic    g  = new Generic();

            verificar();

            bool nombre     = true;
            bool apellido   = true;
            bool rut        = true;
            bool rol        = true;
            bool fono       = true;
            bool direccion  = true;
            bool contrasena = true;

            if (coc.IsSelected || bart.IsSelected || Admin.IsSelected || Gar.IsSelected || fina.IsSelected || caja.IsSelected || bodega.IsSelected)
            {
                rol = true;
            }
            else
            {
                rol         = false;
                lb2.Content = "Ingrese un rol";
            }

            if (txt_apellido.Text.Trim() == "")
            {
                nombre      = false;
                lb4.Content = "Ingrese un apellido";
            }

            if (txt_pass.Text == "")
            {
                contrasena  = false;
                lb7.Content = "Ingrese una contraseña";
            }

            if (txt_nombre.Text.Trim() == "")
            {
                apellido    = false;
                lb3.Content = "Ingrese un nombre";
            }

            if (txt_rut.Text.Trim() == "")
            {
                rut         = false;
                lb1.Content = "Ingrese un rut";
            }

            if (txt_direccion.Text.Trim() == "")
            {
                direccion   = false;
                lb6.Content = "Ingrese una dirección";
            }

            if (txt_fono.Text.Trim() == "")
            {
                fono        = false;
                lb5.Content = "Ingrese un número";
            }



            if (nombre == true && rut == true && apellido == true && rol == true && fono == true && direccion == true && contrasena == true)
            {
                ub.id_usuario = Int32.Parse(txt_rut.Text);
                string roll = "";
                if (coc.IsSelected)
                {
                    roll = "Cocinero";
                }
                else if (bart.IsSelected)
                {
                    roll = "Bartender";
                }
                else if (Gar.IsSelected)
                {
                    roll = "Garzon";
                }
                else if (fina.IsSelected)
                {
                    roll = "Finanzas";
                }
                else if (Admin.IsSelected)
                {
                    roll = "Administrador";
                }
                else if (caja.IsSelected)
                {
                    roll = "Caja";
                }
                else if (bodega.IsSelected)
                {
                    roll = "Bodeguero";
                }
                else
                {
                    lb2.Content = "Ingrese un rol";
                }
                ub.rol = roll;

                string[] partesnom = txt_nombre.Text.Split(' ');
                string[] partesape = txt_apellido.Text.Split(' ');
                string   primera   = partesnom[0];
                string   segunda   = partesape[0];

                string nick      = (primera + "." + segunda).ToString();
                bool   nickexist = ub.Getnick(nick);
                string namefinal = "";
                if (nickexist)
                {
                    string primera1 = partesnom[1];
                    string name     = primera + primera1 + segunda;
                    namefinal = name;
                }
                else
                {
                    namefinal = nick;
                }
                ub.nom_usuario      = txt_nombre.Text;
                ub.apellido_usuario = txt_apellido.Text;
                ub.fono             = Int32.Parse(txt_fono.Text);
                ub.direccion        = txt_direccion.Text;
                ub.rut = Int32.Parse(txt_rut.Text);
                string nomb = txt_nombre.Text + " " + txt_apellido.Text;
                string ru   = txt_rut.Text;
                string ro   = roll;
                ub.clave = txt_pass.Text;
                bool existe = ub.GetUserByRut(Int32.Parse(txt_rut.Text));
                if (existe)
                {
                    PopupNotifier popup = new PopupNotifier();
                    popup.TitleText         = "Aviso";
                    popup.Image             = Properties.Resources.add;
                    popup.ContentText       = "El usuario con RUT: " + ru + " Ya existe en sistema";
                    popup.AnimationDuration = 500;
                    popup.Delay             = 3500;
                    popup.Popup();
                }
                else
                {
                    ub.AddUser(Int32.Parse(txt_rut.Text), namefinal, txt_pass.Text, roll, "Si");
                    ub.AddinfoUser(ub);
                    PopupNotifier popup = new PopupNotifier();
                    popup.TitleText   = "Aviso";
                    popup.Image       = Properties.Resources.add;
                    popup.ContentText = "Se ha Creado el usuario: " + nomb + "\n" +
                                        "RUT: " + ru + "\n" +
                                        "ROL: " + roll;
                    popup.AnimationDuration = 800;
                    popup.Delay             = 1000;
                    popup.Popup();
                    txt_rut.Clear();
                    txt_nombre.Clear();
                    txt_apellido.Clear();
                    cbb_rol.SelectedIndex = -1;
                    txt_fono.Clear();
                    txt_direccion.Clear();
                    txt_pass.Clear();
                }
            }
        }