public List <ucPastOrderItem> GetPastOrders() { MySqlDataReader dr; int orderID = -1; int status; Console.WriteLine(this.UserID); List <ucPastOrderItem> pastOrderList = new List <ucPastOrderItem>(); string query = string.Format("SELECT * FROM `siparisleriGoster` WHERE UserID = {0}", this.UserID); db.Connect(); dr = db.GetQuery(query); ucPastOrderItem ucPastOrder = new ucPastOrderItem(); while (dr.Read()) { if (orderID != Convert.ToInt32(dr["OrderID"])) { orderID = Convert.ToInt32(dr["OrderID"]); ucPastOrder = new ucPastOrderItem(); ucPastOrder.Dock = System.Windows.Forms.DockStyle.Top; ucPastOrder.lblFoodPrice.Text = (Convert.ToSingle(dr["FinalPrice"])).ToString("0.00") + " TL"; ucPastOrder.lblRestName.Text = dr["RestaurantName"].ToString() + " (" + dr["LocationName"].ToString() + ", " + Convert.ToDateTime(dr["OrderDate"]).ToString("dd/MM/yyyy HH:mm") + ")"; ucPastOrder.lblFoods.Text = dr["FoodName"].ToString() + " (x" + dr["QTY"].ToString() + ")"; status = Convert.ToInt32(dr["StatusID"]); ucPastOrder.lblStatus.Text = dr["Status"].ToString(); switch (status) { case 1: // Delivered to restaurant ucPastOrder.BackColor = Color.FromArgb(255, 245, 255); ucPastOrder.lblStatus.ForeColor = Color.DarkMagenta; break; case 2: //Order is preparing ucPastOrder.BackColor = Color.FromArgb(190, 255, 190); ucPastOrder.lblStatus.ForeColor = Color.Green; break; case 3: //Order delivered to customer ucPastOrder.BackColor = Color.White; ucPastOrder.lblStatus.ForeColor = Color.Black; ucPastOrder.lblFoodPrice.ForeColor = Color.Black; break; case 4: // order canceled by restaurant ucPastOrder.BackColor = Color.FromArgb(240, 240, 240); ucPastOrder.lblFoodPrice.ForeColor = Color.Gray; ucPastOrder.lblStatus.ForeColor = Color.Red; break; } pastOrderList.Add(ucPastOrder); } else { ucPastOrder.lblFoods.Text += ", " + dr["FoodName"].ToString() + " (x" + dr["QTY"] + ")";; } } db.Close(); return(pastOrderList); }
public List <ucPastOrderItem> GetPastOrders() { MySqlDataReader dr; int orderID = -1; int status; Console.WriteLine(this.UserID); List <ucPastOrderItem> pastOrderList = new List <ucPastOrderItem>(); string query = string.Format("SELECT O.OrderID,O.OrderDate,F.FoodName,R.RestaurantName,O.StatusID,OS.Status,L.LocationName,O.FinalPrice, B.QTY FROM Orders O" + " INNER JOIN Basket B ON B.OrderID = O.OrderID" + " INNER JOIN Restaurants R ON R.RestaurantID = O.RestaurantID" + " INNER JOIN Foods F ON F.FoodID = B.FoodID" + " INNER JOIN Locations L ON L.LocationID = R.LocationID" + " INNER JOIN OrderStatus OS ON O.StatusID = OS.StatusID WHERE O.UserID = '{0}'" + " ORDER BY O.OrderID ASC", this.UserID); db.Connect(); dr = db.GetQuery(query); ucPastOrderItem ucPastOrder = new ucPastOrderItem(); while (dr.Read()) { if (orderID != Convert.ToInt32(dr["OrderID"])) { orderID = Convert.ToInt32(dr["OrderID"]); ucPastOrder = new ucPastOrderItem(); ucPastOrder.Dock = System.Windows.Forms.DockStyle.Top; ucPastOrder.lblFoodPrice.Text = (Convert.ToSingle(dr["FinalPrice"])).ToString("0.00") + " TL"; ucPastOrder.lblRestName.Text = dr["RestaurantName"].ToString() + " (" + dr["LocationName"].ToString() + ", " + Convert.ToDateTime(dr["OrderDate"]).ToString("dd/MM/yyyy HH:mm") + ")"; ucPastOrder.lblFoods.Text = dr["FoodName"].ToString() + " (x" + dr["QTY"].ToString() + ")"; status = Convert.ToInt32(dr["StatusID"]); ucPastOrder.lblStatus.Text = dr["Status"].ToString(); switch (status) { case 1: ucPastOrder.BackColor = Color.FromArgb(255, 245, 255); ucPastOrder.lblStatus.ForeColor = Color.DarkMagenta; break; case 2: ucPastOrder.BackColor = Color.FromArgb(190, 255, 190); ucPastOrder.lblStatus.ForeColor = Color.Green; break; case 3: ucPastOrder.BackColor = Color.White; ucPastOrder.lblStatus.ForeColor = Color.Black; ucPastOrder.lblFoodPrice.ForeColor = Color.Black; break; case 4: ucPastOrder.BackColor = Color.FromArgb(240, 240, 240); ucPastOrder.lblFoodPrice.ForeColor = Color.Gray; ucPastOrder.lblStatus.ForeColor = Color.Red; break; } pastOrderList.Add(ucPastOrder); } else { ucPastOrder.lblFoods.Text += ", " + dr["FoodName"].ToString() + " (x" + dr["QTY"] + ")";; } } db.Close(); return(pastOrderList); }