Пример #1
0
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listBox1.SelectedIndex >= 0)
            {
                fEditMode         = true;
                cmdAddOrSave.Text = "Save";

                UnderlyingDebtor _selectedItem = manager.My_db.UnderlyingDebtors.FirstOrDefault(x => x.Id == (int)listBox1.SelectedValue);

                if (_selectedItem != null)
                {
                    txtName.Text   = _selectedItem.name;
                    txtNumber.Text = _selectedItem.number;
                }

                cmdCancel.Visible = true;
            }
            else
            {
                fEditMode         = false;
                cmdAddOrSave.Text = "Add";
                txtName.Text      = "";
                txtNumber.Text    = "";

                cmdCancel.Visible = false;
            }
        }
Пример #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (!fEditMode)
                {
                    UnderlyingDebtor _debtor = new UnderlyingDebtor();
                    _debtor.name = txtName.Text;
                    _debtor.FK_UnderlyingDebtors_Funds = manager.Selected;
                    _debtor.number    = txtNumber.Text;
                    _debtor.CountryId = int.Parse(cbCountry.SelectedValue.ToString());
                    manager.My_db.UnderlyingDebtors.Add(_debtor);
                    manager.My_db.SaveChanges();
                }
                else
                {
                    UnderlyingDebtor _selectedItem = manager.My_db.UnderlyingDebtors.FirstOrDefault(x => x.Id == (int)listBox1.SelectedValue);

                    if (_selectedItem != null)
                    {
                        _selectedItem.name      = txtName.Text;
                        _selectedItem.number    = txtNumber.Text;
                        _selectedItem.CountryId = int.Parse(cbCountry.SelectedValue.ToString());
                        manager.My_db.SaveChanges();
                    }
                }

                loadUnderlyingDebtorsData();

                cmdCancel_Click(null, null);
            }
            catch (Exception _ex)
            {
                ErrorMessage.showErrorMessage(_ex);
            }
        }