public NewDrinkScreen() { allDrinkButtons = new List<ImageButton>(); buttonIdToIconId = new Dictionary<int, int>(); newDrink = new DrinkItem(); volume = 0.5; alcoholByVolume = 0.5; }
public DrinkItem GetItem(int id) { var t = new DrinkItem(); lock (locker) { connection = new SqliteConnection("Data Source=" + path); connection.Open(); using (var command = connection.CreateCommand()) { // "CREATE TABLE [Items] (_id INTEGER PRIMARY KEY ASC, Name NTEXT, // About NTEXT, Volume REAL, AlcoholByVolume REAL, IconNumber INTEGER);" command.CommandText = "SELECT [_id], [Name], [About], [Volume], [AlcoholByVolume], [IconNumber] from [Items] WHERE [_id] = ?"; command.Parameters.Add(new SqliteParameter(DbType.Int32) { Value = id }); var r = command.ExecuteReader(); while (r.Read()) { t = FromReader(r); break; } } connection.Close(); } return t; }
public static int SaveDrink(DrinkItem item) { return DrinkItemRepositoryADO.SaveDrink(item); }
public static int SaveDrink(DrinkItem item) { return me.db.SaveItem(item); }
DrinkItem FromReader(SqliteDataReader r) { var t = new DrinkItem(); t.ID = Convert.ToInt32(r["_id"]); t.Name = r["Name"].ToString(); t.AlcoholByVolume = Convert.ToDouble(r["AlcoholByVolume"]); t.Volume = Convert.ToDouble(r["Volume"]); t.IconId = Convert.ToInt32(r["IconNumber"]); t.About = r["About"].ToString(); return t; }
public int SaveItem(DrinkItem item) { int r; lock (locker) { if (item.ID != 0) { connection = new SqliteConnection("Data Source=" + path); connection.Open(); using (var command = connection.CreateCommand()) { // SELECT [_id], [Name], [About], [Volume], [AlcoholByVolume], [IconNumber] command.CommandText = "UPDATE [Items] SET [Name] = ?, [About] = ?, [Volume] = ?, [AlcoholByVolume] = ?, [IconNumber] = ? WHERE [_id] = ?;"; command.Parameters.Add(new SqliteParameter(DbType.String) { Value = item.Name }); command.Parameters.Add(new SqliteParameter(DbType.String) { Value = item.About }); command.Parameters.Add(new SqliteParameter(DbType.Double) { Value = item.Volume }); command.Parameters.Add(new SqliteParameter(DbType.Double) { Value = item.AlcoholByVolume }); command.Parameters.Add(new SqliteParameter(DbType.Int32) { Value = item.IconId }); r = command.ExecuteNonQuery(); } connection.Close(); return r; } else { connection = new SqliteConnection("Data Source=" + path); connection.Open(); using (var command = connection.CreateCommand()) { command.CommandText = "INSERT INTO [Items] ( [Name], [About], [Volume], [AlcoholByVolume], [IconNumber]) VALUES (? ,?, ?, ?, ?)"; command.Parameters.Add(new SqliteParameter(DbType.String) { Value = item.Name }); command.Parameters.Add(new SqliteParameter(DbType.String) { Value = item.About }); command.Parameters.Add(new SqliteParameter(DbType.Double) { Value = item.Volume }); command.Parameters.Add(new SqliteParameter(DbType.Double) { Value = item.AlcoholByVolume }); command.Parameters.Add(new SqliteParameter(DbType.Int32) { Value = item.IconId }); r = command.ExecuteNonQuery(); } connection.Close(); return r; } } }