private void btnAdd_Click(object sender, EventArgs e) { string strError = string.Empty; if (txtCoinName.Text == string.Empty) { MessageBox.Show("Please enter a coin name", "", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (cbxCondition.SelectedIndex == -1) { MessageBox.Show("Please select a condition", "", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (txtPrice.Text == string.Empty) { MessageBox.Show("Please enter a price", "", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (IsNotificationAlreadySetup(txtCoinName.Text)) { MessageBox.Show("That coin has already been added", "", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } MarketCapNotification notifcation = new MarketCapNotification() { CoinName = txtCoinName.Text, Condition = cbxCondition.SelectedItem.ToString(), Enabled = true, Price = txtPrice.Text }; MarketCapitalizationCall call = new MarketCapitalizationCall(); call.InsertMarketCapNotification(notifcation, ref strError); if (!string.IsNullOrEmpty(strError)) Notify.ShowMessage(this, Notify.MessageType.Error, strError); else { SettingsManager.AppSettings.MarketCapNotificationList.Add(notifcation); frmSettings settings = null; foreach (Form form in Application.OpenForms) if (form.Name == "frmSettings") settings = (frmSettings)form; settings.RefreshMarketCapNotificationsList(); this.Close(); } }
public frmEditMarketCapNotification(MarketCapNotification notification) { InitializeComponent(); if (File.Exists(Application.StartupPath + @"\images\c3.ico")) this.Icon = new Icon(Application.StartupPath + @"\images\c3.ico"); notify = notification; chkEnabled.Checked = notify.Enabled; txtCoinName.Text = notify.CoinName; txtPrice.Text = notify.Price; cbxCondition.Text = notify.Condition; }
private void btnSave_Click(object sender, EventArgs e) { string strError = string.Empty; if (txtPrice.Text == string.Empty) { MessageBox.Show("Please enter a valid price", "", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } MarketCapNotification notification = new MarketCapNotification() { CoinName = txtCoinName.Text, Price = txtPrice.Text, Condition = cbxCondition.SelectedItem.ToString(), Enabled = chkEnabled.Checked }; MarketCapitalizationCall call = new MarketCapitalizationCall(); call.UpdateMarketCapNotification(notification, ref strError); if (!string.IsNullOrEmpty(strError)) MessageBox.Show("An error occurred while trying to update that notification:" + strError, "", MessageBoxButtons.OK, MessageBoxIcon.Error); else { SettingsManager.AppSettings.MarketCapNotificationList = call.GetMarketCapNotificationList(ref strError); frmSettings settings = null; foreach (Form form in Application.OpenForms) if (form.Name == "frmSettings") settings = (frmSettings)form; settings.RefreshMarketCapNotificationsList(); if (!string.IsNullOrEmpty(strError)) MessageBox.Show("An error occurred while getting the market cap notification list.", "", MessageBoxButtons.OK, MessageBoxIcon.Error); else this.Close(); } }
public void UpdateMarketCapNotification(MarketCapNotification notification, ref string strError) { MarketCapitalizationData data = new MarketCapitalizationData(); data.UpdateMarketCapNotification(notification, ref strError); }
public void UpdateMarketCapNotification(MarketCapNotification notifcation, ref string strError) { try { using (var conn = new SQLiteConnection(ConnectionString)) using (var cmd = new SQLiteCommand("UPDATE MarketCapNotification SET Enabled = @Enabled, Price = @Price, Condition = @Condition WHERE CoinName = @CoinName", conn)) { conn.Open(); cmd.Parameters.Add(new SQLiteParameter("@Enabled", notifcation.Enabled)); cmd.Parameters.Add(new SQLiteParameter("@CoinName", notifcation.CoinName)); cmd.Parameters.Add(new SQLiteParameter("@Condition", notifcation.Condition)); cmd.Parameters.Add(new SQLiteParameter("@Price", notifcation.Price)); cmd.ExecuteNonQuery(); } } catch (Exception ex) { strError = ex.Message; } }
public MarketCapNotification InsertMarketCapNotification(MarketCapNotification notifcation, ref string strError) { MarketCapNotification newNotification = new MarketCapNotification(); try { using (var conn = new SQLiteConnection(ConnectionString)) using (var cmd = new SQLiteCommand("INSERT INTO MarketCapNotification (Enabled, CoinName, Condition, Price) VALUES (@Enabled, @CoinName, @Condition, @Price)", conn)) { conn.Open(); cmd.Parameters.Add(new SQLiteParameter("@Enabled", notifcation.Enabled)); cmd.Parameters.Add(new SQLiteParameter("@CoinName", notifcation.CoinName)); cmd.Parameters.Add(new SQLiteParameter("@Condition", notifcation.Condition)); cmd.Parameters.Add(new SQLiteParameter("@Price", notifcation.Price)); cmd.ExecuteNonQuery(); cmd.CommandText = "SELECT LAST_INSERT_ROWID();"; int ID = Convert.ToInt32(cmd.ExecuteScalar()); cmd.CommandText = "SELECT * FROM MarketCapNotification WHERE MarketCapNotificationPK = " + ID.ToString(); using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { MarketCapNotification notify = new MarketCapNotification() { MarketCapNotificationPK = reader.GetInt32(reader.GetOrdinal("MarketCapNotificationPK")), CoinName = reader.GetString(reader.GetOrdinal("CoinName")), Condition = reader.GetString(reader.GetOrdinal("Condition")), Enabled = reader.GetBoolean(reader.GetOrdinal("Enabled")), Price = reader.GetString(reader.GetOrdinal("Price")) }; newNotification = notify; } } } } catch (Exception ex) { strError = ex.Message; } return newNotification; }