コード例 #1
0
        public void PopulateID(string BicycleID, string Status)
        {
            TBikeDAL  MyDAL           = new TBikeDAL();
            DataTable ResultTable     = MyDAL.SelectServiceByBike(BicycleID);
            DataTable ResultBikeTable = MyDAL.SelectBicycleByID(BicycleID);

            LBBicycleName.Text = Convert.ToString(ResultBikeTable.Rows[0]["BicycleName"]);
            LBStatus.Text      = Convert.ToString(ResultBikeTable.Rows[0]["BicycleStatus"]);

            BindComboBoxBicycle(CBBicycle);
            CBBicycle.SelectedIndex = CBBicycle.Items.Count - 1;
            if (LBStatus.Text == "M")
            {
                LBStatus.Text          = "Maintenance";
                TBCondition.Text       = Convert.ToString(ResultTable.Rows[0]["Remark"]);
                PickStart.SelectedDate = Convert.ToDateTime(ResultTable.Rows[0]["ServiceStart"]);
                PickEnd.SelectedDate   = Convert.ToDateTime(ResultTable.Rows[0]["ServiceEnd"]);
                LBDuration.Text        = Convert.ToString(PickEnd.SelectedDate.Value - PickStart.SelectedDate.Value) + "Days";
            }
            else if (LBStatus.Text == "I")
            {
                LBStatus.Text    = "InActive";
                TBCondition.Text = Convert.ToString(ResultBikeTable.Rows[0]["Condition"]);
            }
        }
コード例 #2
0
        private void CBBike_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            TBikeDAL    MyDAL   = new TBikeDAL();
            DataRowView dataRow = (DataRowView)dataGrid1.SelectedItem;

            int index = dataGrid1.Items.IndexOf(dataGrid1.CurrentItem);

            if (index == -1)
            {
                index = 0;
            }
            //string cellValue = dataRow.Row.ItemArray[index].ToString();
            DataTable ResultTable = MyDAL.SelectBicycleByID(CBBike.SelectedValue.ToString().Trim());

            Column1.Header   = "Bicycle ID";
            Column1.Binding  = new Binding("BicycleID");
            Column2.Header   = "Bicycle Name";
            Column2.Binding  = new Binding("BicycleName");
            Column3.Header   = "Bicycle Type";
            Column3.Binding  = new Binding("BicycleType");
            Column4.Header   = "Bicycle Status";
            Column4.Binding  = new Binding("BicycleStatusInFull");
            Column5.Header   = "Current Renter";
            Column5.Binding  = new Binding("CurrentRenter");
            Column6.Header   = "Quantity";
            Column6.Binding  = new Binding("Quantity");
            Column7.Header   = "Total Rents";
            Column7.Binding  = new Binding("TotalRents");
            Column8.Header   = "Price";
            Column8.Binding  = new Binding("Price");
            Column9.Header   = "Bicycle Color";
            Column9.Binding  = new Binding("Color");
            Column9.Header   = "Last Date Booked";
            Column9.Binding  = new Binding("LastUpdatedAt");
            Column10.Header  = "Created By";
            Column10.Binding = new Binding("CreatedBy");

            TBIkeUtility.TranslateRecordStatusDescription(new List <string> {
                "BicycleStatus"
            }, ref ResultTable);
            dataGrid1.ItemsSource         = ResultTable.DefaultView;
            dataGrid1.AutoGenerateColumns = false;
            dataGrid1.IsReadOnly          = true;
        }
