public static DataConsentTDS GetConsentChannelAndPurpose()
        {
            TDBTransaction T   = new TDBTransaction();
            TDataBase      DB  = DBAccess.Connect("Get Consent Channel + Purpose");
            DataConsentTDS Set = new DataConsentTDS();

            DB.ReadTransaction(ref T, delegate {
                PConsentChannelAccess.LoadAll(Set, T);
                PPurposeAccess.LoadAll(Set, T);
            });

            return(Set);
        }
        public static DataConsentTDS LastKnownEntry(
            Int64 APartnerKey,
            string ADataType
            )
        {
            TDBTransaction       T            = new TDBTransaction();
            TDataBase            DB           = DBAccess.Connect("Get Last known entry");
            DataConsentTDS       Set          = new DataConsentTDS();
            List <OdbcParameter> SQLParameter = new List <OdbcParameter>();

            DB.ReadTransaction(ref T, delegate {
                string sql = "SELECT " +
                             "`p_data_history`.*, " +
                             "GROUP_CONCAT(`p_data_history_permission`.`p_purpose_code_c` SEPARATOR ',') AS `AllowedPurposes` " +
                             "FROM `p_data_history` " +
                             "LEFT JOIN `p_data_history_permission` " +
                             "ON `p_data_history`.`p_entry_id_i` = `p_data_history_permission`.`p_data_history_entry_i` " +
                             "WHERE `p_data_history`.`p_partner_key_n` = ? " +
                             "AND `p_data_history`.`p_type_c` = ? " +
                             "GROUP BY `p_data_history`.`p_entry_id_i` " +
                             "ORDER BY `p_data_history`.`p_entry_id_i` DESC " +
                             "LIMIT 1";

                SQLParameter.Add(new OdbcParameter("PartnerKey", OdbcType.VarChar)
                {
                    Value = APartnerKey.ToString()
                });
                SQLParameter.Add(new OdbcParameter("DataType", OdbcType.VarChar)
                {
                    Value = ADataType
                });

                // DB.SelectDT(Set, sql, T, SQLParameter.ToArray(), 0,0);
                DB.SelectDT(Set.PDataHistory, sql, T, SQLParameter.ToArray());

                PConsentChannelAccess.LoadAll(Set, T);
                PPurposeAccess.LoadAll(Set, T);
            });

            return(Set);
        }
        public static DataConsentTDS GetHistory(
            Int64 APartnerKey,
            string ADataType
            )
        {
            TDBTransaction       T            = new TDBTransaction();
            TDataBase            DB           = DBAccess.Connect("Get data history for partner");
            DataConsentTDS       Set          = new DataConsentTDS();
            List <OdbcParameter> SQLParameter = new List <OdbcParameter>();

            DB.ReadTransaction(ref T, delegate {
                // prepare for one huge cunk sql
                string sql = "" +
                             "SELECT " +
                             "  `pdh`.*, " +
                             "  GROUP_CONCAT(`pdhp`.`p_purpose_code_c` SEPARATOR ',') AS `AllowedPurposes` " +
                             "FROM `p_data_history` AS `pdh` " +
                             "LEFT JOIN `p_data_history_permission` AS `pdhp` " +
                             "  ON `pdh`.`p_entry_id_i` = `pdhp`.`p_data_history_entry_i` " +
                             "WHERE `pdh`.`p_partner_key_n` = ? " +
                             "  AND `pdh`.`p_type_c` = ? " +
                             "GROUP BY `pdh`.`p_entry_id_i` " +
                             "ORDER BY `pdh`.`p_entry_id_i` DESC";

                SQLParameter.Add(new OdbcParameter("PartnerKey", OdbcType.BigInt)
                {
                    Value = APartnerKey.ToString()
                });
                SQLParameter.Add(new OdbcParameter("DataType", OdbcType.VarChar)
                {
                    Value = ADataType
                });

                Set.PDataHistory.Constraints.Clear(); //mmmm...
                DB.SelectDT(Set.PDataHistory, sql, T, SQLParameter.ToArray());
                PConsentChannelAccess.LoadAll(Set, T);
                PPurposeAccess.LoadAll(Set, T);
            });

            return(Set);
        }