///// <params name="verticesBtmRet">Vector3_DW数据</params> /// <summary> /// 根据导线点坐标绘制巷道 /// </summary> /// <summary> /// 获得导线边线点坐标集 /// </summary> /// <returns>导线边线点坐标集List</returns> //private List<IPoint> GetTunnelPts(Vector3_DW[] verticesBtmRet) //{ // var lstBtmRet = new List<IPoint>(); // try // { // Vector3_DW vector3dw; // IPoint pt; // for (int i = 0; i < verticesBtmRet.Length; i++) // { // vector3dw = new Vector3_DW(); // vector3dw = verticesBtmRet[i]; // pt = new PointClass(); // pt.X = vector3dw.X; // pt.Y = vector3dw.Y; // pt.Z = vector3dw.Z; // if (!lstBtmRet.Contains(pt)) // { // lstBtmRet.Add(pt); // } // } // return lstBtmRet; // } // catch // { // return null; // } //} #endregion 绘制导线点和巷道图形 private void btnMultTxt_Click(object sender, EventArgs e) { var ofd = new OpenFileDialog { RestoreDirectory = true, Multiselect = true, Filter = @"文本文件(*.txt)|*.txt|所有文件(*.*)|*.*" }; _errorMsg = @"失败文件名:"; if (ofd.ShowDialog() != DialogResult.OK) { return; } var fileCount = ofd.FileNames.Length; pbCount.Maximum = fileCount * 2; pbCount.Value = 0; foreach (var fileName in ofd.FileNames) { lblTotal.Text = fileCount.ToString(CultureInfo.InvariantCulture); string safeFileName = null; try { using (new SessionScope()) { safeFileName = fileName.Substring(fileName.LastIndexOf(@"\", StringComparison.Ordinal) + 1); var strs = safeFileName.Split('-'); var miningAreaName = strs[0]; var workingFaceName = strs[1]; var tunnelName = strs[2].Split('.')[0]; var miningArea = MiningArea.FindAllByProperty("name", miningAreaName).FirstOrDefault(); if (miningArea == null) { var newMiningArea = new MiningArea { name = miningAreaName, horizontal = Horizontal.FindFirst() }; newMiningArea.Save(); miningArea = newMiningArea; } var workingFace = Workingface.findone_by_workingface_name_and_mining_area_id(workingFaceName, miningArea.id) ?? AddWorkingFace(miningArea, workingFaceName); if (workingFace == null) { return; } Tunnel tunnel; if (workingFace.tunnels != null && workingFace.tunnels.FirstOrDefault(u => u.name == tunnelName) != null) { tunnel = workingFace.tunnels.FirstOrDefault(u => u.name == tunnelName); } else { tunnel = AddTunnel(workingFace, tunnelName); } var sr = new StreamReader(fileName, Encoding.GetEncoding("GB2312")); string fileContent; var wire = Wire.FindAllByProperty("tunnel.id", tunnel.id).FirstOrDefault(); if (wire != null) { wire.name = tunnelName.Split('.').Length > 0 ? tunnelName.Split('.')[0] + "导线点" : tunnelName + "导线点"; } else { wire = new Wire { tunnel = tunnel, check_date = DateTime.Now, measure_date = DateTime.Now, count_date = DateTime.Now, name = tunnelName.Split('.').Length > 0 ? tunnelName.Split('.')[0] + "导线点" : tunnelName + "导线点" }; } wire.Save(); var wirePoints = new List <WirePoint>(); while ((fileContent = sr.ReadLine()) != null) { if (String.IsNullOrEmpty(fileContent)) { continue; } var temp1 = fileContent.Split('|'); var pointName = temp1[0]; var pointX = temp1[1]; var pointY = temp1[2]; wirePoints.Add(new WirePoint { bid = IdGenerator.NewBindingId(), name = pointName, wire = wire, coordinate_x = Convert.ToDouble(pointX), coordinate_y = Convert.ToDouble(pointY), coordinate_z = 0, left_distance = 2.5, right_distance = 2.5, top_distance = 0, bottom_distance = 0 }); } if (wirePoints.Count < 2) { throw new Exception(); } pbCount.Value++; DrawWirePoint(wirePoints, "CHANGE"); double hdwid; _dics = ConstructDics(tunnel, out hdwid); UpdateHdbyPnts(tunnel.id, wirePoints, _dics, hdwid); pbCount.Value++; lblSuccessed.Text = (Convert.ToInt32(lblSuccessed.Text) + 1).ToString(CultureInfo.InvariantCulture); } } catch (Exception ex) { pbCount.Value++; lblError.Text = (Convert.ToInt32(lblError.Text) + 1).ToString(CultureInfo.InvariantCulture); _errorMsg += safeFileName + "\n"; btnDetails.Enabled = true; } } Alert.AlertMsg("导入完成"); }
private void btnTXT_Click(object sender, EventArgs e) { var ofd = new OpenFileDialog { RestoreDirectory = true, Filter = @"文本文件(*.txt)|*.txt|所有文件(*.*)|*.*" }; if (ofd.ShowDialog() != DialogResult.OK) return; var fileName = ofd.SafeFileName; if (fileName != null) { var strs = fileName.Split('-'); var miningAreaName = strs[0]; var workingFaceName = strs[1]; var tunnelName = strs[2].Split('.')[0]; using (new SessionScope()) { var miningArea = MiningArea.FindAllByProperty("name", miningAreaName).FirstOrDefault(); if (miningArea == null) { var newMiningArea = new MiningArea { name = miningAreaName, horizontal = Horizontal.FindFirst() }; newMiningArea.Save(); miningArea = newMiningArea; } var workingFace = Workingface.findone_by_workingface_name_and_mining_area_id(workingFaceName, miningArea.id); if (workingFace == null) { if (Alert.Confirm("该工作面不存在,是否创建该工作面?")) { workingFace = AddWorkingFace(miningArea, workingFaceName); } } if (workingFace == null) return; if (workingFace.tunnels != null && workingFace.tunnels.FirstOrDefault(u => u.name == tunnelName) != null) { var tunnel = workingFace.tunnels.FirstOrDefault(u => u.name == tunnelName); selectTunnelUserControl1.LoadData(tunnel); } else { if (Alert.Confirm("该巷道不存在,是否创建该巷道?")) { if (Tunnel.exists_by_tunnel_name_and_working_face_id(tunnelName, workingFace.id)) { Alert.AlertMsg("该巷道已经存在"); return; } var tunnel = AddTunnel(workingFace, tunnelName); selectTunnelUserControl1.LoadData(tunnel); } } } txtWireName.Text = tunnelName.Split('.').Length > 0 ? tunnelName.Split('.')[0] + "导线点" : tunnelName + "导线点"; } var sr = new StreamReader(ofd.FileName, Encoding.GetEncoding("GB2312")); string duqu; while ((duqu = sr.ReadLine()) != null) { var temp1 = duqu.Split('|'); if (temp1.Length == 1) continue; var daoxianname = temp1[0]; var daoxianx = temp1[1]; var daoxiany = temp1[2]; dgrdvWire.Rows.Add(1); dgrdvWire[0, dgrdvWire.Rows.Count - 2].Value = daoxianname; dgrdvWire[1, dgrdvWire.Rows.Count - 2].Value = daoxianx; dgrdvWire[2, dgrdvWire.Rows.Count - 2].Value = daoxiany; dgrdvWire[3, dgrdvWire.Rows.Count - 2].Value = "0"; dgrdvWire[4, dgrdvWire.Rows.Count - 2].Value = "2.5"; dgrdvWire[5, dgrdvWire.Rows.Count - 2].Value = "2.5"; } }
private void btnTXT_Click(object sender, EventArgs e) { var ofd = new OpenFileDialog { RestoreDirectory = true, Filter = @"文本文件(*.txt)|*.txt|所有文件(*.*)|*.*" }; if (ofd.ShowDialog() != DialogResult.OK) { return; } var fileName = ofd.SafeFileName; if (fileName != null) { var strs = fileName.Split('-'); var miningAreaName = strs[0]; var workingFaceName = strs[1]; var tunnelName = strs[2].Split('.')[0]; using (new SessionScope()) { var miningArea = MiningArea.FindAllByProperty("name", miningAreaName).FirstOrDefault(); if (miningArea == null) { var newMiningArea = new MiningArea { name = miningAreaName, horizontal = Horizontal.FindFirst() }; newMiningArea.Save(); miningArea = newMiningArea; } var workingFace = Workingface.findone_by_workingface_name_and_mining_area_id(workingFaceName, miningArea.id); if (workingFace == null) { if (Alert.Confirm("该工作面不存在,是否创建该工作面?")) { workingFace = AddWorkingFace(miningArea, workingFaceName); } } if (workingFace == null) { return; } if (workingFace.tunnels != null && workingFace.tunnels.FirstOrDefault(u => u.name == tunnelName) != null) { var tunnel = workingFace.tunnels.FirstOrDefault(u => u.name == tunnelName); selectTunnelUserControl1.LoadData(tunnel); } else { if (Alert.Confirm("该巷道不存在,是否创建该巷道?")) { if (Tunnel.exists_by_tunnel_name_and_working_face_id(tunnelName, workingFace.id)) { Alert.AlertMsg("该巷道已经存在"); return; } var tunnel = AddTunnel(workingFace, tunnelName); selectTunnelUserControl1.LoadData(tunnel); } } } txtWireName.Text = tunnelName.Split('.').Length > 0 ? tunnelName.Split('.')[0] + "导线点" : tunnelName + "导线点"; } var sr = new StreamReader(ofd.FileName, Encoding.GetEncoding("GB2312")); string duqu; while ((duqu = sr.ReadLine()) != null) { var temp1 = duqu.Split('|'); if (temp1.Length == 1) { continue; } var daoxianname = temp1[0]; var daoxianx = temp1[1]; var daoxiany = temp1[2]; dgrdvWire.Rows.Add(1); dgrdvWire[0, dgrdvWire.Rows.Count - 2].Value = daoxianname; dgrdvWire[1, dgrdvWire.Rows.Count - 2].Value = daoxianx; dgrdvWire[2, dgrdvWire.Rows.Count - 2].Value = daoxiany; dgrdvWire[3, dgrdvWire.Rows.Count - 2].Value = "0"; dgrdvWire[4, dgrdvWire.Rows.Count - 2].Value = "2.5"; dgrdvWire[5, dgrdvWire.Rows.Count - 2].Value = "2.5"; } }
private void btnMultTxt_Click(object sender, EventArgs e) { var ofd = new OpenFileDialog { RestoreDirectory = true, Multiselect = true, Filter = @"文本文件(*.txt)|*.txt|所有文件(*.*)|*.*" }; _errorMsg = @"失败文件名:"; if (ofd.ShowDialog() != DialogResult.OK) return; var fileCount = ofd.FileNames.Length; pbCount.Maximum = fileCount * 2; pbCount.Value = 0; foreach (var fileName in ofd.FileNames) { lblTotal.Text = fileCount.ToString(CultureInfo.InvariantCulture); string safeFileName = null; try { using (new SessionScope()) { safeFileName = fileName.Substring(fileName.LastIndexOf(@"\", StringComparison.Ordinal) + 1); var strs = safeFileName.Split('-'); var miningAreaName = strs[0]; var workingFaceName = strs[1]; var tunnelName = strs[2].Split('.')[0]; var miningArea = MiningArea.FindAllByProperty("name", miningAreaName).FirstOrDefault(); if (miningArea == null) { var newMiningArea = new MiningArea { name = miningAreaName, horizontal = Horizontal.FindFirst() }; newMiningArea.Save(); miningArea = newMiningArea; } var workingFace = Workingface.findone_by_workingface_name_and_mining_area_id(workingFaceName, miningArea.id) ?? AddWorkingFace(miningArea, workingFaceName); if (workingFace == null) return; Tunnel tunnel; if (workingFace.tunnels != null && workingFace.tunnels.FirstOrDefault(u => u.name == tunnelName) != null) { tunnel = workingFace.tunnels.FirstOrDefault(u => u.name == tunnelName); } else { tunnel = AddTunnel(workingFace, tunnelName); } var sr = new StreamReader(fileName, Encoding.GetEncoding("GB2312")); string fileContent; var wire = Wire.FindAllByProperty("tunnel.id", tunnel.id).FirstOrDefault(); if (wire != null) { wire.name = tunnelName.Split('.').Length > 0 ? tunnelName.Split('.')[0] + "导线点" : tunnelName + "导线点"; } else { wire = new Wire { tunnel = tunnel, check_date = DateTime.Now, measure_date = DateTime.Now, count_date = DateTime.Now, name = tunnelName.Split('.').Length > 0 ? tunnelName.Split('.')[0] + "导线点" : tunnelName + "导线点" }; } wire.Save(); var wirePoints = new List<WirePoint>(); while ((fileContent = sr.ReadLine()) != null) { if (String.IsNullOrEmpty(fileContent)) continue; var temp1 = fileContent.Split('|'); var pointName = temp1[0]; var pointX = temp1[1]; var pointY = temp1[2]; wirePoints.Add(new WirePoint { bid = IdGenerator.NewBindingId(), name = pointName, wire = wire, coordinate_x = Convert.ToDouble(pointX), coordinate_y = Convert.ToDouble(pointY), coordinate_z = 0, left_distance = 2.5, right_distance = 2.5, top_distance = 0, bottom_distance = 0 }); } if (wirePoints.Count < 2) { throw new Exception(); } pbCount.Value++; DrawWirePoint(wirePoints, "CHANGE"); double hdwid; _dics = ConstructDics(tunnel, out hdwid); UpdateHdbyPnts(tunnel.id, wirePoints, _dics, hdwid); pbCount.Value++; lblSuccessed.Text = (Convert.ToInt32(lblSuccessed.Text) + 1).ToString(CultureInfo.InvariantCulture); } } catch (Exception ex) { pbCount.Value++; lblError.Text = (Convert.ToInt32(lblError.Text) + 1).ToString(CultureInfo.InvariantCulture); _errorMsg += safeFileName + "\n"; btnDetails.Enabled = true; } } Alert.AlertMsg("导入完成"); }