Пример #1
0
        public int AddDELIVERY()
        {
            int      deliveryNumber;
            DELIVERY d = new DELIVERY();

            string connectionString = Config.GetConnectionString("DefaultConnection");

            try
            {
                using (SqlConnection cn = new SqlConnection(connectionString))
                {
                    string     query = "INSERT INTO DELIVERY (Created_At) VALUES (GETDATE()); SELECT SCOPE_IDENTITY()";
                    SqlCommand cmd   = new SqlCommand(query, cn);

                    cn.Open();

                    deliveryNumber = Convert.ToInt32(cmd.ExecuteScalar());
                }
            }
            catch (Exception e)
            {
                throw e;
            }

            return(deliveryNumber);
        }
Пример #2
0
        public DELIVERY updateDeliveryTime(int deliveryNumber, int deliveryTimeId)
        {
            DELIVERY delivery = DELIVERY_DB.GetDELIVERY(deliveryNumber);

            delivery.Fk_Id_Delivery_Time = deliveryTimeId;

            return(DELIVERY_DB.UpdateDELIVERY_Fk_Id_Delivery_Time(delivery));
        }
Пример #3
0
        public DELIVERY updateServiceClass(int deliveryNumber, int serviceClassId)
        {
            DELIVERY delivery = DELIVERY_DB.GetDELIVERY(deliveryNumber);

            delivery.Fk_Id_Service_Class = serviceClassId;

            return(DELIVERY_DB.UpdateDELIVERY_Fk_Id_Service_Class(delivery));
        }
Пример #4
0
        public DELIVERY assignCourier(int deliveryNumber, int restaurantNumber)
        {
            DELIVERY_COURIER_Manager dcm = new DELIVERY_COURIER_Manager(Configuration);

            DELIVERY delivery = DELIVERY_DB.GetDELIVERY(deliveryNumber);

            DELIVERY_DB.UpdateDELIVERY_Start_Time(delivery);
            delivery.Fk_Id_Delivery_Courier = dcm.getAvailableCourier(restaurantNumber, deliveryNumber);

            return(DELIVERY_DB.UpdateDELIVERY_Fk_Id_Delivery_Courier(delivery));
        }
Пример #5
0
        public ORDERS cancelOrders(string [] stab)
        {
            ORDERS orders = ORDERS_DB.GetORDERS(stab);

            orders.Fk_Id_Order_Status = 16;

            DELIVERY_DB dm       = new DELIVERY_DB(Configuration);
            DELIVERY    delivery = dm.GetDELIVERY(orders.Fk_Id_Delivery);

            delivery.Fk_Id_Delivery_Status = 16;
            dm.UpdateDELIVERY_Fk_Id_Delivery_Status(delivery);

            return(ORDERS_DB.UpdateORDERS_Fk_Id_Order_Status(orders));
        }
Пример #6
0
        public ORDERS cancelOrders(int orderNumber)
        {
            ORDERS orders = ORDERS_DB.GetORDERS(orderNumber);

            orders.Fk_Id_Order_Status = 9;

            DELIVERY_DB dm       = new DELIVERY_DB(Configuration);
            DELIVERY    delivery = dm.GetDELIVERY(orders.Fk_Id_Delivery);

            delivery.Fk_Id_Delivery_Status = 9;
            dm.UpdateDELIVERY_Fk_Id_Delivery_Status(delivery);

            return(ORDERS_DB.UpdateORDERS_Fk_Id_Order_Status(orders));
        }
Пример #7
0
        public DELIVERY archiveDelivery(int deliveryNumber)
        {
            DELIVERY delivery = DELIVERY_DB.GetDELIVERY(deliveryNumber);

            DELIVERY_DB.UpdateDELIVERY_Finish_Time(delivery);

            delivery.Fk_Id_Delivery_Status = 15;
            ORDERS_DB om     = new ORDERS_DB(Configuration);
            ORDERS    orders = om.GetORDERS(DELIVERY_DB.GetORDERSid(deliveryNumber));

            orders.Fk_Id_Order_Status = 7;

            om.UpdateORDERS_Fk_Id_Order_Status(orders);

            return(DELIVERY_DB.UpdateDELIVERY_Fk_Id_Delivery_Status(delivery));
        }
