Browse Source

修改。

master
yibo 8 years ago
parent
commit
26f961281e
15 changed files with 1268 additions and 506 deletions
  1. +9
    -0
      BWP.WinFormControl/BWP.WinFormControl.csproj
  2. +0
    -1
      BWP.WinFormControl/ComponentUtil.cs
  3. +42
    -0
      BWP.WinFormControl/UDataGridView.cs
  4. +4
    -0
      BWP.WinFormControl/WeightControl.Designer.cs
  5. +237
    -1
      BWP.WinFormControl/WeightControl.cs
  6. +3
    -0
      BWP.WinFormControl/WeightControl.resx
  7. +57
    -0
      BWP.WinFormControl/WeightDataFormat/DataFormatBase.cs
  8. +40
    -0
      BWP.WinFormControl/WeightDataFormat/IND560DataFormat.cs
  9. +104
    -0
      BWP.WinFormControl/WeightDataFormat/Xk3124DataFormat.cs
  10. +110
    -0
      BWP.WinFormControl/WeightDataFormat/Xk3190A9DataFormat.cs
  11. +106
    -0
      BWP.WinFormControl/WeightDataFormat/Xk3190D10DataFormat.cs
  12. +23
    -0
      BWP.WinFormControl/WinApiSendMessage.cs
  13. +3
    -0
      ButcherManageClient/Login.Designer.cs
  14. +496
    -501
      ButcherWeight/WeightForm.Designer.cs
  15. +34
    -3
      ButcherWeight/WeightForm.cs

+ 9
- 0
BWP.WinFormControl/BWP.WinFormControl.csproj View File

@ -55,6 +55,11 @@
</Compile>
<Compile Include="ComboBoxHelper.cs" />
<Compile Include="ComponentUtil.cs" />
<Compile Include="WeightDataFormat\DataFormatBase.cs" />
<Compile Include="WeightDataFormat\IND560DataFormat.cs" />
<Compile Include="WeightDataFormat\Xk3124DataFormat.cs" />
<Compile Include="WeightDataFormat\Xk3190A9DataFormat.cs" />
<Compile Include="WeightDataFormat\Xk3190D10DataFormat.cs" />
<Compile Include="NumberPad.xaml.cs">
<DependentUpon>NumberPad.xaml</DependentUpon>
</Compile>
@ -62,6 +67,9 @@
<Compile Include="UComboBox.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="UDataGridView.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="UDatePicker.cs">
<SubType>Component</SubType>
</Compile>
@ -77,6 +85,7 @@
<Compile Include="WeightControl.Designer.cs">
<DependentUpon>WeightControl.cs</DependentUpon>
</Compile>
<Compile Include="WinApiSendMessage.cs" />
</ItemGroup>
<ItemGroup>
<Page Include="Calendar.xaml">


+ 0
- 1
BWP.WinFormControl/ComponentUtil.cs View File

@ -23,7 +23,6 @@ namespace BWP.WinFormControl
}
}
return control as Form;
}
}
}

+ 42
- 0
BWP.WinFormControl/UDataGridView.cs View File

@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace BWP.WinFormControl
{
public class UDataGridView : DataGridView
{
public UDataGridView()
{
this.AllowUserToAddRows = false;
this.AllowUserToDeleteRows = false;
this.AllowUserToResizeColumns = false;
this.AllowUserToResizeRows = false;
this.BackgroundColor = System.Drawing.Color.White;
this.ColumnHeadersHeight = 24;
this.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
this.MultiSelect = false;
this.RowHeadersVisible = false;
this.RowTemplate.Height = 23;
this.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
this.AlternatingRowsDefaultCellStyle = new DataGridViewCellStyle() { BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(235)))), ((int)(((byte)(235)))), ((int)(((byte)(235))))) };
this.ColumnHeadersDefaultCellStyle = new DataGridViewCellStyle()
{
Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft,
BackColor = System.Drawing.SystemColors.Control,
Font = new System.Drawing.Font("宋体", 12F),
ForeColor = System.Drawing.SystemColors.WindowText,
SelectionBackColor = System.Drawing.SystemColors.Highlight,
SelectionForeColor = System.Drawing.SystemColors.HighlightText,
WrapMode = System.Windows.Forms.DataGridViewTriState.True,
};
this.RowsDefaultCellStyle = new DataGridViewCellStyle() { SelectionBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(66)))), ((int)(((byte)(163)))), ((int)(((byte)(218))))) };
}
}
}

