public AddEditGeneralPaidsModal(Model.GeneralPaid generalPaidToUpdate) { this.InitializeComponent(); _generalPaidToUpdate = generalPaidToUpdate; _isUpdateGeneralPaid = generalPaidToUpdate != null; dtpPurchaseDate.SelectedDate = DateTime.Now; if (_isUpdateGeneralPaid) { PrepareWindowForUpdates(); } }
private void btnAddUpdateGeneralPaid_Click(object sender, System.Windows.RoutedEventArgs e) { decimal totalAmount; string providerName = txtProviderName.Text.Trim(); string ticketNumber = txtTicketNumber.Text.Trim(); string totalAmountText = txtTotalAmount.Text.Trim(); if (AreValidFields(providerName, totalAmountText, ticketNumber, out totalAmount) == false) { return; } if (_isUpdateGeneralPaid) { _generalPaidToUpdate.ProviderName = providerName; _generalPaidToUpdate.PurchaseDate = dtpPurchaseDate.SelectedDate.Value; _generalPaidToUpdate.TicketNumber = ticketNumber; _generalPaidToUpdate.PaidMethod = cbPaidMethod.SelectedValue.ToString(); _generalPaidToUpdate.TotalAmount = totalAmount; UpdateGeneralPaid(_generalPaidToUpdate); } else { Model.GeneralPaid generalPaidToAdd = new Model.GeneralPaid() { ProviderName = providerName, PurchaseDate = dtpPurchaseDate.SelectedDate.Value, TicketNumber = ticketNumber, PaidMethod = cbPaidMethod.SelectedValue.ToString(), TotalAmount = totalAmount }; AddGeneralPaid(generalPaidToAdd); } }