コード例 #3
0
        public void PopulateID(string ID, string Category, string Status)
        {
            MainStatus = Status;
            TBikeDAL MyDAL = new TBikeDAL();

            if (Status == "Modification")
            {
                BTNPro.Content       = "Update";
                BtnDelete.Visibility = Visibility.Visible;
                if (Category == "Bicycle")
                {
                    LBTitle.Text = "Bicycle";
                    DataTable ResultTable = MyDAL.SelectBicycleByID(ID);
                    if (ResultTable.Rows.Count != 0)
                    {
                        if (RankID > 3)
                        {
                            CBStatus.Visibility = Visibility.Visible;
                            LBStatus.Visibility = Visibility.Visible;
                        }

                        LBID.Text    = ID;
                        TBName.Text  = Convert.ToString(ResultTable.Rows[0]["BicycleName"]).Trim();
                        TBType.Text  = Convert.ToString(ResultTable.Rows[0]["BicycleType"]).Trim();
                        TBPrice.Text = Convert.ToString(ResultTable.Rows[0]["Price"]).Trim();
                        TBColor.Text = Convert.ToString(ResultTable.Rows[0]["Color"]).Trim();
                        string BikeStatus = Convert.ToString(ResultTable.Rows[0]["BicycleStatus"]).Trim();
                        TBQuantity.Text = Convert.ToString(ResultTable.Rows[0]["Quantity"]).Trim();

                        if (BikeStatus == "A")
                        {
                            CBStatus.SelectedIndex = 0;
                            ItemStatus             = "A";
                        }
                        else if (BikeStatus == "E")
                        {
                            CBStatus.SelectedIndex = 1;
                            ItemStatus             = "E";
                        }
                        else if (BikeStatus == "N")
                        {
                            CBStatus.SelectedIndex = 2;
                            ItemStatus             = "N";
                        }
                        else if (BikeStatus == "S")
                        {
                            CBStatus.SelectedIndex = 3;
                            ItemStatus             = "S";
                        }
                        else if (BikeStatus == "R")
                        {
                            CBStatus.SelectedIndex = 4;
                            ItemStatus             = "R";
                        }
                        else if (BikeStatus == "I")
                        {
                            CBStatus.SelectedIndex = 5;
                            ItemStatus             = "I";
                        }
                        else if (BikeStatus == "M")
                        {
                            CBStatus.SelectedIndex = 6;
                            ItemStatus             = "M";
                        }
                        PopulateBikeDataTable();
                    }
                    else
                    {
                        PopWindow pop = new PopWindow(ImageType.Information, "Error", "No data Found!!!", "OK");
                        pop.ShowDialog();
                    }
                }
                else if (Category == "Snacks")
                {
                    if (RankID > 3)
                    {
                        CBSnackStatus.Visibility = Visibility.Visible;
                        LBStatus.Visibility      = Visibility.Visible;
                    }
                    LBTitle.Text = "Snacks";
                    LBColor.Text = "Quantity";
                    DataTable ResultTable = MyDAL.SelectSnackByID(ID);
                    if (ResultTable.Rows.Count != 0)
                    {
                        LBID.Text = ID;
                    }
                    TBName.Text  = Convert.ToString(ResultTable.Rows[0]["SnackName"]).Trim();
                    TBType.Text  = Convert.ToString(ResultTable.Rows[0]["SnackType"]).Trim();
                    TBPrice.Text = Convert.ToString(ResultTable.Rows[0]["Price"]).Trim();
                    TBColor.Text = Convert.ToString(ResultTable.Rows[0]["Quantity"]).Trim();

                    CBSnackStatus.SelectedIndex = ComboIndex;
                    PopulateSnackDataTable();
                }
                else
                {
                    PopWindow pop = new PopWindow(ImageType.Information, "Error", "Incorrect Category", "OK");
                    pop.ShowDialog();
                }
            }

            else if (Status == "Add")
            {
                LBTitle.Text         = Category;
                LBID.Text            = "** New **";
                BTNPro.Content       = "Add";
                BtnDelete.Visibility = Visibility.Hidden;
                if (Category == "Snacks")
                {
                    LBColor.Text = "Quantity";
                    PopulateSnackDataTable();
                }
                else if (Category == "Bicycle")
                {
                    PopulateBikeDataTable();
                }
            }
        }
コード例 #4
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();
            }
        }
