Exemplo n.º 1
0
        /// <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.ImportComplete)
                {
                    Importer.ImportComplete = false;
                    ImportTimer.Stop();

                    BeginDataRemovalProcess();

                    foreach (var file in processedFiles)
                    {
                        if (file is UsPrpoExcelFile)
                        {
                            if (AccessDatabaseUtils.US_PRPO_TableExists)
                            {
                                DateTime dt = file.Date;
                                reportSettings.PrpoUsDate         = dt.Month.ToString() + " " + dt.Day.ToString() + " " + dt.Year.ToString();
                                reportSettings.PrpoUsReportLoaded = true;
                            }
                        }

                        if (file is MxPrpoExcelFile)
                        {
                            if (AccessDatabaseUtils.MX_PRPO_TableExists)
                            {
                                DateTime dt = file.Date;
                                reportSettings.PrpoMxDate         = dt.Month.ToString() + " " + dt.Day.ToString() + " " + dt.Year.ToString();
                                reportSettings.PrpoMxReportLoaded = true;
                            }
                        }

                        // Save the report settings
                        reportSettings.Save();
                    }
                }
            }
            catch (DataImporter.Importing.Exceptions.ImportExceptions.InvalidDataFileException)
            {
                ShowPage(Pages.DragDropDash);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Begins the import process
        /// </summary>
        public void BeginImportProcess()
        {
            // Bring the loading screen to the front
            ActivateLoadingScreen("Importing Data...");

            // Update the top handle bar model
            topHandleBarModel.Update("Loading...", "Loading...");

            // Create a new instance of the overall reports
            CreateReport(ReportingType.KpaOverall);
            CreateReport(ReportingType.KpiOverall);


            if (AccessDatabaseUtils.US_PRPO_TableExists || AccessDatabaseUtils.MX_PRPO_TableExists)
            {
                DatabaseManager.DropCreateDb();
            }
            else
            {
                DatabaseManager.CreateAccessDB();
            }


            // Start the timer to check if the import has completed.
            ImportTimer.Start();


            foreach (var file in processedFiles)
            {
                if (file is UsPrpoExcelFile)
                {
                    // This file is a US PRPO file.
                    // Start importing the Report
                    ImportPrpoExcelFile(file);
                }
                else if (file is MxPrpoExcelFile)
                {
                    // This file is a MX PRPO file.
                    // Start importing the report
                    ImportPrpoExcelFile(file);
                }
            }
        }
Exemplo n.º 3
0
        /// <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");
            }
        }
        /// <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();
                }
            }
        }