/// <summary> /// Returns what product was bought how often by the user. /// Beware! uses the "comment" column of the DB - on-product-comments are possible! /// </summary> /// <param name="user">The user</param> public async Task<List<ProductCount>> GetProductsCountForUserAsync(String user, string deviceID) { await CheckDeviceRights(deviceID, DeviceRights.READ); List<ProductCount> list = new List<ProductCount>(); MySqlDataReader reader = this.Query("SELECT *,COUNT(date) FROM `gk_accounting` WHERE user='******' GROUP BY `comment` DESC LIMIT 0,200"); while (await reader.ReadAsync()) { ProductCount pc = new ProductCount(); pc.amount = reader.GetInt32("COUNT(date)"); pc.product = reader.GetString("comment"); pc.price = reader.GetDouble("price"); list.Add(pc); } reader.Close(); this.Close(); // Check versus current list of products (getting correct pricing, only available products, etc.) List<Product> products = await this.GetFullProductsAsync(); // Compare (not very efficient at the moment) List<ProductCount> listFinal = new List<ProductCount>(); foreach (ProductCount p in list) { foreach (Product prod in products) { if (p.product == prod.product) { p.price = prod.price; listFinal.Add(p); break; } } } return listFinal; }
private async Task<List<ProductCount>> GetAccountingCountSince(string date) { MySqlDataReader reader = this.Query("SELECT comment,COUNT(comment) FROM gk_accounting WHERE gk_accounting.date > {d '"+date+"'} GROUP BY comment"); List<ProductCount> prod = new List<ProductCount>(); while (await reader.ReadAsync()) { ProductCount pro = new ProductCount(); pro.amount = reader.GetInt32("COUNT(comment)"); pro.product = reader.GetString("comment"); prod.Add(pro); } reader.Close(); this.Close(); return prod; }