/// <summary> /// Search Sale`s History /// </summary> /// <param name="obj"> /// obj[0] = ModelCustomerInformation /// obj[1] = by Date -- Date /// obj[2] = Between two date : First Date /// obj[3] = Between Two Date : Second Date /// obj[4] = ModelCustomQueryTime /// obj[5] = With Customer (Bool) /// </param> private void searchSaleHistoryClick(object obj) { this.SaleHistorySearch.IsEnabled = false; Mouse.OverrideCursor = Cursors.Wait; try { if (obj is ArrayList) { ArrayList dataList = obj as ArrayList; IQueryable<ProductSaleHistory> searchQuery=null; using (DueManagementEntity dmDatabase = new DueManagementEntity()) { if ((bool)dataList[5]) { ModelCustomerIno selectedCustomer= dataList[0] as ModelCustomerIno; switch (this.SelectedRadioButton) { case "ByDate": DateTime firstDate = ((DateTime)dataList[1]).Date; searchQuery = from searchedData in dmDatabase.ProductSaleHistories where searchedData.SaleDate == firstDate && searchedData.CustomerID == selectedCustomer.ID select searchedData; break; case "BetweenTwoDate" : DateTime secondDate= ((DateTime)dataList[2]).Date; DateTime thardDate=((DateTime)dataList[3]).Date; searchQuery = from searchedData in dmDatabase.ProductSaleHistories where searchedData.SaleDate <= secondDate && searchedData.SaleDate >= thardDate && searchedData.CustomerID == selectedCustomer.ID select searchedData; break; case "OlderThan" : ModelCustomQueryTime selectedDate = dataList[4] as ModelCustomQueryTime; DateTime olderDate=DateTime.Today.AddDays(selectedDate.QuertyTime).Date; searchQuery = from searchedData in dmDatabase.ProductSaleHistories where searchedData.SaleDate >=olderDate && searchedData.CustomerID == selectedCustomer.ID select searchedData; break; case "All" : searchQuery = from searchedData in dmDatabase.ProductSaleHistories where searchedData.CustomerID == selectedCustomer.ID select searchedData; break; default: break; } this.SaleHistoryGrid.ItemsSource = new ObservableCollection<ModelSalesHistory>(searchQuery.Select(x => new ModelSalesHistory { ID = x.AutoInc, PropductName = x.ProductName, Quantity = x.Quantity, Rate = x.Rate, SaleDate = x.SaleDate, Amount = 0 })); } else { switch (this.SelectedRadioButton) { case "ByDate": DateTime firstDate = ((DateTime)dataList[1]).Date; searchQuery = from searchedData in dmDatabase.ProductSaleHistories where searchedData.SaleDate == firstDate select searchedData; break; case "BetweenTwoDate": DateTime secondDate= ((DateTime)dataList[2]).Date; DateTime thardDate=((DateTime)dataList[3]).Date; searchQuery = from searchedData in dmDatabase.ProductSaleHistories where searchedData.SaleDate <= secondDate && searchedData.SaleDate >= thardDate select searchedData; break; case "OlderThan": ModelCustomQueryTime selectedDate = dataList[4] as ModelCustomQueryTime; DateTime olderDate = DateTime.Today.AddDays(selectedDate.QuertyTime).Date; searchQuery = from searchedData in dmDatabase.ProductSaleHistories where searchedData.SaleDate >= olderDate select searchedData; break; case "All": searchQuery = from searchedData in dmDatabase.ProductSaleHistories select searchedData; break; default: break; } this.SaleHistoryGrid.ItemsSource = new ObservableCollection<ModelSalesHistory> (searchQuery.Select(x => new ModelSalesHistory { ID = x.AutoInc, CustomerName = x.CustomerName, PropductName = x.ProductName, Quantity = x.Quantity, Rate = x.Rate, SaleDate = x.SaleDate, Amount = 0 })); } } } else { Mouse.OverrideCursor = null; MessageBox.Show("Unable to Search 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; this.SaleHistorySearch.IsEnabled = true; } }
/// <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> /// 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> /// Main Manu /// </summary> /// <param name="obj"></param> private void mainMenuClick(object obj) { Mouse.OverrideCursor = Cursors.Wait; try { var visiablePanels = this.PanelRootGrid.Children.OfType<Grid>().Where(x => x.Visibility.Equals(Visibility.Visible)); foreach (var panel in visiablePanels) { panel.Visibility = Visibility.Hidden; } using (DueManagementEntity dmDatabase = new DueManagementEntity()) { switch (obj.ToString()) { case "Home": this.PanelHome.Visibility = Visibility.Visible; break; case "Exit": this.PanelHome.Visibility = Visibility.Visible; this.Close(); break; case "DatabaseBackup": this.PanelDatabaseBackup.Visibility = Visibility.Visible; break; case "DatabaseRestore": this.PanelDatabaseRestore.Visibility = Visibility.Visible; break; case "About": this.PanelAbout.Visibility = Visibility.Visible; break; case "NewCustomer": var customersInfo = new ObservableCollection<ModelCustomerIno>(from custInfo in dmDatabase.CustomerInformations select new ModelCustomerIno { Address=custInfo.Address, CreateDate=custInfo.CreateDate, CustomerName=custInfo.CustomerName, DueAmount=custInfo.DueAmount, ID=custInfo.AutoInc, Mobile=custInfo.Mobile, Remark=custInfo.Remark, ShopName=custInfo.ShopName }); this.newCustomerList.ItemsSource = customersInfo; ICollectionView usesInfoView = CollectionViewSource.GetDefaultView(customersInfo); new CustomerSearch(usesInfoView, this.newCustomerSearch); this.selectFirstItem(this.newCustomerList); this.PanelNewCustomer.Visibility = Visibility.Visible; break; case "NewProduct": var productsInfo= new ObservableCollection<ModelProductInfo>(from prodInfo in dmDatabase.ProductInformations select new ModelProductInfo { ID=prodInfo.AutoInc, ProductName=prodInfo.ProductName, Rate=prodInfo.Rate }); this.NewProductList.ItemsSource = productsInfo; ICollectionView productsInfoView = CollectionViewSource.GetDefaultView(productsInfo); new ProcuctSearch(productsInfoView, this.NewProductSearch); this.selectFirstItem(this.NewProductList); this.PanelNewProduct.Visibility = Visibility.Visible; break; case "Invoice": var invoiceProductsInfo = new ObservableCollection<ModelProductInfo>(from prodInfo in dmDatabase.ProductInformations select new ModelProductInfo { ID = prodInfo.AutoInc, ProductName = prodInfo.ProductName, Rate = prodInfo.Rate }); this.InvoiceCustomer.ItemsSource = new ObservableCollection<ModelCustomerIno>(from custInfo in dmDatabase.CustomerInformations select new ModelCustomerIno { Address = custInfo.Address, CustomerName = custInfo.CustomerName, ID = custInfo.AutoInc }); this.InvoiceProductList.ItemsSource = invoiceProductsInfo; ICollectionView invoiceProductView = CollectionViewSource.GetDefaultView(invoiceProductsInfo); new ProcuctSearch(invoiceProductView, this.InvoiceProductSearch); this.newInvoiceClick(null); this.selectFirstItem(this.newCustomerList); this.PanelInvoice.Visibility = Visibility.Visible; break; case "Payment": this.PaymentCustomers.ItemsSource = new ObservableCollection<ModelCustomerIno>(from custInfo in dmDatabase.CustomerInformations where custInfo.DueAmount >0 select new ModelCustomerIno { Address = custInfo.Address, CustomerName = custInfo.CustomerName, ID = custInfo.AutoInc, DueAmount=custInfo.DueAmount }); this.PanelPayment.Visibility = Visibility.Visible; break; case "ProductSaleHistory": this.SaleHistoryCustomerList.ItemsSource = new ObservableCollection<ModelCustomerIno>(from custInfo in dmDatabase.CustomerInformations select new ModelCustomerIno { Address = custInfo.Address, CustomerName = custInfo.CustomerName, ID = custInfo.AutoInc }); this.PanelProductSaleHistory.Visibility = Visibility.Visible; break; case "PaymentHistory": this.PaymentHisCutomerList.ItemsSource = new ObservableCollection<ModelCustomerIno>(from custInfo in dmDatabase.CustomerInformations select new ModelCustomerIno { Address = custInfo.Address, CustomerName = custInfo.CustomerName, ID = custInfo.AutoInc }); this.PanelPaymentHistory.Visibility = Visibility.Visible; break; default: this.PanelHome.Visibility = Visibility.Visible; break; } } } catch (Exception errorException) { Mouse.OverrideCursor = null; //System.Diagnostics.EventLog.WriteEntry("MyEventSource", errorException.StackTrace, // System.Diagnostics.EventLogEntryType.Warning); 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; } }