Example #1
0
        public static List <TableOrder> GetAll()
        {
            List <TableOrder> allOrders = new List <TableOrder> {
            };
            MySqlConnection conn        = DB.Connection();

            conn.Open();
            MySqlCommand    cmd         = new MySqlCommand("SELECT * FROM table_orders ORDER BY order_date", conn);
            MySqlDataReader rdr         = cmd.ExecuteReader();
            int             id          = 0;
            string          tableNumber = "";
            DateTime        orderDate   = DateTime.Now;

            while (rdr.Read())
            {
                id          = rdr.GetInt32(0);
                tableNumber = rdr.GetString(1);
                orderDate   = rdr.GetDateTime(2);
                TableOrder newOrder = new TableOrder(tableNumber, orderDate, id);
                allOrders.Add(newOrder);
            }
            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            return(allOrders);
        }
Example #2
0
        public static TableOrder Find(int id)
        {
            MySqlConnection conn = DB.Connection();

            conn.Open();
            MySqlCommand   cmd   = new MySqlCommand("SELECT * FROM table_orders WHERE id=@id", conn);
            MySqlParameter prmId = new MySqlParameter("@id", id);

            cmd.Parameters.Add(prmId);
            MySqlDataReader rdr         = cmd.ExecuteReader();
            string          tableNumber = "";
            DateTime        orderDate   = DateTime.Now;

            while (rdr.Read())
            {
                tableNumber = rdr.GetString(1);
                orderDate   = rdr.GetDateTime(2);
            }
            TableOrder foundOrder = new TableOrder(tableNumber, orderDate, id);

            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            return(foundOrder);
        }
Example #3
0
        public override bool Equals(System.Object otherOrder)
        {
            if (!(otherOrder is TableOrder))
            {
                return(false);
            }

            else
            {
                TableOrder newOrder            = (TableOrder)otherOrder;
                bool       idEquality          = this.GetId().Equals(newOrder.GetId());
                bool       dateEquality        = this.GetOrderDate().Equals(newOrder.GetOrderDate());
                bool       tableNumberEquality = this.GetTableNumber().Equals(newOrder.GetTableNumber());
                return(idEquality && dateEquality && tableNumberEquality);
            }
        }