//////////////////////////////////////////////////////////////////////////////////// ///<summary> ///ModifyEnterprise: epriseid must be an existent enterprise. ///neweprise must'n exist ///</summary> public void ModifyEnterprise(int enterpriseid, EnterpriseStruct neweprise) { IDictionary thisEpriseRecord, epriseFields; try { thisEpriseRecord = new Hashtable(); thisEpriseRecord[AdminFields.ID] = "= " +enterpriseid; if (db.Exist(thisEpriseRecord, DBTables.ENTERPRISES)) { epriseFields = new Hashtable(); epriseFields[AdminFields.EPRISENAME] = neweprise.name; epriseFields[AdminFields.EPRISEDESC] = neweprise.desc; epriseFields[AdminFields.PUBLISHED] = neweprise.published; db.SetFieldsWhereas(thisEpriseRecord, epriseFields, DBTables.ENTERPRISES); } else { NullEnterpriseException nee = new NullEnterpriseException(); throw nee; } } 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; } }
////////////////////////////////////////////////////////////////////////////////////// public EnterpriseStruct GetEnterpriseByName(string epriseName) { IDictionary epriseRecord; try { epriseRecord = new Hashtable(); epriseRecord[AdminFields.EPRISENAME] = "= '" +epriseName +"'"; if (db.Exist(epriseRecord, DBTables.ENTERPRISES)) { DataSet ds = db.GetFieldsWhereas(epriseRecord, DBTables.ENTERPRISES); EnterpriseStruct es = new EnterpriseStruct(); es.name = epriseName; es.id = DataTools.GetIntField (ds, AdminFields.ID); es.desc = DataTools.GetTextField(ds, AdminFields.EPRISEDESC); es.published = DataTools.GetBoolField(ds, AdminFields.PUBLISHED); return es; } else { NullEnterpriseException nee = new NullEnterpriseException(); throw nee; } } 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> /// ///</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> ///DeleteEnterprise: Only deletes a row in enterprise table. Groups ///must be deleted with DeleteAllGroups or throught Facade layout, before this ///</summary> public void DelEnterprise(int enterpriseid) { IDictionary epriseRecord; try { epriseRecord = new Hashtable(); epriseRecord[AdminFields.ID] = "= " +enterpriseid; if (db.Exist(epriseRecord, DBTables.ENTERPRISES)) { db.DeleteWhereas(epriseRecord, DBTables.ENTERPRISES); } else { NullEnterpriseException nee = new NullEnterpriseException(); throw nee; } } 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; } }