Beispiel #1
0
        private async void OnToolBarItemClick(object sender, ToolStripItemClickedEventArgs e)
        {
            switch (e.ClickedItem.Name)
            {
            case "tbClose":
                Close();
                break;

            case "tbAdd":
                SpeciesNameForm snf = new SpeciesNameForm(this);
                snf.ShowDialog(this);
                break;

            case "tbRemove":
                break;

            case "tbEdit":
                ShowNameDetail();
                break;

            case "tbExport":
                var count   = 0;
                var taxaCSV = "";
                if (lvTaxa.CheckedItems.Count > 0)
                {
                    foreach (ListViewItem checkedItem in lvTaxa.CheckedItems)
                    {
                        taxaCSV += ((Taxa)int.Parse(checkedItem.Name)).ToString() + ",";
                    }
                    taxaCSV.Trim(',');
                }
                using (ExportImportDialogForm edf = new ExportImportDialogForm(ExportImportDataType.SpeciesNames, ExportImportDeleteAction.ActionExport))
                {
                    edf.TaxaCSV = taxaCSV;
                    edf.ShowDialog(this);
                    if (edf.DialogResult == DialogResult.OK)
                    {
                        ExportImportDataType result = edf.Selection;
                        if (result == ExportImportDataType.SpeciesNames)
                        {
                            FileDialogHelper.Title        = "Provide filename for exported species name";
                            FileDialogHelper.DialogType   = FileDialogType.FileSave;
                            FileDialogHelper.DataFileType = DataFileType.Text | DataFileType.XML | DataFileType.CSV;
                            FileDialogHelper.ShowDialog();
                            var fileName = FileDialogHelper.FileName;
                            if (fileName.Length > 0)
                            {
                                switch (Path.GetExtension(fileName))
                                {
                                case ".xml":
                                case ".XML":
                                    ProgessIndicatorForm pif = new ProgessIndicatorForm(url: "", fileName);
                                    pif.ExportImportDataType     = ExportImportDataType.SpeciesNames;
                                    pif.ExportImportDeleteAction = ExportImportDeleteAction.ActionExport;
                                    pif.Show(this);
                                    int r = await Names.ExportSpeciesNamesAsync(fileName);

                                    break;

                                case ".txt":
                                    break;

                                case ".csv":
                                    break;
                                }
                            }
                        }
                    }
                }
                break;

            case "tbImport":
                using (ExportImportDialogForm edf = new ExportImportDialogForm(ExportImportDataType.SpeciesNames, ExportImportDeleteAction.ActionImport))
                {
                    edf.ShowDialog(this);
                    if (edf.DialogResult == DialogResult.OK)
                    {
                        ExportImportDataType result = edf.Selection;
                        if (result == ExportImportDataType.SpeciesNames)
                        {
                            FileDialogHelper.Title        = "Provide filename for imported species name";
                            FileDialogHelper.DialogType   = FileDialogType.FileOpen;
                            FileDialogHelper.DataFileType = DataFileType.Text | DataFileType.XML | DataFileType.CSV | DataFileType.HTML;
                            FileDialogHelper.ShowDialog();
                            var fileName = FileDialogHelper.FileName;
                            if (fileName.Length > 0)
                            {
                                ProgessIndicatorForm pif;    // = new ProgessIndicatorForm();
                                switch (Path.GetExtension(fileName))
                                {
                                case ".htm":
                                case ".html":
                                    using (HTMLTableSelectColumnsForm htmlColForm = new HTMLTableSelectColumnsForm(fileName, CatchNameDataType.CatchSpeciesName))
                                    {
                                        DialogResult dr = htmlColForm.ShowDialog(this);

                                        if (dr == DialogResult.OK)
                                        {
                                            pif = new ProgessIndicatorForm(url: "", fileName);
                                            pif.ExportImportDataType     = ExportImportDataType.SpeciesNames;
                                            pif.ExportImportDeleteAction = ExportImportDeleteAction.ActionImport;
                                            pif.Show(this);
                                            int r1 = await Names.ImportSpeciesNamesAsync(fileName, htmlColForm.SpeciesNameColumn);

                                            lvNames.Visible = false;
                                            lvNames.Items.Clear();
                                            FillListNames();
                                            SizeColumns(lvNames, false);
                                            lvNames.Visible       = true;
                                            lblListViewLabel.Text = "List of species names";
                                            //GetImportedRows(fileName, htmlColForm.SpeciesNameColumn);
                                        }
                                    }
                                    break;

                                case ".xml":
                                    pif = new ProgessIndicatorForm(url: "", fileName);
                                    pif.ExportImportDataType     = ExportImportDataType.SpeciesNames;
                                    pif.ExportImportDeleteAction = ExportImportDeleteAction.ActionImport;
                                    pif.Show(this);
                                    int r = await Names.ImportSpeciesNamesAsync(fileName, null);

                                    lvNames.Visible = false;
                                    lvNames.Items.Clear();
                                    FillListNames();
                                    SizeColumns(lvNames, false);
                                    lvNames.Visible       = true;
                                    lblListViewLabel.Text = "List of species names";
                                    break;
                                }
                            }
                        }
                    }
                }
                break;
            }
        }
        private bool ImportData(ExportImportDataType dataType, string title)
        {
            var result = Names.Languages;

            FileDialogHelper.Title        = title;
            FileDialogHelper.DialogType   = FileDialogType.FileOpen;
            FileDialogHelper.DataFileType = DataFileType.Text | DataFileType.XML | DataFileType.HTML;
            DialogResult dr = FileDialogHelper.ShowDialog();

            if (dr == DialogResult.OK && FileDialogHelper.FileName.Length > 0)
            {
                var fileName = FileDialogHelper.FileName;
                switch (dataType)
                {
                case ExportImportDataType.CatchNameAll:
                    switch (Path.GetExtension(fileName).ToLower())
                    {
                    case ".xml":
                        GetCatchNamesAllXMLAsync(fileName);
                        break;
                    }
                    break;

                case ExportImportDataType.CatchLocalNames:
                    GetImportedRows(fileName, ExportImportDataType.CatchLocalNames);
                    break;

                case ExportImportDataType.CatchLocalNameSpeciesNamePair:

                    switch (Path.GetExtension(fileName))
                    {
                    case ".htm":
                    case ".html":
                        using (HTMLTableSelectColumnsForm htmlColForm = new HTMLTableSelectColumnsForm(fileName, CatchNameDataType.CatchSpeciesLocalNamePair))
                        {
                            DialogResult dr1 = htmlColForm.ShowDialog(this);
                            if (dr1 == DialogResult.OK)
                            {
                                ProgessIndicatorForm pif = new ProgessIndicatorForm(url: "", fileName);
                                pif.ExportImportDataType     = ExportImportDataType.CatchLocalNameSpeciesNamePair;
                                pif.ExportImportDeleteAction = ExportImportDeleteAction.ActionImport;
                                pif.Show(this);
                                GetImportedRowsAsync(fileName, htmlColForm.SpeciesNameColumn, htmlColForm.LocalNameColumn, htmlColForm.LanguageColumn);
                            }
                        }
                        break;

                    default:
                        GetImportedRows(fileName, ExportImportDataType.CatchLocalNameSpeciesNamePair);
                        break;
                    }
                    break;

                case ExportImportDataType.LocalNameLanguages:
                    var savedLanguages = Names.ImportLanguages(fileName);
                    MessageBox.Show($"{savedLanguages} languages saved to the database");
                    break;
                }
                SetTreeItem("root");
                SetUI();

                return(true);
            }
            else
            {
                return(false);
            }
        }