private void tsbActualzar_Click(object sender, EventArgs e) { try { this.Cursor = Cursors.WaitCursor; if (LosDatosIngresadosSonCorrectos()) { if (txtIdentificador.Text.Length == 0 || txtIdentificador.Text == "0") { MessageBox.Show("No se puede continuar. Ha ocurrido un error y el registro no ha sido cargado correctamente.", OperacionARealizar, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } if (MessageBox.Show("¿Está seguro que desea aplicar los cambios al registro seleccionado?", "Actualizar la Confirmación", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button3) == System.Windows.Forms.DialogResult.No) { return; } ContactoEN oRegistroEN = InformacionDelRegistro(); ContactoLN oRegistroLN = new ContactoLN(); /*if (oRegistroLN.ValidarSiElRegistroEstaVinculado(oRegistroEN, Program.oDatosDeConexion, "ACTUALIZAR")) * { * this.Cursor = Cursors.Default; * MessageBox.Show(oRegistroLN.Error, this.OperacionARealizar, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); * return; * }*/ if (oRegistroLN.ValidarRegistroDuplicado(oRegistroEN, Program.oDatosDeConexion, "ACTUALIZAR")) { this.Cursor = Cursors.Default; MessageBox.Show(oRegistroLN.Error, "Actualizar la información", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (Controles.IsNullOEmptyElControl(txtCedula) == false) { if (oRegistroLN.ValidarRegistroDuplicadoParaCedula(oRegistroEN, Program.oDatosDeConexion, "ACTUALIZAR")) { MessageBox.Show(oRegistroLN.Error, "Guardar información", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } if (oRegistroLN.Actualizar(oRegistroEN, Program.oDatosDeConexion)) { GuardarActualizarVinculo(); EvaluarErrorParaMensajeAPantalla(oRegistroLN.Error, "Actualizar"); oRegistroEN = null; oRegistroLN = null; this.Cursor = Cursors.Default; if (CerrarVentana == true) { this.Close(); } } else { throw new ArgumentException(oRegistroLN.Error); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Actualizar información del registro", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void tsbGuardar_Click(object sender, EventArgs e) { try { this.Cursor = Cursors.WaitCursor; if (LosDatosIngresadosSonCorrectos()) { ContactoEN oRegistroEN = InformacionDelRegistro(); ContactoLN oRegistroLN = new ContactoLN(); if (oRegistroLN.ValidarRegistroDuplicado(oRegistroEN, Program.oDatosDeConexion, "AGREGAR")) { MessageBox.Show(oRegistroLN.Error, "Guardar información", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (Controles.IsNullOEmptyElControl(txtCedula) == false) { if (oRegistroLN.ValidarRegistroDuplicadoParaCedula(oRegistroEN, Program.oDatosDeConexion, "AGREGAR")) { MessageBox.Show(oRegistroLN.Error, "Guardar información", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } EntidadEN oEntidadEN = informacionDeLaEntidad(); EntidadLN oEntidadLN = new EntidadLN(); if (oEntidadLN.Agregar(oEntidadEN, Program.oDatosDeConexion)) { oRegistroEN.idContacto = oEntidadEN.idEntidad; if (oRegistroLN.Agregar(oRegistroEN, Program.oDatosDeConexion)) { txtIdentificador.Text = oRegistroEN.idContacto.ToString(); ValorLlavePrimariaEntidad = oRegistroEN.idContacto; txtCodigo.Text = oRegistroEN.Codigo; GuardarActualizarVinculo(); EvaluarErrorParaMensajeAPantalla(oRegistroLN.Error, "Guardar"); if (CerrarVentana == true) { this.Cursor = Cursors.Default; this.Close(); } else { OperacionARealizar = "Modificar"; ObtenerValoresDeConfiguracion(); DeshabilitarControlesSegunOperacionesARealizar(); EstablecerTituloDeVentana(); LlamarMetodoSegunOperacion(); } } else { oEntidadLN.Eliminar(oEntidadEN, Program.oDatosDeConexion); string mensaje = string.Format("Se ha encontrado el siguiente error al Guardar la iformación del Contacto: {0} {1} {0} Desea continuar ingresando la información del Contacto", Environment.NewLine, oRegistroLN.Error); throw new ArgumentException(mensaje); } } else { string mensaje = string.Format("Se ha encontrado el siguiente error: {0} {1} {0} Desea continuar ingresando la información", Environment.NewLine, oEntidadLN.Error); throw new ArgumentException(mensaje); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Guardar la información del registro", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { this.Cursor = Cursors.Default; } }