public void createEvent(Event evt) { Debug.WriteLine("MySqlConnector.createEvent"); try { conn.Open(); if (conn.State == ConnectionState.Open) { string stm = string.Format("INSERT INTO `bosch`.`events` " + "(`event_process_id`, `event_code`, `event_start`, `event_change`, `event_complete`) " + "VALUES('{0}', '{1}', '{2}', '{3}', '{4}')", process.id, evt.dbCode, evt.dbStart, evt.dbChange, evt.dbComplete); Debug.WriteLine("stm: " + stm); MySqlCommand cmd = new MySqlCommand(stm, conn); cmd.ExecuteNonQuery(); evt.id = (int)cmd.LastInsertedId; } else { mainPage.setStatus("FEJL I DATABASE FORBINDELSE - Tjek konfiguration eller tilkald support"); Debug.WriteLine("Could not connect to DB. \nConnection state: " + conn.State); } } catch (MySqlException ex) { Debug.WriteLine("Could not create event in DB. \nConnection status: " + conn.State + " \nException: " + ex.Message); mainPage.setStatus("FEJL I DATABASE FORBINDELSE - Tjek konfiguration eller tilkald support"); } finally { if (conn != null) conn.Close(); } }
public static void Save(Event @event) { Storage.SetSetting("event", Storage.Serialize(@event)); }
public void updateEvent(Event evt) { Debug.WriteLine("MySqlConnector.updateEvent"); try { conn.Open(); if (conn.State == ConnectionState.Open) { string stm = string.Format("UPDATE `bosch`.`events` " + "SET `event_change` = '{0}', `event_complete` = '{1}' " + "WHERE `events`.`event_id` = '{2}';", evt.dbChange, evt.dbComplete, evt.id); Debug.WriteLine("stm: " + stm); MySqlCommand cmd = new MySqlCommand(stm, conn); cmd.ExecuteNonQuery(); } else { mainPage.setStatus("FEJL I DATABASE FORBINDELSE - Tjek konfiguration eller tilkald support"); Debug.WriteLine("Could not connect to DB. \nConnection state: " + conn.State); } } catch (MySqlException ex) { Debug.WriteLine("Could not update event in DB. \nConnection status: " + conn.State + " \nException: " + ex.Message); mainPage.setStatus("FEJL I DATABASE FORBINDELSE - Tjek konfiguration eller tilkald support"); } finally { if (conn != null) conn.Close(); } }