| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace Core.LgMes.Client.LgIntegrationQuery
- {
- public partial class DialogFormula : Form
- {
- public DataSet _dsSet;//化学成分元素
- public string formula = "";
- private string ss = "+-*/()";
- private frmConfigElementsRow frmConfigEle = new frmConfigElementsRow();
- public DialogFormula(frmConfigElementsRow configele)
- {
- InitializeComponent();
- frmConfigEle = configele;
- }
- private void DialogFormula_Load(object sender, EventArgs e)
- {
- addContrl();
- }
- /// <summary>
- /// 动态添加控件
- /// </summary>
- private void addContrl()
- {
- int X = 12;
- int Y = 46;
- for (int i = 0; i < _dsSet.Tables[0].Rows.Count; i++)
- {
- if ((i + 1) % 10 == 0)
- {
- X = 12;
- Y += 29;
- }
- Button toAddButton = new Button();
- toAddButton.Name = "Button " + i;
- toAddButton.Text = _dsSet.Tables[0].Rows[i]["BASENAME"].ToString();
- toAddButton.Width = 46;
- toAddButton.Height = 23;
- toAddButton.Location = new Point(X, Y);
- X += 52;
- // 设置待添加按钮的事件
- toAddButton.Click += new System.EventHandler(this.Button_Click);
- // 把控件添加到窗口中
- this.Controls.Add(toAddButton);
- }
- }
- private void Button_Click(object sender, EventArgs e)
- {
- Button button = sender as Button;
- if (textBox1.Text.Length > 0 && ss.IndexOf(textBox1.Text.Substring(textBox1.Text.Length - 1)) < 0 && ss.IndexOf(button.Text) < 0)
- {
- MessageBox.Show("请注意,两个元素之间应该有运算符!", "错误");
- return;
- }
- textBox1.Text += button.Text;
- }
- private void button1_Click(object sender, EventArgs e)
- {
- if (textBox1.Text.Length > 0)
- textBox1.Text = textBox1.Text.Substring(0, textBox1.Text.Length - 1);
- }
- /// <summary>
- /// 添加公式到ListBox中
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button8_Click(object sender, EventArgs e)
- {
- frmConfigEle.textBox1.Text = textBox1.Text;
- frmConfigEle.checkedListBox1.Items.Add(textBox1.Text, true);
- }
- /// <summary>
- /// 检查公式是否合理
- /// </summary>
- /// <returns></returns>
- private int checkFormula()
- {
- return 0;
- }
- }
- }
|