/// <summary> /// Clear the filters and set everything back to default. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_clearFilters_Click(object sender, EventArgs e) { Filters.ClbDictionaryValues.Clear(); Filters.FitlerValues.Clear(); Filters.FilterQuery = string.Empty; Filters.SecondaryFilterQuery = string.Empty; Filters.PrDateRangeFilterAdded = false; Filters.PoDateRangeFilterAdded = false; HasFiltersAdded(); if (!FiltersAdded) { FiltersApplied = false; overallData = new Overall(); PRPO_DB_Utils.DataLoadProcessStarted = false; PRPO_DB_Utils.DataLoaded = false; PRPO_DB_Utils.CompletedDataLoads = 0; PRPO_DB_Utils.ScheduledDataLoads = 0; DataLoaderTimer.Start(); } else { MessageBox.Show("Loading data with no filters but filters has filters applied."); } }
/// <summary> /// This function will be called when the form loads. /// </summary> /// <param name="sender">The form</param> /// <param name="e">The load event</param> private void KPA_KPI_UI_Load(object sender, EventArgs e) { mainNavActiveBtn = btn_Dashboard; // set the active button as the first button (Dashboard) FilterUtils.UpdateFilter += UpdateFilters; if (PRPO_DB_Utils.DatabaseConnection != null) { try { PRPO_DB_Utils.ConnectToDatabase(); btn_DatabaseConnectionStatus.Image = Properties.Resources.databaseConn_Connected_Icon; Logger.Log(AppDirectoryUtils.LogFiles.DbConnectionEvents, "Successfully Connected to MS Access Database"); if (AccessUtils.US_PRPO_TableExists && AccessUtils.MX_PRPO_TableExists) { NavigationLocked = true; pnl_CountrySelector.BringToFront(); } else if (AccessUtils.US_PRPO_TableExists) { Overall.SelectedCountry = AccessInfo.MainTables.US_PRPO; PRPO_DB_Utils.DataLoadProcessStarted = false; PRPO_DB_Utils.DataLoaded = false; PRPO_DB_Utils.CompletedDataLoads = 0; PRPO_DB_Utils.ScheduledDataLoads = 0; DataLoaderTimer.Start(); } else // There is a Mexico table within the database. { Overall.SelectedCountry = AccessInfo.MainTables.MX_PRPO; PRPO_DB_Utils.DataLoadProcessStarted = false; PRPO_DB_Utils.DataLoaded = false; PRPO_DB_Utils.CompletedDataLoads = 0; PRPO_DB_Utils.ScheduledDataLoads = 0; DataLoaderTimer.Start(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Application load error", MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Exit(); } } else { pnl_loadingScreen.Visible = false; tblpnl_DragDrop.BringToFront(); } }
/// <summary> /// Triggered when the user clicks the load data button. Once this button is clicked, the data timer /// will be triggered. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_LoadData_Click(object sender, EventArgs e) { if (btn_usSwitch.Value) { Overall.SelectedCountry = AccessInfo.MainTables.US_PRPO; lbl_country.Text = "United States"; } else { Overall.SelectedCountry = AccessInfo.MainTables.MX_PRPO; lbl_country.Text = "Mexico"; } overallData = new Overall(); PRPO_DB_Utils.DataLoadProcessStarted = false; PRPO_DB_Utils.DataLoaded = false; PRPO_DB_Utils.CompletedDataLoads = 0; PRPO_DB_Utils.ScheduledDataLoads = 0; DataLoaderTimer.Start(); }
/// <summary> /// Once the data is loaded into the application this timer will begin. This timer event will begin /// running condition checks and then making a call to remove the data that is not needed from the database. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DataRemovalTimer_Tick(object sender, EventArgs e) { if (!PRPO_DB_Utils.DataRemovalProcessStarted) { PRPO_DB_Utils.DataRemovalProcessStarted = true; if (AccessUtils.US_PRPO_TableExists) { PRPO_DB_Utils.ScheduledDataRemovals++; usThread = new Thread(() => { PRPO_DB_Utils.RemoveData(PRPOCommands.DatabaseTables.MainTables.US_PRPO); }); usThread.Start(); } if (AccessUtils.MX_PRPO_TableExists) { PRPO_DB_Utils.ScheduledDataRemovals++; mxThread = new Thread(() => { PRPO_DB_Utils.RemoveData(PRPOCommands.DatabaseTables.MainTables.MX_PRPO); }); mxThread.Start(); } } if (PRPO_DB_Utils.DataRemoved) { DataRemovalTimer.Stop(); PRPO_DB_Utils.DataRemoved = false; if (PRPO_DB_Utils.DatabaseConnection != null & PRPO_DB_Utils.DatabaseConnection.State == System.Data.ConnectionState.Open) { btn_DatabaseConnectionStatus.Image = Properties.Resources.databaseConn_Connected_Icon; } else { MessageBox.Show("There was an error while attempting to connect to the database", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (AccessUtils.US_PRPO_TableExists && AccessUtils.MX_PRPO_TableExists) { pnl_CountrySelector.BringToFront(); } else if (AccessUtils.US_PRPO_TableExists) { Overall.SelectedCountry = AccessInfo.MainTables.US_PRPO; PRPO_DB_Utils.DataLoadProcessStarted = false; PRPO_DB_Utils.DataLoaded = false; PRPO_DB_Utils.CompletedDataLoads = 0; PRPO_DB_Utils.ScheduledDataLoads = 0; DataLoaderTimer.Start(); } else // only the mexico file exists. { Overall.SelectedCountry = AccessInfo.MainTables.MX_PRPO; PRPO_DB_Utils.DataLoadProcessStarted = false; PRPO_DB_Utils.DataLoaded = false; PRPO_DB_Utils.CompletedDataLoads = 0; PRPO_DB_Utils.ScheduledDataLoads = 0; DataLoaderTimer.Start(); } } }
/// <summary> /// Apply the filters and load the data again with the filters applied. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_applyFilters_Click(object sender, EventArgs e) { Filters.FitlerValues.Clear(); foreach (int i in ChkdListBx_Material.CheckedIndices) { Filters.FitlerValues.material.Add(ChkdListBx_Material.Items[i].ToString()); } foreach (int i in ChkdListBx_MaterialGroup.CheckedIndices) { Filters.FitlerValues.materialGroup.Add(ChkdListBx_MaterialGroup.Items[i].ToString()); } foreach (int i in ChkdListBx_Vendor.CheckedIndices) { Filters.FitlerValues.vendor.Add(ChkdListBx_Vendor.Items[i].ToString()); } foreach (int i in ChkdListBx_VendorDesc.CheckedIndices) { Filters.FitlerValues.vendorDesc.Add(ChkdListBx_VendorDesc.Items[i].ToString()); } foreach (int i in ChkdListBx_PurchGroup.CheckedIndices) { Filters.FitlerValues.purchGroup.Add(ChkdListBx_PurchGroup.Items[i].ToString()); } foreach (int i in ChkdListBx_IRSuppName.CheckedIndices) { Filters.FitlerValues.irSuppName.Add(ChkdListBx_IRSuppName.Items[i].ToString()); } foreach (int i in ChkdListBx_FxdSuppName.CheckedIndices) { Filters.FitlerValues.fxdSuppName.Add(ChkdListBx_FxdSuppName.Items[i].ToString()); } foreach (int i in ChkdListBx_DsrdSuppName.CheckedIndices) { Filters.FitlerValues.dsrdSuppName.Add(ChkdListBx_DsrdSuppName.Items[i].ToString()); } foreach (int i in ChkdListBx_CommodityCat.CheckedIndices) { Filters.FitlerValues.commCategory.Add(ChkdListBx_CommodityCat.Items[i].ToString()); } BuildQueryFilters(); HasFiltersAdded(); if (FiltersAdded) { Filters.SecondaryFilterQuery = filters; filters = " AND " + filters; Filters.FilterQuery = filters; FiltersApplied = true; } else { filters = string.Empty; Filters.FilterQuery = filters; Filters.SecondaryFilterQuery = filters; FiltersApplied = false; } // Check if the user added a PR date range if (Filters.PrDateRangeFilterAdded) { Filters.PrFromDate = dp_PRFromDate.Value; Filters.PrToDate = dp_PRToDate.Value; FiltersApplied = true; } // Check if the user added a PO date range if (Filters.PoDateRangeFilterAdded) { Filters.PoFromDate = dp_POFromDate.Value; Filters.PoToDate = dp_POToDate.Value; FiltersApplied = true; } overallData = new Overall(); PRPO_DB_Utils.DataLoadProcessStarted = false; PRPO_DB_Utils.DataLoaded = false; PRPO_DB_Utils.CompletedDataLoads = 0; PRPO_DB_Utils.ScheduledDataLoads = 0; DataLoaderTimer.Start(); }