Link to home
Start Free TrialLog in
Avatar of mustish1
mustish1

asked on

How to create a text box

ASP.NET MVC entity frame work 6.0

How to create a text box and ask the user to input a date? I am trying to create a calendar that spans four years (excluding weekends and holidays). The format should look like that:


Input-->Enter Start Date: 5/18/2023 (Temporary Variable)

5/15/2023 (5 spaces)5/22/2023 (Text light blue, background yellow)

15 16 17 18 19 (5 spaces) 22 23 24 25 26 (Text light green, background orange)

M T W T F (5 spaces) M T W T F (Text pink, background white)

@{

    ViewBag.Title = "Calendar";

}


<h2>Calendar</h2>


<table class="calendar">

    <tr>

        @for (int year = DateTime.Now.Year; year <= DateTime.Now.Year + 3; year++)

        {

            for (int month = 1; month <= 12; month++)

            {

                DateTime firstDayOfMonth = new DateTime(year, month, 1);

                DateTime lastDayOfMonth = firstDayOfMonth.AddMonths(1).AddDays(-1);


                if (firstDayOfMonth.DayOfWeek != DayOfWeek.Saturday && firstDayOfMonth.DayOfWeek != DayOfWeek.Sunday)

                {

                    <th colspan="@lastDayOfMonth.Day">@firstDayOfMonth.ToString("MMMM yyyy")</th>

                }

            }

        }

    </tr>

    <tr>

        @for (int year = DateTime.Now.Year; year <= DateTime.Now.Year + 3; year++)

        {

            for (int month = 1; month <= 12; month++)

            {

                DateTime firstDayOfMonth = new DateTime(year, month, 1);

                DateTime lastDayOfMonth = firstDayOfMonth.AddMonths(1).AddDays(-1);


                if (firstDayOfMonth.DayOfWeek != DayOfWeek.Saturday && firstDayOfMonth.DayOfWeek != DayOfWeek.Sunday)

                {

                    for (int day = 1; day <= lastDayOfMonth.Day; day++)

                    {

                        DateTime currentDate = new DateTime(year, month, day);


                        string textColor, backgroundColor;

                        if (currentDate.Equals(new DateTime(2023, 5, 15)) || currentDate.Equals(new DateTime(2023, 5, 22)))

                        {

                            textColor = "lightblue";

                            backgroundColor = "yellow";

                        }

                        else if (currentDate.DayOfWeek != DayOfWeek.Saturday && currentDate.DayOfWeek != DayOfWeek.Sunday)

                        {

                            textColor = "lightgreen";

                            backgroundColor = "orange";

                        }

                        else

                        {

                            textColor = "pink";

                            backgroundColor = "white";

                        }


                        <td style="color: @textColor; background-color: @backgroundColor;">@currentDate.Day</td>

                    }

                }

            }

        }

    </tr>

    <tr>

        @for (int year = DateTime.Now.Year; year <= DateTime.Now.Year + 3; year++)

        {

            for (int month = 1; month <= 12; month++)

            {

                DateTime firstDayOfMonth = new DateTime(year, month, 1);

                DateTime lastDayOfMonth = firstDayOfMonth.AddMonths(1).AddDays(-1);


                if (firstDayOfMonth.DayOfWeek != DayOfWeek.Saturday && firstDayOfMonth.DayOfWeek != DayOfWeek.Sunday)

                {

                    for (int day = 1; day <= lastDayOfMonth.Day; day++)

                    {


                    }

                }

            }

        }

</tr> 


</table>

User generated image

User generated image


ASKER CERTIFIED SOLUTION
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial