//スタッフ列の設定 private void StaffSet() { var index = 0; foreach (KeyValuePair <string, string> kvp in m_staffList) { dataGridView1.Rows[index].Visible = true; dataGridView1.Rows[index].Cells["StaffCode"].Value = kvp.Key; dataGridView1.Rows[index].Cells["Staff"].Value = kvp.Value; dataGridView1.Rows[index].Cells["No"].Value = index + 1; //stafshift読み込み DB.m_staff_shift staff_shift = DB.m_staff_shift.getSingle2(l_store, kvp.Key, l_calenderdata); if (staff_shift != null) { dataGridView1.Rows[index].Cells["WorkClass"].Value = staff_shift.work_class; dataGridView1.Rows[index].Cells["StartTime"].Value = staff_shift.start_time.ToString(@"hh\:mm"); dataGridView1.Rows[index].Cells["EndTime"].Value = staff_shift.end_time.ToString(@"hh\:mm"); } else { dataGridView1.Rows[index].Cells["WorkClass"].Value = "0"; dataGridView1.Rows[index].Cells["StartTime"].Value = const_startdate; dataGridView1.Rows[index].Cells["EndTime"].Value = const_enddate; } index++; } //空白行表を削除 // for (var i = index; index < 24; index++) // { //dataGridView1.Rows[index].Visible = false; //dataGridView1.Rows.RemoveAt(22); // } }
//初期化 private void SetDisp(DB.m_staff_shift ss) { //年表示 t_year.Text = (string)monthCalendar1.SelectionStart.Year.ToString("0000") + "年"; //月・日・曜日表示 t_days.Text = (string)monthCalendar1.SelectionStart.Month.ToString("0") + "月" + monthCalendar1.SelectionStart.Day.ToString("0") + "日(" + monthCalendar1.SelectionStart.Date.ToString("dddd") + ")"; if (ss != null) { //開始時刻 t_start_time.Text = ss.start_time.ToString(@"hh\:mm"); //終了時刻 t_end_time.Text = ss.end_time.ToString(@"hh\:mm"); //就業区分 t_syugyoukubun.SelectedIndex = int.Parse(ss.work_class); } else { //開始時刻 t_start_time.Text = ""; //終了時刻 t_end_time.Text = ""; //就業区分 t_syugyoukubun.SelectedIndex = -1; } if (d_staff.Items.Count == 0) { b_regist.Enabled = false; } else { b_regist.Enabled = true; } mod.reset(); }
private void b_regist_Click(object sender, EventArgs e) { chk.clear(); chk.addControl(t_start_time); chk.addControl(t_end_time); chk.addControl(t_syugyoukubun); chk.addControl(d_staff); if (chk.check("W00000", chk.checkControlImportant)) { return; } chk.clear(); chk.addControl(t_start_time); chk.addControl(t_end_time); if (chk.check("W00003", chk.checkTextboxFormat, @"^([0-9]|[0-1][0-9]|[2][0-3]):[0-5][0-9]$", "00:00")) { return; } var ss = GetStaff_Shift(); if (ss == null) { ss = new DB.m_staff_shift(); ss.store_code = DB.m_store.getSingleName(d_tenpo.SelectedItem.ToString()).store_code; ss.staff_code = DB.m_staff.getSingleName(ss.store_code, d_staff.SelectedItem.ToString()).staff_code; ss.work_day = monthCalendar1.SelectionStart; } ss.start_time = TimeSpan.Parse(t_start_time.Text); ss.end_time = TimeSpan.Parse(t_end_time.Text); ss.work_class = t_syugyoukubun.SelectedIndex.ToString(); ss.Command(); Utile.Message.showMessageOK("I11001"); mod.reset(); }
private void btnRegister_Click(object sender, EventArgs e) { chk.clear(); //必須入力チェック(スタッフが選択時、他の項目がブランクの場合はエラー) // 必須チェック chk.addControl(co_store); if (chk.check("W00000", chk.checkControlImportant)) { return; } for (var i = 0; i < dataGridView1.Rows.Count; i++) { if (dataGridView1.Rows[i].Cells["Staff"].Value == null || dataGridView1.Rows[i].Cells["Staff"].Value.ToString() == "") { break; } if (dataGridView1.Rows[i].Cells["StartTime"].Value == null || dataGridView1.Rows[i].Cells["EndTime"].Value == null || dataGridView1.Rows[i].Cells["WorkClass"].Value == null) { dataGridView1.Rows[i].Selected = true; Utile.Message.showMessageOK("E11005"); return; } } //フォーマットチェック(日付: HH: MM) HH:0~23MM:0~59 for (var i = 0; i < dataGridView1.Rows.Count; i++) { if (dataGridView1.Rows[i].Cells["Staff"].Value == null || dataGridView1.Rows[i].Cells["Staff"].Value.ToString() == "") { break; } if (!System.Text.RegularExpressions.Regex.IsMatch( dataGridView1.Rows[i].Cells["StartTime"].Value.ToString(), @"\A[0-2][0-9]:[0-5][0-9]\z")) { dataGridView1.Rows[i].Selected = true; var msg = Utile.Message.message["W00003"].Replace("@フォーマット", dataGridView1.Rows[i].Cells["StartTime"].Value.ToString()); Utile.Message.showMessageOK("W00003", msg); return; } if (!System.Text.RegularExpressions.Regex.IsMatch( dataGridView1.Rows[i].Cells["EndTime"].Value.ToString(), @"\A[0-2][0-9]:[0-5][0-9]\z")) { dataGridView1.Rows[i].Selected = true; var msg = Utile.Message.message["W00003"].Replace("@フォーマット", dataGridView1.Rows[i].Cells["EndTime"].Value.ToString()); Utile.Message.showMessageOK("W00003", msg); return; } } //開始時間 < 終了時間をチェック for (var i = 0; i < dataGridView1.Rows.Count; i++) { if (dataGridView1.Rows[i].Cells["Staff"].Value == null || dataGridView1.Rows[i].Cells["Staff"].Value.ToString() == "") { break; } if (dataGridView1.Rows[i].Cells["WorkClass"].Value.ToString() == "2") { break; } var StartTime = int.Parse(dataGridView1.Rows[i].Cells["StartTime"].Value.ToString().Substring(0, 2) + dataGridView1.Rows[i].Cells["StartTime"].Value.ToString().Substring(3, 2)); var EndTime = int.Parse(dataGridView1.Rows[i].Cells["EndTime"].Value.ToString().Substring(0, 2) + dataGridView1.Rows[i].Cells["EndTime"].Value.ToString().Substring(3, 2)); if (dataGridView1.Rows[i].Cells[1].Value == null) { break; } if (StartTime > 2359) { dataGridView1.Rows[i].Selected = true; Utile.Message.showMessageOK("E11003"); return; } if (EndTime > 2359) { dataGridView1.Rows[i].Selected = true; Utile.Message.showMessageOK("E11003"); return; } if (StartTime >= EndTime) { dataGridView1.Rows[i].Selected = true; Utile.Message.showMessageOK("E11002"); return; } } //DB処理 using (var dbc = new DB.DBConnect()) { dbc.npg.Open(); using (var transaction = dbc.npg.BeginTransaction()) { try { //削除処理 var staff_shift = dbc.m_staff_shift; //var delete_data = dbc.m_staff_shift.Where(x => x.work_day == l_calenderdata && x.store_code==l_store).Select(x=>x.work_day); var delete_data = from ss in dbc.m_staff_shift where ss.work_day == l_calenderdata & ss.store_code == l_store select ss; foreach (var data in delete_data) { dbc.m_staff_shift.Remove(data); } dbc.SaveChanges(); //登録処理 for (var i = 0; i < dataGridView1.Rows.Count; i++) { if (dataGridView1.Rows[i].Cells["Staff"].Value == null || dataGridView1.Rows[i].Cells["Staff"].Value.ToString() == "") { break; } DB.m_staff_shift staff_Shift = new DB.m_staff_shift(); var l_staff_code = dataGridView1.Rows[i].Cells["StaffCode"].Value.ToString(); var register_data = staff_shift.FirstOrDefault(x => x.work_day == l_calenderdata && x.store_code == l_store && x.staff_code == l_staff_code); if (register_data == null) { staff_Shift.work_day = l_calenderdata; staff_Shift.store_code = l_store; staff_Shift.staff_code = l_staff_code; staff_Shift.start_time = TimeSpan.Parse(dataGridView1.Rows[i].Cells["StartTime"].Value.ToString()); staff_Shift.end_time = TimeSpan.Parse(dataGridView1.Rows[i].Cells["EndTime"].Value.ToString()); staff_Shift.registration_date = DateTime.Now.Date; staff_Shift.registration_staff = MainForm.session_m_staff.staff_name; staff_Shift.update_date = DateTime.Now.Date; staff_Shift.work_class = dataGridView1.Rows[i].Cells["WorkClass"].Value.ToString(); staff_Shift.update_staff = MainForm.session_m_staff.staff_name; staff_Shift.delete_flag = "0"; dbc.m_staff_shift.Add(staff_Shift); dbc.SaveChanges(); } else { Utile.Message.showMessageOK("E11004"); transaction.Rollback(); return; } } transaction.Commit(); } catch (SqlCeException) { Utile.Message.showMessageOK("E11006"); transaction.Rollback(); } } } //ひとつ前の画面に戻る SelfViewing = false; pageParent.PageRefresh(); MainForm.backPage(this); }