Esempio n. 1
0
 //Update Photo in DB
 private void insertPicture()
 {
     if (fileName != "")
     {
         //code from http://stackoverflow.com/questions/779211/programmatically-managing-microsoft-access-attachment-typed-field-with-net
         DBEngine  dbe = new DBEngine();
         Database  db  = dbe.OpenDatabase("PineSpringsPottery.accdb", false, false, "");
         Recordset rs  = db.OpenRecordset("SELECT * FROM PATTERN WHERE PATTERN.PatternNo = " + currentPattern.patternNo, RecordsetTypeEnum.dbOpenDynaset, 0, LockTypeEnum.dbOptimistic);
         rs.MoveFirst();
         rs.Edit();
         Recordset2 rs2 = (Recordset2)rs.Fields["PatternPicture"].Value;
         //delete previous pics
         if (rs2.RecordCount != 0)
         {
             rs2.Delete();
         }
         //if not just deleting previous, add new
         if (fileName != "delete")
         {
             rs2.AddNew();
             Field2 f2 = (Field2)rs2.Fields["FileData"];
             f2.LoadFromFile(fileName);
             rs2._30_Update();
         }
         rs2.Close();
         rs._30_Update();
         rs.Close();
     }
 }
Esempio n. 2
0
 //Готовит строку для записи значения и выкидывает исключения, если нужно
 private void BeginEdit()
 {
     if (!_isEdit)
     {
         Recordset.Edit();
         _isEdit = true;
     }
 }
Esempio n. 3
0
        public void UpdateValue(Field aField, string strValue)
        {
            Recordset rs = Document;

            rs.Edit();
            aField.Value = strValue;
            rs.Update((int)UpdateTypeEnum.dbUpdateRegular, false);
        }
Esempio n. 4
0
        private void btn_Commit_Click(object sender, EventArgs e)
        {
            Recordset objRt = null;

            try
            {
                if (chkTheme.SelectedItem == null)
                {
                    m_Application.MessageBox.Show(Message);
                    return;
                }
                Layer3DDataset layer3DDataset = (chkTheme.SelectedItem as Label).Tag as Layer3DDataset;
                objRt = (layer3DDataset.Dataset as DatasetVector).GetRecordset(false, CursorType.Dynamic);
                foreach (DataGridViewRow row in dg_Data.Rows)
                {
                    int id = Convert.ToInt32(row.HeaderCell.Value);
                    if (objRt.SeekID(id) && objRt.Edit())
                    {
                        foreach (DataGridViewColumn column in dg_Data.Columns)
                        {
                            switch (objRt.GetFieldInfos()[column.Name].Type)
                            {
                            case FieldType.WText:
                                objRt.SetFieldValue(column.Name, Convert.ToString(row.Cells[column.Name].Value));
                                break;

                            case FieldType.Double:
                                objRt.SetFieldValue(column.Name, Convert.ToDouble(row.Cells[column.Name].Value));
                                break;

                            case FieldType.Int32:
                                objRt.SetFieldValue(column.Name, Convert.ToInt32(row.Cells[column.Name].Value));
                                break;
                            }
                        }
                        objRt.Update();
                    }
                }
                m_SceneControl.Refresh();
            }
            catch (Exception ex)
            {
                Log.OutputBox(ex);
            }
            finally
            {
                if (objRt != null)
                {
                    objRt.Close();
                    objRt.Dispose();
                }
            }
        }
