public static List <Room> ListRooms() { List <Room> list = new List <Room>(); try { SqlConnection db = new SqlConnection(connectionString); SqlTransaction transaction; db.Open(); transaction = db.BeginTransaction(IsolationLevel.ReadUncommitted); try { SqlCommand cmd = new SqlCommand("SELECT [id_room],[name], [timestamp] FROM [Room] R;", db, transaction); SqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { int id_course = rdr.GetInt32(rdr.GetOrdinal("id_room")); string name = rdr.GetString(rdr.GetOrdinal("name")); Room room = new Room(id_course, name); byte[] buffer = new byte[100]; rdr.GetBytes(rdr.GetOrdinal("timestamp"), 0, buffer, 0, 100); room.setTimestamp(buffer); list.Add(room); } rdr.Close(); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw new GrException(ex, Messages.errProd); } finally { db.Close(); } } catch (Exception ex) { if (ex is GrException) { throw ex; } throw new GrException(ex, Messages.errProd); } return(list); }
public static Room GetRoom(int id) { Room room = null; try { SqlConnection db = new SqlConnection(connectionString); SqlTransaction transaction; db.Open(); transaction = db.BeginTransaction(IsolationLevel.ReadCommitted); try { SqlCommand cmd = new SqlCommand("SELECT [name], [timestamp] FROM [Room] R WHERE R.id_room=@id;", db, transaction); cmd.Parameters.Add("@id", SqlDbType.Int).Value = id; SqlDataReader rdr = cmd.ExecuteReader(); if (rdr.Read()) { string name = rdr.GetString(rdr.GetOrdinal("name")); room = new Room(id, name); byte[] buffer = new byte[100]; rdr.GetBytes(rdr.GetOrdinal("timestamp"), 0, buffer, 0, 100); room.setTimestamp(buffer); } rdr.Close(); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw new GrException(ex, Messages.errProd); } finally { db.Close(); } } catch (Exception ex) { if (ex is GrException) { throw ex; } throw new GrException(ex, Messages.errProd); } return(room); }
public static List<Room> ListRooms() { List<Room> list = new List<Room>(); try { SqlConnection db = new SqlConnection(connectionString); SqlTransaction transaction; db.Open(); transaction = db.BeginTransaction(IsolationLevel.ReadUncommitted); try { SqlCommand cmd = new SqlCommand("SELECT [id_room],[name], [timestamp] FROM [Room] R;", db, transaction); SqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { int id_course = rdr.GetInt32(rdr.GetOrdinal("id_room")); string name = rdr.GetString(rdr.GetOrdinal("name")); Room room = new Room(id_course, name); byte[] buffer = new byte[100]; rdr.GetBytes(rdr.GetOrdinal("timestamp"), 0, buffer, 0, 100); room.setTimestamp(buffer); list.Add(room); } rdr.Close(); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw new GrException(ex, Messages.errProd); } finally { db.Close(); } } catch (Exception ex) { if (ex is GrException) throw ex; throw new GrException(ex, Messages.errProd); } return list; }
public static Room GetRoom(int id) { Room room = null; try { SqlConnection db = new SqlConnection(connectionString); SqlTransaction transaction; db.Open(); transaction = db.BeginTransaction(IsolationLevel.ReadCommitted); try { SqlCommand cmd = new SqlCommand("SELECT [name], [timestamp] FROM [Room] R WHERE R.id_room=@id;", db, transaction); cmd.Parameters.Add("@id", SqlDbType.Int).Value = id; SqlDataReader rdr = cmd.ExecuteReader(); if (rdr.Read()) { string name = rdr.GetString(rdr.GetOrdinal("name")); room = new Room(id, name); byte[] buffer = new byte[100]; rdr.GetBytes(rdr.GetOrdinal("timestamp"), 0, buffer, 0, 100); room.setTimestamp(buffer); } rdr.Close(); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw new GrException(ex, Messages.errProd); } finally { db.Close(); } } catch (Exception ex) { if (ex is GrException) throw ex; throw new GrException(ex, Messages.errProd); } return room; }