コード例 #1
0
        private void cmbDeviceType_SelectedIndexChanged(object sender, EventArgs e)
        {
            Recordset objRt = null;

            try
            {
                if (cmbDeviceType.SelectedItem == null)
                {
                    return;
                }
                ResourceTypeData data = cmbDeviceType.SelectedItem as ResourceTypeData;
                if (!m_Application.Workspace.Datasources["Resource"].Datasets.Contains(data.DatasetName))
                {
                    return;
                }
                dg_Data.Rows.Clear();
                objRt = (m_Application.Workspace.Datasources["Resource"].Datasets[data.DatasetName] as DatasetVector).GetRecordset(false, CursorType.Static);
                objRt.MoveFirst();
                while (!objRt.IsEOF)
                {
                    DataGridViewRow         row   = new DataGridViewRow();
                    DataGridViewTextBoxCell cell1 = new DataGridViewTextBoxCell
                    {
                        Value = Convert.ToString(objRt.GetFieldValue(data.FieldID))
                    };
                    row.Cells.Add(cell1);

                    int isSet = 0;
                    if (objRt.GetFieldValue("Heading") == null && objRt.GetFieldValue("Altitude") == null)
                    {
                        isSet = 0;
                    }
                    else
                    {
                        isSet = 1;
                    }
                    DataGridViewCheckBoxCell cell2 = new DataGridViewCheckBoxCell
                    {
                        Value = isSet
                    };
                    row.Cells.Add(cell2);
                    row.Tag = objRt.GetID();
                    dg_Data.Rows.Add(row);

                    objRt.MoveNext();
                }
            }
            catch (Exception ex)
            {
                Log.OutputBox(ex);
            }
            finally
            {
                if (objRt != null)
                {
                    objRt.Close();
                    objRt.Dispose();
                }
            }
        }
コード例 #2
0
        //private void mSceneControlQuery6(object sender, ObjectSelectedEventArgs e)
        //{
        //    // 无对象被选中
        //    if (e.Count == 0 && mIndex == 7)
        //    {
        //        MessageBox.Show("未选择对象!");
        //    }
        //    //有对象选中
        //    else if (e.Count > 0 && mIndex == 7)
        //    {
        //        AppendQuery();
        //    }
        //}
        public void AppendQuery()
        {
            mSceneControl.Action = Action3D.Select;
            Selection3D[] selection = mSceneControl.Scene.FindSelection(true);
            //判断选择集是否为空
            if (selection == null || selection.Length == 0)
            {
                MessageBox.Show("请选择要查询附属物的空间对象");
                return;
            }
            //将选择集转换为记录
            Recordset recordset = selection[0].ToRecordset();

            string str1 = "";

            string PipeType = recordset.GetFieldValue("PipeType").ToString();

            if (PipeType == "附属物")
            {
                object obj1 = recordset.GetFieldValue("Name");
                str1 = "该附属物为" + ":" + obj1.ToString() + "\n";
                MessageBox.Show(str1, "附属物查询结果");
            }
            else
            {
                MessageBox.Show("该对象不是附属物!");
            }
            recordset.Dispose();
        }
コード例 #3
0
        /// <summary>
        /// 飞向管线ID
        /// </summary>
        /// <param name="flag">判断是第几个管线或管点对象</param>
        /// <param name="ID">获取该ID值</param>
        public void FlyToConnectID(int flag, int ID)
        {
            try
            {
                Recordset     selected = null;
                DatasetVector network  = mConNetWorkName;

                mSceneControl.Bubbles.Clear();
                Bubble bubble = new Bubble();
                mInformationBubble.Visible = true;

                //定义经纬度,为方便飞行定位
                Double mFlylongitude = 0;
                Double mFlylatitude  = 0;
                //区分类型 按点飞 还是 按线飞
                if (recordsetTypeConId1 == GeometryType.GeoLine3D)
                {
                    String expression = "SmID = " + ID;
                    selected = network.Query(expression, CursorType.Static);
                    Geometry3D geometry = selected.GetGeometry() as Geometry3D;
                    mInformationBubble.Description.Text = "管线ID-" + flag + ":" + ID + "的位置如下";;
                    bubble.Pointer              = new Point3D(geometry.InnerPoint3D.X, geometry.InnerPoint3D.Y, mPipeAltitude);
                    bubble.ClientWidth          = mInformationBubble.Width;
                    bubble.ClientHeight         = mInformationBubble.Height;
                    mInformationBubble.Location = new Point(bubble.ClientLeft, bubble.ClientTop);
                    mSceneControl.Bubbles.Add(bubble);
                    mFlylongitude = geometry.InnerPoint3D.X;
                    mFlylatitude  = geometry.InnerPoint3D.Y;
                }
                else if (recordsetTypeConId1 == GeometryType.GeoPoint3D)
                {
                    String expression = "SmID = " + ID;
                    selected = network.ChildDataset.Query(expression, CursorType.Static);
                    object mAnalongitude = selected.GetFieldValue("SmX");
                    object mAnalatitude  = selected.GetFieldValue("SmY");

                    mInformationBubble.Description.Text = "管点ID-" + flag + ":" + ID + "的位置如下";
                    bubble.Pointer              = new Point3D(Convert.ToDouble(mAnalongitude), Convert.ToDouble(mAnalatitude), mPipeAltitude);
                    bubble.ClientWidth          = mInformationBubble.Width;
                    bubble.ClientHeight         = mInformationBubble.Height;
                    mInformationBubble.Location = new Point(bubble.ClientLeft, bubble.ClientTop);
                    mSceneControl.Bubbles.Add(bubble);
                    mFlylongitude = Convert.ToDouble(mAnalongitude);
                    mFlylatitude  = Convert.ToDouble(mAnalatitude);
                }
                Camera camera = new Camera();
                camera.Longitude    = Convert.ToDouble(mFlylongitude);
                camera.Latitude     = Convert.ToDouble(mFlylatitude);
                camera.AltitudeMode = AltitudeMode.RelativeToGround;
                camera.Tilt         = 0;
                camera.Altitude     = 25;
                mSceneControl.Scene.Fly(camera, 10);
                mSceneControl.Scene.Refresh();
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex);
            }
        }
