private void btnSave_Click(object sender, EventArgs e) { try { //if (txtReason.Text.Trim() == string.Empty) //{ // Message.ShowMessage(MyMessages.MessageType.MissingInfo, "Please Enter Name."); // txtReason.Focus(); // return; //} DataTable dt = new DataTable(); if (!vOpenMode) { dt = objDAL.getRecord(string.Format(" AND (convert(datetime,Convert(varchar,HolidayDate,1)) = Convert(Datetime,(convert(varchar,convert(Datetime,'{0} 00:00:00',102),1))))", dtHolidayDate.Value.ToShortDateString())); if (dt.Rows.Count > 0) { Message.ShowMessage(MyMessages.MessageType.General, "Holiday Already Entered."); return; } } else { dt = objDAL.getRecord(string.Format(" AND (convert(datetime,Convert(varchar,HolidayDate,1)) = Convert(Datetime,(convert(varchar,convert(Datetime,'{0} 00:00:00',102),1)))) AND HolidayID<>{1}", dtHolidayDate.Value.ToShortDateString(), txtID.Text)); if (dt.Rows.Count > 0) { Message.ShowMessage(MyMessages.MessageType.General, "Holiday Already Entered."); return; } } Objects.Holidays obj = new Objects.Holidays(); obj.HolidayID = Int64.Parse(txtID.Text); obj.HolidayDate = dtHolidayDate.Value; obj.Reason = txtReason.Text.Trim(); obj.UserID = vUserID; if (!vOpenMode) { //Insert objDAL.InsertRecord(obj); } else { // UPdate objDAL.UpdateRecord(obj); } Message.ShowMessage(MyMessages.MessageType.SaveRecord); LoadGrid(); btnClear_Click(sender, e); } catch (Exception exc) { Message.ShowMessage(MyMessages.MessageType.Error, exc.Message); } }
public void InsertRecord(Objects.Holidays obj) { try { SqlCommand cmd = new SqlCommand(); cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "SP_HolidaysInsert"; cmd.Parameters.AddWithValue("@HolidayDate", obj.HolidayDate); cmd.Parameters.AddWithValue("@Reason", obj.Reason); cmd.Parameters.AddWithValue("@UserID", obj.UserID); new Database(connectionstring).ExecuteNonQueryOnly(cmd); } catch (Exception exc) { throw exc; } }