+ 4
- 0
BWP.WinFormControl/WeightControl.Designer.cs View File

@ -28,9 +28,11 @@
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.panel1 = new System.Windows.Forms.Panel();
this.weightLabel = new System.Windows.Forms.Label();
this.enableWeightBox = new System.Windows.Forms.CheckBox();
this.weightSerialPort = new System.IO.Ports.SerialPort(this.components);
this.panel1.SuspendLayout();
this.SuspendLayout();
//
@ -65,6 +67,7 @@
this.enableWeightBox.TabIndex = 1;
this.enableWeightBox.Text = "启用称重";
this.enableWeightBox.UseVisualStyleBackColor = true;
this.enableWeightBox.CheckedChanged += new System.EventHandler(this.enableWeightBox_CheckedChanged);
//
// WeightControl
//
@ -86,5 +89,6 @@
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Label weightLabel;
private System.Windows.Forms.CheckBox enableWeightBox;
private System.IO.Ports.SerialPort weightSerialPort;
}
}

+ 237
- 1
BWP.WinFormControl/WeightControl.cs View File

@ -7,12 +7,80 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;
using System.Threading;
using System.Collections.Concurrent;
using BWP.WinFormControl.WeightDataFormat;
using System.Windows.Forms;
namespace BWP.WinFormControl
{
public enum WeightType
{
IND560,
Xk3124,
Xk3190A9,
Xk3190D10
}
public partial class WeightControl : UserControl
{
public Label WeightLabel { get { return weightLabel; } }
#region weight Need
private IDataFormat _dataFormat;
private Thread _inQueryThread, _outQueryThread;
readonly StringBuilder _dataStrBuilder = new StringBuilder();
readonly ConcurrentQueue<string> _dataQueue = new ConcurrentQueue<string>();
Form mainForm;
#endregion
bool inited = false;
public void InitSerialPort(string comPort, int baudRate, int dataBits)
{
weightSerialPort.PortName = comPort;
weightSerialPort.BaudRate = baudRate;
weightSerialPort.DataBits = dataBits;
weightSerialPort.ReadBufferSize = 4096 * 100;
inited = true;
}
//public SerialPort WeightSerialPort { get { return this.weightSerialPort; } }
private string _valueFormat = @"0.00";
public string ValueFormat { get { return _valueFormat; } set { _valueFormat = value; } }
private WeightType _weightType = WeightType.Xk3190A9;
/// <summary>
/// 称类型
/// </summary>
public WeightType TypeOfWeight
{
get { return _weightType; }
set { _weightType = value; }
}
string format
{
get
{
if (string.IsNullOrEmpty(_valueFormat))
_valueFormat = @"0.00";
return "{0:" + _valueFormat + "}";
}
}
public decimal? Value
{
get
{
if (string.IsNullOrEmpty(weightLabel.Text)) return null;
return decimal.Parse(string.Format(format, weightLabel.Text));
}
private set { weightLabel.Text = string.Format(format, value); }
}
public void Clear()
{
Value = 0;
}
public CheckBox EnableCheckBox { get { return enableWeightBox; } }
@ -20,5 +88,173 @@ namespace BWP.WinFormControl
{
InitializeComponent();
}
private void OpenSerialPort()
{
if (!inited)
throw new Exception("Com口没有实例化,请先调用InitSerialPort");
// 打开串口
if (!weightSerialPort.IsOpen)
{
try
{
weightSerialPort.Open();
if (mainForm == null)
mainForm = ComponentUtil.GetParentFormm(this);
mainForm.FormClosing += MainFrom_FormClosing;
}
catch (InvalidOperationException)
{
MessageBox.Show(@"指定的端口已打开");
}
catch (UnauthorizedAccessException)
{
MessageBox.Show(@"对端口的访问被拒绝");
}
}
}
void ReadData()
{
_inQueryThread = new Thread(InQuery);
_inQueryThread.Start();
_outQueryThread = new Thread(OutQuery);
_outQueryThread.Start();
}
private void InQuery()
{
while (enableWeightBox.Checked)
{
int availableCount = weightSerialPort.BytesToRead;
if (availableCount == 0)
{
Thread.Sleep(1);
}
char[] buffer = new char[availableCount];
if (!weightSerialPort.IsOpen)
{
continue;
}
weightSerialPort.Read(buffer, 0, availableCount);
foreach (var c in buffer)
{
if (c == _dataFormat.Beginchar)
{
_dataStrBuilder.Clear();
_dataStrBuilder.Append(c);
}
else if (c == _dataFormat.Endchar || _dataStrBuilder.Length > _dataFormat.Bufsize)
{
_dataStrBuilder.Append(c);
_dataQueue.Enqueue(_dataStrBuilder.ToString());
_dataStrBuilder.Clear();
}
else
{
_dataStrBuilder.Append(c);
}
}
}
}
private void OutQuery()
{
while (enableWeightBox.Checked)
{
try
{
bool isStatic;
string str;
string subStr;
if (!_dataQueue.TryDequeue(out subStr))
{
Thread.Sleep(1);
continue;
}
// 解析接受的端口数据
if (_dataFormat.ParseAscii(subStr, out str, out isStatic))
{
Value = decimal.Parse(str);
}
}
catch (Exception)
{
Thread.Sleep(1000);
continue;
}
Thread.Sleep(1);
}
}
void InitWeightType()
{
switch (_weightType)
{
case WeightType.IND560:
_dataFormat = new IND560DataFormat();
break;
case WeightType.Xk3124:
_dataFormat = new Xk3124DataFormat();
break;
case WeightType.Xk3190A9:
_dataFormat = new Xk3190A9DataFormat();
break;
case WeightType.Xk3190D10:
_dataFormat = new Xk3190D10DataFormat();
break;
default:
throw new Exception("未知称类型");
}
}
void DisableWeight()
{
mainForm.FormClosing -= MainFrom_FormClosing;
Thread.Sleep(10);
if (weightSerialPort.IsOpen)
{
weightSerialPort.Close();
}
if (_inQueryThread.IsAlive)
{
_inQueryThread.Abort();
}
if (_outQueryThread.IsAlive)
{
_outQueryThread.Abort();
}
Value = 0;
}
private void MainFrom_FormClosing(object sender, FormClosingEventArgs e)
{
if (!enableWeightBox.Checked)
return;
DisableWeight();
}
private void enableWeightBox_CheckedChanged(object sender, EventArgs e)
{
if (!inited)
{
enableWeightBox.Checked = false;
throw new Exception("Com口没有实例化,请先调用InitSerialPort");
}
if (enableWeightBox.Checked)
{
InitWeightType();
OpenSerialPort();
ReadData();
}
else
DisableWeight();
}
}
}