コード例 #4
0
        /// <summary>
        /// 进行网络分析分析
        /// </summary>
        public void BeginNetworkAnalyst()
        {
            try
            {
                mAnalystResult = mAnalyst.FindTSPPath(mAnalystParameter, false);
                if (mAnalystResult != null)
                {
                    int[][] EdgeId = new int[mAnalystResult.Edges.Length][];
                    //拿到交错数组中第一行元素ID
                    int[] IDedge = new int[mAnalystResult.Edges[0].Length];
                    for (int i = 0; i < IDedge.Length; i++)
                    {
                        IDedge[i] = mAnalystResult.Edges[0][i];
                    }
                    //拿到弧段ID后查询路名
                    string[]  RodeName  = new string[IDedge.Length];
                    Recordset recordset = null;
                    for (int i = 0; i < IDedge.Length; i++)
                    {
                        recordset         = mRodeNetWork.Query("SmID =" + IDedge[i], CursorType.Static);
                        RodeName[i]       = recordset.GetFieldValue("RodeName").ToString().Trim();
                        mRodeTotalLength += Convert.ToInt32(recordset.GetFieldValue("SmLength"));
                    }
                    //编辑路名显示形式
                    string mStartRode = "起点→";
                    string mNewRode   = null;
                    for (int i = 0; i < RodeName.Length; i++)
                    {
                        if (i == 0)
                        {
                            mNewRode = mStartRode.Insert(mStartRode.Length, RodeName[i] + "→");
                        }
                        else
                        {
                            mNewRode = mNewRode.Insert(mNewRode.Length, RodeName[i] + "→");
                        }
                    }
                    mTextBoxRodeName = mNewRode + "终点";
                }
                GeoLine line = mAnalystResult.Routes[0].ConvertToLine();
                if (mLine3D == null)
                {
                    mLine3D = new GeoLine3D();
                }

                for (Int32 i = 0; i < line.PartCount; i++)
                {
                    mLine3D.AddPart(line[i].ToPoint3Ds());
                }
                mLine3D[0].Insert(0, new Point3D(mStartPoint.X, mStartPoint.Y, 0));
                mLine3D[0].Add(new Point3D(mEndPoint.X, mEndPoint.Y, 0));
                DisplayFlyRoute();
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }
        }
コード例 #5
0
        private void DangerResourceLocationControl_Load(object sender, EventArgs e)
        {
            if (m_Application.MainForm.FormManager.ActiveForm is IFormScene formScene)
            {
                m_SceneControl = formScene.SceneControl;
            }

            Recordset objRt = null;

            try
            {
                dg_Data.Rows.Clear();
                objRt = (m_Application.Workspace.Datasources["Resource"].Datasets["DangerResource"] as DatasetVector).GetRecordset(false, CursorType.Static);
                objRt.MoveFirst();
                while (!objRt.IsEOF)
                {
                    DataGridViewRow         row   = new DataGridViewRow();
                    DataGridViewTextBoxCell cell1 = new DataGridViewTextBoxCell
                    {
                        Value = Convert.ToString(objRt.GetFieldValue("ResourceID"))
                    };
                    row.Cells.Add(cell1);

                    int isSet = 0;
                    if (objRt.GetFieldValue("Heading") == null && objRt.GetFieldValue("Altitude") == null)
                    {
                        isSet = 0;
                    }
                    else
                    {
                        isSet = 1;
                    }
                    DataGridViewCheckBoxCell cell2 = new DataGridViewCheckBoxCell
                    {
                        Value = isSet
                    };
                    row.Cells.Add(cell2);
                    row.Tag = objRt.GetID();
                    dg_Data.Rows.Add(row);

                    objRt.MoveNext();
                }
            }
            catch (Exception ex)
            {
                Log.OutputBox(ex);
            }
            finally
            {
                if (objRt != null)
                {
                    objRt.Close();
                    objRt.Dispose();
                }
            }
        }
コード例 #6
0
        public int PickNodeToLine(int nID)
        {
            m_SelectedGeoNetwork.Clear();
            DatasetVector DvLine = m_workspace.Datasources["Pipeline3D"].Datasets["PipeLine3D"] as DatasetVector;
            DatasetVector DvNode = m_workspace.Datasources["Pipeline3D"].Datasets["PipePoint3D"] as DatasetVector;

            int[]     id        = { nID };
            Recordset recordset = DvNode.Query(id, CursorType.Static);
            Geometry  pGeoNode  = recordset.GetGeometry();

            string strNodeID = "PtID";
            int    nNodeID   = Convert.ToInt32(recordset.GetFieldValue(strNodeID));

            string         strFNode       = "FNode";
            string         strTNode       = "ENode";
            QueryParameter queryparameter = new QueryParameter();

            queryparameter.CursorType = CursorType.Static;

            queryparameter.AttributeFilter = String.Format("{0}={1} or {2}={3}", strFNode, nNodeID, strTNode, nNodeID);
            Recordset Rs = DvLine.Query(queryparameter);

            int nCount = Rs.RecordCount;;

            Rs.MoveFirst();
            while (!Rs.IsEOF)
            {
                GeoLine3D geoline3D = Rs.GetGeometry() as GeoLine3D;

                NetworkGeometry NetWorkGeometry = new NetworkGeometry();
                NetWorkGeometry.nID    = geoline3D.ID;
                NetWorkGeometry.nFNode = Convert.ToInt32(Rs.GetFieldValue(strFNode));
                NetWorkGeometry.nTNode = Convert.ToInt32(Rs.GetFieldValue(strTNode));

                if (!m_SelectedGeoNetwork.Contains(NetWorkGeometry))
                {
                    if (NetWorkGeometry.nTNode == nNodeID)
                    {
                        NetWorkGeometry.geometry = geoline3D;
                        m_SelectedGeoNetwork.Add(NetWorkGeometry);//流入对象在第一位
                    }
                    else
                    {
                        NetWorkGeometry.bIsIn    = false;
                        NetWorkGeometry.geometry = geoline3D;
                        m_SelectedGeoNetwork.Add(NetWorkGeometry);//线对象
                    }
                }

                Rs.MoveNext();
            }
            Rs.Dispose();
            return(nCount);
        }
コード例 #7
0
        private void DeviceTypeManagerControl_Load(object sender, EventArgs e)
        {
            Recordset objRt = null;

            try
            {
                if (m_Application.MainForm.FormManager.ActiveForm is IFormScene formScene)
                {
                    m_SceneControl = formScene.SceneControl;
                }
                if (m_lstType == null)
                {
                    m_lstType = new List <ResourceTypeData>();
                }
                if (m_lstTypeData == null)
                {
                    m_lstTypeData = new List <Label>();
                }
                objRt = (m_Application.Workspace.Datasources["Resource"].Datasets["ResourceTable"] as DatasetVector).GetRecordset(false, CursorType.Static);
                objRt.MoveFirst();
                while (!objRt.IsEOF)
                {
                    ResourceTypeData data = new ResourceTypeData
                    {
                        Caption     = Convert.ToString(objRt.GetFieldValue("SourceName")),
                        Name        = Convert.ToString(objRt.GetFieldValue("SourceID")),
                        FieldID     = Convert.ToString(objRt.GetFieldValue("TableField"))?.Split(',')[0],
                        FieldName   = Convert.ToString(objRt.GetFieldValue("TableField"))?.Split(',')[1],
                        DatasetName = Convert.ToString(objRt.GetFieldValue("TableName")),
                    };
                    m_lstType.Add(data);

                    objRt.MoveNext();
                }
                GetData();
            }
            catch (Exception ex)
            {
                Log.OutputBox(ex);
            }
            finally
            {
                if (objRt != null)
                {
                    objRt.Close();
                    objRt.Dispose();
                }
            }
        }
