コード例 #1
0
        private void payAccount(object sender, EventArgs e)
        {
            try
            {
                if (Double.TryParse(payTextBox.Text, out double payment))
                {
                    SaleController saleController = new SaleController();
                    double         verifyPayment  = VerifyPayment.Verify(payment, sale);
                    if (verifyPayment < 0)
                    {
                        throw new Exception($"Ainda faltam R${Math.Abs(verifyPayment).ToString("0.00")} reais");
                    }

                    saleController.finishSale(sale, payment);

                    MessageBox.Show("Compra realizada com sucesso!");

                    if (verifyPayment > 0)
                    {
                        MessageBox.Show($"Troco de: {verifyPayment.ToString("0.00")}");
                    }

                    Close();
                }
                else
                {
                    MessageBox.Show("Por favor, insira um valor válido");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }