Ejemplo n.º 1
0
        private void CurrencyListBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (CurrencyListBox.SelectedIndex > -1)
            {
                //Update the textboxes with the new selected item
                Currency selectedCurrency = (Currency)CurrencyListBox.SelectedItem;

                CurrencyIDTextBox.Text   = selectedCurrency.Id.ToString();
                CurrencyNameTextBox.Text = selectedCurrency.Name;
                CurrencyColourIDComboBox.SelectedValue    = selectedCurrency.ColourId.ToString();
                CountryCodeCurrencyComboBox.SelectedValue = selectedCurrency.CountryCode;
            }
        }
Ejemplo n.º 2
0
        private void SaveCurrencyButton_Click(object sender, EventArgs e)
        {
            if (CurrencyIDTextBox.Text == string.Empty)
            {
                //Create new currency entry
                Currency c = new Currency();
                c.Id   = Convert.ToInt32(CurrencyIDTextBox.Text);
                c.Name = CurrencyNameTextBox.Text;

                Currency savedCurrency = CurrenciesDAL.CurrencyManager.AddCurrency(c);
                //create successful
                MessageBox.Show("Currency Added");

                //refresh the listbox
                List <Currency> currencyList = CurrenciesDAL.CurrencyManager.GetCurrencyList();
                CurrencyListBox.DataSource = currencyList;
            }
            else
            {
                //Update existing currency entry
                int    currencyId   = int.Parse(CurrencyIDTextBox.Text);
                string currencyName = CurrencyNameTextBox.Text;
                int    colourId     = Convert.ToInt32(CurrencyColourIDComboBox.SelectedValue);
                string countryCode  = CountryCodeCurrencyComboBox.SelectedValue.ToString();

                if (CurrenciesDAL.CurrencyManager.UpdateCurrency(currencyId, currencyName, colourId, countryCode) == 1)
                {
                    MessageBox.Show("Currency Updated.");

                    //refresh the currency list
                    List <Currency> currencyList = CurrenciesDAL.CurrencyManager.GetCurrencyList();
                    CurrencyListBox.DataSource = currencyList;

                    //re-select the currency
                    //Prompt user if currency was not updated
                }
                else
                {
                    MessageBox.Show("Currency NOT updated.");
                }
            }
        }