public bool Eliminar(EntidadEN oREgistroEN, DatosDeConexionEN oDatos) { if (string.IsNullOrEmpty(oREgistroEN.idEntidad.ToString()) || oREgistroEN.idEntidad == 0) { this.Error = @"Se debe de seleccionar un elemento de la lista"; return(false); } if (oEntidadAD.Eliminar(oREgistroEN, oDatos)) { Error = string.Empty; return(true); } else { Error = oEntidadAD.Error; return(false); } }
private TransaccionesEN InformacionDelaTransaccion(EntidadEN oEntidad, String TipoDeOperacion, String Descripcion, String Estado) { TransaccionesEN oRegistroEN = new TransaccionesEN(); oRegistroEN.idregistro = oEntidad.idEntidad; oRegistroEN.Modelo = "General"; oRegistroEN.Modulo = "General"; oRegistroEN.Tabla = "Entidad"; oRegistroEN.tipodeoperacion = TipoDeOperacion; oRegistroEN.Estado = Estado; oRegistroEN.ip = oEntidad.oLoginEN.NumeroIP; oRegistroEN.idusuario = oEntidad.oLoginEN.idUsuario; oRegistroEN.idusuarioaprueba = oEntidad.oLoginEN.idUsuario; oRegistroEN.descripciondelusuario = DescripcionDeOperacion; oRegistroEN.descripcioninterna = Descripcion; oRegistroEN.NombreDelEquipo = oEntidad.oLoginEN.NombreDelComputador; return(oRegistroEN); }
private EntidadEN informacionDeLaEntidad() { EntidadEN oRegistroEN = new EntidadEN(); try { oRegistroEN.oTipoDeEntidadEN.Nombre = "Proveedor"; oRegistroEN.oTipoDeEntidadEN.NombreInterno = "proveedor"; oRegistroEN.oLoginEN = Program.oLoginEN; oRegistroEN.IdUsuarioDeCreacion = Program.oLoginEN.idUsuario; oRegistroEN.IdUsuarioDeModificacion = Program.oLoginEN.idUsuario; oRegistroEN.FechaDeCreacion = System.DateTime.Now; oRegistroEN.FechaDeModificacion = System.DateTime.Now; return(oRegistroEN); } catch (Exception ex) { MessageBox.Show(ex.Message, "Información de la entidad", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(oRegistroEN); } }
private void button1_Click(object sender, EventArgs e) { try { this.Cursor = Cursors.WaitCursor; btnImportarDesdeExcel.Enabled = false; btnCerrarVentana.Enabled = false; if (dgvListar.Rows.Count > 0) { pbBarra.Visible = true; lbEtiqueta.Visible = true; pbBarra.Maximum = dgvListar.Rows.Count; pbBarra.Minimum = 1; foreach (DataGridViewRow Fila in dgvListar.Rows) { pbBarra.Value = Fila.Index + 1; Fila.Selected = true; ProveedorEN oRegistroEN = InformacionDelProveedor(Fila); ProveedorLN oRegistroLN = new ProveedorLN(); if (oRegistroLN.ValidarRegistroDuplicado(oRegistroEN, Program.oDatosDeConexion, "AGREGAR")) { string mensaje = string.Format("Se ha encontrado el siguiente error: {0} {1} {0} Desea continuar ingresando la información", Environment.NewLine, oRegistroLN.Error); if (MessageBox.Show(mensaje, "Guardando información del proveedor", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel) { throw new ArgumentException("La operación asido cancelada por el usuario"); } continue; } /*Primero agregaremos la entidad mayor...*/ EntidadEN oEntidadEN = informacionDeLaEntidad(); EntidadLN oEntidadLN = new EntidadLN(); if (oEntidadLN.Agregar(oEntidadEN, Program.oDatosDeConexion)) { oRegistroEN.idProveedor = oEntidadEN.idEntidad; if (oRegistroLN.Agregar(oRegistroEN, Program.oDatosDeConexion) == false) { string mensaje = string.Format("Se ha encontrado el siguiente error al Guardar la iformación del Proveedor: {0} {1} {0} Desea continuar ingresando la información", Environment.NewLine, oRegistroLN.Error); oEntidadLN.Eliminar(oEntidadEN, Program.oDatosDeConexion); if (MessageBox.Show(mensaje, "Guardando información del proveedor", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel) { throw new ArgumentException("La operación asido cancelada por el usuario"); } } } else { string mensaje = string.Format("Se ha encontrado el siguiente error: {0} {1} {0} Desea continuar ingresando la información", Environment.NewLine, oEntidadLN.Error); if (MessageBox.Show(mensaje, "Guardando información del proveedor", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel) { throw new ArgumentException("La operación asido cancelada por el usuario"); } } /* if (oRegistroLN.AgregarUtilizandoLaMismaConexion(oRegistroEN, Program.oDatosDeConexion) == false) * { * string mensaje = string.Format("Se ha encontrado el siguiente error: {0} {1} {0} Desea continuar ingresando la información", Environment.NewLine, oRegistroLN.Error); * * if (MessageBox.Show(mensaje, "Guardando información del proveedor", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel) * { * throw new ArgumentException("La operación asido cancelada por el usuario"); * } * }*/ lbEtiqueta.Text = string.Format("{0} Registros Guardados de {1}", (Fila.Index + 1).ToString(), dgvListar.Rows.Count); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Guardar información del proveedor", MessageBoxButtons.OK, MessageBoxIcon.Warning); } finally { pbBarra.Visible = false; btnImportarDesdeExcel.Enabled = true; btnCerrarVentana.Enabled = true; lbEtiqueta.Visible = false; this.Cursor = Cursors.Default; } }
private void tsbGuardar_Click(object sender, EventArgs e) { try { this.Cursor = Cursors.WaitCursor; if (LosDatosIngresadosSonCorrectos()) { LaboratorioEN oRegistroEN = InformacionDelRegistro(); LaboratorioLN oRegistroLN = new LaboratorioLN(); if (oRegistroLN.ValidarRegistroDuplicado(oRegistroEN, Program.oDatosDeConexion, "AGREGAR")) { MessageBox.Show(oRegistroLN.Error, "Guardar información", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (Controles.IsNullOEmptyElControl(txtNoRUC) == false) { if (oRegistroLN.ValidarRegistroDuplicadoNoRUC(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.idLaboratorio = oEntidadEN.idEntidad; if (oRegistroLN.Agregar(oRegistroEN, Program.oDatosDeConexion)) { txtIdentificador.Text = oRegistroEN.idLaboratorio.ToString(); ValorLlavePrimariaEntidad = oRegistroEN.idLaboratorio; 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 Laboratorio: {0} {1} {0} Desea continuar ingresando la información del Laboratorio", 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; } }
public bool AgregarUtilizandoLaMismaConexion(ContactoEN oRegistroEN, DatosDeConexionEN oDatos) { oTransaccionesAD = new TransaccionesAD(); Cnn = new MySqlConnection(TraerCadenaDeConexion(oDatos)); Cnn.Open(); MySqlTransaction oMySqlTransaction; oMySqlTransaction = Cnn.BeginTransaction(); try { String mensaje = ""; string Errores = string.Empty; //Debemos agrear la Entidad Correspondiente EntidadEN oEntidadEN = new EntidadEN(); oEntidadEN.oTipoDeEntidadEN.Nombre = "Contacto"; oEntidadEN.oTipoDeEntidadEN.NombreInterno = "contacto"; EntidadAD oEntidadAD = new EntidadAD(); if (oEntidadAD.Agregar(oEntidadEN, oDatos, ref Cnn, ref oMySqlTransaction)) { oRegistroEN.idContacto = oEntidadEN.idEntidad; Errores = EvaluarTextoError(Errores, "GUARDAR", oEntidadAD.Error); } else { mensaje = String.Format("Error : '{1}', {0} producido al intentar guardar la información en la Entidad. ", Environment.NewLine, oEntidadAD.Error); throw new System.ArgumentException(mensaje); } oEntidadAD = null; oEntidadEN = null; if (Agregar(oRegistroEN, oDatos, ref Cnn, ref oMySqlTransaction)) { oRegistroEN.idContacto = oEntidadEN.idEntidad; Errores = EvaluarTextoError(Errores, "GUARDAR", this.Error); } else { mensaje = String.Format("Error : '{1}', {0} producido al intentar guardar la información del concto. ", Environment.NewLine, this.Error); throw new System.ArgumentException(mensaje); } this.Error = Errores; oMySqlTransaction.Commit(); return(true); } catch (Exception ex) { this.Error = ex.Message; oMySqlTransaction.Rollback(); DescripcionDeOperacion = string.Format("Se produjo el seguiente error: '{2}' al insertar el registro. {0} {1} ", Environment.NewLine, InformacionDelRegistro(oRegistroEN), ex.Message); //Agregamos la Transacción.... TransaccionesEN oTran = InformacionDelaTransaccion(oRegistroEN, "Agregar", "Agregar Nuevo Registro", "ERROR"); oTransaccionesAD.Agregar(oTran, oDatos); return(false); } finally { if (Cnn != null) { if (Cnn.State == ConnectionState.Open) { Cnn.Close(); } } Cnn = null; Comando = null; Adaptador = null; oTransaccionesAD = null; } }
public bool ValidarSiElRegistroEstaVinculado(EntidadEN oRegistroEN, DatosDeConexionEN oDatos, string TipoDeOperacion) { oTransaccionesAD = new TransaccionesAD(); try { Cnn = new MySqlConnection(TraerCadenaDeConexion(oDatos)); Cnn.Open(); Comando = new MySqlCommand(); Comando.Connection = Cnn; Comando.CommandType = CommandType.StoredProcedure; Comando.CommandText = "ValidarSiElRegistroEstaVinculado"; Comando.Parameters.Add(new MySqlParameter("@CampoABuscar_", MySqlDbType.VarChar, 200)).Value = "idEntidad"; Comando.Parameters.Add(new MySqlParameter("@ValorCampoABuscar", MySqlDbType.Int32)).Value = oRegistroEN.idEntidad; Comando.Parameters.Add(new MySqlParameter("@ExcluirTabla_", MySqlDbType.VarChar, 200)).Value = string.Empty; Adaptador = new MySqlDataAdapter(); DT = new DataTable(); Adaptador.SelectCommand = Comando; Adaptador.Fill(DT); if (DT.Rows[0].ItemArray[0].ToString().ToUpper() == "NINGUNA".ToUpper()) { return(false); } else { this.Error = String.Format("La Operación: '{1}', {0} no se puede completar por que el registro: {0} '{2}', {0} se encuentra asociado con: {0} {3}", Environment.NewLine, TipoDeOperacion, InformacionDelRegistro(oRegistroEN), oTransaccionesAD.ConvertirValorDeLaCadena(DT.Rows[0].ItemArray[0].ToString())); DescripcionDeOperacion = this.Error; //Agregamos la Transacción.... TransaccionesEN oTran = InformacionDelaTransaccion(oRegistroEN, "VALIDAR", "VALIDAR SI EL REGISTRO ESTA VINCULADO", "CORRECTO"); oTransaccionesAD.Agregar(oTran, oDatos); return(true); } } catch (Exception ex) { this.Error = ex.Message; DescripcionDeOperacion = string.Format("Se produjo el seguiente error: '{2}' al validar el registro. {0} {1} ", Environment.NewLine, InformacionDelRegistro(oRegistroEN), ex.Message); //Agregamos la Transacción.... TransaccionesEN oTran = InformacionDelaTransaccion(oRegistroEN, "VALIDAR", "VALIDAR SI EL REGISTRO ESTA VINCULADO", "ERROR"); oTransaccionesAD.Agregar(oTran, oDatos); return(false); } finally { if (Cnn != null) { if (Cnn.State == ConnectionState.Open) { Cnn.Close(); } } Cnn = null; Comando = null; Adaptador = null; oTransaccionesAD = null; } }
public bool Agregar(EntidadEN oRegistroEN, DatosDeConexionEN oDatos) { oTransaccionesAD = new TransaccionesAD(); try { Cnn = new MySqlConnection(TraerCadenaDeConexion(oDatos)); Cnn.Open(); Comando = new MySqlCommand(); Comando.Connection = Cnn; Comando.CommandType = CommandType.Text; Consultas = @" insert into entidad (idTipoDeEntidad, Estado, idUsuarioDeCreacion, FechaDeCreacion, idUsuarioModificacion, FechaDeModificacion) values ((Select idTipoDeEntidad from tipodeentidad where upper(trim(NombreInterno)) = upper(trim(@NombreInterno))), 'ACTIVO', @idUsuarioDeCreacion, current_timestamp(), @idUsuarioModificacion, current_timestamp()); Select last_insert_id() as 'ID';"; Comando.CommandText = Consultas; Comando.Parameters.Add(new MySqlParameter("@NombreInterno", MySqlDbType.VarChar, oRegistroEN.oTipoDeEntidadEN.NombreInterno.Trim().Length)).Value = oRegistroEN.oTipoDeEntidadEN.NombreInterno.Trim(); Comando.Parameters.Add(new MySqlParameter("@idUsuarioDeCreacion", MySqlDbType.Int32)).Value = oRegistroEN.IdUsuarioDeCreacion; Comando.Parameters.Add(new MySqlParameter("@idUsuarioModificacion", MySqlDbType.Int32)).Value = oRegistroEN.IdUsuarioDeModificacion; Adaptador = new MySqlDataAdapter(); DT = new DataTable(); Adaptador.SelectCommand = Comando; Adaptador.Fill(DT); oRegistroEN.idEntidad = Convert.ToInt32(DT.Rows[0].ItemArray[0].ToString()); DescripcionDeOperacion = string.Format("El registro fue Insertado Correctamente. {0} {1}", Environment.NewLine, InformacionDelRegistro(oRegistroEN)); //Agregamos la Transacción.... TransaccionesEN oTran = InformacionDelaTransaccion(oRegistroEN, "Agregar", "Agregar Nuevo Registro", "CORRECTO"); oTransaccionesAD.Agregar(oTran, oDatos); return(true); } catch (Exception ex) { this.Error = ex.Message; DescripcionDeOperacion = string.Format("Se produjo el seguiente error: '{2}' al insertar el registro. {0} {1} ", Environment.NewLine, InformacionDelRegistro(oRegistroEN), ex.Message); //Agregamos la Transacción.... TransaccionesEN oTran = InformacionDelaTransaccion(oRegistroEN, "Agregar", "Agregar Nuevo Registro", "ERROR"); oTransaccionesAD.Agregar(oTran, oDatos); return(false); } finally { if (Cnn != null) { if (Cnn.State == ConnectionState.Open) { Cnn.Close(); } } Cnn = null; Comando = null; Adaptador = null; oTransaccionesAD = null; } }
public bool Actualizar(EntidadEN oRegistroEN, DatosDeConexionEN oDatos) { oTransaccionesAD = new TransaccionesAD(); try { Cnn = new MySqlConnection(TraerCadenaDeConexion(oDatos)); Cnn.Open(); Comando = new MySqlCommand(); Comando.Connection = Cnn; Comando.CommandType = CommandType.Text; Consultas = @"UPDATE entidad SET Estado = @Estado, idUsuarioModificacion = @idUsuarioModificacion, FechaDeModificacion = current_timestamp() where idEntidad = @idEntidad;"; Comando.CommandText = Consultas; Comando.Parameters.Add(new MySqlParameter("@idEntidad", MySqlDbType.Int32)).Value = oRegistroEN.idEntidad; Comando.Parameters.Add(new MySqlParameter("@Estado", MySqlDbType.VarChar, oRegistroEN.Estado.Trim().Length)).Value = oRegistroEN.Estado.Trim(); Comando.Parameters.Add(new MySqlParameter("@idUsuarioModificacion", MySqlDbType.Int32)).Value = oRegistroEN.oLoginEN.idUsuario; Comando.ExecuteNonQuery(); DescripcionDeOperacion = string.Format("El registro fue Actualizado Correctamente. {0} {1}", Environment.NewLine, InformacionDelRegistro(oRegistroEN)); //Agregamos la Transacción.... TransaccionesEN oTran = InformacionDelaTransaccion(oRegistroEN, "Actualizar", "Actualizar Registro", "CORRECTO"); oTransaccionesAD.Agregar(oTran, oDatos); return(true); } catch (Exception ex) { this.Error = ex.Message; DescripcionDeOperacion = string.Format("Se produjo el seguiente error: '{2}' al actualizar el registro. {0} {1} ", Environment.NewLine, InformacionDelRegistro(oRegistroEN), ex.Message); //Agregamos la Transacción.... TransaccionesEN oTran = InformacionDelaTransaccion(oRegistroEN, "Actualizar", "Actualizar Registro", "ERROR"); oTransaccionesAD.Agregar(oTran, oDatos); return(false); } finally { if (Cnn != null) { if (Cnn.State == ConnectionState.Open) { Cnn.Close(); } } Cnn = null; Comando = null; Adaptador = null; oTransaccionesAD = null; } }