コード例 #8
0
        private void recordset_Load(object sender, EventArgs e)
        {
            //Form1 form1 = new Form1();
            Dataset       dataset       = nowdata.getDataset();
            DatasetVector datasetvector = (DatasetVector)dataset as DatasetVector;
            Recordset     recordset     = datasetvector.GetRecordset(false, CursorType.Dynamic);
            Object        value         = recordset.GetValues();//获取字段

            //设置属性
            listView1.GridLines      = true;         //显示网格线
            listView1.FullRowSelect  = true;         //显示全行
            listView1.MultiSelect    = false;        //设置只能单选
            listView1.View           = View.Details; //设置显示模式为详细
            listView1.HoverSelection = true;         //当鼠标停留数秒后自动选择

            //填充表头
            int minlength = 60;

            listView1.Columns.Add("序号", minlength);
            for (int i = 0; i < datasetvector.FieldCount; i++)
            {
                listView1.Columns.Add(datasetvector.FieldInfos[i].Name, minlength);  //相当于上面的添加列名的步骤
            }
            //填充数据
            recordset.MoveFirst();
            this.listView1.BeginUpdate();  //数据更新,UI暂时挂起,直到EndUpdate绘制控件,可以有效避免闪烁并大大提高加载速度
            for (int i = 0; i < recordset.RecordCount; i++)
            {
                ListViewItem lvi = new ListViewItem();
                lvi.Text = i.ToString();
                for (int j = 0; j < datasetvector.FieldCount; j++)
                {
                    String info;
                    if (recordset.GetFieldValue(j) != null)
                    {
                        info = recordset.GetFieldValue(j).ToString();
                    }
                    else
                    {
                        info = "null";
                    }
                    lvi.SubItems.Add(info);
                }
                this.listView1.Items.Add(lvi);
                recordset.MoveNext();
            }
            this.listView1.EndUpdate();  //结束数据处理,UI界面一次性绘制。
        }
コード例 #9
0
ファイル: 查询记录表.cs プロジェクト: saodan/djsysteam
        private void 查询记录表_Load(object sender, EventArgs e)
        {
            this.skinDataGridView1.Columns.Clear();
            this.skinDataGridView1.Rows.Clear();
            this.Text = recordset.Dataset.Name;
            for (int i = 0; i < recordset.FieldCount; i++)
            {
                String fieldName = recordset.GetFieldInfos()[i].Name;
                this.skinDataGridView1.Columns.Add(fieldName, fieldName);
            }
            DataGridViewRow row = null;

            while (!recordset.IsEOF)
            {
                row = new DataGridViewRow();
                for (int i = 0; i < recordset.FieldCount; i++)
                {
                    Object fieldValue            = recordset.GetFieldValue(i);
                    DataGridViewTextBoxCell cell = new DataGridViewTextBoxCell();
                    if (fieldValue != null)
                    {
                        cell.ValueType = fieldValue.GetType();
                        cell.Value     = fieldValue;
                    }

                    row.Cells.Add(cell);
                }

                this.skinDataGridView1.Rows.Add(row);

                recordset.MoveNext();
            }
            this.skinDataGridView1.Update();
        }
コード例 #10
0
ファイル: frmMain.cs プロジェクト: gishjl/DataManager
        private void button4_Click_1(object sender, EventArgs e)
        {
            //string strDatasourceName = "行政区划";
            string strDatasetName = "省会城市";
            string strTableName   = "T_GIS_REGION";

            try
            {
                Datasource dtSource = m_wrkSpace.Datasources[0];
                foreach (Dataset dtSet in dtSource.Datasets)
                {
                    if (dtSet.Name.Equals(strDatasetName))
                    {
                        DatasetVector dtVector = dtSet as DatasetVector;
                        Recordset     recdst   = dtVector.GetRecordset(false, CursorType.Static);
                        while (!recdst.IsEOF)
                        {
                            string   strName = string.Format("{0}", recdst.GetFieldValue("PROVINCE"));
                            GeoPoint geoPt   = recdst.GetGeometry() as GeoPoint;
                            csCenter c       = new csCenter();
                            c.center = geoPt.InnerPoint;
                            string strCenter = JSONHelper.ObjectToJSON(c.center);
                            string strSQL    = string.Format("update {0} t set t.centerpoint = '{1}' where t.regionname = '{2}' and rlevel=1",
                                                             strTableName,
                                                             strCenter,
                                                             strName);
                            DbHelperOra.ExecuteSql(DbHelperOra.connectionString_172, strSQL);
                            recdst.MoveNext();
                        }
                    }
                }
            }
            catch { }
        }
コード例 #11
0
ファイル: Form1.cs プロジェクト: zenglang1/C-GIS
        private void toolStripQueryProperty_Click(object sender, EventArgs e)
        {
            //获取选择集
            Selection[] selection = mapControl1.Map.FindSelection(true);

            //判断选择集是否为空
            if (selection == null || selection.Length == 0)
            {
                MessageBox.Show("请选择要查询属性的空间对象");
                return;
            }

            //将选择集转换为记录
            Recordset recordset = selection[0].ToRecordset();

            this.dataGridView1.Columns.Clear();
            this.dataGridView1.Rows.Clear();

            for (int i = 0; i < recordset.FieldCount; i++)
            {
                //定义并获得字段名称
                String fieldName = recordset.GetFieldInfos()[i].Name;

                //将得到的字段名称添加到dataGridView列中
                this.dataGridView1.Columns.Add(fieldName, fieldName);
            }

            //初始化row
            DataGridViewRow row = null;

            //根据选中记录的个数,将选中对象的信息添加到dataGridView中显示
            while (!recordset.IsEOF)
            {
                row = new DataGridViewRow();
                for (int i = 0; i < recordset.FieldCount; i++)
                {
                    //定义并获得字段值
                    Object fieldValue = recordset.GetFieldValue(i);

                    //将字段值添加到dataGridView中对应的位置
                    DataGridViewTextBoxCell cell = new DataGridViewTextBoxCell();
                    if (fieldValue != null)
                    {
                        cell.ValueType = fieldValue.GetType();
                        cell.Value     = fieldValue;
                    }

                    row.Cells.Add(cell);
                }

                this.dataGridView1.Rows.Add(row);

                recordset.MoveNext();
            }
            this.dataGridView1.Update();

            recordset.Dispose();
        }
