[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Using Switch for displaying images

Posted on 2004-11-15
5
Medium Priority
?
346 Views
Last Modified: 2010-04-15
Hi
can anyone help with this problem, I want to display images depending on the time of year
i.e summer, winter, christmas, easter.

Does anyone know how I can set up the code so that I can achieve this.
My variables are:
StartSummerTime = Convert.ToDateTime("28/03/2004 01:00:00");
EndSummerTime = Convert.ToDateTime("31/10/2004 02:00:00");
StartWinterTime = Convert.ToDateTime("31/10/2004 02:00:01");
EndWinterTime= Convert.ToDateTime("28/03/2004 00:59:00");
ChristmasTime = Convert.ToDateTime("25/12/2004 00:00:00");
EasterTime = Convert.ToDateTime("11/04/2004 00:00:00");

Any help would be appreciated
caz
0
Comment
Question by:BeginningWebDesign
  • 2
  • 2
5 Comments
 
LVL 10

Expert Comment

by:smegghead
ID: 12589439
           DateTime TestTime;
            TestTime=new DateTime(2004,5,25); // Set this to today's date as below
            //TestTime=DateTime.Now;
            string TestString=TestTime.ToString("MMddHH");
            if (TestString.StartsWith("1225")) Console.WriteLine("X-mas");
            else if (TestString.StartsWith("0411")) Console.WriteLine("Easter");
            else if ((TestString.CompareTo("032801")>0) && (TestString.CompareTo("103102")<0)) Console.WriteLine("Summer");
            else Console.WriteLine("Winter");
            Console.ReadLine();
0
 
LVL 2

Accepted Solution

by:
dsabo earned 2000 total points
ID: 12590560
DateTime EvalTime = DateTime.Now


if(EvalTime == ChristmasTime )
{
    //chrismas
}
else if(EvalTime == EasterTime )
{
    //easter
}
else if((StartSummerTime  <= EvalTime) && (EvalTime <= EndSummerTime ))
{
     //summer
}
else if((StartWinterTime <= EvalTime) && (EvalTime <= EndWinterTime))
{
    //winter
}
0
 

Author Comment

by:BeginningWebDesign
ID: 12591179
Hi dsabo

I have got your code to work, except how do I display the images below:

<asp:Image ID="SummerScene" ImageUrl="images/summer.jpg" runat="server"/>
<asp:Image ID="SummerScene" ImageUrl="images/winter.jpg" runat="server"/>
<asp:Image ID="SummerScene" ImageUrl="images/christmas.jpg" runat="server"/>
<asp:Image ID="SummerScene" ImageUrl="images/easter.jpg" runat="server"/>


if(EvalTime == ChristmasTime )
{
    DisplayImage.Text = "What goes here";
}
else if(EvalTime == EasterTime )
{
    //easter
}
else if((StartSummerTime  <= EvalTime) && (EvalTime <= EndSummerTime ))
{
    DisplayImage.Text =  "summer";
}
else if((StartWinterTime <= EvalTime) && (EvalTime <= EndWinterTime))
{
    DisplayImage.Text = "winter";
}
}

Body text ***********************
<asp:Label id="DisplayImage" runat="server"/>

Thanks
Caz
0
 
LVL 2

Expert Comment

by:dsabo
ID: 12593424
Try using this:



if(EvalTime == ChristmasTime )
{
    SummerScene.ImgaeUrl = "images/summer.jpg";
}


I'dont have the IDE at this moment, just give it a try.
0
 
LVL 10

Expert Comment

by:smegghead
ID: 12593507
dsabo,

If it is in the middle of xmas day, your check will show as Winter.

Smg.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question