Loading.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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.Threading;
  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 Loading : Form
  15. {
  16. public Loading()
  17. {
  18. InitializeComponent();
  19. }
  20. public DataTable ResultData { get; private set; }
  21. string Filter;
  22. private CancellationTokenSource _cancellationTokenSource = new CancellationTokenSource();
  23. public Loading(string str)
  24. {
  25. InitializeComponent();
  26. Filter = str;
  27. }
  28. private async void Loading_Load(object sender, EventArgs e)
  29. {
  30. Msg.Visible = false;
  31. Confirm.Enabled = false;
  32. try
  33. {
  34. ResultData = ConnectDB.ExecuteSelect($@"SELECT count(*) num FROM g_packing_sncheck {Filter}");
  35. if(ResultData.Rows.Count > 0)
  36. {
  37. int allCount = Convert.ToInt32(ResultData.Rows[0]["num"].ToString());
  38. loadingBar.Visible = true;
  39. await Task.Run(() =>
  40. {
  41. /*ResultData = ConnectDB.ExecuteSelect($@"SELECT sn dqsn,outbox_no dqoutbox_no,count dqcount,
  42. update_time dqupdate_time,update_name dqname,rule_name dqrule_name,rule_value dqrule_value
  43. FROM g_packing_sncheck {Filter} ORDER BY sn,update_time desc");*/
  44. Task<DataTable> task = ConnectDB.ExecuteSelectCancellableSimpleAsync(
  45. sqlQuery: $@"SELECT sn dqsn,outbox_no dqoutbox_no,count dqcount,
  46. update_time dqupdate_time,update_name dqname,rule_name dqrule_name,rule_value dqrule_value
  47. FROM g_packing_sncheck {Filter} ORDER BY sn,update_time desc",
  48. cancellationToken: _cancellationTokenSource.Token);
  49. ResultData = task.Result;
  50. this.Invoke(new Action(() =>
  51. {
  52. loadingBar.Visible = false;
  53. Msg.Visible = true;
  54. Msg.Text = $"已查询到:{ResultData.Rows.Count}条数据";
  55. Confirm.Enabled = true;
  56. }));
  57. });
  58. }
  59. } catch(Exception ex) { }
  60. }
  61. private void Confirm_Click(object sender, EventArgs e)
  62. {
  63. _cancellationTokenSource?.Dispose();
  64. _cancellationTokenSource = null;
  65. this.DialogResult = DialogResult.OK;
  66. this.Dispose();
  67. this.Close();
  68. GC.Collect();
  69. }
  70. private void Loading_FormClosing(object sender, FormClosingEventArgs e)
  71. {
  72. _cancellationTokenSource?.Dispose();
  73. _cancellationTokenSource = null;
  74. }
  75. }
  76. }