private DataTable InformacionDeLoteProducto() { DataTable ODatos = null; try { ProductoLoteEN oRegistroEN = new ProductoLoteEN(); ProductoLoteLN oRegistroLN = new ProductoLoteLN(); oRegistroEN.oProductoEN.idProducto = ValorLlavePrimariaEntidad; if (oRegistroLN.ListadoDePruductosDelLotePorIdProducto(oRegistroEN, Program.oDatosDeConexion)) { ODatos = oRegistroLN.TraerDatos(); return(ODatos); } else { throw new ArgumentException(oRegistroLN.Error); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Información de los productos asociados", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(ODatos); } }
private ProductoLoteEN InformacionDeLaPromocionEnElDGV(DataGridViewRow Fila) { ProductoLoteEN oRegistroEN = new ProductoLoteEN(); int idLoteDelProducto; int.TryParse(Fila.Cells["idLoteDelProducto"].Value.ToString(), out idLoteDelProducto); oRegistroEN.idLoteDelProducto = idLoteDelProducto; oRegistroEN.oProductoEN.idProducto = ValorLlavePrimariaEntidad; oRegistroEN.oProductoEN.Codigo = CodigoProducto; oRegistroEN.oProductoEN.CodigoDeBarra = CodigoDeBarraDelProducto; oRegistroEN.oProductoEN.Nombre = NombreDelProducto; decimal Cantidad; decimal.TryParse(Fila.Cells["CantidadDelLote"].Value.ToString(), out Cantidad); oRegistroEN.NumeroDeLote = Fila.Cells["NumeroDeLote"].Value.ToString(); oRegistroEN.CantidadDelLote = Cantidad; oRegistroEN.FechaDeCreacion = Convert.ToDateTime(Fila.Cells["FechaDeVencimiento"].Value); oRegistroEN.Descripcion = txtDescripcion.Text.Trim(); 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); }
private ProductoLoteEN InformacionDelLoteDelProducto() { ProductoLoteEN oRegistroEN = new ProductoLoteEN(); int idLoteDelProducto; int.TryParse(txtidLoteDelProducto.Text, out idLoteDelProducto); oRegistroEN.idLoteDelProducto = idLoteDelProducto; oRegistroEN.oProductoEN.idProducto = ValorLlavePrimariaEntidad; oRegistroEN.oProductoEN.Codigo = CodigoProducto; oRegistroEN.oProductoEN.CodigoDeBarra = CodigoDeBarraDelProducto; oRegistroEN.oProductoEN.Nombre = NombreDelProducto; decimal Cantidad; decimal.TryParse(txtCantidad.Text, out Cantidad); oRegistroEN.NumeroDeLote = txtNumeroDeLote.Text.Trim(); oRegistroEN.CantidadDelLote = Cantidad; oRegistroEN.FechaDeVencimiento = dtpkFechaVencimiento.Value; oRegistroEN.Descripcion = txtDescripcion.Text.Trim(); 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); }
private string InformacionDelRegistro(ProductoLoteEN oRegistroEN) { string Cadena = @"idLoteDelProducto: {0}, idProducto: {1}, FechaDeVencimiento: {2}, NumeroDeLote: {3}, CantidadDelLote: {4}, Descripcion: {5}, idUsuarioDeCreacion: {6}, FechaDeCreacion: {7}, idUsuarioModificacion: {8}, FechaDeModificacion: {9}"; Cadena = string.Format(Cadena, oRegistroEN.idLoteDelProducto, oRegistroEN.oProductoEN.idProducto, oRegistroEN.FechaDeVencimiento, oRegistroEN.NumeroDeLote, oRegistroEN.CantidadDelLote, oRegistroEN.Descripcion, oRegistroEN.IdUsuarioDeCreacion, oRegistroEN.FechaDeCreacion, oRegistroEN.IdUsuarioDeModificacion, oRegistroEN.FechaDeModificacion); Cadena = Cadena.Replace(",", Environment.NewLine); return(Cadena); }
public bool Eliminar(ProductoLoteEN 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 ProductoLote Where idLoteDelProducto = @idLoteDelProducto;"; Comando.CommandText = Consultas; Comando.Parameters.Add(new MySqlParameter("@idLoteDelProducto", MySqlDbType.Int32)).Value = oRegistroEN.idLoteDelProducto; 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; } }
public bool ListadoParaReportes(ProductoLoteEN oREgistroEN, DatosDeConexionEN oDatos) { if (oProductoLoteAD.ListadoParaReportes(oREgistroEN, oDatos)) { Error = string.Empty; return(true); } else { Error = oProductoLoteAD.Error; return(false); } }
public bool ValidarSiElRegistroEstaVinculado(ProductoLoteEN oREgistroEN, DatosDeConexionEN oDatos, string TipoDeOperacion) { if (oProductoLoteAD.ValidarSiElRegistroEstaVinculado(oREgistroEN, oDatos, TipoDeOperacion)) { Error = oProductoLoteAD.Error; return(true); } else { Error = string.Empty; return(false); } }
public bool ListadoDePruductosDelLotePorIdProducto(ProductoLoteEN oREgistroEN, DatosDeConexionEN oDatos) { if (oProductoLoteAD.ListadoDePruductosDelLotePorIdProducto(oREgistroEN, oDatos)) { Error = string.Empty; return(true); } else { Error = oProductoLoteAD.Error; return(false); } }
public bool Agregar(ProductoLoteEN oREgistroEN, DatosDeConexionEN oDatos) { if (oProductoLoteAD.Agregar(oREgistroEN, oDatos)) { Error = string.Empty; return(true); } else { Error = oProductoLoteAD.Error; return(false); } }
public bool ListadoParaCombos(ProductoLoteEN 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 idLoteDelProducto, idProducto, FechaDeVencimiento, CantidadDelLote from productolote as pl where idLoteDelProducto > 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; } }
public bool ListadoParaReportes(ProductoLoteEN 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 idLoteDelProducto, idProducto, FechaDeVencimiento, NumeroDeLote, CantidadDelLote, Descripcion, idUsuarioDeCreacion, FechaDeCreacion, idUsuarioModificacion, FechaDeModificacion From productolote Where idLoteDelProducto > 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; } }
public bool ListadoDePruductosDelLotePorIdProducto(ProductoLoteEN 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 idLoteDelProducto, idProducto, SoloFecha(FechaDeVencimiento) as 'FechaDeVencimiento', NumeroDeLote, CantidadDelLote, Descripcion from productolote as pl where idProducto = {0} Order by FechaDeVencimiento asc ; ", oRegistroEN.oProductoEN.idProducto); 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; } }
public bool Eliminar(ProductoLoteEN oREgistroEN, DatosDeConexionEN oDatos) { if (string.IsNullOrEmpty(oREgistroEN.idLoteDelProducto.ToString()) || oREgistroEN.idLoteDelProducto == 0) { this.Error = @"Se debe de seleccionar un elemento de la lista"; return(false); } if (oProductoLoteAD.Eliminar(oREgistroEN, oDatos)) { Error = string.Empty; return(true); } else { Error = oProductoLoteAD.Error; return(false); } }
private TransaccionesEN InformacionDelaTransaccion(ProductoLoteEN oProductoLote, String TipoDeOperacion, String Descripcion, String Estado) { TransaccionesEN oRegistroEN = new TransaccionesEN(); oRegistroEN.idregistro = oProductoLote.idLoteDelProducto; oRegistroEN.Modelo = "ProductoLoteAD"; oRegistroEN.Modulo = "Ubicacion"; oRegistroEN.Tabla = "ProductoLote"; oRegistroEN.tipodeoperacion = TipoDeOperacion; oRegistroEN.Estado = Estado; oRegistroEN.ip = oProductoLote.oLoginEN.NumeroIP; oRegistroEN.idusuario = oProductoLote.oLoginEN.idUsuario; oRegistroEN.idusuarioaprueba = oProductoLote.oLoginEN.idUsuario; oRegistroEN.descripciondelusuario = DescripcionDeOperacion; oRegistroEN.descripcioninterna = Descripcion; oRegistroEN.NombreDelEquipo = oProductoLote.oLoginEN.NombreDelComputador; return(oRegistroEN); }
private void Guardar() { try { if (LosDatosIngresadosSonCorrectos()) { ProductoLoteEN oRegistroEN = InformacionDelLoteDelProducto(); ProductoLoteLN oRegistroLN = new ProductoLoteLN(); MessageBox.Show(oRegistroEN.FechaDeVencimiento.ToString()); 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)) { if (chkCerrarVentana.Checked == true) { this.Close(); } else { CrearyYPoblarColumnasDGVlotes(); LimpiarControles(); } } else { throw new ArgumentException(oRegistroLN.Error); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Guardar el registro", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
public bool Actualizar(ProductoLoteEN 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 productolote SET FechaDeVencimiento = @FechaDeVencimiento, NumeroDeLote = @NumeroDeLote, CantidadDelLote = @CantidadDelLote, Descripcion = @Descripcion, idUsuarioModificacion = @idUsuarioModificacion, FechaDeModificacion = current_timestamp() WHERE idLoteDelProducto = @idLoteDelProducto;"; Comando.CommandText = Consultas; Comando.Parameters.Add(new MySqlParameter("@idLoteDelProducto", MySqlDbType.Int32)).Value = oRegistroEN.idLoteDelProducto; Comando.Parameters.Add(new MySqlParameter("@FechaDeVencimiento", MySqlDbType.DateTime)).Value = oRegistroEN.FechaDeVencimiento; Comando.Parameters.Add(new MySqlParameter("@CantidadDelLote", MySqlDbType.Decimal)).Value = oRegistroEN.CantidadDelLote; Comando.Parameters.Add(new MySqlParameter("@NumeroDeLote", MySqlDbType.VarChar, oRegistroEN.NumeroDeLote.Length)).Value = oRegistroEN.NumeroDeLote; Comando.Parameters.Add(new MySqlParameter("@Descripcion", MySqlDbType.VarChar, oRegistroEN.Descripcion.Length)).Value = oRegistroEN.Descripcion; 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; } }
public bool Agregar(ProductoLoteEN 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 productolote (idProducto, FechaDeVencimiento, NumeroDeLote, CantidadDelLote, Descripcion, idUsuarioDeCreacion, FechaDeCreacion, idUsuarioModificacion, FechaDeModificacion) VALUES (@idProducto, @FechaDeVencimiento, @NumeroDeLote, @CantidadDelLote, @Descripcion, @idUsuarioDeCreacion, current_timestamp(), @idUsuarioModificacion, current_timestamp()); Select last_insert_id() as 'ID'; "; Comando.CommandText = Consultas; Comando.Parameters.Add(new MySqlParameter("@idProducto", MySqlDbType.Int32)).Value = oRegistroEN.oProductoEN.idProducto; Comando.Parameters.Add(new MySqlParameter("@FechaDeVencimiento", MySqlDbType.DateTime)).Value = oRegistroEN.FechaDeVencimiento; Comando.Parameters.Add(new MySqlParameter("@CantidadDelLote", MySqlDbType.Decimal)).Value = oRegistroEN.CantidadDelLote; Comando.Parameters.Add(new MySqlParameter("@NumeroDeLote", MySqlDbType.VarChar, oRegistroEN.NumeroDeLote.Length)).Value = oRegistroEN.NumeroDeLote; Comando.Parameters.Add(new MySqlParameter("@Descripcion", MySqlDbType.VarChar, oRegistroEN.Descripcion.Length)).Value = oRegistroEN.Descripcion; Comando.Parameters.Add(new MySqlParameter("@idUsuarioDeCreacion", MySqlDbType.Int32)).Value = oRegistroEN.oLoginEN.idUsuario; Comando.Parameters.Add(new MySqlParameter("@idUsuarioModificacion", MySqlDbType.Int32)).Value = oRegistroEN.oLoginEN.idUsuario; Adaptador = new MySqlDataAdapter(); Adaptador.SelectCommand = Comando; DT = new DataTable(); Adaptador.Fill(DT); oRegistroEN.idLoteDelProducto = 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; } }
private void Eliminar() { try { if (dgvListar.Rows.Count > 0) { if (EvaluarDataGridView(dgvListar)) { string Mensaje = DescripcionDetallaDGV(dgvListar); MessageBox.Show(Mensaje, "Registros a procesar", MessageBoxButtons.OK, MessageBoxIcon.Information); int RowsProcesar = dgvListar.Rows.Count; if (RowsProcesar > 0) { int indice = 0; int TotalDeFilasMarcadasParaEliminar = TotalDeFilasMarcadas(dgvListar, "Eliminar"); //Aqui Volvemos dinamica El codigo poniendo el valor de la llave primaria string NombreLavePrimariaDetalle = "idLoteDelProducto"; while (indice <= dgvListar.Rows.Count - 1) { DataGridViewRow Fila = dgvListar.Rows[indice]; int ValorDelaLLavePrimaria; int.TryParse(Fila.Cells[NombreLavePrimariaDetalle].Value.ToString(), out ValorDelaLLavePrimaria); Boolean Eliminar = Convert.ToBoolean(Fila.Cells["Eliminar"].Value); if (ValorDelaLLavePrimaria == 0 && Eliminar == false) { indice++; continue; } ProductoLoteEN oRegistroEN = InformacionDeLaPromocionEnElDGV(Fila); ProductoLoteLN oRegistroLN = new ProductoLoteLN(); string Operacion = ""; //El orden es importante porque si un usuario agrego una nueva persona pero lo marco para eliminar, no hacemos nada, solo lo quitamos de la lista. if (ValorDelaLLavePrimaria == 0 && Eliminar == true) { Operacion = "ELIMINAR FILA EN GRILLA"; } //VALIDAREMOS PARA PODER ELIMINAR EL REGISTRO.... else if (ValorDelaLLavePrimaria > 0 && Eliminar == true) { Operacion = "ELIMINAR"; } else if (ValorDelaLLavePrimaria >= 0 && Eliminar == false) { Operacion = "NINGUNA"; } //Validaciones if (Operacion == "ELIMINAR FILA EN GRILLA") { dgvListar.Rows.Remove(Fila); if (dgvListar.RowCount <= 0) { indice++; } continue; } if (Operacion == "NINGUNA") { indice++; continue; } if (Operacion == "ELIMINAR") { if (oRegistroLN.Eliminar(oRegistroEN, Program.oDatosDeConexion)) { dgvListar.Rows.Remove(Fila); oRegistroEN = null; oRegistroLN = null; if (dgvListar.RowCount <= 0) { indice++; } continue; } else { this.Cursor = Cursors.Default; throw new ArgumentException(oRegistroLN.Error); } } } } } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Eliminar", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public bool ValidarRegistroDuplicado(ProductoLoteEN 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 idLoteDelProducto from productolote Where idProducto = @idProducto and SoloFecha(FechaDeVencimiento) = SoloFecha(@FechaDeVencimiento) and CantidadDelLote = @CantidadDelLote) THEN 1 ELSE 0 END AS 'RES'"; Comando.Parameters.Add(new MySqlParameter("@FechaDeVencimiento", MySqlDbType.DateTime)).Value = oRegistroEN.FechaDeVencimiento; Comando.Parameters.Add(new MySqlParameter("@idProducto", MySqlDbType.Int32)).Value = oRegistroEN.oProductoEN.idProducto; Comando.Parameters.Add(new MySqlParameter("@CantidadDelLote", MySqlDbType.Decimal)).Value = oRegistroEN.CantidadDelLote; break; case "ACTUALIZAR": Consultas = @"SELECT CASE WHEN EXISTS(Select idLoteDelProducto from productolote Where idProducto = @idProducto and SoloFecha(FechaDeVencimiento) = SoloFecha(@FechaDeVencimiento) and CantidadDelLote = @CantidadDelLote and idLoteDelProducto <> @idLoteDelProducto) THEN 1 ELSE 0 END AS 'RES'"; Comando.Parameters.Add(new MySqlParameter("@FechaDeVencimiento", MySqlDbType.DateTime)).Value = oRegistroEN.FechaDeVencimiento; Comando.Parameters.Add(new MySqlParameter("@idProducto", MySqlDbType.Int32)).Value = oRegistroEN.oProductoEN.idProducto; Comando.Parameters.Add(new MySqlParameter("@CantidadDelLote", MySqlDbType.Decimal)).Value = oRegistroEN.CantidadDelLote; Comando.Parameters.Add(new MySqlParameter("@idLoteDelProducto", MySqlDbType.Int32)).Value = oRegistroEN.idLoteDelProducto; 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; } }
public bool ValidarSiElRegistroEstaVinculado(ProductoLoteEN 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 = "ValidarSiElRegistroEstaVinculadoUnaTabla"; Comando.Parameters.Add(new MySqlParameter("@CampoABuscar_", MySqlDbType.VarChar, 200)).Value = "idLoteDelProducto"; Comando.Parameters.Add(new MySqlParameter("@ValorCampoABuscar", MySqlDbType.Int32)).Value = oRegistroEN.idLoteDelProducto; Comando.Parameters.Add(new MySqlParameter("@ExcluirTabla_", MySqlDbType.VarChar, 200)).Value = "ProductoLote"; 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; } }