Пример #8
0
        public ORDERS addNewBills(int orderNumber)
        {
            BILLS_Manager bm     = new BILLS_Manager(Configuration);
            ORDERS        orders = ORDERS_DB.GetORDERS(orderNumber);

            orders.Fk_Id_Bills        = bm.createNewBills(orderNumber);
            orders.Fk_Id_Order_Status = 2;

            DELIVERY_DB dm       = new DELIVERY_DB(Configuration);
            DELIVERY    delivery = dm.GetDELIVERY(orders.Fk_Id_Delivery);

            delivery.Fk_Id_Delivery_Status = 2;
            dm.UpdateDELIVERY_Fk_Id_Delivery_Status(delivery);
            ORDERS_DB.UpdateORDERS_Fk_Id_Bills(orders);
            return(ORDERS_DB.UpdateORDERS_Fk_Id_Order_Status(orders));
        }
Пример #9
0
        public ORDERS confirmOrders(int orderNumber)
        {
            ORDERS orders = ORDERS_DB.GetORDERS(orderNumber);

            orders.Fk_Id_Order_Status = 4;

            BILLS_DB bm    = new BILLS_DB(Configuration);
            BILLS    bills = bm.GetBILLS(orders.Fk_Id_Bills);

            bm.UpdateBILLS_Payment_Date(bills);

            DELIVERY_DB dm       = new DELIVERY_DB(Configuration);
            DELIVERY    delivery = dm.GetDELIVERY(orders.Fk_Id_Delivery);

            delivery.Fk_Id_Delivery_Status = 4;
            dm.UpdateDELIVERY_Fk_Id_Delivery_Status(delivery);

            return(ORDERS_DB.UpdateORDERS_Fk_Id_Order_Status(orders));
        }
