/// <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;
     }
 }
 /// <summary>
 /// Delete Product information
 /// </summary>
 /// <param name="obj"></param>
 private void deleteProductClick(object obj)
 {
     this.NewProductDelete.IsEnabled = false;
     try
     {
         if (MessageBox.Show(CommandData.ERROR_MESSAGE[3], CommandData.SOFTWARE_NAME, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
         {
             using (DueManagementEntity dmDatabase = new DueManagementEntity())
             {
                 ModelProductInfo deletedProductInfo = obj as ModelProductInfo;
                 dmDatabase.ProductInformations.DeleteObject(dmDatabase.ProductInformations.First(x => x.AutoInc == deletedProductInfo.ID));
                 dmDatabase.SaveChanges();
                 (this.NewProductList.ItemsSource as ObservableCollection<ModelProductInfo>).Remove(deletedProductInfo);
                 this.selectFirstItem(this.newCustomerList);
                 Mouse.OverrideCursor = null;
                 MessageBox.Show(CommandData.ERROR_MESSAGE[4], CommandData.SOFTWARE_NAME, MessageBoxButton.OK, MessageBoxImage.Information);
             }
         }
     }
     catch (NullReferenceException)
     {
         Mouse.OverrideCursor = null;
         MessageBox.Show(CommandData.ERROR_MESSAGE[5], CommandData.SOFTWARE_NAME, MessageBoxButton.OK, MessageBoxImage.Stop);
     }
     catch (Exception errorMessagess)
     {
         Mouse.OverrideCursor = null;
         MessageBox.Show(errorMessagess.Message, CommandData.SOFTWARE_NAME, MessageBoxButton.OK, MessageBoxImage.Error);
     }
     finally
     {
         Mouse.OverrideCursor = null;
         this.NewProductDelete.IsEnabled = true;
     }
 }
 /// <summary>
 /// Update or Insert Product information
 /// </summary>
 /// <param name="obj"></param>
 private void updateProductClick(object obj)
 {
     this.NewProductUpdate.IsEnabled = false;
     Mouse.OverrideCursor = Cursors.Wait;
     try
     {
         this.NewProductName.GetBindingExpression(TextBox.TextProperty);
         this.getValidationError(this.NewProductName);
         using (DueManagementEntity dmDatabase = new DueManagementEntity())
         {
             ModelProductInfo selectedProductInfo = obj as ModelProductInfo;
             var productExist = dmDatabase.ProductInformations.FirstOrDefault(x => x.AutoInc == selectedProductInfo.ID);
             if (productExist != null)
             {
                 Mouse.OverrideCursor = null;
                 if (MessageBox.Show(CommandData.ERROR_MESSAGE[0], CommandData.SOFTWARE_NAME, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                 {
                     Mouse.OverrideCursor = Cursors.Wait;
                     productExist.ProductName = selectedProductInfo.ProductName;
                     productExist.Rate = selectedProductInfo.Rate;
                     dmDatabase.SaveChanges();
                     Mouse.OverrideCursor = null;
                     MessageBox.Show(CommandData.ERROR_MESSAGE[1], CommandData.SOFTWARE_NAME, MessageBoxButton.OK, MessageBoxImage.Information);
                 }
                 else
                 {
                     return;
                 }
             }
             else
             {
                 ProductInformation newProductInfo = new ProductInformation
                                                         {
                                                             AutoInc = default(long),
                                                             ProductName = selectedProductInfo.ProductName,
                                                             Rate = selectedProductInfo.Rate
                                                         };
                 dmDatabase.ProductInformations.AddObject(newProductInfo);
                 dmDatabase.SaveChanges();
                 selectedProductInfo.ID = newProductInfo.AutoInc;
                 Mouse.OverrideCursor = null;
                 MessageBox.Show(CommandData.ERROR_MESSAGE[2], CommandData.SOFTWARE_NAME, MessageBoxButton.OK, MessageBoxImage.Information);
             }
         }
     }
     catch (NullReferenceException)
     {
         Mouse.OverrideCursor = null;
         MessageBox.Show(CommandData.ERROR_MESSAGE[5], CommandData.SOFTWARE_NAME, MessageBoxButton.OK, MessageBoxImage.Stop);
     }
     catch (Exception errorMessagess)
     {
         Mouse.OverrideCursor = null;
         MessageBox.Show(errorMessagess.Message, CommandData.SOFTWARE_NAME, MessageBoxButton.OK, MessageBoxImage.Error);
     }
     finally
     {
         Mouse.OverrideCursor = null;
     }
 }
 /// <summary>
 /// Update or Insert Customer information
 /// </summary>
 /// <param name="obj"></param>
 private void updateCustomerClick(object obj)
 {
     this.newCustomerUpdate.IsEnabled = false;
     Mouse.OverrideCursor = Cursors.Wait;
     try
     {
         this.newCustomerName.GetBindingExpression(TextBox.TextProperty);
         this.getValidationError(this.newCustomerName);
         using (DueManagementEntity dmDatabase = new DueManagementEntity())
         {
             ModelCustomerIno selectedCustomer = obj as ModelCustomerIno;
             var custometIsExist = dmDatabase.CustomerInformations.FirstOrDefault(x => x.AutoInc== selectedCustomer.ID);
             if (custometIsExist!=null)
             {
                 Mouse.OverrideCursor = null;
                 if (MessageBox.Show(CommandData.ERROR_MESSAGE[0],CommandData.SOFTWARE_NAME,MessageBoxButton.YesNo,MessageBoxImage.Question)==MessageBoxResult.Yes)
                 {
                     Mouse.OverrideCursor = Cursors.Wait;
                     custometIsExist.Address = selectedCustomer.Address;
                     custometIsExist.CustomerName = selectedCustomer.CustomerName;
                     custometIsExist.DueAmount = selectedCustomer.DueAmount;
                     custometIsExist.Mobile = selectedCustomer.Mobile;
                     custometIsExist.Remark = selectedCustomer.Remark;
                     custometIsExist.ShopName = selectedCustomer.ShopName;
                     dmDatabase.SaveChanges();
                     Mouse.OverrideCursor = null;
                     MessageBox.Show(CommandData.ERROR_MESSAGE[1], CommandData.SOFTWARE_NAME, MessageBoxButton.OK, MessageBoxImage.Information);
                 }
                 else
                 {
                     return;
                 }
             }
             else
             {
                 CustomerInformation newCustomerInformation = new CustomerInformation
                                                             {
                                                                 Address = selectedCustomer.Address,
                                                                 AutoInc = default(long),
                                                                 CreateDate = DateTime.Today,
                                                                 CustomerName = selectedCustomer.CustomerName,
                                                                 DueAmount = selectedCustomer.DueAmount,
                                                                 Mobile = selectedCustomer.Mobile,
                                                                 Remark = selectedCustomer.Remark,
                                                                 ShopName = selectedCustomer.ShopName
                                                             };
                 dmDatabase.CustomerInformations.AddObject(newCustomerInformation);
                 dmDatabase.SaveChanges();
                 selectedCustomer.ID = newCustomerInformation.AutoInc;
                 Mouse.OverrideCursor = null;
                 MessageBox.Show(CommandData.ERROR_MESSAGE[2], CommandData.SOFTWARE_NAME, MessageBoxButton.OK, MessageBoxImage.Information);
             }
         }
     }
     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;
     }
 }
 /// <summary>
 /// Delete All items
 /// </summary>
 /// <param name="obj">DataGrid.ItemSource</param>
 private void deleteAllPaymentHistoryClick(object obj)
 {
     this.PaymentHisDeleteAll.IsEnabled = false;
     Mouse.OverrideCursor = Cursors.Wait;
     try
     {
         using (DueManagementEntity dmDatabase = new DueManagementEntity())
         {
             ObservableCollection<ModelPaymentHistory> saleHestoryItems = new ObservableCollection<ModelPaymentHistory>();
             foreach (var singleItem in obj as ObservableCollection<ModelPaymentHistory>)
             {
                 saleHestoryItems.Add(singleItem);
             }
             foreach (var deletedItem in saleHestoryItems)
             {
                 dmDatabase.PaymentHistories.DeleteObject(dmDatabase.PaymentHistories.First(x => x.AutoInc == deletedItem.ID));
                 (this.PaymentHisGrid.ItemsSource as ObservableCollection<ModelPaymentHistory>).Remove(deletedItem);
             }
             dmDatabase.SaveChanges();
             Mouse.OverrideCursor = null;
             MessageBox.Show(CommandData.ERROR_MESSAGE[4], CommandData.SOFTWARE_NAME, MessageBoxButton.OK, MessageBoxImage.Information);
         }
     }
     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;
         this.PaymentHisDeleteAll.IsEnabled = true;
     }
 }