public static RobotList <Contact> GetOrganizationContacts(Organization o) { RobotList <Contact> rval = new RobotList <Contact>(); SqlConnection cn = new SqlConnection(Helpers.CnnStr()); SafeDataReader dr = null; SqlTransaction tr; SqlCommand cmd; cn.Open(); tr = cn.BeginTransaction(IsolationLevel.ReadCommitted); try { cmd = cn.CreateCommand(); cmd.Transaction = tr; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "usp_GetOrganizationContacts"; cmd.Parameters.AddWithValue("@org_id", o.Id); dr = new SafeDataReader(cmd.ExecuteReader()); while (dr.Read()) { Contact c = new Contact(o); c.DoLoad(dr); rval.Add(c); } dr.Close(); tr.Commit(); } catch { if ((dr != null) && !dr.IsClosed) { dr.Close(); } tr.Rollback(); throw; } finally { if ((dr != null) && !dr.IsClosed) { dr.Close(); } cn.Close(); } return(rval); }
public static Organization GetOrganization(int id) { SqlConnection cn = new SqlConnection(Helpers.CnnStr()); SafeDataReader dr = null; Organization rval = null; SqlTransaction tr; SqlCommand cmd; cn.Open(); tr = cn.BeginTransaction(IsolationLevel.ReadCommitted); try { cmd = cn.CreateCommand(); cmd.Transaction = tr; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "usp_GetOrganization"; cmd.Parameters.AddWithValue("@id", id); dr = new SafeDataReader(cmd.ExecuteReader()); if (dr.Read()) { rval = new Organization(); rval.DoLoad(dr); } dr.Close(); tr.Commit(); } catch { if ((dr != null) && !dr.IsClosed) { dr.Close(); } tr.Rollback(); throw; } finally { if ((dr != null) && !dr.IsClosed) { dr.Close(); } cn.Close(); } return(rval); }
static private ItemTy PerformOperation <ItemTy>( string CnnStr, PerformRead <ItemTy> ReadData, CommandFill FillCmd, object[] args) { SqlConnection cn = new SqlConnection(CnnStr); ItemTy rval = default(ItemTy); SafeDataReader dr = null; SqlTransaction tr; cn.Open(); tr = cn.BeginTransaction(IsolationLevel.ReadCommitted); try { SqlCommand cmd = cn.CreateCommand(); cmd.Transaction = tr; FillCmd(cmd, args); dr = new SafeDataReader(cmd.ExecuteReader()); rval = ReadData(dr); dr.Close(); tr.Commit(); } catch { if ((dr != null) && !dr.IsClosed) { dr.Close(); } tr.Rollback(); throw; } finally { if ((dr != null) && !dr.IsClosed) { dr.Close(); } cn.Close(); } return(rval); }
/// <summary> /// Loads a list from the given SQL command text and type. /// </summary> /// <param name="CommandText">String with the SQL command to execute.</param> /// <param name="CommandType">The type of SQL command to execute.</param> public void Load(string CommandText, CommandType CommandType) { SqlConnection cn = new SqlConnection(CnnStr); SqlTransaction tr; SqlCommand cmd; cn.Open(); tr = cn.BeginTransaction(IsolationLevel.ReadCommitted); try { cmd = cn.CreateCommand(); cmd.Transaction = tr; cmd.CommandText = CommandText; cmd.CommandType = CommandType; SafeDataReader dr = new SafeDataReader(cmd.ExecuteReader()); Load(dr); dr.Close(); tr.Commit(); } catch { tr.Rollback(); } finally { cn.Close(); } }
public static RobotList <Organization> GetActiveOrganizations() { RobotList <Organization> rval = new RobotList <Organization>(); SqlConnection cn = new SqlConnection(Helpers.CnnStr()); SafeDataReader dr = null; SqlTransaction tr; SqlCommand cmd; cn.Open(); tr = cn.BeginTransaction(IsolationLevel.ReadCommitted); try { cmd = cn.CreateCommand(); cmd.Transaction = tr; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "usp_GetActiveOrganizations"; dr = new SafeDataReader(cmd.ExecuteReader()); rval = LoadList(dr); dr.Close(); tr.Commit(); } catch (Exception ex) { tr.Rollback(); MessageBox.Show(ex.Message); } finally { if ((dr != null) && !dr.IsClosed) { dr.Close(); } cn.Close(); } return(rval); }