public async Task Add(string store, Dictionary <string, string> entryList) { Main mf = Application.OpenForms["Main"] as Main; foreach (var item in entryList.ToList()) { Database.OpenConnection(); SQLiteCommand checkEntry = new SQLiteCommand( "SELECT COUNT(*) FROM Products WHERE Store = @store AND [ASIN / ISBN] = @asin_isbn", Database.Connection); checkEntry.Parameters.AddWithValue("@store", store); checkEntry.Parameters.AddWithValue("@asin_isbn", item.Key); int entryExist = Convert.ToInt32(checkEntry.ExecuteScalar()); if (entryExist > 0) { entryList.Remove(item.Key); } } if (!entryList.Any()) { metroLabel1.Text = @"Alle ausgewählten Produkte bereits in der Datenbank vorhanden."; return; } foreach (var item in entryList) { string asin_isbn = item.Key; string name = item.Value; var shortUrl = await URLShortener.Generate(Amazon.MakeReferralLink(store, asin_isbn), name, store); if (shortUrl == null) { continue; } Database.OpenConnection(); SQLiteCommand insertEntry = new SQLiteCommand( "INSERT INTO Products (Store, [ASIN / ISBN], Name, URL) Values (@store, @asin_isbn, @name, @shorturl)", Database.Connection); insertEntry.Parameters.AddWithValue("@store", store); insertEntry.Parameters.AddWithValue("@asin_isbn", asin_isbn); insertEntry.Parameters.AddWithValue("@name", name); insertEntry.Parameters.AddWithValue("@shorturl", shortUrl); insertEntry.ExecuteNonQuery(); } ProductDatabase.Display(mf.metroComboBox2.SelectedIndex == -1 ? "ALLE" : mf.metroComboBox2.Text); metroLabel1.Text = @"Alle ausgewählten Produkte Erfolgreich Hinzugefügt."; }
public static async Task Add(string[] stores, string asin_isbn) { if (Tools.ArrayIsNullOrEmpty(stores)) { MetroMessageBox.Show(mf, "Eintrag konnte nicht hinzugefügt werden!" + Environment.NewLine + "Bitte wähle mind. 1 Store für dieses Produkt aus!", "Eintrag Hinzufügen Fehlgeschlagen", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (String.IsNullOrWhiteSpace(asin_isbn)) { MetroMessageBox.Show(mf, "Eintrag konnte nicht hinzugefügt werden!" + Environment.NewLine + "Bitte gebe die Produkt ASIN / ISBN ein.!", "Eintrag Hinzufügen Fehlgeschlagen", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } foreach (string store in stores) { Database.OpenConnection(); SQLiteCommand checkEntry = new SQLiteCommand( "SELECT COUNT(*) FROM Products WHERE Store = @store AND [ASIN / ISBN] = @asin_isbn", Database.Connection); checkEntry.Parameters.AddWithValue("@store", store); checkEntry.Parameters.AddWithValue("@asin_isbn", asin_isbn); int entryExist = Convert.ToInt32(checkEntry.ExecuteScalar()); if (entryExist > 0) { continue; } AmazonItemResponse itemInfo; try { itemInfo = await Task.Run(() => AmazonApi.ItemLookup(store, asin_isbn)); if (itemInfo.Items == null) { continue; } } catch (Exception ex) { Debug.WriteLine("Abfrage Fehler: " + ex.Message, LogLevel.Debug); continue; } if (itemInfo.Items.Request.Errors != null && itemInfo.Items.Request.Errors.Any()) { foreach (var error in itemInfo.Items.Request.Errors) { Logger.Write("AmazonAPI Abfrage Fehlgeschlagen - Grund: " + error.Message, LogLevel.Debug); } continue; } string name = itemInfo.Items.Item[0].ItemAttributes.Title; var shortUrl = await URLShortener.Generate(Amazon.MakeReferralLink(store, asin_isbn), name, store); if (shortUrl == null) { continue; } Database.OpenConnection(); SQLiteCommand insertEntry = new SQLiteCommand( "INSERT INTO Products (Store, [ASIN / ISBN], Name, URL) Values (@store, @asin_isbn, @name, @shorturl)", Database.Connection); insertEntry.Parameters.AddWithValue("@store", store); insertEntry.Parameters.AddWithValue("@asin_isbn", asin_isbn); insertEntry.Parameters.AddWithValue("@name", name); insertEntry.Parameters.AddWithValue("@shorturl", shortUrl); insertEntry.ExecuteNonQuery(); } mf.metroTextBox1.Clear(); Display(mf.metroComboBox2.SelectedIndex == -1 ? "ALLE" : mf.metroComboBox2.Text); }
private async Task Import(string store, string wishlist, int status = 2) { Main mf = Application.OpenForms["Main"] as Main; string reveal = null; switch (status) { case 0: reveal = "all"; break; case 1: reveal = "purchased"; break; case 2: reveal = "unpurchased"; break; } string result = await new BetterWebClient { Timeout = 15000 }.DownloadStringTaskAsync(new Uri( "https://tools.dealreminder.de/wish-lister/wishlist.php?tld=" + Amazon.GetTld(store) + "&id=" + wishlist + "&reveal=" + reveal + "&format=json")); dynamic jsonObj = JsonConvert.DeserializeObject(result); if (jsonObj == null) { metroLabel1.Text = @"Fehler beim Abrufen der Wunschliste. Falsche ID? Nicht Öffentlicht?"; return; } Dictionary <string, string> resultList = new Dictionary <string, string>(); foreach (var obj in jsonObj) { resultList.Add(Convert.ToString(obj.ASIN), Convert.ToString(obj.name)); } foreach (var item in resultList.ToList()) { Database.OpenConnection(); SQLiteCommand checkEntry = new SQLiteCommand( "SELECT COUNT(*) FROM Products WHERE Store = @store AND [ASIN / ISBN] = @asin_isbn", Database.Connection); checkEntry.Parameters.AddWithValue("@store", store); checkEntry.Parameters.AddWithValue("@asin_isbn", item.Key); int entryExist = Convert.ToInt32(checkEntry.ExecuteScalar()); if (entryExist > 0) { resultList.Remove(item.Key); } } if (!resultList.Any()) { metroLabel1.Text = @"Alle Produkte dieser Wunschliste bereits in der Datenbank vorhanden."; return; } foreach (var item in resultList) { string asin_isbn = item.Key; string name = item.Value; var shortUrl = await URLShortener.Generate(Amazon.MakeReferralLink(store, asin_isbn), name, store); if (shortUrl == null) { continue; } Database.OpenConnection(); SQLiteCommand insertEntry = new SQLiteCommand( "INSERT INTO Products (Store, [ASIN / ISBN], Name, URL) Values (@store, @asin_isbn, @name, @shorturl)", Database.Connection); insertEntry.Parameters.AddWithValue("@store", store); insertEntry.Parameters.AddWithValue("@asin_isbn", asin_isbn); insertEntry.Parameters.AddWithValue("@name", name); insertEntry.Parameters.AddWithValue("@shorturl", shortUrl); insertEntry.ExecuteNonQuery(); } ProductDatabase.Display(mf.metroComboBox2.SelectedIndex == -1 ? "ALLE" : mf.metroComboBox2.Text); this.Close(); }
public static async Task DoRemindWhenPossible(string productid) { Database.OpenConnection(); var getReminderEntrys = new SQLiteCommand("SELECT * FROM Reminders INNER JOIN Products ON Products.ID = Reminders.ProductID WHERE Reminders.ProductID = @productid AND (Reminders.[Erinnerung Gesendet] IS NULL OR Reminders.[Erinnerung Gesendet] < @datetime)", Database.Connection); getReminderEntrys.Parameters.AddWithValue("@productid", productid); getReminderEntrys.Parameters.AddWithValue("@datetime", DateTime.Now.AddMinutes(-Settings.Get <int>("RemindResendAfterMinutes")).ToString("yyyy-MM-dd HH:mm:ss")); using (SQLiteDataReader remind = getReminderEntrys.ExecuteReader()) { List <string> remindsToSend = new List <string>(); while (remind.Read()) { Logger.Write("Erinnerungen gefunden für ProductID: " + productid + " mit dem Erinnerungspreis: " + remind["Preis"], LogLevel.Debug); List <string> conditions = new List <string>(); Convert.ToString(remind["Zustand"]).TrimEnd().Split(',') .ToList() .ForEach(item => { if (String.IsNullOrWhiteSpace(Convert.ToString(remind["Preis: " + item])) || Convert.ToDecimal(remind["Preis: " + item]) > Convert.ToDecimal(remind["Preis"])) { return; } remindsToSend.Add(item + ": " + Convert.ToString(remind["Preis: " + item])); conditions.Add(item); Logger.Write("Treffer zur Erinnerung hinzugefügt: " + item + ": " + Convert.ToString(remind["Preis: " + item]), LogLevel.Debug); }); if (remindsToSend.Any()) { /* Erstellt einen neuen Warenkorb * var catInfo = AmazonApi.CreateCart("DE", "B00YUIM2J0"); * if (catInfo?.Cart.PurchaseURL != null) * { * Debug.WriteLine(catInfo?.Cart.PurchaseURL); * } */ string shortUrl = Settings.Get <bool>("ShowOnlyDealConditions") ? await URLShortener.Generate(Amazon.MakeReferralLink(Convert.ToString(remind["Store"]), Convert.ToString(remind["ASIN / ISBN"]), conditions)) : null; shortUrl = shortUrl ?? Convert.ToString(remind["URL"]); string notificationText = remind["Name"] + "\n" + "Store: " + remind["Store"] + " - ASIN/ISBN: " + remind["ASIN / ISBN"] + "\n\n" + "Erinnerungs Preis: " + remind["Preis"] + "\n\n" + "Aktuelle Amazon Preise:\n"; remindsToSend.ForEach(i => notificationText += i + "\n"); notificationText += "\nLink: " + shortUrl; if (!String.IsNullOrWhiteSpace(Convert.ToString(remind["Telegram"]))) { await TelegramApi.SendMessage(Convert.ToString(remind["Telegram"]), notificationText); } if (!String.IsNullOrWhiteSpace(Convert.ToString(remind["Email"]))) { await Mail.NotificationSend(Convert.ToString(remind["Email"]), notificationText, Convert.ToString(remind["Name"])); } Database.OpenConnection(); SQLiteCommand updateRemind = new SQLiteCommand( "UPDATE Reminders SET [Erinnerung Gesendet] = @lastsend WHERE ID = @id", Database.Connection); updateRemind.Parameters.AddWithValue("@id", remind["ID"]); updateRemind.Parameters.AddWithValue("@lastsend", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); updateRemind.ExecuteNonQuery(); Display(); } } } }