/// <summary> /// セル変更時の処理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dgvCalender1_CellEndEdit(object sender, DataGridViewCellEventArgs e) { string year = cmbYearFrom.Text; string old; for (int m = 1; m < 13; m++) { if (Convert.ToInt32(tabControl1.SelectedIndex) + 1 == m) { Control[] cs = this.Controls.Find("dgvCalender" + m.ToString(), true); DataGridView dgv = (DataGridView)cs[0]; string currentDay = dgv[e.ColumnIndex, e.RowIndex - 1].Value.ToString(); string tab = String.Format("{0:D2}", Convert.ToInt32(tabControl1.SelectedIndex) + 1); string currentDate = year + tab + String.Format("{0:D2}", Convert.ToInt32(currentDay)); old = currentDate; if (dgv[e.ColumnIndex, e.RowIndex].Value != null) { string currentCellName = dgv[e.ColumnIndex, e.RowIndex].Value.ToString(); if (dgv[e.ColumnIndex, e.RowIndex].ReadOnly == false) { if (torokuList.Count != 0) { foreach (Holiday listHoliday in torokuList) { if (old.Equals(listHoliday.Date)) { if (listHoliday.status.Equals("2")) { Holiday holiday = new Holiday(currentCellName, currentDate, listHoliday.kbn, "0"); torokuList.Add(holiday); break; } else { Holiday holiday = new Holiday(currentCellName, currentDate, listHoliday.kbn, "1"); torokuList.Add(holiday); break; } } else { Holiday holiday = new Holiday(currentCellName, currentDate, "2", "1"); torokuList.Add(holiday); break; } } } else { Holiday holiday = new Holiday(currentCellName, currentDate, "2", "1"); torokuList.Add(holiday); } changeFlg = true; } } else { if (dgv[e.ColumnIndex, e.RowIndex].ReadOnly == false) { if (torokuList.Count != 0) { foreach (Holiday listHoliday in torokuList) { if (old.Equals(listHoliday.Date)) { Holiday holiday = new Holiday("", currentDate, listHoliday.kbn, "1"); torokuList.Add(holiday); break; } else { Holiday holiday = new Holiday("", currentDate, "2", "1"); torokuList.Add(holiday); break; } } } else { if (dgv[e.ColumnIndex, e.RowIndex].Value == null) { Holiday holiday = new Holiday("", currentDate, "2", "1"); torokuList.Add(holiday); } else { Holiday holiday = new Holiday("", currentDate, "2", "0"); torokuList.Add(holiday); } } changeFlg = true; } } } } }
/// <summary> /// 祝日解除ボタン /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnRelease_Click(object sender, EventArgs e) { string year = cmbYearFrom.Text; Holiday[] dateHoliday = GetHoliday(year); bool flg = true; for (int m = 1; m < 13; m++) { if (flg) { Control[] cs = this.Controls.Find("dgvCalender" + m.ToString(), true); DataGridView dgv = (DataGridView)cs[0]; foreach (DataGridViewCell cell in dgv.SelectedCells) { if (cell.RowIndex % 2 == 1) { string currentCellName = ""; string currentDay = ""; string tab = ""; string currentDate = ""; if (cell.Value != null) { currentCellName = cell.Value.ToString(); currentDay = dgv[cell.ColumnIndex, cell.RowIndex - 1].Value.ToString(); tab = String.Format("{0:D2}", Convert.ToInt32(tabControl1.SelectedIndex) + 1); currentDate = year + tab + String.Format("{0:D2}", Convert.ToInt32(currentDay)); DateTime ymd = new DateTime(Convert.ToInt32(year), m, Convert.ToInt32(currentDay)); int week = (int)ymd.DayOfWeek; //曜日をint型にキャストする。土曜なら「6」、日曜なら「0」 foreach (Holiday listHoliday in dateHoliday) { if (listHoliday.Name.Equals(cell.Value) & listHoliday.kbn.Equals("1")) { MessageBox.Show("国民の祝日は変更できません", "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error); flg = false; break; } else if (listHoliday.Name.Equals(cell.Value) & listHoliday.kbn.Equals("2")) { Holiday holiday = new Holiday(currentCellName, currentDate, "2", "2"); torokuList.Add(holiday); cell.Value = ""; cell.ReadOnly = true; if (week == 6) { dgv[cell.ColumnIndex, cell.RowIndex - 1].Style.ForeColor = Color.Blue; } else if (week == 0) { //日付部の文字色を赤色にする dgv[cell.ColumnIndex, cell.RowIndex - 1].Style.ForeColor = Color.Red; } else { dgv[cell.ColumnIndex, cell.RowIndex - 1].Style.ForeColor = Color.Black; } changeFlg = true; break; } } } else { currentDay = dgv[cell.ColumnIndex, cell.RowIndex - 1].Value.ToString(); tab = String.Format("{0:D2}", Convert.ToInt32(tabControl1.SelectedIndex) + 1); currentDate = year + tab + String.Format("{0:D2}", Convert.ToInt32(currentDay)); DateTime ymd = new DateTime(Convert.ToInt32(year), m, Convert.ToInt32(currentDay)); int week = (int)ymd.DayOfWeek; //曜日をint型にキャストする。土曜なら「6」、日曜なら「0」 Holiday holiday = new Holiday(currentCellName, currentDate, "2", "2"); torokuList.Add(holiday); cell.Value = ""; cell.ReadOnly = true; if (week == 6) { dgv[cell.ColumnIndex, cell.RowIndex - 1].Style.ForeColor = Color.Blue; } else if (week == 0) { //日付部の文字色を赤色にする dgv[cell.ColumnIndex, cell.RowIndex - 1].Style.ForeColor = Color.Red; } else { dgv[cell.ColumnIndex, cell.RowIndex - 1].Style.ForeColor = Color.Black; } changeFlg = true; } } } } } }
/// <summary> /// 祝日設定ボタン /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSet_Click(object sender, EventArgs e) { string year = cmbYearFrom.Text; Holiday[] dateHoliday = GetHoliday(year); string old; for (int m = 1; m < 13; m++) { Control[] cs = this.Controls.Find("dgvCalender" + m.ToString(), true); DataGridView dgv = (DataGridView)cs[0]; foreach (DataGridViewCell cell in dgv.SelectedCells) { if (cell.RowIndex % 2 != 1) { cell.ReadOnly = true; } else { if (dgv[cell.ColumnIndex, cell.RowIndex - 1].Style.ForeColor == Color.LightGray) { cell.ReadOnly = true; } else { cell.ReadOnly = false; //日付部の文字色を赤色にする dgv[cell.ColumnIndex, cell.RowIndex - 1].Style.ForeColor = Color.Red; changeFlg = true; string currentDay = dgv[cell.ColumnIndex, cell.RowIndex - 1].Value.ToString(); string tab = String.Format("{0:D2}", Convert.ToInt32(tabControl1.SelectedIndex) + 1); string currentDate = year + tab + String.Format("{0:D2}", Convert.ToInt32(currentDay)); old = currentDate; if (cell.Value != null) { foreach (Holiday listHoliday in dateHoliday) { if (listHoliday.Name.Equals(cell.Value) & listHoliday.kbn.Equals("1")) { MessageBox.Show("国民の祝日は変更できません", "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error); break; } } } else { if (cell.ReadOnly == false) { if (torokuList.Count != 0) { Holiday holiday; foreach (Holiday listHoliday in torokuList) { if (old.Equals(listHoliday.Date)) { holiday = new Holiday("", currentDate, listHoliday.kbn, "1"); torokuList.Add(holiday); } break; } holiday = new Holiday("", currentDate, "2", "0"); torokuList.Add(holiday); } else { Holiday holiday = new Holiday("", currentDate, "2", "0"); torokuList.Add(holiday); } changeFlg = true; } } } } } } }