Пример #10
0
        public DELIVERY UpdateDELIVERY_Finish_Time(DELIVERY delivery)
        {
            string connectionString = Config.GetConnectionString("DefaultConnection");

            try
            {
                using (SqlConnection cn = new SqlConnection(connectionString))
                {
                    string     query = "UPDATE DELIVERY SET Finish_Time = CONVERT(TIME(7),GETDATE()) WHERE Id = @id";
                    SqlCommand cmd   = new SqlCommand(query, cn);
                    cmd.Parameters.AddWithValue("@id", delivery.Id);

                    cn.Open();

                    cmd.ExecuteNonQuery();
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            return(delivery);
        }
Пример #11
0
        public DELIVERY UpdateDELIVERY_Fk_Id_Delivery_Courier(DELIVERY delivery)
        {
            string connectionString = Config.GetConnectionString("DefaultConnection");

            try
            {
                using (SqlConnection cn = new SqlConnection(connectionString))
                {
                    string     query = "UPDATE DELIVERY SET Fk_Id_Delivery_Courier = @Fk_Id_Delivery_Courier WHERE Id = @id";
                    SqlCommand cmd   = new SqlCommand(query, cn);
                    cmd.Parameters.AddWithValue("@id", delivery.Id);
                    cmd.Parameters.AddWithValue("@Fk_Id_Delivery_Courier", delivery.Fk_Id_Delivery_Courier);

                    cn.Open();

                    cmd.ExecuteNonQuery();
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            return(delivery);
        }
Пример #12
0
        public double GetAmount(DELIVERY delivery)
        {
            string connectionString = Config.GetConnectionString("DefaultConnection");

            try
            {
                using (SqlConnection cn = new SqlConnection(connectionString))
                {
                    string query = "SELECT Price " +
                                   "FROM DELIVERY d, SERVICE_CLASS sc " +
                                   "WHERE d.Fk_Id_Delivery_Status = sc.Id " +
                                   "AND d.Id = @deliveryNumber; ";
                    SqlCommand cmd = new SqlCommand(query, cn);
                    cmd.Parameters.AddWithValue("@deliveryNumber", delivery.Id);

                    cn.Open();

                    using (SqlDataReader dr = cmd.ExecuteReader())
                    {
                        if (dr.Read())
                        {
                            if (dr["Price"] != DBNull.Value)
                            {
                                return((double)dr["Price"]);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }

            return(0.0);
        }
Пример #13
0
        public DELIVERY GetDELIVERY(int Id)
        {
            DELIVERY delivery         = null;
            string   connectionString = Config.GetConnectionString("DefaultConnection");

            try
            {
                using (SqlConnection cn = new SqlConnection(connectionString))
                {
                    string     query = "SELECT * FROM DELIVERY WHERE Id = @id";
                    SqlCommand cmd   = new SqlCommand(query, cn);
                    cmd.Parameters.AddWithValue("@id", Id);

                    cn.Open();

                    using (SqlDataReader dr = cmd.ExecuteReader())
                    {
                        if (dr.Read())
                        {
                            delivery = new DELIVERY();

                            if (dr["Id"] != DBNull.Value)
                            {
                                delivery.Id = (int)dr["Id"];
                            }

                            if (dr["Start_Time"] != DBNull.Value)
                            {
                                delivery.Start_Time = (TimeSpan)dr["Start_Time"];
                            }

                            if (dr["Finish_Time"] != DBNull.Value)
                            {
                                delivery.Finish_Time = (TimeSpan)dr["Finish_Time"];
                            }

                            if (dr["Created_At"] != DBNull.Value)
                            {
                                delivery.Created_At = (DateTime)dr["Created_At"];
                            }

                            if (dr["Fk_Id_Service_Class"] != DBNull.Value)
                            {
                                delivery.Fk_Id_Service_Class = (int)dr["Fk_Id_Service_Class"];
                            }

                            if (dr["Fk_Id_Delivery_Status"] != DBNull.Value)
                            {
                                delivery.Fk_Id_Delivery_Status = (int)dr["Fk_Id_Delivery_Status"];
                            }

                            if (dr["Fk_Id_Delivery_Time"] != DBNull.Value)
                            {
                                delivery.Fk_Id_Delivery_Time = (int)dr["Fk_Id_Delivery_Time"];
                            }

                            if (dr["Fk_Id_Delivery_Courier"] != DBNull.Value)
                            {
                                delivery.Fk_Id_Delivery_Courier = (int)dr["Fk_Id_Delivery_Courier"];
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }

            return(delivery);
        }
Пример #14
0
        public List <DELIVERY> GetDELIVERYforCourier(int deliveryCourierNumber)
        {
            List <DELIVERY> deliveries       = null;
            string          connectionString = Config.GetConnectionString("DefaultConnection");

            try
            {
                using (SqlConnection cn = new SqlConnection(connectionString))
                {
                    string     query = "SELECT * FROM DELIVERY WHERE Fk_Id_Delivery_Courier = @deliveryCourierNumber AND Fk_Id_Delivery_Status=4";
                    SqlCommand cmd   = new SqlCommand(query, cn);
                    cmd.Parameters.AddWithValue("@deliveryCourierNumber", deliveryCourierNumber);

                    cn.Open();

                    using (SqlDataReader dr = cmd.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            if (deliveries == null)
                            {
                                deliveries = new List <DELIVERY>();
                            }

                            DELIVERY delivery = new DELIVERY();

                            if (dr["Id"] != DBNull.Value)
                            {
                                delivery.Id = (int)dr["Id"];
                            }

                            if (dr["Start_Time"] != DBNull.Value)
                            {
                                delivery.Start_Time = (TimeSpan)dr["Start_Time"];
                            }

                            if (dr["Finish_Time"] != DBNull.Value)
                            {
                                delivery.Finish_Time = (TimeSpan)dr["Finish_Time"];
                            }

                            if (dr["Created_At"] != DBNull.Value)
                            {
                                delivery.Created_At = (DateTime)dr["Created_At"];
                            }

                            if (dr["Fk_Id_Service_Class"] != DBNull.Value)
                            {
                                delivery.Fk_Id_Service_Class = (int)dr["Fk_Id_Service_Class"];
                            }

                            if (dr["Fk_Id_Delivery_Status"] != DBNull.Value)
                            {
                                delivery.Fk_Id_Delivery_Status = (int)dr["Fk_Id_Delivery_Status"];
                            }

                            if (dr["Fk_Id_Delivery_Time"] != DBNull.Value)
                            {
                                delivery.Fk_Id_Delivery_Time = (int)dr["Fk_Id_Delivery_Time"];
                            }

                            if (dr["Fk_Id_Delivery_Courier"] != DBNull.Value)
                            {
                                delivery.Fk_Id_Delivery_Courier = (int)dr["Fk_Id_Delivery_Courier"];
                            }

                            deliveries.Add(delivery);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }

            return(deliveries);
        }