/// <summary> /// Begins the Data removal process. /// </summary> public void BeginDataRemovalProcess() { ActivateLoadingScreen("Cleaning Data..."); DatabaseDataRemovalUtils.DataRemoved = false; DatabaseDataRemovalUtils.CompletedDataRemovals = 0; DatabaseDataRemovalUtils.ScheduledDataRemovals = 0; DataRemovalTimer.Start(); RemovePrpoData(); }
/// <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">The data removal timer</param> /// <param name="e">The tick event of the timer</param> private void DataRemovalTimer_Tick(object sender, EventArgs e) { if (DatabaseDataRemovalUtils.DataRemoved) { DatabaseDataRemovalUtils.DataRemoved = false; DataRemovalTimer.Stop(); if (AccessDatabaseUtils.US_PRPO_TableExists && AccessDatabaseUtils.MX_PRPO_TableExists) { ShowPage(Pages.CountrySelector); } else if (AccessDatabaseUtils.US_PRPO_TableExists) { ConfigureToUnitedStates(); BeginDataLoadProcess(); } else // only the mexico file exists. { ConfigureToMexico(); BeginDataLoadProcess(); } } }
/// <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> /// When the user has successfully dropped PRPO files into the application, this timer will initiate. /// The import process will then begin, importing all the data contained within the PRPO report into the /// Acces Database located in the resources folder. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ImportTimer_Tick(object sender, EventArgs e) { try { if (!Importer.importStarted) { Importer.importStarted = true; NavigationLocked = true; // Lock the navigation bar // load loading screen if (ExcelInfo.USUpdated) { // import only the US PRPO file Importer usImport = new Importer( new ExcelInfo() { FileName = DragDropUtils.US_PRPO_FilePath, HasHeaders = true, SheetName = ExcelInfo.sheetName[(int)ExcelInfo.SheetNames.US_PRPO] }, new AccessInfo() { FileName = Configuration.DbPath, TableName = AccessInfo.mainTableNames[(int)AccessInfo.MainTables.US_PRPO] } ); usThread = new Thread(() => { usImport.Run(); }); usThread.Name = "US"; usThread.Start(); } if (ExcelInfo.MXUpdated) { // Import only the MX PRPO file. Importer mxImport = new Importer( new ExcelInfo() { FileName = DragDropUtils.MX_PRPO_FilePath, HasHeaders = true, SheetName = ExcelInfo.sheetName[(int)ExcelInfo.SheetNames.MX_PRPO] }, new AccessInfo() { FileName = Configuration.DbPath, TableName = AccessInfo.mainTableNames[(int)AccessInfo.MainTables.MX_PRPO] } ); mxThread = new Thread(() => { mxImport.Run(); }); mxThread.Name = "MX"; mxThread.Start(); } } if (Importer.ImportComplete) { Importer.ImportComplete = false; ImportTimer.Stop(); PRPO_DB_Utils.DataRemovalProcessStarted = false; PRPO_DB_Utils.DataRemoved = false; PRPO_DB_Utils.CompletedDataRemovals = 0; PRPO_DB_Utils.ScheduledDataRemovals = 0; PRPO_DB_Utils.ConnectToDatabase(); if (AccessUtils.US_PRPO_TableExists) { string strFileName = Path.GetFileNameWithoutExtension(DragDropUtils.US_PRPO_FilePath); string strMonth = strFileName[7].ToString() + strFileName[8].ToString(); string strday = strFileName[9].ToString() + strFileName[10].ToString(); string strYear = strFileName[11].ToString() + strFileName[12].ToString() + strFileName[13].ToString() + strFileName[14].ToString(); int month = int.Parse(strMonth.TrimStart('0')); int day = int.Parse(strday.TrimStart('0')); int year = int.Parse(strYear); DateTime dt = new DateTime(year, month, day); lbl_dashboardDate.Text = dt.ToString("MMMM dd, yyyy"); Logger.Log(AppDirectoryUtils.LogFiles.LoadedUSDate, lbl_dashboardDate.Text); } if (AccessUtils.MX_PRPO_TableExists) { string strFileName = Path.GetFileNameWithoutExtension(DragDropUtils.MX_PRPO_FilePath); string strMonth = strFileName[7].ToString() + strFileName[8].ToString(); string strday = strFileName[9].ToString() + strFileName[10].ToString(); string strYear = strFileName[11].ToString() + strFileName[12].ToString() + strFileName[13].ToString() + strFileName[14].ToString(); int month = int.Parse(strMonth.TrimStart('0')); int day = int.Parse(strday.TrimStart('0')); int year = int.Parse(strYear); DateTime dt = new DateTime(year, month, day); lbl_dashboardDate.Text = dt.ToString("MMMM dd, yyyy"); Logger.Log(AppDirectoryUtils.LogFiles.LoadedMXDate, lbl_dashboardDate.Text); } DataRemovalTimer.Start(); } } catch (Exception ex) { MessageBox.Show(ex.StackTrace, "Import Function Error"); } }