public int createBankingQueue(CustomerQueue q) { int id = -1; SqlCommand cmd = new SqlCommand(); cmd.CommandType = System.Data.CommandType.Text; cmd.CommandText = queueInsertString(q); cmd.Connection = this.con.getSQLConnection(); try { con.getSQLConnection().Open(); id = (Int32)cmd.ExecuteScalar(); } catch (Exception e) { Console.Write(e.ToString()); } finally { con.getSQLConnection().Close(); } return(id); }
private string queueInsertString(CustomerQueue t) { string tableName = t.GetType() == typeof(BankingQueue) ? "BankingQueue" : "Normal Queue"; string ans = "INSERT INTO" + tableName + "(QueueOwner, servers, interarrivalTime,serviceTime) OUTPUT INSERTED.ID VALUES("; ans += t.ownerID + "," + t.numServers + "," + t.interarrivalTime + "," + t.serviceTime; ans += ")"; return(ans); }
public CustomerQueue Put(CustomerQueue q) { CustomerQueue c = (CustomerQueue)q; var t = Get(q.id); if (t == null) { throw new Exception(string.Format("User with id {0} does not exists.", q.id)); } t.ownerID = c.ownerID; t.numServers = c.numServers; t.serviceTime = c.serviceTime; t.interarrivalTime = c.interarrivalTime; servicer.updateDatabase(t); return((CustomerQueue)t); }
public bool updateDatabase(CustomerQueue u) { try { SqlDataReader userData = runOperation(queueUpdateString(u)); userData.Read(); } catch (Exception e) { Console.Write(e.ToString()); return(false); } finally { if (con.getSQLConnection().State == System.Data.ConnectionState.Open) { con.getSQLConnection().Close(); } } return(true); }
private string queueUpdateString(CustomerQueue t) { string tableName = t.GetType() == typeof(BankingQueue) ? "BankingQueue" : "Normal Queue"; return("update " + tableName + " SET QueueOwner =" + t.ownerID + ", servers =" + t.numServers + ", interarrivaltime=" + t.interarrivalTime + ", servicetime=" + t.serviceTime + "where id=" + t.id + ";"); }
public CustomerQueue Post(CustomerQueue q) { return(Get(servicer.createBankingQueue(q))); }
public CustomerQueue Post(CustomerQueue u) { throw new NotImplementedException(); }
public QueueInteractor(int id) { cache = (List <CustomerQueue>)HttpContext.Current.Cache["CustomerQueues"]; queue = cache.Find(t => t.id == id); }