From 7cec79cfd15cf3e0f0efc3b98ec40d6f0d870dda Mon Sep 17 00:00:00 2001 From: yibo <361071264@qq.com> Date: Mon, 12 Nov 2018 08:12:00 +0800 Subject: [PATCH] Init --- .gitignore | 6 + FourComponentWeightClient.sln | 22 ++ FourComponentWeightClient/App.xaml | 265 ++++++++++++++ FourComponentWeightClient/App.xaml.cs | 31 ++ .../BL/FourComponentWeightBL.cs | 48 +++ .../BO/DiscontSetting.cs | 43 +++ .../BO/FourComponentWeight.cs | 38 +++ FourComponentWeightClient/BO/GoodsSetting.cs | 26 ++ .../DataFormat/DataFormat.cs | 70 ++++ .../DataFormat/IND560DataFormat.cs | 58 ++++ .../DataFormat/Xk3124DataFormat.cs | 121 +++++++ .../DataFormat/Xk3190A9DataFormat.cs | 136 ++++++++ .../DiscontSettingWindow.xaml | 53 +++ .../DiscontSettingWindow.xaml.cs | 87 +++++ FourComponentWeightClient/FCWeightForm.xaml | 102 ++++++ .../FCWeightForm.xaml.cs | 186 ++++++++++ .../FourComponentWeightClient.csproj | 181 ++++++++++ .../GoodsSettingWindow.xaml | 28 ++ .../GoodsSettingWindow.xaml.cs | 61 ++++ FourComponentWeightClient/MainWindow.xaml | 24 ++ FourComponentWeightClient/MainWindow.xaml.cs | 94 +++++ .../Properties/AssemblyInfo.cs | 55 +++ .../Properties/Resources.Designer.cs | 63 ++++ .../Properties/Resources.resx | 117 +++++++ .../Properties/Settings.Designer.cs | 26 ++ .../Properties/Settings.settings | 7 + FourComponentWeightClient/SettingDialog.xaml | 11 + .../SettingDialog.xaml.cs | 45 +++ FourComponentWeightClient/Utils/AppContext.cs | 51 +++ FourComponentWeightClient/Utils/Keypad.xaml | 62 ++++ .../Utils/Keypad.xaml.cs | 84 +++++ FourComponentWeightClient/Utils/LoginUtil.cs | 27 ++ .../Utils/WeightConfig.cs | 40 +++ FourComponentWeightClient/Utils/XmlUtil.cs | 47 +++ FourComponentWeightClient/WeightControl.xaml | 14 + .../WeightControl.xaml.cs | 323 ++++++++++++++++++ FourComponentWeightClient/WeightSetForm.xaml | 21 ++ .../WeightSetForm.xaml.cs | 95 ++++++ FourComponentWeightClient/app.config | 3 + FourComponentWeightClient/images/login.png | Bin 0 -> 163568 bytes FourComponentWeightClient/images/setting.png | Bin 0 -> 1531 bytes 41 files changed, 2771 insertions(+) create mode 100644 .gitignore create mode 100644 FourComponentWeightClient.sln create mode 100644 FourComponentWeightClient/App.xaml create mode 100644 FourComponentWeightClient/App.xaml.cs create mode 100644 FourComponentWeightClient/BL/FourComponentWeightBL.cs create mode 100644 FourComponentWeightClient/BO/DiscontSetting.cs create mode 100644 FourComponentWeightClient/BO/FourComponentWeight.cs create mode 100644 FourComponentWeightClient/BO/GoodsSetting.cs create mode 100644 FourComponentWeightClient/DataFormat/DataFormat.cs create mode 100644 FourComponentWeightClient/DataFormat/IND560DataFormat.cs create mode 100644 FourComponentWeightClient/DataFormat/Xk3124DataFormat.cs create mode 100644 FourComponentWeightClient/DataFormat/Xk3190A9DataFormat.cs create mode 100644 FourComponentWeightClient/DiscontSettingWindow.xaml create mode 100644 FourComponentWeightClient/DiscontSettingWindow.xaml.cs create mode 100644 FourComponentWeightClient/FCWeightForm.xaml create mode 100644 FourComponentWeightClient/FCWeightForm.xaml.cs create mode 100644 FourComponentWeightClient/FourComponentWeightClient.csproj create mode 100644 FourComponentWeightClient/GoodsSettingWindow.xaml create mode 100644 FourComponentWeightClient/GoodsSettingWindow.xaml.cs create mode 100644 FourComponentWeightClient/MainWindow.xaml create mode 100644 FourComponentWeightClient/MainWindow.xaml.cs create mode 100644 FourComponentWeightClient/Properties/AssemblyInfo.cs create mode 100644 FourComponentWeightClient/Properties/Resources.Designer.cs create mode 100644 FourComponentWeightClient/Properties/Resources.resx create mode 100644 FourComponentWeightClient/Properties/Settings.Designer.cs create mode 100644 FourComponentWeightClient/Properties/Settings.settings create mode 100644 FourComponentWeightClient/SettingDialog.xaml create mode 100644 FourComponentWeightClient/SettingDialog.xaml.cs create mode 100644 FourComponentWeightClient/Utils/AppContext.cs create mode 100644 FourComponentWeightClient/Utils/Keypad.xaml create mode 100644 FourComponentWeightClient/Utils/Keypad.xaml.cs create mode 100644 FourComponentWeightClient/Utils/LoginUtil.cs create mode 100644 FourComponentWeightClient/Utils/WeightConfig.cs create mode 100644 FourComponentWeightClient/Utils/XmlUtil.cs create mode 100644 FourComponentWeightClient/WeightControl.xaml create mode 100644 FourComponentWeightClient/WeightControl.xaml.cs create mode 100644 FourComponentWeightClient/WeightSetForm.xaml create mode 100644 FourComponentWeightClient/WeightSetForm.xaml.cs create mode 100644 FourComponentWeightClient/app.config create mode 100644 FourComponentWeightClient/images/login.png create mode 100644 FourComponentWeightClient/images/setting.png 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 @@ + + + + + + + + + + + + + + + + +