private void AgregarRegistroForm_Load(object sender, EventArgs e)
        {
            if (Verificar())
            {
                BtVincular.Enabled = true;
            }
            else
            {
                BtVincular.Enabled = false;
            }
            DataBaseControl DbControl = new DataBaseControl(DataBaseControl.cPath, "ProjectDataBase.mdf");

            string[]        para    = new string[] { "@algo" };
            string[]        val     = new string[] { " " };
            List <string[]> alumnos = DbControl.Buscar("Select [ID] from Alumnos where [ID]!=@algo", para, val, 1);

            foreach (string[] list in alumnos)
            {
                foreach (string objeto in list)
                {
                    CBAlumno.Items.Add(objeto);
                }
            }
            para = new string[] { "@algo" };
            val  = new string[] { " " };
            List <string[]> Materias = DbControl.Buscar("Select [Clave] from Materias where [Clave]!=@algo", para, val, 1);

            foreach (string[] list in Materias)
            {
                foreach (string objeto in list)
                {
                    CBMateria.Items.Add(objeto);
                }
            }
        }
Exemplo n.º 2
0
 private void BtEliminar_Click(object sender, EventArgs e)
 {
     try
     {
         DataBaseControl DBControl = new DataBaseControl(DataBaseControl.cPath, "ProjectDataBase.mdf");
         string[]        para      = { "@user" };
         string[]        ele       = { TxtUserName.Text };
         if (DBControl.Buscar("Select * from [Registro] where [materia]= @user", para, ele))
         {
             MessageBox.Show("Esta materia actualmente figura en una seccion, imposible eliminar");
             TxtUserName.Clear();
             return;
         }
         else
         {
             if (DBControl.Eliminar("Delete from [Materias] where [Clave] = @user", para, ele))
             {
                 MessageBox.Show("Materia eliminado con exito");
                 LVUsuarios.Clear();
             }
             else
             {
                 MessageBox.Show("Error al eliminar Materia");
             }
         }
     }
     catch (Exception) { MessageBox.Show("Por favor, verificar los datos"); }
 }
        private void BtVincular_Click(object sender, EventArgs e)
        {
            try
            {
                bool keep = true;

                DataBaseControl DbControl  = new DataBaseControl(DataBaseControl.cPath, "ProjectDataBase.mdf");
                string[]        parameters = { "@word" };
                string[]        value      = { CBAlumno.SelectedItem.ToString() };

                keep = DbControl.Buscar("Select * from Alumnos where [ID] = @word", parameters, value);
                if (keep)
                {
                    parameters = new string[] { "@word" };
                    value      = new string[] { CBMateria.SelectedItem.ToString() };
                    keep       = DbControl.Buscar("Select * from Materias where [Clave] = @word", parameters, value);
                    if (!keep)
                    {
                        keep = false;
                    }
                }

                if (keep == false)
                {
                    MessageBox.Show("Es imposible vincular una materia a un estudiante si uno de los dos no existe");
                }
                else
                {
                    string[] Parameters = new string[] { "@Alm", "@Mat" };
                    string[] values     = new string[] { CBAlumno.SelectedItem.ToString(), CBMateria.SelectedItem.ToString() };
                    if (!DbControl.Buscar("Select * from [Registro] where [Alumno] = @Alm and [Materia] = @Mat", Parameters, values))
                    {
                        DbControl.Insertar("Insert into  [Registro] ([Alumno],[Materia]) values (@Alm,@Mat)", Parameters, values);

                        MessageBox.Show(string.Format("{0} fue inscrito en {1}", CBMateria.SelectedItem.ToString(), CBMateria.SelectedItem.ToString()));
                        CBAlumno.SelectedItem  = null;
                        CBMateria.SelectedItem = null;
                        Verificar();
                    }
                    else
                    {
                        MessageBox.Show("El alumno ya está inscrito en esta materia");
                    }
                }
            }
            catch (Exception) { MessageBox.Show("Por favor, verifique los datos"); }
        }
Exemplo n.º 4
0
        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", "@Materia" };
                string[] _element    = { TxtUserName.Text, TxtMateria.Text };

                foreach (string[] item in DBControl.Buscar("Select [Materia] from [Registro] where [Alumno] = @userN ", _parameters, _element, 1))
                {
                    foreach (var it in item)
                    {
                        LVUsuarios.Items.Add(new ListViewItem(it));
                    }
                }
            }
        }
        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 [ID] from [Maestros] where [ID] like '%' + @userN + '%'", _parameters, _element, 1))
                {
                    foreach (var it in item)
                    {
                        LVUsuarios.Items.Add(new ListViewItem(it));
                    }
                }
            }
        }