Form1.cs
using System.Windows.Forms;
namespace WeekOfDay
{
public partial class Form1 : Form
{
string str1 = "西暦年エラー";
string str2 = "和暦エラー";
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void ButtonCalculate_Click(object sender, EventArgs e)
{
WarekiTextClear();
int year, month, day, maxDay;
month = (int)numericUpDownMonth.Value;
day = (int)numericUpDownDay.Value;
if (!TextToValue.GetValue(textBoxYear.Text, out year) || year < 1)
{
textBoxWareki.Text = str1;
}
else
{
maxDay = DateTime.DaysInMonth(year, month);
if (day > maxDay)
{
textBoxWareki.Text = str2;
}
else
{
textBoxWOD1.Text = GetDayName.getDayName(year, month, day);
var strYouReki = year.ToString("0000") + "." + month.ToString() + "." + day.ToString();
textBoxWareki.Text = ToReki.ToWareki(strYouReki);
var targetDay = new DateTime(year, month, day);
textBoxDifference1.Text = DifferenceInDays.GetDifference(targetDay);
}
}
}
private void ButtonSeirekiGet_Click(object sender, EventArgs e)
{
SeirekiTextClear();
string wareki, year, month, day, warekiStr;
int yearInt;
if (!TextToValue.GetValue(textBoxWarekiNen.Text, out yearInt))
textBoxSeireki.Text = str2;
else
{
year = yearInt.ToString();
wareki = comboBoxWareki.Text;
month = ((int)numericUpDownWarekiMonth.Value).ToString();
day = ((int)numericUpDownWarekiDay.Value).ToString();
warekiStr = wareki + year + "," + month + "," + day;
DateTime targetDay = new DateTime();
if (!DateTime.TryParse(warekiStr, out targetDay))
{
textBoxSeireki.Text = str2;
}
else
{
textBoxSeireki.Text = targetDay.ToString("yyyy-MM-dd");
textBoxWOD2.Text = GetDayName.getDayName(targetDay.Year, targetDay.Month, targetDay.Day);
textBoxDifference2.Text = DifferenceInDays.GetDifference(targetDay);
}
}
}
public void WarekiTextClear()
{
textBoxWareki.Text = "";
textBoxWOD1.Text = "";
textBoxDifference1.Text = "";
}
public void SeirekiTextClear()
{
textBoxSeireki.Text = "";
textBoxWOD2.Text = "";
textBoxDifference2.Text = "";
}
}
}