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();
            }
        }
示例#2
0
        private void BtGuardar_Click(object sender, EventArgs e)
        {
            try
            {
                DataBaseControl DBcontrol = new DataBaseControl(DataBaseControl.cPath, "ProjectDataBase.mdf");
                int             id        = AlumnosCS.GenerarID();
                string[]        Element   = { "@id" };
                string[]        values    = { id.ToString() };
                string          tempID    = DBcontrol.BuscarElemento("Select [ID] from Alumnos where [ID] = @id", Element, values);
                while (tempID != "No encontrado")
                {
                    id     = AlumnosCS.GenerarID();
                    values = new string[] { id.ToString() };
                    tempID = DBcontrol.BuscarElemento("Select [ID] from Alumnos where [ID] = @id", Element, values);
                }
                MemoryStream ms = new System.IO.MemoryStream();
                PBImage.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                AlumnosCS estudiante = new AlumnosCS(TxtNombre.Text, TxtApellido.Text, CBEstado.SelectedItem.ToString(), id, TxtCarrera.Text, TxtIdentificadorNacial.Text, DateTime.Parse(MTBFecha.Text).ToShortDateString());
                string[]  Elements   = new string[] { "@id", "@nombre", "@apellido", "@fecha", "@identifacor", "@estado", "@carrera", "@image" };
                string[]  Values     = new string[]  { estudiante.ID.ToString(), estudiante.Nombre, estudiante.Apellido, estudiante.FechaNacimiento.ToString(), estudiante.IdentificadorPersonal, estudiante.Estado, estudiante.Carrera };

                if (DBcontrol.Insertar("Insert into Alumnos values(@id,@nombre,@apellido,@fecha,@identifacor,@estado,@carrera,@image,0.0)", Elements, Values, ms))
                {
                    Console.WriteLine(MessageBox.Show(string.Format("{0} fue agregado", estudiante.Nombre)));
                }
                else
                {
                    Console.WriteLine(MessageBox.Show(string.Format("{0} no agregado", estudiante.Nombre)));
                }
                TxtNombre.Clear();
                TxtApellido.Clear();
                CBEstado.SelectedItem = null;
                id = 0;
                TxtCarrera.Clear();
                TxtIdentificadorNacial.Clear();
                MTBFecha.Clear();
                Image foto = Image.FromFile("intec.png");
                PBImage.Image = foto;
                Verificar();
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }
        }
示例#3
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;
        }
示例#4
0
        private void BtRegistrar_Click(object sender, EventArgs e)
        {
            try
            {
                if (TxtPass.Text == TxtUserName.Text)
                {
                    MessageBox.Show("El usuario y al contraseña no pueden ser iguales");
                    TxtUserName.Clear();
                    TxtPass.Clear();
                    return;
                }
                DataBaseControl DBControl  = new DataBaseControl(DataBaseControl.cPath, "ProjectDataBase.mdf");
                string[]        parameters = { "@userName", "@pass", "cat" };
                string[]        elements   = { TxtUserName.Text, TxtPass.Text, CBCat.SelectedItem.ToString() };
                if (DBControl.Insertar("insert into Users values(@userName,@pass,@cat)", parameters, elements))
                {
                    string[] para    = { "@id" };
                    string[] val     = { System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString() };
                    int      activos = int.Parse(DBControl.BuscarElemento("select [registros] from Activos where [ID] = @id", para, val));
                    para = new string[] { "@id", "@nums" };
                    string[] nums = { System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString(), (++activos).ToString(), };
                    DBControl.Insertar("update [Activos] set [registros]=@nums where [id]=@id", para, nums);

                    MessageBox.Show("Usuario agregado");
                    this.Close();
                }
                else
                {
                    MessageBox.Show("El usuario no pudo ser agregado");
                }
                DBControl.Close();
            }
            catch (Exception)
            {
                MessageBox.Show("Por favor, verifique los datos");
            }
        }