////////////////////////////////////////////////////////////// ///<summary> ///CreateEnterprise: eprisename must'n exist. ///<return>New enterprise id </return> ///</summary> public int CreateEnterprise(EnterpriseStruct eprise) { IDictionary epriseRecord, epriseFields; try { epriseRecord = new Hashtable(); epriseRecord[AdminFields.EPRISENAME] = "= '" +eprise.name +"'"; if (!db.Exist(epriseRecord, DBTables.ENTERPRISES)) { epriseFields = new Hashtable(); epriseFields[AdminFields.EPRISENAME] = eprise.name; epriseFields[AdminFields.EPRISEDESC] = eprise.desc; epriseFields[AdminFields.PUBLISHED] = eprise.published; db.Insert(epriseFields, DBTables.ENTERPRISES, ref eprise.id); return eprise.id; } else { EnterpriseAlreadyExistException eae = new EnterpriseAlreadyExistException(); throw eae; } } catch (EnterpriseAlreadyExistException eae) { EnterpriseAlreadyExistException wrappedEx = new EnterpriseAlreadyExistException( ErrorManager.AddLayer(eae, 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> ///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 void ModifyEnterprise(string sid, DataSet enterprise) { IDbTransaction t = null; try { Initialize(sid); string epriseName = DataTools.GetTextField(enterprise, AdminFields.EPRISENAME); EnterpriseStruct es = new EnterpriseStruct(); es.name = epriseName; es.published = DataTools.GetBoolField(enterprise, AdminFields.PUBLISHED); es.id = DataTools.GetIntField(enterprise, AdminFields.EPRISEID); es.desc = DataTools.GetTextField(enterprise, AdminFields.EPRISEDESC); t = db.BeginTransaction(); enterprises.ModifyEnterprise(es.id, es); if (cacheMem.SetCacheData(es, DBTables.ENTERPRISES + es.name)) historyObj.Register("Enterprise is already in cache"); } catch (NullEnterpriseException nee) { Exception wrappedEx = new Exception( ErrorManager.GenerateError(RunningClass.GetName(this), RunningClass.GetMethod(), ErrorsMsg.EMPTY_ENTERPRISE)); throw wrappedEx; } catch (Exception ex) { Exception wrappedEx = new Exception( ErrorManager.AddLayer(ex, RunningClass.GetName(this), RunningClass.GetMethod())); throw wrappedEx; } finally { if (t != null) db.Commit(t); } }
////////////////////////////////////////////////////////////////////////////////////// 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; } }
public void AddEnterprise(string sid, DataSet enterprise) { IDbTransaction t = null; try { Initialize(sid); string epriseName = DataTools.GetTextField(enterprise, AdminFields.EPRISENAME); EnterpriseStruct es = new EnterpriseStruct(); es.name = epriseName; es.published = DataTools.GetBoolField(enterprise, AdminFields.PUBLISHED); es.desc = DataTools.GetTextField(enterprise, AdminFields.EPRISEDESC); t = db.BeginTransaction(); es.id = enterprises.CreateEnterprise(es); cacheMem.SetCacheData(es, DBTables.ENTERPRISES + es.name); } catch (EnterpriseAlreadyExistException eae) { Exception wrappedEx = new Exception( ErrorManager.GenerateError(RunningClass.GetName(this), RunningClass.GetMethod(), ErrorsMsg.ENTERPRISE_EXIST)); throw wrappedEx; } catch (Exception ex) { Exception wrappedEx = new Exception( ErrorManager.AddLayer(ex, RunningClass.GetName(this), RunningClass.GetMethod())); throw wrappedEx; } finally { if (t != null) db.Commit(t); } }