public void mostrar() { try { CampanaController func = new CampanaController(); dt = func.mostrar(); datalistado.Columns["Eliminar"].Visible = false; if (dt.Rows.Count != 0) { datalistado.DataSource = dt; txtBuscar.Enabled = true; datalistado.ColumnHeadersVisible = true; inexistente.Visible = true; } else { datalistado.DataSource = null; txtBuscar.Enabled = false; datalistado.ColumnHeadersVisible = false; inexistente.Visible = true; } } catch (Exception e) { MessageBox.Show(e.Message, "Error"); } btnEditar.Enabled = false; buscar(); }
private void btnEditar_Click(object sender, EventArgs e) { DialogResult result; result = MessageBox.Show("Realmente desea editar los datos del Campana", "Modificando Registros", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (result == DialogResult.OK) { if (this.ValidateChildren() == true && txtNombre.Text != "" && txtMensaje.Text != "") { try { Campana dts = new Campana(); CampanaController func = new CampanaController(); dts.id = Convert.ToInt32(txtIdPaciente.Text); dts.nombre = txtNombre.Text; dts.mensaje = txtMensaje.Text; //guardar imagen MemoryStream ms = new MemoryStream(); if (imagen.Image != null) { dts.imagen = txtImagenName.Text; imagen.Image.Save(ms, imagen.Image.RawFormat); FileStream file = new FileStream(path + dts.imagen, FileMode.Create, FileAccess.Write); ms.WriteTo(file); file.Close(); } else { MessageBox.Show("Seleccione una imagen", "Aviso"); return; } if (func.editar(dts)) { MessageBox.Show("Campana modificado correctamente", "Modificando registros", MessageBoxButtons.OK, MessageBoxIcon.Information); mostrar(); limpiar(); } else { MessageBox.Show("Campana no fue modificado", "Ingrese de nuevo", MessageBoxButtons.OK, MessageBoxIcon.Error); mostrar(); limpiar(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error"); } } else { MessageBox.Show("Falta ingresar algunos datos", "Modificando registros", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
private void btnEliminar_Click(object sender, EventArgs e) { DialogResult result; result = MessageBox.Show("Realmente desea eliminar los Registros seleccionados?", "Eliminando Registros", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (result == DialogResult.OK) { try { foreach (DataGridViewRow row in datalistado.Rows) { Boolean marcado = Convert.ToBoolean(row.Cells["Eliminar"].Value); if (marcado) { int onekey = Convert.ToInt32(row.Cells["id"].Value); Campana campana = new Campana(); CampanaController func = new CampanaController(); campana.id = onekey; if (func.eliminar(campana)) { cbEliminar.Checked = false; } else { MessageBox.Show("Campana no fue eliminado", "Eliminando Registros", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } mostrar(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error"); } } else { MessageBox.Show("Cancelar eliminar registros", "Eliminando Registros", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void btnGuardar_Click(object sender, EventArgs e) { if (this.ValidateChildren() == true && txtNombre.Text != "" && txtMensaje.Text != "") { try { Campana dts = new Campana(); CampanaController func = new CampanaController(); dts.nombre = txtNombre.Text; dts.mensaje = txtMensaje.Text; //guardar imagen MemoryStream ms = new MemoryStream(); if (imagen.Image != null) { dts.imagen = txtImagenName.Text; imagen.Image.Save(ms, imagen.Image.RawFormat); FileStream file = new FileStream(path + dts.imagen, FileMode.Create, FileAccess.Write); ms.WriteTo(file); file.Close(); } else { MessageBox.Show("Seleccione una imagen", "Aviso"); return; } if (func.insertar(dts)) { MessageBox.Show("Campana registrado correctamente", "Guardando registros", MessageBoxButtons.OK, MessageBoxIcon.Information); btnNuevo.Visible = true; mostrar(); limpiar(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error"); } } }