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();
            }
        }
        private void VerCalificacionesForm_Load(object sender, EventArgs e)
        {
            DataBaseControl DBControl = new DataBaseControl(DataBaseControl.cPath, "ProjectDataBase.mdf");
            BindingSource   CalSource = new BindingSource();

            CalSource.DataSource                = DBControl.ObtenerTabla("Select * from Calificaciones");
            DGVCalificacion.DataSource          = CalSource;
            DGVCalificacion.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            DGVCalificacion.ReadOnly            = true;
        }
        private void VerMateriasForm_Load(object sender, EventArgs e)
        {
            DataBaseControl DBControl = new DataBaseControl(DataBaseControl.cPath, "ProjectDataBase.mdf");
            BindingSource   MatSource = new BindingSource();

            MatSource.DataSource            = DBControl.ObtenerTabla("Select * from Materias");
            DGVMaterias.DataSource          = MatSource;
            DGVMaterias.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            DGVMaterias.ReadOnly            = true;
        }
Exemple #4
0
        private void VerAlumnosForm_Load_1(object sender, EventArgs e)
        {
            DataBaseControl DBControl   = new DataBaseControl(DataBaseControl.cPath, "ProjectDataBase.mdf");
            BindingSource   AlumnSource = new BindingSource();

            AlumnSource.DataSource        = DBControl.ObtenerTabla("Select * from Alumnos");
            DGVAlumno.DataSource          = AlumnSource;
            DGVAlumno.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            DGVAlumno.ReadOnly            = true;
        }
        private void TxtBuscar_TextChanged(object sender, EventArgs e)
        {
            DataBaseControl DBControl = new DataBaseControl(DataBaseControl.cPath, "ProjectDataBase.mdf");
            BindingSource   AlmSource = new BindingSource();

            string[] parameters = { "@word" };
            string[] value      = { TxtBuscar.Text };
            AlmSource.DataSource           = DBControl.ObtenerTabla("Select * from Alumnos where [Nombre] like '%'+@word+'%' or [ID] like '%'+@word+'%' ", parameters, value);
            DGVAlumnos.DataSource          = AlmSource;
            DGVAlumnos.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            DGVAlumnos.ReadOnly            = true;
        }
Exemple #6
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 BtEliminar_Click_1(object sender, EventArgs e)
 {
     try
     {
         DataBaseControl DBControl = new DataBaseControl(DataBaseControl.cPath, "ProjectDataBase.mdf");
         string[]        para      = { "@user" };
         string[]        ele       = { TxtUserName.Text };
         if (DBControl.Eliminar("Delete from [Users] where [Username] = @user", para, ele))
         {
             MessageBox.Show("Usuario eliminado con exito");
         }
         else
         {
             MessageBox.Show("Error al eliminar usuario");
         }
         DBControl.Close();
     }
     catch (Exception) { MessageBox.Show("Por favor, verificar los datos"); }
 }
Exemple #8
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); }
        }
        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();
            }
        }
Exemple #10
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");
            }
        }