// ------------------------------------------------------------------- // BUTTONS ----------------------------------------------------------- // ------------------------------------------------------------------- private void Save_btn_Click(object sender, EventArgs e) { // get categories fields info int category_id = categoriesStrInt[category_comboBox.SelectedItem.ToString()]; int subcategory_id = subcategory_comboBox.SelectedItem.ToString().Equals(this.none) || subcategory_comboBox.SelectedItem.ToString().Equals("") ? -1 : categoriesStrInt[subcategory_comboBox.SelectedItem.ToString()]; // get amount string amt = amount_textBox.ForeColor == Color.Black ? amount_textBox.Text.Substring(1) : ""; if (amt.Equals("")) { ErrorMessenger.EmptyField("Amount"); return; } double amount = DB_API.UnMoneyfy(amount_textBox.Text); // get date DateTime date = dateTimePicker.Value; // get notes and location string notes = notes_textBox.ForeColor == Color.Black ? notes_textBox.Text : ""; string location = location_textBox.ForeColor == Color.Black ? location_textBox.Text : ""; // get transaction type int transaction_type_id = -1; transaction_type_id = DB_API.SelectTransactionTypeIdByName(type_comboBox.SelectedItem.ToString()); // get wallet string from_wallet_name = wallet_comboBox.SelectedItem.ToString(); string to_wallet_name = wallet2_comboBox.SelectedItem.ToString(); int from_wallet_id = -1; int to_wallet_id = -1; var rdr = DB_API.SelectWalletByName(account_id, from_wallet_name); while (rdr.Read()) { from_wallet_id = (int)rdr[DB_API.WalletEnt.wallet_id.ToString()]; break; } rdr = DB_API.SelectWalletByName(account_id, to_wallet_name); while (rdr.Read()) { to_wallet_id = (int)rdr[DB_API.WalletEnt.wallet_id.ToString()]; break; } // before inserting change amount sign if it is an expense // insert new transaction int cat_id = subcategory_id != -1 ? subcategory_id : category_id; DB_API.InsertTransaction(account_id, cat_id, from_wallet_id, to_wallet_id, transaction_type_id, amount, date, location, notes); // update transactions listBox PopulateTransactionsListView(); }