RulesList.cs 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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.Text.RegularExpressions;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. using UAS_Tools_HY.PublicMethods;
  12. namespace UAS_Tools_HY
  13. {
  14. public partial class RulesList : Form
  15. {
  16. public RulesList(string type,string userName)
  17. {
  18. InitializeComponent();
  19. UserName = userName;
  20. TYPE = type;
  21. }
  22. public RulesList(string type, string ruleId, string userName)
  23. {
  24. InitializeComponent();
  25. UserName = userName;
  26. RULE_ID = ruleId;
  27. TYPE = type;
  28. }
  29. string TYPE,RULE_ID,UserName;
  30. DataTable dt;
  31. private void RulesList_Load(object sender, EventArgs e)
  32. {
  33. dt = ConnectDB.ExecuteSelect($"SELECT * FROM g_packing_rules WHERE rule_id = '{RULE_ID}'");
  34. if(dt.Rows.Count > 0)
  35. {
  36. textBox1.Text = dt.Rows[0]["RULE_NAME"].ToString();
  37. textBox2.Text = dt.Rows[0]["RULE_VALUE"].ToString();
  38. textBox3.Text = dt.Rows[0]["RELE_REMARK"].ToString();
  39. textBox1.Focus();
  40. textBox1.SelectAll();
  41. }
  42. }
  43. private void Submit_Click(object sender, EventArgs e)
  44. {
  45. if (string.IsNullOrEmpty(textBox1.Text))
  46. {
  47. MessageBox.Show("请输入规则名称", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  48. return;
  49. }
  50. if (string.IsNullOrEmpty(textBox2.Text))
  51. {
  52. MessageBox.Show("请输入规则内容", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  53. return;
  54. }
  55. string pattern = @"\{([^}]*)\}";
  56. var matches = Regex.Matches(textBox2.Text.Trim(), pattern);
  57. int totalLen = textBox2.Text.Trim().Length;
  58. int initLen = 0;
  59. int isContain = 0;
  60. foreach (Match match in matches)
  61. {
  62. initLen += match.Length;
  63. if (match.Value.Contains(",")){
  64. isContain += 1;
  65. }
  66. else
  67. {
  68. isContain += match.Groups[1].Value.Length;
  69. }
  70. }
  71. int otherLeng = totalLen - initLen + isContain;
  72. if(TYPE == "Add")
  73. {
  74. int insertCount = ConnectDB.ExecuteInsert($@"INSERT INTO g_packing_rules (rule_id, rule_name, rule_value, rule_length, rele_remark, update_time, update_user) VALUES
  75. (RULEID_SEQ.nextval, '{textBox1.Text.Trim()}', '{textBox2.Text.Trim()}', '{otherLeng}', '{textBox3.Text.Trim()}', sysdate, '{UserName}')");
  76. }
  77. else if(TYPE == "Modify")
  78. {
  79. int updateCount = ConnectDB.ExecuteUpdate($@"UPDATE g_packing_rules SET rule_name = '{textBox1.Text.Trim()}',rule_value = '{textBox2.Text.Trim()}',
  80. rule_length = '{otherLeng}',rele_remark = '{textBox3.Text.Trim()}',update_time = sysdate, update_user = '{UserName}' WHERE rule_id = '{RULE_ID}'");
  81. }
  82. this.DialogResult = DialogResult.OK;
  83. this.Close();
  84. }
  85. }
  86. }