Pebble – Reloj basico

#include <pebble.h>

static Window *s_main_window;

static TextLayer *s_time_layer;

static void update_time() {
//Obtien una estructura de tiempo
time_t temp = time(NULL);
struct tm *tick_time = localtime(&temp);

//Crea una variable para manejar la hora
static char buffer[] = “00:00”;

//Escribe la hora y minuto actual en la variable
if(clock_is_24h_style() == true) {
//Usa el formato de 24 horas
strftime(buffer, sizeof(“00:00”), “%H:%M”, tick_time);
} else {
//Usa el formato de 12 horas
strftime(buffer, sizeof(“00:00”), “%I:%M”, tick_time);
}

//Muestra la hora en el TextLayer
text_layer_set_text(s_time_layer, buffer);
}

static void tick_handler(struct tm *tick_time, TimeUnits units_changed) {
update_time();
}

static void main_window_load(Window *window) {
//Crea el TextLayer para mostrar la hora
s_time_layer = text_layer_create(GRect(0, 55, 144, 50));
text_layer_set_background_color(s_time_layer, GColorClear);
text_layer_set_text_color(s_time_layer, GColorBlack);
text_layer_set_text(s_time_layer, “00:00”);
text_layer_set_font(s_time_layer, fonts_get_system_font(FONT_KEY_BITHAM_42_BOLD));
text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter);

//Agrega el TextLayer a la ventana principal
layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_time_layer));
}

static void main_window_unload(Window *window) {
//Elimina el TextLayer
text_layer_destroy(s_time_layer);
}

static void init() {
//Crea la ventana y le asigna un puntero
s_main_window = window_create();

//Configura el manejador para los elementos de la ventana
window_set_window_handlers(s_main_window, (WindowHandlers) {
.load = main_window_load,
.unload = main_window_unload
});

//Muestra la ventana con las animaciones activas
window_stack_push(s_main_window, true);

//Registra el servicio del TickTimerService
tick_timer_service_subscribe(MINUTE_UNIT, tick_handler);

//Muestra la hora al iniciar la ventana
update_time();
}

static void deinit() {
//Elimina la ventana
window_destroy(s_main_window);
}

int main(void) {
init();
app_event_loop();
deinit();
}

SQLServer – Como atrapar un error en un Stored Procedure

CREATE PROCEDURE [NombreStoredProcedure]
AS
SET NOCOUNT ON;
BEGIN TRY

  –Querys

END TRY
BEGIN CATCH
  DECLARE @ErrorMessage NVARCHAR(4000);
  DECLARE @ErrorSeverity INT;
  DECLARE @ErrorState INT;
  SELECT @ErrorMessage = ERROR_MESSAGE(),
    @ErrorSeverity = ERROR_SEVERITY(),
    @ErrorState = ERROR_STATE();
  RAISERROR (@ErrorMessage, @ErrorSeverity, @ErrorState);
END CATCH
GO

Probado en: SQLServer 2008 R2