/////////////////////////////////////////////////////////////////////////////////////	
 public DataSet GetAllEnterprises()
 {
     try
     {
         return db.GetFields(DBTables.ENTERPRISES);
     }
     catch (NullDataSetException nds)
     {
         NullDataSetException wrappedEx = new
             NullDataSetException(
                 ErrorManager.AddLayer(nds, RunningClass.GetName(this), RunningClass.GetMethod()));
         throw wrappedEx;
     }
     catch (Exception ex)
     {
         Exception wrappedEx = new Exception(
             ErrorManager.AddLayer(ex, RunningClass.GetName(this), RunningClass.GetMethod()));
         throw wrappedEx;
     }
 }
        ///////////////////////////////////////////////////////////////////////////////////	
        ///<summary>
        ///
        ///</summary>
        public DataSet GetAllGroups(int enterpriseid)
        {
            IDictionary epriseRecord;

            try
            {
                epriseRecord = new Hashtable();
                epriseRecord[AdminFields.ID] = "= " +enterpriseid;
                if (db.Exist(epriseRecord, DBTables.ENTERPRISES))
                {
                    epriseRecord.Clear();
                    epriseRecord[AdminFields.EPRISEID] = "= " +enterpriseid;
                    return db.GetFieldsWhereas(epriseRecord, DBTables.GROUPS);
                }
                else
                {
                    NullEnterpriseException nee = new NullEnterpriseException();
                    throw nee;
                }
            }
            catch (NullDataSetException nds)
            {
                NullDataSetException wrappedEx = new
                    NullDataSetException(
                        ErrorManager.AddLayer(nds, RunningClass.GetName(this), RunningClass.GetMethod()));
                throw wrappedEx;
            }
            catch (NullEnterpriseException nee)
            {
                NullEnterpriseException wrappedEx = new
                    NullEnterpriseException(
                        ErrorManager.AddLayer(nee,	RunningClass.GetName(this), RunningClass.GetMethod()));
                throw wrappedEx;
            }
            catch (Exception ex)
            {
                Exception wrappedEx = new Exception(
                        ErrorManager.AddLayer(ex, RunningClass.GetName(this), RunningClass.GetMethod()));
                throw wrappedEx;
            }
        }
        //////////////////////////////////////////////////////////////////////////////////////
        ///<summary>
        ///DeleteAllGroups: delete all groups for a given enterprise, 
        ///deleting groups permissions
        ///and group users. 
        ///If a NullDataSet exception occurs then, 
        ///some of the groups or permissiosn doesnt exist.
        ///</summary>
        public void DeleteAllGroups(int enterpriseid)
        {
            IDictionary groupRecord, epriseRecord;
            ArrayList fields;

            try
            {
                epriseRecord = new Hashtable();
                epriseRecord[AdminFields.ID] = "= " + enterpriseid;
                if (db.Exist(epriseRecord, DBTables.ENTERPRISES))
                {
                    epriseRecord.Clear();
                    epriseRecord[AdminFields.EPRISEID] = "= " +enterpriseid;
                    DataSet ds;
                    fields = new ArrayList();
                    fields.Add(AdminFields.ID);
                    ds = db.GetFieldsWhereas(epriseRecord, fields, DBTables.GROUPS);
                    DataRow[] dsrows = ds.Tables[0].Select(null, null, DataViewRowState.CurrentRows);
                    groupRecord = new Hashtable();
                    for (int i = 0; i < dsrows.Length; i++)
                    {
                        int id_group  = (int)dsrows[0][0];
                        groupRecord[AdminFields.ID] = id_group;
                        db.DeleteWhereas(groupRecord, DBTables.GROUPS);
                        groupRecord.Clear();
                        groupRecord[AdminFields.GROUPID] = id_group;
                        db.DeleteWhereas(groupRecord, DBTables.PERMS);
                        db.DeleteWhereas(groupRecord, DBTables.USERS);
                    }
                }
                else
                {
                    NullEnterpriseException nee = new NullEnterpriseException();
                    throw nee;
                }
            }
            catch (NullDataSetException nds)
            {
                NullDataSetException wrappedEx = new
                    NullDataSetException(
                        ErrorManager.AddLayer(nds, RunningClass.GetName(this), RunningClass.GetMethod()));
                throw wrappedEx;
            }
            catch (NullEnterpriseException nee)
            {
                NullEnterpriseException wrappedEx = new
                    NullEnterpriseException(
                        ErrorManager.AddLayer(nee,	RunningClass.GetName(this), RunningClass.GetMethod()));
                throw wrappedEx;
            }
            catch (Exception ex)
            {
                Exception wrappedEx = new Exception(
                    ErrorManager.AddLayer(ex, RunningClass.GetName(this), RunningClass.GetMethod()));
                throw wrappedEx;
            }
        }
        ///////////////////////////////////////////////////////////////////////////
        ///<summary>
        ///Overloaded
        ///<param name="table">Database table to access </param>
        ///</summary>	
        public DataSet GetFieldsWhereasAndOrder(IDictionary constraint, IDictionary orderby, 
							 IEnumerable fields, string table)
        {
            ICollection constraint_keys, orderby_keys;
            string sql;

            try
            {
                sql = "SELECT " ;
                IEnumerator fieldsIe = fields.GetEnumerator();
                while (fieldsIe.MoveNext())
                    sql += fieldsIe.Current + ", ";
                sql.Substring(0, (sql.Length - 2));
                sql += " FROM " + table;
                constraint_keys = constraint.Keys;
                if (constraint_keys.Count != 0)
                    sql += " WHERE ";
                foreach (string key in constraint_keys)
                    sql += key + constraint[key] + " AND ";
                sql = sql.Substring(0, (sql.Length - 5)); // Remove invalid chars at the end
                orderby_keys = orderby.Keys;
                if (orderby_keys.Count != 0)
                    sql += " ORDER BY ";
                foreach (string key in orderby_keys)
                    sql += key + " " + orderby[key] + ", ";
                sql = sql.Substring(0, (sql.Length - 2));
                db.ExecuteQuery(sql);
                DataSet tmpDs = db.ActiveDataSet();
                if (tmpDs.Tables[0].Rows.Count == 0)
                {
                    NullDataSetException nre = new NullDataSetException();
                    throw nre;
                }
                else
                    return tmpDs;
            }
            catch (NullDataSetException nds)
            {
                NullDataSetException wrappedEx = new
                    NullDataSetException(
                        ErrorManager.AddLayer(nds, RunningClass.GetName(this),
                                            RunningClass.GetMethod()));
                throw wrappedEx;
            }
            catch (Exception ex)
            {
                Exception wrappedEx = new Exception(
                    ErrorManager.AddLayer(ex, RunningClass.GetName(this), RunningClass.GetMethod()));
                throw wrappedEx;
            }
        }
        ////////////////////////////////////////////////////////////////////////////
        ///<summary>
        ///Overloaded
        ///<param name="table">Database table to access </param>
        ///</summary>	
        public DataSet GetFieldsWhereas(IDictionary constraint, string table)
        {
            ICollection constraint_keys;
            string sql;

            try
            {
                sql = "SELECT * FROM " + table;
                constraint_keys = constraint.Keys;
                if (constraint_keys.Count != 0)
                    sql += " WHERE ";
                foreach (string key in constraint_keys)
                    sql += key + constraint[key] + " AND ";
                sql = sql.Substring(0, (sql.Length - 5)); 	// Erase latest AND
                db.ExecuteQuery(sql);
                DataSet tmpDs = db.ActiveDataSet();
                if (tmpDs.Tables[0].Rows.Count == 0)
                {
                    NullDataSetException nre = new NullDataSetException();
                    throw nre;
                }
                else
                    return tmpDs;
            }
            catch (NullDataSetException nds)
            {
                NullDataSetException wrappedEx = new
                    NullDataSetException(
                        ErrorManager.AddLayer(nds, RunningClass.GetName(this),
                                  				RunningClass.GetMethod()));
                throw wrappedEx;
            }
            catch (Exception ex)
            {
                Exception wrappedEx = new Exception(
                    ErrorManager.AddLayer(ex, RunningClass.GetName(this), RunningClass.GetMethod()));
                throw wrappedEx;
            }
        }
 ///////////////////////////////////////////////////////////////////////////////
 ///<summary>
 ///Overloaded
 ///<param name="table">Database table to access </param>
 ///</summary>	
 public DataSet GetFields(IEnumerable fields, string table)
 {
     try
     {
         string sql = "SELECT " ;
         IEnumerator fieldsIe = fields.GetEnumerator();
         while (fieldsIe.MoveNext())
             sql += fieldsIe.Current + ", ";
         sql.Substring(0, (sql.Length - 2));
         sql += " FROM " + table;
         db.ExecuteQuery(sql);
         DataSet tmpDs = db.ActiveDataSet();
         if (tmpDs.Tables[0].Rows.Count == 0)
         {
             NullDataSetException nre = new NullDataSetException();
             throw nre;
         }
         else
             return tmpDs;
     }
     catch (NullDataSetException nds)
     {
         NullDataSetException wrappedEx = new
             NullDataSetException(
                 ErrorManager.AddLayer(nds, RunningClass.GetName(this),
                           					RunningClass.GetMethod()));
         throw wrappedEx;
     }
     catch (Exception ex)
     {
         Exception wrappedEx = new Exception(
             ErrorManager.AddLayer(ex, RunningClass.GetName(this), RunningClass.GetMethod()));
         throw wrappedEx;
     }
 }
 //////////////////////////////////////////////////////////////////////////////
 ///<summary>
 ///Overloaded
 ///<param name="table">Database table to access </param>
 ///</summary>	
 public DataSet GetFields(string table)
 {
     try
     {
         string sql = "SELECT * FROM " + table;
         db.ExecuteQuery(sql);
         DataSet tmpDs = db.ActiveDataSet();
         if (tmpDs.Tables[0].Rows.Count == 0)
         {
             NullDataSetException nds = new NullDataSetException();
             throw nds;
         }
         else
             return tmpDs;
     }
     catch (NullDataSetException nds)
     {
         NullDataSetException wrappedEx = new
             NullDataSetException(
                 ErrorManager.AddLayer(nds, RunningClass.GetName(this),
                           					RunningClass.GetMethod()));
         throw wrappedEx;
     }
     catch (Exception ex)
     {
         Exception wrappedEx = new Exception(
             ErrorManager.AddLayer(ex, RunningClass.GetName(this), RunningClass.GetMethod()));
         throw wrappedEx;
     }
 }