예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }
예제 #5
0
        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 + ";");
        }
예제 #6
0
 public CustomerQueue Post(CustomerQueue q)
 {
     return(Get(servicer.createBankingQueue(q)));
 }
예제 #7
0
 public CustomerQueue Post(CustomerQueue u)
 {
     throw new NotImplementedException();
 }
예제 #8
0
 public QueueInteractor(int id)
 {
     cache = (List <CustomerQueue>)HttpContext.Current.Cache["CustomerQueues"];
     queue = cache.Find(t => t.id == id);
 }