yhluo 1 month ago
parent
commit
12a4b1ed0f

+ 93 - 0
UAS_Tools_HY/Loading.Designer.cs

@@ -0,0 +1,93 @@
+namespace UAS_Tools_HY
+{
+    partial class Loading
+    {
+        /// <summary>
+        /// Required designer variable.
+        /// </summary>
+        private System.ComponentModel.IContainer components = null;
+
+        /// <summary>
+        /// Clean up any resources being used.
+        /// </summary>
+        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
+        protected override void Dispose(bool disposing)
+        {
+            if (disposing && (components != null))
+            {
+                components.Dispose();
+            }
+            base.Dispose(disposing);
+        }
+
+        #region Windows Form Designer generated code
+
+        /// <summary>
+        /// Required method for Designer support - do not modify
+        /// the contents of this method with the code editor.
+        /// </summary>
+        private void InitializeComponent()
+        {
+            this.loadingBar = new System.Windows.Forms.ProgressBar();
+            this.Confirm = new System.Windows.Forms.Button();
+            this.Msg = new System.Windows.Forms.Label();
+            this.SuspendLayout();
+            // 
+            // loadingBar
+            // 
+            this.loadingBar.Location = new System.Drawing.Point(15, 42);
+            this.loadingBar.Margin = new System.Windows.Forms.Padding(4);
+            this.loadingBar.MarqueeAnimationSpeed = 30;
+            this.loadingBar.Name = "loadingBar";
+            this.loadingBar.Size = new System.Drawing.Size(350, 35);
+            this.loadingBar.Style = System.Windows.Forms.ProgressBarStyle.Marquee;
+            this.loadingBar.TabIndex = 0;
+            // 
+            // Confirm
+            // 
+            this.Confirm.Cursor = System.Windows.Forms.Cursors.Hand;
+            this.Confirm.Location = new System.Drawing.Point(132, 100);
+            this.Confirm.Margin = new System.Windows.Forms.Padding(4);
+            this.Confirm.Name = "Confirm";
+            this.Confirm.Size = new System.Drawing.Size(100, 35);
+            this.Confirm.TabIndex = 2;
+            this.Confirm.Text = "确定";
+            this.Confirm.UseVisualStyleBackColor = true;
+            this.Confirm.Click += new System.EventHandler(this.Confirm_Click);
+            // 
+            // Msg
+            // 
+            this.Msg.Location = new System.Drawing.Point(12, 42);
+            this.Msg.Name = "Msg";
+            this.Msg.Size = new System.Drawing.Size(353, 24);
+            this.Msg.TabIndex = 3;
+            this.Msg.Text = "已找到:0条数据";
+            this.Msg.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
+            // 
+            // Loading
+            // 
+            this.AutoScaleDimensions = new System.Drawing.SizeF(11F, 24F);
+            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+            this.ClientSize = new System.Drawing.Size(378, 148);
+            this.Controls.Add(this.Msg);
+            this.Controls.Add(this.Confirm);
+            this.Controls.Add(this.loadingBar);
+            this.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
+            this.Margin = new System.Windows.Forms.Padding(4);
+            this.Name = "Loading";
+            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
+            this.Text = "Loading";
+            this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Loading_FormClosing);
+            this.Load += new System.EventHandler(this.Loading_Load);
+            this.ResumeLayout(false);
+
+        }
+
+        #endregion
+
+        private System.Windows.Forms.ProgressBar loadingBar;
+        private System.Windows.Forms.Button Confirm;
+        private System.Windows.Forms.Label Msg;
+    }
+}

+ 88 - 0
UAS_Tools_HY/Loading.cs

@@ -0,0 +1,88 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+using UAS_Tools_HY.PublicMethods;
+
+namespace UAS_Tools_HY
+{
+    public partial class Loading : Form
+    {
+        public Loading()
+        {
+            InitializeComponent();
+        }
+
+        public DataTable ResultData { get; private set; }
+
+        string Filter;
+
+        private CancellationTokenSource _cancellationTokenSource = new CancellationTokenSource();
+
+        public Loading(string str)
+        {
+            InitializeComponent();
+            Filter = str;
+        }
+
+        private async void Loading_Load(object sender, EventArgs e)
+        {
+            Msg.Visible = false;
+            Confirm.Enabled = false;
+            try
+            {
+                ResultData = ConnectDB.ExecuteSelect($@"SELECT count(*) num FROM g_packing_sncheck {Filter}");
+                if(ResultData.Rows.Count > 0)
+                {
+                    int allCount = Convert.ToInt32(ResultData.Rows[0]["num"].ToString());
+                    loadingBar.Visible = true;
+                    await Task.Run(() =>
+                    {
+                        /*ResultData = ConnectDB.ExecuteSelect($@"SELECT sn dqsn,outbox_no dqoutbox_no,count dqcount,
+                            update_time dqupdate_time,update_name dqname,rule_name dqrule_name,rule_value dqrule_value
+                            FROM g_packing_sncheck {Filter} ORDER BY sn,update_time desc");*/
+
+                        Task<DataTable> task = ConnectDB.ExecuteSelectCancellableSimpleAsync(
+                            sqlQuery: $@"SELECT sn dqsn,outbox_no dqoutbox_no,count dqcount,
+                                update_time dqupdate_time,update_name dqname,rule_name dqrule_name,rule_value dqrule_value
+                                FROM g_packing_sncheck {Filter} ORDER BY sn,update_time desc",
+                            cancellationToken: _cancellationTokenSource.Token);
+
+                        ResultData = task.Result;
+
+                        this.Invoke(new Action(() =>
+                        {
+                            loadingBar.Visible = false;
+                            Msg.Visible = true;
+                            Msg.Text = $"已查询到:{ResultData.Rows.Count}条数据";
+                            Confirm.Enabled = true;
+                        }));
+                    });
+                }
+            } catch(Exception ex) { }
+        }
+
+        private void Confirm_Click(object sender, EventArgs e)
+        {
+            _cancellationTokenSource?.Dispose();
+            _cancellationTokenSource = null;
+
+            this.DialogResult = DialogResult.OK;
+            this.Dispose();
+            this.Close();
+            GC.Collect();
+        }
+
+        private void Loading_FormClosing(object sender, FormClosingEventArgs e)
+        {
+            _cancellationTokenSource?.Dispose();
+            _cancellationTokenSource = null;
+        }
+    }
+}

