Ребята вот задача :
Написать программу, которая по веденной дате определяет день недели. Результат вывести в текстовое поле.
Вроде все просто, но мне как нубу новичку, это очень сложно. Я не могу понять как мне на виндоус форме все это сделать, то есть я вписываю допустим 20.07.2012 и он должен мне выбить что это Пятница. но вот как эти данные достать из календаря ?
Заранее спасибо )
Другие языки программирования и технологии
Задача по C#
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
namespace ToDefineDayOfWeek
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.button1.Enabled=false;
this.button2.Enabled=false;
this.число. Tag=false;
this.месяц. Tag=false;
this.год. Tag=false;
this.число. Validating += new
System.ComponentModel.CancelEventHandler(this.число_Validating);
this.месяц. Validating += new
System.ComponentModel.CancelEventHandler(this.месяц_Validating);
this.год. Validating += new
System.ComponentModel.CancelEventHandler(this.год_Validating);
}
public int year{ get; set; }
public int month { get; set; }
public int day { get; set; }
private void button1_Click(object sender, EventArgs e)
{
DateTime dateValue=new DateTime(
Int32.Parse(this.год. Text),
Int32.Parse(this.месяц. Text),
Int32.Parse(this.число. Text));
this.день_недели. Text=dateValue.ToString("dddd");
}
private void ввод_данных_KeyPress(object sender, KeyPressEventArgs e)
{
if ((e.KeyChar < 48 || e.KeyChar > 57) && e.KeyChar != 8)
e.Handled=true;
}
private void ValidateOK()
{
this.button1.Enabled=(
(bool)(this.число. Tag) &&
(bool)(this.месяц. Tag) &&
(bool)(this.год. Tag));
this.button2.Enabled=true;
}
private void число_Validating(object sender, CancelEventArgs e)
{
try
{
day=Int32.Parse(this.число. Text);
TextBox tb=(TextBox)sender;
if (tb.Text.Length == 0 || tb.Text.Length > 2 || day > 31)
{
tb.BackColor=Color.Red;
tb.Tag=false;
}
else
{
tb.BackColor=SystemColors.Window;
tb.Tag=true;
}
ValidateOK();
}
catch (FormatException) { ValidateOK(); }
}
private void месяц_Validating(object sender, CancelEventArgs e)
{
try
{
day=Int32.Parse(this.число. Text);
month=Int32.Parse(this.месяц. Text);
TextBox tb=(TextBox)sender;
if (tb.Text.Length == 0 || tb.Text.Length > 2
|| month == 0 || month > 12 ||
(day > 30 && month == 4) || (day > 30 && month == 6) ||
(day > 30 && month == 9) || (day > 30 && month == 11) ||
(day > 29 && month == 2))
{
tb.BackColor=Color.Red;
tb.Tag=false;
}
else
{
tb.BackColor=SystemColors.Window;
tb.Tag=true;
}
ValidateOK();
}
catch (FormatException) { ValidateOK(); }
}
private void год_Validating(object sender, CancelEventArgs e)
{
try
{
day=Int32.Parse(this.число. Text);
month=Int32.Parse(this.месяц. Text);
year= Int32.Parse(this.год. Text);
TextBox tb=(TextBox)sender;
if (tb.Text.Length == 0 || tb.Text.Length > 4 || year == 0 ||
(day == 29 && (year % 400 != 0 && year % 100 == 0)) ||
(day > 28 && month == 2 && year % 4 != 0))
{
tb.BackColor=Color.Red;
tb.Tag=false;
}
else
{
tb.BackColor=SystemColors.Window;
tb.Tag=true;
}
ValidateOK();
}
catch (FormatException) { ValidateOK(); }
}
private void textBox_TextChanged(object sender, EventArgs e)
{
TextBox tb=(TextBox)sender;
if (tb.Text.Length == 0)
{
tb.BackColor=Color.Red;
tb.Tag=false;
}
else
{
tb.BackColor=SystemColors.Window;
tb.Tag=true;
}
ValidateOK();
}
private void сброс_Click(object sender, EventArgs e)
{
this.число. Text="";
this.месяц. Text="";
this.год. Text="";
this.день_недели. Text="";
this.число. Tag=false;
this.месяц. Tag=false;
this.год. Tag= false;
this.число. BackColor=SystemColors.Window;
this.месяц. BackColor=SystemColors.Window;
this.год. BackColor=SystemColors.Window;
this.button2.Enabled=false;
}
private void clear_Click(object sender, EventArgs e)
{
if ((bool)this.число. Tag == false)
{
this.число. Text="";
this.число. BackColor=SystemColors.Window;
}
if ((bool)this.месяц. Tag == false)
{
this.месяц. Text="";
this.месяц. BackColor=SystemColors.Window;
}
if ((bool)this.год. Tag == false)
{
this.год. Text="";
this.год. BackColor=SystemColors.Window;
}
}
}
}
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
namespace ToDefineDayOfWeek
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.button1.Enabled=false;
this.button2.Enabled=false;
this.число. Tag=false;
this.месяц. Tag=false;
this.год. Tag=false;
this.число. Validating += new
System.ComponentModel.CancelEventHandler(this.число_Validating);
this.месяц. Validating += new
System.ComponentModel.CancelEventHandler(this.месяц_Validating);
this.год. Validating += new
System.ComponentModel.CancelEventHandler(this.год_Validating);
}
public int year{ get; set; }
public int month { get; set; }
public int day { get; set; }
private void button1_Click(object sender, EventArgs e)
{
DateTime dateValue=new DateTime(
Int32.Parse(this.год. Text),
Int32.Parse(this.месяц. Text),
Int32.Parse(this.число. Text));
this.день_недели. Text=dateValue.ToString("dddd");
}
private void ввод_данных_KeyPress(object sender, KeyPressEventArgs e)
{
if ((e.KeyChar < 48 || e.KeyChar > 57) && e.KeyChar != 8)
e.Handled=true;
}
private void ValidateOK()
{
this.button1.Enabled=(
(bool)(this.число. Tag) &&
(bool)(this.месяц. Tag) &&
(bool)(this.год. Tag));
this.button2.Enabled=true;
}
private void число_Validating(object sender, CancelEventArgs e)
{
try
{
day=Int32.Parse(this.число. Text);
TextBox tb=(TextBox)sender;
if (tb.Text.Length == 0 || tb.Text.Length > 2 || day > 31)
{
tb.BackColor=Color.Red;
tb.Tag=false;
}
else
{
tb.BackColor=SystemColors.Window;
tb.Tag=true;
}
ValidateOK();
}
catch (FormatException) { ValidateOK(); }
}
private void месяц_Validating(object sender, CancelEventArgs e)
{
try
{
day=Int32.Parse(this.число. Text);
month=Int32.Parse(this.месяц. Text);
TextBox tb=(TextBox)sender;
if (tb.Text.Length == 0 || tb.Text.Length > 2
|| month == 0 || month > 12 ||
(day > 30 && month == 4) || (day > 30 && month == 6) ||
(day > 30 && month == 9) || (day > 30 && month == 11) ||
(day > 29 && month == 2))
{
tb.BackColor=Color.Red;
tb.Tag=false;
}
else
{
tb.BackColor=SystemColors.Window;
tb.Tag=true;
}
ValidateOK();
}
catch (FormatException) { ValidateOK(); }
}
private void год_Validating(object sender, CancelEventArgs e)
{
try
{
day=Int32.Parse(this.число. Text);
month=Int32.Parse(this.месяц. Text);
year= Int32.Parse(this.год. Text);
TextBox tb=(TextBox)sender;
if (tb.Text.Length == 0 || tb.Text.Length > 4 || year == 0 ||
(day == 29 && (year % 400 != 0 && year % 100 == 0)) ||
(day > 28 && month == 2 && year % 4 != 0))
{
tb.BackColor=Color.Red;
tb.Tag=false;
}
else
{
tb.BackColor=SystemColors.Window;
tb.Tag=true;
}
ValidateOK();
}
catch (FormatException) { ValidateOK(); }
}
private void textBox_TextChanged(object sender, EventArgs e)
{
TextBox tb=(TextBox)sender;
if (tb.Text.Length == 0)
{
tb.BackColor=Color.Red;
tb.Tag=false;
}
else
{
tb.BackColor=SystemColors.Window;
tb.Tag=true;
}
ValidateOK();
}
private void сброс_Click(object sender, EventArgs e)
{
this.число. Text="";
this.месяц. Text="";
this.год. Text="";
this.день_недели. Text="";
this.число. Tag=false;
this.месяц. Tag=false;
this.год. Tag= false;
this.число. BackColor=SystemColors.Window;
this.месяц. BackColor=SystemColors.Window;
this.год. BackColor=SystemColors.Window;
this.button2.Enabled=false;
}
private void clear_Click(object sender, EventArgs e)
{
if ((bool)this.число. Tag == false)
{
this.число. Text="";
this.число. BackColor=SystemColors.Window;
}
if ((bool)this.месяц. Tag == false)
{
this.месяц. Text="";
this.месяц. BackColor=SystemColors.Window;
}
if ((bool)this.год. Tag == false)
{
this.год. Text="";
this.год. BackColor=SystemColors.Window;
}
}
}
}
Либо стандартными средствами с помощью DateTime либо по давно известной формуле
Azamjon Toshev
а можно чуть подробней ? я понимаю что либо MonthCalendar , либо DateTime. но у меня не малейшего представления как это сделать нету.
Похожие вопросы
- Помогите решить задачи на C#
- Помогите решить задачу на C или C++, пожалуйста.
- Помогите решить задачу по C++
- Помогите с решением задачи на C++
- Помогите решить задачи по C++
- Как решить задачу в C#
- Задача по C++
- Помогите решить задачу (Visual c++)
- Задача на C#. 7 КЛАСС
- помогите решить задачу математически. C++