using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Collections;
using System.Text.RegularExpressions;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string path;
string id;
string yt;
string c;
Hashtable ht = new Hashtable();
Hashtable ht1 = new Hashtable();
XmlDocument doc = new XmlDocument();
string txtFormula;
private void Form1_Load(object sender, EventArgs e)
{
path = "e://config.xml";
doc.Load(path);
attributesOpertion oper = new attributesOpertion();
oper.Doc = doc;
id = "ST3";
ht = oper.GetSummary(id);
foreach (string st in ht.Values)
{
listBox1.Items.Add(st);
}
ht1 = oper.GetDetail(id);
foreach (string st in ht1.Values)
{
listBox1.Items.Add(st);
}
this.richTextBox1.DragEnter +=new DragEventHandler(richTextBox1_DragEnter);
this.richTextBox1.DragDrop +=new DragEventHandler(richTextBox1_DragDrop);
richTextBox1.AllowDrop = true;
}
private void listBox1_MouseDown(object sender, MouseEventArgs e)
{
ListBox lb = ((ListBox)sender);
Point pt = new Point(e.X, e.Y);
int index = lb.IndexFromPoint(pt);
if (index >= 0)
{
lb.DoDragDrop(lb.Items[index].ToString(), DragDropEffects.All);
}
}
private void richTextBox1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.Text))
e.Effect = DragDropEffects.All;
c = this.richTextBox1.Text;
}
private void richTextBox1_DragDrop(object sender, DragEventArgs e)
{
yt = (String)e.Data.GetData(DataFormats.Text).ToString();
foreach (DictionaryEntry de in ht)
{
if (de.Value.ToString() == yt)
{
yt = de.Key.ToString();
break;
}
}
foreach (DictionaryEntry de in ht1)
{
if (de.Value.ToString() == yt)
{
yt = de.Key.ToString();
break;
}
}
string strInsertText = "@" + yt;
int start = this.richTextBox1.SelectionStart;
this.richTextBox1.Text = this.richTextBox1.Text.Insert(start, strInsertText);
this.richTextBox1.Focus();
this.richTextBox1.SelectionStart = start;
this.richTextBox1.SelectionLength = strInsertText.Length;
}
private void button1_Click(object sender, EventArgs e)
{
addOneNode(path);
MathParser.MathParser Fun = new MathParser.MathParser();
bool OK;
double y;
txtFormula = richTextBox1.Text;
Hashtable ft = new Hashtable();
ft.Add("@STM1", 1);
ft.Add("@SVAL1", 2);
ft.Add("@STM2", 3);
ft.Add("@SVAL2", 4);
ft.Add("@DVAL2", 5);
ft.Add("@DVAL1", 6);
ft.Add("@DTM1", 7);
TxtValue(ft);
OK = Fun.StoreExpression(txtFormula);
if (OK == false)
{
MessageBox.Show("表?式不正?");
}
y = Fun.Eval1(0);
textBox1.Text = Convert.ToString(y);
//if (textBox1.Text=="1")
//{
// textBox1.Text = Convert.ToString(true);
//}
}
private void addOneNode(string filePath)
{
doc.Load(filePath);
string xPath = "//HILS/zzz";
if (exits(xPath) == true)
{
XmlElement xel = (XmlElement)doc.SelectSingleNode(xPath);
xel.RemoveAll();
xel.SetAttribute("str", richTextBox1.Text);
doc.Save(path);
}
else
{
XmlNode root = doc.SelectSingleNode("//HILS");
XmlElement xel = doc.CreateElement("zzz");
root.AppendChild(xel);
xel.SetAttribute("str", richTextBox1.Text);
doc.Save(path);
}
}
private bool exits(string xPath)
{
XmlNodeList nodeList;
nodeList = doc.SelectNodes(xPath);
if (nodeList.Count == 1)
{
return true;
}
else
{
return false;
}
}
public string TxtValue(Hashtable tt)
{
foreach (DictionaryEntry de in tt)
{
txtFormula = txtFormula.Replace(de.Key.ToString(),de.Value.ToString() );
}
return txtFormula;
}
private void ?制ToolStripMenuItem_Click(object sender, EventArgs e)
{
richTextBox1.Copy();??
}
private void 撤?ToolStripMenuItem_Click(object sender, EventArgs e)
{
//richTextBox1.Undo();??
richTextBox1.Text = c;
}
private void 剪?ToolStripMenuItem_Click(object sender, EventArgs e)
{
richTextBox1.Cut();??
}
private void 粘?ToolStripMenuItem_Click(object sender, EventArgs e)
{
richTextBox1.Paste();?
}
private void 全?ToolStripMenuItem_Click(object sender, EventArgs e)
{
richTextBox1.SelectAll();??
}
}
}