public static void Change(BOCron cron) { var paramsToPass = new SqlParameter[5]; string sql; paramsToPass[1] = new SqlParameter("@AdminEmailList", cron.AdminEmailList); paramsToPass[2] = new SqlParameter("@CrontabEntry", cron.CrontabEntry); paramsToPass[3] = SqlHelper.GetNullable("@LastFinished", cron.LastFinished); paramsToPass[4] = new SqlParameter("@ClassName", cron.ClassName); if (cron.JobId > 0) { paramsToPass[0] = new SqlParameter("@JobId", cron.JobId); sql = @"UPDATE [dbo].[cron_jobs] SET admin_email_list = @AdminEmailList, crontab_entry = @CrontabEntry, last_finished = @LastFinished, fully_qualified_class_name = @ClassName WHERE id = @JobId"; } else { paramsToPass[0] = new SqlParameter("@Id", DBNull.Value); paramsToPass[0].Direction = ParameterDirection.InputOutput; paramsToPass[0].DbType = DbType.Int32; sql = @"INSERT [dbo].[cron] (admin_email_list, crontab_entry, last_finished, settings, fully_qualified_class_name) VALUES (@AdminEmailList, @CrontabEntry, @LastFinished, @ClassName) WHERE id = @JobId; SET @JobId = SCOPE_IDENTITY();"; } SqlHelper.ExecuteNonQuery(DbHelper.ConnectionString, CommandType.Text, sql, paramsToPass); if (cron.JobId == 0) cron.JobId = Int32.Parse(paramsToPass[0].Value.ToString()); }
private static BOCron PopulateCron(IDataRecord reader) { var cron = new BOCron { JobId = (int)reader["id"], AdminEmailList = (string)reader["admin_email_list"], CrontabEntry = (string)reader["crontab_entry"], LastFinished = (reader["last_finished"] == DBNull.Value ? null : (DateTime?)reader["last_finished"]), ClassName = (string)reader["fully_qualified_class_name"] }; return(cron); }
public static BOCron Get(int id) { BOCron cron = null; using (SqlDataReader reader = SqlHelper.ExecuteReader(DbHelper.ConnectionString, CommandType.Text, @"SELECT id, admin_email_list, crontab_entry, last_finished, fully_qualified_class_name FROM [dbo].[cron_jobs] WHERE id=@id", new SqlParameter("@id", id))) { if (reader.Read()) { cron = PopulateCron(reader); } } return(cron); }
public static void Change(BOCron cron) { var paramsToPass = new SqlParameter[5]; string sql; paramsToPass[1] = new SqlParameter("@AdminEmailList", cron.AdminEmailList); paramsToPass[2] = new SqlParameter("@CrontabEntry", cron.CrontabEntry); paramsToPass[3] = SqlHelper.GetNullable("@LastFinished", cron.LastFinished); paramsToPass[4] = new SqlParameter("@ClassName", cron.ClassName); if (cron.JobId > 0) { paramsToPass[0] = new SqlParameter("@JobId", cron.JobId); sql = @"UPDATE [dbo].[cron_jobs] SET admin_email_list = @AdminEmailList, crontab_entry = @CrontabEntry, last_finished = @LastFinished, fully_qualified_class_name = @ClassName WHERE id = @JobId"; } else { paramsToPass[0] = new SqlParameter("@Id", DBNull.Value); paramsToPass[0].Direction = ParameterDirection.InputOutput; paramsToPass[0].DbType = DbType.Int32; sql = @"INSERT [dbo].[cron] (admin_email_list, crontab_entry, last_finished, settings, fully_qualified_class_name) VALUES (@AdminEmailList, @CrontabEntry, @LastFinished, @ClassName) WHERE id = @JobId; SET @JobId = SCOPE_IDENTITY();"; } SqlHelper.ExecuteNonQuery(DbHelper.ConnectionString, CommandType.Text, sql, paramsToPass); if (cron.JobId == 0) { cron.JobId = Int32.Parse(paramsToPass[0].Value.ToString()); } }
private static BOCron PopulateCron(IDataRecord reader) { var cron = new BOCron { JobId = (int) reader["id"], AdminEmailList = (string) reader["admin_email_list"], CrontabEntry = (string) reader["crontab_entry"], LastFinished = (reader["last_finished"] == DBNull.Value ? null : (DateTime?) reader["last_finished"]), ClassName = (string)reader["fully_qualified_class_name"] }; return cron; }