Form1.cs
using System;
using System.Windows.Forms;
namespace WeekOfDay
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
labelWOD.Text = "曜日"; //変更
labelWareki.Text = "和暦"; //変更
}
private void ButtonCalculate_Click(object sender, EventArgs e)
{
labelWOD.Text = "";
labelWareki.Text = "";
int year, month, day, maxDay;
TextToValue.textToValue(textBoxYear.Text, out year);
month = (int)numericUpDownMonth.Value;
day = (int)numericUpDownDay.Value;
if (year <= -1)
{
labelWOD.Text = "西暦年エラー";
}
else
{
maxDay = DateTime.DaysInMonth(year, month);
if (day > maxDay)
{
labelWOD.Text = "日数エラー";
}
else
{
labelWOD.Text = GetDayName.getDayName(year, month, day);
var strYouReki = year.ToString("0000") + "." + month.ToString() + "." + day.ToString();
labelWareki.Text = ToReki.ToWareki(strYouReki);
labelSeireki.Text = "";
}
}
}
private void ButtonYourekiGet_Click(object sender, EventArgs e)
{
/*和暦形式の日付文字列を変換する
DateTime dt;
if (DateTime.TryParse("令和1年5月1日", out dt))
Console.WriteLine(dt);
else
Console.WriteLine("表示できません");*/
string wareki,year, month, day,warekiStr;
int yearInt;
var str = "西暦取得に失敗しました";TextToValue.textToValue(textBoxWarekiNen.Text, out yearInt);
if (yearInt == -1)
labelSeireki.Text = str;
else
{
year = yearInt.ToString();
wareki = comboBoxWareki.Text;
month = ((int)numericUpDownWarekiMonth.Value).ToString();
day = ((int)numericUpDownWarekiDay.Value).ToString();
warekiStr = wareki + year + "," + month + "," + day;
DateTime date = new DateTime();
if (DateTime.TryParse(warekiStr, out date))
{
labelSeireki.Text = date.ToString("yyyy-MM-dd");
labelWOD.Text = GetDayName.getDayName(date.Year,date.Month,date.Day);
labelWareki.Text = "";
}
else
labelSeireki.Text = str;
}
}
}
}