Please ignore this post due to not proper format and proper instruction.
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
public partial class _Default : System.Web.UI.Page
{
List<string> ListDay = new List<string>();
List<string> ListMonth = new List<string>();
List<ShowDate> ListDate = new List<ShowDate>();
string[] dayArr = { "sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday" };
string[] monthArr = { "january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december" };
Hashtable HTWeekDay = new Hashtable();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DateTime DT = DateTime.Now;
DT = GetFirstDateOfWeek(DT);
System.Globalization.CultureInfo ci = System.Threading.Thread.CurrentThread.CurrentCulture;
object index = DateTime.Now;
string r = String.Format("ww", index);
int res = getPreviousWeekNumber(index);
//0 First day of year
res = System.Globalization.CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(
Convert.ToDateTime(index), System.Globalization.CalendarWeekRule.FirstDay, System.Globalization.DateTimeFormatInfo.CurrentInfo.FirstDayOfWeek);
res = System.Globalization.CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(
Convert.ToDateTime(index), System.Globalization.CalendarWeekRule.FirstDay, DayOfWeek.Sunday);
DateTime curMonth = Convert.ToDateTime(DateTime.Today.Year.ToString() + "-09-07");
//Calendar1.VisibleDate = curMonth;
Response.Write(getISOWeek(curMonth).ToString());
int week = ci.Calendar.GetWeekOfYear(DateTime.Now , ci.DateTimeFormat.CalendarWeekRule, ci.DateTimeFormat.FirstDayOfWeek);
//Convert.ToDateTime(index), System.Globalization.CalendarWeekRule.FirstDay, System.Globalization.DateTimeFormatInfo.CurrentInfo.FirstDayOfWeek);
HTWeekDay.Add("FirstWeekDay", "1");
HTWeekDay.Add("SecondWeekDay", "2");
HTWeekDay.Add("ThirdWeekDay", "3");
HTWeekDay.Add("FourthWeekDay", "4");
foreach (string day in dayArr)
{
ListDay.Add(day);
}
foreach (string month in monthArr)
{
ListMonth.Add(month);
}
// foreach (string weekday in weekArr)
// {
// ListWeekDay.Add(weekday);
// }
drpDay.DataSource = ListDay;
drpDay.DataBind();
drpDay.Items.Insert(0, new ListItem("ALL", "0"));
drpMonth.DataSource = ListMonth;
drpMonth.DataBind();
drpMonth.Items.Insert(0, new ListItem("ALL", "0"));
drpDay.SelectedValue = "0";
drpMonth.SelectedValue = "0";
drpWeekDay.DataSource = HTWeekDay;
drpWeekDay.DataTextField = "key";
drpWeekDay.DataValueField = "value";
drpWeekDay.DataBind();
drpWeekDay.Items.Insert(0, new ListItem("ALL", "0"));
drpWeekDay.SelectedValue = "0";
}
}
protected void btnClick_Click(object sender, EventArgs e)
{
DateTime FromDt = CalFromDt.SelectedDate;
//Response.Write((CalToDt.SelectedDate-FromDt).Days);
string day = string.Empty;
string month = string.Empty;
while ((CalToDt.SelectedDate - FromDt).Days >= 0)
{
day = FromDt.DayOfWeek.ToString().ToLower();
month = FromDt.ToString("MMMM").ToLower();
if (!drpDay.SelectedValue.Equals("0"))
{
if (!drpMonth.SelectedValue.Equals("0"))
{
if (month.Equals(drpMonth.SelectedValue) && day.Equals(drpDay.SelectedValue))
{
ShowDateBasedonsingleCriteria(FromDt);
}
}
else if (day.Equals(drpDay.SelectedValue))
{
ShowDateBasedonsingleCriteria(FromDt);
}
}
else if (!drpMonth.SelectedValue.Equals("0"))
{
if (month.Equals(drpMonth.SelectedValue))
{
ShowDateBasedonsingleCriteria(FromDt);
}
}
else if (!drpWeekDay.SelectedValue.Equals("0"))
{
int weekday = System.Globalization.CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(FromDt, CalendarWeekRule.FirstDay, System.Globalization.DateTimeFormatInfo.CurrentInfo.FirstDayOfWeek);
if (weekday == 0) { weekday = 5; }
Math.DivRem(weekday, 5, out weekday);
if (weekday.ToString().Equals(drpWeekDay.SelectedValue))
{
ShowDateBasedonsingleCriteria(FromDt);
}
}
else
{
ShowDateBasedonsingleCriteria(FromDt);
}
FromDt = FromDt.AddDays(1);
}
gv.DataSource = ListDate;
gv.DataBind();
//lblDiff.Text = (CalToDt.SelectedDate - CalFromDt.SelectedDate).ToString();
}
private void ShowDateBasedonsingleCriteria(DateTime FromDt)
{
ShowDate objshowdate = new ShowDate();
objshowdate.rownumber = 1;
objshowdate.date = FromDt.ToString("dd/MM/yyyy");
ListDate.Add(objshowdate);
}
private int getPreviousWeekNumber(Object Date)
{
DateTime dtSend;
try
{
dtSend = Convert.ToDateTime(Date);
}
catch (Exception)
{
throw new Exception("Please give Valid Date");
}
object dtLastWeek = dtSend.AddDays(-7); // Am adding -7 Days because it exactly a 7 Days back from to Day
return System.Globalization.CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(
Convert.ToDateTime(dtLastWeek), System.Globalization.CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Sunday);
}
public class ShowDate
{
public int rownumber { get; set; }
public string date { get; set; }
}
public static DateTime GetFirstDateOfWeek(DateTime dayInWeek)
{
CultureInfo defaultCultureInfo = CultureInfo.CurrentCulture;
return GetFirstDateOfWeek(dayInWeek, defaultCultureInfo);
}
public static DateTime GetFirstDateOfWeek(DateTime dayInWeek, CultureInfo cultureInfo)
{
DayOfWeek firstDay = cultureInfo.DateTimeFormat.FirstDayOfWeek;
DateTime firstDateInWeek = dayInWeek.Date;
while (firstDateInWeek.DayOfWeek != firstDay)
firstDateInWeek = firstDateInWeek.AddDays(-1);
return firstDateInWeek;
}
public int getISOWeek(DateTime day)
{
return CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(day, System.Globalization.CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
}
}
Send Push Notification using C#
5 years ago
No comments:
Post a Comment