コード例 #12
0
        public bool layerExist(Recordset tempRecordset)
        {
            bool flag = false;
            //项目地块是否存在标记
            bool isExit = false;

            if (formatRecordset == null)
            {
                return(flag);
            }
            //地块编号
            string strDkbh = "";

            if (formatRecordset.RecordCount > 0)
            {
                for (int i = 0; i <= formatRecordset.RecordCount; i++)
                {
                    formatRecordset.MoveTo(i);


                    //判断该图斑是否已经由临时图层导入正式图层
                    if (formatRecordset.GetGeometry().Bounds.Equals(tempRecordset.GetGeometry().Bounds))
                    {
                        //取得地块编号
                        strDkbh = formatRecordset.GetFieldValue("DKBH").ToString();
                        flag    = true;
                        break;
                    }
                }
            }
            //补耕地块录入时同一个旗县可能存在多个复垦项目的情况,该种情况下,判断该项目下是否存在上面处理中取得的地块编号
            //获取项目名称值
            if (textBox2.Text == "补耕")
            {
                sqlQuery.Clear();
                sqlQuery.Append("SELECT  DKBH   AS 地块编号, ");
                sqlQuery.Append("  FKXMMC           AS 所属复垦项目名称, ");
                sqlQuery.Append("  XMSZXM           AS 项目所在县名称 ");
                sqlQuery.Append(",  BZ           AS 备注 ");
                sqlQuery.Append(" FROM " + "BG" + gkfqd.Common.DbUse.GetTownCode(textBox3.Text));
                sqlQuery.Append(" WHERE         FKXMMC='" + textBox1.Text + "'AND DKBH='" + strDkbh + "'");
                gkfqd.Common.DbUse.GetOleDbconnection().Close();
                gkfqd.Common.DbUse.GetOleDbconnection().Open();
                dataSet6.Clear();
                OleDbDataAdapter MyAdapter = new OleDbDataAdapter(sqlQuery.ToString(), gkfqd.Common.DbUse.GetOleDbconnection());
                MyAdapter.Fill(dataSet6);
                gkfqd.Common.DbUse.GetOleDbconnection().Close();
                if (dataSet6.Tables[0].Rows.Count > 0)
                {
                    isExit = true;
                }
                //当地块存在,并且该项目名称下有该地块的情况
                return(flag && isExit);
            }
            return(flag);
        }
コード例 #13
0
        private void GetData()
        {
            Recordset objRt = null;

            try
            {
                dg_Data.Rows.Clear();
                dg_Data.Columns.Clear();
                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.Static);
                for (int i = 0; i < objRt.FieldCount; i++)
                {
                    FieldInfo fieldInfo = objRt.GetFieldInfos()[i];
                    if (fieldInfo.Caption.ToLower().Contains("sm"))
                    {
                        continue;
                    }
                    dg_Data.Columns.Add(fieldInfo.Name, fieldInfo.Caption);
                }

                objRt.MoveFirst();
                while (!objRt.IsEOF)
                {
                    DataGridViewRow row = new DataGridViewRow();
                    row.HeaderCell.Value = objRt.GetID().ToString();
                    for (int j = 0; j < dg_Data.ColumnCount; j++)
                    {
                        DataGridViewTextBoxCell textBoxCell = new DataGridViewTextBoxCell
                        {
                            Value = Convert.ToString(objRt.GetFieldValue(dg_Data.Columns[j].Name))
                        };
                        row.Cells.Add(textBoxCell);
                    }
                    dg_Data.Rows.Add(row);

                    objRt.MoveNext();
                }
            }
            catch (Exception ex)
            {
                Log.OutputBox(ex);
            }
            finally
            {
                if (objRt != null)
                {
                    objRt.Close();
                    objRt.Dispose();
                }
            }
        }
コード例 #14
0
        private void ShowAllRecordInfoTolistview()
        {
            //设置属性
            listView1.GridLines      = true;         //显示网格线
            listView1.FullRowSelect  = true;         //显示全行
            listView1.MultiSelect    = false;        //设置只能单选
            listView1.View           = View.Details; //设置显示模式为详细
            listView1.HoverSelection = true;         //当鼠标停留数秒后自动选择

            //填充表头
            int minlength = 60;

            listView1.Columns.Add("序号", minlength);
            for (int i = 0; i < dataset.FieldCount; i++)
            {
                listView1.Columns.Add(dataset.FieldInfos[i].Name, minlength);  //相当于上面的添加列名的步骤
            }
            //填充数据
            recordset.MoveFirst();
            this.listView1.BeginUpdate();  //数据更新,UI暂时挂起,直到EndUpdate绘制控件,可以有效避免闪烁并大大提高加载速度
            for (int i = 0; i < recordset.RecordCount; i++)
            {
                ListViewItem lvi = new ListViewItem();
                lvi.Text = i.ToString();
                for (int j = 0; j < dataset.FieldCount; j++)
                {
                    String info;
                    if (recordset.GetFieldValue(j) != null)
                    {
                        info = recordset.GetFieldValue(j).ToString();
                    }
                    else
                    {
                        info = "null";
                    }
                    lvi.SubItems.Add(info);
                }
                this.listView1.Items.Add(lvi);
                recordset.MoveNext();
            }
            this.listView1.EndUpdate();  //结束数据处理,UI界面一次性绘制。
        }
コード例 #15
0
        private void dg_Data_RowHeaderMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            Recordset objRt = null;

            try
            {
                DataGridViewRow  row  = dg_Data.Rows[e.RowIndex];
                ResourceTypeData data = cmbDeviceType.SelectedItem as ResourceTypeData;
                objRt = (m_Application.Workspace.Datasources["Resource"].Datasets[data.DatasetName] as DatasetVector).GetRecordset(false, CursorType.Static);
                if (objRt.SeekID(Convert.ToInt32(row.Tag)))
                {
                    double lon     = Convert.ToDouble(objRt.GetFieldValue("Longitude"));
                    double lat     = Convert.ToDouble(objRt.GetFieldValue("Latitude"));
                    double alt     = Convert.ToDouble(objRt.GetFieldValue("Altitude"));
                    double heading = Convert.ToDouble(objRt.GetFieldValue("Heading"));
                    double tilt    = Convert.ToDouble(objRt.GetFieldValue("Tilt"));
                    Camera camera  = new Camera
                    {
                        Longitude    = lon,
                        Latitude     = lat,
                        Altitude     = alt,
                        Heading      = heading,
                        Tilt         = tilt,
                        AltitudeMode = AltitudeMode.Absolute
                    };
                    m_SceneControl.Scene.Fly(camera);
                }
            }
            catch (Exception ex)
            {
                Log.OutputBox(ex);
            }
            finally
            {
                if (objRt != null)
                {
                    objRt.Close();
                    objRt.Dispose();
                }
            }
        }