Esempio n. 5
0
        private void btn_Save_Click(object sender, EventArgs e)
        {
            Recordset objRt = null;

            try
            {
                btn_Draw.Enabled = true;
                objRt            = (m_Application.Workspace.Datasources["Resource"].Datasets["ArtCraftTable"] as DatasetVector).GetRecordset(false, CursorType.Dynamic);
                switch (m_Type)
                {
                case WorkflowEditType.New:
                    Dictionary <string, object> dic = new Dictionary <string, object>();
                    dic.Add("CraftName", txt_Name.Text.Trim());
                    dic.Add("Note", rtb_Description.Text.Equals(m_Tip) ? "" : rtb_Description.Text);
                    dic.Add("CraftID", (objRt.RecordCount + 1).ToString());
                    dic.Add("PlaySpeed", txt_PlaySpeed.Text);
                    dic.Add("Symbol", btn_SelectColor.Text + ',' + btn_SelectColor.Tag);
                    objRt.AddNew(null, dic);
                    objRt.Update();
                    break;

                case WorkflowEditType.Edit:
                    objRt.Edit();
                    objRt.SetFieldValue("CraftName", txt_Name.Text.Trim());
                    objRt.SetFieldValue("Note", rtb_Description.Text.Equals(m_Tip) ? "" : rtb_Description.Text);
                    objRt.SetFieldValue("CraftID", objRt.RecordCount + 1);
                    objRt.SetFieldValue("PlaySpeed", txt_PlaySpeed.Text);
                    objRt.SetFieldValue("Symbol", btn_SelectColor.Text + ',' + btn_SelectColor.Tag);
                    objRt.Update();
                    break;
                }

                Layer3DDataset layer = m_SceneControl.Scene.Layers[txt_Name.Text + "@SpaceData"] as Layer3DDataset;
                for (int i = 0; i < (layer.Theme as Theme3DUnique).Count; i++)
                {
                    Theme3DUniqueItem item = (layer.Theme as Theme3DUnique)[i];
                    item.IsVisible = false;
                }
                m_Application.MessageBox.Show("保存成功!");
            }
            catch (Exception ex)
            {
                Log.OutputBox(ex);
            }
            finally
            {
                if (objRt != null)
                {
                    objRt.Close();
                    objRt.Dispose();
                }
            }
        }
Esempio n. 6
0
        private void btnGetCamera_Click(object sender, EventArgs e)
        {
            Recordset objRt = null;

            try
            {
                if (dg_Data.SelectedRows.Count == 0)
                {
                    m_Application.MessageBox.Show("未选中数据!");
                    return;
                }
                DataGridViewRow  row  = dg_Data.SelectedRows[0];
                ResourceTypeData data = cmbDeviceType.SelectedItem as ResourceTypeData;
                objRt = (m_Application.Workspace.Datasources["Resource"].Datasets[data.DatasetName] as DatasetVector).GetRecordset(false, CursorType.Dynamic);
                if (objRt.SeekID(Convert.ToInt32(row.Tag)) && objRt.Edit())
                {
                    objRt.SetFieldValue("Longitude", m_SceneControl.Scene.Camera.Longitude);
                    objRt.SetFieldValue("Latitude", m_SceneControl.Scene.Camera.Latitude);
                    objRt.SetFieldValue("Altitude", m_SceneControl.Scene.Camera.Altitude);
                    objRt.SetFieldValue("Heading", m_SceneControl.Scene.Camera.Heading);
                    objRt.SetFieldValue("Tilt", m_SceneControl.Scene.Camera.Tilt);

                    if (objRt.Update())
                    {
                        m_Application.MessageBox.Show("视角保存成功!");
                    }
                    else
                    {
                        m_Application.MessageBox.Show("视角保存失败!");
                    }
                }
            }
            catch (Exception ex)
            {
                Log.OutputBox(ex);
            }
            finally
            {
                if (objRt != null)
                {
                    objRt.Close();
                    objRt.Dispose();
                }
            }
        }
Esempio n. 7
0
 //Готовит строку для записи значения и выкидывает исключения, если нужно
 private void BeginEdit()
 {
     if (!_isEdit)
     {
         try
         {
             Recordset.Edit();
         }
         catch (COMException ex)
         {
             if (ex.Message.StartsWith("Превышено число блокировок") || ex.Message.StartsWith("Обновление невозможно"))
             {
                 Thread.Sleep(1);
                 Recordset.Edit();
             }
         }
         _isEdit = true;
     }
 }
