private void MapPath_Click(object sender, RoutedEventArgs e)
 {
     //CAD文件转换所得xml文件
     if (MapPath_comboBox.SelectedIndex == 0)
     {
         OpenFileDialog dialog = new OpenFileDialog();
         dialog.InitialDirectory = "d:\\";
         dialog.RestoreDirectory = true;
         dialog.Filter           = "Xml文件 (*.xml) | *.xml";
         if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
         {
             MapPath_textBox.Text = dialog.FileName;
             mapPath    = dialog.FileName;
             cadXmlFile = new CadXmlFile(mapPath);
         }
     }
     //数字地图
     else if (MapPath_comboBox.SelectedIndex == 1)
     {
         FolderBrowserDialog dialog = new FolderBrowserDialog();
         if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
         {
             string path = dialog.SelectedPath;
             if (!PrjItem.isDirectoryValid(path))
             {
                 System.Windows.MessageBox.Show("当前路径不符合数字地图文件要求", "错误");
                 return;
             }
             prjItem = new PrjItem(path);
             //获取选中的文件夹
             this.MapPath_textBox.Text = dialog.SelectedPath;
             mapPath = dialog.SelectedPath;
         }
     }
 }
示例#2
0
        //写入数字地图的信息
        public void WriteDigitalMap(PrjItem prjItem)
        {
            Int16 i, j;

            dbFileConnection.Open();
            cmd   = dbFileConnection.CreateCommand();
            trans = dbFileConnection.BeginTransaction();

            try
            {
                //将text数据写进去
                foreach (TextPoint textPoint in prjItem.getTextParser().getTextPointList())
                {
                    cmd.CommandText = "INSERT INTO Text VALUES " +
                                      "("
                                      + "'" + "" + "', "
                                      + "'" + textPoint.getLongitude() + "', "
                                      + "'" + textPoint.getLatitude() + "', "
                                      + "'" + textPoint.getContent() + "', "
                                      + "'" + textPoint.getType() + "'"
                                      + ")";
                    cmd.ExecuteNonQuery();
                }

                //将Poly数据写进去
                j = 0;
                foreach (Vector vector in prjItem.getVectorParser().getVectorList())
                {
                    //将每个Vector中的Point放进去
                    for (i = 0; i < vector.getPointList().Count; i++)
                    {
                        Point point = vector.getPointList()[i];

                        cmd.CommandText = "INSERT INTO Poly (layer, id, orderId, longitude, latitude, name) "
                                          + "VALUES "
                                          + "("
                                          + "'" + "" + "', "
                                          + "'" + j + "', "
                                          + "'" + i + "', "
                                          + "'" + point.getLongitude() + "', "
                                          + "'" + point.getLatitude() + "', "
                                          + "'" + vector.getContent() + "'"
                                          + ")";
                        cmd.ExecuteNonQuery();
                    }
                    j++;
                }
                //提交事务
                trans.Commit();
            }
            catch (Exception e)
            {
                trans.Rollback(); //回滚事务
            }

            cmd.Dispose();
            dbFileConnection.Close();
        }
示例#3
0
        //初始化View---事件
        private void initView()
        {
            //获取数字地图文件路径
            btnChooseDigitalMap.Click += delegate
            {
                FolderBrowserDialog dialog = new FolderBrowserDialog();
                if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    string path = dialog.SelectedPath;
                    if (!PrjItem.isDirectoryValid(path))
                    {
                        System.Windows.MessageBox.Show("当前路径不符合数字地图文件要求", "错误");
                        return;
                    }
                    //获取选中的文件夹
                    this.tboxDigitalPath.Text = dialog.SelectedPath;
                    digitalFilePath           = dialog.SelectedPath;
                }
            };

            //获取输出路径
            btnChooseOutputPath.Click += delegate(object sender, RoutedEventArgs args)
            {
                var saveFileDialog = new SaveFileDialog();
                saveFileDialog.Filter = "数据库文件|*.db";
                if (saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    //获取得到的path
                    var path = saveFileDialog.FileName;
                    if (path != null && path.Length != 0)
                    {
                        outputPath          = path;
                        tboxOutputPath.Text = path;
                    }
                }
            };

            //生成数据库文件的按钮
            this.btnGenerateDBFile.Click += delegate(object sender, RoutedEventArgs args)
            {
                //需要先选择数字地图文件夹
                if (digitalFilePath == null)
                {
                    System.Windows.MessageBox.Show("请先选择数字地图文件夹!");
                    return;
                }
                if (outputPath == null)
                {
                    System.Windows.MessageBox.Show("请先选择输出路径!");
                    return;
                }
                //启动线程---生成数据库文件
                Thread thread = new Thread(new ThreadStart(generateDbFile));
                thread.Start();
            };
        }
示例#4
0
        /// <summary>
        /// 生成数据库文件(在新线程中执行)
        /// </summary>
        private void generateDbFile()
        {
            //让progressbar显示出来
            Action <System.Windows.Controls.ProgressBar, bool> updataAction = new Action <System.Windows.Controls.ProgressBar, bool>(updataProgressBar);

            this.pbDigitalMapConvert.Dispatcher.BeginInvoke(updataAction, pbDigitalMapConvert, true);
            if (prjItem == null)
            {
                prjItem = new PrjItem(digitalFilePath);
            }
            if (dbHelper == null)
            {
                dbHelper = new DbHelper(prjItem);
            }
            dbHelper.generateDbFile(outputPath);
            this.pbDigitalMapConvert.Dispatcher.BeginInvoke(updataAction, pbDigitalMapConvert, false);
        }
示例#5
0
 /// <summary>
 /// 传入一个PrjItem的构造方法
 /// </summary>
 /// <param name="prjItem"></param>
 public DbHelper(PrjItem prjItem)
 {
     this.prjItem = prjItem;
 }
示例#6
0
 /// <summary>
 /// 传入一个PrjItem的构造方法
 /// </summary>
 /// <param name="prjItem"></param>
 public DbHelper(PrjItem prjItem)
 {
     this.prjItem = prjItem;
 }