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(); } } }
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(); } } }
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(); } } }
private void dg_Data_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs 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); int index = Convert.ToInt32(e.Row.HeaderCell.Value); if (objRt.SeekID(index)) { if (m_Application.MessageBox.Show("要删除第【" + index.ToString() + "】条数据吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { objRt.Delete(); objRt.Update(); } else { e.Cancel = true; } } m_SceneControl.Refresh(); } catch (Exception ex) { Log.OutputBox(ex); } finally { if (objRt != null) { objRt.Close(); objRt.Dispose(); } } }
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(); } } }
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(); } }
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); } }
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); } }
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(); }