コード例 #1
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();
        }
コード例 #2
0
        /// <summary>
        /// 生成数据库文件
        /// </summary>
        /// <param name="path"></param>
        public void generateDbFile(String path)
        {
            //创建数据库,并打开连接
            SQLiteConnection connection = new SQLiteConnection("Data Source=" + path);

            connection.Open();

            /******************************** 创建table *********************************/
            //按照最新标准建立数据库
            SQLiteCommand cmd = connection.CreateCommand();



            //尝试使用事物进行数据库操作
            DbTransaction trans = connection.BeginTransaction();

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

                //将Vector中的数据写进去
                foreach (Vector vector in prjItem.getVectorParser().getVectorList())
                {
                    //将每个Vector中的Point放进去
                    for (int i = 0; i < vector.getPointList().Count; i++)
                    {
                        Point point = vector.getPointList()[i];
                        cmd.CommandText = "INSERT INTO Vector (name, longitude, latitude, orderInVector) "
                                          + "VALUES "
                                          + "("
                                          + "'" + vector.getContent() + "', "
                                          + "'" + point.getLongitude() + "', "
                                          + "'" + point.getLatitude() + "', "
                                          + "'" + i + "'"
                                          + ")";
                        cmd.ExecuteNonQuery();
                    }
                }
                //提交事务
                trans.Commit();
            }
            catch (Exception e)
            {
                trans.Rollback(); //回滚事务
            }

            //释放资源
            cmd.Dispose();
            connection.Close();



            MessageBox.Show("文件生成成功", "提示");
        }