private void dgvLista_DoubleClick(object sender, EventArgs e) { if (ActivarFiltros == true) { int a = 0; this.Cursor = Cursors.WaitCursor; dgvLista.CurrentRow.Cells["Seleccionar"].Value = true; foreach (DataGridViewRow Fila in dgvLista.Rows) { if (Convert.ToBoolean(Fila.Cells["Seleccionar"].Value) == true) { a++; Array.Resize(ref oTiposDeEntradas, a); oTiposDeEntradas[a - 1] = new TiposDeEntradasEN(); oTiposDeEntradas[a - 1].idTipoDeEntrada = Convert.ToInt32(Fila.Cells["idTipoDeEntrada"].Value); oTiposDeEntradas[a - 1].Nombre = Fila.Cells["Nombre"].Value.ToString(); oTiposDeEntradas[a - 1].Descripcion = Fila.Cells["Descripcion"].Value.ToString(); } } this.Cursor = Cursors.Default; this.Close(); } }
private string InformacionDelRegistro(TiposDeEntradasEN oRegistroEN) { string Cadena = @"idTipoDeEntrada: {0}, Nombre: {1}, Descripcion: {2}, idUsuarioDeCreacion: {3}, FechaDeCreacion: {4}, idUsuarioModificacion: {5}, FechaDeModificacion: {6}"; Cadena = string.Format(Cadena, oRegistroEN.idTipoDeEntrada, oRegistroEN.Nombre, oRegistroEN.Descripcion, oRegistroEN.idUsuarioDeCreacion, oRegistroEN.FechaDeCreacion, oRegistroEN.idUsuarioModificacion, oRegistroEN.FechaDeModificacion); Cadena = Cadena.Replace(",", Environment.NewLine); return(Cadena); }
public bool Eliminar(TiposDeEntradasEN 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 = @"DELETE FROM tiposdeentradas where idTipoDeEntrada = @idTipoDeEntrada;"; Comando.CommandText = Consultas; Comando.Parameters.Add(new MySqlParameter("@idTipoDeEntrada", MySqlDbType.Int32)).Value = oRegistroEN.idTipoDeEntrada; Comando.ExecuteNonQuery(); DescripcionDeOperacion = string.Format("El registro fue Eliminado Correctamente. {0} {1}", Environment.NewLine, InformacionDelRegistro(oRegistroEN)); //Agregamos la Transacción.... TransaccionesEN oTran = InformacionDelaTransaccion(oRegistroEN, "Eliminar", "Elminar 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 eliminar el registro. {0} {1} ", Environment.NewLine, InformacionDelRegistro(oRegistroEN), ex.Message); //Agregamos la Transacción.... TransaccionesEN oTran = InformacionDelaTransaccion(oRegistroEN, "Eliminar", "Eliminar 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; } }
private void tsbGuardar_Click(object sender, EventArgs e) { try { this.Cursor = Cursors.WaitCursor; if (LosDatosIngresadosSonCorrectos()) { TiposDeEntradasEN oRegistroEN = InformacionDelRegistro(); TiposDeEntradasLN oRegistroLN = new TiposDeEntradasLN(); if (oRegistroLN.ValidarRegistroDuplicado(oRegistroEN, Program.oDatosDeConexion, "AGREGAR")) { MessageBox.Show(oRegistroLN.Error, "Guardar información", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (oRegistroLN.Agregar(oRegistroEN, Program.oDatosDeConexion)) { txtIdentificador.Text = oRegistroEN.idTipoDeEntrada.ToString(); ValorLlavePrimariaEntidad = oRegistroEN.idTipoDeEntrada; EvaluarErrorParaMensajeAPantalla(oRegistroLN.Error, "Guardar"); oRegistroEN = null; oRegistroLN = null; this.Cursor = Cursors.Default; if (CerrarVentana == true) { this.Close(); } else { OperacionARealizar = "Modificar"; ObtenerValoresDeConfiguracion(); LlamarMetodoSegunOperacion(); EstablecerTituloDeVentana(); DeshabilitarControlesSegunOperacionesARealizar(); } } else { throw new ArgumentException(oRegistroLN.Error); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Guardar la información del registro", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { this.Cursor = Cursors.Default; } }
public bool ListadoPorIdentificador(TiposDeEntradasEN oREgistroEN, DatosDeConexionEN oDatos) { if (oTiposDeEntradasAD.ListadoPorIdentificador(oREgistroEN, oDatos)) { Error = string.Empty; return(true); } else { Error = oTiposDeEntradasAD.Error; return(false); } }
public bool Agregar(TiposDeEntradasEN oREgistroEN, DatosDeConexionEN oDatos) { if (oTiposDeEntradasAD.Agregar(oREgistroEN, oDatos)) { Error = string.Empty; return(true); } else { Error = oTiposDeEntradasAD.Error; return(false); } }
public bool ValidarSiElRegistroEstaVinculado(TiposDeEntradasEN oREgistroEN, DatosDeConexionEN oDatos, string TipoDeOperacion) { if (oTiposDeEntradasAD.ValidarSiElRegistroEstaVinculado(oREgistroEN, oDatos, TipoDeOperacion)) { Error = oTiposDeEntradasAD.Error; return(true); } else { Error = string.Empty; return(false); } }
public bool ListadoParaReportes(TiposDeEntradasEN oRegistroEN, DatosDeConexionEN oDatos) { try { Cnn = new MySqlConnection(TraerCadenaDeConexion(oDatos)); Cnn.Open(); Comando = new MySqlCommand(); Comando.Connection = Cnn; Comando.CommandType = CommandType.Text; Consultas = string.Format(@"Select te.idTipoDeEntrada, te.Nombre, te.Descripcion, te.idUsuarioDeCreacion, te.FechaDeCreacion, u.Nombre as 'UsuarioDeCreacion', te.idUsuarioModificacion, te.FechaDeModificacion, u1.Nombre as 'UsuarioDeModificacion' from tiposdeentradas as te inner join usuario as u on u.idUsuario = te.idUsuarioDeCreacion left join usuario as u1 on u1.idUsuario = te.idUsuarioModificacion Where te.idTipoDeEntrada > 0 {0} {1} ", oRegistroEN.Where, oRegistroEN.OrderBy); Comando.CommandText = Consultas; Adaptador = new MySqlDataAdapter(); DT = new DataTable(); Adaptador.SelectCommand = Comando; Adaptador.Fill(DT); return(true); } catch (Exception ex) { this.Error = ex.Message; return(false); } finally { if (Cnn != null) { if (Cnn.State == ConnectionState.Open) { Cnn.Close(); } } Cnn = null; Comando = null; Adaptador = null; } }
private TiposDeEntradasEN InformacionDelRegistro() { TiposDeEntradasEN oRegistroEN = new TiposDeEntradasEN(); oRegistroEN.idTipoDeEntrada = Convert.ToInt32((txtIdentificador.Text.Length > 0 ? txtIdentificador.Text : "0")); oRegistroEN.Nombre = txtNombre.Text.Trim(); oRegistroEN.Descripcion = txtDescripcion.Text.Trim(); //partes generales. oRegistroEN.oLoginEN = Program.oLoginEN; oRegistroEN.idUsuarioDeCreacion = Program.oLoginEN.idUsuario; oRegistroEN.idUsuarioModificacion = Program.oLoginEN.idUsuario; oRegistroEN.FechaDeCreacion = System.DateTime.Now; oRegistroEN.FechaDeCreacion = System.DateTime.Now; return(oRegistroEN); }
public bool ListadoParaCombos(TiposDeEntradasEN oRegistroEN, DatosDeConexionEN oDatos) { try { Cnn = new MySqlConnection(TraerCadenaDeConexion(oDatos)); Cnn.Open(); Comando = new MySqlCommand(); Comando.Connection = Cnn; Comando.CommandType = CommandType.Text; Consultas = string.Format(@"Select te.idTipoDeEntrada, te.Nombre from tiposdeentradas as te Where te.idTipoDeEntrada > 0 {0} {1} ; ", oRegistroEN.Where, oRegistroEN.OrderBy); Comando.CommandText = Consultas; System.Diagnostics.Debug.Print("Consultas de Tipo de transaccion: " + Consultas); Adaptador = new MySqlDataAdapter(); DT = new DataTable(); Adaptador.SelectCommand = Comando; Adaptador.Fill(DT); return(true); } catch (Exception ex) { this.Error = ex.Message; return(false); } finally { if (Cnn != null) { if (Cnn.State == ConnectionState.Open) { Cnn.Close(); } } Cnn = null; Comando = null; Adaptador = null; } }
private void LlenarCamposDesdeBaseDatosSegunID() { this.Cursor = Cursors.WaitCursor; TiposDeEntradasEN oRegistrosEN = new TiposDeEntradasEN(); TiposDeEntradasLN oRegistrosLN = new TiposDeEntradasLN(); oRegistrosEN.idTipoDeEntrada = ValorLlavePrimariaEntidad; if (oRegistrosLN.ListadoPorIdentificador(oRegistrosEN, Program.oDatosDeConexion)) { if (oRegistrosLN.TraerDatos().Rows.Count > 0) { DataRow Fila = oRegistrosLN.TraerDatos().Rows[0]; txtDescripcion.Text = Fila["Descripcion"].ToString(); txtNombre.Text = Fila["Nombre"].ToString(); oRegistrosEN = null; oRegistrosLN = null; } else { string Mensaje; Mensaje = string.Format("El registro solicitado de {0} no ha sido encontrado." + "\n\r-----Causas---- " + "\n\r1. Este registro pudo haber sido eliminado por otro usuario." + "\n\r2. El listado no está actualizado.", NombreEntidad); MessageBox.Show(Mensaje, "Listado", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); oRegistrosEN = null; oRegistrosLN = null; this.Close(); } } else { this.Cursor = Cursors.Default; MessageBox.Show(oRegistrosLN.Error, "Listado", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); oRegistrosEN = null; oRegistrosLN = null; } this.Cursor = Cursors.Default; }
private void tsbSeleccionarTodos_Click(object sender, EventArgs e) { try { this.Cursor = Cursors.WaitCursor; tsbSeleccionarTodos.Checked = !tsbMarcarTodos.Checked; if (tsbSeleccionarTodos.Checked == true) { tsbSeleccionarTodos.Image = Properties.Resources.unchecked16x16; } else { tsbSeleccionarTodos.Image = Properties.Resources.checked16x16; } int a = 0; this.Cursor = Cursors.WaitCursor; if (dgvLista.Rows.Count > 0) { foreach (DataGridViewRow Fila in dgvLista.Rows) { if (Convert.ToBoolean(Fila.Cells["Seleccionar"].Value) == true) { a++; Array.Resize(ref oTiposDeEntradas, a); oTiposDeEntradas[a - 1] = new TiposDeEntradasEN(); oTiposDeEntradas[a - 1].idTipoDeEntrada = Convert.ToInt32(Fila.Cells["idTipoDeEntrada"].Value); oTiposDeEntradas[a - 1].Nombre = Fila.Cells["Nombre"].Value.ToString(); oTiposDeEntradas[a - 1].Descripcion = Fila.Cells["Descripcion"].Value.ToString(); } } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Seleccionar registros", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { AgregarRegistrosAlDTUsuario(); this.Cursor = Cursors.Default; this.Close(); } }
public bool Eliminar(TiposDeEntradasEN oREgistroEN, DatosDeConexionEN oDatos) { if (string.IsNullOrEmpty(oREgistroEN.idTipoDeEntrada.ToString()) || oREgistroEN.idTipoDeEntrada == 0) { this.Error = @"Se debe de seleccionar un elemento de la lista"; return(false); } if (oTiposDeEntradasAD.Eliminar(oREgistroEN, oDatos)) { Error = string.Empty; return(true); } else { Error = oTiposDeEntradasAD.Error; return(false); } }
private TransaccionesEN InformacionDelaTransaccion(TiposDeEntradasEN oTiposDeEntradas, String TipoDeOperacion, String Descripcion, String Estado) { TransaccionesEN oRegistroEN = new TransaccionesEN(); oRegistroEN.idregistro = oTiposDeEntradas.idTipoDeEntrada; oRegistroEN.Modelo = "TransaccionAD"; oRegistroEN.Modulo = "Transacciones"; oRegistroEN.Tabla = "TiposDeEntradas"; oRegistroEN.tipodeoperacion = TipoDeOperacion; oRegistroEN.Estado = Estado; oRegistroEN.ip = oTiposDeEntradas.oLoginEN.NumeroIP; oRegistroEN.idusuario = oTiposDeEntradas.oLoginEN.idUsuario; oRegistroEN.idusuarioaprueba = oTiposDeEntradas.oLoginEN.idUsuario; oRegistroEN.descripciondelusuario = DescripcionDeOperacion; oRegistroEN.descripcioninterna = Descripcion; oRegistroEN.NombreDelEquipo = oTiposDeEntradas.oLoginEN.NombreDelComputador; return(oRegistroEN); }
private void LLenarListado() { try { this.Cursor = Cursors.WaitCursor; TiposDeEntradasEN oRegistrosEN = new TiposDeEntradasEN(); TiposDeEntradasLN oRegistrosLN = new TiposDeEntradasLN(); oRegistrosEN.Where = WhereDinamico(); if (oRegistrosLN.Listado(oRegistrosEN, Program.oDatosDeConexion)) { dgvLista.Columns.Clear(); System.Diagnostics.Debug.Print(oRegistrosLN.TraerDatos().Rows.Count.ToString()); if (ActivarFiltros == true) { dgvLista.DataSource = AgregarColumnaSeleccionar(oRegistrosLN.TraerDatos()); } else { dgvLista.DataSource = oRegistrosLN.TraerDatos(); } FormatearDGV(); this.dgvLista.ClearSelection(); tsbNoRegistros.Text = "No. Registros: " + oRegistrosLN.TotalRegistros().ToString(); } else { throw new ArgumentException(oRegistrosLN.Error); } }catch (Exception ex) { MessageBox.Show(ex.Message, "Llenar listado de registro en la lista", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { this.Cursor = Cursors.Default; } }
private void tsbEliminar_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 eliminar el registro?", "Eliminar la Confirmación", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button3) == System.Windows.Forms.DialogResult.No) { return; } TiposDeEntradasEN oRegistroEN = InformacionDelRegistro(); TiposDeEntradasLN oRegistroLN = new TiposDeEntradasLN(); if (oRegistroLN.ValidarSiElRegistroEstaVinculado(oRegistroEN, Program.oDatosDeConexion, "ELIMINAR")) { this.Cursor = Cursors.Default; MessageBox.Show(oRegistroLN.Error, this.OperacionARealizar, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } if (oRegistroLN.Eliminar(oRegistroEN, Program.oDatosDeConexion)) { txtIdentificador.Text = oRegistroEN.idTipoDeEntrada.ToString(); ValorLlavePrimariaEntidad = oRegistroEN.idTipoDeEntrada; EvaluarErrorParaMensajeAPantalla(oRegistroLN.Error, "Eliminar"); 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, "Eliminar la información del registro", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { this.Cursor = Cursors.Default; } }
public bool Actualizar(TiposDeEntradasEN 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 tiposdeentradas SET Nombre = @Nombre, Descripcion = @Descripcion, idUsuarioModificacion = @idUsuarioModificacion, FechaDeModificacion = current_timestamp() WHERE idTipoDeEntrada = @idTipoDeEntrada"; Comando.CommandText = Consultas; Comando.Parameters.Add(new MySqlParameter("@idTipoDeEntrada", MySqlDbType.Int32)).Value = oRegistroEN.idTipoDeEntrada; Comando.Parameters.Add(new MySqlParameter("@Nombre", MySqlDbType.VarChar, oRegistroEN.Nombre.Trim().Length)).Value = oRegistroEN.Nombre.Trim(); Comando.Parameters.Add(new MySqlParameter("@Descripcion", MySqlDbType.VarChar, oRegistroEN.Descripcion.Trim().Length)).Value = oRegistroEN.Descripcion.Trim(); Comando.Parameters.Add(new MySqlParameter("@idUsuarioModificacion", MySqlDbType.Int32)).Value = oRegistroEN.idUsuarioModificacion; 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; } }
public bool ValidarSiElRegistroEstaVinculado(TiposDeEntradasEN 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 = "idTipoDeEntrada"; Comando.Parameters.Add(new MySqlParameter("@ValorCampoABuscar", MySqlDbType.Int32)).Value = oRegistroEN.idTipoDeEntrada; 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(TiposDeEntradasEN 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 tiposdeentradas (Nombre, Descripcion, idUsuarioDeCreacion, FechaDeCreacion, idUsuarioModificacion, FechaDeModificacion) VALUES (@Nombre, @Descripcion, @idUsuarioDeCreacion, current_timestamp(), @idUsuarioModificacion, current_timestamp()); Select last_insert_id() as 'ID';"; Comando.CommandText = Consultas; Comando.Parameters.Add(new MySqlParameter("@Nombre", MySqlDbType.VarChar, oRegistroEN.Nombre.Trim().Length)).Value = oRegistroEN.Nombre.Trim(); Comando.Parameters.Add(new MySqlParameter("@Descripcion", MySqlDbType.VarChar, oRegistroEN.Descripcion.Trim().Length)).Value = oRegistroEN.Descripcion.Trim(); Comando.Parameters.Add(new MySqlParameter("@idUsuarioDeCreacion", MySqlDbType.Int32)).Value = oRegistroEN.idUsuarioDeCreacion; Comando.Parameters.Add(new MySqlParameter("@idUsuarioModificacion", MySqlDbType.Int32)).Value = oRegistroEN.idUsuarioModificacion; Adaptador = new MySqlDataAdapter(); DT = new DataTable(); Adaptador.SelectCommand = Comando; Adaptador.Fill(DT); oRegistroEN.idTipoDeEntrada = 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 ValidarRegistroDuplicado(TiposDeEntradasEN 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.Text; switch (TipoDeOperacion.Trim().ToUpper()) { case "AGREGAR": Consultas = @"SELECT CASE WHEN EXISTS(Select idTipoDeEntrada from TiposDeEntradas where upper( trim(Nombre) ) = upper(trim(@Nombre))) THEN 1 ELSE 0 END AS 'RES'"; Comando.Parameters.Add(new MySqlParameter("@Nombre", MySqlDbType.VarChar, oRegistroEN.Nombre.Trim().Length)).Value = oRegistroEN.Nombre; break; case "ACTUALIZAR": Consultas = @"SELECT CASE WHEN EXISTS(Select idTipoDeEntrada from TiposDeEntradas where upper( trim(Nombre) ) = upper(trim(@Nombre)) and idTipoDeEntrada <> @idTipoDeEntrada) THEN 1 ELSE 0 END AS 'RES'"; Comando.Parameters.Add(new MySqlParameter("@Nombre", MySqlDbType.VarChar, oRegistroEN.Nombre.Trim().Length)).Value = oRegistroEN.Nombre; Comando.Parameters.Add(new MySqlParameter("@idTipoDeEntrada", MySqlDbType.Int32)).Value = oRegistroEN.idTipoDeEntrada; break; default: throw new ArgumentException("La aperación solicitada no esta disponible"); } Comando.CommandText = Consultas; Adaptador = new MySqlDataAdapter(); DT = new DataTable(); Adaptador.SelectCommand = Comando; Adaptador.Fill(DT); if (Convert.ToInt32(DT.Rows[0]["RES"].ToString()) > 0) { DescripcionDeOperacion = string.Format("Ya existe información del Registro dentro de nuestro sistema: {0} {1}", Environment.NewLine, InformacionDelRegistro(oRegistroEN)); this.Error = DescripcionDeOperacion; return(true); } return(false); } 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", "REGISTRO DUPLICADO DENTRO DE LA BASE DE DATOS", "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; } }