Exemplo n.º 1
0
        //------------------------------------------------------------------------------------
        //add payment rate
        private void button2_Click(object sender, EventArgs e)
        {
            if (textBoxRateConversion.Text != "" && textBoxAmountPaid.Text != "" &&
                comboBoxCurrency.Text != "" && comboBoxPayMethod.Text != "" && comboBoxOriginalCurr.Text != "")
            {
                if (Convert.ToDecimal(textBoxAmountPaid.Text) < 0)
                {
                    MessageBox.Show("You cannot type negative values!");
                }
                else
                {
                    try
                    {
                        ratesAdded = true;
                        rateCounter++;
                        rate               = new PaymentRate();
                        rate.RateNumber    = rateCounter;
                        rate.BookingNumber = booking.BookingNumber;
                        if (checkBoxContraRate.Checked == true)
                        {
                            decimal contra_rate = -1 * Convert.ToDecimal(textBoxAmountPaid.Text);
                            rate.AmountPaid = contra_rate;
                        }
                        else
                        {
                            rate.AmountPaid = Convert.ToDecimal(textBoxAmountPaid.Text);
                        }
                        rate.Currency         = comboBoxCurrency.Text;
                        rate.date             = dbUtil.FormatDate(dateTimePicker1.Value);
                        rate.PaymentMethod    = comboBoxPayMethod.Text;
                        rate.ConversionValue  = Convert.ToDecimal(textBoxRateConversion.Text);
                        rate.RateNote         = textBoxRateNote.Text;
                        rate.OriginalCurrency = comboBoxOriginalCurr.Text;
                        rate.VersionCode      = 1;

                        if (rate.Currency != "GBP")
                        {
                            decimal convertedValue = rate.AmountPaid / rate.ConversionValue;
                            convertedValue     = Math.Round(convertedValue, 2);
                            TotalOutstanding  -= convertedValue;
                            rate.OriginalValue = convertedValue;
                            rate.VersionCode   = 1;
                        }
                        else
                        {
                            TotalOutstanding  -= rate.AmountPaid;
                            rate.OriginalValue = rate.AmountPaid;
                        }

                        PaymentRates.Add(rate);
                        rateSynchronizerList.Add(rate);

                        object[] parameters = new object[7];
                        parameters[0] = rate.AmountPaid;
                        parameters[1] = rate.Currency;
                        parameters[2] = rate.OriginalValue;
                        parameters[3] = rate.PaymentMethod;
                        parameters[4] = rate.ConversionValue;
                        parameters[5] = dbUtil.ChangeDateToSerbianFormat(rate.date);
                        parameters[6] = rate.RateNote;

                        dataGridView2.Rows.Add(parameters);
                        this.textBoxOutstanding.Text = TotalOutstanding.ToString();

                        textBoxAmountPaid.Clear();
                        comboBoxCurrency.ResetText();
                        comboBoxPayMethod.ResetText();
                        textBoxRateConversion.Clear();
                        textBoxRateNote.Clear();

                        if (checkBoxContraRate.Checked == true)
                        {
                            checkBoxContraRate.Checked = false;
                        }
                    }
                    catch (System.Exception ex)
                    {
                        MessageBox.Show(ex.ToString());
                    }
                }
            }
            else
            {
                MessageBox.Show("You must fill all required fields!");
            }
        }