+ 3
- 0
BWP.WinFormControl/WeightControl.resx View File

@ -117,4 +117,7 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="weightSerialPort.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

+ 57
- 0
BWP.WinFormControl/WeightDataFormat/DataFormatBase.cs View File

@ -0,0 +1,57 @@
namespace BWP.WinFormControl.WeightDataFormat
{
interface IDataFormat {
char Beginchar { get; }
char Endchar { get; }
short Bufsize { get; }
bool ParseAscii(string buf, out string weight, out bool isStatic);
bool ParseAscii(string buf, out string weight, out bool isStatic, out string subStr);
}
public abstract class DataFormatBase : IDataFormat {
public abstract int DataLength {
get;
}
public abstract char Beginchar {
get;
}
public abstract char Endchar {
get;
}
public abstract short Bufsize { get; }
public const short BUFSIZE = 36;
// 根据开始字符找出 一个完整的数据帧
public string FindDataFrame(string buf, int fSize) {
var bufSize = buf.Length;
if (fSize > bufSize) {
return string.Empty;
}
int index = buf.IndexOf(Beginchar); // 查找开始字符的索引
if (index < 0 || (index + fSize) > bufSize) {
return string.Empty;
}
string data = buf.Substring(index, fSize);
// 检查结束字符
if (data[fSize - 1] != Endchar) {
return string.Empty;
}
return data;
}
public abstract string ParseData(string buf, out bool isStatic);
public abstract bool ParseAscii(string buf, out string weight, out bool isStatic);
public abstract bool ParseAscii(string buf, out string weight, out bool isStatic, out string subStr);
}
}

