I write a Datepicker
in wpf c#. Its let the selected day always of the end of the Month and I need that my Application check if the day is Saturday
so its return the selectedday-2
and if it is Sunday
than day-1
but this weekend function it doesn't work. I didn't see where is the Error
Code:
public partial class MainWindow : Window
{
public void weekend(DatePicker dp1, DateTime d_temp)
{
if (d_temp.DayOfWeek.Equals("Sunday"))
{
dp1.SelectedDate = new DateTime(d_temp.Year, d_temp.Month, d_temp.Day-2);
}
if (d_temp.DayOfWeek.Equals("Saturday"))
{
dp1.SelectedDate = new DateTime(d_temp.Year, d_temp.Month, d_temp.Day-1);
}
}
public MainWindow()
{
InitializeComponent();
DateTime d_temp = new DateTime(System.DateTime.Now.Year, System.DateTime.Now.Month, System.DateTime.Now.Day);
if (d_temp.Month == 2 )
{
dp1.SelectedDate = new DateTime(d_temp.Year, d_temp.Month, 28);
}
if (d_temp.Month >= 1 && d_temp.Month <= 7)
{
if (d_temp.Month % 2 == 0)
{
dp1.SelectedDate = new DateTime(d_temp.Year, d_temp.Month, 30);
weekend(dp1, d_temp);
}
else
{
dp1.SelectedDate = new DateTime(d_temp.Year, d_temp.Month, 31);
weekend(dp1, d_temp);
}
}
if (d_temp.Month > 7)
{
if (d_temp.Month % 2 == 0)
{
dp1.SelectedDate = new DateTime(d_temp.Year, d_temp.Month, 31);
weekend(dp1, d_temp);
}
else
{
dp1.SelectedDate = new DateTime(d_temp.Year, d_temp.Month, 30);
weekend(dp1, d_temp);
}
}
}
private void Button_Click(object sender, RoutedEventArgs e)
{
dp1.SelectedDate = System.DateTime.Now;
}
}