Пример #1
0
        public void MakeNewAppointment()
        {
            string      startTime = "";
            string      endTime   = "";
            bool        converted = false;
            DateTime    date;
            DBcontroler DB = new DBcontroler();

            do
            {
                Console.Write("Date (dd-mm-yyyy): ");
                converted = DateTime.TryParse(Console.ReadLine(), out date);
                if (converted == false)
                {
                    Console.WriteLine();
                    Console.WriteLine("Wrong input! Try again!");
                    Console.ReadKey();
                    Console.Clear();
                }
            } while (converted == false);

            ShowAvailableTime(date);
            do
            {
                Console.Write("Start time (hh:mm): ");
                startTime = Console.ReadLine();
            } while (CheckHours(startTime) == false || CheckMinutes(startTime) == false);
            do
            {
                Console.Write("End time (hh:mm): ");
                endTime = Console.ReadLine();
            } while (CheckHours(endTime) == false || CheckMinutes(endTime) == false);

            Console.Write("Notes: ");
            string notes        = Appointment.ChangeNotes(Console.ReadLine());
            string phone        = "";
            bool   phoneIsRight = false;

            do
            {
                phoneIsRight = false;
                Console.Write("Customer's phone number: ");
                phone = Console.ReadLine();
                if (PhoneNumberChecking(phone) == true)
                {
                    phoneIsRight = true;
                    phone        = Customer.SplitPhoneNumber(phone);
                }
            } while (phoneIsRight == false);

            Customer    customer    = cuRepo.Load(phone);
            Appointment appointment = new Appointment(date, startTime, endTime, notes, customer);

            DB.InsertAppointment(appointment);
            Console.ReadKey();
        }
Пример #2
0
        internal static void GetOrders(OrderRepository orderRepository, CustomerRepository customerRepository, ProductTypeRepository productTypeRepository)
        {
            List <Order> listOfOrders = new List <Order>();

            try
            {
                conn.Open();
                orderRepository.Clear();
                SqlCommand    cmd = new SqlCommand("SP_GET_ALL_ORDERS", conn);
                SqlDataReader rdr = cmd.ExecuteReader();

                if (rdr.HasRows)
                {
                    while (rdr.Read())
                    {
                        Customer customerOfThisOrder = customerRepository.Load(Convert.ToInt32(rdr["CUSTOMER_ID"]));
                        Order    order = new Order(Convert.ToInt32(rdr["ORDER_ID"]), Convert.ToDateTime(rdr["DATE"]), Convert.ToDateTime(rdr["DELIVERY_DATE"]), customerOfThisOrder);
                        order.Registered = Convert.ToBoolean(rdr["Registered"]);
                        listOfOrders.Add(order);
                    }
                }

                rdr.Close();

                foreach (Order ord in listOfOrders)
                {
                    cmd             = new SqlCommand("SP_GET_ORDER_LINE_BY_ORDER_ID", conn);
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SqlParameter("@ORDER_ID", ord.Id));

                    List <int>         listOfOrderLinesQuantity = new List <int>();
                    List <ProductType> listOfOrderLinesProducts = new List <ProductType>();

                    rdr = cmd.ExecuteReader();

                    if (rdr.HasRows)
                    {
                        while (rdr.Read())
                        {
                            listOfOrderLinesProducts.Add(productTypeRepository.Load(Convert.ToInt32(rdr["PRODUCT_ID"])));
                            listOfOrderLinesQuantity.Add(Convert.ToInt32(rdr["QUANTITY"]));
                        }
                        rdr.Close();
                        cmd.Dispose();
                    }

                    Order newOrder = orderRepository.InsertOrder(ord.Customer, ord.Date, ord.DeliveryDate, ord.Id, listOfOrderLinesQuantity, listOfOrderLinesProducts, ord.Registered, productTypeRepository);
                    ord.Customer.OrderRepository.InsertOrder(ord.Customer, ord.Date, ord.DeliveryDate, ord.Id, listOfOrderLinesQuantity, listOfOrderLinesProducts, ord.Registered, productTypeRepository);
                }
            }
            catch (SqlException e)
            {
                UI.WriteL(e.Message.ToString());
                UI.Wait();
            }
            finally
            {
                conn.Close();
            }
        }
Пример #3
0
        public void InsertOrder()
        {
            UI.Write("Customer id:");
            int customerId = Convert.ToInt32(Console.ReadLine());

            Customer cust = customerRepository.Load(customerId);

            if (cust == null)
            {
                UI.Clear();
                UI.WriteL("Customer not found in the DB, please create one.");
                InsertCustomer();
                customerId = customerRepository.NewCustomerId();
            }

            UI.WriteL("Order date:");
            DateTime date = Convert.ToDateTime(Console.ReadLine());

            UI.WriteL("Delivery date:");
            DateTime deliveryDate = Convert.ToDateTime(Console.ReadLine());

            UI.Clear();

            int              orderId          = orderRepository.NewOrderNumber();
            bool             isChoosing       = true;
            List <OrderLine> listOfOrderLines = new List <OrderLine>();

            do
            {
                UI.Clear();
                ShowListOfProducts();
                UI.WriteL("Choose a product (any char to exit):");
                int productId;

                isChoosing = Int32.TryParse(Console.ReadLine(), out productId);

                if (isChoosing == true)
                {
                    UI.WriteL("Choose a quantity:");
                    int productQuantity = Convert.ToInt32(Console.ReadLine());
                    listOfOrderLines.Add(new OrderLine(productTypeRepository.Load(productId), productQuantity));
                }
            } while (isChoosing == true);

            DB.InsertOrder(customerId, orderId, date, deliveryDate, listOfOrderLines);
        }