Esempio n. 1
0
 private void CBBike_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (CBBike.Items.Count == 0)
     {
         MainWindow main = new MainWindow();
         main.Framework.Visibility = Visibility.Collapsed;
     }
     else
     {
         if (CBBike.SelectedIndex == -1)
         {
             CBBike.SelectedIndex = 0;
         }
         TBikeDAL  MyDAL       = new TBikeDAL();
         DataTable ResultTable = MyDAL.ShowBookingTableByBike(CBBike.SelectedValue.ToString().Trim(), "R");
         TBIkeUtility.TranslateRecordStatusDescription(new List <string> {
             "BookingStatus"
         }, ref ResultTable);
         LBCustomer.Text    = Convert.ToString(ResultTable.Rows[0]["Customer"]);
         Customer           = LBCustomer.Text;
         LBBookingDate.Text = Convert.ToString(ResultTable.Rows[0]["BookingDate"]);
         LBBicycle.Text     = Convert.ToString(ResultTable.Rows[0]["BicycleName"]);
         LBRemarks.Text     = Convert.ToString(ResultTable.Rows[0]["Remark"]);
     }
 }
Esempio n. 2
0
        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            int insertCounter = 0;
            int count         = 0;

            //book button
            try
            {
                string   BikeID = Convert.ToString(CBBike.SelectedValue).Trim();
                TBikeDAL MyDAL  = new TBikeDAL();
                DateTime Start  = Convert.ToDateTime(StartDate.SelectedDate.Value);

                TimeSpan CheckTime = new TimeSpan(08, 00, 00);
                TimeSpan endTime   = new TimeSpan(16, 00, 00);



                DataTable ResultTable     = new DataTable();
                DataTable ResultBikeTable = MyDAL.SelectBicycleByID(CBBike.SelectedValue.ToString().Trim());
                int       bikeQuantity    = Convert.ToInt32(ResultBikeTable.Rows[0]["Quantity"]);
                ResultTable = MyDAL.ShowBookingTableByBike(CBBike.SelectedValue.ToString().Trim(), "");
                if (bikeQuantity != 0)
                {
                    var dates = new List <DateTime>();
                    if (ResultTable.Rows.Count == 0)
                    {
                        MyDAL.AddBookingTime(Start, CBBike.SelectedValue.ToString().Trim(), "A", TBCustomer.Text, null, TLUsername.Text, null, null, TBRemarks.Text);
                        MessageBox.PopWindow pop = new MessageBox.PopWindow(AppData.ImageType.Information, "Success", "Booking made at :" + Start, "OK");
                        pop.ShowDialog();
                    }
                    for (int i = 0; i < ResultTable.Rows.Count; i++)
                    {
                        if (Convert.ToString(ResultTable.Rows[A]["BookingStatus"]).Trim() != "S")
                        {
                            DateTime GetDate = Convert.ToDateTime(ResultTable.Rows[A]["BookingDate"]);
                            if (Start.Date == GetDate && CBBike.SelectedValue.ToString().Trim() == Convert.ToString(ResultTable.Rows[A]["BicycleID"]).ToString().Trim())
                            {
                                count++;
                                break;
                            }

                            else if (Start.Date > DateTime.Now && Convert.ToDateTime(ResultTable.Rows[A]["BookingDate"]).Date <Start.Date && Start.TimeOfDay> CheckTime && Start.TimeOfDay < endTime)
                            {
                                insertCounter++;
                                A++;
                            }
                            else if (Start.Date < DateTime.Now)
                            {
                                MessageBox.PopWindow pop = new MessageBox.PopWindow(AppData.ImageType.Warning, "Sorry", "Date must be booked 1 day ahead from today", "OK");
                                pop.ShowDialog();
                                insertCounter = 0;
                                break;
                            }
                            else if (Start.TimeOfDay < CheckTime || Start.TimeOfDay > endTime)
                            {
                                MessageBox.PopWindow pop = new MessageBox.PopWindow(AppData.ImageType.Warning, "Sorry", "Booking must be booked at 8am-4pm", "OK");
                                pop.ShowDialog();
                                insertCounter = 0;
                                break;
                            }

                            else
                            {
                                count = count + 1;
                                A++;
                            }

                            if (ResultTable.Rows.Count <= A)
                            {
                                A = 0;
                                insertCounter++;
                                break;
                            }
                        }
                        else
                        {
                            A++;
                            insertCounter++;
                        }
                    }

                    if (count >= 1)
                    {
                        MessageBox.PopWindow pop = new MessageBox.PopWindow(AppData.ImageType.Warning, "Sorry", "Sorry Booking not made, This bike has been booked on " + Start.ToLongDateString(), "OK");
                        count = 0;
                        pop.ShowDialog();
                    }
                    else if (insertCounter >= 1)
                    {
                        MyDAL.AddBookingTime(Start, CBBike.SelectedValue.ToString().Trim(), "A", TBCustomer.Text, null, TLUsername.Text, null, null, TBRemarks.Text);
                        MessageBox.PopWindow pop = new MessageBox.PopWindow(AppData.ImageType.Information, "Success", "Bicycle: " + Convert.ToString(ResultTable.Rows[0]["BicycleName"]).Trim() + ", Booking made at :" + Start.ToLongDateString(), "OK");
                        insertCounter = 0;
                        pop.ShowDialog();
                    }
                }
                else
                {
                    MessageBox.PopWindow pop = new MessageBox.PopWindow(AppData.ImageType.Warning, "Sorry", "This bike has ran out of stock", "Sad :(");
                    pop.ShowDialog();
                }
            }

            catch (Exception ex)
            {
                MessageBox.PopWindow pop = new MessageBox.PopWindow(AppData.ImageType.Error, "Error", ex.Message, "Sad :(");
                pop.ShowDialog();
            }
            finally
            {
                //dispose all counters
                A             = 0;
                count         = 0;
                insertCounter = 0;
                MainWindow main = new MainWindow();
                main.Notification();
            }
        }