public List<DetalleMateriaPrima> ObtenerDetalleMateriaPrimaTipo(int AIdMaestro, string ATipo)
        {
            List<DetalleMateriaPrima> pResult = new List<DetalleMateriaPrima>();
            DetalleMateriaPrima pDetalleMateriaPrima = null;
            string pSentencia = "SELECT T0.PRODUCTO, T1.DESCRIPCION, COUNT(*) AS CAJAS, SUM(T0.PESO) AS KILOS, MAX(T0.ID_SALIDA) AS ID_SALIDA FROM DRASMATPRIMAD_DETALLE T0 " +
                                "JOIN DRASPROD T1 ON T1.CLAVE = T0.PRODUCTO " +
                                "WHERE T0.ID_MAESTRO = @IDMAESTRO AND T0.TIPO = @TIPO " +
                                "GROUP BY PRODUCTO, T1.DESCRIPCION ORDER BY T0.PRODUCTO";
            FbConnection con = _Conexion.ObtenerConexion();

            FbCommand com = new FbCommand(pSentencia, con);
            com.Parameters.Add("@IDMAESTRO", FbDbType.Integer).Value = AIdMaestro;
            com.Parameters.Add("@TIPO", FbDbType.VarChar).Value = ATipo;

            try
            {

                con.Open();
                FbDataReader reader = com.ExecuteReader();

                while (reader.Read())
                {
                    pDetalleMateriaPrima              = new DetalleMateriaPrima();
                    pDetalleMateriaPrima.Producto     = reader["PRODUCTO"] != DBNull.Value ? (string)reader["PRODUCTO"] : "";
                    pDetalleMateriaPrima.Descripcion  = reader["DESCRIPCION"] != DBNull.Value ? (string)reader["DESCRIPCION"] : "";
                    pDetalleMateriaPrima.Cajas        = reader["CAJAS"] != DBNull.Value ? (int)reader["CAJAS"] : 0;
                    pDetalleMateriaPrima.Kilos        = reader["KILOS"] != DBNull.Value ? (decimal)reader["KILOS"] : 0;
                    pDetalleMateriaPrima.Id_Salida    = reader["ID_SALIDA"] != DBNull.Value ? (int)reader["ID_SALIDA"] : -1;

                    pResult.Add(pDetalleMateriaPrima);
                }
            }
            finally
            {
                if (con.State == System.Data.ConnectionState.Open)
                {
                    con.Close();
                }
            }
            return pResult;
        }
        public List<DetalleMateriaPrima> ObtenerDetalleMateriaPrima(int AIdMatPrima, int ADestino)
        {
            List<DetalleMateriaPrima> pResult = new List<DetalleMateriaPrima>();
            DetalleMateriaPrima pDetalleMateriaPrima = null;
            string pSentencia = "SELECT T0.*, T1.DESCRIPCION FROM DRASMATPRIMAD T0 JOIN DRASPROD T1 ON T1.CLAVE = T0.PRODUCTO WHERE ID_MATPRIMA = @IDMATPRIMA AND ID_DESTINO = @IDDESTINO";
            FbConnection con = _Conexion.ObtenerConexion();

            FbCommand com = new FbCommand(pSentencia, con);
            com.Parameters.Add("@IDMATPRIMA", FbDbType.Integer).Value = AIdMatPrima;
            com.Parameters.Add("@IDDESTINO", FbDbType.Integer).Value  = ADestino;
            try
            {

                con.Open();
                FbDataReader reader = com.ExecuteReader();

                while (reader.Read())
                {
                    pDetalleMateriaPrima              = new DetalleMateriaPrima();
                    pDetalleMateriaPrima.Id           = reader["ID"] != DBNull.Value ? (int)reader["ID"] : -1;
                    pDetalleMateriaPrima.Id_MatPrima  = reader["ID_MATPRIMA"] != DBNull.Value ? (int)reader["ID_MATPRIMA"] : -1;
                    pDetalleMateriaPrima.Producto     = reader["PRODUCTO"] != DBNull.Value ? (string)reader["PRODUCTO"] : "";
                    pDetalleMateriaPrima.Cajas        = reader["CAJAS"] != DBNull.Value ? (decimal)reader["CAJAS"] : 0;
                    pDetalleMateriaPrima.Kilos        = reader["KILOS"] != DBNull.Value ? (decimal)reader["KILOS"] : 0;
                    pDetalleMateriaPrima.Tipo         = reader["TIPO"] != DBNull.Value ? (string)reader["TIPO"] : "";
                    pDetalleMateriaPrima.Id_Salida    = reader["ID_SALIDA"] != DBNull.Value ? (int)reader["ID_SALIDA"] : -1;
                    pDetalleMateriaPrima.Id_Destino   = reader["ID_DESTINO"] != DBNull.Value ? (int)reader["ID_DESTINO"] : -1;
                    pDetalleMateriaPrima.Subtipo      = reader["SUBTIPO"] != DBNull.Value ? (string)reader["SUBTIPO"] : "";
                    pDetalleMateriaPrima.Descripcion  = reader["DESCRIPCION"] != DBNull.Value ? (string)reader["DESCRIPCION"] : "";
                    pResult.Add(pDetalleMateriaPrima);
                }
            }
            finally
            {
                if (con.State == System.Data.ConnectionState.Open)
                {
                    con.Close();
                }
            }
            return pResult;
        }