private string InformacionDelRegistro(ProductoLaboratoriosEN oRegistroEN)
        {
            string Cadena = @"idProductoLaboratorios: {0}, idProducto: {1}, idLaboratorio: {2}, idUsuarioDeCreacion: {3}, FechaDeCreacion: {4}, idUsuarioModificacion: {5}, FechaDeModificacion: {6}";

            Cadena = string.Format(Cadena, oRegistroEN.idProductoLaboratorios, oRegistroEN.oProductoEN.idProducto, oRegistroEN.oLaboratorioEN.idLaboratorio, oRegistroEN.idUsuarioDeCreacion, oRegistroEN.FechaDeCreacion, oRegistroEN.idUsuarioModificacion, oRegistroEN.FechaDeModificacion);
            Cadena = Cadena.Replace(",", Environment.NewLine);
            return(Cadena);
        }
        public bool Eliminar(ProductoLaboratoriosEN 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 ProductoLaboratorios Where idProductoLaboratorios = @idProductoLaboratorios;";
                Comando.CommandText = Consultas;

                Comando.Parameters.Add(new MySqlParameter("@idProductoLaboratorios", MySqlDbType.Int32)).Value = oRegistroEN.idProductoLaboratorios;

                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 ListadoPorIdentificador(ProductoLaboratoriosEN oREgistroEN, DatosDeConexionEN oDatos)
 {
     if (oProductoLaboratoriosAD.ListadoPorIdentificador(oREgistroEN, oDatos))
     {
         Error = string.Empty;
         return(true);
     }
     else
     {
         Error = oProductoLaboratoriosAD.Error;
         return(false);
     }
 }
 public bool Agregar(ProductoLaboratoriosEN oREgistroEN, DatosDeConexionEN oDatos)
 {
     if (oProductoLaboratoriosAD.Agregar(oREgistroEN, oDatos))
     {
         Error = string.Empty;
         return(true);
     }
     else
     {
         Error = oProductoLaboratoriosAD.Error;
         return(false);
     }
 }
 public bool ValidarSiElRegistroEstaVinculado(ProductoLaboratoriosEN oREgistroEN, DatosDeConexionEN oDatos, string TipoDeOperacion)
 {
     if (oProductoLaboratoriosAD.ValidarSiElRegistroEstaVinculado(oREgistroEN, oDatos, TipoDeOperacion))
     {
         Error = oProductoLaboratoriosAD.Error;
         return(true);
     }
     else
     {
         Error = string.Empty;
         return(false);
     }
 }
        public bool ListadoParaReportes(ProductoLaboratoriosEN 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 idProductoLaboratorios, pl.idProducto, pl.idLaboratorio, 
                l.Codigo, l.Nombre as 'Laboratorio',
                pl.idUsuarioDeCreacion, pl.FechaDeCreacion, u.Nombre as 'UsuarioDeCreacion' ,
                pl.idUsuarioModificacion, pl.FechaDeModificacion, u1.Nombre as 'UsuarioDeModificacion' 
                FROM productolaboratorios pl
                inner join laboratorio as l on l.idLaboratorio = pl.idLaboratorio
                inner join usuario as u on u.idUsuario = pl.idUsuarioDeCreacion
                left join usuario as u1 on u1.idUsuario = pl.idUsuarioModificacion
                where idProductoLaboratorios > 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 Eliminar(ProductoLaboratoriosEN oREgistroEN, DatosDeConexionEN oDatos)
        {
            if (string.IsNullOrEmpty(oREgistroEN.idProductoLaboratorios.ToString()) || oREgistroEN.idProductoLaboratorios == 0)
            {
                this.Error = @"Se debe de seleccionar un elemento de la lista";
                return(false);
            }

            if (oProductoLaboratoriosAD.Eliminar(oREgistroEN, oDatos))
            {
                Error = string.Empty;
                return(true);
            }
            else
            {
                Error = oProductoLaboratoriosAD.Error;
                return(false);
            }
        }
        private TransaccionesEN InformacionDelaTransaccion(ProductoLaboratoriosEN oProductoLaboratorios, String TipoDeOperacion, String Descripcion, String Estado)
        {
            TransaccionesEN oRegistroEN = new TransaccionesEN();

            oRegistroEN.idregistro      = oProductoLaboratorios.idProductoLaboratorios;
            oRegistroEN.Modelo          = "ProductoLaboratoriosAD";
            oRegistroEN.Modulo          = "Producto";
            oRegistroEN.Tabla           = "ProductoLaboratorios";
            oRegistroEN.tipodeoperacion = TipoDeOperacion;
            oRegistroEN.Estado          = Estado;
            oRegistroEN.ip                    = oProductoLaboratorios.oLoginEN.NumeroIP;
            oRegistroEN.idusuario             = oProductoLaboratorios.oLoginEN.idUsuario;
            oRegistroEN.idusuarioaprueba      = oProductoLaboratorios.oLoginEN.idUsuario;
            oRegistroEN.descripciondelusuario = DescripcionDeOperacion;
            oRegistroEN.descripcioninterna    = Descripcion;
            oRegistroEN.NombreDelEquipo       = oProductoLaboratorios.oLoginEN.NombreDelComputador;

            return(oRegistroEN);
        }
        public bool ValidarRegistroDuplicado(ProductoLaboratoriosEN 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 idProductoLaboratorios from ProductoLaboratorios where idLaboratorio = @idLaboratorio and idProducto = @idProducto) THEN 1 ELSE 0 END AS 'RES'";
                    Comando.Parameters.Add(new MySqlParameter("@idProducto", MySqlDbType.Int32)).Value    = oRegistroEN.oProductoEN.idProducto;
                    Comando.Parameters.Add(new MySqlParameter("@idLaboratorio", MySqlDbType.Int32)).Value = oRegistroEN.oLaboratorioEN.idLaboratorio;

                    break;

                case "ACTUALIZAR":

                    Consultas = @"SELECT CASE WHEN EXISTS(Select idProductoLaboratorios from ProductoLaboratorios where idLaboratorio = @idLaboratorio and idProducto = @idProducto and idProductoLaboratorios <> @idProductoLaboratorios) THEN 1 ELSE 0 END AS 'RES'";
                    Comando.Parameters.Add(new MySqlParameter("@idProducto", MySqlDbType.Int32)).Value             = oRegistroEN.oProductoEN.idProducto;
                    Comando.Parameters.Add(new MySqlParameter("@idLaboratorio", MySqlDbType.Int32)).Value          = oRegistroEN.oLaboratorioEN.idLaboratorio;
                    Comando.Parameters.Add(new MySqlParameter("@idProductoLaboratorios", MySqlDbType.Int32)).Value = oRegistroEN.idProductoLaboratorios;

                    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(ProductoLaboratoriosEN 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 = "idProductoLaboratorios";
                Comando.Parameters.Add(new MySqlParameter("@ValorCampoABuscar", MySqlDbType.Int32)).Value    = oRegistroEN.idProductoLaboratorios;
                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(ProductoLaboratoriosEN 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 productolaboratorios
                (idProducto, idLaboratorio, 
                idUsuarioDeCreacion, FechaDeCreacion, idUsuarioModificacion, FechaDeModificacion)
                values
                (@idProducto, @idLaboratorio, 
                @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("@idLaboratorio", MySqlDbType.Int32)).Value         = oRegistroEN.oLaboratorioEN.idLaboratorio;
                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.idProductoLaboratorios = 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;
            }
        }