diff --git a/BO/BO/Bill/GradeAndWeight/GradeAndWeight_Detail.cs b/BO/BO/Bill/GradeAndWeight/GradeAndWeight_Detail.cs index 9192c6b..233e9ca 100644 --- a/BO/BO/Bill/GradeAndWeight/GradeAndWeight_Detail.cs +++ b/BO/BO/Bill/GradeAndWeight/GradeAndWeight_Detail.cs @@ -14,7 +14,7 @@ namespace BO.BO.Bill public long OrderDetail_ID { get; set; } - public int Order { get; set; } + public int? Order { get; set; } public short Technics { get; set; } diff --git a/BO/Utils/BillRpc/GradeAndWeightRpc.cs b/BO/Utils/BillRpc/GradeAndWeightRpc.cs index aa857f1..051a9ec 100644 --- a/BO/Utils/BillRpc/GradeAndWeightRpc.cs +++ b/BO/Utils/BillRpc/GradeAndWeightRpc.cs @@ -28,16 +28,16 @@ namespace BO.Utils.BillRpc return serializer.Deserialize>(result); } - public static void InsertDetail(GradeAndWeight_Detail detail) + public static void InsertOrInsertDetail(GradeAndWeight_Detail detail) { - const string method = "/MainSystem/B3ClientService/Rpcs/BillRpc/GradeAndWeightRpc/InsertDetail"; + const string method = "/MainSystem/B3ClientService/Rpcs/BillRpc/GradeAndWeightRpc/InsertOrInsertDetail"; detail.ID = RpcFacade.Call(method, serializer.Serialize(detail)); } - public static void FillDetailWeight(long id, decimal weight) + public static void UpdateLivestock(long id, long liveStockID,string liveStockName) { - const string method = "/MainSystem/B3ClientService/Rpcs/BillRpc/GradeAndWeightRpc/FillWeight"; - RpcFacade.Call(method, id, weight); + const string method = "/MainSystem/B3ClientService/Rpcs/BillRpc/GradeAndWeightRpc/UpdateLivestock"; + RpcFacade.Call(method, id, liveStockID, liveStockName); } } } diff --git a/BWP.WinFormControl/WeightControl.cs b/BWP.WinFormControl/WeightControl.cs index 4d6005f..061976c 100644 --- a/BWP.WinFormControl/WeightControl.cs +++ b/BWP.WinFormControl/WeightControl.cs @@ -29,7 +29,7 @@ namespace BWP.WinFormControl private IDataFormat _dataFormat; private Thread _inQueryThread; - //, _outQueryThread; + //, _outQueryThread; readonly StringBuilder _dataStrBuilder = new StringBuilder(); //readonly ConcurrentQueue _dataQueue = new ConcurrentQueue(); Form mainForm; @@ -150,7 +150,7 @@ namespace BWP.WinFormControl _dataStrBuilder.Clear(); _dataStrBuilder.Append(c); } - else if (c == _dataFormat.Endchar || _dataStrBuilder.Length > _dataFormat.Bufsize) + else if (c == _dataFormat.Endchar || _dataStrBuilder.Length == _dataFormat.DataLength - 1) { _dataStrBuilder.Append(c); bool isStatic; @@ -162,7 +162,7 @@ namespace BWP.WinFormControl } _dataStrBuilder.Clear(); } - else + else if (_dataStrBuilder.Length != 0) { _dataStrBuilder.Append(c); } diff --git a/BWP.WinFormControl/WeightDataFormat/DataFormatBase.cs b/BWP.WinFormControl/WeightDataFormat/DataFormatBase.cs index 041e4fb..bf3bcd8 100644 --- a/BWP.WinFormControl/WeightDataFormat/DataFormatBase.cs +++ b/BWP.WinFormControl/WeightDataFormat/DataFormatBase.cs @@ -3,7 +3,7 @@ public interface IDataFormat { char Beginchar { get; } char Endchar { get; } - short Bufsize { get; } + int DataLength { get; } bool ParseAscii(string buf, out string weight, out bool isStatic); bool ParseAscii(string buf, out string weight, out bool isStatic, out string subStr); } @@ -22,8 +22,6 @@ get; } - public abstract short Bufsize { get; } - public const short BUFSIZE = 36; // 根据开始字符找出 一个完整的数据帧 diff --git a/BWP.WinFormControl/WeightDataFormat/IND560DataFormat.cs b/BWP.WinFormControl/WeightDataFormat/IND560DataFormat.cs index e1e086b..a65c696 100644 --- a/BWP.WinFormControl/WeightDataFormat/IND560DataFormat.cs +++ b/BWP.WinFormControl/WeightDataFormat/IND560DataFormat.cs @@ -6,15 +6,11 @@ namespace BWP.WinFormControl.WeightDataFormat } public override char Beginchar { - get { return (char)0x80; }//ûй̶Ŀʼ־ + get { return (char)0x0A; }//ûй̶Ŀʼ־ } public override char Endchar { - get { return (char)0x0A; ; } - } - - public override short Bufsize { - get { return 10; } + get { return (char)0x0D; } } public override string ParseData(string buf, out bool isStatic) diff --git a/BWP.WinFormControl/WeightDataFormat/Xk3124DataFormat.cs b/BWP.WinFormControl/WeightDataFormat/Xk3124DataFormat.cs index 07d1e0c..0a9f53f 100644 --- a/BWP.WinFormControl/WeightDataFormat/Xk3124DataFormat.cs +++ b/BWP.WinFormControl/WeightDataFormat/Xk3124DataFormat.cs @@ -17,11 +17,6 @@ namespace BWP.WinFormControl.WeightDataFormat get { return (char)0x0D; ; } } - public override short Bufsize - { - get { return 36; } - } - public override string ParseData(string buf, out bool isStatic) { StringBuilder str = new StringBuilder(); diff --git a/BWP.WinFormControl/WeightDataFormat/Xk3190A9DataFormat.cs b/BWP.WinFormControl/WeightDataFormat/Xk3190A9DataFormat.cs index e192ab9..9672f37 100644 --- a/BWP.WinFormControl/WeightDataFormat/Xk3190A9DataFormat.cs +++ b/BWP.WinFormControl/WeightDataFormat/Xk3190A9DataFormat.cs @@ -11,11 +11,7 @@ namespace BWP.WinFormControl.WeightDataFormat } public override char Endchar { - get { return (char)0x03; ; } - } - - public override short Bufsize { - get { return 36; } + get { return (char)0x03;} } public override string ParseData(string buf, out bool isStatic) { diff --git a/BWP.WinFormControl/WeightDataFormat/Xk3190D10DataFormat.cs b/BWP.WinFormControl/WeightDataFormat/Xk3190D10DataFormat.cs index aef0b22..8b55a7f 100644 --- a/BWP.WinFormControl/WeightDataFormat/Xk3190D10DataFormat.cs +++ b/BWP.WinFormControl/WeightDataFormat/Xk3190D10DataFormat.cs @@ -13,11 +13,6 @@ namespace BWP.WinFormControl.WeightDataFormat get { return (char)0x0D; ; } } - public override short Bufsize - { - get { return 24; } - } - public override string ParseData(string buf, out bool isStatic) { string weight; // Сλ0-4 diff --git a/ButcherWeight/WeightFormWeightPart.cs b/ButcherWeight/WeightFormWeightPart.cs index 4b400a0..37f3d56 100644 --- a/ButcherWeight/WeightFormWeightPart.cs +++ b/ButcherWeight/WeightFormWeightPart.cs @@ -114,13 +114,13 @@ namespace ButcherWeight _dataStrBuilder.Clear(); _dataStrBuilder.Append(c); } - else if (c == _dataFormat.Endchar || _dataStrBuilder.Length > _dataFormat.Bufsize) + else if (c == _dataFormat.Endchar || _dataStrBuilder.Length == _dataFormat.DataLength - 1) { _dataStrBuilder.Append(c); _dataQueue.Enqueue(_dataStrBuilder.ToString()); _dataStrBuilder.Clear(); } - else + else if (_dataStrBuilder.Length != 0) { _dataStrBuilder.Append(c); } diff --git a/Setup/Release/Setup.msi b/Setup/Release/Setup.msi index 70b2630..8e71296 100644 Binary files a/Setup/Release/Setup.msi and b/Setup/Release/Setup.msi differ diff --git a/WeighAndGrading/GradeFrom.Designer.cs b/WeighAndGrading/GradeFrom.Designer.cs index 306a94d..b6dea56 100644 --- a/WeighAndGrading/GradeFrom.Designer.cs +++ b/WeighAndGrading/GradeFrom.Designer.cs @@ -28,13 +28,13 @@ /// private void InitializeComponent() { - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle5 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle6 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle7 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle22 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle23 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle25 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle26 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle27 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle28 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle24 = new System.Windows.Forms.DataGridViewCellStyle(); this.label1 = new System.Windows.Forms.Label(); this.syncBtn = new System.Windows.Forms.Button(); this.label2 = new System.Windows.Forms.Label(); @@ -63,14 +63,6 @@ this.queryBtn = new System.Windows.Forms.Button(); this.saiXuanBtn = new System.Windows.Forms.Button(); this.historyGrid = new BWP.WinFormControl.UDataGridView(); - this.H_ID = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.H_Livestock_ID = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.H_Index = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.H_Order = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.H_Technics = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.H_Livestock_Name = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.H_Weight = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.H_Time = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.enableWeight = new System.Windows.Forms.CheckBox(); this.isPrintCheckBox = new System.Windows.Forms.CheckBox(); this.printBtn = new System.Windows.Forms.Button(); @@ -87,8 +79,17 @@ this.butcherTimeInput = new BWP.WinFormControl.UDatePicker(); this.closeBtn = new System.Windows.Forms.Button(); this.configBtn = new System.Windows.Forms.Button(); - this.label5 = new System.Windows.Forms.Label(); - this.wb = new System.Windows.Forms.Label(); + this.stateLabel = new System.Windows.Forms.Label(); + this.modifyPanel = new System.Windows.Forms.Panel(); + this.cancelBtn = new System.Windows.Forms.Button(); + this.H_ID = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.H_Livestock_ID = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.H_Index = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.H_Order = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.H_Technics = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.H_Livestock_Name = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.H_Weight = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.H_Time = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.groupBox1.SuspendLayout(); this.groupBox2.SuspendLayout(); this.groupBox3.SuspendLayout(); @@ -97,6 +98,7 @@ ((System.ComponentModel.ISupportInitialize)(this.historyGrid)).BeginInit(); this.panel1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.modifyPanel.SuspendLayout(); this.SuspendLayout(); // // label1 @@ -396,17 +398,17 @@ this.historyGrid.AllowUserToDeleteRows = false; this.historyGrid.AllowUserToResizeColumns = false; this.historyGrid.AllowUserToResizeRows = false; - dataGridViewCellStyle1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(235)))), ((int)(((byte)(235)))), ((int)(((byte)(235))))); - this.historyGrid.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle1; + dataGridViewCellStyle22.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(235)))), ((int)(((byte)(235)))), ((int)(((byte)(235))))); + this.historyGrid.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle22; this.historyGrid.BackgroundColor = System.Drawing.Color.White; - dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; - dataGridViewCellStyle2.BackColor = System.Drawing.SystemColors.Control; - dataGridViewCellStyle2.Font = new System.Drawing.Font("宋体", 12F); - dataGridViewCellStyle2.ForeColor = System.Drawing.SystemColors.WindowText; - dataGridViewCellStyle2.SelectionBackColor = System.Drawing.SystemColors.Highlight; - dataGridViewCellStyle2.SelectionForeColor = System.Drawing.SystemColors.HighlightText; - dataGridViewCellStyle2.WrapMode = System.Windows.Forms.DataGridViewTriState.True; - this.historyGrid.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle2; + dataGridViewCellStyle23.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; + dataGridViewCellStyle23.BackColor = System.Drawing.SystemColors.Control; + dataGridViewCellStyle23.Font = new System.Drawing.Font("宋体", 12F); + dataGridViewCellStyle23.ForeColor = System.Drawing.SystemColors.WindowText; + dataGridViewCellStyle23.SelectionBackColor = System.Drawing.SystemColors.Highlight; + dataGridViewCellStyle23.SelectionForeColor = System.Drawing.SystemColors.HighlightText; + dataGridViewCellStyle23.WrapMode = System.Windows.Forms.DataGridViewTriState.True; + this.historyGrid.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle23; this.historyGrid.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.historyGrid.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.H_ID, @@ -422,76 +424,13 @@ this.historyGrid.Name = "historyGrid"; this.historyGrid.ReadOnly = true; this.historyGrid.RowHeadersVisible = false; - dataGridViewCellStyle4.SelectionBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(66)))), ((int)(((byte)(163)))), ((int)(((byte)(218))))); - this.historyGrid.RowsDefaultCellStyle = dataGridViewCellStyle4; + dataGridViewCellStyle25.SelectionBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(66)))), ((int)(((byte)(163)))), ((int)(((byte)(218))))); + this.historyGrid.RowsDefaultCellStyle = dataGridViewCellStyle25; this.historyGrid.RowTemplate.Height = 40; this.historyGrid.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; this.historyGrid.Size = new System.Drawing.Size(426, 571); this.historyGrid.TabIndex = 0; - // - // H_ID - // - this.H_ID.DataPropertyName = "ID"; - this.H_ID.HeaderText = "ID"; - this.H_ID.Name = "H_ID"; - this.H_ID.ReadOnly = true; - this.H_ID.Visible = false; - // - // H_Livestock_ID - // - this.H_Livestock_ID.HeaderText = "Livestock_ID"; - this.H_Livestock_ID.Name = "H_Livestock_ID"; - this.H_Livestock_ID.ReadOnly = true; - this.H_Livestock_ID.Visible = false; - // - // H_Index - // - this.H_Index.DataPropertyName = "Index"; - this.H_Index.HeaderText = "序号"; - this.H_Index.Name = "H_Index"; - this.H_Index.ReadOnly = true; - this.H_Index.Width = 65; - // - // H_Order - // - this.H_Order.DataPropertyName = "Order"; - this.H_Order.HeaderText = "屠宰顺序"; - this.H_Order.Name = "H_Order"; - this.H_Order.ReadOnly = true; - this.H_Order.Width = 95; - // - // H_Technics - // - this.H_Technics.DataPropertyName = "Technics_Name"; - this.H_Technics.HeaderText = "工艺"; - this.H_Technics.Name = "H_Technics"; - this.H_Technics.ReadOnly = true; - this.H_Technics.Width = 65; - // - // H_Livestock_Name - // - this.H_Livestock_Name.DataPropertyName = "Livestock_Name"; - this.H_Livestock_Name.HeaderText = "级别"; - this.H_Livestock_Name.Name = "H_Livestock_Name"; - this.H_Livestock_Name.ReadOnly = true; - this.H_Livestock_Name.Width = 90; - // - // H_Weight - // - this.H_Weight.DataPropertyName = "Weight"; - dataGridViewCellStyle3.Format = "#0.######"; - this.H_Weight.DefaultCellStyle = dataGridViewCellStyle3; - this.H_Weight.HeaderText = "重量"; - this.H_Weight.Name = "H_Weight"; - this.H_Weight.ReadOnly = true; - this.H_Weight.Width = 65; - // - // H_Time - // - this.H_Time.DataPropertyName = "Time"; - this.H_Time.HeaderText = "时间"; - this.H_Time.Name = "H_Time"; - this.H_Time.ReadOnly = true; + this.historyGrid.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.historyGrid_CellClick); // // enableWeight // @@ -508,9 +447,10 @@ // // isPrintCheckBox // + this.isPrintCheckBox.AutoCheck = false; this.isPrintCheckBox.AutoSize = true; this.isPrintCheckBox.Font = new System.Drawing.Font("宋体", 15F); - this.isPrintCheckBox.Location = new System.Drawing.Point(268, 2); + this.isPrintCheckBox.Location = new System.Drawing.Point(277, 2); this.isPrintCheckBox.Name = "isPrintCheckBox"; this.isPrintCheckBox.Size = new System.Drawing.Size(108, 24); this.isPrintCheckBox.TabIndex = 30; @@ -564,17 +504,17 @@ this.dataGridView.AllowUserToDeleteRows = false; this.dataGridView.AllowUserToResizeColumns = false; this.dataGridView.AllowUserToResizeRows = false; - dataGridViewCellStyle5.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(235)))), ((int)(((byte)(235)))), ((int)(((byte)(235))))); - this.dataGridView.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle5; + dataGridViewCellStyle26.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(235)))), ((int)(((byte)(235)))), ((int)(((byte)(235))))); + this.dataGridView.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle26; this.dataGridView.BackgroundColor = System.Drawing.Color.White; - dataGridViewCellStyle6.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; - dataGridViewCellStyle6.BackColor = System.Drawing.SystemColors.Control; - dataGridViewCellStyle6.Font = new System.Drawing.Font("宋体", 12F); - dataGridViewCellStyle6.ForeColor = System.Drawing.SystemColors.WindowText; - dataGridViewCellStyle6.SelectionBackColor = System.Drawing.SystemColors.Highlight; - dataGridViewCellStyle6.SelectionForeColor = System.Drawing.SystemColors.HighlightText; - dataGridViewCellStyle6.WrapMode = System.Windows.Forms.DataGridViewTriState.True; - this.dataGridView.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle6; + dataGridViewCellStyle27.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; + dataGridViewCellStyle27.BackColor = System.Drawing.SystemColors.Control; + dataGridViewCellStyle27.Font = new System.Drawing.Font("宋体", 12F); + dataGridViewCellStyle27.ForeColor = System.Drawing.SystemColors.WindowText; + dataGridViewCellStyle27.SelectionBackColor = System.Drawing.SystemColors.Highlight; + dataGridViewCellStyle27.SelectionForeColor = System.Drawing.SystemColors.HighlightText; + dataGridViewCellStyle27.WrapMode = System.Windows.Forms.DataGridViewTriState.True; + this.dataGridView.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle27; this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.D_OrderDetail_ID, @@ -588,8 +528,8 @@ this.dataGridView.Name = "dataGridView"; this.dataGridView.ReadOnly = true; this.dataGridView.RowHeadersVisible = false; - dataGridViewCellStyle7.SelectionBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(66)))), ((int)(((byte)(163)))), ((int)(((byte)(218))))); - this.dataGridView.RowsDefaultCellStyle = dataGridViewCellStyle7; + dataGridViewCellStyle28.SelectionBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(66)))), ((int)(((byte)(163)))), ((int)(((byte)(218))))); + this.dataGridView.RowsDefaultCellStyle = dataGridViewCellStyle28; this.dataGridView.RowTemplate.Height = 30; this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; this.dataGridView.Size = new System.Drawing.Size(364, 517); @@ -678,30 +618,110 @@ this.configBtn.UseVisualStyleBackColor = true; this.configBtn.Click += new System.EventHandler(this.configBtn_Click); // - // label5 + // stateLabel + // + this.stateLabel.AutoSize = true; + this.stateLabel.Font = new System.Drawing.Font("宋体", 15F); + this.stateLabel.ForeColor = System.Drawing.Color.Red; + this.stateLabel.Location = new System.Drawing.Point(14, 19); + this.stateLabel.Name = "stateLabel"; + this.stateLabel.Size = new System.Drawing.Size(289, 20); + this.stateLabel.TabIndex = 35; + this.stateLabel.Text = "您正在修改等级为 1000 的等级"; + // + // modifyPanel + // + this.modifyPanel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.modifyPanel.Controls.Add(this.cancelBtn); + this.modifyPanel.Controls.Add(this.stateLabel); + this.modifyPanel.Location = new System.Drawing.Point(826, 107); + this.modifyPanel.Name = "modifyPanel"; + this.modifyPanel.Size = new System.Drawing.Size(438, 56); + this.modifyPanel.TabIndex = 36; + this.modifyPanel.Visible = false; + // + // cancelBtn + // + this.cancelBtn.Font = new System.Drawing.Font("宋体", 15F); + this.cancelBtn.ForeColor = System.Drawing.Color.Red; + this.cancelBtn.Location = new System.Drawing.Point(330, 6); + this.cancelBtn.Name = "cancelBtn"; + this.cancelBtn.Size = new System.Drawing.Size(102, 43); + this.cancelBtn.TabIndex = 36; + this.cancelBtn.Text = "取消"; + this.cancelBtn.UseVisualStyleBackColor = true; + this.cancelBtn.Click += new System.EventHandler(this.cancelBtn_Click); + // + // H_ID + // + this.H_ID.DataPropertyName = "ID"; + this.H_ID.HeaderText = "ID"; + this.H_ID.Name = "H_ID"; + this.H_ID.ReadOnly = true; + this.H_ID.Visible = false; + // + // H_Livestock_ID + // + this.H_Livestock_ID.HeaderText = "Livestock_ID"; + this.H_Livestock_ID.Name = "H_Livestock_ID"; + this.H_Livestock_ID.ReadOnly = true; + this.H_Livestock_ID.Visible = false; + // + // H_Index + // + this.H_Index.DataPropertyName = "Index"; + this.H_Index.HeaderText = "序号"; + this.H_Index.Name = "H_Index"; + this.H_Index.ReadOnly = true; + this.H_Index.Width = 65; + // + // H_Order // - this.label5.AutoSize = true; - this.label5.Location = new System.Drawing.Point(435, 37); - this.label5.Name = "label5"; - this.label5.Size = new System.Drawing.Size(113, 12); - this.label5.TabIndex = 35; - this.label5.Text = "重量显示(测试用)"; + this.H_Order.DataPropertyName = "Order"; + this.H_Order.HeaderText = "顺序"; + this.H_Order.Name = "H_Order"; + this.H_Order.ReadOnly = true; + this.H_Order.Width = 65; // - // wb + // H_Technics // - this.wb.AutoSize = true; - this.wb.Location = new System.Drawing.Point(565, 37); - this.wb.Name = "wb"; - this.wb.Size = new System.Drawing.Size(0, 12); - this.wb.TabIndex = 36; + this.H_Technics.DataPropertyName = "Technics_Name"; + this.H_Technics.HeaderText = "工艺"; + this.H_Technics.Name = "H_Technics"; + this.H_Technics.ReadOnly = true; + this.H_Technics.Width = 65; + // + // H_Livestock_Name + // + this.H_Livestock_Name.DataPropertyName = "Livestock_Name"; + this.H_Livestock_Name.HeaderText = "级别"; + this.H_Livestock_Name.Name = "H_Livestock_Name"; + this.H_Livestock_Name.ReadOnly = true; + this.H_Livestock_Name.Width = 90; + // + // H_Weight + // + this.H_Weight.DataPropertyName = "Weight"; + dataGridViewCellStyle24.Format = "#0.######"; + this.H_Weight.DefaultCellStyle = dataGridViewCellStyle24; + this.H_Weight.HeaderText = "重量"; + this.H_Weight.Name = "H_Weight"; + this.H_Weight.ReadOnly = true; + this.H_Weight.Width = 65; + // + // H_Time + // + this.H_Time.DataPropertyName = "Time"; + this.H_Time.HeaderText = "时间"; + this.H_Time.Name = "H_Time"; + this.H_Time.ReadOnly = true; // // GradeFrom // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(1276, 865); - this.Controls.Add(this.wb); - this.Controls.Add(this.label5); + this.Controls.Add(this.modifyPanel); this.Controls.Add(this.configBtn); this.Controls.Add(this.closeBtn); this.Controls.Add(this.label10); @@ -739,6 +759,8 @@ this.panel1.ResumeLayout(false); this.panel1.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.modifyPanel.ResumeLayout(false); + this.modifyPanel.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); @@ -790,6 +812,9 @@ private System.Windows.Forms.DataGridViewTextBoxColumn D_Number; private System.Windows.Forms.DataGridViewTextBoxColumn D_Already; private System.Windows.Forms.Button configBtn; + private System.Windows.Forms.Label stateLabel; + private System.Windows.Forms.Panel modifyPanel; + private System.Windows.Forms.Button cancelBtn; private System.Windows.Forms.DataGridViewTextBoxColumn H_ID; private System.Windows.Forms.DataGridViewTextBoxColumn H_Livestock_ID; private System.Windows.Forms.DataGridViewTextBoxColumn H_Index; @@ -798,7 +823,5 @@ private System.Windows.Forms.DataGridViewTextBoxColumn H_Livestock_Name; private System.Windows.Forms.DataGridViewTextBoxColumn H_Weight; private System.Windows.Forms.DataGridViewTextBoxColumn H_Time; - private System.Windows.Forms.Label label5; - private System.Windows.Forms.Label wb; } } \ No newline at end of file diff --git a/WeighAndGrading/GradeFrom.cs b/WeighAndGrading/GradeFrom.cs index 39d8cf9..d3a70b4 100644 --- a/WeighAndGrading/GradeFrom.cs +++ b/WeighAndGrading/GradeFrom.cs @@ -37,10 +37,10 @@ namespace WeighAndGrading List details; SerialPort weightPort; int maxIndex = 0; - Thread syncWegithThread; + readonly ConcurrentQueue tempList = new ConcurrentQueue(); - readonly ConcurrentQueue _detailQueue = new ConcurrentQueue(); - readonly ConcurrentQueue _weightQueue = new ConcurrentQueue(); + // readonly ConcurrentQueue _detailQueue = new ConcurrentQueue(); + //readonly ConcurrentQueue _weightQueue = new ConcurrentQueue(); #region weightNeed private IDataFormat _dataFormat; @@ -51,21 +51,20 @@ namespace WeighAndGrading private const int WmUpdDisplayMessage = 0x0500 + 2; private string _displayValue; - private int _mainHandle; - string lbShow = ""; + // private int _mainHandle; #endregion - int MainHandle - { - get - { - if (_mainHandle == 0) - { - _mainHandle = WinApiSendMessage.FindWindow(null, this.Text); - } - return _mainHandle; - } - } + //int MainHandle + //{ + // get + // { + // if (_mainHandle == 0) + // { + // _mainHandle = WinApiSendMessage.FindWindow(null, this.Text); + // } + // return _mainHandle; + // } + //} public GradeFrom() { @@ -74,45 +73,46 @@ namespace WeighAndGrading dataGridView.AutoGenerateColumns = false; dataGridView.DataSource = null; historyGrid.AutoGenerateColumns = false; - historyGrid.DataSource = null; AddLivestockBtn(); weightPort = new SerialPort(); - syncWegithThread = new Thread(SyncTask) { IsBackground = true }; + // syncWegithThread = new Thread(SyncTask) { IsBackground = true }; this.FormClosing += delegate { - if (syncWegithThread.IsAlive) - syncWegithThread.Abort(); + //if (syncWegithThread.IsAlive) + //syncWegithThread.Abort(); if (_inQueryThread != null && _inQueryThread.IsAlive) DisableWeight(); }; } - private void SyncTask() - { - while (_mainProcessIsRun) - { - if (_detailQueue.Any() && _weightQueue.Any()) - { - long id; - decimal weight; - if (_detailQueue.TryDequeue(out id) && _weightQueue.TryDequeue(out weight)) - { - GradeAndWeightRpc.FillDetailWeight(id, weight); - var first = details.FirstOrDefault(x => x.ID == id); - if (first != null) - { - first.Weight = weight; - this.Invoke(new InvokeHandler(delegate() - { - historyGrid.Refresh(); - })); - } - } - } - else - Thread.Sleep(1000); - } - } + //private void SyncTask() + //{ + // while (_mainProcessIsRun) + // { + // if (_detailQueue.Any() && _weightQueue.Any()) + // { + // long id; + // decimal weight; + // if (_detailQueue.TryDequeue(out id) && _weightQueue.TryDequeue(out weight)) + // { + // GradeAndWeightRpc.FillDetailWeight(id, weight); + // var first = details.FirstOrDefault(x => x.ID == id); + // if (first != null) + // { + // first.Weight = weight; + // this.Invoke(new InvokeHandler(delegate() + // { + // historyGrid.Refresh(); + // })); + // } + // } + // } + // else + // Thread.Sleep(1000); + // } + //} + + GradeAndWeight_Detail modifyDetail; void AddLivestockBtn() { @@ -122,36 +122,23 @@ namespace WeighAndGrading var btn = new Button() { Name = "_" + item.Item1, Text = item.Item2, Tag = item, Size = new Size(70, 60), TextAlign = ContentAlignment.MiddleCenter, Margin = new Padding { All = 10 }, Font = new Font("宋体", 15) }; btn.Click += (sender, e) => { - var selectRows = GetEnableTopTowRows(); - if (selectRows.Count == 0) - throw new Exception("没有可定级的数据记录了"); - var livestock = (CTuple)btn.Tag; - var tech = livestock.Item3 == 0 ? "烫褪" : "毛剥"; - var targetRow = selectRows.FirstOrDefault(x => x.Cells["D_Technics_Name"].Value.ToString() == tech); - if (targetRow == null) - throw new Exception(string.Format("没有 {0} 的数据可操作", tech)); - var currentRow = targetRow.DataBoundItem as GradeAndWeight; - - maxIndex += 1; - var entity = new GradeAndWeight_Detail(); - entity.Index = maxIndex; - entity.OrderDetail_ID = currentRow.OrderDetail_ID; - entity.Order = currentRow.Order; - entity.Livestock_ID = livestock.Item1; - entity.Livestock_Name = livestock.Item2; - entity.Technics = livestock.Item3; - entity.Technics_Name = livestock.Item3 == 0 ? "烫褪" : "毛剥"; - entity.Time = DateTime.Now; - - details.Insert(0, entity); - GradeAndWeightRpc.InsertDetail(entity); - _detailQueue.Enqueue(entity.ID); - currentRow.Already = currentRow.Already + 1; - - BindDataGrid(); - historyGrid.DataSource = null; - historyGrid.DataSource = details; - historyGrid.Refresh(); + var livestockTag = btn.Tag as CTuple; + if (modifyDetail == null) + AddDetail(livestockTag); + else + { + if (modifyDetail.Technics != livestockTag.Item3) + { + MessageBox.Show("工艺选择错误!请重新选择"); + return; + } + modifyDetail.Livestock_ID = livestockTag.Item1; + modifyDetail.Livestock_Name = livestockTag.Item2; + GradeAndWeightRpc.UpdateLivestock(modifyDetail.ID, modifyDetail.Livestock_ID, modifyDetail.Livestock_Name); + historyGrid.Refresh(); + modifyDetail = null; + modifyPanel.Hide(); + } //var name = livestock.Technics == 0 ? "带皮白条" : "去皮白条"; //Print(name, entity.Index); @@ -247,7 +234,9 @@ namespace WeighAndGrading void BindDetailGrid() { - historyGrid.DataSource = details; + historyGrid.DataSource = null; + if (details.Any()) + historyGrid.DataSource = details; historyGrid.Refresh(); } @@ -387,13 +376,13 @@ namespace WeighAndGrading _dataStrBuilder.Clear(); _dataStrBuilder.Append(c); } - else if (c == _dataFormat.Endchar || _dataStrBuilder.Length > _dataFormat.Bufsize) + else if (c == _dataFormat.Endchar && _dataStrBuilder.Length == _dataFormat.DataLength - 1) { _dataStrBuilder.Append(c); _dataQueue.Enqueue(_dataStrBuilder.ToString()); _dataStrBuilder.Clear(); } - else + else if (_dataStrBuilder.Length != 0) { _dataStrBuilder.Append(c); } @@ -425,10 +414,13 @@ namespace WeighAndGrading _displayValue = string.Format(format, decimal.Parse(str)); if (str != "0") { - _weightQueue.Enqueue(decimal.Parse(_displayValue)); - lbShow += (string.Format(",{0}", str)); + this.Invoke(new InvokeHandler(delegate() + { + lblChengZhong.Text = _displayValue; + //AddWeightDetail(decimal.Parse(_displayValue)); + })); } - WinApiSendMessage.SendMessage(MainHandle, WmUpdDisplayMessage, 0, 0); + //WinApiSendMessage.SendMessage(MainHandle, WmUpdDisplayMessage, 0, 0); } } catch (Exception) @@ -443,8 +435,8 @@ namespace WeighAndGrading void DisableWeight() { _mainProcessIsRun = false; - if (syncWegithThread != null && syncWegithThread.IsAlive) - syncWegithThread.Abort(); + //if (syncWegithThread != null && syncWegithThread.IsAlive) + // syncWegithThread.Abort(); WeightValue = 0; format = "{0:0.00}"; Thread.Sleep(10); @@ -462,13 +454,18 @@ namespace WeighAndGrading public void enableWeight_Click(object sender, EventArgs e) { + if (details == null) + { + MessageBox.Show("请先同步数据"); + return; + } if (!enableWeight.Checked) { OpenSerialPort(); _mainProcessIsRun = true; ReadData(); - if (syncWegithThread != null && !syncWegithThread.IsAlive) - syncWegithThread.Start(); + //if (syncWegithThread != null && !syncWegithThread.IsAlive) + // syncWegithThread.Start(); } else DisableWeight(); @@ -486,20 +483,115 @@ namespace WeighAndGrading set { lblChengZhong.Text = string.Format(format, value); } } - protected override void DefWndProc(ref Message m) + //protected override void DefWndProc(ref Message m) + //{ + // switch (m.Msg) + // { + // case WmUpdDisplayMessage: + // lblChengZhong.Text = _displayValue; + // break; + // default: + // base.DefWndProc(ref m); + // break; + // } + //} + #endregion + + static object _obj = new object(); + + void AddDetail(CTuple livestock) { - switch (m.Msg) + lock (_obj) { - case WmUpdDisplayMessage: - lblChengZhong.Text = _displayValue; - wb.Text = lbShow; - break; + var selectRows = GetEnableTopTowRows(); + if (selectRows.Count == 0) + throw new Exception("没有可定级的数据记录了"); + // var livestock = (CTuple)btn.Tag; + var tech = livestock.Item3 == 0 ? "烫褪" : "毛剥"; + var targetRow = selectRows.FirstOrDefault(x => x.Cells["D_Technics_Name"].Value.ToString() == tech); + if (targetRow == null) + throw new Exception(string.Format("没有 {0} 的数据可操作", tech)); + var currentRow = targetRow.DataBoundItem as GradeAndWeight; + + + GradeAndWeight_Detail first; + if (tempList.TryPeek(out first) && first.Livestock_ID == 0) + { + tempList.TryDequeue(out first); + first.OrderDetail_ID = currentRow.OrderDetail_ID; + first.Order = currentRow.Order; + first.Livestock_ID = livestock.Item1; + first.Livestock_Name = livestock.Item2; + first.Technics = livestock.Item3; + first.Technics_Name = livestock.Item3 == 0 ? "烫褪" : "毛剥"; + GradeAndWeightRpc.InsertOrInsertDetail(first); + historyGrid.Refresh(); + } + else//add + { + maxIndex++; + var entity = new GradeAndWeight_Detail(); + entity.Index = maxIndex; + entity.OrderDetail_ID = currentRow.OrderDetail_ID; + entity.Order = currentRow.Order; + entity.Livestock_ID = livestock.Item1; + entity.Livestock_Name = livestock.Item2; + entity.Technics = livestock.Item3; + entity.Technics_Name = livestock.Item3 == 0 ? "烫褪" : "毛剥"; + entity.Time = DateTime.Now; - default: - base.DefWndProc(ref m); - break; + details.Insert(0, entity); + GradeAndWeightRpc.InsertOrInsertDetail(entity); + tempList.Enqueue(entity); + BindDetailGrid(); + } + currentRow.Already = currentRow.Already + 1; + + BindDataGrid(); } } - #endregion + + void AddWeightDetail(decimal weight) + { + lock (_obj) + { + weight -= (GradeContext.Config.Discont ?? 0); + GradeAndWeight_Detail first; + if (tempList.TryPeek(out first) && first.Weight == null) + { + tempList.TryDequeue(out first); + first.Weight = weight; + GradeAndWeightRpc.InsertOrInsertDetail(first); + historyGrid.Refresh(); + } + else//add + { + maxIndex++; + var entity = new GradeAndWeight_Detail(); + entity.Index = maxIndex; + entity.Weight = weight; + entity.Time = DateTime.Now; + details.Insert(0, entity); + GradeAndWeightRpc.InsertOrInsertDetail(entity); + tempList.Enqueue(entity); + BindDetailGrid(); + } + } + } + + private void cancelBtn_Click(object sender, EventArgs e) + { + modifyDetail = null; + modifyPanel.Hide(); + } + + private void historyGrid_CellClick(object sender, DataGridViewCellEventArgs e) + { + if (e.RowIndex < 0) + return; + modifyDetail = historyGrid.Rows[e.RowIndex].DataBoundItem as GradeAndWeight_Detail; + stateLabel.Text = string.Format("您正在修改序号为 {0} 的等级", modifyDetail.Index); + modifyPanel.Show(); + } } }