using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using DevComponents.DotNetBar; using GeoScene.Data; using GeoScene.Engine; using GeoScene.Globe; using System.IO; namespace Cyberpipe { public partial class FrmAnalysisGuiHuaResult : Office2007Form { //DataTable dt = null; //定位和闪烁初始化定义 int count = 0; private string flashflag = "single"; GSOFeature hlfeature = null; public GSOGlobeControl globleControl1; DevComponents.DotNetBar.Controls.DataGridViewX dataGridView2; List<MainFrm.LineStruct> lineStrcut = new List<MainFrm.LineStruct>(); PanelEx panel; //ToolStripStatusLabel toolStripNumbers; //ToolStripStatusLabel toolStripFeatureLength; string layer; string hxName; public FrmAnalysisGuiHuaResult(GSOGlobeControl _globleControl1, List<MainFrm.LineStruct> _lineStrcut, PanelEx p, DevComponents.DotNetBar.Controls.DataGridViewX _dataGridView1,string _layer,string _hxName) { InitializeComponent(); this.lineStrcut = _lineStrcut; panel = p; globleControl1 = _globleControl1; dataGridView2 = _dataGridView1; layer = _layer; hxName = _hxName; } private void FrmAnalysisGuiHuaResult_Load(object sender, EventArgs e) { DataTable dt = new DataTable(); dt.Columns.Add("管线类型"); dt.Columns.Add("编号"); for (int i = 0; i < lineStrcut.Count;i++ ) { if (lineStrcut[i].layerName == layer&&lineStrcut[i].hxName==hxName) { DataRow row = dt.NewRow(); row[0] = lineStrcut[i].layerName; row[1] = lineStrcut[i].layerCode; dt.Rows.Add(row); } } dataGridView1.DataSource = dt; dataGridView1.Columns[1].Width = 200; } private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { string BH=dataGridView1.Rows[e.RowIndex].Cells["编号"].Value.ToString(); GSOLayer gsoLayer = globleControl1.Globe.Layers.GetLayerByCaption(layer); GSOFeatures rowFeatures = gsoLayer.GetFeatureByName(BH, true); GSOFeature feature = rowFeatures[0]; hlfeature = feature; highlight(); //globleControl1.Globe.FlyToFeature(feature, 0, 45, 3); globleControl1.Globe.JumpToFeature(feature, 10); #region //string layer = dataGridView1.Rows[e.RowIndex].Cells["管线类型"].Value.ToString(); //string sql = "select " + getpipeLineFields.getFields(layer, globleControl1) + " from " + layer + " where 编号 = "; //for (int i = 0; i < lineStrcut.Count; i++) //{ // if (i == lineStrcut.Count - 1) // { // sql += "'" + lineStrcut[i].layerCode + "'"; // } // else // { // sql += "'" + lineStrcut[i].layerCode + "'" + " or 编号 = "; // } //} //DataTable table = OledbHelper.QueryTable(sql); //if (table != null && table.Rows.Count > 0) //{ // dataGridView2.DataSource = table; // panel.Visible = true; // toolStripNumbers.Text =layer; // toolStripFeatureLength.Text = " 共有:" + table.Rows.Count + "条"; //} //else //{ //} #endregion } /// <summary> /// 高亮显示 /// </summary> public void highlight() { flashflag = "single"; timer1.Start(); } private void timer1_Tick(object sender, EventArgs e) { GSOFeature rowFeature = hlfeature;//as GSOFeature; if (rowFeature == null) return; if (count < 100) { count++; if (flashflag == "single") { if (rowFeature != null) { if (count % 2 != 0) { rowFeature.HighLight = true; globleControl1.Refresh(); } else { rowFeature.HighLight = false; globleControl1.Refresh(); } } } } else { timer1.Stop(); rowFeature.HighLight = false; count = 0; } } private void FrmAnalysisGuiHuaResult_FormClosing(object sender, FormClosingEventArgs e) { //dataGridView2.DataSource = null; //dataGridView2.Refresh(); //panel.Visible = false; //toolStripNumbers.Text = " 类型:"; //toolStripFeatureLength.Text = " 管线里程:"; //lineStrcut.Clear(); timer1.Stop(); this.Close(); } int rowIndex = 0; private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { rowIndex = e.RowIndex; } private void buttonXExp_Click(object sender, EventArgs e) { ExportExcel("红线审核详细结果", dataGridView1, null); } /// <summary> /// 导出指定DataGridView控件中的内容 /// </summary> /// <param name="type"></param> /// <param name="_dataGridView"></param> private void ExportExcel(string type, DataGridView _dataGridView, ListBox _listBox) { if (_dataGridView.Rows.Count > 0) { SaveFileDialog dlg = new SaveFileDialog(); dlg.Filter = "Excel files (*.xls)|*.xls"; dlg.FilterIndex = 0; dlg.RestoreDirectory = true; dlg.Title = "保存为Excel文件"; dlg.FileName = type + "-" + DateTime.Now.ToString("yyyyMMdd") + ".xls"; if (dlg.ShowDialog() == DialogResult.OK) { Stream myStream; myStream = dlg.OpenFile(); StreamWriter sw = new StreamWriter(myStream, System.Text.Encoding.GetEncoding(-0)); string columnTitle = ""; try { if (_listBox != null) { string strList = ""; for (int i = 0; i < _listBox.Items.Count; i++) { strList += _listBox.Items[i].ToString() + @"/"; } sw.WriteLine("内容:" + type + " 日期:" + DateTime.Now.ToString("yyyy-MM-dd") + " 结果:" + strList); } else { sw.WriteLine("内容:" + type + " 日期:" + DateTime.Now.ToString("yyyy-MM-dd")); } //写入列标题 for (int i = 0; i < _dataGridView.ColumnCount; i++) { if (i > 0) { columnTitle += "\t"; } columnTitle += _dataGridView.Columns[i].HeaderText; } sw.WriteLine(columnTitle); //写入列内容 for (int j = 0; j < _dataGridView.Rows.Count; j++) { string columnValue = ""; for (int k = 0; k < _dataGridView.Columns.Count; k++) { if (k > 0) { columnValue += "\t"; } if (_dataGridView.Rows[j].Cells[k].Value == null) { columnValue += ""; } else { columnValue += _dataGridView.Rows[j].Cells[k].Value.ToString().Trim(); } } sw.WriteLine(columnValue); } sw.Close(); myStream.Close(); if (MessageBox.Show("导出Excel文件成功!是否打开?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes) { System.Diagnostics.Process.Start(dlg.FileName); } } catch (Exception ex) { //MessageBox.Show(ex.ToString()); } finally { sw.Close(); myStream.Close(); } } } } } }