private void ShowShiftItemOnRow(DataGridViewRow row, ShiftItem item)
 {
     row.Tag = item;
     row.Cells["colStartTime"].Value = item.StartTime.ToString();
     row.Cells["colEndTime"].Value = item.NextDay ? "第二天 " + item.EndTime.ToString() : item.EndTime.ToString();
     row.Cells["colLogAtStart"].Value = item.LogAtStart ? "是" : "否";
     row.Cells["colLogAtEnd"].Value = item.LogAtEnd ? "是" : "否";
     row.Cells["colBeforeStartTime"].Value =(int) item.BeforeStartTime;
     row.Cells["colAfterEndTime"].Value = (int)item.AfterEndTime;
     row.Cells["colAllowLateTime"].Value = (int)item.AllowLateTime;
     row.Cells["colAllowLeaveEarlyTime"].Value = (int)item.AllowLeaveEarlyTime;
     row.Cells["colDuration"].Value = (int)item.Duration;
 }
 private  void ItemShowing(ShiftItem shift)
 {
     txtStartHour.Value = shift.StartTime.Hour;
     txtStartMinute.Value = shift.StartTime.Minute;
     chkNextDay.Checked = shift.NextDay;
     txtEndHour.Value = shift.EndTime.Hour;
     txtEndMinute.Value = shift.EndTime.Minute;
     chkLogAtStart.Checked = shift.LogAtStart;
     chkLogAtEnd.Checked = shift.LogAtEnd;
     txtAllowLateTime.Value = shift.AllowLateTime;
     txtAllowLeaveEarlyTime.Value = shift.AllowLeaveEarlyTime;
     txtBeforeStartTime.Value = shift.BeforeStartTime;
     txtAfterEndTime.Value = shift.AfterEndTime;
     txtShiftTime.Value = shift.Duration;
 }
 private ShiftItem GetItemFromInput()
 {
     ShiftItem shift = ShiftItem as ShiftItem;
     if (shift == null) shift = new ShiftItem();
     shift.StartTime = new MyTime((int)txtStartHour.Value, (int)txtStartMinute.Value, 0);
     shift.NextDay = chkNextDay.Checked;
     shift.EndTime = new MyTime((int)txtEndHour.Value, (int)txtEndMinute.Value, 0);
     shift.LogAtStart = chkLogAtStart.Checked;
     shift.LogAtEnd = chkLogAtEnd.Checked;
     shift.AllowLateTime = txtAllowLateTime.Value;
     shift.AllowLeaveEarlyTime = txtAllowLeaveEarlyTime.Value;
     shift.BeforeStartTime = txtBeforeStartTime.Value;
     shift.AfterEndTime = txtAfterEndTime.Value;
     shift.Duration = txtShiftTime.Value;
     return shift;
 }
 private void AddShiftItemToGridView(ShiftItem item)
 {
     bool exists = false;
     foreach (DataGridViewRow row in this.dataGridView1.Rows)
     {
         ShiftItem si = row.Tag as ShiftItem;
         if (si.ID == item.ID)
         {
             ShowShiftItemOnRow(row, item);
             exists = true;
             break;
         }
     }
     if (!exists)
     {
         int row = dataGridView1.Rows.Add();
         ShowShiftItemOnRow(dataGridView1.Rows[row], item);
     }
 }
 private void btnOk_Click(object sender, EventArgs e)
 {
     if (CheckInput())
     {
         ShiftItem = GetItemFromInput();
         this.DialogResult = DialogResult.OK;
     }
 }