private void btnSave_Click(object sender, EventArgs e) { try { oMVotingSchedule = new Model.VotingSchedule(); if (DateTimeValidation()) { oFrmMsgBox = new Forms.frmMessageBox("THE DATE RANGE YOU HAVE SELECTED ARE INVALID OR END DATE ARE LESS THAN THE CURRENT DATE."); oFrmMsgBox.MessageType = Forms.frmMessageBox.MESSAGE_TYPE.INFO; oFrmMsgBox.ShowDialog(); LoadRecordDetails(); return; } oVotingSchedule = new DataAccess.SystemFunction(); if (oVotingSchedule.IsScheduleExists()) { oMVotingSchedule.DATE_START = dtDateFrom.Value.ToString("yyyy-MM-dd"); oMVotingSchedule.TIME_START = dtTimeFrom.Value.ToString("h:mm:ss tt"); oMVotingSchedule.DATE_END = dtDateTo.Value.ToString("yyyy-MM-dd"); oMVotingSchedule.TIME_END = dtTimeTo.Value.ToString("h:mm:ss tt"); oMVotingSchedule.STATUS = cboStatus.Text; oVotingSchedule.UpdateSchedule(oMVotingSchedule); } LoadRecordDetails(); MessageBox.Show("Record has been succesfully saved", sTitle, MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { } }
void LoadRecordDetails() { try { oVotingSchedule = new DataAccess.SystemFunction(); oMVotingSchedule = new Model.VotingSchedule(); dgDetails.Rows.Clear(); if (!oVotingSchedule.IsScheduleExists()) { oMVotingSchedule.DATE_END = DateTime.Now.ToString("yyyy-MM-dd"); oMVotingSchedule.TIME_END = DateTime.Now.ToString("h:mm:ss tt"); oMVotingSchedule.DATE_START = DateTime.Now.ToString("yyyy-MM-dd"); oMVotingSchedule.TIME_END = DateTime.Now.ToString("h:mm:ss tt"); oMVotingSchedule.STATUS = "CLOSED"; oVotingSchedule.InsertSchedule(oMVotingSchedule); } foreach (DataRow row in oVotingSchedule.GetVotingSchedule().Rows) { dgDetails.Rows.Add(row["DATE_START"].ToString().Trim(), row["TIME_START"].ToString().Trim(), row["DATE_END"].ToString().Trim(), row["TIME_END"].ToString().Trim(), row["STATUS"].ToString().Trim()); sScheduleStatus = row["STATUS"].ToString().Trim(); } if (CheckDateTime()) { oMVotingSchedule = new Model.VotingSchedule(); oMVotingSchedule.STATUS = "CLOSED"; oVotingSchedule.UpdateSchedule(oMVotingSchedule); } if (sScheduleStatus != "CLOSED") { lblStatus.ForeColor = Color.Lime; lblStatus.Text = "OPEN"; } else { lblStatus.ForeColor = Color.Red; lblStatus.Text = "CLOSED"; } } catch (Exception ex) { } }