private void CheckedNode(TreeNode treeNode, DataTable tb) { if (!treeNode.Checked) { List <DataRow> removeList = new List <DataRow>(); foreach (DataRow dr in tb.Rows) { if (dr[0].ToString() == treeNode.Text) { removeList.Add(dr); } } foreach (DataRow dr in removeList) { tb.Rows.Remove(dr); } LayerModel mm = new LayerModel(); foreach (LayerModel item in model.allLines) { if (item.Name == treeNode.Text) { mm = item; } } model.allLines.Remove(mm); model.selectedLayerList.Remove(treeNode.Text); } else { ModelBaseMethod <ModelBase> modelMe = new ModelBaseMethod <ModelBase>(); LayerModel lyModel = modelMe.GetAllLayerGemo(model, treeNode.Text); if (!model.selectedLayerList.Contains(treeNode.Text)) { model.selectedLayerList.Add(treeNode.Text); } GetLineDataRowInfo(lyModel.pointFs, tb, treeNode.Text); if (this.model.allLines == null) { this.model.allLines = new List <LayerModel>(); } this.model.allLines.Add(lyModel); } this.dataGridView1.DataSource = tb; }
private void AutoInitData() { ModelBase mb = new ModelBase(); try { mb = ChangeToModel(mb); isOnlyModel = mb.IsOnlyModel; mb.DocName = System.IO.Path.GetFileNameWithoutExtension(CadHelper.fileName); ModelBaseMethod <ModelBase> mbm = new ModelBaseMethod <ModelBase>(); // mbm.GetLengedPoints(mb); mbm.GetAllLengedGemo(mb); mbm.GetExportLayers(mb); LayerSpecialCommand <ModelBase> layerSpecial = new LayerSpecialCommand <ModelBase>(); layerSpecial.AddSpecialLayerModel(mb); // mb.AddSpecialLayerModel(); DataTable tb = new DataTable(); tb.Columns.Add("所在图层"); //tb.Columns.Add("图例文本"); //tb.Columns.Add("图例线段"); if (mb.LegendList != null) { tb.Columns.Add("数据图层"); tb.Columns.Add("图例框顶点"); for (int i = 0; i < mb.LegendList.Count; i++) { DataRow dr = tb.NewRow(); dr[0] = MethodCommand.LegendLayer; dr["数据图层"] = mb.LegendList[i].LayerName; string peakPoint = ""; foreach (PointF PT in mb.LegendList[i].BoxPointList) { peakPoint += "Point:" + PT.X + "," + PT.Y + ";"; } dr["图例框顶点"] = peakPoint; AnalyBlockList(tb, dr, mb.LegendList[i].GemoModels, "图例"); //for (int j = 0; j < mb.LegendList.Count; j++) //{ // if (colNum <= j + 1) // { // colNum++; // DataColumn dc = new DataColumn("Point" + (j + 1)); // tb.Columns.Add(dc); // } // dr[j + 1] = "X:" + mb.LegendList[i][j].X + ",Y:" + mb.LegendList[i][j].Y; //} tb.Rows.Add(dr); } } if (mb.LayerList != null) { TreeNode rotNode = new TreeNode("图层筛选"); this.treeView1.Nodes.Add(rotNode); foreach (string layer in mb.LayerList) { TreeNode node = new TreeNode(layer); rotNode.Nodes.Add(node); } this.treeView1.ExpandAll(); } if (mb is RoadModel) { if (mb is RoadSectionModel) { LayerModel spModel = (mb as RoadSectionModel).allLines[(mb as RoadSectionModel).allLines.Count - 1]; GetSpecialDataRowInfo(spModel.modelItemList, tb, spModel.Name); } if (mb is RoadNoSectionModel) { LayerModel spModel = (mb as RoadNoSectionModel).allLines[(mb as RoadNoSectionModel).allLines.Count - 1]; GetSpecialDataRowInfo(spModel.modelItemList, tb, spModel.Name); } } else if (mb is PipeModel) { LayerModel spModel = (mb as PipeModel).allLines[(mb as PipeModel).allLines.Count - 1]; GetSpecialDataRowInfo(spModel.modelItemList, tb, spModel.Name); } this.dataGridView1.DataSource = tb; model = mb; if (treeView1.Nodes.Count > 0) { treeView1.Nodes[0].Checked = true; } } catch { System.IO.FileStream fs = new System.IO.FileStream(@"C:\Users\Administrator\Desktop\测试结果.txt", System.IO.FileMode.Create); System.IO.StreamWriter sw = new System.IO.StreamWriter(fs); //开始写入 sw.WriteLine(mb.DocName); //清空缓冲区 sw.Flush(); //关闭流 sw.Close(); fs.Close(); } }