Esempio n. 8
0
        private void btnSetCamera_Click(object sender, EventArgs e)
        {
            Recordset objRt = null;

            try
            {
                if (lst_Items.SelectedItem == null)
                {
                    m_Application.MessageBox.Show("请选择分段数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                int id = Convert.ToInt32((lst_Items.SelectedItem as Label).Tag);
                objRt = (m_Application.Workspace.Datasources["SpaceData"].Datasets[txt_Name.Text.Trim()] as DatasetVector).GetRecordset(false, CursorType.Dynamic);
                objRt.MoveTo(id);
                objRt.Edit();
                objRt.SetFieldValue("Longitude", m_SceneControl.Scene.Camera.Longitude.ToString());
                objRt.SetFieldValue("Latitude", m_SceneControl.Scene.Camera.Latitude.ToString());
                objRt.SetFieldValue("Altitude", m_SceneControl.Scene.Camera.Altitude.ToString());
                objRt.SetFieldValue("Tilt", m_SceneControl.Scene.Camera.Tilt.ToString());
                objRt.SetFieldValue("Heading", m_SceneControl.Scene.Camera.Heading.ToString());
                objRt.SetFieldValue("Time", txt_PlaySpeed.Text);
                objRt.Update();

                (m_lstItems[lst_Items.SelectedIndex] as Label).Text = (lst_Items.SelectedItem as Label).Text.Split('(')[0];

                lst_Items.DataSource    = null;
                lst_Items.DataSource    = m_lstItems;
                lst_Items.DisplayMember = "Text";
            }
            catch (Exception ex)
            {
                Log.OutputBox(ex);
            }
            finally
            {
                if (objRt != null)
                {
                    objRt.Close();
                    objRt.Dispose();
                }
            }
        }
        private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                Recordset rec      = mDataVec.GetRecordset(false, CursorType.Dynamic);
                int       Rowindex = e.RowIndex;                                         //获取修改记录的行索引
                int       Colindex = e.ColumnIndex;                                      //获取修改记录的列索引

                rec.MoveTo(Rowindex);                                                    //记录集移到当前索引
                object changevalue = dataGridView1.Rows[Rowindex].Cells[Colindex].Value; //获取修改之后的cell值
                if (!rec.Dataset.FieldInfos[Colindex].IsSystemField)
                {
                    rec.Edit();//编辑记录集中该行记录
                    rec.SetFieldValue(Colindex, changevalue);
                    rec.Update();
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 10
0
        static void Main(string[] args)
        {
            var sw = new System.Diagnostics.Stopwatch();

            sw.Start();
            // This code requires the following COM reference in your project:
            //     Microsoft DAO 3.6 Object Library
            //
            var       dbe = new DBEngine();
            Database  db  = dbe.OpenDatabase(@"C:\Users\Gord\Desktop\speed.mdb");
            Recordset rst = db.OpenRecordset(
                "SELECT TOP 4001 ID FROM tblBooks ORDER BY ID",
                RecordsetTypeEnum.dbOpenSnapshot);

            rst.MoveLast();
            int startID = rst.Fields["ID"].Value;

            rst.Close();
            rst = db.OpenRecordset(
                String.Format(
                    "SELECT TOP 10000 Title FROM tblBooks WHERE ID >= {0} ORDER BY ID",
                    startID),
                RecordsetTypeEnum.dbOpenDynaset);
            int i = 1;

            while (!rst.EOF)
            {
                rst.Edit();
                rst.Fields["Title"].Value = String.Format("Book {0}", i++);
                rst.Update();
                rst.MoveNext();
            }
            rst.Close();
            sw.Stop();
            Console.WriteLine(String.Format("{0:0.0} seconds", sw.ElapsedMilliseconds / 1000.0));
        }
Esempio n. 11
0
        //private void CreatePointDataset(string tableName)
        //{
        //    Workspace workspace = new Workspace();
        //    DatasourceConnectionInfo info = new DatasourceConnectionInfo();
        //    Datasource datasource = GetDbDatasource(workspace, info);
        //    var datasetVector = (DatasetVector)datasource.Datasets[tableName];
        //    if (datasetVector == null)
        //    {
        //        CreateDataset(datasource, DatasetType.Point, tableName);
        //    }
        //    //只取了数据结构,没有取数据
        //    var recordset = datasetVector.GetRecordset(true, SuperMap.Data.CursorType.Dynamic);
        //    recordset.Edit();
        //    recordset.fi
        //}

        private void InsertRecordSetToDb(string shapeFieldName, string tableName)
        {
            Workspace workspace           = new Workspace();
            DatasourceConnectionInfo info = new DatasourceConnectionInfo();
            var filePath = $"{Directory.GetCurrentDirectory()}\\{Guid.NewGuid().ToString()}";
            var files    = new List <string> {
                $"{filePath}.udb", $"{filePath}.udd"
            };

            Datasource datasource = GetDbDatasource(workspace, info);

            if (datasource != null)
            {
                //临时数据源
                DatasourceConnectionInfo tempInfo = new DatasourceConnectionInfo();
                //设置数据源连接的引擎类型
                tempInfo.EngineType = EngineType.UDB;
                tempInfo.Alias      = tableName;

                tempInfo.Server = filePath;
                // 创建/打开数据库数据源
                Datasource tempDatasource = workspace.Datasources.Create(tempInfo);
                Recordset  recordset = null, tempRecordset = null;
                if (tempDatasource != null)
                {
                    ImportResult result = ImportShpToTemp(shapeFieldName, tempDatasource, tableName);
                    if (result.FailedSettings.Length == 0)
                    {
                        Console.WriteLine($"导入{shapeFieldName}成功!");
                        try
                        {
                            for (int index = 0; index < tempDatasource.Datasets.Count; index++)
                            {
                                DatasetVector tempDatasetVector = (DatasetVector)tempDatasource.Datasets[index];
                                tempRecordset = tempDatasetVector.GetRecordset(false, SuperMap.Data.CursorType.Dynamic);
                                //没有数据
                                if (tempRecordset.RecordCount == 0)
                                {
                                    continue;
                                }
                                var tempFieldInfos = tempDatasetVector.FieldInfos;
                                //注意:数据集是手工录入的,不是超图sdk生成的,所以不能删除数据集
                                //如果更新数据集中的记录,则应该操纵记录集(删除、修改、新增)
                                var datasetVector = (DatasetVector)datasource.Datasets[tableName];
                                if (datasetVector == null)
                                {
                                    CreateDataset(datasource, DatasetType.Point, tableName);
                                    //throw new Exception($"不存在数据集名称为{tableName}的数据集!");
                                }
                                //删去之前的所有记录
                                //datasetVector.GetRecordset(false, SuperMap.Data.CursorType.Dynamic).DeleteAll();
                                //只取了数据结构,没有取数据
                                recordset = datasetVector.GetRecordset(true, SuperMap.Data.CursorType.Dynamic);
                                //设置批量提交
                                // 设置批量更新的限度为5000,注意一定要在开始批量更新前设置MaxRecordCount!
                                recordset.Batch.MaxRecordCount = 500;
                                // 开始批量更新,当添加到设置的MaxRecordCount的下一条记录时,将会将MaxRecordCount条记录自动提交到数据库中。
                                recordset.Batch.Begin();

                                tempRecordset.MoveFirst();
                                //遍历临时记录集
                                for (Int32 i = 0; i < tempRecordset.RecordCount; i++)
                                {
                                    //往mysql新增记录
                                    SuperMap.Data.Geometry geoPoint = tempRecordset.GetGeometry();
                                    recordset.AddNew(geoPoint);
                                    //SeekID:在记录中搜索指定 ID 号的记录,并定位该记录为当前记录。
                                    recordset.MoveLast();
                                    foreach (SuperMap.Data.FieldInfo fileInfo in tempFieldInfos)
                                    {
                                        if (!fileInfo.IsSystemField && IsHaveField(datasetVector.FieldInfos, fileInfo.Name))
                                        {
                                            recordset.Edit();
                                            recordset.SetFieldValue(fileInfo.Name, tempRecordset.GetFieldValue(fileInfo.Name));
                                            Object valueID = recordset.GetFieldValue(fileInfo.Name);
                                        }
                                    }

                                    //处理业务数据

                                    tempRecordset.MoveNext();

                                    //recordset.Update();
                                }

                                // 使用批量更新的Update,提交没有自动提交的记录
                                recordset.Batch.Update();
                            }
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                        finally
                        {
                            //示例程序BatchAdd说明要释放记录集
                            if (recordset != null)
                            {
                                recordset.Dispose();
                            }
                            if (tempRecordset != null)
                            {
                                tempRecordset.Dispose();
                            }
                        }
                    }
                    else
                    {
                        throw new Exception($"导入{shapeFieldName}失败!");
                    }
                }
                else
                {
                    throw new Exception($"创建临时数据源{filePath}失败!");
                }
            }

            // 释放工作空间资源
            info.Dispose();
            workspace.Dispose();


            foreach (var file in files)
            {
                if (File.Exists(file))
                {
                    File.Delete(file);
                }
            }

            MessageBox.Show("成功!");
        }
Esempio n. 12
0
        public void run()
        {
            Recordset rc = dv.GetRecordset(false, CursorType.Dynamic);

            Dictionary <int, Feature> feas = rc.GetAllFeatures();

            foreach (KeyValuePair <int, Feature> item in feas)
            {
                GeoModel gm = item.Value.GetGeometry() as GeoModel;
                Console.WriteLine("==" + gm.Position + "==");

                GeoModel model = new GeoModel();
                model.Position = gm.Position;
                foreach (Mesh m in gm.Meshes)
                {
                    if (m.Material.TextureFile.Length > 1)
                    {
                        //Console.WriteLine(m.Material.TextureFile.ToString());
                        Point3Ds p3ds = new Point3Ds();

                        for (int i = 0; i < m.Vertices.Length; i += 3)
                        {
                            bool repition = false;
                            foreach (Point3D p in p3ds)
                            {
                                if (p.X == m.Vertices[i] && p.Y == m.Vertices[i + 1] && p.Z == m.Vertices[i + 2])
                                {
                                    repition = true;
                                }
                            }
                            if (!repition)
                            {
                                p3ds.Add(new Point3D(m.Vertices[i], m.Vertices[i + 1], m.Vertices[i + 2]));
                            }
                        }

                        foreach (Point3D p3d in p3ds)
                        {
                            Console.WriteLine(string.Format(" {0},{1},{2}", p3d.X, p3d.Y, p3d.Z));
                            scene.TrackingLayer.Add(new GeoPoint3D(p3d.X, p3d.Y, p3d.Z), "");
                        }
                        //model.Meshes.Add(MakeMeshPot(p3ds));
                        Mesh mesh = new Mesh(m);
                        mesh.Material.TextureFile = @".\78310a55b319ebc41f7810198326cffc1e171629.png";
                        model.Meshes.Add(mesh);


                        #region 写属性表
                        Dictionary <string, double> fields = new Dictionary <string, double>();
                        fields.Add("FaceMeshCenterX", model.Position.X);
                        fields.Add("FaceMeshCenterY", model.Position.Y);
                        fields.Add("FaceMeshCenterZ", model.Position.Z);
                        fields.Add("FaceMeshLx", p3ds.leftbottom().X);
                        fields.Add("FaceMeshLy", p3ds.leftbottom().Y);
                        fields.Add("FaceMeshLz", p3ds.leftbottom().Z);
                        fields.Add("FaceMeshUx", p3ds.rightup().X);
                        fields.Add("FaceMeshUy", p3ds.rightup().Y);
                        fields.Add("FaceMeshUz", p3ds.rightup().Z);


                        foreach (KeyValuePair <string, double> field in fields)
                        {
                            if (dv.FieldInfos.IndexOf(field.Key) < 0)
                            {
                                FieldInfo fieldInf = new FieldInfo(field.Key, FieldType.Double);
                                dv.FieldInfos.Add(fieldInf);
                            }

                            string fieldName  = field.Key;
                            double fieldValue = field.Value;
                            try
                            {
                                rc.SeekID(item.Value.GetID());
                                rc.Edit();
                                rc.SetFieldValue(fieldName, fieldValue);
                                rc.Update();
                            }
                            catch
                            {
                                Console.WriteLine("error!");
                            }
                            //Console.WriteLine(string.Format("{0},{1},{2}", item.GetID(), fieldName, fieldValue));
                        }
                        #endregion
                    }
                }
                Console.WriteLine("");

                model.ComputeBoundingBox();
                scene.TrackingLayer.Add(model, gm.Position.ToString());
                scene.Refresh();
            }
        }
Esempio n. 13
0
        private void seekExcel(string Name, DataTable dt, Recordset recordset, int m)
        {
            //Hashtable h1 = new Hashtable();//存储乡镇和GDP
            //Hashtable h2 = new Hashtable();//存储乡镇和人口
            //Hashtable h3 = new Hashtable();//存储乡镇和耕地面积
            bool next = false;
            try
            {
                //循环查找 乡镇和GDP装入h1中
                for (int seekXZ = 0; seekXZ < dt.Rows.Count; seekXZ++)
                {
                    for (int seekColumn = 0; seekColumn < dt.Columns.Count; seekColumn++)
                    {
                        string s = dt.Rows[seekXZ][seekColumn].ToString();
                        if (s == Name)
                        {
                            
                            double valueGDP = Convert.ToDouble(dt.Rows[seekXZ][seekColumn + 1]);
                            double valueAC = Convert.ToDouble(dt.Rows[seekXZ][seekColumn + 2]);
                            double valuePE = Convert.ToDouble(dt.Rows[seekXZ][seekColumn + 3]);
                            recordset.SeekID(m);
                            recordset.Edit();
                            recordset.SetDouble("生产总值", valueGDP);
                            recordset.Update();
                            recordset.SeekID(m);
                            recordset.Edit();
                            recordset.SetDouble("耕地面积", valueAC);
                            recordset.Update();
                            recordset.SeekID(m);
                            recordset.Edit();
                            recordset.SetDouble("人口总数", valuePE);
                            recordset.Update();
                            recordset.Refresh();
                            next = true;
                            break;
                        }
                        if (next)
                            break;
                    }
                    if (next)
                        break;
                }
                /*MessageBox.Show(valueGDP.ToString() + recordset.GetObject("GDP").ToString());

                            //continue;
                            for (int r = 0; r < dt.Rows.Count; r++)
                            {
                                string n = dt.Rows[r][seekColumn].ToString();
                                if (dt.Rows[r][seekColumn].ToString() == Name)
                                {
                                    for (int recircle = 0; recircle < dt.Columns.Count; recircle++)
                                    {
                                        if (dt.Columns[recircle].ColumnName == "生产总值")
                                        {
                                            recordset.SeekID(m);
                                            recordset.Edit();
                                            object valueGDP = dt.Rows[r][recircle];
                                            recordset.SetFieldValue("GDP", valueGDP);
                                            recordset.Update();
                                            MessageBox.Show(valueGDP.ToString() + recordset.GetObject("GDP").ToString());

                                        }
                                        else
                                            if (dt.Columns[recircle].ColumnName == "耕地面积")
                                            {
                                                recordset.SeekID(m);
                                                recordset.Edit();
                                                object valueAC = dt.Rows[r][recircle];
                                                recordset.SetFieldValue("耕地面积", valueAC);
                                                recordset.Update();

                                                MessageBox.Show(valueAC.ToString() + recordset.GetObject("耕地面积").ToString());

                                            }
                                            else if (dt.Columns[recircle].ColumnName == "人口总数")
                                            {
                                                recordset.SeekID(m);
                                                recordset.Edit();
                                                object valuePE = dt.Rows[r][recircle];
                                                recordset.SetFieldValue("总人口", valuePE);
                                                recordset.Update();
                                                MessageBox.Show(valuePE.ToString() + recordset.GetObject("总人口").ToString());

                                            }
                                            else
                                                continue;
                                    }
                                }
                            }

                        }*/


                //for (int i = 0; i < dt.Columns.Count; i++)
                //{
                //    if (dt.Columns[i].ColumnName == "乡镇名称")
                //    {

                //    }
                //}
                //}

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 14
0
        private void UpdateFieldValueTest(Recordset recordset, string xlsPath)
        {
            try
            {
                string[] sheetNameList = importTool.GetSheetNameList(xlsPath);
                DataTable dt = importTool.ExcelToDataTable(xlsPath , sheetNameList[0]);
               // DataTable dt = importTool.ExcelToDataTable(xlsPath, "6.5.1综合经济指标表");

                int length = recordset.RecordCount;
                if (length != 0)
                {

                    /*需求:根据乡镇名字确定更新数据
                     1、选择成行改变:1)循环判断工作表中name列的所有记录,是否等于属性表中name列的第一行的内容   
                                     2)记录工作表中的对应的行数h
                                     3)对数据集中特定字段逐行赋值*/
                    try
                    {
                        for (int m = 1; m <= length; m++)//行循环更新
                        {
                            recordset.SeekID(m);
                            recordset.Edit();
                            object name = recordset.GetObject("T_NAME");
                            seekExcel(name.ToString(), dt, recordset, m);

                        }

                        recordset.Update();

                        Msg("修改属性字段完成");
                    }
                    catch (Exception ex)
                    {
                        Msg(ex.Message);
                    }
                }
                else
                {
                    Msg("记录集中没有记录");
                }
            }
            catch (Exception ex)
            {
                Msg(ex.Message);
            }


        }
Esempio n. 15
0
        void addBox(DatasetVector dv, string file)
        {
            FileStream   f;
            StreamWriter sw;
            Recordset    rc = dv.GetRecordset(false, CursorType.Dynamic);

            Console.WriteLine(dv.Name + "\t::\t" + dv.Type.ToString() + "\t::\t" + dv.RecordCount);

            Dictionary <int, Feature> feas = rc.GetAllFeatures();

            f  = new FileStream(file, FileMode.OpenOrCreate);
            sw = new StreamWriter(f);

            foreach (Feature item in feas.Values)
            {
                Point3D lower, uper, center;

                if ((item.GetGeometry() as Geometry3D) != null)
                {
                    lower  = (item.GetGeometry() as Geometry3D).BoundingBox.Lower;
                    uper   = (item.GetGeometry() as Geometry3D).BoundingBox.Upper;
                    center = (item.GetGeometry() as Geometry3D).BoundingBox.Center;

                    sw.WriteLine(string.Format("{0},{1},{2},{3},{4},{5},{6}", item.GetID(), lower.X, lower.Y, lower.Z, uper.X, uper.Y, uper.Z));
                    if (!dv.IsOpen)
                    {
                        dv.Open();
                    }

                    Dictionary <string, double> fields = new Dictionary <string, double>();
                    fields.Add("Lx", lower.X);
                    fields.Add("Ly", lower.Y);
                    fields.Add("Lz", lower.Z);
                    fields.Add("Ux", uper.X);
                    fields.Add("Uy", uper.Y);
                    fields.Add("Uz", uper.Z);


                    foreach (KeyValuePair <string, double> field in fields)
                    {
                        if (dv.FieldInfos.IndexOf(field.Key) < 0)
                        {
                            FieldInfo fieldInf = new FieldInfo(field.Key, FieldType.Double);
                            dv.FieldInfos.Add(fieldInf);
                        }

                        string fieldName  = field.Key;
                        double fieldValue = field.Value;
                        try
                        {
                            rc.SeekID(item.GetID());
                            rc.Edit();
                            rc.SetFieldValue(fieldName, fieldValue);
                            rc.Update();
                        }
                        catch
                        {
                            Console.WriteLine("error!");
                        }
                        //Console.WriteLine(string.Format("{0},{1},{2}", item.GetID(), fieldName, fieldValue));
                    }
                    //Console.WriteLine("=="+item.GetID()+"==");
                }
            }
            Console.WriteLine(dv.Name + " done!");
            sw.Close();
            f.Close();
            rc.Close();
            dv.Close();
        }