コード例 #16
0
ファイル: frmMain.cs プロジェクト: gishjl/DataManager
        private DatasetVector DatasetConvertRegionToLine(DatasetVector dtVector2)
        {
            DatasetVector dtVector = null;

            if (dtVector2 != null)
            {
                DatasetVectorInfo dvi = new DatasetVectorInfo();
                dvi.Name = m_selLayer.Dataset.Datasource.Datasets.GetAvailableDatasetName("C_geoLine");
                dvi.Type = DatasetType.Line;

                //DatasetVector
                dtVector = m_selLayer.Dataset.Datasource.Datasets.Create(dvi);
                foreach (FieldInfo fi in dtVector2.FieldInfos)
                {
                    if (dtVector.FieldInfos.IndexOf(fi.Name) < 0 && !fi.IsSystemField)
                    {
                        dtVector.FieldInfos.Add(fi.Clone());
                    }
                }

                Recordset recdst = dtVector.GetRecordset(true, CursorType.Dynamic);

                recdst.Batch.Begin();
                try
                {
                    Recordset recdst2 = dtVector2.GetRecordset(false, CursorType.Static);
                    while (!recdst2.IsEOF)
                    {
                        GeoRegion geoR = recdst2.GetGeometry() as GeoRegion;

                        if (geoR != null)
                        {
                            GeoLine geoLine = geoR.ConvertToLine();
                            recdst.AddNew(geoLine);
                            foreach (FieldInfo fi in dtVector2.FieldInfos)
                            {
                                if (dtVector.FieldInfos.IndexOf(fi.Name) > -1 && !fi.IsSystemField)
                                {
                                    recdst.SetFieldValue(fi.Name, recdst2.GetFieldValue(fi.Name));
                                }
                            }
                            geoR.Dispose();
                        }
                        recdst2.MoveNext();
                    }
                    recdst2.Dispose();
                }
                catch { }
                recdst.Batch.Update();
                recdst.Dispose();
            }
            return(dtVector);
        }
コード例 #17
0
        public void Query()
        {
            try
            {
                mDataVec = mData as DatasetVector;
                Recordset rec = mDataVec.GetRecordset(false, CursorType.Dynamic);
                this.dataGridView1.Columns.Clear();
                this.dataGridView1.Rows.Clear();

                for (int i = 0; i < rec.FieldCount; i++)
                {
                    //定义并获得字段名称
                    String fieldName = rec.GetFieldInfos()[i].Name;
                    //将得到的字段名称添加到dataGridView列中
                    this.dataGridView1.Columns.Add(fieldName, fieldName);
                }

                //初始化row
                DataGridViewRow row = null;

                //根据选中记录的个数,将选中对象的信息添加到dataGridView中显示
                while (!rec.IsEOF)
                {
                    row = new DataGridViewRow();
                    for (int i = 0; i < rec.FieldCount; i++)
                    {
                        //定义并获得字段值
                        Object fieldValue = rec.GetFieldValue(i);

                        //将字段值添加到dataGridView中对应的位置
                        DataGridViewTextBoxCell cell = new DataGridViewTextBoxCell();
                        if (fieldValue != null)
                        {
                            cell.ValueType = fieldValue.GetType();
                            cell.Value     = fieldValue;
                        }
                        row.Cells.Add(cell);
                    }

                    this.dataGridView1.Rows.Add(row);
                    rec.MoveNext();
                }
                this.dataGridView1.Update();
                rec.Dispose();
            }
            catch (System.Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }
        }
コード例 #18
0
ファイル: gk043.cs プロジェクト: knowledge0603/gkfqd
        /// <summary>
        /// 没有选择对象的时候表格清空
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        //private void m_mapControl_Paint(object sender, PaintEventArgs e)
        //{
        //    try
        //    {
        //        if (mapControl1.Map.Layers[0].Selection.Count < 1)
        //        {
        //            dataGridView1.Columns.Clear();
        //            dataGridView1.Rows.Clear();
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        Trace.WriteLine(ex.Message);
        //    }
        //}

        /// <summary>
        /// 使用记录集填充DataGridView
        /// </summary>
        /// <param name="recordset">获取的记录集</param>
        private void FillDataGridView(Recordset recordset)
        {
            try
            {
                dataGridView1.Columns.Clear();
                dataGridView1.Rows.Clear();

                for (int i = 0; i < recordset.FieldCount; i++)
                {
                    String fieldName = recordset.GetFieldInfos()[i].Name;

                    dataGridView1.Columns.Add(fieldName, fieldName);
                }

                DataGridViewRow row = null;
                //根据选中记录的个数,将选中对象的信息添加到dataGridView中显示
                while (!recordset.IsEOF)
                {
                    row = new DataGridViewRow();
                    for (int i = 0; i < recordset.FieldCount; i++)
                    {
                        //定义并获得字段值
                        Object fieldValue = recordset.GetFieldValue(i);
                        //将字段值添加到dataGridView中对应的位置
                        DataGridViewTextBoxCell cell = new DataGridViewTextBoxCell();
                        if (fieldValue != null)
                        {
                            cell.ValueType = fieldValue.GetType();
                            cell.Value     = fieldValue;
                        }

                        row.Cells.Add(cell);
                    }

                    this.dataGridView1.Rows.Add(row);

                    recordset.MoveNext();
                }

                this.dataGridView1.Update();

                recordset.Dispose();
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }
        }
コード例 #19
0
ファイル: 图查属性.cs プロジェクト: sishui198/Wetland-GIS
        private void 图查属性_Load(object sender, EventArgs e)
        {
            dataGridView1.AllowUserToAddRows = false;
            dataGridView1.ReadOnly           = true;
            this.dataGridView1.Columns.Clear();
            this.dataGridView1.Rows.Clear();
            Recordset recordset = Program.re;

            for (int i = 0; i < recordset.FieldCount; i++)
            {
                //定义并获得字段名称
                String fieldName = recordset.GetFieldInfos()[i].Name;

                //将得到的字段名称添加到dataGridView列中
                this.dataGridView1.Columns.Add(fieldName, fieldName);
            }

            //初始化row
            DataGridViewRow row = null;

            //根据选中记录的个数,将选中对象的信息添加到dataGridView中显示
            while (!recordset.IsEOF)
            {
                row = new DataGridViewRow();
                for (int i = 0; i < recordset.FieldCount; i++)
                {
                    //定义并获得字段值
                    Object fieldValue = recordset.GetFieldValue(i);
                    //将字段值添加到dataGridView中对应的位置
                    DataGridViewTextBoxCell cell = new DataGridViewTextBoxCell();
                    if (fieldValue != null)
                    {
                        cell.ValueType = fieldValue.GetType();
                        cell.Value     = fieldValue;
                    }
                    row.Cells.Add(cell);
                }

                this.dataGridView1.Rows.Add(row);

                recordset.MoveNext();
            }
            this.dataGridView1.Update();
            recordset.Dispose();
        }
