void CargarColegios() { try { NColegio n = new NColegio(); List <EColegios> lista = n.ListaColegios().OrderBy(x => x.Departamento).ToList(); dataGridView1.DataSource = lista; CargarDepartamento(); dataGridView1.Columns[0].Visible = false; dataGridView1.Columns[3].Visible = false; } catch (Exception ex) { throw ex; } }
void CargaColegio() { try { NColegio n = new NColegio(); List <EColegios> listaColegio = n.ListaColegios(); cbmColegio.DataSource = listaColegio; cbmColegio.DisplayMember = "Colegio"; cbmColegio.ValueMember = "ColegioId"; cbmColegio.Text = "Seleccione Colegio"; } catch (Exception ex) { throw ex; } }
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); } }
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); } }