public ActionResult GetSchedularInfo(int id) { SchdularInfo info = null; try { StringBuilder sb = new StringBuilder(); sb.Append(" SELECT schedule_id, name, enabled,freq_type, freq_interval,freq_subday_type, "); sb.Append(" freq_subday_interval, freq_relative_interval, freq_recurrence_factor, active_start_date, "); sb.Append(" active_end_date, active_start_time, active_end_time "); sb.Append($" FROM sysschedules WHERE schedule_id = {id} "); using (SqlConnection con = new SqlConnection(strConString)) { con.Open(); SqlCommand cmd = new SqlCommand(sb.ToString(), con); SqlDataReader dr = cmd.ExecuteReader(); if (dr != null) { dr.Read(); info = new SchdularInfo(); info.schedule_id = Convert.ToInt32(dr["schedule_id"]); info.name = Convert.ToString(dr["name"]); info.enabled = Convert.ToInt32(dr["enabled"]); info.freq_type = Convert.ToInt32(dr["freq_type"]); info.freq_interval = Convert.ToInt32(dr["freq_interval"]); info.freq_subday_type = Convert.ToInt32(dr["freq_subday_type"]); info.freq_subday_interval = Convert.ToInt32(dr["freq_subday_interval"]); info.freq_relative_interval = Convert.ToInt32(dr["freq_relative_interval"]); info.freq_recurrence_factor = Convert.ToInt32(dr["freq_recurrence_factor"]); info.active_start_date = Convert.ToInt32(dr["active_start_date"]); info.active_end_date = Convert.ToInt32(dr["active_end_date"]); info.active_start_time = Convert.ToInt32(dr["active_start_time"]); info.active_end_time = Convert.ToInt32(dr["active_end_time"]); } dr.Close(); } return(Json(new { isSuccess = true, info }, JsonRequestBehavior.AllowGet)); } catch (Exception) { return(Json(new { isSuccess = false, info }, JsonRequestBehavior.AllowGet)); } }
public ActionResult UpdateSchedular(SchdularInfo schdularInfo) { try { StringBuilder sb = new StringBuilder(); //sb.Append(" USE msdb GO "); sb.Append(" EXEC dbo.sp_update_schedule "); sb.Append("@schedule_id = 11 "); sb.Append($", @enabled = {schdularInfo.enabled} "); sb.Append($", @freq_type = {schdularInfo.freq_type} "); sb.Append($", @freq_interval = {schdularInfo.freq_interval}"); sb.Append($", @freq_subday_type = {schdularInfo.freq_subday_type}"); sb.Append($", @freq_subday_interval = {schdularInfo.freq_subday_interval}"); sb.Append($", @freq_relative_interval = {schdularInfo.freq_relative_interval} "); sb.Append($", @freq_recurrence_factor = {schdularInfo.freq_recurrence_factor} "); sb.Append($", @active_start_date = {schdularInfo.active_start_date} "); sb.Append($", @active_end_date = {schdularInfo.active_end_date} "); sb.Append($", @active_start_time = {schdularInfo.active_start_time} "); sb.Append($", @active_end_time = {schdularInfo.active_end_time} "); using (SqlConnection con = new SqlConnection(strConString)) { con.Open(); SqlCommand cmd = new SqlCommand(sb.ToString(), con); cmd.ExecuteNonQuery(); } return(Json(true, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(false, JsonRequestBehavior.AllowGet)); } }