private void frmRasterDataReduction_Load(object sender, EventArgs e) { SysCommon.CProgress vProgress = new SysCommon.CProgress("正在加载数据"); vProgress.EnableCancel = false; vProgress.ShowDescription = true; vProgress.FakeProgress = true; vProgress.TopMost = true; vProgress.ShowProgress(); GetDataTreeInitIndex dIndex = new GetDataTreeInitIndex(); string strExp = "select 数据源名称 from 物理数据源表"; string mypath = dIndex.GetDbInfo(); string strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + mypath + ";Mode=ReadWrite|Share Deny None;Persist Security Info=False";//生成连接数据库字符串 GeoDataCenterDbFun db = new GeoDataCenterDbFun(); List <string> list = db.GetDataReaderFromMdb(strCon, strExp); for (int i = 0; i < list.Count; i++) { comboBoxSource.Items.Add(list[i]);//加载数据源列表框 } if (list.Count > 0) { comboBoxSource.SelectedIndex = 0;//默认选择第一个 } vProgress.Close(); this.Activate(); }
//显示栅格目录 private void comboBoxSource_SelectedIndexChanged(object sender, EventArgs e) { comboBoxCatalog.Items.Clear(); comboBoxCatalog.Text = ""; //初始化进度条 SysCommon.CProgress vProgress = new SysCommon.CProgress("正在加载栅格目录"); vProgress.EnableCancel = false; vProgress.ShowDescription = true; vProgress.FakeProgress = true; vProgress.TopMost = true; vProgress.ShowProgress(); //IWorkspaceFactory Pwf = new FileGDBWorkspaceFactoryClass(); //IWorkspace pWorkspace = (IWorkspace)(Pwf.OpenFromFile(GetSourcePath(comboBoxSource.Text), 0)); IWorkspace pWorkspace = GetWorkspace(comboBoxSource.Text); if (pWorkspace == null) { MessageBox.Show("数据源空间不存在", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); vProgress.Close(); this.Activate(); return; } //获取所有的raster catalog目录 comboBoxCatalog.Items.Clear(); IEnumDataset enumDataset = pWorkspace.get_Datasets(esriDatasetType.esriDTRasterCatalog) as IEnumDataset; IDataset dataset = enumDataset.Next(); while (dataset != null) { string catalog = dataset.Name; if (!comboBoxCatalog.Items.Contains(catalog)) { comboBoxCatalog.Items.Add(catalog); } dataset = enumDataset.Next(); } if (comboBoxCatalog.Items.Count != 0) { comboBoxCatalog.SelectedIndex = 0; } vProgress.Close(); this.Activate(); }
public static TreeNode Node; //公共静态变量获得从数据单元树的节点 private void frmDataReduction_Load(object sender, EventArgs e) { m_first = true; //初始化进度条 SysCommon.CProgress vProgress = new SysCommon.CProgress("正在加载数据"); vProgress.EnableCancel = false; vProgress.ShowDescription = true; vProgress.FakeProgress = true; vProgress.TopMost = true; vProgress.ShowProgress(); LoadGridView(vProgress); vProgress.Close(); this.Activate(); }
//下载为MDB文件 private void btn_ExportNDB_Click(object sender, EventArgs e) { pWorkspace = GetWorkspace(comboBoxSource.Text); if (pWorkspace == null) { MessageBox.Show("数据源空间不存在", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } bool flag = false; //获取模板路径 string sourcefilename = Application.StartupPath + "\\..\\Template\\DATATEMPLATE.mdb"; foreach (DataGridViewRow row in datagwSource.Rows) { if ((bool)row.Cells[0].EditedFormattedValue == true) { flag = true; } } if (!flag) { MessageBox.Show("没有选中行!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } SysCommon.CProgress vProgress = new SysCommon.CProgress("正在下载数据,请稍后"); try { if (File.Exists(sourcefilename))//原模板存在 { SaveFileDialog dlg = new SaveFileDialog(); dlg.Filter = "MDB数据|*.mdb"; dlg.OverwritePrompt = false; dlg.Title = "保存到MDB"; DialogResult result = MessageBox.Show("下载是否去掉前缀?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (dlg.ShowDialog() == DialogResult.OK) { //初始化进度条 vProgress.EnableCancel = false; vProgress.ShowDescription = false; vProgress.FakeProgress = true; vProgress.TopMost = true; vProgress.ShowProgress(); Application.DoEvents(); //IWorkspaceFactory pWorkspaceFactory = new FileGDBWorkspaceFactoryClass(); //pWorkspace = (IWorkspace)(pWorkspaceFactory.OpenFromFile(GetSourcePath(comboBoxSource.Text), 0)); //如果存在mdb,替换文件,则复制模板到指定路径 //如果存在mdb,不替换,则追加到这个文件 File.Copy(sourcefilename, dlg.FileName, true); string cellvalue = ""; IWorkspaceFactory Pwf = new AccessWorkspaceFactoryClass(); IWorkspace pws = (IWorkspace)(Pwf.OpenFromFile(dlg.FileName, 0)); IWorkspace2 pws2 = (IWorkspace2)pws; foreach (DataGridViewRow row in datagwSource.Rows) { if ((bool)row.Cells[0].EditedFormattedValue == true) { cellvalue = row.Cells[1].Value.ToString().Trim(); if (cellvalue.Contains(".")) { cellvalue = cellvalue.Substring(cellvalue.LastIndexOf(".") + 1); } if (result == DialogResult.Yes) { cellvalue = cellvalue.Substring(15); //去掉前缀 } pws2 = (IWorkspace2)pws; if (pws2.get_NameExists(esriDatasetType.esriDTFeatureClass, cellvalue)) { IFeatureClass tmpfeatureclass; IFeatureWorkspace pFeatureWorkspace = (IFeatureWorkspace)pws; tmpfeatureclass = pFeatureWorkspace.OpenFeatureClass(cellvalue); IDataset set = tmpfeatureclass as IDataset; set.CanDelete(); set.Delete(); flag = true; } IFeatureDataConverter_ConvertFeatureClass(pWorkspace, pws, row.Cells[1].Value.ToString().Trim(), cellvalue); } } vProgress.Close(); MessageBox.Show("下载成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Activate(); } } } catch (Exception ex) { vProgress.Close(); MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Activate(); } }
//导出数据 public static bool ExportDataGridview(DataGridViewX gridView, List <string> lstFields, string defaultName) { //添加进度条 ygc 2012-10-8 SysCommon.CProgress vProgress = new SysCommon.CProgress(); vProgress.ShowDescription = true; vProgress.ShowProgressNumber = true; vProgress.TopMost = true; vProgress.EnableCancel = true; vProgress.EnableUserCancel(true); vProgress.ProgresssValue = 0; vProgress.Step = 1; vProgress.ShowProgress(); vProgress.SetProgress("正在导出" + defaultName + "数据......"); Microsoft.Office.Interop.Excel.Application excel = null; Workbook wb = null; try { if (gridView.Rows.Count == 0) { return(false); } //建立Excel对象 excel = new Microsoft.Office.Interop.Excel.Application(); wb = excel.Application.Workbooks.Add(true); excel.Visible = true; wb.Application.ActiveWindow.Caption = defaultName; //生成字段名称 //for (int i = 0; i < gridView.ColumnCount; i++) //{ // if(!lstFields.Contains(gridView.Columns[i].HeaderText)) continue; // excel.Cells[1, i + 1] = gridView.Columns[i].HeaderText; //} for (int i = 0; i < lstFields.Count; i++) { //if (!lstFields.Contains(gridView.Columns[i].HeaderText)) continue; excel.Cells[1, i + 1] = gridView.Columns[lstFields[i]].HeaderText; } vProgress.MaxValue = gridView.Columns.Count * gridView.Rows.Count; int t = 0; //填充数据 for (int i = 0; i < gridView.RowCount; i++) { for (int j = 0; j < lstFields.Count; j++) { //if (!lstFields.Contains(gridView.Columns[j].HeaderText)) continue; int intFieldIndex = gridView.Columns.IndexOf(gridView.Columns[lstFields[j]]); if (gridView[intFieldIndex, i].ValueType == typeof(string)) { if (gridView[intFieldIndex, i].Value != null) { excel.Cells[i + 2, j + 1] = "'" + gridView[intFieldIndex, i].Value.ToString(); } } else { if (gridView[intFieldIndex, i].Value != null) { excel.Cells[i + 2, j + 1] = gridView[intFieldIndex, i].Value.ToString(); } } t++; vProgress.ProgresssValue = t; } } vProgress.Close(); Microsoft.Office.Core.FileDialog fd = wb.Application.get_FileDialog(Microsoft.Office.Core.MsoFileDialogType.msoFileDialogSaveAs); fd.InitialFileName = defaultName; int result = fd.Show(); if (result == 0) { return(true); } string fileName = fd.InitialFileName; if (!string.IsNullOrEmpty(fileName)) { if (fileName.IndexOf(".xls") == -1) { fileName += ".xls"; } wb.SaveAs(fileName, XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, Type.Missing, Type.Missing, XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); } return(true); } catch { vProgress.Close(); return(false); } }
private void dgvCheckItem_CellClick(object sender, DataGridViewCellEventArgs e) { if (dgvCheckItem.CurrentRow == null) { return; } if (dgvCheckItem.CurrentRow.Cells["IsRight"].Value.ToString() != "检查未通过") { return; } string LayerName = dgvCheckItem.CurrentRow.Cells["LayerName"].Value.ToString(); IFeatureClass pFeaureClass = GetFeatureClassByName(m_DicErrorData, LayerName); if (pFeaureClass == null) { return; } string Condition = dgvCheckItem.CurrentRow.Cells["CONDITION"].Value.ToString(); System.Data.DataTable ErrorTable = InitializeErrorTable("错误信息"); IQueryFilter pFilter = new QueryFilterClass(); pFilter.WhereClause = Condition; IFeatureCursor pFeatureCursor = null; SysCommon.CProgress vProgress = new SysCommon.CProgress(); vProgress.ShowDescription = true; vProgress.ShowProgressNumber = true; vProgress.TopMost = true; vProgress.EnableCancel = false; vProgress.EnableUserCancel(false); vProgress.MaxValue = pFeaureClass.FeatureCount(pFilter); vProgress.ProgresssValue = 0; vProgress.Step = 1; vProgress.ShowProgress(); try { pFeatureCursor = pFeaureClass.Search(pFilter, false); IFeature pFeature = pFeatureCursor.NextFeature(); while (pFeature != null) { int shengIndex = pFeature.Fields.FindField("sheng"); DataRow newRow = ErrorTable.NewRow(); newRow["LayerName"] = pFeaureClass.AliasName; newRow["sheng"] = ModXZQ.GetXzqName(Plugin.ModuleCommon.TmpWorkSpace, pFeature.get_Value(shengIndex).ToString().Substring(0, 2)); int shiIndex = pFeature.Fields.FindField("shi"); newRow["shi"] = ModXZQ.GetXzqName(Plugin.ModuleCommon.TmpWorkSpace, pFeature.get_Value(shiIndex).ToString().Substring(0, 4)); int xianIndex = pFeature.Fields.FindField("xian"); newRow["xian"] = ModXZQ.GetXzqName(Plugin.ModuleCommon.TmpWorkSpace, pFeature.get_Value(xianIndex).ToString().Substring(0, 6)); int xiangIndex = pFeature.Fields.FindField("xiang"); newRow["xiang"] = ModXZQ.GetXzqName(Plugin.ModuleCommon.TmpWorkSpace, pFeature.get_Value(xiangIndex).ToString().Substring(0, 8)); int cunIndex = pFeature.Fields.FindField("cun"); newRow["cun"] = ModXZQ.GetXzqName(Plugin.ModuleCommon.TmpWorkSpace, pFeature.get_Value(cunIndex).ToString().Substring(0, 10)); int xbhIndex = pFeature.Fields.FindField("xbh"); newRow["xbh"] = pFeature.get_Value(xbhIndex).ToString(); ErrorTable.Rows.Add(newRow); pFeature = pFeatureCursor.NextFeature(); vProgress.ProgresssValue += 1; } } catch (Exception ex) { vProgress.Close(); } vProgress.Close(); dgvCheckResultData.DataSource = ErrorTable; DataGridViewCellStyle ds = new DataGridViewCellStyle(); ds.ForeColor = Color.Red; for (int i = 0; i < dgvCheckResultData.Rows.Count; i++) { dgvCheckResultData.Rows[i].DefaultCellStyle = ds; } for (int j = 0; j < dgvCheckResultData.Columns.Count; j++) { dgvCheckResultData.Columns[j].HeaderText = ErrorTable.Columns[j].Caption; dgvCheckResultData.Columns[j].SortMode = DataGridViewColumnSortMode.NotSortable; dgvCheckResultData.Columns[j].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } }