private void btnSave_Click(object sender, EventArgs e) { try { DateTime dateTimeStart = pickerStartDate.Value.Date.AddHours(pickerStartTime.Value.Hour).AddMinutes(pickerStartTime.Value.Minute); DateTime dateTimeEnd = pickerEndDate.Value.Date.AddHours(pickerEndTime.Value.Hour).AddMinutes(pickerEndTime.Value.Minute); if (checkValid(dateTimeStart, dateTimeEnd)) { AndonModel andon; if (_isAdd) { string sql = string.Format("exec spCheckAndonIsCreatedByTime @dateTimeStart = '{0}', @dateTimeEnd = '{1}'", dateTimeStart.ToString("yyyy-MM-dd HH:mm"), dateTimeEnd.ToString("yyyy-MM-dd HH:mm")); int check = TextUtils.ToInt(TextUtils.ExcuteScalar(sql)); if (check > 0) { MessageBox.Show(dateTimeStart.ToString("yyyy/MM/dd HH:mm") + " - " + dateTimeEnd.ToString("yyyy/MM/dd HH:mm") + " exist a another shift ", "Notice", MessageBoxButtons.OK); return; } andon = new AndonModel(); } else { int ID = Convert.ToInt32(grvData.GetRowCellValue(grvData.FocusedRowHandle, "ID").ToString()); string sql = string.Format("exec spCheckAndonIsUpdatedByTime @AndonID = {0}, @dateTimeStart = '{1}', @dateTimeEnd = '{2}'", ID, dateTimeStart.ToString("yyyy-MM-dd HH:mm"), dateTimeEnd.ToString("yyyy-MM-dd HH:mm")); int check = TextUtils.ToInt(TextUtils.ExcuteScalar(sql)); if (check > 0) { MessageBox.Show(dateTimeStart.ToString("yyyy/MM/dd HH:mm") + " - " + dateTimeEnd.ToString("yyyy/MM/dd HH:mm") + " had a another shift ", "Notice", MessageBoxButtons.OK); return; } andon = AndonBO.Instance.FindByPK(ID) as AndonModel; } DataRowView shiftRow = cbxShiftType.SelectedItem as DataRowView; TimeSpan timeSpan = dateTimeEnd - dateTimeStart; int totalSeconds = TextUtils.ToInt(timeSpan.TotalSeconds); andon.ShiftStartTime = dateTimeStart; andon.ShiftEndTime = dateTimeEnd; andon.TotalSeconds = totalSeconds; andon.Takt = TextUtils.ToInt(txtTakt.Text); andon.QtyPlanDay = TextUtils.ToInt(txtPlanDay.Text); andon.ShiftID = TextUtils.ToInt(shiftRow.Row["ID"]); if (_isAdd) { AndonBO.Instance.Insert(andon); LoadData(); MessageBox.Show("Add a shift successfully!", TextUtils.Caption, MessageBoxButtons.OK); } else { AndonBO.Instance.Update(andon); LoadData(); MessageBox.Show("Edit a shift successfully!", TextUtils.Caption, MessageBoxButtons.OK); } } } catch (Exception ex) { MessageBox.Show(ex.Message, TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void frmServer_Load(object sender, EventArgs e) { _NotUseCD = new StatusColorCDModel(); //Load trạng thái ban đầu trong file trạng thái dạng text _StatusColorCDModel = new StatusColorCDModel(); //Load Andon từ file setting dạng text _AndonModel = new AndonModel(); btnSend.Enabled = false; buffer = new byte[BUFFER_SIZE]; OpenPort(3); btnStart_Click(null, null); }
private void btnSave_Click(object sender, EventArgs e) { try { textBox1.Focus(); DateTime[] dateTimes = loadDateTime(pickerStartDate.Value, pickerStartTime.Value, pickerEndTime.Value, pickerStartBreak1.Value, pickerEndBreak1.Value, pickerStartBreak2.Value, pickerEndBreak2.Value, pickerStartBreak3.Value, pickerEndBreak3.Value, pickerStartBreak4.Value, pickerEndBreak4.Value); if (checkValid(dateTimes[0], dateTimes[1], dateTimes[2], dateTimes[3], dateTimes[4], dateTimes[5], dateTimes[6], dateTimes[7], dateTimes[8], dateTimes[9])) { AndonModel andon = new AndonModel(); if (!_isAdd) { // Check trong khoảng thời gian xem đã có ca nào được tạo chưa trừ ca đang chọn int ID = Convert.ToInt32(grvData.GetRowCellValue(grvData.FocusedRowHandle, "ID").ToString()); andon = AndonBO.Instance.FindByPK(ID) as AndonModel; } string sql = string.Format("exec spCheckAndonIsUpdatedByTime @AndonID = {0}, @dateTimeStart = '{1}', @dateTimeEnd = '{2}'", andon.ID, dateTimes[0].ToString("yyyy-MM-dd HH:mm"), dateTimes[1].ToString("yyyy-MM-dd HH:mm")); int check = TextUtils.ToInt(TextUtils.ExcuteScalar(sql)); if (check > 0) { MessageBox.Show(dateTimes[0].ToString("yyyy/MM/dd HH:mm") + " - " + dateTimes[1].ToString("yyyy/MM/dd HH:mm") + " had a another shift ", "Notice", MessageBoxButtons.OK); return; } //DataRowView shiftRow = cbxShiftType.SelectedItem as DataRowView; TimeSpan timeSpan = dateTimes[1] - dateTimes[0]; int totalSeconds = TextUtils.ToInt(timeSpan.TotalSeconds); andon.ShiftStartTime = dateTimes[0]; andon.ShiftEndTime = dateTimes[1]; andon.StartTimeBreak1 = dateTimes[2]; andon.EndTimeBreak1 = dateTimes[3]; andon.StartTimeBreak2 = dateTimes[4]; andon.EndTimeBreak2 = dateTimes[5]; andon.StartTimeBreak3 = dateTimes[6]; andon.EndTimeBreak3 = dateTimes[7]; andon.StartTimeBreak4 = dateTimes[8]; andon.EndTimeBreak4 = dateTimes[9]; andon.TotalSeconds = totalSeconds; andon.Takt = TextUtils.ToInt(txtTakt.Text); andon.QtyPlanDay = TextUtils.ToInt(txtPlanDay.Text); andon.ShiftID = TextUtils.ToInt(cbxShiftType.SelectedValue); if (_isAdd) { AndonBO.Instance.Insert(andon); } else { _UpdateAndon(false); AndonBO.Instance.Update(andon); _UpdateAndon(true); } LoadData(); SetInterface(false); ClearInterface(); } } catch (Exception ex) { MessageBox.Show(ex.Message, TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
protected AndonFacade(AndonModel model) : base(model) { }