コード例 #20
0
        private void Button_allval_Click(object sender, EventArgs e)
        {
            try
            {
                if (LV_fieldinfo.SelectedItems.Count == 1)
                {
                    LB_allval.Items.Clear();

                    string selFieldname = LV_fieldinfo.SelectedItems[0].Text;
                    if (selFieldname == "*")
                    {
                        return;
                    }
                    Recordset recordset = mData.GetRecordset(false, CursorType.Dynamic);
                    recordset.MoveFirst();
                    while (!recordset.IsEOF)
                    {
                        object allvalue = recordset.GetFieldValue(selFieldname);
                        if (allvalue == null)
                        {
                            return;
                        }
                        if (LB_allval.Items.Contains("\'" + allvalue + "\'"))
                        {
                            recordset.MoveNext();
                            continue;
                        }
                        else
                        {
                            LB_allval.Items.Add("\'" + allvalue + "\'");
                        }
                        recordset.MoveNext();
                    }
                    recordset.Dispose();
                }
                if (LV_fieldinfo.SelectedItems.Count > 1)
                {
                    MessageBox.Show("只能选择一个字段");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("error:" + ex.Message);
            }
        }
コード例 #21
0
ファイル: GISUtility.cs プロジェクト: zfc317/mscd
        public static DataTable RecordsetToDataTable(Recordset rs,LayerInfo layerInfo)
        {
            var dt = CreateDataTableByLayerInfo(layerInfo);
            if (rs.IsEmpty) return dt;

            while (!rs.IsEOF)
            {
                var row = dt.NewRow();
                foreach (var fieldInfo in layerInfo.FieldInfos)
                {
                    var value = rs.GetFieldValue(fieldInfo.FieldName);
                    row[fieldInfo.FieldName] = value;
                }
                dt.Rows.Add(row);
                rs.MoveNext();
            }
            return dt;
        }
コード例 #22
0
        //
        public static string GetQHBMByPoint(Point2D pt2D)
        {
            string strQHBM = "";

            try
            {
                if (m_ChinaXZQH != null)
                {
                    GeoPoint  geoPt  = new GeoPoint(pt2D);
                    Recordset recdst = m_ChinaXZQH.Query(geoPt, 0.0001, CursorType.Static);
                    if (recdst.RecordCount > 0)
                    {
                        string strCode = string.Format("{0}", recdst.GetFieldValue("code"));
                        strQHBM = strCode;
                    }
                }
            }
            catch { }
            return(strQHBM);
        }
コード例 #23
0
ファイル: 主界面.cs プロジェクト: sishui198/Wetland-GIS
        private void mapControl1_DoubleClick(object sender, EventArgs e)
        {
            Selection[] selection    = mapControl1.Map.FindSelection(true);
            Recordset   recordset    = selection[0].ToRecordset();
            FieldInfo   objFieldinfo = null;

            if (recordset.RecordCount > 0)
            {
                string str = " ";
                for (int i = 0; i < recordset.FieldCount; i++)
                {
                    objFieldinfo = recordset.GetFieldInfos()[i];

                    //String fieldName = recordset.GetFieldInfos()[i].Name;
                    str += objFieldinfo.Name;
                    str += ":" + recordset.GetFieldValue(i).ToString() + "\n";
                }
                MessageBox.Show(str, "属性");
            }
            recordset.Close();
        }
コード例 #24
0
        //private void mSceneControlQuery5(object sender, ObjectSelectedEventArgs e)
        //{
        //    // 无对象被选中
        //    if (e.Count == 0&& mIndex==6)
        //    {
        //        MessageBox.Show("未选择对象!");
        //    }
        //    //有对象选中
        //    else if (e.Count > 0 && mIndex == 6)
        //    {
        //        DiametQuery();
        //    }
        //}
        public void DiametQuery()
        {
            mSceneControl.Action = Action3D.Select;
            Selection3D[] selection = mSceneControl.Scene.FindSelection(true);
            //判断选择集是否为空
            if (selection == null || selection.Length == 0)
            {
                MessageBox.Show("请选择要查询管径的空间对象");
                return;
            }
            //将选择集转换为记录
            Recordset recordset = selection[0].ToRecordset();

            string str  = "";
            string str1 = "";
            object obj;
            bool   bol = false;

            for (int i = 0; i < recordset.FieldCount; i++)
            {
                str = recordset.GetFieldInfos()[i].Name;
                if (str == "PipeDiameter")
                {
                    bol  = true;
                    obj  = recordset.GetFieldValue(i);
                    str1 = "管径" + ":" + obj.ToString() + "mm" + "\n";
                    MessageBox.Show(str1, "管径查询结果");
                    break;
                }
                else
                {
                    continue;
                }
            }
            if (bol == false)
            {
                MessageBox.Show("该对象没有管径属性!");
            }
            recordset.Dispose();
        }
コード例 #25
0
        private void M_SceneControl_ObjectAdded(object sender, ObjectAddedEventArgs e)
        {
            Recordset objRt = null;

            try
            {
                if (chkTheme.SelectedItem == null)
                {
                    m_Application.MessageBox.Show(Message);
                    return;
                }
                dg_Data.Rows.Clear();
                Layer3DDataset layer3DDataset = (chkTheme.SelectedItem as Label).Tag as Layer3DDataset;
                objRt = (layer3DDataset.Dataset as DatasetVector).GetRecordset(false, CursorType.Static);
                if (objRt.SeekID(e.ID))
                {
                    DataGridViewRow row = new DataGridViewRow();
                    row.HeaderCell.Value = objRt.GetID().ToString();
                    for (int j = 0; j < dg_Data.ColumnCount; j++)
                    {
                        DataGridViewTextBoxCell textBoxCell = new DataGridViewTextBoxCell();
                        textBoxCell.Value = Convert.ToString(objRt.GetFieldValue(dg_Data.Columns[j].Name));
                        row.Cells.Add(textBoxCell);
                    }
                    dg_Data.Rows.Add(row);
                }
            }
            catch (Exception ex)
            {
                Log.OutputBox(ex);
            }
            finally
            {
                if (objRt != null)
                {
                    objRt.Close();
                    objRt.Dispose();
                }
            }
        }
コード例 #26
0
        public static DataTable RecordsetToDataTable(Recordset rs, LayerInfo layerInfo)
        {
            var dt = CreateDataTableByLayerInfo(layerInfo);

            if (rs.IsEmpty)
            {
                return(dt);
            }

            while (!rs.IsEOF)
            {
                var row = dt.NewRow();
                foreach (var fieldInfo in layerInfo.FieldInfos)
                {
                    var value = rs.GetFieldValue(fieldInfo.FieldName);
                    row[fieldInfo.FieldName] = value;
                }
                dt.Rows.Add(row);
                rs.MoveNext();
            }
            return(dt);
        }
コード例 #27
0
 //复制某记录到另外记录中
 private void CopyRecordset(Recordset sour_recdst, Recordset dest_recdst)
 {
     try
     {
         FieldInfos dest_fis = dest_recdst.GetFieldInfos();
         FieldInfos sour_fis = sour_recdst.GetFieldInfos();
         dest_recdst.Batch.Begin();
         while (!sour_recdst.IsEOF)
         {
             if (dest_recdst.AddNew(sour_recdst.GetGeometry()))
             {
                 Dictionary <string, object> arrValues = new Dictionary <string, object>();
                 foreach (FieldInfo item in dest_fis)
                 {
                     if (!item.IsSystemField)
                     {
                         int iDex = GetIndexByCaption(sour_fis, item.Name);
                         if (iDex > -1)
                         {
                             object obj = sour_recdst.GetFieldValue(iDex);
                             arrValues.Add(item.Name, obj);
                         }
                     }
                 }
                 //增加主体类型
                 {
                     arrValues.Add("ZTLX", m_strZTLX);
                 }
                 bool bRes = dest_recdst.SetValues(arrValues);
             }
             sour_recdst.MoveNext();
         }
         dest_recdst.Batch.Update();
     }
     catch { }
 }
コード例 #28
0
        public void AttQuery(DataGridView bd_DataGridAttit)
        {
            try
            {
                DataGridView mDataGridAttit = bd_DataGridAttit;
                mDataGridAttit.Columns.Clear();
                mDataGridAttit.Rows.Clear();
                Selection3D[] selection = mSceneControl.Scene.FindSelection(true);
                // 判断选择集是否为空
                if (selection == null || selection.Length == 0)
                {
                    MessageBox.Show("请选择要查询属性的空间对象");
                    return;
                }
                //将选择集转换为记录
                Recordset     recordset = selection[0].ToRecordset();
                DatasetVector dataset   = recordset.Dataset;
                mDataGridAttit.Columns.Add("", "字段");
                mDataGridAttit.Columns.Add("", "字段值");
                mDataGridAttit.Columns.Add("", "类型");
                mDataGridAttit.Columns.Add("", "长度");
                mDataGridAttit.Columns.Add("", "缺省值");

                string str   = "";
                string str_1 = "";
                string str1  = "";
                string str2  = "";
                object obj;
                string str3 = "";
                string str4 = "";
                for (int i = 0; i < dataset.FieldCount; i++)
                {
                    if (!recordset.GetFieldInfos()[i].IsSystemField)
                    {
                        if (recordset.GetFieldInfos()[i].Name == "SmPPoint" || recordset.GetFieldInfos()[i].Name == "SmNPoint")
                        {
                            continue;
                        }
                        str   = recordset.GetFieldInfos()[i].Name;
                        str_1 = recordset.GetFieldInfos()[i].Caption;
                        obj   = recordset.GetFieldValue(i);
                        if (obj != null)
                        {
                            str1 = obj.ToString();
                        }
                        else
                        {
                            str1 = null;
                        }
                        str2 = recordset.GetFieldInfos()[i].Type.ToString();
                        str3 = recordset.GetFieldInfos()[i].MaxLength.ToString();
                        str4 = recordset.GetFieldInfos()[i].DefaultValue;

                        mDataGridAttit.Rows.Add(new[] { str_1, str1, str2, str3, str4 });
                    }
                }
                mDataGridAttit.Update();
                recordset.Dispose();
            }
            catch (System.Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }
        }
コード例 #29
0
        /// <summary>
        /// 捕捉公交站点
        /// Snap the bus stops
        /// </summary>
        public void SnapPoint()
        {
            try
            {
                if (m_selection != null)
                {
                    // 获取被选中的站点对象
                    // Get the selected stop object
                    Recordset recordset = m_selection.ToRecordset();
                    GeoPoint  snapPoint = recordset.GetGeometry() as GeoPoint;

                    // 构造文本对象,用于在跟踪层上显示站点的名称
                    // Construct the text object, which is used to display the stop name on the tracking name
                    GeoText stopText = new GeoText();
                    // 站点名称
                    // Stop name
                    String stopName = "";
                    if (SuperMap.Data.Environment.CurrentCulture != "zh-CN")
                    {
                        stopName = recordset.GetFieldValue("Name_en").ToString();
                    }
                    else
                    {
                        stopName = recordset.GetFieldValue("Name").ToString();
                    }
                    TextPart textPart = new TextPart(stopName, new Point2D(snapPoint.X, snapPoint.Y));
                    stopText.AddPart(textPart);

                    if (m_isStartPoint)
                    {
                        // 绘制之前先清空跟踪层上的点和文字
                        // Clear all points and words on the tracking layer before drawing
                        Int32 indexStartStop = m_trackingLayer.IndexOf("StartStop");
                        if (indexStartStop != -1)
                        {
                            m_trackingLayer.Remove(indexStartStop);
                        }
                        Int32 indexStartText = m_trackingLayer.IndexOf("StartStopName");
                        if (indexStartText != -1)
                        {
                            m_trackingLayer.Remove(indexStartText);
                        }
                        // 分别设置站点及其名称文本的风格,并添加到跟踪层上
                        // Set the stop and name style and add them to the tracking layer
                        snapPoint.Style = GetStopStyle(new Size2D(8, 8), Color.FromArgb(236, 118, 0));
                        m_trackingLayer.Add(snapPoint, "StartStop");
                        stopText.TextStyle = GetStopTextStyle(6.0, Color.FromArgb(0, 0, 0));
                        m_trackingLayer.Add(stopText, "StartStopName");

                        // 设置为起始站点ID
                        // Set the strat stop ID
                        m_startStopID = recordset.GetInt64("STOPID");
                    }
                    else
                    {
                        // 绘制之前先清空跟踪层上的点和文字
                        // Clear all points and words on the tracking layer before drawing
                        Int32 indexEndStop = m_trackingLayer.IndexOf("EndStop");
                        if (indexEndStop != -1)
                        {
                            m_trackingLayer.Remove(indexEndStop);
                        }
                        Int32 indexEndText = m_trackingLayer.IndexOf("EndStopName");
                        if (indexEndText != -1)
                        {
                            m_trackingLayer.Remove(indexEndText);
                        }
                        // 分别设置站点及其名称文本的风格,并添加到跟踪层上
                        // Set the stop and name style and add them to the tracking layer
                        snapPoint.Style = GetStopStyle(new Size2D(8, 8), Color.FromArgb(22, 255, 0));
                        m_trackingLayer.Add(snapPoint, "EndStop");
                        stopText.TextStyle = GetStopTextStyle(6.0, Color.FromArgb(0, 0, 0));
                        m_trackingLayer.Add(stopText, "EndStopName");

                        // 设置为起始站点ID
                        // Set the strat stop ID
                        m_endStopID = recordset.GetInt64("STOPID");
                    }
                    recordset.Dispose();
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }
        }
コード例 #30
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("成功!");
        }
コード例 #31
0
        public string TransFile(byte[] fileBt, double width, string fileName, bool ifCreate)
        {
            // 0长度文件返回 0
            string rst = "0";

            if (fileBt.Length == 0)
            {
                return(rst);
            }
            string filePath = Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["CSVPath"].ToString());   //存储文件路径

            //创建系统日期文件夹,避免同一文件夹下文件太多问题,避免同一地图应文档重名
            filePath = filePath + DateTime.Now.ToString("yyyyMMdd") + "\\";

            if (!Directory.Exists(filePath))
            {
                Directory.CreateDirectory(filePath);
            }

            FileStream fstream;

            //是否创建新文件
            if (ifCreate)
            {
                fstream = new FileStream(filePath + fileName, FileMode.Create);
            }
            else
            {
                fstream = new FileStream(filePath + fileName, FileMode.Append);
            }
            try
            {
                fstream.Write(fileBt, 0, fileBt.Length);   //二进制转换成文件
                //上传成功返回 1
                fstream.Close();
            }
            catch (Exception ex)
            {
                //上传失败返回 1
                rst = "error";
            }
            finally
            {
                fstream.Close();
            }
            //读取坐标文件转换面积
            //设置为实际值
            string imgPath = filePath + fileName;
            //坐标点导入处理
            StreamReader objReader = new StreamReader(imgPath);
            string       sLine     = "";
            ArrayList    LineList  = new ArrayList();

            while (sLine != null)
            {
                sLine = objReader.ReadLine();
                if (sLine != null && !sLine.Equals(""))
                {
                    LineList.Add(sLine);
                }
            }
            objReader.Close();
            bool   isrewrite  = true;
            string sourcePath = Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["sourcePath"].ToString());   //存储文件路径
            string targetPath = Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["targetPath"].ToString());   //存储文件路径            String targetPath = str + "\\tempFolder\\temp_gkfqd.shp";
            string temp       = GenerateRandomCode(10);

            targetPath = targetPath + DateTime.Now.ToString("yyyyMMdd") + "\\";

            if (!Directory.Exists(targetPath))
            {
                Directory.CreateDirectory(targetPath);
            }
            targetPath = targetPath + temp + "\\";
            if (!Directory.Exists(targetPath))
            {
                Directory.CreateDirectory(targetPath);
            }
            System.IO.File.Copy(sourcePath + "testG.smwu", targetPath + "testG.smwu", isrewrite);
            System.IO.File.Copy(sourcePath + "test.udd", targetPath + "test.udd", isrewrite);
            System.IO.File.Copy(sourcePath + "test.udb", targetPath + "test.udb", isrewrite);
            this.fileWorkspace = new SuperMap.Data.Workspace();
            string workSpaceFilePath = Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["BinPath"].ToString());   //存储文件路径

            try
            {
                //打开工作空间及地图文件类型
                WorkspaceConnectionInfo conInfo = new WorkspaceConnectionInfo(targetPath + "testG.smwu");
                fileWorkspace.Open(conInfo);
                fileDatasource      = fileWorkspace.Datasources["test"];
                sourceDatasetVector = fileDatasource.Datasets["dataT"] as DatasetVector;
                Recordset recordset = (sourceDatasetVector as DatasetVector).GetRecordset(false, CursorType.Dynamic);
                // 获得记录集对应的批量更新对象
                Recordset.BatchEditor editor = recordset.Batch;
                // 开始批量添加,将 example 数据集每条记录对应的几何对象添加到数据集中
                editor.Begin();
                //删除所有记录
                recordset.DeleteAll();
                Point2Ds points = new Point2Ds();
                for (int i = 1; i < LineList.Count - 1; i++)
                {
                    string[] fieldInfoListZ = LineList[i].ToString().Split(',');
                    Point2D  point2D        = new Point2D();
                    point2D.X = double.Parse(fieldInfoListZ[0].ToString());
                    point2D.Y = double.Parse(fieldInfoListZ[1].ToString());
                    points.Add(point2D);
                }
                GeoLine geolineE = new GeoLine();
                geolineE.AddPart(points);
                recordset.AddNew(geolineE);
                editor.Update();
                //调用创建矢量数据集缓冲区方法
                //设置缓冲区分析参数
                BufferAnalystParameter bufferAnalystParam = new BufferAnalystParameter();

                //FLAT:平头缓冲。ROUND:圆头缓冲。
                bufferAnalystParam.EndType = BufferEndType.Flat;
                //左侧缓冲距离,单位:米。
                bufferAnalystParam.LeftDistance = width / 2;
                //右侧缓冲距离,单位:米。
                bufferAnalystParam.RightDistance = width / 2;
                String bufferName = "bufferRegionDt";
                bufferName      = fileDatasource.Datasets.GetAvailableDatasetName(bufferName);
                m_bufferDataset = fileDatasource.Datasets.Create(new DatasetVectorInfo(bufferName, DatasetType.Region));
                //设置投影信息 不设置 报投影不一致错误
                m_bufferDataset.Datasource.Datasets["bufferRegionDt"].PrjCoordSys = (fileDatasource.Datasets["dataT"] as DatasetVector).PrjCoordSys;
                Boolean   isTrue     = SuperMap.Analyst.SpatialAnalyst.BufferAnalyst.CreateBuffer(recordset, m_bufferDataset, bufferAnalystParam, false, true);
                Recordset recordsetS = m_bufferDataset.Query("SmID=1", CursorType.Static);
                pfm = double.Parse(recordsetS.GetFieldValue("SMAREA").ToString());
                mu  = pfm * 0.0015;
                double gongqing = 0.0666667 * mu;
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }
            rst = String.Format("{0:F2}", mu);
            fileWorkspace.Close();
            return(rst);
        }