Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
Hello Everyone, I made a form (WPF User Control) with a textbox called Tracking_Num, a comboBox called Courier_List, and a button called Tracking_Button. The idea is the user selects a courier, enters the tracking number, and hits track to launch the default browser and track the package using the provided courier and tracking #.

The button is completely not working - nothing happens when I click it not even an error.

Here is my XML code:

XML
<ComboBox x:Name="Courier_List" Margin="102,363.711,83,125.874" ItemsSource="{Binding Path=Courier_List, Mode=Default, UpdateSourceTrigger=PropertyChanged}" >
        <ComboBoxItem x:Name="UPS" Content="UPS"/>
        <ComboBoxItem x:Name="FedEX" Content="FedEX"/>
        <ComboBoxItem x:Name="UPS_SCS" Content="UPS SCS"/>
</ComboBox>

<TextBox x:Name="Tracking_Num" Margin="102,393.2,83,96.237" Text="{Binding Path=Tracking_Num, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>

<Button x:Name="Tracking_Button" Content="Track!" HorizontalAlignment="Left" Margin="284.6,393.2,0,0" VerticalAlignment="Top" Width="75" Height="24.8" Click="Tracking_Button_Click">


Here is my C# Code:
C#
private void Tracking_Button_Click(object sender, RoutedEventArgs e)
        {

            switch (Courier_List.SelectedValue.ToString())
            {
                case "UPS":

                    System.Diagnostics.Process.Start("http://wwwapps.ups.com/ietracking/tracking.cgi?loc=CA_CA^&tracknum^=" + Tracking_Num.Text.ToString());
                    break;

                case "FedEX":
                    System.Diagnostics.Process.Start("https://www.fedex.com/fedextrack/index.html?tracknumbers^=" + Tracking_Num.Text.ToString() + "^&locale=en_CA^&cntry_code=ca_english");
                    break;

                case "UPS_SCS":
                    System.Diagnostics.Process.Start("https://www.upspostsaleslogistics.com/cfw/trackOrder.do?trackNumber^=" + Tracking_Num.Text.ToString());
                    break;

                default:
                    break;
            }
        }


More Info: I am running SCSM 2012 R2 (the program this form is being imported into), my project is targeted at a 3.5 .Net framework (required by SCSM) being coded in Visual Studio 2013, and running the program while logged on under a Domain Administrator account.


UPDATE:

So I am pretty sure now that the problem is coming from the switch not recognizing a selection is being made or incorrectly passing it to selectedValue. Perhaps it is in the ToString method? What is the best way to pass the selection from comboBox to my switch?
Posted
Updated 22-Oct-14 4:35am
v3
Comments
[no name] 20-Oct-14 18:44pm    
And what exactly does "nothing happens" mean? The button click handler never fires? It fires, and then what happens? Debug your code. Incidentally, why are you converting a string to a string? Tracking_Num.Text is already a string, calling ToString on a string is redundant and makes no sense.
SirLearnAlot 21-Oct-14 11:21am    
How can I debug the code? I would love to learn how to :) In the past I have always just ran the code and debugged, but I cant do that with this specific project as its a .dll part for a form that needs to be bundled into a Management Pack and imported into SCSM before I can view any changes. Unfortunately I do not know of an easier way to run or debug the code

I presume you've stepped through it with a debugger - put a breakpoint for example in [Tracking_Button_Click] and made sure the button click is going into any of the handlers

Are you running under elevation ?

There's a discussion here that has a few things that might help - more reading sorry http://stackoverflow.com/questions/502199/how-to-open-a-web-page-from-my-application[^]
 
Share this answer
 
Comments
SirLearnAlot 21-Oct-14 11:19am    
How do I add a breakpoint? Its not like I can run the assembly after... I have to package it into an MPB and import it into SCSM before I launch my form...
Garth J Lancaster 22-Oct-14 1:30am    
usually you go down to the line you want the 'run' to stop on and push F9 - the code will stop here - since you're running under SCSM (a pertinent fact you omitted in the initial question btw, I think the procedure is different - have a look at this and see if it helps instead http://scsmlab.com/2013/04/09/debugging-custom-scsm-form-in-visual-studio/
SirLearnAlot 21-Oct-14 11:23am    
What do you mean am I running under elevation? I am running SCSM (the program this .dll form is being imported into) while logged in as an administrator, but I am not launching it by right clicking and run as administrator as its not necessary... The program itself is configured to run under a domain admin account too.
Garth J Lancaster 22-Oct-14 1:31am    
yes, I meant 'as administrator' - as per my previous reply, if you don't add pertinent information about your environment when asking a question, how are we supposed to know ?
SirLearnAlot 22-Oct-14 10:25am    
@Garth My apologies. You see, I have posted on many technical forums before and most seem to dislike the amount of information I include, so being new to codeproject I tried to dumb it down and really make my question short as possible as has been requested of me in the past.
I solved the problem. I changed selectedValue method to selectedIndex, then I changed each option to correspond with index values from 0 - 2.

Provided working code, thanks to all who tried to help!

C#
private void Tracking_Button_Click(object sender, RoutedEventArgs e)
        {
            var SelectedCourier = Courier_List.SelectedIndex;
            switch (SelectedCourier)
            {
                case 0:
                   
                    try
                    {
                        System.Diagnostics.Process.Start("http://wwwapps.ups.com/WebTracking/track?HTMLVersion=5.0&loc=en_CA&Requester=UPSHome&WBPM_lid=homepage%2Fct1.html_pnl_trk&trackNums=" + Tracking_Num.Text.ToString() + "&track.x=Track");
                    }
                    catch (Exception ex)
                    {
                       MessageBox.Show(ex.Message);
                    }
            
                    break;

                    
                case 1:
                    try
                    {
                        System.Diagnostics.Process.Start("https://www.fedex.com/fedextrack/WTRK/index.html?action=track&action=track&ascend_header=1&clienttype=dotcomreg&mi=n&cntry_code=ca_english&language=english&tracknumbers=" + Tracking_Num.Text.ToString() + "&fdx=1490");
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                    break;

                case 2:
                    try
                    {
                    System.Diagnostics.Process.Start("https://www.upspostsaleslogistics.com/cfw/trackOrder.do?trackNumber=" + Tracking_Num.Text.ToString());
                    }
                    catch (Exception ex)
                    {
                       MessageBox.Show(ex.Message);
                    }
                    break;

                //default:
                //    break;
            }
        }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900