+ 40
- 0
BWP.WinFormControl/WeightDataFormat/IND560DataFormat.cs View File

@ -0,0 +1,40 @@
namespace BWP.WinFormControl.WeightDataFormat
{
public class IND560DataFormat : DataFormatBase {
public override int DataLength {
get { return 10; }
}
public override char Beginchar {
get { return (char)0x80; }//这种数据没有固定的开始标志
}
public override char Endchar {
get { return (char)0x0A; ; }
}
public override short Bufsize {
get { return 10; }
}
public override string ParseData(string buf, out bool isStatic)
{
isStatic = false;
return string.Empty;
}
public override bool ParseAscii(string buf, out string weight, out bool isStatic) {
isStatic = true;
weight = buf.Replace("kg", "").Replace((char)0x0D, (char)0x20).Replace((char)0x0A, (char)0x20);
weight = weight.Trim();
return true;
}
public override bool ParseAscii(string buf, out string weight, out bool isStatic, out string subStr) {
weight = "";
isStatic = false;
subStr = "";
return false;
}
}
}

+ 104
- 0
BWP.WinFormControl/WeightDataFormat/Xk3124DataFormat.cs View File

@ -0,0 +1,104 @@
using System.Text;
namespace BWP.WinFormControl.WeightDataFormat
{
public class Xk3124DataFormat : DataFormatBase {
public override int DataLength {
get { return 17; }
}
public override char Beginchar
{
get { return (char)0x02; }
}
public override char Endchar
{
get { return (char)0x0D; ; }
}
public override short Bufsize
{
get { return 36; }
}
public override string ParseData(string buf, out bool isStatic) {
StringBuilder str = new StringBuilder();
char swa = buf[1]; // 状态字A
char swb = buf[2]; // 状态字B
int dotIndex = (swa & 0x07) - 2; // 小数点位置
bool isPositive = (((swb >> 1) & 0x01) == 0); // 符号:是否为正数
isStatic = (((swb >> 3) & 0x01) == 0);
char[] num = new char[6];
for (int i = 0; i < 6; i++) {
num[i] = buf[i + 4];
}
if (dotIndex < 0) { // 不考虑精确到十,百位
return str.ToString();
}
for (int i = 0; i < 6 - dotIndex; i++) {
str.Append(num[i]);
}
str.Append('.');
for (int i = 0; i < dotIndex; i++) {
str.Append(num[6 - dotIndex + i]);
}
// 去掉空格
string result = str.ToString().Trim();
// 取消前面多余的0
for (int i = 0; i < result.Length; i++) {
if (result[i] != '0') {
result = result.Substring(i, result.Length - i);
break;
}
}
if (result.IndexOf('.') == 0) {
result = result.Insert(0, "0");
}
if (result.IndexOf('.') == result.Length - 1) {
result = result.Remove(result.IndexOf('.'), 1);
}
if (!isPositive) { // 负数
result = result.Insert(0, "-");
}
return result;
}
public override bool ParseAscii(string buf, out string weight, out bool isStatic) {
isStatic = false;
weight = FindDataFrame(buf, DataLength );
if (string.IsNullOrEmpty(weight)) {
return false;
}
weight = ParseData(weight, out isStatic);
return true;
}
public override bool ParseAscii(string buf, out string weight, out bool isStatic, out string subStr) {
weight = "";
isStatic = false;
subStr = "";
return false;
}
}
//IND560单次读入
}

+ 110
- 0
BWP.WinFormControl/WeightDataFormat/Xk3190A9DataFormat.cs View File