コード例 #5
0
        private void BTNRent_Click(object sender, RoutedEventArgs e)
        {
            TBikeDAL MyDAL = new TBikeDAL();

            try
            {
                TimeSpan duration = TPEnd.SelectedTime.Value - TPStart.SelectedTime.Value;
                if (CBBike.SelectedIndex != -1)
                {
                    DataTable ResultTable = MyDAL.ShowBookingTableByCustomer(LBCustomer.Text.Trim(), "A");
                    string    Bike        = Convert.ToString(ResultTable.Rows[0]["BicycleID"]);
                    string    BikeName    = Convert.ToString(ResultTable.Rows[0]["BicycleName"]);
                    string    customer    = Convert.ToString(ResultTable.Rows[0]["CurrentRenter"]);
                    DateTime  bookTime    = Convert.ToDateTime(ResultTable.Rows[0]["BookingDate"]);
                    string    BookingID   = Convert.ToString(ResultTable.Rows[0]["BookingID"]).Trim();
                    //double Deposit = Convert.ToDouble(ResultTable.Rows[0]["BookingDeposit"]);
                    double Price = Convert.ToDouble(ResultTable.Rows[0]["Price"]);

                    //This is for booked rents
                    if (TPStart.SelectedTime < bookTime.TimeOfDay)
                    {
                        PopWindow pop = new PopWindow(ImageType.Error, "Sorry", "Can't rent time that is before booking time", "Okay");
                        pop.ShowDialog();
                    }
                    else
                    {
                        TimeSpan CheckTime = new TimeSpan(08, 00, 00);
                        TimeSpan endTime   = new TimeSpan(20, 00, 00);

                        if (TPEnd.SelectedTime < CheckTime || TPEnd.SelectedTime > endTime)
                        {
                            PopWindow pop = new PopWindow(ImageType.Error, "Error", "Please rent in working hours about 8am to 8pm", "Okay");
                            pop.ShowDialog();
                        }
                        else
                        {
                            if (TPEnd.SelectedTime - TPStart.SelectedTime <= new TimeSpan(0, 30, 0))
                            {
                                PopWindow pop = new PopWindow(ImageType.Warning, "Too less time", "Please rent At least 30mins", "Okay");
                                pop.ShowDialog();
                            }
                            else
                            {
                                //if bicycle status is Renting, dont rent bike
                                if (Convert.ToString(ResultTable.Rows[0]["BicycleStatus"]) == "R")
                                {
                                    PopWindow pop = new PopWindow(ImageType.Warning, "Sorry", "This Bike has been rented By, " + customer.Trim(), "Okay");
                                    pop.ShowDialog();
                                }
                                //if able to rent start process add
                                else
                                {
                                    double TotalPrice = (((double)duration.TotalHours) * Price);
                                    TotalPrice = System.Math.Round(TotalPrice, 2);


                                    ConfirmWindow confirm = new ConfirmWindow(ImageType.Question, "Confirm?", "Bicycle " + BikeName + ", for Renter " + LBCustomer.Text + ", Duration is " + duration + " Hours, " + " Total Price: RM" + TotalPrice, "Yes, Rent Out", "No, Don't Rent");
                                    confirm.ShowDialog();
                                    if (SnackPanel.Visibility == Visibility.Visible)
                                    {
                                        DataTable ResultTableSnack = MyDAL.SelectSnackBySnackID(CBSnack.SelectedValue.ToString().Trim());
                                        int       Sorter           = Convert.ToInt32(ResultTableSnack.Rows[0]["Quantity"]);
                                        double    price            = Convert.ToDouble(ResultTableSnack.Rows[0]["Price"]) * Convert.ToInt32(TBQuantity.Text);
                                        string    Snack            = Convert.ToString(ResultTableSnack.Rows[0]["SnackName"]).Trim();
                                        confirm = new ConfirmWindow(ImageType.Question, "Confirm?", "Snack: " + Snack + " , Total Price: " + price, "Confirm", "No, Don't Confirm");
                                        confirm.ShowDialog();
                                        if (Sorter >= Convert.ToInt32(TBQuantity.Text) && confirm.Confirmed)
                                        {
                                            MyDAL.AddSnackSales(CBSnack.SelectedValue.ToString().Trim(), Convert.ToInt32(TBQuantity.Text), LBCustomer.Text.Trim(), price, TLUsername.Text.Trim(), BookingID);
                                        }
                                        else if (confirm.Confirmed == false)
                                        {
                                            confirm.Confirmed = false;
                                        }
                                        else
                                        {
                                            PopWindow poper = new PopWindow(ImageType.Warning, "Can't Sale!!", "Item lack of stock, please Restock", "OK");
                                            poper.ShowDialog();
                                            confirm.Confirmed = false;
                                        }
                                    }
                                    //MessageBox.Show("Rented For " + LBCustomer.Text + " Duration is " + Convert.ToString(duration.Hours).Trim() + " Hours","Question",MessageBoxButton.YesNo,MessageBoxImage.Information);
                                    if (confirm.Confirmed)
                                    {
                                        MyDAL.UpdateBikeStatus(Bike, LBCustomer.Text.Trim(), "R", "", null, null, TLUsername.Text);
                                        MyDAL.UpdateBookingDate(Convert.ToDateTime(LBBookingDate.Text), Bike, LBCustomer.Text.Trim(), TotalPrice, "R", TLUsername.Text.Trim(), TPStart.SelectedTime, TPEnd.SelectedTime, TBRemarks.Text);
                                        PopWindow pop = new PopWindow(ImageType.Information, "Success rent", "Bicycle " + BikeName + ", for Renter " + LBCustomer.Text + ", Duration is " + duration + " Hours, " + " Total Price: RM" + TotalPrice + " ,has been Rented", "OK");
                                        CBBike.SelectedIndex = 0;
                                        stack1.Visibility    = Visibility.Hidden;
                                        TPStart.Visibility   = Visibility.Hidden;
                                        TPEnd.Visibility     = Visibility.Hidden;
                                    }
                                    else
                                    {
                                        PopWindow pop = new PopWindow(ImageType.Warning, "Cancel", "Rented Canceled by " + TLUsername.Text, "Okay");
                                        pop.ShowDialog();
                                    }
                                }
                            }
                        }
                    }
                }
                // This is for adding new rent
                else if (TPStart.SelectedTime < DateTime.Now.TimeOfDay)
                {
                    PopWindow pop = new PopWindow(ImageType.Warning, "Sorry", "Can't rent time that is before the current time", "Okay");
                    pop.ShowDialog();
                }
                //Must select a bicycle inorder to proceed next step...
                else if (CBBicycle.SelectedIndex != -1)
                {
                    TimeSpan CheckTime = new TimeSpan(08, 00, 00);
                    TimeSpan endTime   = new TimeSpan(20, 00, 00);

                    if (stack1.Visibility != Visibility.Hidden)
                    {
                        if (TPEnd.SelectedTime < CheckTime || TPEnd.SelectedTime > endTime)
                        {
                            PopWindow pop = new PopWindow(ImageType.Warning, "Error", "Please rent in working hours about 8am to 8pm", "Okay");
                            pop.ShowDialog();
                        }
                        else
                        {
                            if (TPEnd.SelectedTime - TPStart.SelectedTime <= new TimeSpan(0, 30, 0))
                            {
                                PopWindow pop = new PopWindow(ImageType.Warning, "Error", "Please rent At least 30mins", "Okay");
                                pop.ShowDialog();
                            }
                            else
                            {
                                DataTable ResultTable = MyDAL.SelectBicycleByID(CBBicycle.SelectedValue.ToString().Trim());
                                string    Bike        = Convert.ToString(ResultTable.Rows[0]["BicycleID"]);
                                string    BikeName    = Convert.ToString(ResultTable.Rows[0]["BicycleName"]);
                                string    customer    = TBCustomer.Text;

                                //double Deposit = Convert.ToDouble(ResultTable.Rows[0]["BookingDeposit"]);
                                double Price = Convert.ToDouble(ResultTable.Rows[0]["Price"]);

                                if (Convert.ToString(ResultTable.Rows[0]["BicycleStatus"]) == "R")
                                {
                                    PopWindow pop = new PopWindow(ImageType.Warning, "Sorry", "This Bike has been rented By, " + customer.Trim(), "Okay");
                                    pop.ShowDialog();
                                }
                                //if able to rent start process add
                                else
                                {
                                    double TotalPrice = (((double)duration.TotalHours) * Price);
                                    TotalPrice = System.Math.Round(TotalPrice, 2);

                                    ConfirmWindow con = new ConfirmWindow(ImageType.Question, "Confirm", "Bicycle " + BikeName + ", for Renter " + LBCustomer.Text + ", Duration is " + duration + " Hours, " + " Total Price: RM" + TotalPrice, "Yes, Rent", "No, Don't");
                                    con.ShowDialog();
                                    if (SnackPanel.Visibility == Visibility.Visible)
                                    {
                                        DataTable ResultTableSnack = MyDAL.SelectSnackBySnackID(CBSnack.SelectedValue.ToString().Trim());
                                        int       Sorter           = Convert.ToInt32(ResultTableSnack.Rows[0]["Quantity"]);
                                        double    price            = Convert.ToDouble(ResultTableSnack.Rows[0]["Price"]) * Convert.ToInt32(TBQuantity.Text);
                                        string    Snack            = Convert.ToString(ResultTableSnack.Rows[0]["SnackName"]).Trim();
                                        con = new ConfirmWindow(ImageType.Question, "Confirm?", "Snack: " + Snack + " , Total Price: " + price, "Confirm", "No, Don't Confirm");
                                        con.ShowDialog();
                                        if (Sorter >= Convert.ToInt32(TBQuantity.Text) && con.Confirmed)
                                        {
                                            MyDAL.AddSnackSales(CBSnack.SelectedValue.ToString().Trim(), Convert.ToInt32(TBQuantity.Text), LBCustomer.Text.Trim(), price, TLUsername.Text.Trim(), "");
                                        }
                                        else if (con.Confirmed == false)
                                        {
                                            con.Confirmed = false;
                                        }
                                        else
                                        {
                                            PopWindow poper = new PopWindow(ImageType.Warning, "Can't Sale!!", "Item lack of stock, please Restock", "OK");
                                            poper.ShowDialog();
                                            con.Confirmed = false;
                                        }
                                    }
                                    //MessageBox.Show("Rented For " + LBCustomer.Text + " Duration is " + Convert.ToString(duration.Hours).Trim() + " Hours","Question",MessageBoxButton.YesNo,MessageBoxImage.Information);
                                    if (con.Confirmed)
                                    {
                                        MyDAL.AddBookingTime(DateTime.Now.Date, Bike, "R", LBCustomer.Text.Trim(), TotalPrice, TLUsername.Text.Trim(), TPStart.SelectedTime, TPEnd.SelectedTime, TBRemarks.Text);

                                        PopWindow pop = new PopWindow(ImageType.Information, "Complete", "Rented Out by " + TLUsername.Text, "Okay");
                                        pop.ShowDialog();
                                        TBCustomer.Text         = "";
                                        CBBicycle.SelectedIndex = 0;
                                        stack1.Visibility       = Visibility.Hidden;
                                        TPStart.Visibility      = Visibility.Hidden;
                                        TPEnd.Visibility        = Visibility.Hidden;
                                    }
                                    else
                                    {
                                        PopWindow pop = new PopWindow(ImageType.Warning, "Cancel", "Rented Canceled by " + TLUsername.Text, "Okay");
                                        pop.ShowDialog();
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        PopWindow pop = new PopWindow(ImageType.Warning, "Sorry", "Please Click next to proceed rental", "Ok");
                        pop.ShowDialog();
                    }
                }
                BindComboBox(CBBike);
            }
            catch (Exception ex)
            {
                PopWindow pop = new PopWindow(ImageType.Information, "Error", ex.Message, "I will Fix this");
                pop.ShowDialog();
            }
        }