DialogFormula.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. namespace Core.LgMes.Client.LgIntegrationQuery
  10. {
  11. public partial class DialogFormula : Form
  12. {
  13. public DataSet _dsSet;//化学成分元素
  14. public string formula = "";
  15. private string ss = "+-*/()";
  16. private frmConfigElementsRow frmConfigEle = new frmConfigElementsRow();
  17. public DialogFormula(frmConfigElementsRow configele)
  18. {
  19. InitializeComponent();
  20. frmConfigEle = configele;
  21. }
  22. private void DialogFormula_Load(object sender, EventArgs e)
  23. {
  24. addContrl();
  25. }
  26. /// <summary>
  27. /// 动态添加控件
  28. /// </summary>
  29. private void addContrl()
  30. {
  31. int X = 12;
  32. int Y = 46;
  33. for (int i = 0; i < _dsSet.Tables[0].Rows.Count; i++)
  34. {
  35. if ((i + 1) % 10 == 0)
  36. {
  37. X = 12;
  38. Y += 29;
  39. }
  40. Button toAddButton = new Button();
  41. toAddButton.Name = "Button " + i;
  42. toAddButton.Text = _dsSet.Tables[0].Rows[i]["BASENAME"].ToString();
  43. toAddButton.Width = 46;
  44. toAddButton.Height = 23;
  45. toAddButton.Location = new Point(X, Y);
  46. X += 52;
  47. // 设置待添加按钮的事件
  48. toAddButton.Click += new System.EventHandler(this.Button_Click);
  49. // 把控件添加到窗口中
  50. this.Controls.Add(toAddButton);
  51. }
  52. }
  53. private void Button_Click(object sender, EventArgs e)
  54. {
  55. Button button = sender as Button;
  56. if (textBox1.Text.Length > 0 && ss.IndexOf(textBox1.Text.Substring(textBox1.Text.Length - 1)) < 0 && ss.IndexOf(button.Text) < 0)
  57. {
  58. MessageBox.Show("请注意,两个元素之间应该有运算符!", "错误");
  59. return;
  60. }
  61. textBox1.Text += button.Text;
  62. }
  63. private void button1_Click(object sender, EventArgs e)
  64. {
  65. if (textBox1.Text.Length > 0)
  66. textBox1.Text = textBox1.Text.Substring(0, textBox1.Text.Length - 1);
  67. }
  68. /// <summary>
  69. /// 添加公式到ListBox中
  70. /// </summary>
  71. /// <param name="sender"></param>
  72. /// <param name="e"></param>
  73. private void button8_Click(object sender, EventArgs e)
  74. {
  75. frmConfigEle.textBox1.Text = textBox1.Text;
  76. frmConfigEle.checkedListBox1.Items.Add(textBox1.Text, true);
  77. }
  78. /// <summary>
  79. /// 检查公式是否合理
  80. /// </summary>
  81. /// <returns></returns>
  82. private int checkFormula()
  83. {
  84. return 0;
  85. }
  86. }
  87. }