private void OnToolbar_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            switch (e.ClickedItem.Name)
            {
            case "tsButtonXY":
                var g25MouseCoordForm = Grid25CoordinateForm.GetInstance(global.MappingForm.MapControl, _grid25MajorGrid);
                if (g25MouseCoordForm.Visible)
                {
                    g25MouseCoordForm.BringToFront();
                }
                else
                {
                    g25MouseCoordForm.Show(this);
                }
                break;

            case "tsButtonMBRs":
                break;

            //retrieve fishing grid boundaries and shows them on the map form
            case "tsButtonRetrieve":
                var folderBrowser = new FolderBrowserDialog();
                folderBrowser.ShowNewFolderButton = true;
                folderBrowser.SelectedPath        = SaveMapForm.GetSavedMapsFolder();
                folderBrowser.Description         = "Locate folder containing saved fishing ground grid maps";
                DialogResult result = FolderBrowserLauncher.ShowFolderBrowser(folderBrowser);
                if (result == DialogResult.OK)
                {
                    SaveMapForm.SetSavedMapsFolder(folderBrowser.SelectedPath);
                    SetupDictionary();
                    _grid25MajorGrid.ShowGridBoundaries(folderBrowser.SelectedPath, _utmZone, _labelAndGridProperties);
                }
                break;

            //Saves fishing grids either as shapefile or image file
            case "tsButtonSaveImage":
            case "tsButtonSaveShapefile":
                if (txtMapTitle.Text.Length > 0 && _grid25MajorGrid.HasGrid)
                {
                    RedoGridLabel();
                    using (var saveForm = new SaveMapForm(this))
                    {
                        saveForm.SaveType(SaveAsShapefile: e.ClickedItem.Name == "tsButtonSaveShapefile");
                        saveForm.MapTitle = txtMapTitle.Text;
                        saveForm.ShowDialog(this);
                        if (saveForm.DialogResult == DialogResult.OK)
                        {
                            _hasUnsavedMap = false;
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Please provide map title and fishing grid", "Validation error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                break;

            case "tsButtonFitMap":
                _grid25MajorGrid.FitGridToMap();
                break;

            case "tsButtonExit":
                if (!_hasUnsavedMap)
                {
                    Close();
                }
                else
                {
                    if (MessageBox.Show("You have not saved the map. Are you sure you still want to close?",
                                        "Close this window", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        Close();
                    }
                }
                break;
            }
        }
示例#2
0
        private void OnButton_Click(object sender, EventArgs e)
        {
            switch (((Button)sender).Name)
            {
            case "btnOK":
                if (txtSave.Text.Length > 0)
                {
                    if (_saveAsShapefile)
                    {
                        FolderBrowserDialog fbd = new FolderBrowserDialog();
                        fbd.Description  = "Select folder to save fishing ground grid map";
                        fbd.SelectedPath = GetSavedMapsFolder();
                        DialogResult result = FolderBrowserLauncher.ShowFolderBrowser(fbd);
                        if (result == DialogResult.OK && fbd.SelectedPath.Length > 0)
                        {
                            SetSavedMapsFolder(fbd.SelectedPath);
                            if (!_parentForm.Grid25MajorGrid.Save($@"{fbd.SelectedPath}\{txtSave.Text}"))
                            {
                                Logger.Log("Not all grid25 shapefiles were saved.", "Grid25SaveForm", "OnButton_Click");
                            }
                            else
                            {
                                DialogResult = DialogResult.OK;
                            }
                        }
                    }
                    else
                    {
                        if (_fileName.Length > 0 &&
                            txtSave.Text.Length > 0 &&
                            int.Parse(txtSave.Text) <= (int)global.MappingForm.SuggestedDPI)
                        {
                            if (global.MappingForm.SaveMapToImage(int.Parse(txtSave.Text), _fileName, maintainOnePointLineWidth: true))
                            {
                                Close();
                            }
                        }
                        else
                        {
                            SaveFileDialog sfd = new SaveFileDialog();
                            sfd.Title            = "Provide file name of image file";
                            sfd.Filter           = "jpeg|*.jpg|tiff|*.tif";
                            sfd.FilterIndex      = 2;
                            sfd.AddExtension     = true;
                            sfd.InitialDirectory = GetSavedMapsFolder();
                            DialogResult result = sfd.ShowDialog();
                            if (result == DialogResult.OK && sfd.FileName.Length > 0)
                            {
                                _fileName = sfd.FileName;
                                if (global.MappingForm.SaveMapToImage(int.Parse(txtSave.Text), _fileName, maintainOnePointLineWidth: true))
                                {
                                    Close();
                                }
                                else
                                {
                                    if (global.MappingForm.SuggestedDPI > 0)
                                    {
                                        txtSave.Text = ((int)global.MappingForm.SuggestedDPI).ToString();
                                    }
                                    else

                                    {
                                        Logger.Log("Was not able to save map to image.", "Grid25SaveForm", "OnButton_Click SaveMapToImage");
                                    }
                                }
                            }
                        }
                    }
                }
                break;

            case "btnCancel":
                DialogResult = DialogResult.Cancel;
                break;
            }
        }