Esempio n. 1
0
        private void Save_btn_Click(object sender, EventArgs e)
        {   //apaga este comentario
            string   loan_name      = Name_textBox.ForeColor == Color.Black ? Name_textBox.Text : "";
            string   initial_amount = InitialAmount_textBox.ForeColor == Color.Black ? InitialAmount_textBox.Text : "";
            string   current_debt   = CurrentDebt_textBox.ForeColor == Color.Black ? CurrentDebt_textBox.Text : "";
            string   interest_str   = Interest_textBox.ForeColor == Color.Black ? Interest_textBox.Text : "";
            DateTime term           = DateTime.Parse(Enddate_dateTimePicker.Value.ToString());

            // verify if mandatory fields are filled
            if (loan_name.Equals("") || initial_amount.Equals("") || current_debt.Equals(""))
            {
                ErrorMessenger.EmptyField("Name, Initial Amount and Current Debt");
                return;
            }

            // process inserted values
            double init_amt = DB_API.UnMoneyfy(initial_amount);
            double cur_debt = DB_API.UnMoneyfy(current_debt);
            double interest = 0.0;

            try
            {
                if (interest_str.Equals(""))
                {
                    interest = 0.0;
                }
                else
                {
                    interest = Double.Parse(interest_str);
                }
            }
            catch
            {
                ErrorMessenger.WrongFormat("A numeric textBox");
                return;
            }

            // add loan
            try
            {
                DB_API.InsertLoan(account_id, loan_name, init_amt, cur_debt, term, interest);
            }
            catch (SqlException ex)
            {
                ErrorMessenger.Exception(ex);
                return;
            }

            // upadte listBox with new user
            PopulateLoansListView();
        }