private void buttonXPath_Click(object sender, EventArgs e) { FrmOpenData frmOpenData = new FrmOpenData(); frmOpenData.IsShowTable = true; if (frmOpenData.ShowDialog() == DialogResult.Cancel) { return; } Collection <object> tableCol = new Collection <object>(); tableCol = frmOpenData.TableCollection; IDataset dataset = null; //if (tableCol.Count == 1) if (tableCol.Count > 1) { dataset = tableCol[0] as IDataset; entiTable = tableCol[0] as ITable; } else { MessageBox.Show("请加载数据源", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (dataset == null) { MessageBox.Show("请加载匹配结果表!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } string tempResultTablePath = frmOpenData.PathName + @"\" + dataset.Name; if (string.IsNullOrEmpty(tempResultTablePath)) { return; } textBoxX1.Text = tempResultTablePath; }
/// <summary> /// 加载源数据按钮,更新数据按钮 /// </summary> public void buttonXAddData_Click() { FrmOpenData frmOpenData = new FrmOpenData(); if (frmOpenData.ShowDialog() == DialogResult.Cancel) { return; } string pathName = frmOpenData.PathName; Collection <object> featClsCol = new Collection <object>(); //获取选中的FeatureClass集合 featClsCol = frmOpenData.FeatClsCollection; ResourceManager rm = new ResourceManager("ZJGISDataUpdating.Properties.Resources", Assembly.GetExecutingAssembly()); if (featClsCol.Count > 0) { for (int i = 0; i < featClsCol.Count; i++) { IFeatureClass pNewFeatCls = featClsCol[i] as IFeatureClass; string fileName = pNewFeatCls.AliasName; DataGridViewRow dgvRow = new DataGridViewRow(); dgvRow = dataGridViewX1.Rows[dataGridViewX1.Rows.Add()]; //设置选中的实体的类型图标 if (pNewFeatCls.ShapeType == esriGeometryType.esriGeometryPolygon) { dgvRow.Cells[2].Value = (Bitmap)rm.GetObject("polygon"); dgvRow.Cells[2].Tag = "面"; } else if (pNewFeatCls.ShapeType == esriGeometryType.esriGeometryPolyline || pNewFeatCls.ShapeType == esriGeometryType.esriGeometryLine) { dgvRow.Cells[2].Value = (Bitmap)rm.GetObject("line"); dgvRow.Cells[2].Tag = "线"; } else if (pNewFeatCls.ShapeType == esriGeometryType.esriGeometryMultipoint || pNewFeatCls.ShapeType == esriGeometryType.esriGeometryPoint) { dgvRow.Cells[2].Value = (Bitmap)rm.GetObject("point"); dgvRow.Cells[2].Tag = "点"; } else { MessageBox.Show("请加载正确格式的数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); dataGridViewX1.Rows.Remove(dgvRow); return; } DataGridViewCheckBoxCell dgvCheckBoxCell = new DataGridViewCheckBoxCell(); dgvCheckBoxCell = dgvRow.Cells[0] as DataGridViewCheckBoxCell; dgvCheckBoxCell.Value = true; dgvRow.Cells[1].Value = fileName; dgvRow.Cells[1].Tag = pNewFeatCls; dgvRow.Cells[3].Value = pathName; } } #region comments //if (dataGridViewX1.Rows.Count > 0) //{ // for (int i = 0; i < dataGridViewX1.Rows.Count; i++) // { // if (dataGridViewX1.Rows[i].Visible == true) // { // string path = dataGridViewX1[3, i].Value.ToString(); // if (path.Contains(".")) // { // string type = path.Substring(path.LastIndexOf(".") + 1, 3); // if (type.ToUpper() == "GDB") // { // textBoxX1.Text = path.Substring(0, path.LastIndexOf(".")) + ".gdb"; // } // } // else // { // textBoxX1.Text = dataGridViewX1[3, i].Value.ToString(); // } // break; // } // } //} //ClsDeclare.g_WorkspacePath = textBoxX1.Text; #endregion }
/// <summary> /// 加载待更新的数据 /// </summary> public void btnAddData_Click() { //string path = ClsDeclare.g_WorkspacePath; //if (path == null || path == "") //{ // MessageBox.Show("请先加在源数据!"); // return; //} FrmOpenData frmOpenData = new FrmOpenData(); //frmOpenData.IsUpdateDate = true; if (frmOpenData.ShowDialog() == DialogResult.Cancel) { return; } string pathName = frmOpenData.PathName; Collection <object> featClsCol = new Collection <object>(); featClsCol = frmOpenData.FeatClsCollection; ResourceManager rm = new ResourceManager("ZJGISDataUpdating.Properties.Resources", Assembly.GetExecutingAssembly()); if (featClsCol.Count > 0) { for (int i = 0; i < featClsCol.Count; i++) { IFeatureClass pNewFeatCls = featClsCol[i] as IFeatureClass; string fileName = pNewFeatCls.AliasName; DataGridViewRow dgvRow = new DataGridViewRow(); dgvRow = dataGridViewX1.Rows[dataGridViewX1.Rows.Add()]; if (pNewFeatCls.ShapeType == esriGeometryType.esriGeometryPolygon) { dgvRow.Cells[2].Value = (Bitmap)rm.GetObject("polygon"); dgvRow.Cells[2].Tag = "面"; } else if (pNewFeatCls.ShapeType == esriGeometryType.esriGeometryPolyline || pNewFeatCls.ShapeType == esriGeometryType.esriGeometryLine) { dgvRow.Cells[2].Value = (Bitmap)rm.GetObject("line"); dgvRow.Cells[2].Tag = "线"; } else if (pNewFeatCls.ShapeType == esriGeometryType.esriGeometryMultipoint || pNewFeatCls.ShapeType == esriGeometryType.esriGeometryPoint) { dgvRow.Cells[2].Value = (Bitmap)rm.GetObject("point"); dgvRow.Cells[2].Tag = "点"; } else { MessageBox.Show("请加载正确格式的数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); dataGridViewX1.Rows.Remove(dgvRow); return; } DataGridViewCheckBoxCell dgvCheckBoxCell = new DataGridViewCheckBoxCell(); dgvCheckBoxCell = dgvRow.Cells[0] as DataGridViewCheckBoxCell; dgvCheckBoxCell.Value = true; dgvRow.Cells[1].Value = fileName; dgvRow.Cells[1].Tag = pNewFeatCls; dgvRow.Cells[3].Value = pathName; ////生成工作层 //IWorkspaceFactory2 pWorkspaceFactory = new FileGDBWorkspaceFactory() as IWorkspaceFactory2; //IWorkspace2 workspace; //string temp = path.Substring(path.LastIndexOf(".") + 1); //if (temp.ToUpper() == "GDB") //{ // workspace = pWorkspaceFactory.OpenFromFile(path, 0) as IWorkspace2; //} //else //{ // if (Directory.Exists(path + @"\temp.gdb")) // { // workspace = pWorkspaceFactory.OpenFromFile(path + @"\temp.gdb", 0) as IWorkspace2; // ClsDeclare.g_WorkspacePath = path + @"\temp.gdb"; // } // else // { // IWorkspaceName workspaceName = pWorkspaceFactory.Create(path, "temp", null, 0); // IName name = workspaceName as IName; // workspace = name.Open() as IWorkspace2; // ClsDeclare.g_WorkspacePath = path + @"\temp.gdb"; // } //} // if (dataGridViewX1.Rows.Count > 0) { for (int j = 0; j < dataGridViewX1.Rows.Count; j++) { if (dataGridViewX1.Rows[j].Visible == true) { string path = dataGridViewX1[3, j].Value.ToString(); if (path.Contains(".")) { string type = path.Substring(path.LastIndexOf(".") + 1, 3); if (type.ToUpper() == "GDB") { textBoxX1.Text = path.Substring(0, path.LastIndexOf(".")) + ".gdb"; } } else { textBoxX1.Text = dataGridViewX1[3, j].Value.ToString(); } } } } ClsDeclare.g_WorkspacePath = textBoxX1.Text; } } }
private void btOpenBrowser_Click(object sender, EventArgs e) { pFrmOpenData = new FrmOpenData((IBasicMap)m_pMap); pFrmOpenData.BlnAddData = m_bAddData; //不将数据载入mapcontrol pFrmOpenData.ShowDialog(); bool bHasIt = false; ////是否已经加载过 IGeoDataset pGeodataset = default(IGeoDataset); if (pFrmOpenData.DialogResult == System.Windows.Forms.DialogResult.OK) { ////批量载入要素类路径 if (m_PathCollection == null) { m_PathCollection = (Collection <object>)pFrmOpenData.PathCln; m_FeatClsCollection = (Collection <object>)pFrmOpenData.FeatClsCollection; //如果没有选中任何项,退出函数 if (m_PathCollection == null || m_PathCollection.Count == 0) { return; } // 20081213 if (m_FeatClsCollection.Count == 0) { return; } //修改为在datagridView中显示要素类 this.dgvData.Rows.Add(m_PathCollection.Count); for (m_iNum = 0; m_iNum <= m_PathCollection.Count - 1; m_iNum++) { pGeodataset = (IGeoDataset)m_FeatClsCollection[m_iNum]; this.dgvData.Rows[m_iNum].Tag = m_FeatClsCollection[m_iNum]; this.dgvData.Rows[m_iNum].Cells["colNum"].Value = m_iNum; this.dgvData.Rows[m_iNum].Cells["colFeatClsPath"].Value = m_PathCollection[m_iNum]; this.dgvData.Rows[m_iNum].Cells["colCoordinateSys"].Value = pGeodataset.SpatialReference.Name; } } else { //// 重复添加数据 Collection <object> NextPathCollection = null; Collection <object> NextFeatClsCollection = null; int j = 0; int k = 0; NextPathCollection = (Collection <object>)pFrmOpenData.PathCln; NextFeatClsCollection = (Collection <object>)pFrmOpenData.FeatClsCollection; // 处理选中要素集后确定出错的问题 if (NextFeatClsCollection.Count == 0) { return; } //印骅 如果没有选中任何项,退出函数 if (NextPathCollection == null || NextPathCollection.Count == 0) { return; } //for (int i = 0; i <= NextPathCollection.Count-1; i++) //{ // m_PathCollection.Add(NextPathCollection[i]); //} for (k = 0; k <= NextPathCollection.Count - 1; k++) { for (j = 0; j <= m_PathCollection.Count - 1; j++) { bHasIt = false; //重复项 if (NextPathCollection[k] == m_PathCollection[j]) { bHasIt = true; break; // TODO: might not be correct. Was : Exit For } } //添加非重复项 if (!bHasIt) { this.dgvData.Rows.Add(); pGeodataset = (IGeoDataset)NextFeatClsCollection[k]; this.dgvData.Rows[m_iNum].Cells["colNum"].Value = m_iNum; this.dgvData.Rows[m_iNum].Cells["colFeatClsPath"].Value = NextPathCollection[k]; this.dgvData.Rows[m_iNum].Cells["colCoordinateSys"].Value = pGeodataset.SpatialReference.Name; m_PathCollection.Add(NextPathCollection[k]); m_FeatClsCollection.Add(NextFeatClsCollection[k]); m_iNum += 1; } } } } }