using DevExpress.CodeParser; using InterfaceWorkAreaData; using NPOI.SS.Formula.Functions; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.IO; using System.Linq; using System.Windows.Forms; //using WorkData; //using WorkData.Entity; //using WorkData.EntityBase; namespace GeoSigma.UCDraw.WellAndSection { public partial class FrmNewWellPole : Form { public cWellBaseInfo mwellInfo = new cWellBaseInfo(); public string mWellName; public string mTemplatefileNamePath; public float mTop; public float mBottom; public float mRatio; public string preSetWellName; //预先选定的井名称 string mTemplatePath; public string mFileName; public List wellNodeNames = new List(); class CTempfileInfo { public string fileName { get; set; } } List mTempFileList = new List(); class CRatioInfo { public string text { get; set; } public float value { get; set; } } List mRatioList = new List(); class CLayersInfo { public string text { get; set; } public int levelId { get; set; } } List mLayersInfo = new List(); class CWellLayerInfo { public string cw { get; set; } public int order { get; set; } public int id { get; set; } } BindingList mWellTopLayersInfo = new BindingList(); BindingList mWellBottomLayersInfo = new BindingList(); List mWellStrats = new List(); public int mWellDepthMode = 1; // =1是井段,=2是分层 public FrmNewWellPole() { InitializeComponent(); radioButtonDepth.Checked = true; radioButtonLayers.Checked = false; comboBoxLayers.Enabled = false; comboBoxTopLayer.Enabled = false; comboBoxBottomLayer.Enabled = false; //comboBoxTopLayer.DataSource = mWellLayersInfo; //comboBoxTopLayer.DisplayMember = "cw"; } private void btnOK_Click(object sender, EventArgs e) { if (comboxTemplate.SelectedItem is CTempfileInfo selectTemp) { if (selectTemp.fileName != "") mTemplatefileNamePath = mTemplatePath + selectTemp.fileName; else mTemplatefileNamePath = ""; } if (comBoxRatio.SelectedItem is CRatioInfo tratio) { mRatio = tratio.value; } if (wellNameCbx.SelectedItem is cWellBaseInfo wellInfo) { mWellName = wellInfo.WellName; mwellInfo = wellInfo; } else { mWellName = wellNameCbx.Text; mwellInfo.WellName = wellNameCbx.Text; mwellInfo.id = -1; } bool bSet = false; if (radioButtonLayers.Checked) { if ((comboBoxTopLayer.SelectedItem is CWellLayerInfo topLayer) && (comboBoxBottomLayer.SelectedItem is CWellLayerInfo bottomLayer)) { if (topLayer.order > bottomLayer.order) { MessageBox.Show("结束层位序号应大于结束层位"); this.DialogResult = DialogResult.None; } List selectlayers = new List(); selectlayers = mWellTopLayersInfo.Where(item => (item.order >= topLayer.order && item.order <= bottomLayer.order)).ToList(); int botLevelId = mLayersInfo[mLayersInfo.Count - 1].levelId; int levelId = -1; if (comboBoxLayers.SelectedItem is CLayersInfo layer) { levelId = layer.levelId; } List childsNodes = new List(); //实际的井段都是最底的地层,因此搜集最底层的井段 if (levelId < botLevelId) { for (int i = 0; i < selectlayers.Count; i++) { List tchildsNodes = GetAllChildren(mWellStrats, selectlayers[i].id); childsNodes.AddRange(tchildsNodes); } } else { for (int i = 0; i < selectlayers.Count; i++) { childsNodes.AddRange(mWellStrats.Where(item => item.code == selectlayers[i].cw).ToList()); } } List tWellLayers = workAreaDb.Instance.workData.getWellSandSets(mWellName); List selWellLayers = tWellLayers.Join(childsNodes, item => item.name, cnode => cnode.code, (item, cnode) => item).OrderBy(item => item.top).ToList(); if (selWellLayers.Count > 0) { mTop = (float)selWellLayers[0].top; mBottom = (float)selWellLayers[selWellLayers.Count - 1].bottom; bSet = true; } } } if (bSet == false) { float fv = 0; if (float.TryParse(textBoxWellTop.Text, out fv)) { mTop = fv; } if (float.TryParse(textBoxWellBottom.Text, out fv)) { mBottom = fv; } } mFileName = fileNameTextBox.Text; if (wellNodeNames.Contains(mFileName + ".pcg", StringComparer.OrdinalIgnoreCase)) { MessageBox.Show("存在同名文件,请修改名称"); this.DialogResult = DialogResult.None; } else { this.DialogResult = DialogResult.OK; } } // 递归获取所有子节点(包括子孙节点) List GetAllChildren(List allNodes, int parentId) { var children = new List(); // 查找直接子节点 var directChildren = allNodes.Where(n => n.parentId == parentId).ToList(); foreach (var child in directChildren) { children.Add(child); // 递归获取子节点的子节点 children.AddRange(GetAllChildren(allNodes, child.id)); } return children; } private void FrmNewWellPole_Shown(object sender, EventArgs e) { mTop = 0; mBottom = 1000; mRatio = 200; this.textBoxWellTop.Text = "500"; this.textBoxWellBottom.Text = "1000"; // this.textBoxWellName.Text = "新井"; if (preSetWellName != "") { List wellInfos = new List(); cWellBaseInfo wellinfo = new cWellBaseInfo(); wellinfo.id = 0; wellinfo.WellName = preSetWellName; wellinfo.WellCode = preSetWellName; wellInfos.Add(wellinfo); this.wellNameCbx.DataSource = wellInfos; this.wellNameCbx.DisplayMember = "WellName"; this.wellNameCbx.ValueMember = "id"; this.wellNameCbx.SelectedIndex = 0; setWellDepth(this.wellNameCbx.Text); } else { List wellInfos = workAreaDb.Instance.workData.getWellsInfo(); //wellInfos.Insert(0, new cWellBaseInfo());//插入一个空的井数据 if (wellInfos.Count > 0) { this.wellNameCbx.DataSource = wellInfos; this.wellNameCbx.DisplayMember = "WellName"; this.wellNameCbx.ValueMember = "id"; this.wellNameCbx.SelectedIndex = 0; setWellDepth(this.wellNameCbx.Text); } } CRatioInfo tratioInfo = new CRatioInfo(); tratioInfo.text = "1:50"; tratioInfo.value = 50; mRatioList.Add(tratioInfo); tratioInfo = new CRatioInfo(); tratioInfo.text = "1:100"; tratioInfo.value = 100; mRatioList.Add(tratioInfo); tratioInfo = new CRatioInfo(); tratioInfo.text = "1:200"; tratioInfo.value = 200; mRatioList.Add(tratioInfo); tratioInfo = new CRatioInfo(); tratioInfo.text = "1:500"; tratioInfo.value = 500; mRatioList.Add(tratioInfo); tratioInfo = new CRatioInfo(); tratioInfo.text = "1:800"; tratioInfo.value = 800; mRatioList.Add(tratioInfo); tratioInfo = new CRatioInfo(); tratioInfo.text = "1:1000"; tratioInfo.value = 1000; mRatioList.Add(tratioInfo); tratioInfo = new CRatioInfo(); tratioInfo.text = "1:2000"; tratioInfo.value = 2000; mRatioList.Add(tratioInfo); tratioInfo = new CRatioInfo(); tratioInfo.text = "1:5000"; tratioInfo.value = 5000; mRatioList.Add(tratioInfo); tratioInfo = new CRatioInfo(); tratioInfo.text = "1:10000"; tratioInfo.value = 10000; mRatioList.Add(tratioInfo); this.comBoxRatio.DataSource = mRatioList; this.comBoxRatio.DisplayMember = "text"; this.comBoxRatio.ValueMember = "value"; this.comBoxRatio.SelectedIndex = 2; CTempfileInfo tfile = new CTempfileInfo(); tfile.fileName = ""; mTempFileList.Add(tfile); //增加一个空的名称 mTemplatePath = AppDomain.CurrentDomain.BaseDirectory + "Templates\\WellPole\\"; if (Directory.Exists(mTemplatePath)) { try { var fileNames = Directory.GetFiles(mTemplatePath) .Select(Path.GetFileName) .OrderBy(name => name) .ToArray(); foreach (var fileName in fileNames) { string tname = fileName.ToLower(); String tstr1 = tname.Length > 4 ? tname.Substring(tname.Length - 4) : ""; if (tstr1 == ".pcg") { CTempfileInfo tfile1 = new CTempfileInfo(); tfile1.fileName = fileName; mTempFileList.Add(tfile1); } } } catch (Exception ex) { } } this.comboxTemplate.DataSource = mTempFileList; this.comboxTemplate.DisplayMember = "fileName"; this.comboxTemplate.SelectedIndex = 0; mWellStrats = workAreaDb.Instance.workData.getWellStratification(); List distinctByLevel = mWellStrats .GroupBy(item => item.level) .Select(g => g.First()) // 或 g.Last()、g.OrderBy(...).First() 等 .ToList(); for (int i = 0; i < distinctByLevel.Count; i++) { CLayersInfo tinfo = new CLayersInfo(); string str = (i + 1).ToString() + "级"; tinfo.levelId = distinctByLevel[i].level; tinfo.text = str; mLayersInfo.Add(tinfo); } this.comboBoxTopLayer.DataSource = mWellTopLayersInfo; this.comboBoxTopLayer.DisplayMember = "cw"; this.comboBoxBottomLayer.DataSource = mWellBottomLayersInfo; this.comboBoxBottomLayer.DisplayMember = "cw"; this.comboBoxLayers.DataSource = mLayersInfo; this.comboBoxLayers.DisplayMember = "text"; this.comboBoxLayers.ValueMember = "levelId"; } void setWellDepth(string wellName) { //string wellName = this.wellNameCbx.Text; if (wellName != "") { List wellSandSets = workAreaDb.Instance.workData.getWellSandSets(wellName); double top, bottom; top = 500; bottom = 1000; if (wellSandSets.Count > 0) { top = wellSandSets[0].top; bottom = wellSandSets[wellSandSets.Count - 1].bottom; } DataTable curvesTable = new DataTable(); workAreaDb.Instance.workData.getCurvesData(wellName, ref curvesTable); if (curvesTable.Columns.Count > 0 && curvesTable.Rows.Count > 0) { string topstr = curvesTable.Rows[0][0].ToString(); int rownum = curvesTable.Rows.Count - 1; string bottomstr = curvesTable.Rows[rownum][0].ToString(); if (double.TryParse(topstr, out double ttop)) { top = ttop; } if (double.TryParse(bottomstr, out double tbottom)) { bottom = tbottom; } } textBoxWellTop.Text = top.ToString(); textBoxWellBottom.Text = bottom.ToString(); } } private void wellNameCbx_SelectedIndexChanged(object sender, EventArgs e) { setWellDepth(this.wellNameCbx.Text); fileNameTextBox.Text = GetWellName(); // SelectWellLayersInfo(); } private void wellNameCbx_TextChanged(object sender, EventArgs e) { string template = comboxTemplate.Text; fileNameTextBox.Text = wellNameCbx.Text + "井" + template; } string GetWellName() { string wellName = this.wellNameCbx.Text; string template = comboxTemplate.Text; int dotPos = template.LastIndexOf('.'); if (dotPos > 0) { template = template.Substring(0, dotPos); } wellName = wellNameCbx.Text + "井" + template; return wellName; } private void comboxTemplate_SelectedIndexChanged(object sender, EventArgs e) { fileNameTextBox.Text = GetWellName(); } private void radioButtonDepth_CheckedChanged(object sender, EventArgs e) { if (radioButtonDepth.Checked) { textBoxWellTop.Enabled = true; textBoxWellBottom.Enabled = true; } else { textBoxWellTop.Enabled = false; textBoxWellBottom.Enabled = false; } } private void radioButtonLayers_CheckedChanged(object sender, EventArgs e) { if (radioButtonLayers.Checked) { comboBoxLayers.Enabled = true; comboBoxTopLayer.Enabled = true; comboBoxBottomLayer.Enabled = true; } else { comboBoxLayers.Enabled = false; comboBoxTopLayer.Enabled = false; comboBoxBottomLayer.Enabled = false; } } void SelectWellLayersInfo() { int levelId = -1; if (comboBoxLayers.SelectedItem is CLayersInfo layer) { levelId = layer.levelId; } if (levelId < 0) return; mWellTopLayersInfo.Clear(); mWellBottomLayersInfo.Clear(); List layersByLevel = mWellStrats.Where(item => item.level == levelId).ToList(); for (int i = 0; i < layersByLevel.Count; i++) { CWellLayerInfo twellLayer = new CWellLayerInfo(); twellLayer.cw = layersByLevel[i].code; twellLayer.order = layersByLevel[i].order; twellLayer.id = layersByLevel[i].id; mWellTopLayersInfo.Add(twellLayer); CWellLayerInfo twellLayer1 = new CWellLayerInfo(); twellLayer1.cw = layersByLevel[i].code; twellLayer1.order = layersByLevel[i].order; twellLayer1.id = layersByLevel[i].id; mWellBottomLayersInfo.Add(twellLayer1); } if (layersByLevel.Count > 0) { // this.comboBoxTopLayer.DataSource = mWellTopLayersInfo; // this.comboBoxTopLayer.DisplayMember = "cw"; comboBoxTopLayer.SelectedIndex = 0; // this.comboBoxBottomLayer.DataSource = mWellBottomLayersInfo; // this.comboBoxBottomLayer.DisplayMember = "cw"; comboBoxBottomLayer.SelectedIndex = mWellBottomLayersInfo.Count - 1; } //string wellName = this.wellNameCbx.Text; //List wellLayers = workAreaDb.Instance.workData.getWellSandSets(wellName); //mWellLayersInfo.Clear(); //for (int i = 0; i< wellLayers.Count;i++) //{ // CWellLayerInfo twellLayer = new CWellLayerInfo(); // twellLayer.cw = wellLayers[i].name; // twellLayer.top = wellLayers[i].top; // twellLayer.bottom = wellLayers[i].bottom; //} } private void comboBoxLayers_SelectedValueChanged(object sender, EventArgs e) { SelectWellLayersInfo(); } } }