public makeNewReservation(ReservationDetails _newReservation, IEnumerable <Table> _empty_tables)
 {
     InitializeComponent();
     this.ipRDetails  = _newReservation;
     this.emptyTables = _empty_tables;
     this.Left        = SystemParameters.WorkArea.Width - this.MaxWidth;
 }
        private void Cvs_slot_1_MouseUp(object sender, MouseButtonEventArgs e)
        {
            var rDate = DateTime.Now.Date;

            if (Dp_DatePicker.SelectedDate != null)
            {
                rDate = (DateTime)Dp_DatePicker.SelectedDate;
            }

            Console.WriteLine("Date : " + rDate);

            if (!App.isDateTimeIsPast(rDate))
            {
                var pos = e.GetPosition(Cvs_slot_1);

                var TableID   = Math.Ceiling(pos.Y / (Cvs_slot_1.Height / 9));
                int startTime = getStartTimeGUI(pos.X);
                int endTime   = startTime + 100;


                Console.WriteLine("start Time " + startTime);
                Console.WriteLine("end Time " + endTime);


                var booked_tables = (from et in App.reservedTables
                                     where
                                     et.ReservationDate.Date.Equals(rDate) &&
                                     et.TableId.Equals(Convert.ToInt32(TableID)) &&
                                     ((endTime > et.StartTime && endTime < et.EndTime) || (startTime > et.StartTime && startTime < et.EndTime)) &&
                                     et.IsActive == 1
                                     select et.TableId).ToList();

                Console.WriteLine("IsCVSnewReservationOpen : " + App.IsCVSnewReservationOpen);

                if (booked_tables.Count() == 0 & endTime <= 2300 & !App.IsCVSnewReservationOpen)
                {
                    ReservationDetails reservationDetails = new ReservationDetails
                    {
                        StartTime       = startTime,
                        EndTime         = startTime + 100,
                        TableId         = Convert.ToInt32(TableID),
                        ReservationDate = rDate,
                        NumberOfGuest   = (from tbx in App.tables where tbx.TableId.Equals(Convert.ToInt32(TableID)) select tbx.TableCapacity).FirstOrDefault(),
                        IsActive        = 1
                    };



                    var newCvsReservation = new newReservationFromCanvas(reservationDetails)
                    {
                        Owner = this
                    };
                    newCvsReservation.Show();
                }
                else
                {
                    MessageBox.Show("Time Overlapped! Please select other time slot", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
Ejemplo n.º 3
0
 public newReservationFromCanvas(ReservationDetails _newReservation)
 {
     InitializeComponent();
     this.ipRDetails = _newReservation;
     this.Left       = SystemParameters.WorkArea.Width - this.MaxWidth;
 }
        private void Btn_Search_Click(object sender, RoutedEventArgs e)
        {
            if (Dtp_reservation_date.SelectedDate == null)
            {
                if (Cbx_guest_number.Text.Equals(".") & Dtp_reservation_date.SelectedDate == null & Cbx_reservation_hours.Text.Equals("Hrs")
                    & Cbx_reservation_minute.Text.Equals("Min") & !string.IsNullOrEmpty(Tbx_reservation_name.Text))
                {
                    var r_by_name = (from r in App.reservedTables where r.GuestName.Equals(Tbx_reservation_name.Text) && r.IsActive == 1 select r).FirstOrDefault();
                    if (r_by_name != null & !App.IsEditReservationOpen)
                    {
                        var editReservation = new EditReservation(r_by_name)
                        {
                            Owner = this
                        };
                        editReservation.Show();
                    }
                    else
                    {
                        MessageBox.Show("No Reservation by Name " + Tbx_reservation_name.Text, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
            }
            else
            {
                if (!Cbx_guest_number.Text.Equals(".") & Dtp_reservation_date.SelectedDate != null & !Cbx_reservation_hours.Text.Equals("Hrs")
                    & !Cbx_reservation_minute.Text.Equals("Min") & string.IsNullOrEmpty(Tbx_reservation_name.Text))
                {
                    if (!App.isDateTimeIsPast(ipDate: (DateTime)Dtp_reservation_date.SelectedDate, time: (int.Parse(Cbx_reservation_hours.Text) * 100) + int.Parse(Cbx_reservation_minute.Text)))
                    {
                        int et_startTime = Int32.Parse(Cbx_reservation_hours.Text) * 100 + Int32.Parse(Cbx_reservation_minute.Text);
                        int et_endtime   = ((Int32.Parse(Cbx_reservation_hours.Text) + 1) * 100) + Int32.Parse(Cbx_reservation_minute.Text);


                        if (et_endtime <= 2300)
                        {
                            var booked_tables = (from et in App.reservedTables
                                                 where
                                                 et.ReservationDate.Date.Equals((DateTime)Dtp_reservation_date.SelectedDate) &&
                                                 ((et_endtime > et.StartTime && et_endtime < et.EndTime) || (et_startTime > et.StartTime && et_startTime < et.EndTime)) &&
                                                 et.IsActive == 1
                                                 select et.TableId).ToList();
                            // todo check if time overlapps
                            var empty_tables = App.tables.Where(i => !booked_tables.Contains(i.TableId) && i.TableCapacity >= Int32.Parse(Cbx_guest_number.Text));

                            if (empty_tables.Count() > 0 & !App.IsMakeNewReservationOpen)
                            {
                                ReservationDetails newReservation = new ReservationDetails
                                {
                                    NumberOfGuest   = Int32.Parse(Cbx_guest_number.Text),
                                    ReservationDate = (DateTime)Dtp_reservation_date.SelectedDate,
                                    StartTime       = Int32.Parse(Cbx_reservation_hours.Text) * 100 + Int32.Parse(Cbx_reservation_minute.Text),
                                    EndTime         = ((Int32.Parse(Cbx_reservation_hours.Text) + 1) * 100) + Int32.Parse(Cbx_reservation_minute.Text),
                                    IsActive        = 1
                                };

                                var newReservationWindow = new makeNewReservation(newReservation, empty_tables)
                                {
                                    Owner = this
                                };
                                newReservationWindow.Show();
                            }
                        }
                        else
                        {
                            MessageBox.Show("No Tables Availiable", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                    }
                }

                if (Cbx_guest_number.Text.Equals(".") & Dtp_reservation_date.SelectedDate != null & Cbx_reservation_hours.Text.Equals("Hrs")
                    & Cbx_reservation_minute.Text.Equals("Min") & !string.IsNullOrEmpty(Tbx_reservation_name.Text))
                {
                    var r_by_name_n_Date = (from r in App.reservedTables
                                            where r.GuestName.Equals(Tbx_reservation_name.Text) &&
                                            r.ReservationDate.Date.Equals((DateTime)Dtp_reservation_date.SelectedDate) &&
                                            r.IsActive == 1
                                            select r).FirstOrDefault();
                    if (r_by_name_n_Date != null & !App.IsEditReservationOpen)
                    {
                        var editReservation = new EditReservation(r_by_name_n_Date)
                        {
                            Owner = this
                        };
                        editReservation.Show();
                    }
                    else
                    {
                        MessageBox.Show("No Reservation by Name " + Tbx_reservation_name.Text, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
            }
        }