private void button1_Click(object sender, EventArgs e)
        {
            if (oneMonth.Checked || threeMonths.Checked || (otherType.Checked && otherPaymentType.Text.Length > 5))
            {
                decimal _amountPaid = 0;
                string  paymentType = otherPaymentType.Text;

                if (oneMonth.Checked)
                {
                    paymentType = "MENSALIDADE";
                }
                if (threeMonths.Checked)
                {
                    paymentType = "TRIMESTRALIDADE";
                }

                if (decimal.TryParse(amountPaid.Text, out _amountPaid))
                {
                    var receiptInfo = new ReceiptInfo(studentName.Text, _amountPaid, paymentType, paymentDate.Value.Date);

                    if (receiptInfo.Valid())
                    {
                        var fileDialog = new SaveFileDialog
                        {
                            AddExtension     = true,
                            CheckPathExists  = true,
                            DefaultExt       = "pdf",
                            Filter           = "PDF (*.pdf)|*.pdf",
                            InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
                            OverwritePrompt  = true,
                            ValidateNames    = true
                        };

                        if (fileDialog.ShowDialog() == DialogResult.OK)
                        {
                            new Receipt(receiptInfo).GenerateReceipt(fileDialog.FileName);
                            MessageBox.Show("Recibo gerado.", "Sucesso", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                            Process.Start(Path.GetDirectoryName(fileDialog.FileName));
                        }
                    }
                    else
                    {
                        Util.ShowError(receiptInfo.ErrorMesage());
                    }
                }
                else
                {
                    Util.ShowError("Valor deve ser um número.");
                }
            }
            else
            {
                Util.ShowError("Tipo de Pagamento obrigatório.");
            }
        }
示例#2
0
 public Receipt(ReceiptInfo info)
 {
     receiptInfo = info;
 }