Exemplo n.º 1
0
        /// <summary>
        /// btnCheckFile_Click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCheckFile_Click(object sender, EventArgs e)
        {
            if(this.txtFilename.Text != null
            && this.txtFilename.Text.Trim() != ""
            && this.txtSheet.Text != null
            && this.txtSheet.Text.Trim() != "") {
                DataSet data;

                switch(this.cbImport.SelectedIndex) {
                    case 0:
                        if(File.Exists(this.txtFilename.Text.Trim())) {
                            try {
                                this._importer = (IImporter)new OpenDocumentImporter(
                                    Configuration.ConnectionString,
                                    this.txtFilename.Text.Trim()
                                );

                                if(this._importer.LoadFile()) {
                                    this.btnImport.Enabled = true;
                                    this._fileCanImported = true;

                                    this._importer.PercentState += new ImportPercentEventHandler(_importer_PercentState);

                                    data = this._importer.GetPreview();

                                    DataSetPreviewForm dspf = new DataSetPreviewForm(data);

                                    if(dspf.ShowDialog(this) == DialogResult.OK) {
                                        this._allocation = dspf.ColumnAllocation;
                                    }
                                }
                                else {
                                    this.btnImport.Enabled = false;
                                    this._fileCanImported = false;
                                }
                            }
                            catch(FileNotFoundException fileex) {
                                ErrorHandler.DisplayErrorMessagebox(fileex);

                                this.btnImport.Enabled = false;
                                this._fileCanImported = false;
                            }
                            catch(ArgumentNullException nullex) {
                                ErrorHandler.DisplayErrorMessagebox(nullex);

                                this.btnImport.Enabled = false;
                                this._fileCanImported = false;
                            }
                            catch(Exception ex) {
                                ErrorHandler.DisplayErrorMessagebox(ex);

                                this.btnImport.Enabled = false;
                                this._fileCanImported = false;
                            }
                        }
                        break;

                    case 1:
                        if(File.Exists(this.txtFilename.Text.Trim())) {
                            try {
                                this._importer = (IImporter)new Excel2003Importer(
                                    this.txtFilename.Text.Trim(),
                                    this.txtSheet.Text.Trim()
                                );

                                if(this._importer.LoadFile()) {
                                    this.btnImport.Enabled = true;
                                    this._fileCanImported = true;

                                    this._importer.PercentState += new ImportPercentEventHandler(_importer_PercentState);

                                    data = this._importer.GetPreview();
                                }
                                else {
                                    this.btnImport.Enabled = false;
                                    this._fileCanImported = false;
                                }
                            }
                            catch(FileNotFoundException fileex) {
                                ErrorHandler.DisplayErrorMessagebox(fileex);

                                this.btnImport.Enabled = false;
                                this._fileCanImported = false;
                            }
                            catch(ArgumentNullException nullex) {
                                ErrorHandler.DisplayErrorMessagebox(nullex);

                                this.btnImport.Enabled = false;
                                this._fileCanImported = false;
                            }
                            catch(Exception ex) {
                                ErrorHandler.DisplayErrorMessagebox(ex);

                                this.btnImport.Enabled = false;
                                this._fileCanImported = false;
                            }
                        }
                        break;

                    default:
                        if(File.Exists(this.txtFilename.Text.Trim())) {
                            try {
                                this._importer = (IImporter)new OpenDocumentImporter(
                                    Configuration.ConnectionString,
                                    this.txtFilename.Text.Trim()
                                );

                                if(this._importer.LoadFile()) {
                                    this.btnImport.Enabled = true;
                                    this._fileCanImported = true;

                                    this._importer.PercentState += new ImportPercentEventHandler(_importer_PercentState);

                                    // Hier Fenster mit Datenvorschau
                                }
                                else {
                                    this.btnImport.Enabled = false;
                                    this._fileCanImported = false;
                                }
                            }
                            catch(FileNotFoundException fileex) {
                                ErrorHandler.DisplayErrorMessagebox(fileex);

                                this.btnImport.Enabled = false;
                                this._fileCanImported = false;
                            }
                            catch(ArgumentNullException nullex) {
                                ErrorHandler.DisplayErrorMessagebox(nullex);

                                this.btnImport.Enabled = false;
                                this._fileCanImported = false;
                            }
                            catch(Exception ex) {
                                ErrorHandler.DisplayErrorMessagebox(ex);

                                this.btnImport.Enabled = false;
                                this._fileCanImported = false;
                            }
                        }
                        break;
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// btnCheckFile_Click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCheckFile_Click(object sender, EventArgs e)
        {
            if (this.txtFilename.Text != null &&
                this.txtFilename.Text.Trim() != "" &&
                this.txtSheet.Text != null &&
                this.txtSheet.Text.Trim() != "")
            {
                DataSet data;

                switch (this.cbImport.SelectedIndex)
                {
                case 0:
                    if (File.Exists(this.txtFilename.Text.Trim()))
                    {
                        try {
                            this._importer = (IImporter) new OpenDocumentImporter(
                                Configuration.ConnectionString,
                                this.txtFilename.Text.Trim()
                                );

                            if (this._importer.LoadFile())
                            {
                                this.btnImport.Enabled = true;
                                this._fileCanImported  = true;

                                this._importer.PercentState += new ImportPercentEventHandler(_importer_PercentState);

                                data = this._importer.GetPreview();

                                DataSetPreviewForm dspf = new DataSetPreviewForm(data);

                                if (dspf.ShowDialog(this) == DialogResult.OK)
                                {
                                    this._allocation = dspf.ColumnAllocation;
                                }
                            }
                            else
                            {
                                this.btnImport.Enabled = false;
                                this._fileCanImported  = false;
                            }
                        }
                        catch (FileNotFoundException fileex) {
                            ErrorHandler.DisplayErrorMessagebox(fileex);

                            this.btnImport.Enabled = false;
                            this._fileCanImported  = false;
                        }
                        catch (ArgumentNullException nullex) {
                            ErrorHandler.DisplayErrorMessagebox(nullex);

                            this.btnImport.Enabled = false;
                            this._fileCanImported  = false;
                        }
                        catch (Exception ex) {
                            ErrorHandler.DisplayErrorMessagebox(ex);

                            this.btnImport.Enabled = false;
                            this._fileCanImported  = false;
                        }
                    }
                    break;

                case 1:
                    if (File.Exists(this.txtFilename.Text.Trim()))
                    {
                        try {
                            this._importer = (IImporter) new Excel2003Importer(
                                this.txtFilename.Text.Trim(),
                                this.txtSheet.Text.Trim()
                                );

                            if (this._importer.LoadFile())
                            {
                                this.btnImport.Enabled = true;
                                this._fileCanImported  = true;

                                this._importer.PercentState += new ImportPercentEventHandler(_importer_PercentState);

                                data = this._importer.GetPreview();
                            }
                            else
                            {
                                this.btnImport.Enabled = false;
                                this._fileCanImported  = false;
                            }
                        }
                        catch (FileNotFoundException fileex) {
                            ErrorHandler.DisplayErrorMessagebox(fileex);

                            this.btnImport.Enabled = false;
                            this._fileCanImported  = false;
                        }
                        catch (ArgumentNullException nullex) {
                            ErrorHandler.DisplayErrorMessagebox(nullex);

                            this.btnImport.Enabled = false;
                            this._fileCanImported  = false;
                        }
                        catch (Exception ex) {
                            ErrorHandler.DisplayErrorMessagebox(ex);

                            this.btnImport.Enabled = false;
                            this._fileCanImported  = false;
                        }
                    }
                    break;

                default:
                    if (File.Exists(this.txtFilename.Text.Trim()))
                    {
                        try {
                            this._importer = (IImporter) new OpenDocumentImporter(
                                Configuration.ConnectionString,
                                this.txtFilename.Text.Trim()
                                );

                            if (this._importer.LoadFile())
                            {
                                this.btnImport.Enabled = true;
                                this._fileCanImported  = true;

                                this._importer.PercentState += new ImportPercentEventHandler(_importer_PercentState);

                                // Hier Fenster mit Datenvorschau
                            }
                            else
                            {
                                this.btnImport.Enabled = false;
                                this._fileCanImported  = false;
                            }
                        }
                        catch (FileNotFoundException fileex) {
                            ErrorHandler.DisplayErrorMessagebox(fileex);

                            this.btnImport.Enabled = false;
                            this._fileCanImported  = false;
                        }
                        catch (ArgumentNullException nullex) {
                            ErrorHandler.DisplayErrorMessagebox(nullex);

                            this.btnImport.Enabled = false;
                            this._fileCanImported  = false;
                        }
                        catch (Exception ex) {
                            ErrorHandler.DisplayErrorMessagebox(ex);

                            this.btnImport.Enabled = false;
                            this._fileCanImported  = false;
                        }
                    }
                    break;
                }
            }
        }