예제 #1
0
        internal async Task LoadImageData(IDataObject dataObject)
        {
            if (!this._panelId.HasValue)
            {
                this._panelId = this._processingTaskMonitor.OpenPanel();
            }

            var imageFromHtml = await DragDropUtils.TryExtractImageDataFromHtml(dataObject, _processingTaskMonitor, this._panelId.Value);

            if (imageFromHtml.Success)
            {
                this._sourceImage.ImageBinary = imageFromHtml.ImageData;
                return;
            }

            if (dataObject.GetFormats().Contains("FileDrop"))
            {
                var    filePaths = (string[])dataObject.GetData("FileDrop");
                byte[] buffer    = null;
                using (Stream stream = File.OpenRead(filePaths[0]))
                {
                    buffer = new byte[stream.Length];
                    await stream.ReadAsync(buffer, 0, (int)stream.Length);
                }
                this._sourceImage.ImageBinary = buffer;
            }
        }
        /// <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();
                }
            }
        }