/// <summary>
 /// Update Customer Account and Insert in Payment History
 /// </summary>
 /// <param name="obj">
 /// obj[0] = ModelCustomerInfo
 /// obj[1] = paymentAmount
 /// obj[2] = Remain Due
 /// </param>
 private void updatePaymentClick(object obj)
 {
     Mouse.OverrideCursor = Cursors.Wait;
     try
     {
         if (obj is ArrayList)
         {
             using (DueManagementEntity dmDatabase = new DueManagementEntity())
             {
                 ArrayList dataList = obj as ArrayList;
                 ModelCustomerIno selectedCustomer = dataList[0] as ModelCustomerIno;
                 var customerInformation = dmDatabase.CustomerInformations.First(x => x.AutoInc == selectedCustomer.ID);
                 customerInformation.DueAmount = +Convert.ToDecimal(dataList[2]);
                 dmDatabase.AddToPaymentHistories(new PaymentHistory
                                                                     {
                                                                         AutoInc = default(long),
                                                                         Amount = Convert.ToDecimal(dataList[1]),
                                                                         CustomerName = selectedCustomer.CustomerName,
                                                                         PaymentDate = DateTime.Today,
                                                                         CustomerID=selectedCustomer.ID
                                                                     });
                 dmDatabase.SaveChanges();
                 Mouse.OverrideCursor = null;
                 MessageBox.Show(CommandData.ERROR_MESSAGE[1], CommandData.SOFTWARE_NAME, MessageBoxButton.OK, MessageBoxImage.Information);
             }
         }
         else
         {
             Mouse.OverrideCursor = null;
             MessageBox.Show("Unable to receive payment", CommandData.SOFTWARE_NAME, MessageBoxButton.OK, MessageBoxImage.Stop);
         }
     }
     catch (NullReferenceException)
     {
         Mouse.OverrideCursor = null;
         MessageBox.Show(CommandData.ERROR_MESSAGE[5], CommandData.SOFTWARE_NAME, MessageBoxButton.OK, MessageBoxImage.Stop);
     }
     catch (Exception errorException)
     {
         Mouse.OverrideCursor = null;
         MessageBox.Show(errorException.Message, CommandData.SOFTWARE_NAME, MessageBoxButton.OK, MessageBoxImage.Stop);
     }
     finally
     {
         Mouse.OverrideCursor = null;
     }
 }
 /// <summary>
 /// Insert invoice Reports
 /// </summary>
 /// <param name="obj">
 /// obj[0] = invoiceGrid.ItemSource
 /// obj[1] = Payment Amount
 /// obj[2] = Due Amount
 /// obj[3] = ModelCustomerInfo
 /// </param>
 private void updateInvoiceClick(object obj)
 {
     Mouse.OverrideCursor = null;
     try
     {
         if (obj is ArrayList)
         {
             using (DueManagementEntity dmDatabase = new DueManagementEntity())
             {
                 ArrayList dataList = obj as ArrayList;
                 ObservableCollection<ModelSalesHistory> salesItems = dataList[0] as ObservableCollection<ModelSalesHistory>;
                 ModelCustomerIno selectedCustomer = dataList[3] as ModelCustomerIno;
                 foreach (ModelSalesHistory sale in salesItems)
                 {
                     dmDatabase.AddToProductSaleHistories(new ProductSaleHistory
                                                                               {
                                                                                   AutoInc = default(long),
                                                                                   CustomerName = sale.CustomerName,
                                                                                   ProductName = sale.PropductName,
                                                                                   Quantity = sale.Quantity,
                                                                                   Rate = sale.Rate,
                                                                                   SaleDate = sale.SaleDate,
                                                                                   CustomerID=selectedCustomer.ID
                                                                               });
                 }
                 var customerInfo = dmDatabase.CustomerInformations.First(x => x.AutoInc == selectedCustomer.ID);
                 customerInfo.DueAmount = +Convert.ToDecimal(dataList[2]);
                 dmDatabase.AddToPaymentHistories(new PaymentHistory 
                                                                   {
                                                                       AutoInc=default(long),
                                                                       CustomerName=selectedCustomer.CustomerName,
                                                                       Amount=Convert.ToDecimal(dataList[1]),
                                                                       PaymentDate=DateTime.Today,
                                                                       CustomerID=selectedCustomer.ID
                                                                   });
                 dmDatabase.SaveChanges();
                 Mouse.OverrideCursor = null;
                 MessageBox.Show(CommandData.ERROR_MESSAGE[1], CommandData.SOFTWARE_NAME, MessageBoxButton.OK, MessageBoxImage.Information);
             }
         }
         else
         {
             Mouse.OverrideCursor = null;
             MessageBox.Show("Unable to save in database", CommandData.SOFTWARE_NAME, MessageBoxButton.OK, MessageBoxImage.Stop);
         }
     }
     catch (NullReferenceException)
     {
         Mouse.OverrideCursor = null;
         MessageBox.Show(CommandData.ERROR_MESSAGE[5], CommandData.SOFTWARE_NAME, MessageBoxButton.OK, MessageBoxImage.Stop);
     }
     catch (Exception errorException)
     {
         Mouse.OverrideCursor = null;
         MessageBox.Show(errorException.Message, CommandData.SOFTWARE_NAME, MessageBoxButton.OK, MessageBoxImage.Error);
     }
     finally
     {
         Mouse.OverrideCursor = null;
     }
 }