private void InisiarSesion()
        {
            DataBaseControl DBControl = new DataBaseControl(DataBaseControl.cPath, "ProjectDataBase.mdf");

            string[] parameters = { "@id", "@pass" };
            string[] elements   = { TxtUserName.Text, TxtPassword.Text };
            TxtUserName.Clear();
            TxtPassword.Clear();
            List <string> admins = new List <string> {
                "Admin", "Develop"
            };

            if (DBControl.Buscar("select * from Users where [UserName]=@id and [KeyWord]=@pass", parameters, elements))
            {
                string       cat      = DBControl.BuscarElemento("select [Category] from Users where [UserName]=@id and [KeyWord]=@pass", parameters, elements);
                MainPageForm mainPage = new MainPageForm(cat);
                this.Hide();
                mainPage.ShowDialog();
                this.Show();
                TxtUserName.Focus();
            }
            else
            {
                MessageBox.Show("Usuario o contraseña inválidos");
                TxtUserName.Focus();
            }
        }
Exemple #2
0
        private void MaterialLayout_Load(object sender, EventArgs e)
        {
            DataBaseControl DBControl = new DataBaseControl(DataBaseControl.cPath, "ProjectDataBase.mdf");

            string[] para = { "@id" };
            string[] val  = { System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString() };
            if (cat != "Adm" || cat != "Develop")
            {
                if (DBControl.Buscar("select * from Activos where [id]=@id", para, val))
                {
                    int activos = int.Parse(DBControl.BuscarElemento("select [registros] from [Activos] where [ID] = @id", para, val));
                    if (activos > 1)
                    {
                        this.Size = new Size(336, 313);
                        LbCat.Hide();
                        CBCat.Hide();
                        cat = "User";
                    }
                    else
                    {
                        this.Size = new Size(497, 313);
                        LbCat.Show();
                        CBCat.Show();
                        cat = "Adm";
                    }
                }
                else
                {
                    string[] nums = { System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString(), "0" };
                    para = new string[] { "@id", "@nums" };
                    if (DBControl.Insertar("Insert into [Activos] values(@id,@nums)", para, nums))
                    {
                        this.Size = new Size(497, 313);
                        LbCat.Show();
                        CBCat.Show();
                        cat = "Adm";
                    }
                    else
                    {
                        MessageBox.Show("Algún error inesperado ha ocurrido, por favor, intente de nuevo");
                        this.Close();
                    }
                }
            }

            CBCat.SelectedValue = cat;
        }
        private void TxtUserName_TextChanged(object sender, EventArgs e)
        {
            if (TxtUserName.Text.Length > 0)
            {
                DataBaseControl DBControl = new DataBaseControl(DataBaseControl.cPath, "ProjectDataBase.mdf");
                LVUsuarios.Clear();
                string[] _parameters = { "@userN" };
                string[] _element    = { TxtUserName.Text };
                string[] _returned   = { "UserName" };

                foreach (string[] item in DBControl.Buscar("Select [UserName] from [Users] where [Username] like '%' + @userN + '%'", _parameters, _element, 1))
                {
                    foreach (var it in item)
                    {
                        LVUsuarios.Items.Add(new ListViewItem(it));
                    }
                }
                DBControl.Close();
            }
        }