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"