diff --git a/FATrace.App/App.config b/FATrace.App/App.config index 3f0878c..4681fcc 100644 --- a/FATrace.App/App.config +++ b/FATrace.App/App.config @@ -2,8 +2,8 @@ - - + + diff --git a/FATrace.App/FATrace.App.csproj b/FATrace.App/FATrace.App.csproj index 217fcb0..371b656 100644 --- a/FATrace.App/FATrace.App.csproj +++ b/FATrace.App/FATrace.App.csproj @@ -11,6 +11,405 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + @@ -52,286 +451,4 @@ - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - \ No newline at end of file diff --git a/FATrace.App/Images/ele_icon_w_depository.png b/FATrace.App/Images/ele_icon_w_depository.png new file mode 100644 index 0000000..a1ffd11 Binary files /dev/null and b/FATrace.App/Images/ele_icon_w_depository.png differ diff --git a/FATrace.App/Images/信息.png b/FATrace.App/Images/信息.png new file mode 100644 index 0000000..80096af Binary files /dev/null and b/FATrace.App/Images/信息.png differ diff --git a/FATrace.App/Images/信息输入输出.png b/FATrace.App/Images/信息输入输出.png new file mode 100644 index 0000000..03282a9 Binary files /dev/null and b/FATrace.App/Images/信息输入输出.png differ diff --git a/FATrace.App/Images/原料需求.png b/FATrace.App/Images/原料需求.png new file mode 100644 index 0000000..3f4218a Binary files /dev/null and b/FATrace.App/Images/原料需求.png differ diff --git a/FATrace.App/Images/选择.png b/FATrace.App/Images/选择.png index 016fff5..39e74c6 100644 Binary files a/FATrace.App/Images/选择.png and b/FATrace.App/Images/选择.png differ diff --git a/FATrace.App/Properties/Resources.Designer.cs b/FATrace.App/Properties/Resources.Designer.cs index c377ea7..e0e8b29 100644 --- a/FATrace.App/Properties/Resources.Designer.cs +++ b/FATrace.App/Properties/Resources.Designer.cs @@ -60,6 +60,16 @@ namespace FATrace.App.Properties { } } + /// + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// + internal static System.Drawing.Bitmap ele_icon_w_depository { + get { + object obj = ResourceManager.GetObject("ele_icon_w_depository", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// 查找 System.Drawing.Bitmap 类型的本地化资源。 /// @@ -70,6 +80,26 @@ namespace FATrace.App.Properties { } } + /// + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// + internal static System.Drawing.Bitmap 信息 { + get { + object obj = ResourceManager.GetObject("信息", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// + internal static System.Drawing.Bitmap 信息输入输出 { + get { + object obj = ResourceManager.GetObject("信息输入输出", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// 查找 System.Drawing.Bitmap 类型的本地化资源。 /// @@ -100,6 +130,16 @@ namespace FATrace.App.Properties { } } + /// + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// + internal static System.Drawing.Bitmap 原料需求 { + get { + object obj = ResourceManager.GetObject("原料需求", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// 查找 System.Drawing.Bitmap 类型的本地化资源。 /// @@ -119,5 +159,25 @@ namespace FATrace.App.Properties { return ((System.Drawing.Bitmap)(obj)); } } + + /// + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// + internal static System.Drawing.Bitmap 称重 { + get { + object obj = ResourceManager.GetObject("称重", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// + internal static System.Drawing.Bitmap 选择 { + get { + object obj = ResourceManager.GetObject("选择", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } } } diff --git a/FATrace.App/Properties/Resources.resx b/FATrace.App/Properties/Resources.resx index 21990a1..68163cc 100644 --- a/FATrace.App/Properties/Resources.resx +++ b/FATrace.App/Properties/Resources.resx @@ -118,22 +118,40 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - ..\Resources\GilicoLogo.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\关闭.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a ..\Resources\分类.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\Resources\登录 (2).png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\原料需求.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\选择.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a ..\Resources\工单信息.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\Resources\关闭.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\信息.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a ..\Resources\分类1.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\信息输入输出.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\ele_icon_w_depository.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\GilicoLogo.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\登录 (2).png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\称重.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + \ No newline at end of file diff --git a/FATrace.App/Resources/ele_icon_w_depository.png b/FATrace.App/Resources/ele_icon_w_depository.png new file mode 100644 index 0000000..a1ffd11 Binary files /dev/null and b/FATrace.App/Resources/ele_icon_w_depository.png differ diff --git a/FATrace.App/Resources/信息.png b/FATrace.App/Resources/信息.png new file mode 100644 index 0000000..80096af Binary files /dev/null and b/FATrace.App/Resources/信息.png differ diff --git a/FATrace.App/Resources/信息输入输出.png b/FATrace.App/Resources/信息输入输出.png new file mode 100644 index 0000000..03282a9 Binary files /dev/null and b/FATrace.App/Resources/信息输入输出.png differ diff --git a/FATrace.App/Resources/原料需求.png b/FATrace.App/Resources/原料需求.png new file mode 100644 index 0000000..3f4218a Binary files /dev/null and b/FATrace.App/Resources/原料需求.png differ diff --git a/FATrace.App/Resources/称重.png b/FATrace.App/Resources/称重.png new file mode 100644 index 0000000..a8a9bdf Binary files /dev/null and b/FATrace.App/Resources/称重.png differ diff --git a/FATrace.App/Resources/选择.png b/FATrace.App/Resources/选择.png new file mode 100644 index 0000000..39e74c6 Binary files /dev/null and b/FATrace.App/Resources/选择.png differ diff --git a/FATrace.App/frmMain.Designer.cs b/FATrace.App/frmMain.Designer.cs index 52bf7a0..777ad06 100644 --- a/FATrace.App/frmMain.Designer.cs +++ b/FATrace.App/frmMain.Designer.cs @@ -49,6 +49,7 @@ namespace FATrace.App TabControlMain = new TabControl(); tabPage2 = new TabPage(); panel3 = new Panel(); + pictureBox4 = new PictureBox(); btnWeightPrint = new Button(); txtCode = new TextBox(); label13 = new Label(); @@ -57,6 +58,7 @@ namespace FATrace.App label8 = new Label(); label10 = new Label(); panel2 = new Panel(); + pictureBox3 = new PictureBox(); lblRawUseStateTip = new Label(); btnClearRaw = new Button(); lblRawUseState = new Label(); @@ -73,6 +75,7 @@ namespace FATrace.App label4 = new Label(); label3 = new Label(); panel1 = new Panel(); + pictureBox2 = new PictureBox(); lblRawBeforeInfo = new Label(); btnRawName3 = new Button(); btnRawName2 = new Button(); @@ -109,8 +112,11 @@ namespace FATrace.App TabControlMain.SuspendLayout(); tabPage2.SuspendLayout(); panel3.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox4).BeginInit(); panel2.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox3).BeginInit(); panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox2).BeginInit(); tabPage3.SuspendLayout(); tabPage1.SuspendLayout(); groupBox1.SuspendLayout(); @@ -336,6 +342,7 @@ namespace FATrace.App // panel3 // panel3.BorderStyle = BorderStyle.FixedSingle; + panel3.Controls.Add(pictureBox4); panel3.Controls.Add(btnWeightPrint); panel3.Controls.Add(txtCode); panel3.Controls.Add(label13); @@ -349,6 +356,17 @@ namespace FATrace.App panel3.Size = new Size(878, 176); panel3.TabIndex = 3; // + // pictureBox4 + // + pictureBox4.BackgroundImageLayout = ImageLayout.None; + pictureBox4.Image = Properties.Resources.称重; + pictureBox4.Location = new Point(7, 3); + pictureBox4.Name = "pictureBox4"; + pictureBox4.Size = new Size(35, 35); + pictureBox4.SizeMode = PictureBoxSizeMode.StretchImage; + pictureBox4.TabIndex = 15; + pictureBox4.TabStop = false; + // // btnWeightPrint // btnWeightPrint.Font = new Font("Microsoft YaHei UI", 15.75F, FontStyle.Bold, GraphicsUnit.Point, 134); @@ -367,6 +385,7 @@ namespace FATrace.App txtCode.ForeColor = Color.Blue; txtCode.Location = new Point(129, 127); txtCode.Name = "txtCode"; + txtCode.ReadOnly = true; txtCode.Size = new Size(410, 33); txtCode.TabIndex = 16; txtCode.Text = "YG05030013,20250923,1802,3,01,0001"; @@ -387,7 +406,7 @@ namespace FATrace.App label9.AutoSize = true; label9.Font = new Font("Microsoft YaHei UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point, 134); label9.ForeColor = SystemColors.WindowFrame; - label9.Location = new Point(235, 56); + label9.Location = new Point(235, 63); label9.Name = "label9"; label9.Size = new Size(24, 25); label9.TabIndex = 11; @@ -396,7 +415,7 @@ namespace FATrace.App // txtRtWeight // txtRtWeight.Font = new Font("Microsoft YaHei UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point, 134); - txtRtWeight.Location = new Point(129, 50); + txtRtWeight.Location = new Point(129, 57); txtRtWeight.Name = "txtRtWeight"; txtRtWeight.Size = new Size(100, 32); txtRtWeight.TabIndex = 10; @@ -404,11 +423,11 @@ namespace FATrace.App // label8 // label8.AutoSize = true; - label8.Font = new Font("Microsoft YaHei UI", 15.75F, FontStyle.Bold, GraphicsUnit.Point, 134); + label8.Font = new Font("Microsoft YaHei UI", 18F, FontStyle.Bold); label8.ForeColor = SystemColors.ControlDarkDark; - label8.Location = new Point(14, 4); + label8.Location = new Point(44, 5); label8.Name = "label8"; - label8.Size = new Size(96, 28); + label8.Size = new Size(110, 31); label8.TabIndex = 9; label8.Text = "称重信息"; // @@ -417,7 +436,7 @@ namespace FATrace.App label10.AutoSize = true; label10.Font = new Font("Microsoft YaHei UI", 14.25F, FontStyle.Bold, GraphicsUnit.Point, 134); label10.ForeColor = SystemColors.WindowFrame; - label10.Location = new Point(30, 53); + label10.Location = new Point(30, 60); label10.Name = "label10"; label10.Size = new Size(107, 26); label10.TabIndex = 9; @@ -426,6 +445,7 @@ namespace FATrace.App // panel2 // panel2.BorderStyle = BorderStyle.FixedSingle; + panel2.Controls.Add(pictureBox3); panel2.Controls.Add(lblRawUseStateTip); panel2.Controls.Add(btnClearRaw); panel2.Controls.Add(lblRawUseState); @@ -447,12 +467,23 @@ namespace FATrace.App panel2.Size = new Size(878, 156); panel2.TabIndex = 2; // + // pictureBox3 + // + pictureBox3.BackgroundImageLayout = ImageLayout.None; + pictureBox3.Image = Properties.Resources.信息输入输出; + pictureBox3.Location = new Point(7, 5); + pictureBox3.Name = "pictureBox3"; + pictureBox3.Size = new Size(35, 35); + pictureBox3.SizeMode = PictureBoxSizeMode.StretchImage; + pictureBox3.TabIndex = 13; + pictureBox3.TabStop = false; + // // lblRawUseStateTip // lblRawUseStateTip.BackColor = Color.LightSalmon; lblRawUseStateTip.Font = new Font("Microsoft YaHei UI", 14.25F, FontStyle.Bold, GraphicsUnit.Point, 134); lblRawUseStateTip.ForeColor = SystemColors.ButtonHighlight; - lblRawUseStateTip.Location = new Point(159, 106); + lblRawUseStateTip.Location = new Point(159, 102); lblRawUseStateTip.Name = "lblRawUseStateTip"; lblRawUseStateTip.Size = new Size(247, 34); lblRawUseStateTip.TabIndex = 11; @@ -470,6 +501,7 @@ namespace FATrace.App btnClearRaw.TabIndex = 10; btnClearRaw.Text = "清零当前原料"; btnClearRaw.UseVisualStyleBackColor = true; + btnClearRaw.Click += btnClearRaw_Click; // // lblRawUseState // @@ -489,7 +521,7 @@ namespace FATrace.App label11.AutoSize = true; label11.Font = new Font("Microsoft YaHei UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point, 134); label11.ForeColor = SystemColors.WindowFrame; - label11.Location = new Point(819, 51); + label11.Location = new Point(819, 54); label11.Name = "label11"; label11.Size = new Size(36, 25); label11.TabIndex = 14; @@ -510,7 +542,7 @@ namespace FATrace.App // txtRemainWeight // txtRemainWeight.Font = new Font("Microsoft YaHei UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point, 134); - txtRemainWeight.Location = new Point(715, 46); + txtRemainWeight.Location = new Point(715, 49); txtRemainWeight.Name = "txtRemainWeight"; txtRemainWeight.Size = new Size(100, 32); txtRemainWeight.TabIndex = 13; @@ -518,7 +550,7 @@ namespace FATrace.App // txtShelfLife // txtShelfLife.Font = new Font("Microsoft YaHei UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point, 134); - txtShelfLife.Location = new Point(504, 46); + txtShelfLife.Location = new Point(504, 49); txtShelfLife.Name = "txtShelfLife"; txtShelfLife.Size = new Size(100, 32); txtShelfLife.TabIndex = 7; @@ -528,7 +560,7 @@ namespace FATrace.App label12.AutoSize = true; label12.Font = new Font("Microsoft YaHei UI", 14.25F, FontStyle.Bold, GraphicsUnit.Point, 134); label12.ForeColor = SystemColors.WindowFrame; - label12.Location = new Point(618, 49); + label12.Location = new Point(618, 52); label12.Name = "label12"; label12.Size = new Size(107, 26); label12.TabIndex = 12; @@ -539,7 +571,7 @@ namespace FATrace.App label6.AutoSize = true; label6.Font = new Font("Microsoft YaHei UI", 14.25F, FontStyle.Bold, GraphicsUnit.Point, 134); label6.ForeColor = SystemColors.WindowFrame; - label6.Location = new Point(428, 49); + label6.Location = new Point(428, 52); label6.Name = "label6"; label6.Size = new Size(88, 26); label6.TabIndex = 6; @@ -548,7 +580,7 @@ namespace FATrace.App // txtBatch // txtBatch.Font = new Font("Microsoft YaHei UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point, 134); - txtBatch.Location = new Point(315, 46); + txtBatch.Location = new Point(315, 49); txtBatch.Name = "txtBatch"; txtBatch.Size = new Size(100, 32); txtBatch.TabIndex = 5; @@ -558,7 +590,7 @@ namespace FATrace.App label7.AutoSize = true; label7.Font = new Font("Microsoft YaHei UI", 14.25F, FontStyle.Bold, GraphicsUnit.Point, 134); label7.ForeColor = SystemColors.WindowFrame; - label7.Location = new Point(260, 49); + label7.Location = new Point(260, 52); label7.Name = "label7"; label7.Size = new Size(69, 26); label7.TabIndex = 4; @@ -569,7 +601,7 @@ namespace FATrace.App label5.AutoSize = true; label5.Font = new Font("Microsoft YaHei UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point, 134); label5.ForeColor = SystemColors.WindowFrame; - label5.Location = new Point(221, 52); + label5.Location = new Point(221, 55); label5.Name = "label5"; label5.Size = new Size(36, 25); label5.TabIndex = 3; @@ -578,7 +610,7 @@ namespace FATrace.App // txtWeight // txtWeight.Font = new Font("Microsoft YaHei UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point, 134); - txtWeight.Location = new Point(115, 46); + txtWeight.Location = new Point(115, 49); txtWeight.Name = "txtWeight"; txtWeight.Size = new Size(100, 32); txtWeight.TabIndex = 2; @@ -588,7 +620,7 @@ namespace FATrace.App label4.AutoSize = true; label4.Font = new Font("Microsoft YaHei UI", 14.25F, FontStyle.Bold, GraphicsUnit.Point, 134); label4.ForeColor = SystemColors.WindowFrame; - label4.Location = new Point(22, 49); + label4.Location = new Point(22, 52); label4.Name = "label4"; label4.Size = new Size(107, 26); label4.TabIndex = 1; @@ -597,17 +629,18 @@ namespace FATrace.App // label3 // label3.AutoSize = true; - label3.Font = new Font("Microsoft YaHei UI", 15.75F, FontStyle.Bold, GraphicsUnit.Point, 134); + label3.Font = new Font("Microsoft YaHei UI", 18F, FontStyle.Bold); label3.ForeColor = SystemColors.ControlDarkDark; - label3.Location = new Point(14, 6); + label3.Location = new Point(42, 6); label3.Name = "label3"; - label3.Size = new Size(96, 28); + label3.Size = new Size(110, 31); label3.TabIndex = 0; label3.Text = "信息输入"; // // panel1 // panel1.BorderStyle = BorderStyle.FixedSingle; + panel1.Controls.Add(pictureBox2); panel1.Controls.Add(lblRawBeforeInfo); panel1.Controls.Add(btnRawName3); panel1.Controls.Add(btnRawName2); @@ -619,6 +652,17 @@ namespace FATrace.App panel1.Size = new Size(878, 170); panel1.TabIndex = 1; // + // pictureBox2 + // + pictureBox2.BackgroundImageLayout = ImageLayout.None; + pictureBox2.Image = Properties.Resources.选择; + pictureBox2.Location = new Point(8, 6); + pictureBox2.Name = "pictureBox2"; + pictureBox2.Size = new Size(35, 35); + pictureBox2.SizeMode = PictureBoxSizeMode.StretchImage; + pictureBox2.TabIndex = 12; + pictureBox2.TabStop = false; + // // lblRawBeforeInfo // lblRawBeforeInfo.BackColor = Color.Tomato; @@ -668,11 +712,11 @@ namespace FATrace.App // label2 // label2.AutoSize = true; - label2.Font = new Font("Microsoft YaHei UI", 15.75F, FontStyle.Bold, GraphicsUnit.Point, 134); + label2.Font = new Font("Microsoft YaHei UI", 18F, FontStyle.Bold); label2.ForeColor = SystemColors.ControlDarkDark; - label2.Location = new Point(7, 6); + label2.Location = new Point(45, 8); label2.Name = "label2"; - label2.Size = new Size(138, 28); + label2.Size = new Size(158, 31); label2.TabIndex = 0; label2.Text = "选中原料名称"; // @@ -925,6 +969,7 @@ namespace FATrace.App StartPosition = FormStartPosition.CenterScreen; Text = "管理界面"; WindowState = FormWindowState.Maximized; + FormClosed += frmMain_FormClosed; Load += frmMain_Load; statusStrip1.ResumeLayout(false); statusStrip1.PerformLayout(); @@ -938,10 +983,13 @@ namespace FATrace.App tabPage2.ResumeLayout(false); panel3.ResumeLayout(false); panel3.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox4).EndInit(); panel2.ResumeLayout(false); panel2.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox3).EndInit(); panel1.ResumeLayout(false); panel1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox2).EndInit(); tabPage3.ResumeLayout(false); tabPage3.PerformLayout(); tabPage1.ResumeLayout(false); @@ -1026,5 +1074,8 @@ namespace FATrace.App private Label label26; private Label label27; private Button btnMain; + private PictureBox pictureBox2; + private PictureBox pictureBox3; + private PictureBox pictureBox4; } } \ No newline at end of file diff --git a/FATrace.App/frmMain.cs b/FATrace.App/frmMain.cs index 5dcccc6..883c273 100644 --- a/FATrace.App/frmMain.cs +++ b/FATrace.App/frmMain.cs @@ -206,6 +206,8 @@ namespace FATrace.App private async void frmMain_Load(object sender, EventArgs e) // 将加载事件改为 async 以便等待连接 { + this.TabControlMain.SelectedIndex = 1; + // 初始化打印机对象 CurZebraPrint = new ZebraPrint(_printerIp, _printerPort); @@ -275,6 +277,8 @@ namespace FATrace.App await CheckDbStatusAsync(); await CheckPrinterStatusAsync(); }); + + } /// @@ -604,6 +608,37 @@ namespace FATrace.App } } + /// + /// 清零当前的原料 + /// + /// + /// + private void btnClearRaw_Click(object sender, EventArgs e) + { + DialogResult result = MessageBox.Show("您确定清零当前的原料?", "Confirmation", + MessageBoxButtons.YesNo, MessageBoxIcon.Question); + if (result == DialogResult.No) + { + return; + } + + if (CurSelectedRawProInput == null) + { + MessageBox.Show("请选中原料后再操作。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + var UpdatedData = FSqlContext.FDb.Update() + .Set(a => a.RawState, RawSplitState.SplitComplete) + .Where(a => a.Id == CurSelectedRawProInput.Id) + .ExecuteUpdated(); + + if (UpdatedData.Count() > 0) + { + ClearInput(); + } + } + /// /// 称重打印数据 /// @@ -613,9 +648,15 @@ namespace FATrace.App { if (CurSelectedRawProInput == null) { - MessageBox.Show("请先选择要称重的产品", "称重通信错误", MessageBoxButtons.OK, MessageBoxIcon.Warning); + MessageBox.Show("请先选择要称重的产品", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } + if (string.IsNullOrEmpty(CurSelectedRawProInput.RawName) || string.IsNullOrEmpty(CurSelectedRawProInput.Batch) || string.IsNullOrEmpty(CurSelectedRawProInput.RawCode)) + { + MessageBox.Show("选择的产品信息无数据,请信息输入后再操作", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); + return; + } + //新的剩余重量 Kg var NewRemainWeight = CurSelectedRawProInput.RemainWeight - CurWeight / 1000; @@ -654,6 +695,9 @@ namespace FATrace.App { Batch = CurSelectedRawProInput.Batch, InBagCode = Code, + BoxCode = Code + ",A", + OpUser = CurrentOperationNo, + CheckUser = CurrentOperationNo, RawCode = CurSelectedRawProInput.RawCode, ShelfLife = CurSelectedRawProInput.ShelfLife, RawName = CurSelectedRawProInput.RawName, @@ -962,7 +1006,10 @@ namespace FATrace.App private void btnSysConfig_Click(object sender, EventArgs e) { + if (!string.IsNullOrEmpty(CurrentOperationNo)) + { + } } private void btnExit_Click(object sender, EventArgs e) @@ -1001,7 +1048,14 @@ namespace FATrace.App private void btnMain_Click(object sender, EventArgs e) { - TabControlMain.SelectedIndex = 0; + if (!string.IsNullOrEmpty(CurrentOperationNo)) + { + TabControlMain.SelectedIndex = 0; + } + else + { + MessageBox.Show("请登录后再操作!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); + } } private void btnHistoryData_Click(object sender, EventArgs e) @@ -1016,7 +1070,6 @@ namespace FATrace.App #endregion - #region 历史数据搜索 private void btnSearchHistoryData_Click(object sender, EventArgs e) @@ -1169,6 +1222,15 @@ namespace FATrace.App #endregion + private void frmMain_FormClosed(object sender, FormClosedEventArgs e) + { + //CurZebraPrint.Close(); + if (_scaleTcp != null) + { + _scaleTcp!.StopAsync(); + } + + } } } diff --git a/FATrace.WPLApp/App.config b/FATrace.WPLApp/App.config index f0bd202..55a0ac9 100644 --- a/FATrace.WPLApp/App.config +++ b/FATrace.WPLApp/App.config @@ -2,9 +2,10 @@ - - - + + + + diff --git a/FATrace.WPLApp/App.xaml.cs b/FATrace.WPLApp/App.xaml.cs index 1160e20..2b07f00 100644 --- a/FATrace.WPLApp/App.xaml.cs +++ b/FATrace.WPLApp/App.xaml.cs @@ -248,7 +248,7 @@ namespace FATrace.WPLApp //containerRegistry.RegisterSingleton(); containerRegistry.RegisterForNavigation(); - //containerRegistry.RegisterForNavigation(); + containerRegistry.RegisterForNavigation("DashBoardView"); //containerRegistry.RegisterForNavigation(); containerRegistry.RegisterForNavigation(); containerRegistry.RegisterForNavigation(); diff --git a/FATrace.WPLApp/Events/DashboardEvents.cs b/FATrace.WPLApp/Events/DashboardEvents.cs new file mode 100644 index 0000000..dfd21bf --- /dev/null +++ b/FATrace.WPLApp/Events/DashboardEvents.cs @@ -0,0 +1,9 @@ +using Prism.Events; + +namespace FATrace.WPLApp.Events +{ + /// + /// 请求刷新 Dashboard 统计信息的事件(无负载)。 + /// + public class DashboardRefreshEvent : PubSubEvent { } +} diff --git a/FATrace.WPLApp/Services/CsvServices.cs b/FATrace.WPLApp/Services/CsvServices.cs index a6bbdf7..40f344d 100644 --- a/FATrace.WPLApp/Services/CsvServices.cs +++ b/FATrace.WPLApp/Services/CsvServices.cs @@ -115,20 +115,36 @@ namespace FATrace.WPLApp.Services { public RawProUserCsvDtoMap() { - Map(x => x.RawCode).Index(0).Name(nameof(RawProUserCsvDto.RawCode)); - Map(x => x.RawName).Index(1).Name(nameof(RawProUserCsvDto.RawName)); - Map(x => x.InBagCode).Index(2).Name(nameof(RawProUserCsvDto.InBagCode)); - Map(x => x.BoxCode).Index(3).Name(nameof(RawProUserCsvDto.BoxCode)); - Map(x => x.Batch).Index(4).Name(nameof(RawProUserCsvDto.Batch)); - Map(x => x.ShelfLife).Index(5).Name(nameof(RawProUserCsvDto.ShelfLife)); - Map(x => x.Weight).Index(6).Name(nameof(RawProUserCsvDto.Weight)); - Map(x => x.DeliveryDate).Index(7).Name(nameof(RawProUserCsvDto.DeliveryDate)); - Map(x => x.RemainWeight).Index(8).Name(nameof(RawProUserCsvDto.RemainWeight)); - Map(x => x.StockWeight).Index(9).Name(nameof(RawProUserCsvDto.StockWeight)); - Map(x => x.WeightTime).Index(10).Name(nameof(RawProUserCsvDto.WeightTime)).TypeConverterOption.Format("yyyy-MM-dd HH:mm:ss"); - Map(x => x.OpUser).Index(11).Name(nameof(RawProUserCsvDto.OpUser)); - Map(x => x.CheckUser).Index(12).Name(nameof(RawProUserCsvDto.CheckUser)); - Map(x => x.OutTime).Index(13).Name(nameof(RawProUserCsvDto.OutTime)).TypeConverterOption.Format("yyyy-MM-dd HH:mm:ss"); + //Map(x => x.RawCode).Index(0).Name(nameof(RawProUserCsvDto.RawCode)); + //Map(x => x.RawName).Index(1).Name(nameof(RawProUserCsvDto.RawName)); + //Map(x => x.InBagCode).Index(2).Name(nameof(RawProUserCsvDto.InBagCode)); + //Map(x => x.BoxCode).Index(3).Name(nameof(RawProUserCsvDto.BoxCode)); + //Map(x => x.Batch).Index(4).Name(nameof(RawProUserCsvDto.Batch)); + //Map(x => x.ShelfLife).Index(5).Name(nameof(RawProUserCsvDto.ShelfLife)); + //Map(x => x.Weight).Index(6).Name(nameof(RawProUserCsvDto.Weight)); + //Map(x => x.DeliveryDate).Index(7).Name(nameof(RawProUserCsvDto.DeliveryDate)); + //Map(x => x.RemainWeight).Index(8).Name(nameof(RawProUserCsvDto.RemainWeight)); + //Map(x => x.StockWeight).Index(9).Name(nameof(RawProUserCsvDto.StockWeight)); + //Map(x => x.WeightTime).Index(10).Name(nameof(RawProUserCsvDto.WeightTime)).TypeConverterOption.Format("yyyy-MM-dd HH:mm:ss"); + //Map(x => x.OpUser).Index(11).Name(nameof(RawProUserCsvDto.OpUser)); + //Map(x => x.CheckUser).Index(12).Name(nameof(RawProUserCsvDto.CheckUser)); + //Map(x => x.OutTime).Index(13).Name(nameof(RawProUserCsvDto.OutTime)).TypeConverterOption.Format("yyyy-MM-dd HH:mm:ss"); + + Map(x => x.RawCode).Index(0).Name("原料编号"); + Map(x => x.RawName).Index(1).Name("原料名称"); + Map(x => x.InBagCode).Index(2).Name("内袋二维码"); + Map(x => x.BoxCode).Index(3).Name("外箱二维码"); + Map(x => x.Batch).Index(4).Name("批号"); + Map(x => x.ShelfLife).Index(5).Name("保质期"); + Map(x => x.Weight).Index(6).Name("称重重量(g)"); + Map(x => x.DeliveryDate).Index(7).Name("配料日期"); + Map(x => x.RemainWeight).Index(8).Name("剩余重量(Kg)"); + Map(x => x.StockWeight).Index(9).Name("入库总重量(Kg)"); + Map(x => x.WeightTime).Index(10).Name("称重时间").TypeConverterOption.Format("yyyy-MM-dd HH:mm:ss"); + Map(x => x.OpUser).Index(11).Name("操作者"); + Map(x => x.CheckUser).Index(12).Name("确认者"); + Map(x => x.OutTime).Index(13).Name("出库时间").TypeConverterOption.Format("yyyy-MM-dd HH:mm:ss"); + } } } diff --git a/FATrace.WPLApp/Services/DataServices.cs b/FATrace.WPLApp/Services/DataServices.cs index 2a40b20..f2fbc3a 100644 --- a/FATrace.WPLApp/Services/DataServices.cs +++ b/FATrace.WPLApp/Services/DataServices.cs @@ -6,6 +6,8 @@ using Prism.Mvvm; using System.Collections.Concurrent; using System.Windows; using ComConfigHelper = FATrace.Com.ConfigHelper; +using Prism.Events; +using FATrace.WPLApp.Events; namespace FATrace.WPLApp.Services { @@ -15,10 +17,12 @@ namespace FATrace.WPLApp.Services /// public class DataServices : BindableBase, IDisposable { - public DataServices(ILogService logService, IFreeSql freeSql) + public DataServices(ILogService logService, IFreeSql freeSql, IEventAggregator eventAggregator, SysRunService sysRunService) { LogService = logService; FreeSql = freeSql; + EventAggregator = eventAggregator; + SysRunService = sysRunService; LineSglModel = new LineSglModel(); LineSglModel.WeightScanCodeHandle += LineSglModel_WeightScanCodeHandle; @@ -116,7 +120,7 @@ namespace FATrace.WPLApp.Services var Result = FreeSql.Update() .Set(p => p.OutTime, DateTime.Now) - .Where(p => p.BoxCode == BoxScanCode+",A")//外箱二维码就是外箱扫描码 + .Where(p => p.BoxCode == BoxScanCode + ",A")//外箱二维码就是外箱扫描码 .ExecuteAffrows(); if (Result > 0) { @@ -151,7 +155,7 @@ namespace FATrace.WPLApp.Services KeyencePlcMcNet.Write("D1250", new Int16[30]); }); - + try { EventAggregator?.GetEvent()?.Publish(true); } catch { } } /// @@ -227,8 +231,19 @@ namespace FATrace.WPLApp.Services public ILogService LogService { get; } public IFreeSql FreeSql { get; } + public IEventAggregator EventAggregator { get; } + public SysRunService SysRunService { get; } - //通信组件 + private bool _plcConnected; + public bool PlcConnected + { + get { return _plcConnected; } + private set { _plcConnected = value; RaisePropertyChanged(); } + } + + /// + /// 基恩士通信组件 + /// private KeyenceMcNet KeyencePlcMcNet { get; set; } = null; private string _WeightScanCode; @@ -304,6 +319,7 @@ namespace FATrace.WPLApp.Services // 读取 PLC 配置(大小写敏感,采用公共 ConfigHelper 并提供默认值) string PLCIP = ComConfigHelper.GetStringOrDefault("PLCIP", "192.0.1.10"); int Port = ComConfigHelper.GetIntOrDefault("PLCPort", 5000); + try { SysRunService.PlcIp = PLCIP; SysRunService.PlcPort = Port; } catch { } //PLC通信的连接 KeyencePlcMcNet = new KeyenceMcNet(); @@ -317,16 +333,22 @@ namespace FATrace.WPLApp.Services if (connect.IsSuccess)//初始连接状态的显示判断 { Console.WriteLine($"PLC-连接 OK"); + PlcConnected = true; + try { SysRunService.PlcLinkState = true; SysRunService.SysRunState.ComState = 1; SysRunService.SysRunState.ComMsg = "正常"; } catch { } } else { MessageBox.Show(connect.Message + Environment.NewLine + "ErrorCode: " + connect.ErrorCode); + PlcConnected = false; + try { SysRunService.PlcLinkState = false; SysRunService.SysRunState.ComState = 2; SysRunService.SysRunState.ComMsg = "连接失败"; } catch { } } } catch (Exception ex) { LogService.Error(String.Format("ErrSource : {0} ErrMsg : {1}", ex.StackTrace.ToString(), ex.Message.ToString())); //insertLogToDBDelegate.BeginInvoke(1, "UpdateUIMethod异常", ex.Message.ToString() + ex.StackTrace.Substring(ex.StackTrace.Length - 40, 40), null, null); + PlcConnected = false; + try { SysRunService.PlcLinkState = false; SysRunService.SysRunState.ComState = 2; SysRunService.SysRunState.ComMsg = "异常"; } catch { } } } @@ -446,6 +468,14 @@ namespace FATrace.WPLApp.Services if (OperateResultBoxScanSgl.IsSuccess) { LineSglModel.BoxScanCodeEnable = OperateResultBoxScanSgl.Content; + + PlcConnected = true; + try { SysRunService.PlcLinkState = true; SysRunService.SysRunState.ComState = 1; SysRunService.SysRunState.ComMsg = "正常"; } catch { } + } + else + { + PlcConnected = false; + try { SysRunService.PlcLinkState = false; SysRunService.SysRunState.ComState = 2; SysRunService.SysRunState.ComMsg = "连接失败"; } catch { } } } @@ -488,11 +518,16 @@ namespace FATrace.WPLApp.Services if (!ret.IsSuccess) { LogService.Warn($"PLC重连失败: {ret.Message} (Code: {ret.ErrorCode})"); + PlcConnected = false; + try { SysRunService.PlcLinkState = false; SysRunService.SysRunState.ComState = 2; SysRunService.SysRunState.ComMsg = "异常"; } catch { } } + else { PlcConnected = true; try { SysRunService.PlcLinkState = true; SysRunService.SysRunState.ComState = 1; SysRunService.SysRunState.ComMsg = "正常"; } catch { } } } catch (Exception ex) { LogService.Error($"PLC重连异常: {ex.Message}"); + PlcConnected = false; + try { SysRunService.PlcLinkState = false; SysRunService.SysRunState.ComState = 2; SysRunService.SysRunState.ComMsg = "异常"; } catch { } } } diff --git a/FATrace.WPLApp/Services/SysRunService.cs b/FATrace.WPLApp/Services/SysRunService.cs index 5d26cad..60ed016 100644 --- a/FATrace.WPLApp/Services/SysRunService.cs +++ b/FATrace.WPLApp/Services/SysRunService.cs @@ -23,6 +23,41 @@ namespace FATrace.WPLApp.Services } + private string _PlcIp; + /// + /// PLC IP + /// + public string PlcIp + { + get => _PlcIp; + set { _PlcIp = value; RaisePropertyChanged(); UpdatePlcEndPoint(); } + } + + private int _PlcPort; + /// + /// PLC 端口 + /// + public int PlcPort + { + get => _PlcPort; + set { _PlcPort = value; RaisePropertyChanged(); UpdatePlcEndPoint(); } + } + + private string _PlcEndPoint; + /// + /// PLC 终端显示:IP:Port + /// + public string PlcEndPoint + { + get => _PlcEndPoint; + private set { _PlcEndPoint = value; RaisePropertyChanged(); } + } + + private void UpdatePlcEndPoint() + { + PlcEndPoint = string.IsNullOrWhiteSpace(PlcIp) ? string.Empty : $"{PlcIp}:{PlcPort}"; + } + private bool _PlcLinkState = false; /// /// PLC连接状态 diff --git a/FATrace.WPLApp/ViewModels/DashboardViewModel.cs b/FATrace.WPLApp/ViewModels/DashboardViewModel.cs new file mode 100644 index 0000000..e8dc2ff --- /dev/null +++ b/FATrace.WPLApp/ViewModels/DashboardViewModel.cs @@ -0,0 +1,315 @@ +using FATrace.WPLApp.Core; +using Prism.Commands; +using System; +using System.Collections.ObjectModel; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Threading; +using FreeSql; +using FATrace.Model; +using FATrace.WPLApp.Services; +using System.IO; +using System.Windows; +using System.Text; +using Prism.Events; +using FATrace.WPLApp.Events; + +namespace FATrace.WPLApp.ViewModels +{ + public class DashboardViewModel : NavigationViewModel + { + private readonly IFreeSql _fsql; + private readonly ILogService _log; + private readonly DataServices _data; + + private DispatcherTimer _logTimer; + private bool _initialized; + private TextWriter _originalConsoleOut; + private ConsoleInterceptWriter _consoleInterceptor; + + private readonly IEventAggregator _ea; + + public DashboardViewModel(IFreeSql fsql, ILogService log, DataServices data, IEventAggregator ea) + { + _fsql = fsql; + _log = log; + _data = data; + _ea = ea; + + LiveMessages = new ObservableCollection(); + + RefreshCommand = new DelegateCommand(async () => await RefreshStatsAsync()); + ClearLogsCommand = new DelegateCommand(() => LiveMessages.Clear()); + + PlcConnected = _data.PlcConnected; + _data.PropertyChanged += (s, e) => + { + if (e.PropertyName == nameof(DataServices.PlcConnected)) + { + var val = _data.PlcConnected; + if (Application.Current?.Dispatcher?.CheckAccess() == true) + PlcConnected = val; + else + Application.Current?.Dispatcher?.BeginInvoke(new Action(() => PlcConnected = val)); + } + }; + + // 订阅产线信号事件,生成人类可读的运行消息 + _data.LineSglModel.WeightScanCodeHandle += (s, e) => + { + var code = _data.WeightScanCode; + if (Application.Current?.Dispatcher?.CheckAccess() == true) + LatestWeightScanCode = code; + else + Application.Current?.Dispatcher?.BeginInvoke(new Action(() => LatestWeightScanCode = code)); + AppendLiveMessage($"称重扫码触发: {code}"); + }; + _data.LineSglModel.BoxSprayCodeReqHandle += (s, e) => + { + AppendLiveMessage("外箱喷码请求: 已向PLC下发喷码数据"); + }; + _data.LineSglModel.BoxScanCodeReqHandle += (s, e) => + { + var code = _data.BoxScanCode; + if (Application.Current?.Dispatcher?.CheckAccess() == true) + LatestBoxScanCode = code; + else + Application.Current?.Dispatcher?.BeginInvoke(new Action(() => LatestBoxScanCode = code)); + AppendLiveMessage($"外箱扫码触发: {code}"); + }; + + // 订阅外部刷新事件(来自 DataServices 的 BoxScanCode 完成后) + try + { + _dashEventToken = _ea.GetEvent().Subscribe(_ => + { + Application.Current?.Dispatcher?.BeginInvoke(new Action(async () => await RefreshStatsAsync())); + }); + } + catch { } + } + + #region Properties + private double _todayWeight; + public double TodayWeight { get => _todayWeight; set { _todayWeight = value; RaisePropertyChanged(); } } + + private double _monthWeight; + public double MonthWeight { get => _monthWeight; set { _monthWeight = value; RaisePropertyChanged(); } } + + private double _yearWeight; + public double YearWeight { get => _yearWeight; set { _yearWeight = value; RaisePropertyChanged(); } } + + private double _totalWeight; + public double TotalWeight { get => _totalWeight; set { _totalWeight = value; RaisePropertyChanged(); } } + + private string _latestWeightScanCode; + public string LatestWeightScanCode { get => _latestWeightScanCode; set { _latestWeightScanCode = value; RaisePropertyChanged(); } } + + private string _latestBoxScanCode; + public string LatestBoxScanCode { get => _latestBoxScanCode; set { _latestBoxScanCode = value; RaisePropertyChanged(); } } + + private bool _plcConnected; + public bool PlcConnected { get => _plcConnected; set { _plcConnected = value; RaisePropertyChanged(); } } + + public ObservableCollection LiveMessages { get; } + #endregion + + #region Commands + public DelegateCommand RefreshCommand { get; } + public DelegateCommand ClearLogsCommand { get; } + #endregion + + private void StartLogTimer() + { + if (_logTimer != null) return; + _logTimer = new DispatcherTimer + { + Interval = TimeSpan.FromMilliseconds(500) + }; + _logTimer.Tick += (s, e) => + { + // 从 DataServices 的队列中取出消息并展示 + int drain = 0; + while (_data.TryDequeueMessage(out var msg)) + { + if (!string.IsNullOrWhiteSpace(msg)) + { + AppendLiveMessage(msg); + drain++; + if (drain >= 50) break; // 防止一次处理过多 + } + } + }; + _logTimer.Start(); + } + + private void AppendLiveMessage(string message) + { + if (string.IsNullOrWhiteSpace(message)) return; + var line = $"{DateTime.Now:HH:mm:ss} {message}"; + void add() => LiveMessages.Add(line); + if (Application.Current?.Dispatcher?.CheckAccess() == true) add(); + else Application.Current?.Dispatcher?.BeginInvoke(new Action(add)); + // 限制最大条数,避免内存增长 + const int max = 500; + void trim() + { + if (LiveMessages.Count > max) + { + while (LiveMessages.Count > max) + LiveMessages.RemoveAt(0); + } + } + if (Application.Current?.Dispatcher?.CheckAccess() == true) trim(); + else Application.Current?.Dispatcher?.BeginInvoke(new Action(trim)); + } + + private async Task RefreshStatsAsync() + { + try + { + var todayStart = DateTime.Today; + var todayEnd = todayStart.AddDays(1).AddTicks(-1); + + var monthStart = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1); + var monthEnd = monthStart.AddMonths(1).AddTicks(-1); + + var yearStart = new DateTime(DateTime.Today.Year, 1, 1); + var yearEnd = yearStart.AddYears(1).AddTicks(-1); + + var ret = await Task.Run(() => + { + double t = Convert.ToDouble( + _fsql.Select() + .Where(a => a.WeightTime >= todayStart && a.WeightTime <= todayEnd) + .Sum(a => a.Weight)); + + double m = Convert.ToDouble( + _fsql.Select() + .Where(a => a.WeightTime >= monthStart && a.WeightTime <= monthEnd) + .Sum(a => a.Weight)); + + double y = Convert.ToDouble( + _fsql.Select() + .Where(a => a.WeightTime >= yearStart && a.WeightTime <= yearEnd) + .Sum(a => a.Weight)); + + double all = Convert.ToDouble(_fsql.Select().Sum(a => a.Weight)); + + return (t, m, y, all); + }); + + TodayWeight = ret.t; + MonthWeight = ret.m; + YearWeight = ret.y; + TotalWeight = ret.all; + } + catch (Exception ex) + { + _log.Error($"Dashboard 统计刷新失败: {ex}"); + } + } + + public override async void OnNavigatedTo(Prism.Regions.NavigationContext navigationContext) + { + if (!_initialized) + { + _initialized = true; + //StartLogTimer(); + await RefreshStatsAsync(); + // 初始化展示最近一次扫描值 + LatestWeightScanCode = _data.WeightScanCode; + LatestBoxScanCode = _data.BoxScanCode; + TryHookConsole(); + } + } + + public override void OnNavigatedFrom(Prism.Regions.NavigationContext navigationContext) + { + if (_logTimer != null) + { + try { _logTimer.Stop(); } catch { } + _logTimer = null; + } + UnhookConsole(); + try { if (_dashEventToken != null) _ea.GetEvent().Unsubscribe(_dashEventToken); } catch { } + } + + private void TryHookConsole() + { + try + { + if (_consoleInterceptor != null) return; + _originalConsoleOut = Console.Out; + _consoleInterceptor = new ConsoleInterceptWriter(_originalConsoleOut, AppendLiveMessage); + Console.SetOut(_consoleInterceptor); + } + catch { } + } + + private void UnhookConsole() + { + try + { + if (_consoleInterceptor != null && _originalConsoleOut != null) + { + Console.SetOut(_originalConsoleOut); + } + } + catch { } + finally + { + _consoleInterceptor = null; + _originalConsoleOut = null; + } + } + + private class ConsoleInterceptWriter : TextWriter + { + private readonly TextWriter _inner; + private readonly Action _onLine; + private readonly StringWriter _buffer = new StringWriter(); + + public ConsoleInterceptWriter(TextWriter inner, Action onLine) + { + _inner = inner; + _onLine = onLine; + } + + public override Encoding Encoding => _inner.Encoding; + + public override void Write(char value) + { + _inner.Write(value); + if (value == '\n') + { + var line = _buffer.ToString(); + _buffer.GetStringBuilder().Clear(); + if (!string.IsNullOrWhiteSpace(line)) _onLine(line.TrimEnd('\r')); + } + else + { + _buffer.Write(value); + } + } + + public override void Write(string value) + { + _inner.Write(value); + if (value == null) return; + foreach (var ch in value) + { + Write(ch); + } + } + + public override void WriteLine(string value) + { + _inner.WriteLine(value); + if (!string.IsNullOrWhiteSpace(value)) _onLine(value); + } + } + + private SubscriptionToken _dashEventToken; + } +} diff --git a/FATrace.WPLApp/ViewModels/RawProUseViewModel.cs b/FATrace.WPLApp/ViewModels/RawProUseViewModel.cs index c0f1c30..24efc44 100644 --- a/FATrace.WPLApp/ViewModels/RawProUseViewModel.cs +++ b/FATrace.WPLApp/ViewModels/RawProUseViewModel.cs @@ -28,12 +28,13 @@ namespace FATrace.WPLApp.ViewModels { private readonly IFreeSql _fsql; private readonly ILogService _log; + private readonly CsvServices csvServices; - public RawProUseViewModel(IFreeSql fsql, ILogService log) + public RawProUseViewModel(IFreeSql fsql, ILogService log, CsvServices csvServices) { _fsql = fsql; _log = log; - + this.csvServices = csvServices; Items = new ObservableCollection(); // 集合变化时动态刷新导出命令可用性 Items.CollectionChanged += (s, e) => @@ -51,6 +52,8 @@ namespace FATrace.WPLApp.ViewModels .ObservesProperty(() => IsBusy) // Items 是集合引用,通常不会替换引用,这里通过 CollectionChanged 手动触发 ; + ExportCSVCommand = new DelegateCommand(ExportToCsv, () => !IsBusy && Items.Count > 0) + .ObservesProperty(() => IsBusy); ClearCommand = new DelegateCommand(ClearFilters, () => !IsBusy) .ObservesProperty(() => IsBusy); @@ -212,6 +215,7 @@ namespace FATrace.WPLApp.ViewModels #region 命令 public DelegateCommand SearchCommand { get; } public DelegateCommand ExportCommand { get; } + public DelegateCommand ExportCSVCommand { get; } public DelegateCommand ClearCommand { get; } public DelegateCommand FirstPageCommand { get; } public DelegateCommand PrevPageCommand { get; } @@ -356,6 +360,63 @@ namespace FATrace.WPLApp.ViewModels } } + /// + /// 使用 CsvServices 将当前界面数据导出为 CSV 文件(每条记录一个文件,命名为 InBagCode.csv) + /// + private void ExportToCsv() + { + if (IsBusy) return; + if (Items.Count == 0) + { + System.Windows.MessageBox.Show("无可导出的数据", "提示", MessageBoxButton.OK, MessageBoxImage.Information); + return; + } + + try + { + IsBusy = true; + + var dr = "D:\\迅雷下载"; + // 转换为 RawProUserCsvDto + var all = Items.Select(it => new RawProUserCsvDto + { + RawCode = it.RawCode, + RawName = it.RawName, + InBagCode = it.InBagCode, + BoxCode = it.BoxCode, + Batch = it.Batch, + ShelfLife = it.ShelfLife, + Weight = it.Weight, + DeliveryDate = it.WeightTime.ToString("yyyyMMdd"), + RemainWeight = it.RemainWeight, + StockWeight = it.StockWeight, + WeightTime = it.WeightTime, + OpUser = it.OpUser, + CheckUser = it.CheckUser, + OutTime = it.OutTime + }).ToList(); + + // 过滤 InBagCode 为空的记录,避免导出失败 + var valid = all.Where(x => !string.IsNullOrWhiteSpace(x.InBagCode)).ToList(); + int skipped = all.Count - valid.Count; + + var svc = csvServices; + var paths = svc.ExportMany(valid, dr, overwrite: true); + + _log.Info($"RawProUse CSV 导出完成: 目录={dr}, 成功={valid.Count}, 跳过={skipped}"); + System.Windows.MessageBox.Show($"导出完成:成功 {valid.Count} 条,跳过 {skipped} 条。\n目录:{dr}", "提示", MessageBoxButton.OK, MessageBoxImage.Information); + } + catch (Exception ex) + { + _log.Error($"RawProUse CSV 导出失败: {ex}"); + System.Windows.MessageBox.Show($"导出失败: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error); + } + finally + { + IsBusy = false; + } + } + /// /// 导出当前查询结果为 Excel(.xlsx) /// diff --git a/FATrace.WPLApp/Views/DashboardView.xaml b/FATrace.WPLApp/Views/DashboardView.xaml new file mode 100644 index 0000000..91a4bd1 --- /dev/null +++ b/FATrace.WPLApp/Views/DashboardView.xaml @@ -0,0 +1,125 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/FATrace.WPLApp/Views/DashboardView.xaml.cs b/FATrace.WPLApp/Views/DashboardView.xaml.cs new file mode 100644 index 0000000..dfc93db --- /dev/null +++ b/FATrace.WPLApp/Views/DashboardView.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace FATrace.WPLApp.Views +{ + /// + /// DashboardView.xaml 的交互逻辑 + /// + public partial class DashboardView : UserControl + { + public DashboardView() + { + InitializeComponent(); + } + } +} diff --git a/FATrace.WPLApp/Views/FootView.xaml b/FATrace.WPLApp/Views/FootView.xaml index 0250c48..94df29a 100644 --- a/FATrace.WPLApp/Views/FootView.xaml +++ b/FATrace.WPLApp/Views/FootView.xaml @@ -11,7 +11,7 @@ - + @@ -78,13 +78,34 @@ + + + + + - + + + - + - +