コード例 #1
0
 public DisplayFare()
 {
     InitializeComponent();
     dtpFDateFilter.SelectedDate = DateTime.Now;
     dgFareHistory.ItemsSource   = DBGuide.RetrieveFareRecordFromDatabase().DefaultView;         //How to fill datagrid using datatable: https://stackoverflow.com/questions/20770438/how-to-bind-datatable-to-datagrid
     tbxTotalFare.Text           = string.Format("S{0:C}", DBGuide.FareHistoryTotalCollected()); //Total Fare Computed
 }
コード例 #2
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         DateTime dateFilter = dtpFDateFilter.SelectedDate.Value;
         dgFareHistory.ItemsSource = null; //How to clear datagrid https://stackoverflow.com/questions/14472894/clear-datagrid-values-in-wpf
         dgFareHistory.Items.Refresh();    //refresh Datagrid
         dgFareHistory.ItemsSource = DBGuide.RetrieveFareRecordFromDatabase(dateFilter).DefaultView;
         tbxTotalFare.Text         = string.Format("S{0:C}", DBGuide.FareHistoryTotalCollected(dateFilter));
     }
     catch (Exception ex) //catch exception error
     {
         MessageBox.Show("Please select a date");
     }
 }
コード例 #3
0
        public static void initGraph(char mode = 'N') //initializes the Graph
        {
            if (mode.Equals('N'))
            {
                mode = 'T';
            }

            mrtGraph = new Graph(size);                                //creates the Graph with size found in initStationIndex()

            foreach (Line line in Guide.MRTLine)                       //foreach loop
            {
                for (int i = 0; i < (line.StationList.Count - 1); i++) //for loop
                {
                    double weight = -1;
                    try
                    {
                        List <string> queryResult = DBGuide.QueryFareFromDatabase(line.StationList[i].StationCode[0], line.StationList[i + 1].StationCode[0]); //invoke method and store in list
                        switch (mode)
                        {
                        case 'F':     //case for fare
                            weight = double.Parse(queryResult[0]);
                            break;

                        case 'T':     //case for time
                            weight = double.Parse(queryResult[2]);
                            break;
                        }
                    }
                    catch (Exception ex)                                                                                                                             //catch exception error
                    {
                        MessageBox.Show(string.Format("Start: {0} |End: {1}\n{2}", line.StationList[i].StationCode[0], line.StationList[i + 1].StationCode[0], ex)); //SHows missing stations
                    }
                    Console.WriteLine("Weight:{0}", weight);
                    mrtGraph.addEdge(line.StationList[i].GraphIndex, line.StationList[i + 1].GraphIndex, weight); //add an edge

                    Console.WriteLine("{0}({1}) - {2}({3})", line.StationList[i].StationName, line.StationList[i].GraphIndex, line.StationList[i + 1].StationName, line.StationList[i + 1].GraphIndex);
                }
            }
        }
コード例 #4
0
 public static void initLineArray()               //initialize line array
 {
     MRT = DBGuide.RetrieveMRTDataFromDBtoList(); //store in list
     Console.WriteLine("Reading Done");
 }
コード例 #5
0
        private void btnSearch_Click(object sender, RoutedEventArgs e) //event that happens when button is clicked
        {
            string bStatCode;
            string aStatCode;

            if (radBStatName.IsChecked == true)                                                    //if Station Name radiobutton is checked
            {
                bStatCode = Guide.SearchByStationName(cmbxBStationStrChooser.Text).StationCode[0]; //Search for the input Station Code based on user input
            }
            else //else if Station Code radiobutton is checked
            {
                bStatCode = cmbxBStationStrChooser.Text;
            }

            if (radAStatName.IsChecked == true)                                                    //if Station Name radiobutton is checked
            {
                aStatCode = Guide.SearchByStationName(cmbxAStationStrChooser.Text).StationCode[0]; //search for the input Station Code based on user input
            }
            else //else if Station Code radiobutton is checked
            {
                aStatCode = cmbxAStationStrChooser.Text;
            }

            string cardFare        = "Stored Value Card Fare -- " + "$" + DBGuide.QueryFareFromDatabase(bStatCode, aStatCode)[0]; //assign value of card fare
            string ticketFare      = "Adult Standard Ticket -- " + "$" + DBGuide.QueryFareFromDatabase(bStatCode, aStatCode)[1];  //assign value of ticket fare
            string timeTaken       = "Time Taken -- " + DBGuide.QueryFareFromDatabase(bStatCode, aStatCode)[2] + " minutes";      //assign value of time taken
            bool   cardFareValue   = radCardFare.IsChecked.Value;                                                                 //check if radiobutton is checked
            bool   ticketFareValue = radTicketFare.IsChecked.Value;                                                               //check if radiobutton is checked
            bool   time            = radTime.IsChecked.Value;                                                                     //check if radiobutton is checked
            bool   fare            = radFare.IsChecked.Value;                                                                     //check if radiobutton is checked
            string output          = string.Empty;                                                                                //empty string

            if (chkAdvFeature.IsChecked.Value)                                                                                    //if checkbox for advanced feature is checked
            {
                if (time)                                                                                                         //if time is true
                {
                    output = Guide.FindPathV2(bStatCode, aStatCode, chkAdvFeature.IsChecked.Value);                               //output
                }
                else if (fare)                                                                                                    //if fare is true
                {
                    output = Guide.FindPathV2(bStatCode, aStatCode, chkAdvFeature.IsChecked.Value);                               //output
                }
                else
                {
                    output = "Error";
                }
            }
            else //else
            {
                output = Guide.FindPathV2(bStatCode, aStatCode, chkAdvFeature.IsChecked.Value); //output
            }


            DisplayResults Results = new DisplayResults();                                                     //create new instance of Results form

            if (cardFareValue)                                                                                 //if true
            {
                Results.Show();                                                                                //show Results form
                Results.txtBoxDisplay.Text = "Displaying Route : " + "\n" + output;                            //calls Guide.FindPathV2 and Displays Output in textbox in DirectionsResults window
                Results.tripDetails.Text   = "-- Fare Details and Time -- \n" + cardFare + "\n" + timeTaken;   //Fare Details and Time
                this.Hide();                                                                                   //hides current window
                DBGuide.InsertFareDataIntoHistory(bStatCode, aStatCode, 'C');                                  //Insert Query into database
            }
            else if (ticketFareValue)                                                                          //else if ticketfarevalue is true
            {
                Results.Show();                                                                                //show Results form
                Results.txtBoxDisplay.Text = "Displaying Route : " + "\n" + output;                            //calls Guide.FindPathV2 and Displays Output in textbox in DirectionsResults window
                Results.tripDetails.Text   = "-- Fare Details and Time -- \n" + ticketFare + "\n" + timeTaken; //fare details and time
                this.Hide();                                                                                   //hides current window
                DBGuide.InsertFareDataIntoHistory(bStatCode, aStatCode, 'T');                                  //Insert Query into database
            }
            else
            {
                Results.Show();                                                                                                                                                                                                   //show Results form
                Results.txtBoxDisplay.Text = "Displaying Route : " + "\n" + output;                                                                                                                                               //calls Guide.FindPathV2 and Displays Output in textbox in DirectionsResults window
                Results.tripDetails.Text   = "-- Fare Details and Time -- \n" + cardFare + "\n" + ticketFare + "\n" + timeTaken + "\nThis fare record will not be inserted into the database as Fare Type has not been selected"; //fare details and time
                this.Hide();                                                                                                                                                                                                      //hides current window
            }
        }