Exemple #1
0
        private void saveMapFileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if ((subViewControl1.myComponents.MapList == null) ||
                (subViewControl1.myComponents.MapList.Count == 0))
            {
                return;
            }

            FileChooserDialog fcd = new FileChooserDialog("Choose the file to save",
                                                          this,
                                                          FileChooserAction.Save,
                                                          "Cancel", ResponseType.Cancel,
                                                          "Save", ResponseType.Accept);

            fcd.CurrentName = "test.map";
            fcd.Filter      = new FileFilter();
            fcd.Filter.AddPattern("*.map");

            if (fcd.Run() == (int)ResponseType.Accept)
            {
                List <string> textList = new List <string>();

                bool ret = RmAddressMap.Convert(textList, subViewControl1.myComponents.MapList);

                if (ret == true)
                {
                    try
                    {
                        System.IO.StreamWriter sw = new System.IO.StreamWriter(fcd.Filename,
                                                                               false,
                                                                               System.Text.Encoding.GetEncoding("utf-8"));

                        foreach (var item in textList)
                        {
                            sw.WriteLine(item);
                        }

                        sw.Close();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.ShowWarning(ex.Message);
                    }
                }
            }

            fcd.Destroy();
        }
Exemple #2
0
        private void saveMapFileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Title = "Save Map File";
            //sfd.InitialDirectory = @"D:\";
            sfd.FileName = "test.rmmap";
            sfd.Filter   =
                "RM Map File(*.rmmap)|*.rmmap|All Files(*.*)|*.*";
            sfd.FilterIndex = 1;
            if (!string.IsNullOrEmpty(pathMapFileName))
            {
                sfd.InitialDirectory = System.IO.Path.GetDirectoryName(pathMapFileName);
            }

            if (sfd.ShowDialog() == DialogResult.OK)
            {
                List <string> textList = new List <string>();

                if (RmAddressMap.Convert(textList, subViewCtrl.MapList))
                {
                    try
                    {
                        using (System.IO.StreamWriter sw = new System.IO.StreamWriter(sfd.FileName, false, Encoding.GetEncoding("utf-8")))
                        {
                            foreach (var item in textList)
                            {
                                sw.WriteLine(item);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }

            sfd.Dispose();
        }