Example #1
0
        private void SelectFiles_OnCommit(object sender, AeroWizard.WizardPageConfirmEventArgs e)
        {
            string SrcFilename  = select_source_file.Text;
            string SrcFileExt   = GetFileExt(SrcFilename);
            string DestFilename = select_dest_file.Text;
            string DestFileExt  = GetFileExt(DestFilename);

            if (SrcFileExt == ".jb64")
            {
                if (!File.Exists(SrcFilename))
                {
                    MessageBox.Show("Please enter or select a valid source file.\n\nSource file must exist and be accessible to this application.", "Error");

                    e.Cancel = true;
                }
                else if (DestFileExt != ".xls" && DestFileExt != ".xlsx" && DestFileExt != ".jb64")
                {
                    MessageBox.Show("Please enter or select a valid destination file.\n\nDestination file must have a .xls, .xlsx, or .jb64 extension.", "Error");

                    e.Cancel = true;
                }
            }
            else if (SrcFileExt == ".xls" || SrcFileExt == ".xlsx")
            {
                if (!File.Exists(SrcFilename))
                {
                    MessageBox.Show("Please enter or select a valid source file.\n\nSource file must exist and be accessible to this application.", "Error");

                    e.Cancel = true;
                }
                else if (DestFileExt != ".jb64")
                {
                    MessageBox.Show("Please enter or select a valid destination file.\n\nDestination file must have a .jb64 extension.", "Error");

                    e.Cancel = true;
                }
            }
            else
            {
                MessageBox.Show("Please enter or select a valid source file.\n\nSource file must have a .jb64, .xls, or .xlsx extension.", "Error");

                e.Cancel = true;
            }

            if (!e.Cancel)
            {
                if (SrcFilename == DestFilename)
                {
                    MessageBox.Show("Please enter or select a valid destination file.\n\nDestination file must be different than source file.", "Error");

                    e.Cancel = true;
                }
                else if (File.Exists(DestFilename) && MessageBox.Show("Destination file exists.  Overwrite?", "Warning", MessageBoxButtons.YesNo) == DialogResult.No)
                {
                    e.Cancel = true;
                }
                else
                {
                    try
                    {
                        if (SrcFileExt == ".jb64")
                        {
                            this.ReadConvert = new Reader_JB64();
                        }
                        else
                        {
                            this.ReadConvert = new Reader_Excel();
                        }

                        if (DestFileExt == ".jb64")
                        {
                            this.WriteConvert = new Writer_JB64();
                        }
                        else
                        {
                            this.WriteConvert = new Writer_Excel();
                        }

                        this.ReadConvert.Init(SrcFilename, "");

                        this.SetOptionsEntries = this.ReadConvert.GetSetOptionsEntryList(this.WriteConvert.IsBinaryAllowed());

                        options_sheet_select_box.DropDownStyle = this.ReadConvert.GetSheetNameBoxStyle();
                        options_sheet_select_box.DataSource    = this.ReadConvert.GetSheetNames();

                        if (this.ReadConvert.GetSheetNameBoxStyle() == ComboBoxStyle.DropDownList)
                        {
                            options_sheet_select_box.SelectedIndex = 0;
                        }

                        if (this.SetOptionsEntries.Count > 0)
                        {
                            SetOptions_SwitchActiveEntry(0);
                        }
                        else
                        {
                            MessageBox.Show("Unable to locate a header or record data in the source file.\n\nTip:  Header and record column counts must be identical.", "Error");

                            e.Cancel = true;
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("An exception occurred while attempting to read the source file.\n\n" + ex.Message + "\n\n" + ex.StackTrace, "Error");

                        e.Cancel = true;
                    }
                }
            }
        }
Example #2
0
        private void SelectFiles_OnCommit(object sender, AeroWizard.WizardPageConfirmEventArgs e)
        {
            string SrcFilename = select_source_file.Text;
            string SrcFileExt = GetFileExt(SrcFilename);
            string DestFilename = select_dest_file.Text;
            string DestFileExt = GetFileExt(DestFilename);

            if (SrcFileExt == ".jb64")
            {
                if (!File.Exists(SrcFilename))
                {
                    MessageBox.Show("Please enter or select a valid source file.\n\nSource file must exist and be accessible to this application.", "Error");

                    e.Cancel = true;
                }
                else if (DestFileExt != ".xls" && DestFileExt != ".xlsx" && DestFileExt != ".jb64")
                {
                    MessageBox.Show("Please enter or select a valid destination file.\n\nDestination file must have a .xls, .xlsx, or .jb64 extension.", "Error");

                    e.Cancel = true;
                }
            }
            else if (SrcFileExt == ".xls" || SrcFileExt == ".xlsx")
            {
                if (!File.Exists(SrcFilename))
                {
                    MessageBox.Show("Please enter or select a valid source file.\n\nSource file must exist and be accessible to this application.", "Error");

                    e.Cancel = true;
                }
                else if (DestFileExt != ".jb64")
                {
                    MessageBox.Show("Please enter or select a valid destination file.\n\nDestination file must have a .jb64 extension.", "Error");

                    e.Cancel = true;
                }
            }
            else
            {
                MessageBox.Show("Please enter or select a valid source file.\n\nSource file must have a .jb64, .xls, or .xlsx extension.", "Error");

                e.Cancel = true;
            }

            if (!e.Cancel)
            {
                if (SrcFilename == DestFilename)
                {
                    MessageBox.Show("Please enter or select a valid destination file.\n\nDestination file must be different than source file.", "Error");

                    e.Cancel = true;
                }
                else if (File.Exists(DestFilename) && MessageBox.Show("Destination file exists.  Overwrite?", "Warning", MessageBoxButtons.YesNo) == DialogResult.No)
                {
                    e.Cancel = true;
                }
                else
                {
                    try
                    {
                        if (SrcFileExt == ".jb64")  this.ReadConvert = new Reader_JB64();
                        else  this.ReadConvert = new Reader_Excel();

                        if (DestFileExt == ".jb64")  this.WriteConvert = new Writer_JB64();
                        else  this.WriteConvert = new Writer_Excel();

                        this.ReadConvert.Init(SrcFilename, "");

                        this.SetOptionsEntries = this.ReadConvert.GetSetOptionsEntryList(this.WriteConvert.IsBinaryAllowed());

                        options_sheet_select_box.DropDownStyle = this.ReadConvert.GetSheetNameBoxStyle();
                        options_sheet_select_box.DataSource = this.ReadConvert.GetSheetNames();

                        if (this.ReadConvert.GetSheetNameBoxStyle() == ComboBoxStyle.DropDownList)  options_sheet_select_box.SelectedIndex = 0;

                        if (this.SetOptionsEntries.Count > 0)
                        {
                            SetOptions_SwitchActiveEntry(0);
                        }
                        else
                        {
                            MessageBox.Show("Unable to locate a header or record data in the source file.\n\nTip:  Header and record column counts must be identical.", "Error");

                            e.Cancel = true;
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("An exception occurred while attempting to read the source file.\n\n" + ex.Message + "\n\n" + ex.StackTrace, "Error");

                        e.Cancel = true;
                    }
                }
            }
        }