using DevExpress.CodeParser; using GeoSigmaDrawLib; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Windows.Shapes; using System.Xml; //using System.Xml.Linq; namespace GeoSigma.UCDraw.WellAndSection { public partial class FrmInterpretResultSymbol : Form { XmlDocument m_xmlDoc; public DataTable m_Datas; public string m_filePath = ""; public FrmInterpretResultSymbol() { InitializeComponent(); m_Datas = new DataTable(); dataGridView1.EnableHeadersVisualStyles = false; dataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.AliceBlue; dataGridView1.RowHeadersDefaultCellStyle.BackColor = Color.Azure; } private void btnOk_Click(object sender, EventArgs e) { System.Xml.XmlNode resultsNode = m_xmlDoc.SelectSingleNode("/Root/InterpretResults"); resultsNode.RemoveAll(); for(int i = 0; i< m_Datas.Rows.Count; i++) { DataRow rw = m_Datas.Rows[i]; string name = rw[0].ToString(); string value = rw[1].ToString(); System.Xml.XmlElement te = m_xmlDoc.CreateElement("Sybmol"); resultsNode.AppendChild(te); te.SetAttribute("name", name); te.SetAttribute("otherValue", value); } m_xmlDoc.Save(m_filePath); } private void FrmInterpretResultSymbol_Shown(object sender, EventArgs e) { string appDir = AppDomain.CurrentDomain.BaseDirectory; m_filePath = appDir + "WellInterpretResult.xml"; m_xmlDoc = new XmlDocument(); bool bOpen = false; if(File.Exists(m_filePath)) { try { var reader = new StreamReader(m_filePath, Encoding.UTF8); // m_xmlDoc.LoadXml(m_filePath); m_xmlDoc.Load(reader); bOpen = true; } catch(Exception ex) { Console.WriteLine("文件错误。"); } } if(bOpen == false) { XmlDeclaration xmlDecl = m_xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null); m_xmlDoc.AppendChild(xmlDecl); System.Xml.XmlElement root = m_xmlDoc.CreateElement("Root"); m_xmlDoc.AppendChild(root); System.Xml.XmlElement xmlEresults = m_xmlDoc.CreateElement("InterpretResults"); root.AppendChild(xmlEresults); GeoSigmaWellPoleXY.GetSymbolNamesForResult(out string[] NamesArr); for(int i = 0; i < NamesArr.Length; i++) { System.Xml.XmlElement te = m_xmlDoc.CreateElement("Sybmol"); xmlEresults.AppendChild(te); te.SetAttribute("name", NamesArr[i]); te.SetAttribute("otherValue", ""); } } DataColumn col = new DataColumn("名称" , typeof(string)); m_Datas.Columns.Add(col); col = new DataColumn("映射值", typeof(string)); m_Datas.Columns.Add(col); try { System.Xml.XmlNode resultsNode = m_xmlDoc.SelectSingleNode("/Root/InterpretResults"); if (resultsNode != null) { foreach (System.Xml.XmlNode child in resultsNode.ChildNodes) { string name = child.Attributes["name"].Value; string value = child.Attributes["otherValue"].Value; DataRow dr = m_Datas.NewRow(); dr[0] = name; dr[1] = value; m_Datas.Rows.Add(dr); } } } catch (Exception ex) { } dataGridView1.DataSource = m_Datas.DefaultView; dataGridView1.Columns[0].ReadOnly = true; dataGridView1.Columns[0].DefaultCellStyle.BackColor = Color.LightGray; } } }