private void btnReadMultTxt_Click(object sender, EventArgs e) { var ofd = new OpenFileDialog { RestoreDirectory = true, Filter = @"文本文件(*.txt)|*.txt|所有文件(*.*)|*.*", Multiselect = true }; if (ofd.ShowDialog() != DialogResult.OK) { return; } _errorMsg = @"失败文件名:"; pbCount.Maximum = ofd.FileNames.Length; pbCount.Value = 0; lblTotal.Text = ofd.FileNames.Length.ToString(CultureInfo.InvariantCulture); foreach (var fileName in ofd.FileNames) { var encoder = TxtFileEncoding.GetEncoding(fileName, Encoding.GetEncoding("GB2312")); var sr = new StreamReader(fileName, encoder); string duqu; while ((duqu = sr.ReadLine()) != null) { try { var str = duqu.Split('|'); var borehole = Borehole.FindOneByBoreholeNum(str[0]) ?? new Borehole { BindingId = IDGenerator.NewBindingID() }; borehole.BoreholeNumber = str[0]; borehole.GroundElevation = Convert.ToDouble(str[3]); borehole.CoordinateX = Convert.ToDouble(str[1].Split(',')[0]); borehole.CoordinateY = Convert.ToDouble(str[1].Split(',')[1]); borehole.CoordinateZ = 0; borehole.CoalSeamsTexture = String.Empty; // 创建钻孔岩性实体 var boreholeLithology = new BoreholeLithology { Borehole = borehole, Lithology = Lithology.FindOneByCoal(), FloorElevation = Convert.ToDouble(str[4]), CoalSeamsName = CoalSeams.FindAll().First().CoalSeamsName, Thickness = Convert.ToDouble(str[2]), CoordinateX = Convert.ToDouble(str[1].Split(',')[0]), CoordinateY = Convert.ToDouble(str[1].Split(',')[1]), CoordinateZ = 0 }; borehole.BoreholeLithologys = new[] { boreholeLithology }; DrawZuanKong(borehole, boreholeLithology); borehole.Save(); } catch (Exception) { lblError.Text = (Convert.ToInt32(lblError.Text) + 1).ToString(CultureInfo.InvariantCulture); lblSuccessed.Text = (Convert.ToInt32(lblSuccessed.Text) - 1).ToString(CultureInfo.InvariantCulture); _errorMsg += fileName.Substring(fileName.LastIndexOf(@"\", StringComparison.Ordinal) + 1) + "\n"; btnDetails.Enabled = true; } } lblSuccessed.Text = (Convert.ToInt32(lblSuccessed.Text) + 1).ToString(CultureInfo.InvariantCulture); pbCount.Value++; } Alert.alert("导入成功!"); }
/// <summary> /// 见煤钻孔 /// </summary> /// <param name="breholeEntity">钻孔实体</param> /// <param name="boreholeLithologyEntity">钻孔岩性实体</param> private void DrawZuanKong(Borehole breholeEntity, BoreholeLithology boreholeLithologyEntity) { ////1.获得当前编辑图层 //DrawSpecialCommon drawspecial = new DrawSpecialCommon(); //string sLayerAliasName = LibCommon.LibLayerNames.DEFALUT_BOREHOLE;//“默认_钻孔”图层 //IFeatureLayer featureLayer = drawspecial.GetFeatureLayerByName(sLayerAliasName); //if (featureLayer == null) //{ // MessageBox.Show("未找到" + sLayerAliasName + "图层,无法绘制钻孔图元。"); // return; //} ////2.绘制图元 //IPoint pt = new PointClass(); //pt.X = breholeEntity.CoordinateX; //pt.Y = breholeEntity.CoordinateY; //pt.Z = breholeEntity.CoordinateZ; ////标注内容 //string strH = breholeEntity.GroundElevation.ToString();//地面标高 //string strName = breholeEntity.BoreholeNumber.ToString();//孔号(名称) //string strDBBG = boreholeLithologyEntity.FloorElevation.ToString();//底板标高 //string strMCHD = boreholeLithologyEntity.Thickness.ToString();//煤层厚度 //GIS.SpecialGraphic.DrawZK1 drawZK1 = new GIS.SpecialGraphic.DrawZK1(strName, strH, strDBBG, strMCHD); //DataEditCommon.g_CurWorkspaceEdit.StartEditing(false); //DataEditCommon.g_CurWorkspaceEdit.StartEditOperation(); //IFeature feature = featureLayer.FeatureClass.CreateFeature(); //IGeometry geometry = pt; //DataEditCommon.ZMValue(feature, geometry); //几何图形Z值处理 ////drawspecial.ZMValue(feature, geometry);//几何图形Z值处理 //feature.Shape = pt;//要素形状 ////要素ID字段赋值(对应属性表中BindingID) //int iFieldID = feature.Fields.FindField("BID"); //feature.Value[iFieldID] =breholeEntity.BindingId.ToString(); //feature.Store();//存储要素 //DataEditCommon.g_CurWorkspaceEdit.StopEditOperation(); //DataEditCommon.g_CurWorkspaceEdit.StopEditing(true); //string strValue = feature.get_Value(feature.Fields.FindField("OBJECTID")).ToString(); //DataEditCommon.SpecialPointRenderer(featureLayer, "OBJECTID", strValue, drawZK1.m_Bitmap); /////3.显示钻孔图层 //if (featureLayer.Visible == false) // featureLayer.Visible = true; //IEnvelope envelop = feature.Shape.Envelope; //DataEditCommon.g_pMyMapCtrl.ActiveView.Extent = envelop; //DataEditCommon.g_pMyMapCtrl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewBackground, null, null); //DataEditCommon.g_pMyMapCtrl.ActiveView.Refresh(); IPoint pt = new PointClass(); pt.X = breholeEntity.CoordinateX; pt.Y = breholeEntity.CoordinateY; pt.Z = breholeEntity.CoordinateZ; if (double.IsNaN(pt.Z)) { pt.Z = 0; } var pLayer = DataEditCommon.GetLayerByName(DataEditCommon.g_pMap, LayerNames.DEFALUT_BOREHOLE); if (pLayer == null) { MessageBox.Show(@"未找到钻孔图层,无法绘制钻孔图元。"); return; } var pFeatureLayer = (IFeatureLayer)pLayer; IGeometry geometry = pt; var list = new List <ziduan> { new ziduan("bid", breholeEntity.BindingId), new ziduan("BOREHOLE_NUMBER", breholeEntity.BoreholeNumber), new ziduan("addtime", DateTime.Now.ToString(CultureInfo.InvariantCulture)), new ziduan("GROUND_ELEVATION", breholeEntity.GroundElevation.ToString(CultureInfo.InvariantCulture)), new ziduan("FLOOR_ELEVATION", boreholeLithologyEntity.FloorElevation.ToString(CultureInfo.InvariantCulture)), new ziduan("THICKNESS", boreholeLithologyEntity.Thickness.ToString(CultureInfo.InvariantCulture)), new ziduan("type", "2") }; var pfeature = DataEditCommon.CreateNewFeature(pFeatureLayer, geometry, list); if (pfeature != null) { MyMapHelp.Jump(pt); DataEditCommon.g_pMyMapCtrl.ActiveView.PartialRefresh( (esriViewDrawPhase)34, null, null); } }
/// <summary> /// 提 交 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSubmit_Click(object sender, EventArgs e) { // 验证 if (!Check()) { DialogResult = DialogResult.None; return; } var borehole = Borehole.FindOneByBoreholeNum(txtBoreholeNumber.Text) ?? new Borehole { BindingId = IDGenerator.NewBindingID() }; borehole.BoreholeNumber = txtBoreholeNumber.Text.Trim(); borehole.GroundElevation = Convert.ToDouble(txtGroundElevation.Text.Trim()); borehole.CoordinateX = Convert.ToDouble(txtCoordinateX.Text.Trim()); borehole.CoordinateY = Convert.ToDouble(txtCoordinateY.Text.Trim()); borehole.CoordinateZ = Convert.ToDouble(txtCoordinateZ.Text.Trim()); borehole.CoalSeamsTexture = string.Empty; var boreholeLithologys = new List <BoreholeLithology>(); for (var i = 0; i < gvCoalSeamsTexture.RowCount; i++) { // 最后一行为空行时,跳出循环 if (i == gvCoalSeamsTexture.RowCount - 1) { break; } // 创建钻孔岩性实体 var boreholeLithology = new BoreholeLithology { FloorElevation = Convert.ToDouble(gvCoalSeamsTexture.Rows[i].Cells[1].Value), Thickness = Convert.ToDouble(gvCoalSeamsTexture.Rows[i].Cells[2].Value), CoalSeamsName = gvCoalSeamsTexture.Rows[i].Cells[3].Value.ToString(), CoordinateX = Convert.ToDouble(gvCoalSeamsTexture.Rows[i].Cells[4].Value), CoordinateY = Convert.ToDouble(gvCoalSeamsTexture.Rows[i].Cells[5].Value), CoordinateZ = Convert.ToDouble(gvCoalSeamsTexture.Rows[i].Cells[6].Value), Lithology = Lithology.FindOneByLithologyName(gvCoalSeamsTexture.Rows[i].Cells[0].Value.ToString()), Borehole = borehole }; boreholeLithologys.Add(boreholeLithology); } borehole.BoreholeLithologys = boreholeLithologys; borehole.Save(); // var dlgResult = MessageBox.Show(@"是:见煤钻孔,否:未见煤钻孔,取消:不绘制钻孔", @"绘制钻孔", // MessageBoxButtons.YesNoCancel); // if (dlgResult == DialogResult.Yes) // { // DrawZuanKong(borehole, boreholeLithologyEntityList[0]); // } // else if (dlgResult == DialogResult.No) // { // DrawZuanKong(borehole); // } // else if (dlgResult == DialogResult.Cancel) // { // } //} //else //{ //1.获得当前编辑图层 var drawspecial = new DrawSpecialCommon(); const string sLayerAliasName = LayerNames.DEFALUT_BOREHOLE; //“默认_钻孔”图层 var featureLayer = drawspecial.GetFeatureLayerByName(sLayerAliasName); if (featureLayer == null) { MessageBox.Show(@"未找到" + sLayerAliasName + @"图层,无法删钻孔图元。"); return; } if (borehole.BoreholeId != 0) { DataEditCommon.DeleteFeatureByBId(featureLayer, borehole.BindingId); } var dlgResult = MessageBox.Show(@"是:见煤钻孔,否:未见煤钻孔,取消:不绘制钻孔", @"绘制钻孔", MessageBoxButtons.YesNoCancel); switch (dlgResult) { case DialogResult.Yes: DrawZuanKong(borehole, borehole.BoreholeLithologys.First()); break; case DialogResult.No: DrawZuanKong(borehole); break; case DialogResult.Cancel: break; } DialogResult = DialogResult.OK; }