/// <summary> /// Elimina dal DB l'elemento Scommessa indicato dal parametro. /// </summary> /// <param name="s">Scommessa</param> /// <returns>bool True per query eseguita, False in caso di Exception</returns> public async Task <bool> DeleteScommessa(Scommessa s) { string messageForLog = string.Empty; bool isCompleted = false; try { Database dbInstance = GetSQLiteConnection(); await dbInstance.OpenAsync(SqliteOpenMode.OpenReadWrite); string querySqlEnablePragma = " PRAGMA foreign_keys = ON "; await dbInstance.ExecuteStatementAsync(querySqlEnablePragma); string query = " DELETE FROM " + Constants.TABLE_NAME_SCOMMESSA + " WHERE " + " IdScommessa=" + s.IdScommessa + " AND " + " IdMatch='" + s.IdMatch + "'" + " AND " + " TeamCasa='" + s.TeamCasa + "'" + " AND " + " TeamFCasa='" + s.TeamFCasa + "'"; await dbInstance.ExecuteStatementAsync(query); messageForLog = "Query eseguita con successo"; isCompleted = true; } catch (Exception ex) { isCompleted = false; messageForLog = ex.Message; } finally { System.Diagnostics.Debug.WriteLine("[DATAACCESSDB - DeleteScommessa] \t" + messageForLog.ToString()); } return(isCompleted); }
public async Task <Scommessa> GetScommessa(Incontro i, Schedina s) { Scommessa scommessa = null; string messageForLog = string.Empty; try { Database dbInstance = GetSQLiteConnection(); await dbInstance.OpenAsync(SqliteOpenMode.OpenRead); string query = " SELECT * FROM " + Constants.TABLE_NAME_SCOMMESSA + " INNER JOIN " + Constants.TABLE_NAME_SCHEDINA + " ON " + Constants.TABLE_NAME_SCOMMESSA + ".IdScommessa" + " = " + Constants.TABLE_NAME_SCHEDINA + ".Id" + " WHERE " + " IdScommessa = '" + s.Id + "'" + " AND " + " TeamCasa = '" + i.TeamCasa + "'" + " AND " + " TeamFCasa = '" + i.TeamFCasa + "'" + " AND " + " Data = '" + i.Data + "'" + " AND " + " IdMatch = '" + i.IdMatch + "'" ; using (Statement statement = await dbInstance.PrepareStatementAsync(query)) { statement.EnableColumnsProperty(); System.Diagnostics.Debug.WriteLine("[DATAACCESSDB - GetScommessa] \t" + query.ToString()); while (await statement.StepAsync()) { var columns = statement.Columns; scommessa = new Scommessa { IdScommessa = int.Parse(columns["IdScommessa"]), TeamCasa = columns["TeamCasa"], TeamFCasa = columns["TeamFCasa"], Data = columns["Data"], IdMatch = columns["IdMatch"], TotalScore = columns["TotalScore"], OVER = columns["Over"], UNDER = columns["Under"], Q1 = columns["Q1"], QX = columns["Qx"], Q2 = columns["Q2"], HC = columns["Hc"], HC1 = columns["Hc1"], HC2 = columns["Hc2"], HCX = columns["Hcx"], DC1X = columns["Dc1x"], DC12 = columns["Dc12"], DCX2 = columns["Dcx2"], Home12 = columns["Home12"], Away12 = columns["Away12"] }; } messageForLog = "Query eseguita con successo"; } } catch (Exception ex) { messageForLog = ex.Message; } finally { System.Diagnostics.Debug.WriteLine("[DATAACCESSDB - GetScommessa] \t" + messageForLog + "\n"); } return(scommessa); }