FormNewCommand.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using DevExpress.XtraEditors;
  3. using UAS_PLCDataReader.Entity;
  4. using System.Data;
  5. using UAS_PLCDataReader.DataOperate;
  6. using UAS_PLCDataReader.PublicMethod;
  7. namespace UAS_PLCDataReader.Device.Command
  8. {
  9. public partial class FormNewCommand : XtraForm
  10. {
  11. string brand = "";
  12. public FormNewCommand()
  13. {
  14. InitializeComponent();
  15. }
  16. public FormNewCommand(string BrandCode, string BrandName)
  17. {
  18. InitializeComponent();
  19. brand = BrandCode;
  20. Text = "新增指令(" + BrandName + ")";
  21. }
  22. /// <summary>
  23. /// 设置下拉框的值
  24. /// </summary>
  25. /// <param name="sender"></param>
  26. /// <param name="e"></param>
  27. private void FormNewCommand_Load(object sender, EventArgs e)
  28. {
  29. DataTable dt = (DataTable)SystemInf.dh.ExecuteSql("select * from CommandFunctionSetting where cfs_debrand='" + brand + "' order by cfs_id ", "select");
  30. BaseUtil.FillComBoxEditWidthDataTable(CodeClientAddress, "cfs_name", "cfs_value", BaseUtil.ToDataTable(dt.Select("cfs_type='CA'")));
  31. BaseUtil.FillComBoxEditWidthDataTable(CodeFunction, "cfs_name", "cfs_value", BaseUtil.ToDataTable(dt.Select("cfs_type='CF'")));
  32. BaseUtil.FillComBoxEditWidthDataTable(CodeComplement, "cfs_name", "cfs_value", BaseUtil.ToDataTable(dt.Select("cfs_type='CC'")));
  33. BaseUtil.FillComBoxEditWidthDataTable(CodeEnd, "cfs_name", "cfs_value", BaseUtil.ToDataTable(dt.Select("cfs_type='CE'")));
  34. }
  35. /// <summary>
  36. /// 插入生成的指令,根据选择的功能码+地址位+长度+补码+结束码
  37. /// </summary>
  38. /// <param name="sender"></param>
  39. /// <param name="e"></param>
  40. private void AddCommand_Click(object sender, EventArgs e)
  41. {
  42. string code = BaseUtil.GetComboxEditValue(CodeClientAddress) + BaseUtil.GetComboxEditValue(CodeFunction) + CodeAddress.Text + CodeLength.Text;
  43. //添加指令的补码
  44. code = code + BaseUtil.getLRC(code);
  45. code = code + BaseUtil.GetComboxEditValue(CodeEnd);
  46. SystemInf.dh.ExecuteSql("insert into devicecommand(dc_id,dc_name,dc_code,dc_command,dc_brand) values (devicecommand_seq.nextval,'" + dc_name.Text + "','" + dc_code.Text + "','" + code + "','" + brand + "')", "insert");
  47. XtraMessageBox.Show("指令保存成功");
  48. Close();
  49. }
  50. }
  51. }