private void DeleteRecieptButton_Click(object sender, RoutedEventArgs e)
 {
     if (PaymentGrid.SelectedItems.Count != 1)
     {
         MessageBox.Show("Please select one payment entry to delete", "Error");
         return;
     }
     if (MessageBox.Show("Are you sure you want to delete this payment entry. This operation cannot be reversed.", "Confirm", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
     {
         PaymentEntry           paymentEntry = (PaymentEntry)PaymentGrid.SelectedItem;
         BillingDataDataContext db           = new BillingDataDataContext();
         paymentEntry = db.PaymentEntries.SingleOrDefault(x => x.Id == paymentEntry.Id);
         if (paymentEntry == null)
         {
             MessageBox.Show("Cannot find this payment entry!!!", "Error");
             return;
         }
         db.PaymentEntries.DeleteOnSubmit(paymentEntry);
         db.SubmitChanges();
         MessageBox.Show("Entry deleted!! Please fetch again to see changes.", "Info");
     }
 }
예제 #2
0
        private void SubmitButton_Click(object sender, RoutedEventArgs e)
        {
            bool         isdone       = false;
            PaymentEntry paymentEntry = new PaymentEntry();
            string       errorMessage = "";

            paymentEntry.Id = PaymentRefNoBox.Text;
            double tempStorage;

            if (!double.TryParse(AmountTextBox.Text, out tempStorage))
            {
                errorMessage += "Amount is not in correct format. \n";
            }
            else
            {
                paymentEntry.RecievedAmount = tempStorage;
            }
            if (InvoiceSelectRadio.IsChecked == true)
            {
                Invoice invoice = (Invoice)InvoiceComboBox.SelectedItem;
                paymentEntry.InvoiceNumber = invoice.BillId;
                paymentEntry.ClientCode    = invoice.ClientCode;
            }
            else
            {
                Client client = (Client)ClientComboBox.SelectedItem;
                paymentEntry.ClientCode = client.CLCODE;
            }
            if (PaymentDatePicker.SelectedDate != null)
            {
                paymentEntry.Date = (DateTime)PaymentDatePicker.SelectedDate;
            }
            else
            {
                errorMessage += "Payment Entry Date is not Selected. \n";
            }
            if ((bool)ChequeRadio.IsChecked)
            {
                paymentEntry.Type = "Cheque";
                if (ChequeNumberBox.Text == "")
                {
                    errorMessage += "Enter the cheque number. \n";
                }
                else
                {
                    paymentEntry.ChequeNumber = ChequeNumberBox.Text;
                }
                if (ChequeBankName.Text == "")
                {
                    errorMessage += "Enter bank name: \n";
                }
                else
                {
                    paymentEntry.BankName = ChequeBankName.Text;
                }
            }
            else
            {
                paymentEntry.Type = "Cash";
            }
            paymentEntry.Remarks = RemarkBox.Text;
            if (double.TryParse(DebitNoteBox.Text, out tempStorage))
            {
                paymentEntry.DebitNote = tempStorage;
            }
            else
            {
                errorMessage += "Enter debit note properly \n";
            }
            if (double.TryParse(TDSBox.Text, out tempStorage))
            {
                paymentEntry.TDS = tempStorage;
            }
            else
            {
                errorMessage += "Enter TDS properly \n";
            }

            if (errorMessage == "")
            {
                BillingDataDataContext db = new BillingDataDataContext();
                db.PaymentEntries.InsertOnSubmit(paymentEntry);
                try
                {
                    db.SubmitChanges();
                    isdone = true;
                }
                catch (Exception ex) { MessageBox.Show(ex.Message); isdone = false; return; }
            }
            else
            {
                MessageBox.Show("Please correct the following errors: \n" + errorMessage);
            }
            if (isdone)
            {
                MessageBox.Show("Payment Received\nReference no is " + paymentEntry.Id);
                fillFields();
            }
        }