Преобразование textBox.Text в свой класс Date - C#
Формулировка задачи:
Исправьте пожалуйста, чтобы строка из textBox1 становилась датой и исполнялись методы и прочее из класса для этой даты
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication12
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void textBox1_TextChanged(object sender, EventArgs e)
{
}
class Data
{
DateTime date1;
DateTime date;
public Data(DateTime date, DateTime date1)
{
this.date = date1;
this.date = date;
}
public TextBox textBox1;
public Data()
{
string st = textBox1.Text;
DateTime date1 = Convert.ToDateTime(st);
date = new DateTime(2009, 1, 1);
}
public DateTime PrevDay()
{
return date.Subtract(TimeSpan.FromDays(1));
}
public DateTime NextDay()
{
return date.Add(TimeSpan.FromDays(1));
}
public int DaysLeft()
{
return DateTime.DaysInMonth(date.Year, date.Month) - date.Day;
}
public DateTime Date
{
get { return date; }
set { date = value; }
}
public bool IsLeap
{
get { return DateTime.IsLeapYear(date.Year); }
}
public DateTime PrevDay1()
{
return date1.Subtract(TimeSpan.FromDays(1));
}
public DateTime NextDay1()
{
return date1.Add(TimeSpan.FromDays(1));
}
public int DaysLeft1()
{
return DateTime.DaysInMonth(date1.Year, date1.Month) - date1.Day;
}
public DateTime Date1
{
get { return date1; }
set { date1 = value; }
}
public bool IsLeap1
{
get { return DateTime.IsLeapYear(date1.Year); }
}
}
private void button1_Click(object sender, EventArgs e)
{
Data A = new Data();
Data f = new Data();
listBox1.Items.Add("дата: ");
listBox1.Items.Add(f.Date);
listBox1.Items.Add("прошлый день: ");
listBox1.Items.Add(f.PrevDay());
listBox1.Items.Add("следующий день: ");
listBox1.Items.Add(f.NextDay());
listBox1.Items.Add("дней до конца месяца: ");
listBox1.Items.Add(f.DaysLeft());
listBox1.Items.Add("високосный ли год?: ");
listBox1.Items.Add(f.IsLeap);
listBox1.Items.Add("дата: ");
listBox1.Items.Add(A.Date1);
listBox1.Items.Add("прошлый день: ");
listBox1.Items.Add(A.PrevDay1());
listBox1.Items.Add("следующий день: ");
listBox1.Items.Add(A.NextDay1());
listBox1.Items.Add("дней до конца месяца: ");
listBox1.Items.Add(A.DaysLeft1());
listBox1.Items.Add("високосный ли год?: ");
listBox1.Items.Add(A.IsLeap1);
}
}
}Решение задачи: «Преобразование textBox.Text в свой класс Date»
textual
Листинг программы
public Data()
{
string st = textBox1.Text;
DateTime date1 = Convert.ToDateTime(st);
date = new DateTime(2009, 1, 1);
}