@ -0,0 +1,110 @@
namespace BWP.WinFormControl.WeightDataFormat
{
public class Xk3190A9DataFormat : DataFormatBase {
public override int DataLength {
get { return 12; }
}
public override char Beginchar {
get { return (char)0x02; }
}
public override char Endchar {
get { return (char)0x03; ; }
}
public override short Bufsize {
get { return 36; }
}
public override string ParseData(string buf, out bool isStatic) {
string weight;
// 小数位数0-4
int dot = (short)(0x0F & buf[8]);
weight = buf.Substring(2, 6).Trim();
// insert dot
weight = InsertDot(weight, dot);
isStatic = true; // 默认 为 稳定
// buffer[1] 符号位
if (buf[1] == '-') {
weight = weight.Insert(0, "-");
}
return weight;
}
public override bool ParseAscii(string buf, out string weight, out bool isStatic) {
isStatic = false;
weight = FindDataFrame(buf, DataLength );
if (string.IsNullOrEmpty(weight)) {
return false;
}
weight = ParseData(weight, out isStatic);
return true;
}
private static string InsertDot(string weight, int dotBits) {
string str = weight.TrimStart(new[] {
'0'
});
str = str.Trim();
if (dotBits > 0) {
//str = str.Insert(str.Length - dotBits, ".");
if (string.IsNullOrEmpty(str)) {
str = "0";
str = str.Insert(str.Length, ".");
for (int i = 0; i < dotBits; i++) {
str = str.Insert(str.Length, "0");
}
} else
str = str.Insert(str.Length - dotBits, ".");
}
if (str.IndexOf(".") == 0) {
str = str.Insert(0, "0");
}
return str;
}
public override bool ParseAscii(string buf, out string weight, out bool isStatic, out string subStr) {
isStatic = false;
weight = FindDataFrame(buf, DataLength , out subStr);
if (string.IsNullOrEmpty(weight)) {
return false;
}
weight = ParseData(weight, out isStatic);
return true;
}
// 根据开始字符找出 一个完整的数据帧
public string FindDataFrame(string buf, int fSize , out string subStr) {
var bufSize = buf.Length;
subStr = "";
int index = buf.IndexOf(Beginchar); // 查找开始字符的索引
if (index < 0 || (index + fSize) > bufSize) {
return string.Empty;
}
string data = buf.Substring(index, fSize);
subStr = buf.Substring(index + fSize);
// 检查结束字符
if (data[fSize - 1] != Endchar) {
return string.Empty;
}
return data;
}
}
}

+ 106
- 0
BWP.WinFormControl/WeightDataFormat/Xk3190D10DataFormat.cs View File

@ -0,0 +1,106 @@
namespace BWP.WinFormControl.WeightDataFormat
{
public class Xk3190D10DataFormat : DataFormatBase {
public override int DataLength {
get { return 12; }
}
public override char Beginchar {
get { return (char)0x02; }
}
public override char Endchar {
get { return (char)0x0D; ; }
}
public override short Bufsize
{
get { return 24; }
}
public override string ParseData(string buf, out bool isStatic) {
string weight;
// 小数位数0-4
int dot = (short)(0x0F & buf[8]);
weight = buf.Substring(2, 6).Trim();
// insert dot
weight = InsertDot(weight, dot);
isStatic = true; // 默认 为 稳定
// buffer[1] 符号位
if (buf[1] == '-') {
weight = weight.Insert(0, "-");
} else {
}
return weight;
}
public override bool ParseAscii(string buf, out string weight, out bool isStatic) {
isStatic = false;
weight = FindDataFrame(buf, DataLength);
if (string.IsNullOrEmpty(weight)) {
return false;
}
weight = ParseData(weight, out isStatic);
return true;
}
private static string InsertDot(string weight, int dotBits) {
string str = weight.TrimStart(new[] {
'0'
});
str = str.Trim();
if (dotBits > 0) {
//str = str.Insert(str.Length - dotBits, ".");
if (string.IsNullOrEmpty(str)) {
str = "0";
str = str.Insert(str.Length, ".");
for (int i = 0; i < dotBits; i++) {
str = str.Insert(str.Length, "0");
}
} else
str = str.Insert(str.Length - dotBits, ".");
}
if (str.IndexOf(".") == 0) {
str = str.Insert(0, "0");
}
return str;
}
public override bool ParseAscii(string buf, out string weight, out bool isStatic, out string subStr) {
isStatic = false;
weight = FindDataFrame(buf, DataLength );
subStr = "";
if (string.IsNullOrEmpty(weight)) {
return false;
}
weight = ParseData(weight, out isStatic);
return true;
}
#region 1.3 验证int奇数偶数
/// <summary>
/// 1.3 验证int奇数偶数
/// </summary>
/// <param name="num"></param>
/// <returns></returns>
public bool isJO(int num) {
int a = num % 2;
if (a == 0)
return true;
else
return false;
}
#endregion
}
}

