/// <summary> /// Updates the User Payment History on Submit. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button_userPayment_Click(object sender, EventArgs e) { //Validation To check for Empty Values if (textBox_amountPaid.Text.Trim().Length == 0 || textBox_paymentMethod.Text.Trim().Length == 0) { MessageBox.Show("Please Enter the Amount and Payment Mode", "Error"); return; } //If payment amount is not an integer int paymentAmount = 0; Int32.TryParse(textBox_amountPaid.Text, out paymentAmount); if (paymentAmount == 0) { MessageBox.Show("Payment amount should be a positive integer greater than 0", "Error"); return; } //Validation to check for Special Characters var withoutSpecial = new string(textBox_amountPaid.Text.Where(c => Char.IsLetterOrDigit(c) || Char.IsWhiteSpace(c)).ToArray()); if (textBox_amountPaid.Text != withoutSpecial) { MessageBox.Show("Amount Paid Contains Special Characters", "Error"); return; } DateTime theEnteredDate = DateTime.Parse(dateTimePicker_paidOn.Text); //To check if any payment was made on the same date if (db.CustomerPaymentHistories.Where(x => x.CustomerId == selectedCustomerId).ToList().Select(x => x.PaidOn).Contains(theEnteredDate)) { MessageBox.Show("You've Already Entered A Payment Record on the Same day.Please verify.", "Error"); return; } CustomerPaymentHistory paymentDetails = new CustomerPaymentHistory(); paymentDetails.CustomerId = selectedCustomerId; paymentDetails.PaidAmount = Int32.Parse(textBox_amountPaid.Text); paymentDetails.PaidOn = theEnteredDate; paymentDetails.PaymentMethod = textBox_paymentMethod.Text; db.CustomerPaymentHistories.AddObject(paymentDetails); db.SaveChanges(); MessageBox.Show("Added Payment Details Successfully", "Success"); displayPaymentHistory(); //Update CustomerDues CommonUtilities.updateCustomerDues(selectedCustomerId); //Update values in text boxes textBox_dueAmount.Text = db.CustomerDues.Where(x => x.CustomerId == selectedCustomerId).First().DueAmount.ToString(); textBox_carryForwardAmount.Text = db.CustomerDues.Where(x => x.CustomerId == selectedCustomerId).First().CarryforwardAmount.ToString(); }
/// <summary> /// Deprecated Method for adding a new object to the CustomerPaymentHistories EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToCustomerPaymentHistories(CustomerPaymentHistory customerPaymentHistory) { base.AddObject("CustomerPaymentHistories", customerPaymentHistory); }
/// <summary> /// Create a new CustomerPaymentHistory object. /// </summary> /// <param name="customerId">Initial value of the CustomerId property.</param> /// <param name="paidAmount">Initial value of the PaidAmount property.</param> /// <param name="paidOn">Initial value of the PaidOn property.</param> public static CustomerPaymentHistory CreateCustomerPaymentHistory(global::System.Int32 customerId, global::System.Int32 paidAmount, global::System.DateTime paidOn) { CustomerPaymentHistory customerPaymentHistory = new CustomerPaymentHistory(); customerPaymentHistory.CustomerId = customerId; customerPaymentHistory.PaidAmount = paidAmount; customerPaymentHistory.PaidOn = paidOn; return customerPaymentHistory; }