+ 120 - 0
UAS_Tools_HY/Loading.resx

@@ -0,0 +1,120 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+  <!-- 
+    Microsoft ResX Schema 
+    
+    Version 2.0
+    
+    The primary goals of this format is to allow a simple XML format 
+    that is mostly human readable. The generation and parsing of the 
+    various data types are done through the TypeConverter classes 
+    associated with the data types.
+    
+    Example:
+    
+    ... ado.net/XML headers & schema ...
+    <resheader name="resmimetype">text/microsoft-resx</resheader>
+    <resheader name="version">2.0</resheader>
+    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+        <value>[base64 mime encoded serialized .NET Framework object]</value>
+    </data>
+    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+        <comment>This is a comment</comment>
+    </data>
+                
+    There are any number of "resheader" rows that contain simple 
+    name/value pairs.
+    
+    Each data row contains a name, and value. The row also contains a 
+    type or mimetype. Type corresponds to a .NET class that support 
+    text/value conversion through the TypeConverter architecture. 
+    Classes that don't support this are serialized and stored with the 
+    mimetype set.
+    
+    The mimetype is used for serialized objects, and tells the 
+    ResXResourceReader how to depersist the object. This is currently not 
+    extensible. For a given mimetype the value must be set accordingly:
+    
+    Note - application/x-microsoft.net.object.binary.base64 is the format 
+    that the ResXResourceWriter will generate, however the reader can 
+    read any of the formats listed below.
+    
+    mimetype: application/x-microsoft.net.object.binary.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+            : and then encoded with base64 encoding.
+    
+    mimetype: application/x-microsoft.net.object.soap.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+            : and then encoded with base64 encoding.
+
+    mimetype: application/x-microsoft.net.object.bytearray.base64
+    value   : The object must be serialized into a byte array 
+            : using a System.ComponentModel.TypeConverter
+            : and then encoded with base64 encoding.
+    -->
+  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+    <xsd:element name="root" msdata:IsDataSet="true">
+      <xsd:complexType>
+        <xsd:choice maxOccurs="unbounded">
+          <xsd:element name="metadata">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" />
+              </xsd:sequence>
+              <xsd:attribute name="name" use="required" type="xsd:string" />
+              <xsd:attribute name="type" type="xsd:string" />
+              <xsd:attribute name="mimetype" type="xsd:string" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="assembly">
+            <xsd:complexType>
+              <xsd:attribute name="alias" type="xsd:string" />
+              <xsd:attribute name="name" type="xsd:string" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="data">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="resheader">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" />
+            </xsd:complexType>
+          </xsd:element>
+        </xsd:choice>
+      </xsd:complexType>
+    </xsd:element>
+  </xsd:schema>
+  <resheader name="resmimetype">
+    <value>text/microsoft-resx</value>
+  </resheader>
+  <resheader name="version">
+    <value>2.0</value>
+  </resheader>
+  <resheader name="reader">
+    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <resheader name="writer">
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+</root>

+ 33 - 6
UAS_Tools_HY/Main.cs

@@ -143,6 +143,15 @@ namespace UAS_MES_Tools
                 return;
             }
 
