Example #1
0
        /// <summary>
        /// This function will check the application directories and make sure they are all there before continueing.
        /// </summary>
        private void CheckApplicationFolderStructure()
        {
            lbl_CheckStatus.Invoke((MethodInvoker) delegate { lbl_CheckStatus.Text = "Checking Folder Structure..."; });

            try
            {
                foreach (var directory in Enum.GetValues(typeof(IOUtils.AppDirectoryUtils.Directories)))
                {
                    if (!Directory.Exists(Path.Combine(Configuration.AppDir, IOUtils.AppDirectoryUtils.DirectoryStructures[(int)directory])))
                    {
                        lbl_CheckStatus.Invoke((MethodInvoker) delegate { lbl_CheckStatus.Text = "Creating Directory - " + IOUtils.AppDirectoryUtils.DirectoryStructures[(int)directory]; });
                        Directory.CreateDirectory(Path.Combine(Configuration.AppDir, IOUtils.AppDirectoryUtils.DirectoryStructures[(int)directory]));
                    }
                }
            }
            catch (Exception ex)
            {
                errorList.Add(ex.Message);
                errorList.Add("There was an error generated while trying to create an application directory.");
                using (IOUtils.ErrorMessageBox errmsgbx = new IOUtils.ErrorMessageBox()
                {
                    Errors = errorList
                })
                {
                    if (errmsgbx.ShowDialog() == DialogResult.OK)
                    {
                        errmsgbx.Close();
                    }
                }
            }


            Thread.Sleep(2000);
            CurrentStatus = CheckStatus.Complete;
        }
        /// <summary>
        /// Triggered when the user drops any file into the region that allows a drop.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void pnl_DragDropArea_DragDrop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                string[] filePaths = ((string[])e.Data.GetData(DataFormats.FileDrop));

                try
                {
                    DragDropUtils.ProcessFiles(filePaths);
                }
                catch (DragDropExceptions.DragDropFileOverloadException ex)
                {
                    // An attempt of more than two files were dropped on the form.
                    errorList.Clear();
                    errorList.Add(ex.Message);
                    using (IOUtils.ErrorMessageBox errmsgbox = new IOUtils.ErrorMessageBox())
                    {
                        if (errmsgbox.ShowDialog() == DialogResult.OK)
                        {
                            errmsgbox.Close();
                        }
                    }
                }
                catch (DragDropExceptions.DragDropInvalidExtensionException ex)
                {
                    // Files were dropped that had an invalid file extention
                    errorList.Clear();
                    errorList.Add(ex.Message);
                    using (IOUtils.ErrorMessageBox errmsgbox = new IOUtils.ErrorMessageBox())
                    {
                        if (errmsgbox.ShowDialog() == DialogResult.OK)
                        {
                            errmsgbox.Close();
                        }
                    }
                }
                catch (DragDropExceptions.DragDropInvalidExcelFileException ex)
                {
                    // Files were dropped that were not PRPO files
                    errorList.Clear();
                    errorList.Add(ex.Message);
                    using (IOUtils.ErrorMessageBox errmsgbox = new IOUtils.ErrorMessageBox())
                    {
                        if (errmsgbox.ShowDialog() == DialogResult.OK)
                        {
                            errmsgbox.Close();
                        }
                    }
                }
                catch (Exception ex)
                {
                    errorList.Clear();
                    errorList.Add(ex.Message);
                    using (IOUtils.ErrorMessageBox errmsgbox = new IOUtils.ErrorMessageBox())
                    {
                        if (errmsgbox.ShowDialog() == DialogResult.OK)
                        {
                            errmsgbox.Close();
                            Application.Exit();
                        }
                    }
                }



                Importer.NumberOfImports  = filePaths.Length;
                Importer.ImportComplete   = false;
                Importer.CompletedImports = 0;
                Importer.ImportProgress  += ImportProgress;
                Importer.importStarted    = false;

                if (ExcelInfo.USUpdated || ExcelInfo.MXUpdated)
                {
                    overallData = new KPA_KPI_Overall.Overall();
                    if (AccessUtils.US_PRPO_TableExists || AccessUtils.MX_PRPO_TableExists)
                    {
                        PRPO_DB_Utils.DropCreateDb();
                    }
                    else
                    {
                        AccessUtils.CreateAccessDB();
                    }


                    btn_DatabaseConnectionStatus.Invoke((MethodInvoker) delegate { btn_DatabaseConnectionStatus.Image = Properties.Resources.databaseConn_Disconnected_Icon; });

                    pnl_activePage.Controls.Clear();
                    pnl_loadingScreen.Visible = true;
                    pnl_loadingScreen.BringToFront();
                    lbl_loadingStatus.Text = "Importing Data...";


                    ImportTimer.Start();
                }
            }
        }