+ 23
- 0
BWP.WinFormControl/WinApiSendMessage.cs View File

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace BWP.WinFormControl
{
public class WinApiSendMessage
{
[DllImport("User32.dll", EntryPoint = "SendMessage")]
public static extern int SendMessage(
int hWnd, // handle to destination window
int Msg, // message
int wParam, // first message parameter
int lParam // second message parameter
);
[DllImport("User32.dll", EntryPoint = "FindWindow")]
public static extern int FindWindow(string lpClassName, string lpWindowName);
}
}

+ 3
- 0
ButcherManageClient/Login.Designer.cs View File

@ -39,6 +39,7 @@
//
// closeBtn
//
this.closeBtn.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.closeBtn.Font = new System.Drawing.Font("宋体", 20F);
this.closeBtn.Location = new System.Drawing.Point(233, 211);
this.closeBtn.Name = "closeBtn";
@ -111,8 +112,10 @@
//
// Login
//
this.AcceptButton = this.loginBtn;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.closeBtn;
this.ClientSize = new System.Drawing.Size(540, 314);
this.Controls.Add(this.closeBtn);
this.Controls.Add(this.loginBtn);


+ 496
- 501
ButcherWeight/WeightForm.Designer.cs
File diff suppressed because it is too large
View File


+ 34
- 3
ButcherWeight/WeightForm.cs View File

@ -2,6 +2,7 @@
using BO.Utils;
using BO.Utils.BillRpc;
using ButcherManageClient;
using BWP.WinFormControl;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@ -41,13 +42,19 @@ namespace ButcherWeight
farmerSelect.Init("BaseInfoRpc/GetFarmerList");
farmerSelect.EnableTopItem = false;
weightTimeSelect.Date = DateTime.Now;
testTimeInput.Date = DateTime.Now;
testTimeInput.Date = null;
dmoList = WeightBillRpc.GetWeightBillList();
billGrid.AutoGenerateColumns = false;
farmerGrid.AutoGenerateColumns = false;
weightGrid.AutoGenerateColumns = false;
houseGird.AutoGenerateColumns = false;
abnormalGrid.AutoGenerateColumns = false;
weightControl.EnableCheckBox.CheckedChanged += delegate
{
readMaoBtn.Enabled = readPiBtn.Enabled = weightControl.EnableCheckBox.Checked;
};
weightControl.InitSerialPort("COM2", 9600, 8);
weightControl.TypeOfWeight = WeightType.Xk3190A9;
BindWeightBill();
}
@ -65,11 +72,17 @@ namespace ButcherWeight
private void exitBtn_Click(object sender, EventArgs e)
{
if (weightControl.EnableCheckBox.Checked)
weightControl.EnableCheckBox.Checked = false;
this.Close();
}
private void commitBtn_Click(object sender, EventArgs e)
{
if (!_details.Any())
throw new Exception("没有称重记录");
if (!_farmerDetails.Any())
throw new Exception("没有养殖户信息");
GetFromUI();
Dmo.Details.Clear();
Dmo.Details.AddRange(_details.ToList());
@ -95,12 +108,30 @@ namespace ButcherWeight
private void readMaoBtn_Click(object sender, EventArgs e)
{
var d = new WeightBill_Detail();
_details.Add(d);
d.Index = _details.Max(x => x.Index) + 1;
d.WeightBill_ID = Dmo.ID;
d.MaoWeight = weightControl.Value;
d.Weight = d.MaoWeight;
weightGrid.DataSource = null;
weightGrid.DataSource = _details;
weightGrid.Refresh();
weightControl.Clear();
}
private void readPiBtn_Click(object sender, EventArgs e)
{
if (weightGrid.SelectedRows.Count == 0)
{
MessageBox.Show("请选中过磅记录");
return;
}
var target = weightGrid.CurrentRow.DataBoundItem as WeightBill_Detail;
target.PiWeight = weightControl.Value;
target.Weight = target.MaoWeight - target.PiWeight;
weightGrid.Refresh();
weightControl.Clear();
}
private void farmerSelect_SelectedIndexChanged(object sender, EventArgs e)


Loading…
Cancel
Save