RulesList.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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, string account)
  17. {
  18. InitializeComponent();
  19. UserName = userName;
  20. TYPE = type;
  21. Account = account;
  22. }
  23. public RulesList(string type, string ruleId, string userName, string account)
  24. {
  25. InitializeComponent();
  26. UserName = userName;
  27. RULE_ID = ruleId;
  28. TYPE = type;
  29. Account = account;
  30. }
  31. string TYPE,RULE_ID,UserName,Account;
  32. DataTable dt;
  33. private void RulesList_Load(object sender, EventArgs e)
  34. {
  35. dt = ConnectDB.ExecuteSelect($"SELECT * FROM employee WHERE em_code = '{Account}' AND em_checkrule = 1");
  36. if (dt.Rows.Count == 0)
  37. {
  38. MessageBox.Show("该账户没有操作核对规则权限", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  39. this.DialogResult = DialogResult.No;
  40. this.Close();
  41. return;
  42. }
  43. dt = ConnectDB.ExecuteSelect($"SELECT * FROM g_packing_rules WHERE rule_id = '{RULE_ID}'");
  44. if(dt.Rows.Count > 0)
  45. {
  46. textBox1.Text = dt.Rows[0]["RULE_NAME"].ToString();
  47. textBox2.Text = dt.Rows[0]["RULE_VALUE"].ToString();
  48. textBox3.Text = dt.Rows[0]["RELE_REMARK"].ToString();
  49. textBox1.Focus();
  50. textBox1.SelectAll();
  51. }
  52. }
  53. private void Submit_Click(object sender, EventArgs e)
  54. {
  55. if (string.IsNullOrEmpty(textBox1.Text))
  56. {
  57. MessageBox.Show("请输入规则名称", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  58. return;
  59. }
  60. if (string.IsNullOrEmpty(textBox2.Text))
  61. {
  62. MessageBox.Show("请输入规则内容", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  63. return;
  64. }
  65. string pattern = @"\{([^}]*)\}";
  66. var matches = Regex.Matches(textBox2.Text.Trim(), pattern);
  67. int totalLen = textBox2.Text.Trim().Length;
  68. int initLen = 0;
  69. int isContain = 0;
  70. foreach (Match match in matches)
  71. {
  72. initLen += match.Length;
  73. if (match.Value.Contains(",")){
  74. isContain += 1;
  75. }
  76. else
  77. {
  78. isContain += match.Groups[1].Value.Length;
  79. }
  80. }
  81. int otherLeng = totalLen - initLen + isContain;
  82. if(TYPE == "Add")
  83. {
  84. int insertCount = ConnectDB.ExecuteInsert($@"INSERT INTO g_packing_rules (rule_id, rule_name, rule_value, rule_length, rele_remark, update_time, update_user) VALUES
  85. (RULEID_SEQ.nextval, '{textBox1.Text.Trim()}', '{textBox2.Text.Trim()}', '{otherLeng}', '{textBox3.Text.Trim()}', sysdate, '{UserName}')");
  86. }
  87. else if(TYPE == "Modify")
  88. {
  89. int updateCount = ConnectDB.ExecuteUpdate($@"UPDATE g_packing_rules SET rule_name = '{textBox1.Text.Trim()}',rule_value = '{textBox2.Text.Trim()}',
  90. rule_length = '{otherLeng}',rele_remark = '{textBox3.Text.Trim()}',update_time = sysdate, update_user = '{UserName}' WHERE rule_id = '{RULE_ID}'");
  91. }
  92. this.DialogResult = DialogResult.OK;
  93. this.Close();
  94. }
  95. }
  96. }