Calculate more than one text box and display in a specific text box

2

Good morning everyone,  I'm breaking my head how to proceed with such logic;

I would like to get the value of these 4 textboxes (txtDomain, txtCheque, txtCredito and txtDebito)

and in the end go doing the arithmetic process in txtRestante.

Example would be if the customer were to pay in more than one form of payment (money and debit) that the 2 subtracted and would show in the rest until equal to the total value.

Follow the image of the payment part of my POS

    
asked by anonymous 10.05.2018 / 12:19

2 answers

1

You can create a class, which represents the payment, and associate an object of this class with DataBind of textBox . The calculations are all performed in the class, the Form only takes care of the display.

I gave an example:

 public partial class Form4 : Form
    {
        Pagamento objPg;



        public Form4()
        {
            InitializeComponent();
            objPg = new Pagamento();


            textBoxDinheiro.DataBindings.Add("Text", objPg, "Dinheiro", true, DataSourceUpdateMode.OnPropertyChanged);
            textBoxCredito.DataBindings.Add("Text", objPg, "Credito", true, DataSourceUpdateMode.OnPropertyChanged);
            textBoxDebito.DataBindings.Add("Text", objPg, "Debito", true, DataSourceUpdateMode.OnPropertyChanged);
            textBoxCheque.DataBindings.Add("Text", objPg, "Cheque", true, DataSourceUpdateMode.OnPropertyChanged);
            textBoxTotal.DataBindings.Add("Text", objPg, "TotalVenda", true, DataSourceUpdateMode.OnPropertyChanged);
            textBoxTotalPago.DataBindings.Add("Text", objPg, "TotalPago", true, DataSourceUpdateMode.OnPropertyChanged);
            textBoxRestante.DataBindings.Add("Text", objPg, "Restante", true, DataSourceUpdateMode.OnPropertyChanged);
            textBoxTroco.DataBindings.Add("Text", objPg, "Troco", true, DataSourceUpdateMode.OnPropertyChanged);


        }
    }


    public class Pagamento
    {
        public decimal Dinheiro { get; set; }
        public decimal Credito { get; set; }
        public decimal Debito { get; set; }
        public decimal Cheque { get; set; }
        public decimal TotalVenda { get; set; }
        public decimal TotalPago { get { return Dinheiro + Credito + Debito + Cheque; } }
        public decimal Restante { get { return TotalPago > TotalVenda ? 0 : TotalVenda - TotalPago; } }
        public decimal Troco { get { return TotalPago > TotalVenda ? TotalPago - TotalVenda : 0; } }
    }
}

Result:

Thereisstillawaytoformatforcurrency: link

  

Tip: Do not use 'ESC' (Escape) to complete the sale. It looks something like "Press Delete to Save"

    
10.05.2018 / 13:57
0

I do not know what program or language you are doing, but here is my solution.

I do not understand much of the accounts, but I assume that the debt is what he owes in cash or card, so first let's sum up all the ways he may have used to pay, which is going to be equal to the value that is pay. And in the other we will subtract what you owe to what he is paying to have the change.

So:

int a;
int b;
int c;
int d;
int resultado;
int valor_pago;
int valor_total_a_pagar;

txtDinheiro.Text = a;
txtCheque.Text = b;
txtCredito.Text = c;
txtDebito.Text = d;

a + b + c = valor_pago;
a + b + c - valor_total_a_pagar = resultado;

valorpago.Text = valor_pago;
troco.Text = resultado;
label1.Text = valor_total_a_pagar;
    
10.05.2018 / 13:04