Skip Navigation Links
C# Corner Home
Forum Home
Latest 50
Unanswered
Win Prizes
All Time Leaders
Jump to CategoryExpand Jump to Category
Login 
    Welcome Guest!
 Search Forum For :  
X
 Login
Please login to submit a new post, reply and edit exiting posts, see user profiles, and access more features. If you are not a registered member, Register here.
User Id / Email:
Password:  
Forgot Password | Forgot UserName
   Home » WPF » Accessing the code in One If Condition from another condition
       
Author Reply
anupama b
posted 3 posts
since Sep 08, 2010 
from

Accessing the code in One If Condition from another condition

  Posted on: 10 Feb 2012       
Hi,

I am trying to access the code in another if condition from another but unable to . could you please suggest an approach. Here is the code i am using

foreach (string arg in Environment.GetCommandLineArgs())
{
if (arg == "–Auto_BlueGrass")
{
for (int i = 0; i < 2; i++)
{
if (i==0)
{
mstrSwitch = "BluegrassCH";
AllocConsole();
Console.WriteLine("BlueGrass Chargeable Claims Job started in Auto mode - " + DateTime.Now + " ");
mblnAutomode = true;
goto AutoModePoint;
}
else if(i==1)
{
mstrSwitch = "BluegrassRP";
AllocConsole();
Console.WriteLine("BlueGrass Reporting Claims Job started in Auto mode - " + DateTime.Now + " ");
mblnAutomode = true;
goto AutoModePoint;
}
}


}



AutoModePoint: if (!IsUserAuthorized())
{
if (mblnAutomode)
{
Console.WriteLine("You do not have permissions to run this application. This application will now close." + " " + DateTime.Now);
Application.Current.Shutdown();
}
else
{
MessageBox.Show("You do not have permissions to run this application. This application will now close.", "No Access", MessageBoxButton.OK, MessageBoxImage.Stop);
Application.Current.Shutdown();
}
}
else
{
this.DataContext = this;
DefinePacificareStateCodes();
ReadApplicationSettings();
}


In the above code first i am using a for condition inside a if and foreach condition.

After execution the steps next to if(i==0) cond it has to goto the if (!IsUserAuthorized()) and execute those steps under that condition.
I tried using the goto statement but in that case it only executes if(i==0) condition but i also want if(i==1) condition to eexecute once the i is incremented in for loop which is not happening using goto statement could anyone please suggets an approach or any idea is appreciated

Aim : suppose i have a x job and x1 and x2 are sub jobs to it instead of executing x1 and x2 individually whenever i click on x first it has to complete x1 and then it should automatically start x2 and complete it.

if question is not understandable please let me know i will modify the question more ..



Vulpes
posted  5419 posts
since  Feb 28, 2011 
from 

 Re: Accessing the code in One If Condition from another condition
  Posted on: 10 Feb 2012   Accepted Answer     1  
If I've understood it correctly, I'd rewrite it like this:


foreach (string arg in Environment.GetCommandLineArgs())
{
   if (arg == "–Auto_BlueGrass")
   {
      for (int i = 0; i < 2; i++)
      {
         if (i==0)
         {
            mstrSwitch = "BluegrassCH";
            Console.WriteLine("BlueGrass Chargeable Claims Job started in Auto mode - " + DateTime.Now + " ");
         }
         else // i can only be 1
         {
            mstrSwitch = "BluegrassRP";
            Console.WriteLine("BlueGrass Reporting Claims Job started in Auto mode - " + DateTime.Now + " ");
         }

         // these next two lines are the same for both values of i
         AllocConsole();
         mblnAutomode = true;

         // now embed the AutoModePoint routine

         if (!IsUserAuthorized())
         {
            if (mblnAutomode)
            {
               Console.WriteLine("You do not have permissions to run this application. This application will now close." + " " + DateTime.Now);
            }
            else
            {
               MessageBox.Show("You do not have permissions to run this application. This application will now close.", "No Access", MessageBoxButton.OK, MessageBoxImage.Stop);
            }

           Application.Current.Shutdown();            
         }
         else
         {
            this.DataContext = this;
            DefinePacificareStateCodes();
            ReadApplicationSettings();
         }         
      } 

      break; // no point going on if required command line argument found
   }
}
       
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Team Foundation Server Hosting
 Hosted by MaximumASP  |  Found a broken link?  |  Contact Us  |  Terms & conditions  |  Privacy Policy  |  Site Map  |  Advertise with us
Current Version: 5.2011.3.12
 © 1999 - 2012  Mindcracker LLC. All Rights Reserved