Example #3
0
        /// <summary>
        /// This function will check the presence of the database used to read data from.
        /// </summary>
        private void CheckDatabase()
        {
            try
            {
                lbl_CheckStatus.Invoke((MethodInvoker) delegate { lbl_CheckStatus.Text = "Checking for a valid database..."; });
                Thread.Sleep(2000);
                AccessUtils.CheckDatabase();
                lbl_CheckStatus.Invoke((MethodInvoker) delegate { lbl_CheckStatus.Text = "Valid database found. Establishing a connection..."; });

                conn = new OleDbConnection(AccessUtils.AI.connectionString());

                Thread.Sleep(5000);
                CurrentStatus = CheckStatus.Complete;
            }
            catch (TablesDoNotExistException)
            {
                // The database exists but the tables did not. We want to keep the current database but we do not want to attempt to connect.
                CurrentStatus = CheckStatus.Complete;
            }
            catch (PRPODatabaseNotFoundException)
            {
                // The database did not exist so create a new one before the application starts.
                lbl_CheckStatus.Invoke((MethodInvoker) delegate { lbl_CheckStatus.Text = "Creating new database..."; });
                try
                {
                    AccessUtils.CreateAccessDB();
                }
                catch (DatabaseCreationFailureException ex)
                {
                    errorList.Add(ex.Message);
                    using (IOUtils.ErrorMessageBox errmsgbx = new IOUtils.ErrorMessageBox()
                    {
                        Errors = errorList
                    })
                    {
                        if (errmsgbx.ShowDialog() == DialogResult.OK)
                        {
                            errmsgbx.Close();
                            Application.Exit();
                        }
                    }
                }
                Thread.Sleep(2000);
                CurrentStatus = CheckStatus.Complete;
            }
            catch (TableNameMismatchException)
            {
                // The names of the table are not correct so lets delete the database and create a new one and
                // wait for the user to drop new files to load.
                lbl_CheckStatus.Invoke((MethodInvoker) delegate { lbl_CheckStatus.Text = "Database error! Creating new database..."; });

                try
                {
                    File.Delete(Configuration.DbPath);
                    AccessUtils.CreateAccessDB();
                    Thread.Sleep(2000);
                    CurrentStatus = CheckStatus.Complete;
                }
                catch (DatabaseCreationFailureException ex)
                {
                    errorList.Add(ex.Message);
                    using (IOUtils.ErrorMessageBox errmsgbx = new IOUtils.ErrorMessageBox()
                    {
                        Errors = errorList
                    })
                    {
                        if (errmsgbx.ShowDialog() == DialogResult.OK)
                        {
                            errmsgbx.Close();
                            Application.Exit();
                        }
                    }
                }
                catch (Exception ex)
                {
                    // Something happened while deleting the file
                    errorList.Add(ex.Message);
                    errorList.Add("There was an error while attempting to delete the MS Access Database");
                    using (IOUtils.ErrorMessageBox errmsgbx = new IOUtils.ErrorMessageBox()
                    {
                        Errors = errorList
                    })
                    {
                        if (errmsgbx.ShowDialog() == DialogResult.OK)
                        {
                            errmsgbx.Close();
                            Application.Exit();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // Some other type of run-time error occured.
                errorList.Add(ex.Message);
                using (IOUtils.ErrorMessageBox errmsgbx = new IOUtils.ErrorMessageBox()
                {
                    Errors = errorList
                })
                {
                    if (errmsgbx.ShowDialog() == DialogResult.OK)
                    {
                        errmsgbx.Close();
                        Application.Exit();
                    }
                }
            }
        }
Example #4
0
        /// <summary>
        /// This function will check the files of the application. If they are not there, create them.
        /// </summary>
        private void CheckApplicationFiles()
        {
            lbl_CheckStatus.Invoke((MethodInvoker) delegate { lbl_CheckStatus.Text = "Checking Application Files..."; });
            try
            {
                foreach (var file in Enum.GetValues(typeof(IOUtils.AppDirectoryUtils.ResourceFiles)))
                {
                    if (!File.Exists(Path.Combine(Configuration.AppDir, IOUtils.AppDirectoryUtils.resourceFiles[(int)file])))
                    {
                        lbl_CheckStatus.Invoke((MethodInvoker) delegate { lbl_CheckStatus.Text = "Creating File - " + IOUtils.AppDirectoryUtils.resourceFiles[(int)file]; });
                        try
                        {
                            AccessUtils.CreateAccessDB();
                        }
                        catch (Exception ex)
                        {
                            throw ex; // throw the exception thrown by AccesUtils
                        }
                        Thread.Sleep(2000);
                    }
                }

                foreach (var file in Enum.GetValues(typeof(IOUtils.AppDirectoryUtils.ReportFiles)))
                {
                    if (!File.Exists(Path.Combine(Configuration.AppDir, IOUtils.AppDirectoryUtils.reportFiles[(int)file])))
                    {
                        lbl_CheckStatus.Invoke((MethodInvoker) delegate { lbl_CheckStatus.Text = "Creating File - " + IOUtils.AppDirectoryUtils.reportFiles[(int)file]; });
                        File.Create(IOUtils.AppDirectoryUtils.reportFiles[(int)file]);
                        Thread.Sleep(2000);
                    }
                }

                foreach (var file in Enum.GetValues(typeof(IOUtils.AppDirectoryUtils.LogFiles)))
                {
                    if (!File.Exists(Path.Combine(Configuration.AppDir, IOUtils.AppDirectoryUtils.logFiles[(int)file])))
                    {
                        lbl_CheckStatus.Invoke((MethodInvoker) delegate { lbl_CheckStatus.Text = "Creating File - " + IOUtils.AppDirectoryUtils.logFiles[(int)file]; });
                        File.Create(Path.Combine(Configuration.AppDir, IOUtils.AppDirectoryUtils.logFiles[(int)file]));
                        Thread.Sleep(2000);
                    }
                }
            }
            catch (DatabaseCreationFailureException ex)
            {
                errorList.Add(ex.Message);
                using (IOUtils.ErrorMessageBox errmsgbx = new IOUtils.ErrorMessageBox()
                {
                    Errors = errorList
                })
                {
                    if (errmsgbx.ShowDialog() == DialogResult.OK)
                    {
                        errmsgbx.Close();
                        Application.Exit();
                    }
                }
            }
            catch (Exception ex)
            {
                errorList.Add(ex.Message);
                using (IOUtils.ErrorMessageBox errmsgbx = new IOUtils.ErrorMessageBox()
                {
                    Errors = errorList
                })
                {
                    if (errmsgbx.ShowDialog() == DialogResult.OK)
                    {
                        errmsgbx.Close();
                    }
                }
            }

            Thread.Sleep(2000);
            CurrentStatus = CheckStatus.Complete;
        }