commit 7cec79cfd15cf3e0f0efc3b98ec40d6f0d870dda
Author: yibo <361071264@qq.com>
Date: Mon Nov 12 08:12:00 2018 +0800
Init
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..f83ed3c
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,6 @@
+.*
+*.TMP
+*.suo
+*.user
+obj
+bin
diff --git a/FourComponentWeightClient.sln b/FourComponentWeightClient.sln
new file mode 100644
index 0000000..cc364cb
--- /dev/null
+++ b/FourComponentWeightClient.sln
@@ -0,0 +1,22 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 2013
+VisualStudioVersion = 12.0.40629.0
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FourComponentWeightClient", "FourComponentWeightClient\FourComponentWeightClient.csproj", "{51E5F43A-248E-4956-A819-9626FCB669D5}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {51E5F43A-248E-4956-A819-9626FCB669D5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {51E5F43A-248E-4956-A819-9626FCB669D5}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {51E5F43A-248E-4956-A819-9626FCB669D5}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {51E5F43A-248E-4956-A819-9626FCB669D5}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
diff --git a/FourComponentWeightClient/App.xaml b/FourComponentWeightClient/App.xaml
new file mode 100644
index 0000000..9ac300e
--- /dev/null
+++ b/FourComponentWeightClient/App.xaml
@@ -0,0 +1,265 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/FourComponentWeightClient/App.xaml.cs b/FourComponentWeightClient/App.xaml.cs
new file mode 100644
index 0000000..eadfd8a
--- /dev/null
+++ b/FourComponentWeightClient/App.xaml.cs
@@ -0,0 +1,31 @@
+using System;
+using System.Collections.Generic;
+using System.Configuration;
+using System.Data;
+using System.Linq;
+using System.Windows;
+
+namespace FourComponentWeightClient
+{
+ ///
+ /// App.xaml 的交互逻辑
+ ///
+ public partial class App : Application
+ {
+ public App()
+ {
+ //处理程序中未捕获的异常
+ DispatcherUnhandledException += App_DispatcherUnhandledException;
+ }
+
+ private void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
+ {
+ var msg = e.Exception.Message;
+#if DEBUG
+ msg = e.Exception.ToString();
+#endif
+ MessageBox.Show(msg, "错误", MessageBoxButton.OK, MessageBoxImage.Error);
+ e.Handled = true;
+ }
+ }
+}
diff --git a/FourComponentWeightClient/BL/FourComponentWeightBL.cs b/FourComponentWeightClient/BL/FourComponentWeightBL.cs
new file mode 100644
index 0000000..473367c
--- /dev/null
+++ b/FourComponentWeightClient/BL/FourComponentWeightBL.cs
@@ -0,0 +1,48 @@
+using Forks.JsonRpc.Client;
+using FourComponentWeightClient.BO;
+using Newtonsoft.Json;
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace FourComponentWeightClient.BL
+{
+ public static class FourComponentWeightBL
+ {
+ public static ObservableCollection LoadList(DateTime date)
+ {
+ var json = RpcFacade.Call("/MainSystem/B3DaHongMen/Rpcs/FourComponentWeightRpc/GetList", date);
+ var list = JsonConvert.DeserializeObject>(json);
+ var idx = list.Count;
+ foreach (var item in list)
+ {
+ item.RowIdx = idx;
+ idx--;
+ }
+ return new ObservableCollection(list);
+ }
+
+ public static void Insert(FourComponentWeight detail)
+ {
+ detail.ID = RpcFacade.Call("/MainSystem/B3DaHongMen/Rpcs/FourComponentWeightRpc/Insert", JsonConvert.SerializeObject(detail));
+ }
+
+ public static void FillDiaoPaiNumber(long id, int diaoPai)
+ {
+ RpcFacade.Call("/MainSystem/B3DaHongMen/Rpcs/FourComponentWeightRpc/FillDiaoPai", id, diaoPai);
+ }
+
+ public static void UpdateDiscont(long id, decimal discont)
+ {
+ RpcFacade.Call("/MainSystem/B3DaHongMen/Rpcs/FourComponentWeightRpc/UpdateDiscont", id, discont);
+ }
+
+ public static void DeleteItem(long id)
+ {
+ RpcFacade.Call("/MainSystem/B3DaHongMen/Rpcs/FourComponentWeightRpc/DeleteRecord", id);
+ }
+ }
+}
diff --git a/FourComponentWeightClient/BO/DiscontSetting.cs b/FourComponentWeightClient/BO/DiscontSetting.cs
new file mode 100644
index 0000000..bf28cde
--- /dev/null
+++ b/FourComponentWeightClient/BO/DiscontSetting.cs
@@ -0,0 +1,43 @@
+using FourComponentWeightClient.Utils;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Xml.Serialization;
+
+namespace FourComponentWeightClient.BO
+{
+ public class DiscontSetting : INotifyPropertyChanged
+ {
+ public string Name { get; set; }
+
+ public decimal Weight { get; set; }
+
+ [XmlIgnore]
+ public int Number { get; set; }
+
+ [XmlIgnore]
+ public decimal TotalWeight { get { return Weight * Number; } }
+
+ public static List Load()
+ {
+ return XmlUtil.DeserializeFromFile>("Config\\DiscontSetting.xml");
+ }
+
+ public static void Save(List list)
+ {
+ XmlUtil.SerializerObjToFile(list, "Config\\DiscontSetting.xml");
+ }
+
+ public event PropertyChangedEventHandler PropertyChanged;
+ public void Change(params string[] fields)
+ {
+ if (this.PropertyChanged == null)
+ return;
+ foreach (var item in fields)
+ this.PropertyChanged(this, new PropertyChangedEventArgs(item));
+ }
+ }
+}
diff --git a/FourComponentWeightClient/BO/FourComponentWeight.cs b/FourComponentWeightClient/BO/FourComponentWeight.cs
new file mode 100644
index 0000000..a703885
--- /dev/null
+++ b/FourComponentWeightClient/BO/FourComponentWeight.cs
@@ -0,0 +1,38 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace FourComponentWeightClient.BO
+{
+ public class FourComponentWeight : INotifyPropertyChanged
+ {
+ public long ID { get; set; }
+
+ public int RowIdx { get; set; }
+
+ public int? DiaoPaiNum { get; set; }
+
+ public decimal? Weight { get; set; }
+
+ public decimal? Discont { get; set; }
+
+ public decimal? NetWeight { get { return Weight - Discont; } }
+ public int Type { get; set; }
+ public DateTime? Date { get; set; }
+ public long Goods_ID { get; set; }
+
+ public string Goods_Name { get; set; }
+
+ public event PropertyChangedEventHandler PropertyChanged;
+ public void Change(params string[] fields)
+ {
+ if (this.PropertyChanged == null)
+ return;
+ foreach (var item in fields)
+ this.PropertyChanged(this, new PropertyChangedEventArgs(item));
+ }
+ }
+}
diff --git a/FourComponentWeightClient/BO/GoodsSetting.cs b/FourComponentWeightClient/BO/GoodsSetting.cs
new file mode 100644
index 0000000..9b22eb3
--- /dev/null
+++ b/FourComponentWeightClient/BO/GoodsSetting.cs
@@ -0,0 +1,26 @@
+using FourComponentWeightClient.Utils;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace FourComponentWeightClient.BO
+{
+ public class GoodsSetting
+ {
+ public long Goods_ID { get; set; }
+
+ public int Type { get; set; }
+
+ public static List Load()
+ {
+ return XmlUtil.DeserializeFromFile>("Config\\GoodsSetting.xml");
+ }
+
+ public static void Save(List list)
+ {
+ XmlUtil.SerializerObjToFile(list, "Config\\GoodsSetting.xml");
+ }
+ }
+}
diff --git a/FourComponentWeightClient/DataFormat/DataFormat.cs b/FourComponentWeightClient/DataFormat/DataFormat.cs
new file mode 100644
index 0000000..cd9581f
--- /dev/null
+++ b/FourComponentWeightClient/DataFormat/DataFormat.cs
@@ -0,0 +1,70 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace FourComponentWeightClient.DataFormat
+{
+ 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);
+ }
+
+ internal 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);
+ }
+}
diff --git a/FourComponentWeightClient/DataFormat/IND560DataFormat.cs b/FourComponentWeightClient/DataFormat/IND560DataFormat.cs
new file mode 100644
index 0000000..00342fd
--- /dev/null
+++ b/FourComponentWeightClient/DataFormat/IND560DataFormat.cs
@@ -0,0 +1,58 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace FourComponentWeightClient.DataFormat
+{
+ internal 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)0x67; }
+ }
+
+ public override short Bufsize
+ {
+ get { return 36; }
+ }
+ 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).Replace((char)0x3F, (char)0x20);
+ weight = weight.Trim();
+ if (weight.Any(x => x == ' '))
+ {
+ var arr = weight.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
+ if (arr.Length > 1)
+ weight = arr[1];
+ }
+ return true;
+ }
+
+ public override bool ParseAscii(string buf, out string weight, out bool isStatic, out string subStr)
+ {
+ weight = "";
+ isStatic = false;
+ subStr = "";
+ return false;
+ }
+ }
+}
diff --git a/FourComponentWeightClient/DataFormat/Xk3124DataFormat.cs b/FourComponentWeightClient/DataFormat/Xk3124DataFormat.cs
new file mode 100644
index 0000000..3637e75
--- /dev/null
+++ b/FourComponentWeightClient/DataFormat/Xk3124DataFormat.cs
@@ -0,0 +1,121 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace FourComponentWeightClient.DataFormat
+{
+ internal 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;
+ }
+ }
+}
diff --git a/FourComponentWeightClient/DataFormat/Xk3190A9DataFormat.cs b/FourComponentWeightClient/DataFormat/Xk3190A9DataFormat.cs
new file mode 100644
index 0000000..63f8a35
--- /dev/null
+++ b/FourComponentWeightClient/DataFormat/Xk3190A9DataFormat.cs
@@ -0,0 +1,136 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace FourComponentWeightClient.DataFormat
+{
+ internal 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;
+ }
+ }
+}
diff --git a/FourComponentWeightClient/DiscontSettingWindow.xaml b/FourComponentWeightClient/DiscontSettingWindow.xaml
new file mode 100644
index 0000000..93ebaf4
--- /dev/null
+++ b/FourComponentWeightClient/DiscontSettingWindow.xaml
@@ -0,0 +1,53 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/FourComponentWeightClient/DiscontSettingWindow.xaml.cs b/FourComponentWeightClient/DiscontSettingWindow.xaml.cs
new file mode 100644
index 0000000..c1650bc
--- /dev/null
+++ b/FourComponentWeightClient/DiscontSettingWindow.xaml.cs
@@ -0,0 +1,87 @@
+using FourComponentWeightClient.BO;
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+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.Shapes;
+
+namespace FourComponentWeightClient
+{
+ ///
+ /// DiscontSettingWindow.xaml 的交互逻辑
+ ///
+ public partial class DiscontSettingWindow : Window
+ {
+ ObservableCollection list;
+ public DiscontSettingWindow()
+ {
+ InitializeComponent();
+ list = new ObservableCollection(DiscontSetting.Load());
+ discontGrid.ItemsSource = list;
+ }
+
+ private void saveBtn_Click(object sender, RoutedEventArgs e)
+ {
+ DiscontSetting.Save(list.ToList());
+ MessageBox.Show("保存成功!");
+ }
+
+ private void delBtn_Click(object sender, RoutedEventArgs e)
+ {
+ var item = discontGrid.SelectedItem as DiscontSetting;
+ if (MessageBox.Show(string.Format("确定删除选{0}?", item.Name), "删除确认", MessageBoxButton.OKCancel, MessageBoxImage.Question) == MessageBoxResult.OK)
+ {
+ list.Remove(item);
+ }
+ }
+
+ private void addBtn_Click(object sender, RoutedEventArgs e)
+ {
+ if (string.IsNullOrEmpty(itemName.Text))
+ throw new Exception("扣重项不能为空");
+ if (list.Any(x => x.Name == itemName.Text))
+ throw new Exception("重复添加项");
+ if (string.IsNullOrEmpty(itemValue.Text))
+ throw new Exception("标准值不能为空");
+ var item = new DiscontSetting { Name = itemName.Text, Weight = decimal.Parse(itemValue.Text) };
+ if (item.Weight <= 0)
+ throw new Exception("标准值不合法");
+ list.Add(item);
+ }
+
+ private void upBtn_Click(object sender, RoutedEventArgs e)
+ {
+ var item = discontGrid.SelectedItem as DiscontSetting;
+ ExChangeOrder(item, true);
+ }
+
+ private void downBtn_Click(object sender, RoutedEventArgs e)
+ {
+ var item = discontGrid.SelectedItem as DiscontSetting;
+ ExChangeOrder(item, false);
+ }
+
+ void ExChangeOrder(DiscontSetting current, bool up)
+ {
+ var idx = list.IndexOf(current);
+ if (up && idx == 0)
+ return;
+ if (!up && idx == list.Count - 1)
+ return;
+
+ var nIdx = idx + (up ? -1 : 1);
+ var change = list[nIdx];
+ list[nIdx] = current;
+ list[idx] = change;
+ }
+ }
+}
diff --git a/FourComponentWeightClient/FCWeightForm.xaml b/FourComponentWeightClient/FCWeightForm.xaml
new file mode 100644
index 0000000..ddbface
--- /dev/null
+++ b/FourComponentWeightClient/FCWeightForm.xaml
@@ -0,0 +1,102 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/FourComponentWeightClient/FCWeightForm.xaml.cs b/FourComponentWeightClient/FCWeightForm.xaml.cs
new file mode 100644
index 0000000..f183821
--- /dev/null
+++ b/FourComponentWeightClient/FCWeightForm.xaml.cs
@@ -0,0 +1,186 @@
+using FourComponentWeightClient.BL;
+using FourComponentWeightClient.BO;
+using FourComponentWeightClient.Utils;
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+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.Shapes;
+
+namespace FourComponentWeightClient
+{
+ ///
+ /// FCWeightForm.xaml 的交互逻辑
+ ///
+ public partial class FCWeightForm : Window
+ {
+
+ ObservableCollection discontList;
+ ObservableCollection weightList;
+ public FCWeightForm()
+ {
+ InitializeComponent();
+ datePicker.SelectedDate = DateTime.Today;
+ BindGoodsBtns();
+ BindDiscontItems();
+ weightList = new ObservableCollection();
+ }
+
+ DataGridRow focusRow;
+ void Item_GotFocus(object sender, MouseButtonEventArgs e)
+ {
+ focusRow = sender as DataGridRow;
+ }
+
+ void diaoPaiCell_PreviewMouseDown(object sender, MouseButtonEventArgs e)
+ {
+ var keyPad = new Keypad(this);
+ if (keyPad.ShowDialog() == true)
+ {
+ int num = 0;
+ if (int.TryParse(keyPad.Result, out num))
+ {
+ var entity = focusRow.Item as FourComponentWeight;
+ FourComponentWeightBL.FillDiaoPaiNumber(entity.ID, num);
+ entity.DiaoPaiNum = num;
+ entity.Change("DiaoPaiNum");
+ }
+ else
+ throw new Exception("输入吊牌号不正确");
+ }
+ }
+
+ string[] gNames = new string[] { "牛肩", "牛前", "牛后" };
+ void BindGoodsBtns()
+ {
+ goodsPanel.Children.Clear();
+ var list = GoodsSetting.Load();
+ if (list.Any(x => x.Goods_ID != 0))
+ {
+ for (var i = 0; i < gNames.Length; i++)
+ {
+ var btn = new Button { Content = gNames[i], Tag = list[i], Margin = new Thickness(25), Width = 115, Height = 60 };
+ btn.Click += btn_Click;
+ goodsPanel.Children.Add(btn);
+ }
+ }
+ }
+
+ void btn_Click(object sender, RoutedEventArgs e)
+ {
+ if (weightCtl.Weight == 0)
+ throw new Exception("重量不能为0");
+ var btn = sender as Button;
+ var tag = btn.Tag as GoodsSetting;
+ var detail = new FourComponentWeight();
+ if (weightList.Any())
+ detail.RowIdx = weightList[0].RowIdx + 1;
+ else
+ detail.RowIdx = 1;
+ detail.Date = datePicker.SelectedDate.Value;
+ detail.Weight = weightCtl.Weight;
+ detail.Discont = Convert.ToDecimal(totalDiscontLbl.Text);
+ detail.Goods_Name = btn.Content.ToString();
+ detail.Goods_ID = tag.Goods_ID;
+ detail.Type = tag.Type;
+ FourComponentWeightBL.Insert(detail);
+ weightList.Insert(0, detail);
+ ResetDiscont();
+ }
+
+ void BindDiscontItems()
+ {
+ discontList = new ObservableCollection(DiscontSetting.Load());
+ discontGrid.ItemsSource = discontList;
+ }
+
+ void ResetDiscont()
+ {
+ foreach (var item in discontList)
+ {
+ item.Number = 0;
+ item.Change("Number", "TotalWeight");
+ }
+ totalDiscontLbl.Text = "0";
+ }
+
+ private void subBtn_Click(object sender, RoutedEventArgs e)
+ {
+ var item = discontGrid.SelectedItem as DiscontSetting;
+ if (item.Number == 0)
+ return;
+ item.Number -= 1;
+ item.Change("Number", "TotalWeight");
+ totalDiscontLbl.Text = discontList.Sum(x => x.TotalWeight).ToString("#0.###");
+ }
+
+ private void addBtn_Click(object sender, RoutedEventArgs e)
+ {
+ var item = discontGrid.SelectedItem as DiscontSetting;
+ item.Number += 1;
+ item.Change("Number", "TotalWeight");
+ totalDiscontLbl.Text = discontList.Sum(x => x.TotalWeight).ToString("#0.###");
+ }
+
+ private void discontSetBtn_Click(object sender, RoutedEventArgs e)
+ {
+ new DiscontSettingWindow().ShowDialog();
+ BindDiscontItems();
+ ResetDiscont();
+ }
+
+ private void goodsSetBtn_Click(object sender, RoutedEventArgs e)
+ {
+ new GoodsSettingWindow().ShowDialog();
+ BindGoodsBtns();
+ }
+
+ private void queryBtn_Click(object sender, RoutedEventArgs e)
+ {
+ weightList = FourComponentWeightBL.LoadList(datePicker.SelectedDate.Value);
+ weightGrid.ItemsSource = weightList;
+ }
+
+ private void discontCell_PreviewMouseDown(object sender, MouseButtonEventArgs e)
+ {
+ var keypad = new Keypad(this);
+ if (keypad.ShowDialog() == true)
+ {
+ decimal discont;
+ if (decimal.TryParse(keypad.Result, out discont))
+ {
+ var item = focusRow.Item as FourComponentWeight;
+ FourComponentWeightBL.UpdateDiscont(item.ID, discont);
+ item.Discont = discont;
+ item.Change("Discont", "NetWeight");
+ }
+ else
+ MessageBox.Show("扣重输入不正确", "提示");
+ }
+ }
+
+ private void delBtn_Click(object sender, RoutedEventArgs e)
+ {
+ var item = focusRow.Item as FourComponentWeight;
+ if (MessageBox.Show(string.Format("确定删除选序号为{0}的明细吗?", item.RowIdx), "删除确认", MessageBoxButton.OKCancel, MessageBoxImage.Question) == MessageBoxResult.OK)
+ {
+ FourComponentWeightBL.DeleteItem(item.ID);
+ foreach (var a in weightList.Where(x => x.RowIdx > item.RowIdx))
+ {
+ a.RowIdx -= 1;
+ a.Change("RowIdx");
+ }
+ weightList.Remove(item);
+ }
+ }
+ }
+}
diff --git a/FourComponentWeightClient/FourComponentWeightClient.csproj b/FourComponentWeightClient/FourComponentWeightClient.csproj
new file mode 100644
index 0000000..65002c2
--- /dev/null
+++ b/FourComponentWeightClient/FourComponentWeightClient.csproj
@@ -0,0 +1,181 @@
+
+
+
+
+ Debug
+ AnyCPU
+ {51E5F43A-248E-4956-A819-9626FCB669D5}
+ WinExe
+ Properties
+ FourComponentWeightClient
+ FourComponentWeightClient
+ v4.5
+ 512
+ {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
+ 4
+
+
+
+ AnyCPU
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+ false
+
+
+ AnyCPU
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+ false
+
+
+
+ False
+ ..\..\..\..\..\..\..\BwpB3Project\tsref\release\Forks.JsonRpc.Client.dll
+
+
+ False
+ ..\..\..\..\..\..\..\BwpB3Project\tsref\release\Newtonsoft.Json.dll
+
+
+
+
+
+
+
+
+
+ 4.0
+
+
+
+
+
+
+
+ MSBuild:Compile
+ Designer
+
+
+
+
+
+
+
+
+ DiscontSettingWindow.xaml
+
+
+ GoodsSettingWindow.xaml
+
+
+
+
+
+ FCWeightForm.xaml
+
+
+ SettingDialog.xaml
+
+
+
+ Keypad.xaml
+
+
+
+
+ WeightControl.xaml
+
+
+ WeightSetForm.xaml
+
+
+ Designer
+ MSBuild:Compile
+
+
+ Designer
+ MSBuild:Compile
+
+
+ Designer
+ MSBuild:Compile
+
+
+ MSBuild:Compile
+ Designer
+
+
+ App.xaml
+ Code
+
+
+ MainWindow.xaml
+ Code
+
+
+ Designer
+ MSBuild:Compile
+
+
+ Designer
+ MSBuild:Compile
+
+
+ Designer
+ MSBuild:Compile
+
+
+ Designer
+ MSBuild:Compile
+
+
+
+
+ Code
+
+
+ True
+ True
+ Resources.resx
+
+
+ True
+ Settings.settings
+ True
+
+
+ ResXFileCodeGenerator
+ Resources.Designer.cs
+
+
+
+ SettingsSingleFileGenerator
+ Settings.Designer.cs
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/FourComponentWeightClient/GoodsSettingWindow.xaml b/FourComponentWeightClient/GoodsSettingWindow.xaml
new file mode 100644
index 0000000..898cb6f
--- /dev/null
+++ b/FourComponentWeightClient/GoodsSettingWindow.xaml
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/FourComponentWeightClient/GoodsSettingWindow.xaml.cs b/FourComponentWeightClient/GoodsSettingWindow.xaml.cs
new file mode 100644
index 0000000..fcc07ff
--- /dev/null
+++ b/FourComponentWeightClient/GoodsSettingWindow.xaml.cs
@@ -0,0 +1,61 @@
+using FourComponentWeightClient.BO;
+using FourComponentWeightClient.Utils;
+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.Shapes;
+
+namespace FourComponentWeightClient
+{
+ ///
+ /// GoodsSettingWindow.xaml 的交互逻辑
+ ///
+ public partial class GoodsSettingWindow : Window
+ {
+ List list;
+ List ctls;
+ public GoodsSettingWindow()
+ {
+ InitializeComponent();
+ ctls = new List { nj, nq, nh };
+ list = GoodsSetting.Load();
+ if (list.Count == 0)
+ {
+ for (var i = 0; i < ctls.Count;i++ )
+ list.Add(new GoodsSetting() { Type = i });
+ }
+ for (var i = 0; i < ctls.Count; i++)
+ {
+ ctls[i].Text = list[i].Goods_ID.ToString();
+ ctls[i].PreviewMouseDown += nj_PreviewMouseDown;
+ }
+ }
+
+ void nj_PreviewMouseDown(object sender, MouseButtonEventArgs e)
+ {
+ var pad = new Keypad(this);
+ if (pad.ShowDialog() == true)
+ (sender as TextBox).Text = pad.Result;
+ }
+
+ private void Button_Click(object sender, RoutedEventArgs e)
+ {
+ for (var i = 0; i < ctls.Count;i++ )
+ list[i].Goods_ID = long.Parse(ctls[i].Text);
+
+ if (list.Any(x => x.Goods_ID == 0))
+ throw new Exception("存货ID不能设置为0");
+ GoodsSetting.Save(list);
+ MessageBox.Show("保存成功!");
+ }
+ }
+}
diff --git a/FourComponentWeightClient/MainWindow.xaml b/FourComponentWeightClient/MainWindow.xaml
new file mode 100644
index 0000000..71a0bdd
--- /dev/null
+++ b/FourComponentWeightClient/MainWindow.xaml
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/FourComponentWeightClient/MainWindow.xaml.cs b/FourComponentWeightClient/MainWindow.xaml.cs
new file mode 100644
index 0000000..40466f0
--- /dev/null
+++ b/FourComponentWeightClient/MainWindow.xaml.cs
@@ -0,0 +1,94 @@
+using FourComponentWeightClient.Utils;
+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 FourComponentWeightClient
+{
+ ///
+ /// MainWindow.xaml 的交互逻辑
+ ///
+ public partial class MainWindow : Window
+ {
+ public MainWindow()
+ {
+ InitializeComponent();
+ }
+
+ private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
+ {
+ this.DragMove();
+ }
+
+ private async void LoginBtn_Click(object sender, RoutedEventArgs e)
+ {
+ try
+ {
+ loginBtn.IsEnabled = false;
+ var username = userNameInput.Text.Trim();
+ var pwd = pwdInput.Password;
+
+ if (string.IsNullOrEmpty(username))
+ throw new Exception("请输入用户名");
+ await Task.Factory.StartNew(() => LoginUtil.Login(username, pwd));
+
+ var window = new FCWeightForm();
+ window.Closing += delegate
+ {
+ this.Show();
+ };
+ window.Show();
+ Hide();
+ }
+ catch { throw; }
+ finally
+ {
+ loginBtn.IsEnabled = true;
+ }
+ }
+
+ private void ExistBtn_Click(object sender, RoutedEventArgs e)
+ {
+ App.Current.Shutdown();
+ }
+
+ private void UserNameTextBoxClick(object sender, MouseButtonEventArgs e)
+ {
+ var keypad = new Keypad(this);
+ if (keypad.ShowDialog() == true)
+ {
+ if (string.IsNullOrEmpty(keypad.Result))
+ throw new Exception("请输工号");
+ userNameInput.Text = LoginUtil.GetUserNameByCode(keypad.Result);
+ }
+ }
+
+ private void PwdTextBoxClick(object sender, MouseButtonEventArgs e)
+ {
+ var keypad = new Keypad(this);
+ if (keypad.ShowDialog() == true)
+ pwdInput.Password = keypad.Result;
+ }
+
+ private void Image_PreviewMouseDown(object sender, MouseButtonEventArgs e)
+ {
+ new SettingDialog().ShowDialog();
+ }
+
+ private void Window_Loaded(object sender, RoutedEventArgs e)
+ {
+ userNameInput.Text = AppContext.Instance.UserName;
+ }
+ }
+}
diff --git a/FourComponentWeightClient/Properties/AssemblyInfo.cs b/FourComponentWeightClient/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..6130ce3
--- /dev/null
+++ b/FourComponentWeightClient/Properties/AssemblyInfo.cs
@@ -0,0 +1,55 @@
+using System.Reflection;
+using System.Resources;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using System.Windows;
+
+// 有关程序集的常规信息通过以下
+// 特性集控制。更改这些特性值可修改
+// 与程序集关联的信息。
+[assembly: AssemblyTitle("FourComponentWeightClient")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("FourComponentWeightClient")]
+[assembly: AssemblyCopyright("Copyright © 2018")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// 将 ComVisible 设置为 false 使此程序集中的类型
+// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型,
+// 则将该类型上的 ComVisible 特性设置为 true。
+[assembly: ComVisible(false)]
+
+//若要开始生成可本地化的应用程序,请在
+// 中的 .csproj 文件中
+//设置 CultureYouAreCodingWith。 例如,如果您在源文件中
+//使用的是美国英语,请将 设置为 en-US。 然后取消
+//对以下 NeutralResourceLanguage 特性的注释。 更新
+//以下行中的“en-US”以匹配项目文件中的 UICulture 设置。
+
+//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
+
+
+[assembly: ThemeInfo(
+ ResourceDictionaryLocation.None, //主题特定资源词典所处位置
+ //(在页面或应用程序资源词典中
+ // 未找到某个资源的情况下使用)
+ ResourceDictionaryLocation.SourceAssembly //常规资源词典所处位置
+ //(在页面、应用程序或任何主题特定资源词典中
+ // 未找到某个资源的情况下使用)
+)]
+
+
+// 程序集的版本信息由下面四个值组成:
+//
+// 主版本
+// 次版本
+// 生成号
+// 修订号
+//
+// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
+// 方法是按如下所示使用“*”:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/FourComponentWeightClient/Properties/Resources.Designer.cs b/FourComponentWeightClient/Properties/Resources.Designer.cs
new file mode 100644
index 0000000..4aa1be3
--- /dev/null
+++ b/FourComponentWeightClient/Properties/Resources.Designer.cs
@@ -0,0 +1,63 @@
+//------------------------------------------------------------------------------
+//
+// 此代码由工具生成。
+// 运行时版本:4.0.30319.42000
+//
+// 对此文件的更改可能会导致不正确的行为,并且如果
+// 重新生成代码,这些更改将会丢失。
+//
+//------------------------------------------------------------------------------
+
+namespace FourComponentWeightClient.Properties {
+ using System;
+
+
+ ///
+ /// 一个强类型的资源类,用于查找本地化的字符串等。
+ ///
+ // 此类是由 StronglyTypedResourceBuilder
+ // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
+ // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
+ // (以 /str 作为命令选项),或重新生成 VS 项目。
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+ internal class Resources {
+
+ private static global::System.Resources.ResourceManager resourceMan;
+
+ private static global::System.Globalization.CultureInfo resourceCulture;
+
+ [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
+ internal Resources() {
+ }
+
+ ///
+ /// 返回此类使用的缓存的 ResourceManager 实例。
+ ///
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Resources.ResourceManager ResourceManager {
+ get {
+ if (object.ReferenceEquals(resourceMan, null)) {
+ global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("FourComponentWeightClient.Properties.Resources", typeof(Resources).Assembly);
+ resourceMan = temp;
+ }
+ return resourceMan;
+ }
+ }
+
+ ///
+ /// 使用此强类型资源类,为所有资源查找
+ /// 重写当前线程的 CurrentUICulture 属性。
+ ///
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Globalization.CultureInfo Culture {
+ get {
+ return resourceCulture;
+ }
+ set {
+ resourceCulture = value;
+ }
+ }
+ }
+}
diff --git a/FourComponentWeightClient/Properties/Resources.resx b/FourComponentWeightClient/Properties/Resources.resx
new file mode 100644
index 0000000..af7dbeb
--- /dev/null
+++ b/FourComponentWeightClient/Properties/Resources.resx
@@ -0,0 +1,117 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/FourComponentWeightClient/Properties/Settings.Designer.cs b/FourComponentWeightClient/Properties/Settings.Designer.cs
new file mode 100644
index 0000000..af03ef4
--- /dev/null
+++ b/FourComponentWeightClient/Properties/Settings.Designer.cs
@@ -0,0 +1,26 @@
+//------------------------------------------------------------------------------
+//
+// 此代码由工具生成。
+// 运行时版本:4.0.30319.42000
+//
+// 对此文件的更改可能会导致不正确的行为,并且如果
+// 重新生成代码,这些更改将会丢失。
+//
+//------------------------------------------------------------------------------
+
+namespace FourComponentWeightClient.Properties {
+
+
+ [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0")]
+ internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
+
+ private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
+
+ public static Settings Default {
+ get {
+ return defaultInstance;
+ }
+ }
+ }
+}
diff --git a/FourComponentWeightClient/Properties/Settings.settings b/FourComponentWeightClient/Properties/Settings.settings
new file mode 100644
index 0000000..033d7a5
--- /dev/null
+++ b/FourComponentWeightClient/Properties/Settings.settings
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/FourComponentWeightClient/SettingDialog.xaml b/FourComponentWeightClient/SettingDialog.xaml
new file mode 100644
index 0000000..c710831
--- /dev/null
+++ b/FourComponentWeightClient/SettingDialog.xaml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
diff --git a/FourComponentWeightClient/SettingDialog.xaml.cs b/FourComponentWeightClient/SettingDialog.xaml.cs
new file mode 100644
index 0000000..14e828f
--- /dev/null
+++ b/FourComponentWeightClient/SettingDialog.xaml.cs
@@ -0,0 +1,45 @@
+using Forks.JsonRpc.Client;
+using FourComponentWeightClient.Utils;
+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.Shapes;
+
+namespace FourComponentWeightClient
+{
+ ///
+ /// SettingDialog.xaml 的交互逻辑
+ ///
+ public partial class SettingDialog : Window
+ {
+ public SettingDialog()
+ {
+ InitializeComponent();
+ urlBox.Text = AppContext.Instance.Url;
+ }
+
+ private void Button_Click(object sender, RoutedEventArgs e)
+ {
+ if (string.IsNullOrEmpty(urlBox.Text))
+ throw new Exception("服务器地址不能为空");
+ AppContext.Instance.Url = urlBox.Text;
+ XmlUtil.SerializerObjToFile(AppContext.Instance);
+ AppContext.ReInitRpc();
+ MessageBox.Show("保存成功!");
+ }
+
+ private void urlBox_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
+ {
+
+ }
+ }
+}
diff --git a/FourComponentWeightClient/Utils/AppContext.cs b/FourComponentWeightClient/Utils/AppContext.cs
new file mode 100644
index 0000000..d1ba411
--- /dev/null
+++ b/FourComponentWeightClient/Utils/AppContext.cs
@@ -0,0 +1,51 @@
+using Forks.JsonRpc.Client;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Xml.Serialization;
+
+namespace FourComponentWeightClient.Utils
+{
+ public class AppContext
+ {
+ private static AppContext inst = null;
+ public static AppContext Instance
+ {
+ get
+ {
+ if (inst == null)
+ inst = XmlUtil.DeserializeFromFile();
+ return inst;
+ }
+ }
+
+ public string Url { get; set; }
+
+ public string UserName { get; set; }
+
+ [XmlIgnore]
+ public bool RpcInited { get; set; }
+
+ public static void ReInitRpc()
+ {
+ if (AppContext.Instance.RpcInited)
+ RpcFacade.ReInit(AppContext.Instance.Url);
+ else
+ {
+ RpcFacade.Init(AppContext.Instance.Url, "fourCompWeight");
+ AppContext.Instance.RpcInited = true;
+ }
+ }
+
+ public static void InitRpc()
+ {
+ if (!AppContext.Instance.RpcInited)
+ {
+ RpcFacade.Init(AppContext.Instance.Url, "fourCompWeight");
+ AppContext.Instance.RpcInited = true;
+ }
+ }
+ }
+}
diff --git a/FourComponentWeightClient/Utils/Keypad.xaml b/FourComponentWeightClient/Utils/Keypad.xaml
new file mode 100644
index 0000000..8280a3c
--- /dev/null
+++ b/FourComponentWeightClient/Utils/Keypad.xaml
@@ -0,0 +1,62 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/FourComponentWeightClient/Utils/Keypad.xaml.cs b/FourComponentWeightClient/Utils/Keypad.xaml.cs
new file mode 100644
index 0000000..7572684
--- /dev/null
+++ b/FourComponentWeightClient/Utils/Keypad.xaml.cs
@@ -0,0 +1,84 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+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.Shapes;
+
+namespace FourComponentWeightClient.Utils
+{
+ ///
+ /// Keypad.xaml 的交互逻辑
+ ///
+ public partial class Keypad : Window, INotifyPropertyChanged
+ {
+ #region Public Properties
+
+ private string _result;
+ public string Result
+ {
+ get { return _result; }
+ private set {
+ if (_result != value)
+ {
+ _result = value;
+ this.OnPropertyChanged("Result");
+ }
+ }
+ }
+
+ #endregion
+
+ public Keypad(Window owner)
+ {
+ InitializeComponent();
+ this.Owner = owner;
+ lbl.DataContext = this;
+ }
+
+ private void button_Click(object sender, RoutedEventArgs e)
+ {
+ Button button = sender as Button;
+ switch (button.CommandParameter.ToString())
+ {
+ case "ESC":
+ this.Close();
+ break;
+
+ case "RETURN":
+ this.DialogResult = true;
+ break;
+
+ case "BACK":
+ if (Result.Length > 0)
+ Result = Result.Remove(Result.Length - 1);
+ break;
+
+ default:
+ Result += button.Content.ToString();
+ break;
+ }
+ }
+
+ #region INotifyPropertyChanged members
+
+ public event PropertyChangedEventHandler PropertyChanged;
+ private void OnPropertyChanged(String info)
+ {
+ if (PropertyChanged != null)
+ {
+ PropertyChanged(this, new PropertyChangedEventArgs(info));
+ }
+ }
+
+ #endregion
+ }
+}
diff --git a/FourComponentWeightClient/Utils/LoginUtil.cs b/FourComponentWeightClient/Utils/LoginUtil.cs
new file mode 100644
index 0000000..55214bd
--- /dev/null
+++ b/FourComponentWeightClient/Utils/LoginUtil.cs
@@ -0,0 +1,27 @@
+using Forks.JsonRpc.Client;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace FourComponentWeightClient.Utils
+{
+ public static class LoginUtil
+ {
+ public static void Login(string userName, string pwd)
+ {
+ AppContext.InitRpc();
+ RpcFacade.Login(userName, pwd);
+ AppContext.Instance.UserName = userName;
+ XmlUtil.SerializerObjToFile(AppContext.Instance);
+ }
+
+ internal static string GetUserNameByCode(string code)
+ {
+ AppContext.InitRpc();
+ var method = "/MainSystem/B3CowButcherManage/Rpcs/ClientRpc/GetWpfUserName";
+ var result = RpcFacade.Call(method, code);
+ return result;
+ }
+ }
+}
diff --git a/FourComponentWeightClient/Utils/WeightConfig.cs b/FourComponentWeightClient/Utils/WeightConfig.cs
new file mode 100644
index 0000000..e5d949d
--- /dev/null
+++ b/FourComponentWeightClient/Utils/WeightConfig.cs
@@ -0,0 +1,40 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace FourComponentWeightClient.Utils
+{
+ public class WeightConfig
+ {
+ public string WeightSet { get; set; }
+
+ public string ComSet { get; set; }
+
+ public int? RateSet { get; set; }
+
+ public int? BitSet { get; set; }
+
+ public string Format { get; set; }
+
+ public decimal? Discont { get; set; }
+
+ public int WeightType { get; set; }
+
+ public decimal MinWeight { get; set; }
+
+ public decimal MaxWeight { get; set; }
+
+ public static WeightConfig Init(string flag)
+ {
+ return XmlUtil.DeserializeFromFile();
+ }
+
+ public void Save(string flag)
+ {
+ XmlUtil.SerializerObjToFile(this);
+ }
+ }
+}
diff --git a/FourComponentWeightClient/Utils/XmlUtil.cs b/FourComponentWeightClient/Utils/XmlUtil.cs
new file mode 100644
index 0000000..25a7031
--- /dev/null
+++ b/FourComponentWeightClient/Utils/XmlUtil.cs
@@ -0,0 +1,47 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Xml.Serialization;
+
+namespace FourComponentWeightClient.Utils
+{
+ public static class XmlUtil
+ {
+ static string config = "Config";
+ public static void SerializerObjToFile(object obj, string fileName = "")
+ {
+ if (string.IsNullOrWhiteSpace(fileName))
+ {
+ fileName = Path.Combine(config, obj.GetType().Name + ".xml");
+ }
+ var ser = new XmlSerializer(obj.GetType());
+ using (var stream = File.Open(fileName, FileMode.Create))
+ {
+ ser.Serialize(stream, obj);
+ }
+ }
+
+ public static T DeserializeFromFile(string fileName = "")
+ where T : new()
+ {
+ if (string.IsNullOrWhiteSpace(fileName))
+ {
+ fileName = Path.Combine(config, typeof(T).Name + ".xml");
+ }
+ if (!File.Exists(fileName))
+ {
+ return new T();
+ }
+ using (var reader = new StreamReader(fileName))
+ {
+ var xs = new XmlSerializer(typeof(T));
+ object obj = xs.Deserialize(reader);
+ reader.Close();
+ return (T)obj;
+ }
+ }
+ }
+}
diff --git a/FourComponentWeightClient/WeightControl.xaml b/FourComponentWeightClient/WeightControl.xaml
new file mode 100644
index 0000000..778e873
--- /dev/null
+++ b/FourComponentWeightClient/WeightControl.xaml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/FourComponentWeightClient/WeightControl.xaml.cs b/FourComponentWeightClient/WeightControl.xaml.cs
new file mode 100644
index 0000000..61250d3
--- /dev/null
+++ b/FourComponentWeightClient/WeightControl.xaml.cs
@@ -0,0 +1,323 @@
+using FourComponentWeightClient.DataFormat;
+using FourComponentWeightClient.Utils;
+using System;
+using System.Collections.Concurrent;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.IO.Ports;
+using System.Linq;
+using System.Text;
+using System.Threading;
+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 FourComponentWeightClient
+{
+ ///
+ /// WeightControl.xaml 的交互逻辑
+ ///
+ public partial class WeightControl : UserControl
+ {
+ WeightConfig config;
+ SerialPort weightPort;
+ IDataFormat _dataFormat;
+ Thread _inQueryThread;
+ private bool _mainProcessIsRun;
+ readonly StringBuilder _dataStrBuilder = new StringBuilder();
+ private bool switchOn;
+
+ [Browsable(true), Description("称设置标识")]
+ public string WeightFalg { get; set; }
+
+ [Browsable(true), Description("读取到值的事件")]
+ public event Action ReceivedValue;
+
+ [Browsable(false)]
+ public decimal Weight
+ {
+ get
+ {
+ var v = Convert.ToDecimal(lblChengZhong.Content);
+ if (config != null)
+ v -= (config.Discont ?? 0);
+ return v;
+ }
+ }
+
+ [Browsable(false)]
+ public bool SwitchOn
+ {
+ get
+ {
+ return switchOn;
+ }
+ }
+
+ [Browsable(false)]
+ public decimal? Discont { get { return config.Discont; } }
+
+ public WeightControl()
+ {
+ InitializeComponent();
+ this.Loaded += WeightControl_Loaded;
+ }
+
+ void WeightControl_Loaded(object sender, RoutedEventArgs e)
+ {
+ var parentWindow = Window.GetWindow(this);
+ if (parentWindow != null)
+ {
+ parentWindow.Closing += delegate
+ {
+ if (_inQueryThread != null && _inQueryThread.IsAlive)
+ {
+ DisableWeight();
+ }
+ };
+ }
+ }
+
+ private void weightSetBtn_Click(object sender, RoutedEventArgs e)
+ {
+
+ if (new WeightSetForm(WeightFalg).ShowDialog() == true)
+ config = WeightConfig.Init(WeightFalg);
+ }
+
+ private void weightSwitch_Click(object sender, RoutedEventArgs e)
+ {
+ try
+ {
+ if (config == null)
+ {
+ config = WeightConfig.Init(WeightFalg);
+ WeighAvgControl.config = config;
+ }
+ weightSetBtn.IsEnabled = switchOn;
+ switchOn = !switchOn;
+ ChangeWeightBtnState();
+ if (switchOn)
+ {
+ OpenSerialPort();
+ _mainProcessIsRun = true;
+ ReadData();
+ }
+ else
+ {
+ DisableWeight();
+ }
+ }
+ catch
+ {
+ switchOn = !switchOn;
+ weightSetBtn.IsEnabled = !switchOn;
+ ChangeWeightBtnState();
+ throw;
+ }
+ finally
+ {
+ this.Focus();
+ }
+ }
+
+ void ChangeWeightBtnState()
+ {
+ if (switchOn)
+ weightSwitch.Content = "停止称重";
+ else
+ weightSwitch.Content = "启用称重";
+ }
+
+ void OpenSerialPort()
+ {
+ if (!switchOn)
+ return;
+ if (config.RateSet == null)
+ throw new Exception("请先配置称相关信息");
+ weightPort = new SerialPort();
+ weightPort.PortName = config.ComSet;
+ weightPort.BaudRate = config.RateSet.Value;
+ weightPort.DataBits = config.BitSet.Value;
+ weightPort.ReadBufferSize = 4096 * 100;
+ if (!string.IsNullOrEmpty(config.Format))
+ format = "{0:{format}}".Replace("{format}", config.Format);
+
+ switch (config.WeightSet)
+ {
+ case "IND560":
+ _dataFormat = new IND560DataFormat();
+ break;
+ case "Xk3124":
+ case "IND231":
+ _dataFormat = new Xk3124DataFormat();
+ break;
+ case "Xk3190A9":
+ _dataFormat = new Xk3190A9DataFormat();
+ break;
+ }
+ if (!weightPort.IsOpen)
+ {
+ try
+ {
+ weightPort.Open();
+ }
+ catch (InvalidOperationException)
+ {
+ throw new Exception("指定的端口已打开");
+ }
+ catch (UnauthorizedAccessException)
+ {
+ throw new Exception("对端口的访问被拒绝");
+ }
+ }
+ }
+
+ void ReadData()
+ {
+ _inQueryThread = new Thread(InQuery);
+ _inQueryThread.Start();
+ }
+
+ string format = "{0:0.00}";
+
+ private void InQuery()
+ {
+ while (_mainProcessIsRun)
+ {
+ int availableCount = weightPort.BytesToRead;
+ if (availableCount == 0)
+ {
+ Thread.Sleep(10);
+ }
+ char[] buffer = new char[availableCount];
+ weightPort.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);
+ bool isStatic;
+ string str=string.Empty;
+ if (_dataFormat.ParseAscii(_dataStrBuilder.ToString(), out str, out isStatic))
+ {
+ if (config.WeightType == 0)
+ {
+ if (string.IsNullOrEmpty(str))
+ str = "0";
+ this.Dispatcher.Invoke(new Action(delegate()
+ {
+ decimal v = 0;
+ decimal.TryParse(str, out v);
+ lblChengZhong.Content = string.Format(format, v);
+ if (str != "0")
+ {
+ if (ReceivedValue != null)
+ ReceivedValue(v - (config.Discont ?? 0));
+ }
+ }));
+ }
+ else
+ {
+ decimal num = 0;
+ if (decimal.TryParse(str, out num))
+ {
+ this.Dispatcher.Invoke(new Action(delegate()
+ {
+ lblChengZhong.Content = string.Format(format, num);
+ }));
+ WeighAvgControl.Add(num, isStatic);
+ }
+ if (WeighAvgControl.TryGetValue(out num))
+ {
+ this.Dispatcher.Invoke(new Action(delegate()
+ {
+ if (str != "0")
+ {
+ if (ReceivedValue != null)
+ ReceivedValue(num - (config.Discont ?? 0));
+ }
+ }));
+ }
+ }
+ }
+ _dataStrBuilder.Clear();
+ }
+ else
+ {
+ _dataStrBuilder.Append(c);
+ }
+ }
+ }
+ }
+
+ private class WeighAvgControl
+ {
+ public static WeightConfig config;
+ public static bool TryGetValue(out decimal result)
+ {
+ List> list = null;
+ if (mWeighList.TryDequeue(out list))
+ {
+ var r = list.Where(x => x.Item2).Select(x => x.Item1).GroupBy(x => x);
+ var firstOrDefault = r.OrderByDescending(x => x.Count()).FirstOrDefault();
+ if (firstOrDefault != null)
+ {
+ result = firstOrDefault.Key;
+ return true;
+ }
+ result = 0;
+ return false;
+ }
+ result = 0;
+ return false;
+ }
+
+ static ConcurrentQueue>> mWeighList = new ConcurrentQueue>>();
+
+ static List> _list = new List>();
+
+ public static void Add(decimal value, bool isStatic)
+ {
+ if (value >= config.MinWeight && value <= config.MaxWeight)
+ {
+ _list.Add(new Tuple(value, isStatic));
+ }
+ else
+ {
+ if (_list.Count > 0)
+ {
+ mWeighList.Enqueue(_list);
+ _list = new List>();
+ }
+ }
+ }
+ }
+
+ void DisableWeight()
+ {
+ _mainProcessIsRun = false;
+ lblChengZhong.Content = string.Format(format, 0);
+ format = "{0:0.00}";
+ Thread.Sleep(10);
+ if (_inQueryThread.IsAlive)
+ {
+ _inQueryThread.Abort();
+ }
+ if (weightPort.IsOpen)
+ weightPort.Close();
+ }
+ }
+}
diff --git a/FourComponentWeightClient/WeightSetForm.xaml b/FourComponentWeightClient/WeightSetForm.xaml
new file mode 100644
index 0000000..c8aa8b9
--- /dev/null
+++ b/FourComponentWeightClient/WeightSetForm.xaml
@@ -0,0 +1,21 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/FourComponentWeightClient/WeightSetForm.xaml.cs b/FourComponentWeightClient/WeightSetForm.xaml.cs
new file mode 100644
index 0000000..d49c0ce
--- /dev/null
+++ b/FourComponentWeightClient/WeightSetForm.xaml.cs
@@ -0,0 +1,95 @@
+using FourComponentWeightClient.Utils;
+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.Shapes;
+
+namespace FourComponentWeightClient
+{
+ ///
+ /// WeightSetForm.xaml 的交互逻辑
+ ///
+ public partial class WeightSetForm : Window
+ {
+ List weight = new List { "IND560", "Xk3124", "Xk3190A9"};
+ List com = new List { "COM1", "COM2", "COM3", "COM4", "COM5" };
+ List rate = new List { "1200", "2400", "4800", "7200", "9600" };
+ List bit = new List { "5", "6", "7", "8" };
+ string _flag;
+ WeightConfig config;
+
+ public WeightSetForm(string flag)
+ {
+ this._flag = flag;
+ InitializeComponent();
+ weightSet.ItemsSource = weight;
+ comSet.ItemsSource = com;
+ rateSet.ItemsSource = rate;
+ bitSet.ItemsSource = bit;
+ config = WeightConfig.Init(flag);
+ if (!string.IsNullOrEmpty(config.WeightSet))
+ weightSet.SelectedIndex = weight.IndexOf(config.WeightSet);
+ else
+ weightSet.SelectedIndex = 0;
+ if (!string.IsNullOrEmpty(config.ComSet))
+ comSet.SelectedIndex = com.IndexOf(config.ComSet);
+ else
+ comSet.SelectedIndex = 0;
+ if (config.RateSet.HasValue)
+ rateSet.SelectedIndex = rate.IndexOf(config.RateSet.ToString());
+ else
+ rateSet.SelectedIndex = 2;
+ if (config.BitSet.HasValue)
+ bitSet.SelectedIndex = bit.IndexOf(config.BitSet.ToString());
+ else
+ bitSet.SelectedIndex = 3;
+ if (string.IsNullOrEmpty(config.Format))
+ format.Text = "0.00";
+ else
+ format.Text = config.Format;
+ if (config.Discont == null)
+ discont.Text = "0.00";
+ else
+ discont.Text = config.Discont.ToString();
+ }
+
+ bool changed;
+ private void saveBtn_Click(object sender, RoutedEventArgs e)
+ {
+ config.WeightSet = weight[this.weightSet.SelectedIndex];
+ config.ComSet = com[this.comSet.SelectedIndex];
+ config.RateSet = int.Parse(rate[this.rateSet.SelectedIndex]);
+ config.BitSet = int.Parse(bit[this.bitSet.SelectedIndex]);
+ config.Format = format.Text;
+ if (!string.IsNullOrEmpty(discont.Text))
+ {
+ decimal v;
+ if (decimal.TryParse(discont.Text, out v))
+ config.Discont = v;
+ else
+ throw new Exception("扣重格式输入不正确");
+ }
+ else
+ config.Discont = 0;
+ config.Save(_flag);
+ changed = true;
+ MessageBox.Show("保存成功!");
+ }
+
+ private void closeBtn_Click(object sender, RoutedEventArgs e)
+ {
+ if (changed)
+ DialogResult = true;
+ this.Close();
+ }
+ }
+}
diff --git a/FourComponentWeightClient/app.config b/FourComponentWeightClient/app.config
new file mode 100644
index 0000000..51278a4
--- /dev/null
+++ b/FourComponentWeightClient/app.config
@@ -0,0 +1,3 @@
+
+
+
diff --git a/FourComponentWeightClient/images/login.png b/FourComponentWeightClient/images/login.png
new file mode 100644
index 0000000..41e43a5
Binary files /dev/null and b/FourComponentWeightClient/images/login.png differ
diff --git a/FourComponentWeightClient/images/setting.png b/FourComponentWeightClient/images/setting.png
new file mode 100644
index 0000000..3789db2
Binary files /dev/null and b/FourComponentWeightClient/images/setting.png differ