Esempio n. 1
0
 public List <EColegios> ListaColegios()
 {
     try
     {
         string sql = "select ColegioId,Colegio,Telefono,c.DepartamentoId,Departamento from dba.colegio c inner \n" +
                      "join dba.Departamentos d on c.DepartamentoId = d.DepartamentoID";
         comando             = new SqlCommand(sql, conexion);
         comando.CommandType = CommandType.Text;
         comando.Connection  = conexion;
         conexion.Open();
         List <EColegios> lista = new List <EColegios>();
         SqlDataReader    leer  = comando.ExecuteReader();
         while (leer.Read())
         {
             EColegios c = new EColegios();
             c.ColegioId      = (int)leer[0];
             c.Colegio        = leer[1].ToString();
             c.Telefono       = leer[2].ToString();
             c.DepartamentoID = (int)leer["DepartamentoId"];
             c.Departamento   = leer["Departamento"].ToString();
             lista.Add(c);
         }
         leer.Close();
         conexion.Close();
         conexion.Dispose();
         return(lista);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Esempio n. 2
0
 public void EliminarColegio(EColegios c)
 {
     try
     {
         if (c.ColegioId == 0)
         {
             throw new ArgumentException("Colegio no existe");
         }
         DColegios d = new DColegios();
         d.EliminarColegio(c);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Esempio n. 3
0
 public void ModificarColegio(EColegios c)
 {
     try
     {
         if (c.Colegio == "")
         {
             throw new ArgumentException("Ingrese Nombre del Colegio");
         }
         DColegios d = new DColegios();
         d.ModificarColegio(c);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Esempio n. 4
0
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            try
            {
                EColegios C = new EColegios();
                NColegio  n = new NColegio();

                if (Bandera == 0)
                {
                    if (cbmDepartmento.SelectedValue != null)
                    {
                        C.Colegio        = txtcolegio.Text;
                        C.Telefono       = txttelefono.Text;
                        C.DepartamentoID = Convert.ToInt32(cbmDepartmento.SelectedValue.ToString());
                        n.IngresarColegio(C);
                        limpiar();
                        CargarColegios();
                    }
                    else
                    {
                        MessageBox.Show("Seleccione un departamento");
                    }
                }
                if (Bandera == 1)
                {
                    if (chkeditar.Checked == true)
                    {
                        C.ColegioId      = Convert.ToInt32(txtcolegio.Tag);
                        C.Colegio        = txtcolegio.Text;
                        C.Telefono       = txttelefono.Text;
                        C.DepartamentoID = int.Parse(cbmDepartmento.SelectedValue.ToString());
                        n.ModificarColegio(C);
                        MessageBox.Show("Colegio Modificado correctamente", "SGA", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        limpiar();
                        CargarColegios();
                    }
                    else
                    {
                        MessageBox.Show("Si has elegido un dato, por favor vuelve a marcar el check EDITAR", "SGA", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "SGA", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 5
0
 public void EliminarColegio(EColegios c)
 {
     try
     {
         comando             = new SqlCommand("EliminarColegio");
         comando.CommandType = CommandType.StoredProcedure;
         comando.Parameters.AddWithValue("@ColegioId", c.ColegioId);
         comando.Connection = conexion;
         conexion.Open();
         comando.ExecuteNonQuery();
         conexion.Close();
         conexion.Dispose();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Esempio n. 6
0
 public void IngresarColegio(EColegios c)
 {
     try
     {
         comando             = new SqlCommand("IngresarColegio");
         comando.CommandType = CommandType.StoredProcedure;
         comando.Parameters.AddWithValue("@Colegio", c.Colegio);
         comando.Parameters.AddWithValue("@Telefono", c.Telefono);
         comando.Parameters.AddWithValue("@DepartamentoId", c.DepartamentoID);
         comando.Connection = conexion;
         conexion.Open();
         comando.ExecuteNonQuery();
         conexion.Close();
         conexion.Dispose();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Esempio n. 7
0
 private void eliminarToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         EColegios c = new EColegios();
         NColegio  n = new NColegio();
         c.ColegioId = Convert.ToInt32(dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["ColegioId"].Value.ToString());
         var          colegio = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["Colegio"].Value.ToString();
         DialogResult o       = MessageBox.Show("¿Eliminar el Departamento " + colegio + "?", "SGA", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
         if (o == DialogResult.OK)
         {
             n.EliminarColegio(c);
             MessageBox.Show("Colegio eliminado correctamente", "SGA", MessageBoxButtons.OK, MessageBoxIcon.Information);
             CargarColegios();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "SGA", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Esempio n. 8
0
 public void IngresarColegio(EColegios c)
 {
     try
     {
         if (c.Colegio == "")
         {
             throw new ArgumentException("Ingrese Nombre del Colegio");
         }
         List <EColegios> l = ListaColegios().Where(x => x.Colegio == c.Colegio && x.DepartamentoID == c.DepartamentoID).ToList();
         if (l.Count > 0)
         {
             throw new ArgumentException("El Colegio : " + c.Colegio + " ya existe");
         }
         DColegios d = new DColegios();
         d.IngresarColegio(c);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }