Ejemplo n.º 1
0
 public override Order GetOrder(ulong orderID)
 {
     Order result = Order.Null;
     string statement = "SELECT * FROM Orders WHERE OrderID=@ID";
     try
     {
         using (SqlConnection sqlConn = new SqlConnection(GetConnectionString()))
         {
             sqlConn.Open();
             if (sqlConn.State == ConnectionState.Open)
             {
                 SqlCommand sqlQuery = new SqlCommand(statement, sqlConn);
                 sqlQuery.Parameters.AddWithValue("@ID", (int)orderID);
                 SqlDataReader sqlDR = sqlQuery.ExecuteReader();
                 if (sqlDR.Read())
                 {
                     Order o = new Order();
                     o.OrderID = Convert.ToUInt64(sqlDR["OrderID"]);
                     o.ClientID = Convert.ToUInt64(sqlDR["ClientID"]);
                     o.StartDateTime = (DateTime)sqlDR["StartDateTime"];
                     o.EndDateTime = (DateTime)sqlDR["EndDateTime"];
                     o.Seated = (Boolean)sqlDR["Seated"];
                     o.Payed = (Boolean)sqlDR["Payed"];
                     return o;
                 }
                 result = Order.Null;
             }
         }
     }
     catch { result = Order.Null; }
     return result;
 }
Ejemplo n.º 2
0
 public override List<Order> GetAllOrders()
 {
     List<Order> orders = new List<Order>();
     string statement = "SELECT * FROM Orders";
     try
     {
         using (SqlConnection sqlConn = new SqlConnection(GetConnectionString()))
         {
             sqlConn.Open();
             if (sqlConn.State == ConnectionState.Open)
             {
                 SqlCommand sqlQuery = new SqlCommand(statement, sqlConn);
                 SqlDataReader sqlDR = sqlQuery.ExecuteReader();
                 while (sqlDR.Read())
                 {
                     Order o = new Order();
                     o.OrderID = Convert.ToUInt64(sqlDR["OrderID"]);
                     o.ClientID = Convert.ToUInt64(sqlDR["ClientID"]);
                     o.StartDateTime = (DateTime)sqlDR["StartDateTime"];
                     o.EndDateTime = (DateTime)sqlDR["EndDateTime"];
                     orders.Add(o);
                 }
                 return orders;
             }
             return null;
         }
     }
     catch { return null; }
 }