private void ClearEntryButton_LostFocus(object sender, RoutedEventArgs e)
 {
     if (ClearEntryButton.Visibility == Visibility.Collapsed && ClearButton.Visibility == Visibility.Visible)
     {
         ClearButton.Focus(FocusState.Programmatic);
     }
 }
Beispiel #2
0
        /* Event Hander for Book Button
         * 1. Calculate Transaction Operations such as No. of Transactions, Bus Cost, Optional Cost and Average Revenure
         * 2. Provides Success Message after Completing of Booking
         */
        private void BookButton_Click(object sender, EventArgs e)
        {
            decimal CurrentAverage = 0.0m;
            string  StringMessage  = "";

            toolTip1.Active = false;
            toolTip1.Active = true;
            //Performing Calculations
            HighlightPanel.Location = new Point(2, BookButton.Location.Y);
            TotalTransactions      += 1;
            TotalTripCost          += CurrentTotalBusFare;
            TotalOptionalValues    += CurrentTotalOptional;
            CurrentAverage          = CurrentTotalPayableLabel / int.Parse(NoOfGuestsLabel.Text);
            AverageRevenue          = (AverageRevenue + CurrentAverage) / TotalTransactions;
            //Add-on Functionality- Changing Booking Status to Confirmed and Changing Color of Text
            BookingStatusLabel.Text      = "Confirmed";
            BookingStatusLabel.ForeColor = Color.Green;

            //Disabling Booking Details along with Book Button and Modify Button
            if (SummaryButton.Enabled != true)
            {
                SummaryButton.Enabled = true;//Enabling Summary Button after first Booking
            }
            BookButton.Enabled                                                 = ModifyBookingButton.Enabled
                                                                               = TourCostGroupBox.Visible
                                                                               = TimeDiscountPanel.Visible
                                                                               = FareTripTextLabel.Visible
                                                                               = TotalBusFareLabel.Visible
                                                                               = HotelBookingGroupBox.Visible
                                                                               = PackedLunchGroupBox.Visible
                                                                               = TotalOptionalTextLable.Visible
                                                                               = TotalOptionalCostLabel.Visible
                                                                               = SpecialDiscountPanel.Visible
                                                                               = false;


            //Dynamically creating Message to display based on user inputs
            StringMessage = "Destination Name\t:   " + LocationLabel.Text +
                            "\nDeparture Time\t:   " + TimeLabel.Text +
                            "\nNo of Guests\t:   " + NoOfGuestTextBox.Text +
                            "\n\nBus Trip Charges \t\t\t :" + "€" + CurrentTotalBusFare.ToString();

            if (Hotel1RadioButton.Checked)
            {
                StringMessage = StringMessage + "\n\nHotel Booking: \n5-Star Hotel Booking \t\t :" + HotelTotalLabel.Text;
            }
            else if (Hotel2RadioButton.Checked)
            {
                StringMessage = StringMessage + "\n\nHotel Booking: \n4-Star Hotel Booking \t\t :" + HotelTotalLabel.Text;
            }
            else if (Hotel3RadioButton.Checked)
            {
                StringMessage = StringMessage + "\n\nHotel Booking: \n3-Star Hotel Booking \t\t :" + HotelTotalLabel.Text;
            }

            if (LunchCheckBox.Checked)
            {
                StringMessage = StringMessage + "\n\nPacked Lunch Charges: \t\t :" + PackedLunchTotalLabel.Text;
            }

            StringMessage = StringMessage + "\n\n Total Tour Charges\t\t:" + "€" + CurrentTotalPayableLabel.ToString("n2");
            MessageBox.Show(StringMessage, "Booking Successful", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

            ClearButton.Focus();
            //Showing Clear Button Tooltip 'Click to take Next Booking'
            toolTip1.Show(toolTip1.GetToolTip(ClearButton), ClearButton);
        }
        private void SearchButton_Click(object sender, EventArgs e)
        {
            //Code to change the visibility of the form.
            ClearButton.Visible = true;;
            ClearButton.Focus();
            SearchDetailsListBox.Items.Clear();
            Searchpanel.Visible        = true;
            SearchListBoxPanel.Visible = true;
            //Code to create an instance of Stream reader class.
            StreamReader IntFile;

            IntFile = File.OpenText("TransactionsFile.txt");
            string line;
            //List stores the transacton details stored in File.
            List <string> list    = new List <string>();
            int           counter = 0;

            while ((line = IntFile.ReadLine()) != null)

            {
                list.Add(line);
                counter++;
            }
            IntFile.Close();
            // code which list elements are added to array.
            string[] TransactionArraySearch = list.ToArray();
            //decision construct to check TransactionId entered.
            if (TransactionIDTextBox.Text != "" && TransactionDateTextBox.Text == "")
            {
                //Local variables declaration.
                string   ID      = TransactionIDTextBox.Text;
                string[] content = new string[500];
                //123 is like delimitter for file. helps to retrive specific data.
                string result = "123";
                //Decision construct check whether array contains Transaction ID.
                if (TransactionArraySearch.Any(x => x == ID))
                {
                    //code to fetch the index of the Transaction ID presrent in Array.
                    var index = Array.IndexOf(TransactionArraySearch, ID);
                    for (int i = index; i < TransactionArraySearch.Length; i++)
                    {
                        //Decision construct to retrive specific lines.
                        if (TransactionArraySearch[i] != result)
                        {
                            //code to add the details to listbox and Content array.
                            content[i] = TransactionArraySearch[i];
                            SearchDetailsListBox.Items.Add(content[i]);
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Transaction ID is not found", "Please Enter Valid Transaction ID", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            //decison construct if date is provided.
            else if (TransactionIDTextBox.Text == "" && TransactionDateTextBox.Text != "")
            {//Local variable declaration.
                string[] TransactionArrayDuplicate = list.ToArray();
                string   Date       = TransactionDateTextBox.Text;
                string[] contentTwo = new string[500];
                string   result     = "123";
                //Code to find whether Array contains the date.
                if (TransactionArrayDuplicate.Any(x => x == Date))
                {
                    //code to fetch the index of the transactiondate.
                    var index = Array.IndexOf(TransactionArrayDuplicate, Date);
                    for (int i = index - 1; i < TransactionArrayDuplicate.Length; i++)
                    {
                        if (TransactionArrayDuplicate[i] != result)
                        {
                            //code to add the details to listbox and Content array.
                            contentTwo[i] = TransactionArrayDuplicate[i];
                            SearchDetailsListBox.Items.Add(contentTwo[i]);
                        }
                        else
                        {
                            continue;
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Transcations not found for provided date", "Please Enter Valid Date", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Please provide Date or TransactionId to search", "Please Enter Valid details ", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #4
0
        // Confirm button which send transaction details to text file.
        private void button2_Click(object sender, EventArgs e)
        {
            ClearButton.Visible  = true;
            CancelButton.Visible = false;
            // Code to shift the focus to ClearButton.
            ClearButton.Focus();
            // Code to create string builder and formatted into Text File.
            StringBuilder sb = new StringBuilder();
            //Local variable declaration section.
            int DataGridCartLength = DataGridCart.RowCount;

            for (int i = 0; i < DataGridCartLength; i++)
            {
                // code to format the string and appended from datagrid view.
                sb.AppendLine(DataGridCart[0, i].Value?.ToString() + " 0f " + DataGridCart[2, i].Value?.ToString() + " " + DataGridCart[1, i].Value?.ToString() + " " + DataGridCart[3, i].Value?.ToString());
            }
            //decision construct to write the transaction text file.
            if (MessageBox.Show(string.Format(sb.ToString() + "Total Transaction Cost is" + CURRENCY + FinalValue.ToString()), "Confirmation Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                //code which instanciates streamwriter class.
                StreamWriter OutputFile;
                //code to append the string to file.
                OutputFile = File.AppendText("TransactionsFile.txt");
                OutputFile.Close();
                // Local Variable declaration restriceted to this decision construct.
                string Temp;
                int    RandomNumber      = 0;
                int    BeerConfirmIndex  = BeerNamesListBox.SelectedIndex;
                int    BeerSizeConfirmed = BeerSubTypeListBox.SelectedIndex;
                //Code which copy the contents of original array to destination array.
                Array.Copy(TempStockArray, StockArray, TempStockArray.Length);
                //StockArray[BeerConfirmIndex, BeerSizeConfirmed] = TempStockArray[BeerConfirmIndex, BeerSizeConfirmed];
                // calling random number generation method.
                RandomNumberGenerator(ref RandomNumber);
                StreamReader InputFile;
                InputFile = File.OpenText("TransactionsFile.txt");
                while (!InputFile.EndOfStream)
                {
                    Temp = InputFile.ReadLine();
                    // To check and generate unique random number.
                    if (Temp == RandomNumber.ToString())
                    {
                        RandomNumberGenerator(ref RandomNumber);
                    }
                }
                InputFile.Close();
                //Code which appends transaction details from gridview to text file.
                StreamWriter FileOpen;
                FileOpen = File.AppendText("TransactionsFile.txt");
                FileOpen.WriteLine(RandomNumber);
                FileOpen.WriteLine(GetDateTime.ToShortDateString());
                for (int i = 0; i < DataGridCart.Rows.Count; i++)
                {
                    for (int j = 0; j < 4; j++)
                    {
                        FileOpen.WriteLine(DataGridCart[j, i].Value?.ToString());
                    }
                }
                FileOpen.WriteLine("123");
                FileOpen.Close();
            }
            // Decision construct if selected cart items will not be purchased.
            else
            {
                // code to clear the gridview cells.
                DataGridCart.ClearSelection();
                DataGridCart.Rows.Clear();
                TotalCostValueTextBox.Clear();
                QuantityValuesTextBox.Clear();
                ClearButton.Focus();
            }
        }