+            dt = ConnectDB.ExecuteSelect($@"select * from g_packing_sncheck where sn = '{SN.Text.Trim()}'");
+            if (dt.Rows.Count > 0)
+            {
+                PlaySound("NG");
+                MessageBox.Show($"{SN.Text.Trim()},历史记录中已核对", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
+                checkRes = false;
+                return;
+            }
+
             ishaveInd = -1;
             if (Datas.Rows.Count > 0)
             {
@@ -157,11 +166,16 @@ namespace UAS_MES_Tools
 
             if (ishaveInd >= 0)
             {
-                int iCou = Convert.ToInt32(Datas.Rows[ishaveInd].Cells[2].Value);
+                PlaySound("NG");
+                MessageBox.Show($"{SN.Text.Trim()},已核对装箱", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
+                checkRes = false;
+                return;
+
+                /*int iCou = Convert.ToInt32(Datas.Rows[ishaveInd].Cells[2].Value);
                 iCou += 1;
                 Datas.Rows[ishaveInd].Cells[3].Value = currTime.Text;
                 Datas.Rows[ishaveInd].Cells[6].Value = checkRes ? "OK" : "NG";
-                PlaySound("OK");
+                PlaySound("OK");*/
             }
             else
             {
@@ -326,10 +340,23 @@ namespace UAS_MES_Tools
                     filterStr.Append($" AND update_time > TO_DATE('{dtp1}','YYYY-MM-DD HH24:MI:SS') AND update_time <= TO_DATE('{dtp2}','YYYY-MM-DD HH24:MI:SS')");
                 }
             }
-            dt = ConnectDB.ExecuteSelect($@"SELECT sn dqsn,outbox_no dqoutbox_no,count dqcount,
-                update_time dqupdate_time,update_name dqname,rule_name dqrule_name,rule_value dqrule_value
-                FROM g_packing_sncheck {filterStr.ToString()} ORDER BY sn,update_time desc");
-            QDDatas.DataSource = dt;
+
+            if(sender == null)
+            {
+                dt = ConnectDB.ExecuteSelect($@"SELECT sn dqsn,outbox_no dqoutbox_no,count dqcount,
+                    update_time dqupdate_time,update_name dqname,rule_name dqrule_name,rule_value dqrule_value
+                    FROM g_packing_sncheck {filterStr.ToString()} ORDER BY sn,update_time desc");
+                QDDatas.DataSource = dt;
+            }
+            else
+            {
+                Loading LoadingForm = new Loading(filterStr.ToString());
+                if (LoadingForm.ShowDialog() == DialogResult.OK)
+                {
+                    DataTable dt = LoadingForm.ResultData;
+                    QDDatas.DataSource = dt;
+                }
+            }
         }
 
         private void QDexport_Click(object sender, EventArgs e)

+ 47 - 0
UAS_Tools_HY/PublicMethods/ConnectDB.cs

@@ -3,6 +3,8 @@ using System;
 using System.Collections.Generic;
 using System.Data;
 using System.Security.Cryptography;
+using System.Threading;
+using System.Threading.Tasks;
 
 namespace UAS_Tools_HY.PublicMethods
 {
@@ -136,6 +138,51 @@ namespace UAS_Tools_HY.PublicMethods
                 throw new Exception(ex.Message);
             }
         }
+
+        public static async Task<DataTable> ExecuteSelectCancellableSimpleAsync(string sqlQuery,Dictionary<string, object> parameters = null,CancellationToken cancellationToken = default)
+        {
+            DataTable dataTable = new DataTable();
+            try
+            {
+                using (OracleConnection connection = new OracleConnection(ConnectionString))
+                {
+                    await connection.OpenAsync(cancellationToken);
+
+                    using (OracleCommand command = new OracleCommand(sqlQuery, connection))
+                    {
+                        if (parameters != null && parameters.Count > 0)
+                        {
+                            foreach (var param in parameters)
+                            {
+                                command.Parameters.Add(new OracleParameter(param.Key, param.Value ?? DBNull.Value));
+                            }
+                        }
+
+                        command.CommandTimeout = 0;
+
+                        using (OracleDataAdapter adapter = new OracleDataAdapter(command))
+                        {
+                            await Task.Run(() =>
+                            {
+                                adapter.Fill(dataTable);
+
+                                cancellationToken.ThrowIfCancellationRequested();
+                            }, cancellationToken);
+                        }
+                    }
+                }
+            }
+            catch (OperationCanceledException)
+            {
+                throw new OperationCanceledException("数据库查询已取消");
+            }
+            catch (Exception ex)
+            {
+                throw new Exception($"数据库查询失败: {ex.Message}");
+            }
+
+            return dataTable;
+        }
     }
 }
 

+ 9 - 0
UAS_Tools_HY/UAS_Tools_HY.csproj

@@ -82,6 +82,12 @@
     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="Loading.cs">
+      <SubType>Form</SubType>
+    </Compile>
+    <Compile Include="Loading.Designer.cs">
+      <DependentUpon>Loading.cs</DependentUpon>
+    </Compile>
     <Compile Include="Login.cs">
       <SubType>Form</SubType>
     </Compile>
@@ -107,6 +113,9 @@
     <Compile Include="RulesList.Designer.cs">
       <DependentUpon>RulesList.cs</DependentUpon>
     </Compile>
+    <EmbeddedResource Include="Loading.resx">
+      <DependentUpon>Loading.cs</DependentUpon>
+    </EmbeddedResource>
     <EmbeddedResource Include="Login.resx">
       <DependentUpon>Login.cs</DependentUpon>
     </EmbeddedResource>