commit dcf08ab64dad8c7dbcd7a1e6f494d36861bd3baf Author: robin Date: Mon Jun 19 10:14:22 2017 +0800 add diff --git a/BLUtil/BLUtil.csproj b/BLUtil/BLUtil.csproj new file mode 100644 index 0000000..d086a60 --- /dev/null +++ b/BLUtil/BLUtil.csproj @@ -0,0 +1,69 @@ + + + + Debug + AnyCPU + 8.0.30703 + 2.0 + {7E4543F1-5E83-40BF-B47A-29C40429EC2C} + Library + Properties + BLUtil + BLUtil + v4.0 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + False + ..\..\..\..\..\tsref\release\forks.json.dll + + + False + ..\..\..\..\..\tsref\release\Forks.JsonRpc.Client.dll + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/BLUtil/BaseInforObj.cs b/BLUtil/BaseInforObj.cs new file mode 100644 index 0000000..29d840c --- /dev/null +++ b/BLUtil/BaseInforObj.cs @@ -0,0 +1,11 @@ +namespace BLUtil +{ + public class BaseInforObj { + public long ID { get; set; } + public string Name { get; set; } + public string Code { get; set; } + public string Spell { get; set; } + public int RowVersion { get; set; } + public string Unit { get; set; } + } +} \ No newline at end of file diff --git a/BLUtil/DbUtil.cs b/BLUtil/DbUtil.cs new file mode 100644 index 0000000..c8bcdc5 --- /dev/null +++ b/BLUtil/DbUtil.cs @@ -0,0 +1,178 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.IO; +using System.Windows.Forms; +using Forks.EnterpriseServices; +using Forks.Utils.Data; + +namespace BLUtil { + public class DbUtil { + + public static string ConnectionStr = ""; + + public static object DialogReturnValue { get; set; } + + private static int _startTime = 12;//默认12点 + + private static DateTime NewToday { + get { + if (DateTime.Now.Hour >= _startTime) { + return new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, _startTime, 0, 0); + } + return new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, _startTime, 0, 0).AddDays(-1); + } + } + + private static DateTime NextNewToday { + get { return NewToday.AddHours(24); } + } + + + public static void Init() { + ConnectionStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Directory.GetCurrentDirectory() + "\\AppDb.mdb"; + } + + public static int GetSequence() { + using (var sqlUtil = DbFactory.GetSqlUtil(ConnectionStr, DbProviderType.OleDb)) { + var sql = string.Format("select top 1 Sequence from [Weight] where [DateTime] >= @P1 and [DateTime] < @P2 order by Sequence desc"); + var paramList = "@P1;@P2"; + var obj = sqlUtil.ExecuteScalar(sql, paramList , NewToday, NextNewToday); + return obj != null ? (int.Parse(obj.ToString()) + 1) : 1; + } + } + + private static string _querySql = "SELECT [ID], Sequence, [DateTime] ,Goods_ID, Goods_Name, Goods_Code, Weight, Unit FROM [Weight] where Finish = 0 order by [ID] desc"; + + public static DataSet GetWeight() { + using (var sqlUtil = DbFactory.GetSqlUtil(ConnectionStr, DbProviderType.OleDb)) { + DataSet data = null; + try { + data = sqlUtil.ExecuteSql(_querySql); + sqlUtil.Close(); + } catch (Exception ex) { + MessageBox.Show(ex.Message); + } + return data; + } + } + + public static void InsertGoods(List infos, bool clearFirst = false) { + using (var sqlUtil = DbFactory.GetSqlUtil(ConnectionStr, DbProviderType.OleDb)) { + if (clearFirst) { + var delete = "Delete FROM Goods"; + sqlUtil.ExecuteNonQuery(delete); + } + foreach (var obj in infos) { + var sql = String.Format( + "Insert into Goods([Goods_ID],[Goods_Name],[Goods_Spell],[Goods_Code],[Unit],[RowVersion]) values (@P1, @P2, @P3, @P4, @P5, @P6)"); + string paramList = "@P1;@P2;@P3;@P4;@P5;@P6"; + sqlUtil.ExecuteNonQuery(sql, paramList, obj.ID, obj.Name, obj.Spell, obj.Code, obj.Unit, obj.RowVersion); + } + sqlUtil.Commit(); + } + } + + public static List SelectGoods(string searchKey) { + var infos = new List(); + using (var sqlUtil = DbFactory.GetSqlUtil(ConnectionStr, DbProviderType.OleDb)) { + + var sql = String.Format( + "Select top 30 [Goods_ID],[Goods_Name], [Goods_Code],[Unit] From Goods Where ([Goods_Name] like @P1) or ([Goods_Spell] like @2) or ([Goods_Code] like @P3) order by [Goods_ID] "); + var paramList = "@P1;@P2;@P3;"; + using (var reader = sqlUtil.ExecuteReader(sql, paramList, "%" + searchKey + "%", "%" + searchKey + "%", "%" + searchKey + "%")) { + while (reader.Read()) { + var obj = new BaseInforObj(); + obj.ID = (int)reader["Goods_ID"]; + obj.Name = (string)reader["Goods_Name"]; + obj.Code = (string)reader["Goods_Code"]; + obj.Unit = (string)reader["Unit"]; + infos.Add(obj); + } + } + } + return infos; + } + + public static List SelectStore(string searchKey) { + var infos = new List(); + using (var sqlUtil = DbFactory.GetSqlUtil(ConnectionStr, DbProviderType.OleDb)) { + + var sql = String.Format( + "Select top 30 [Store_ID],[Store_Name] From [Store] Where ([Store_Name] like @P1) or ([Store_Spell] like @P2) order by [Store_ID] "); + var paramList = "@P1;@P2;"; + using (var reader = sqlUtil.ExecuteReader(sql, paramList, "%" + searchKey + "%", "%" + searchKey + "%")) { + while (reader.Read()) { + var obj = new BaseInforObj(); + obj.ID = (int)reader["Store_ID"]; + obj.Name = (string)reader["Store_Name"]; + infos.Add(obj); + } + } + } + return infos; + } + + public static void InsertStore(List infos) { + using (var sqlUtil = DbFactory.GetSqlUtil(ConnectionStr, DbProviderType.OleDb)) { + var delete = "Delete FROM Store"; + sqlUtil.ExecuteNonQuery(delete); + int i = 0; + foreach (var obj in infos) { + i++; + var sql = String.Format( + "Insert into Store([Store_ID],[Store_Name],[Store_Spell],[RowVersion]) values (@P1, @P2, @P3, @P4 )"); + string paramList = "@P1;@P2;@P3;@P4 "; + sqlUtil.ExecuteNonQuery(sql, paramList, obj.ID, obj.Name, obj.Spell, obj.RowVersion); + } + sqlUtil.Commit(); + } + } + + public static void InsertWeight(WeightTable bo) { + using (var sqlUtil = DbFactory.GetSqlUtil(ConnectionStr, DbProviderType.OleDb)) { + var sql = String.Format( + "Insert into Weight([Goods_ID],[Goods_Name],[Goods_Code],[Unit],[Weight],[DateTime],[Sequence],[Finish]) values (@P1, @P2, @P3, @P4 ,@P5, @P6 , @P7,0 )"); + string paramList = "@P1;@P2;@P3;@P4;@P5;@P6;@P7 "; + sqlUtil.ExecuteNonQuery(sql, paramList, bo.Goods_ID, bo.Goods_Name, bo.Goods_Code, bo.Unit, bo.Weight, bo.DateTime, bo.Sequence); + sqlUtil.Commit(); + } + } + + public void GetLogList(string conStr, string sql) { + + //using (var conn = new OleDbConnection(conStr)) { + // conn.Open(); + + // var myCommand = new OleDbCommand(sql, conn); + + // using (var reader = myCommand.ExecuteReader()) { + // while (reader.Read()) { + // var log = new FrmMain.AttLog(); + // log.EnrNo = (string)reader["EnrNo"]; + // log.DateTime = (DateTime)reader["DateTime"]; + // log.TyVerifype = (int)reader["Verify"]; + // log.ID = (int)reader["ID"]; + // log.IP = (string)reader["IP"]; + // list.Add(log); + // } + // } + // conn.Close(); + //} + //return list; + } + + //public static void UpdateState(List logs) { + // using (var conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + + // Directory.GetCurrentDirectory() + "\\AttDB.mdb")) { + // conn.Open(); + + // var sql = String.Format( + // "update AttLog set [Uploaded]=1 where [ID] in ({0})", string.Join(",", logs.Select(x => x.ID))); + // var cmd = new OleDbCommand(sql, conn); + // cmd.ExecuteNonQuery(); + // conn.Close(); + // } + //} + } +} diff --git a/BLUtil/EncodeString.cs b/BLUtil/EncodeString.cs new file mode 100644 index 0000000..cc953bd --- /dev/null +++ b/BLUtil/EncodeString.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BLUtil { + public class EncodeString { + public static string Encode(string str) { + int length = str.Length; + byte[] buffer = new byte[length]; + + int i = 0; + + foreach (char c in str) { + byte b = (byte)c; + byte tem = b; + + byte bit0 = (byte)(b & 1); + byte bit1 = (byte)((b >> 1) & 1); + byte bit2 = (byte)((b >> 2) & 1); + byte bit3 = (byte)((b >> 3) & 1); + byte bit4 = (byte)((b >> 4) & 1); + byte bit5 = (byte)((b >> 5) & 1); + byte bit6 = (byte)((b >> 6) & 1); + byte bit7 = (byte)((b >> 7) & 1); + + tem = (byte)(tem & 0); + + tem = (byte)((bit0 << 7) | tem); + tem = (byte)((bit1 << 6) | tem); + tem = (byte)((bit2 << 3) | tem); + tem = (byte)((bit3 << 2) | tem); + tem = (byte)((bit4 << 5) | tem); + tem = (byte)((bit5 << 4) | tem); + tem = (byte)((bit6 << 1) | tem); + tem = (byte)(bit7 | tem); + + buffer[i] = tem; + i++; + } + + char[] ch = new char[length]; + int j = 0; + foreach (byte b in buffer) { + ch[j] = (char)b; + j++; + } + + return new string(ch); + } + public static readonly object RwLocker = new object(); + + public static string UserName = ""; + public static string Password=""; + } +} diff --git a/BLUtil/LoginRpc.cs b/BLUtil/LoginRpc.cs new file mode 100644 index 0000000..df40473 --- /dev/null +++ b/BLUtil/LoginRpc.cs @@ -0,0 +1,60 @@ +using System; +using Forks.JsonRpc.Client; + +namespace BLUtil { + public static class RpcUtil { + + const string WpfUserMethod = "/MainSystem/B3TianJinMeatUnite/Rpcs/ClientRpc/GetWpfUserInfoByIds"; + public const string GetGoods = "/MainSystem/B3TianJinMeatUnite/Rpcs/ClientRpc/GetGoodsInfor"; + public const string GetStore = "/MainSystem/B3TianJinMeatUnite/Rpcs/ClientRpc/GetStoreInfor"; + public static string OnLineLoadNameByCode(string code, out string error) { + try { + error = string.Empty; + + return RpcFacade.Call(WpfUserMethod, code); + } catch (Exception ex) { + error = ex.ToString(); + } + return string.Empty; + } + + public static bool Login(string name, string password, out string error) { + error = string.Empty; + try { + RpcFacade.Login(name, password); + } catch (Exception e) { + error = e.Message; + return false; + } + return true; + } + + public static bool Logout(out string error) { + error = string.Empty; + try { + RpcFacade.Logout(); + } catch (Exception e) { + error = e.Message; + return false; + } + return true; + } + + + public static T Call(string relativeMethod, params object[] parameters) { + + bool logedIn; + try { + logedIn = RpcFacade.IsLogedIn; + } catch { + logedIn = false; + } + + if (!logedIn) { + RpcFacade.Login(EncodeString.UserName, EncodeString.Password); + } + + return RpcFacade.Call(relativeMethod, parameters); + } + } +} diff --git a/BLUtil/Properties/AssemblyInfo.cs b/BLUtil/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..530c6a4 --- /dev/null +++ b/BLUtil/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的常规信息通过以下 +// 特性集控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("BLUtil")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("BLUtil")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 使此程序集中的类型 +// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型, +// 则将该类型上的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("cd79bd33-a30d-4e8b-9bbb-b6c4290b9e27")] + +// 程序集的版本信息由下面四个值组成: +// +// 主版本 +// 次版本 +// 内部版本号 +// 修订号 +// +// 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/BLUtil/WeightTable.cs b/BLUtil/WeightTable.cs new file mode 100644 index 0000000..cf61c58 --- /dev/null +++ b/BLUtil/WeightTable.cs @@ -0,0 +1,29 @@ +using System; +using System.Data; +using Forks.EnterpriseServices; +using Forks.EnterpriseServices.DomainObjects2; + +namespace BLUtil +{ + [MapToTable("Weight")] + public class WeightTable { + public long ID { get; set; } + + public long Goods_ID { get; set; } + + public string Goods_Name { get; set; } + + public string Goods_Code { get; set; } + + public string Unit { get; set; } + + public decimal? Weight { get; set; } + + [LogicName("")] + [DbColumn(DbType = SqlDbType.DateTime)] + public DateTime DateTime { get; set; } + + [LogicName("˳")] + public long Sequence { get; set; } + } +} \ No newline at end of file diff --git a/BWPClientForTianRou.sln b/BWPClientForTianRou.sln new file mode 100644 index 0000000..054d92d --- /dev/null +++ b/BWPClientForTianRou.sln @@ -0,0 +1,56 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BWPClientForTianRou", "BWPClientForTianRou\BWPClientForTianRou.csproj", "{C422269D-C1F6-48B4-B26C-6FF26F2FDD46}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KeyPad", "BWPClientForTianRou\KeyPad\KeyPad.csproj", "{3ADBFF38-915C-4115-9CDD-81C0CAD9733A}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BLUtil", "BLUtil\BLUtil.csproj", "{7E4543F1-5E83-40BF-B47A-29C40429EC2C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|Mixed Platforms = Debug|Mixed Platforms + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|Mixed Platforms = Release|Mixed Platforms + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C422269D-C1F6-48B4-B26C-6FF26F2FDD46}.Debug|Any CPU.ActiveCfg = Debug|x86 + {C422269D-C1F6-48B4-B26C-6FF26F2FDD46}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {C422269D-C1F6-48B4-B26C-6FF26F2FDD46}.Debug|Mixed Platforms.Build.0 = Debug|x86 + {C422269D-C1F6-48B4-B26C-6FF26F2FDD46}.Debug|x86.ActiveCfg = Debug|x86 + {C422269D-C1F6-48B4-B26C-6FF26F2FDD46}.Debug|x86.Build.0 = Debug|x86 + {C422269D-C1F6-48B4-B26C-6FF26F2FDD46}.Release|Any CPU.ActiveCfg = Release|x86 + {C422269D-C1F6-48B4-B26C-6FF26F2FDD46}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {C422269D-C1F6-48B4-B26C-6FF26F2FDD46}.Release|Mixed Platforms.Build.0 = Release|x86 + {C422269D-C1F6-48B4-B26C-6FF26F2FDD46}.Release|x86.ActiveCfg = Release|x86 + {C422269D-C1F6-48B4-B26C-6FF26F2FDD46}.Release|x86.Build.0 = Release|x86 + {3ADBFF38-915C-4115-9CDD-81C0CAD9733A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3ADBFF38-915C-4115-9CDD-81C0CAD9733A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3ADBFF38-915C-4115-9CDD-81C0CAD9733A}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {3ADBFF38-915C-4115-9CDD-81C0CAD9733A}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {3ADBFF38-915C-4115-9CDD-81C0CAD9733A}.Debug|x86.ActiveCfg = Debug|x86 + {3ADBFF38-915C-4115-9CDD-81C0CAD9733A}.Debug|x86.Build.0 = Debug|x86 + {3ADBFF38-915C-4115-9CDD-81C0CAD9733A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3ADBFF38-915C-4115-9CDD-81C0CAD9733A}.Release|Any CPU.Build.0 = Release|Any CPU + {3ADBFF38-915C-4115-9CDD-81C0CAD9733A}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {3ADBFF38-915C-4115-9CDD-81C0CAD9733A}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {3ADBFF38-915C-4115-9CDD-81C0CAD9733A}.Release|x86.ActiveCfg = Release|x86 + {3ADBFF38-915C-4115-9CDD-81C0CAD9733A}.Release|x86.Build.0 = Release|x86 + {7E4543F1-5E83-40BF-B47A-29C40429EC2C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7E4543F1-5E83-40BF-B47A-29C40429EC2C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7E4543F1-5E83-40BF-B47A-29C40429EC2C}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {7E4543F1-5E83-40BF-B47A-29C40429EC2C}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {7E4543F1-5E83-40BF-B47A-29C40429EC2C}.Debug|x86.ActiveCfg = Debug|Any CPU + {7E4543F1-5E83-40BF-B47A-29C40429EC2C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7E4543F1-5E83-40BF-B47A-29C40429EC2C}.Release|Any CPU.Build.0 = Release|Any CPU + {7E4543F1-5E83-40BF-B47A-29C40429EC2C}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {7E4543F1-5E83-40BF-B47A-29C40429EC2C}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {7E4543F1-5E83-40BF-B47A-29C40429EC2C}.Release|x86.ActiveCfg = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/BWPClientForTianRou/App.config b/BWPClientForTianRou/App.config new file mode 100644 index 0000000..30fc7df --- /dev/null +++ b/BWPClientForTianRou/App.config @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + diff --git a/BWPClientForTianRou/AppDb.mdb b/BWPClientForTianRou/AppDb.mdb new file mode 100644 index 0000000..19bb2f9 Binary files /dev/null and b/BWPClientForTianRou/AppDb.mdb differ diff --git a/BWPClientForTianRou/AutoSizeFormClass.cs b/BWPClientForTianRou/AutoSizeFormClass.cs new file mode 100644 index 0000000..0543760 --- /dev/null +++ b/BWPClientForTianRou/AutoSizeFormClass.cs @@ -0,0 +1,111 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Windows.Forms; + +namespace BWPClientForTianRou { + class AutoSizeFormClass { + //(1).声明结构,只记录窗体和其控件的初始位置和大小。 + public struct controlRect { + public int Left; + public int Top; + public int Width; + public int Height; + } + //(2).声明 1个对象 + //注意这里不能使用控件列表记录 List nCtrl;,因为控件的关联性,记录的始终是当前的大小。 + // public List oldCtrl= new List();//这里将西文的大于小于号都过滤掉了,只能改为中文的,使用中要改回西文 + public List oldCtrl = new List(); + int ctrlNo = 0;//1; + //(3). 创建两个函数 + //(3.1)记录窗体和其控件的初始位置和大小, + public void ControllInitializeSize(Control mForm) { + controlRect cR; + cR.Left = mForm.Left; + cR.Top = mForm.Top; + cR.Width = mForm.Width; + cR.Height = mForm.Height; + oldCtrl.Add(cR);//第一个为"窗体本身",只加入一次即可 + AddControl(mForm);//窗体内其余控件还可能嵌套控件(比如panel),要单独抽出,因为要递归调用 + //this.WindowState = (System.Windows.Forms.FormWindowState)(2);//记录完控件的初始位置和大小后,再最大化 + //0 - Normalize , 1 - Minimize,2- Maximize + } + private void AddControl(Control ctl) { + foreach (Control c in ctl.Controls) { //**放在这里,是先记录控件的子控件,后记录控件本身 + //if (c.Controls.Count > 0) + // AddControl(c);//窗体内其余控件还可能嵌套控件(比如panel),要单独抽出,因为要递归调用 + controlRect objCtrl; + objCtrl.Left = c.Left; + objCtrl.Top = c.Top; + objCtrl.Width = c.Width; + objCtrl.Height = c.Height; + oldCtrl.Add(objCtrl); + //**放在这里,是先记录控件本身,后记录控件的子控件 + if (c.Controls.Count > 0) + AddControl(c);//窗体内其余控件还可能嵌套控件(比如panel),要单独抽出,因为要递归调用 + } + } + //(3.2)控件自适应大小, + public void controlAutoSize(Control mForm) { + if (ctrlNo == 0) { //*如果在窗体的Form1_Load中,记录控件原始的大小和位置,正常没有问题,但要加入皮肤就会出现问题,因为有些控件如dataGridView的的子控件还没有完成,个数少 + //*要在窗体的Form1_SizeChanged中,第一次改变大小时,记录控件原始的大小和位置,这里所有控件的子控件都已经形成 + controlRect cR; + // cR.Left = mForm.Left; cR.Top = mForm.Top; cR.Width = mForm.Width; cR.Height = mForm.Height; + cR.Left = 0; + cR.Top = 0; + cR.Width = mForm.PreferredSize.Width; + cR.Height = mForm.PreferredSize.Height; + + oldCtrl.Add(cR);//第一个为"窗体本身",只加入一次即可 + AddControl(mForm);//窗体内其余控件可能嵌套其它控件(比如panel),故单独抽出以便递归调用 + } + float wScale = (float)mForm.Width / (float)oldCtrl[0].Width;//新旧窗体之间的比例,与最早的旧窗体 + float hScale = (float)mForm.Height / (float)oldCtrl[0].Height;//.Height; + ctrlNo = 1;//进入=1,第0个为窗体本身,窗体内的控件,从序号1开始 + AutoScaleControl(mForm, wScale, hScale);//窗体内其余控件还可能嵌套控件(比如panel),要单独抽出,因为要递归调用 + } + + private void AutoScaleControl(Control ctl, float wScale, float hScale) { + int ctrLeft0, ctrTop0, ctrWidth0, ctrHeight0; + //int ctrlNo = 1;//第1个是窗体自身的 Left,Top,Width,Height,所以窗体控件从ctrlNo=1开始 + foreach (Control c in ctl.Controls) { //**放在这里,是先缩放控件的子控件,后缩放控件本身 + //if (c.Controls.Count > 0) + // AutoScaleControl(c, wScale, hScale);//窗体内其余控件还可能嵌套控件(比如panel),要单独抽出,因为要递归调用 + ctrLeft0 = oldCtrl[ctrlNo].Left; + ctrTop0 = oldCtrl[ctrlNo].Top; + ctrWidth0 = oldCtrl[ctrlNo].Width; + ctrHeight0 = oldCtrl[ctrlNo].Height; + //c.Left = (int)((ctrLeft0 - wLeft0) * wScale) + wLeft1;//新旧控件之间的线性比例 + //c.Top = (int)((ctrTop0 - wTop0) * h) + wTop1; + c.Left = (int)((ctrLeft0) * wScale);//新旧控件之间的线性比例。控件位置只相对于窗体,所以不能加 + wLeft1 + c.Top = (int)((ctrTop0) * hScale);// + c.Width = (int)(ctrWidth0 * wScale);//只与最初的大小相关,所以不能与现在的宽度相乘 (int)(c.Width * w); + c.Height = (int)(ctrHeight0 * hScale);// + ctrlNo++;//累加序号 + //**放在这里,是先缩放控件本身,后缩放控件的子控件 + if (c.Controls.Count > 0) + AutoScaleControl(c, wScale, hScale);//窗体内其余控件还可能嵌套控件(比如panel),要单独抽出,因为要递归调用 + + if (ctl is DataGridView) { + //var dgv = ctl as DataGridView; + //Cursor.Current = Cursors.WaitCursor; + + //var widths = 0; + //for (int i = 0; i < dgv.Columns.Count; i++) { + // dgv.AutoResizeColumn(i, DataGridViewAutoSizeColumnMode.AllCells); // 自动调整列宽 + // widths += dgv.Columns[i].Width; // 计算调整列后单元列的宽度和 + //} + //if (widths >= ctl.Size.Width) // 如果调整列的宽度大于设定列宽 + // dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells; // 调整列的模式 自动 + //else + // dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; // 如果小于 则填充 + + //Cursor.Current = Cursors.Default; + } + } + + + } + } +} diff --git a/BWPClientForTianRou/BWPClientForTianRou.csproj b/BWPClientForTianRou/BWPClientForTianRou.csproj new file mode 100644 index 0000000..c143ebc --- /dev/null +++ b/BWPClientForTianRou/BWPClientForTianRou.csproj @@ -0,0 +1,157 @@ + + + + Debug + x86 + 8.0.30703 + 2.0 + {C422269D-C1F6-48B4-B26C-6FF26F2FDD46} + WinExe + Properties + BWPClientForTianRou + BWPClientForTianRou + v4.0 + Client + 512 + + + x86 + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + x86 + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + False + ..\..\..\..\..\tsref\release\Forks.EnterpriseServices.dll + + + False + ..\..\..\..\..\tsref\release\forks.json.dll + + + + False + D:\Projects\tsref\release\Forks.Utils.dll + + + + + + + + + + + + + + + + + + + + + + + Form + + + SelectGoodsForm.cs + + + Form + + + FormProcessBar.cs + + + Form + + + LoginForm.cs + + + Form + + + MainForm.cs + + + + + SelectGoodsForm.cs + + + FormProcessBar.cs + + + LoginForm.cs + + + MainForm.cs + Designer + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + PreserveNewest + + + + + + + + + {7E4543F1-5E83-40BF-B47A-29C40429EC2C} + BLUtil + + + {3ADBFF38-915C-4115-9CDD-81C0CAD9733A} + KeyPad + + + + + \ No newline at end of file diff --git a/BWPClientForTianRou/Config.txt b/BWPClientForTianRou/Config.txt new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/BWPClientForTianRou/Config.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/BWPClientForTianRou/ConfigUtil.cs b/BWPClientForTianRou/ConfigUtil.cs new file mode 100644 index 0000000..f0c61ca --- /dev/null +++ b/BWPClientForTianRou/ConfigUtil.cs @@ -0,0 +1,62 @@ +using System; +using System.IO; +using System.Windows.Forms; +using Forks.Utils.IO; + +namespace BWPClientForTianRou { + public class ConfigUtil { + public static string ConfigFilePath = Application.StartupPath + "\\Config.txt"; + public static string LivestockFilePath = Application.StartupPath + "\\Livestock.txt"; + + public static void Init() { + using (TextReader reader = FS.OpenReader(ConfigFilePath, true)) { + var nutFile = NutFile.Parse(reader); + + LogFilePath = Application.StartupPath + "\\log\\" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt"; + + mStartTime = nutFile.AsInt32( StartTime, 12); + + if (string.IsNullOrEmpty(nutFile.AsString( Seconds, "1"))) { + mSeconds = 1; + } else { + mSeconds = (short)nutFile.AsInt32( Seconds, 1); + } + + mComName = nutFile.AsString( ComName, "COM1"); + mBaundRate = nutFile.AsString( BaundRate, "9600"); + mDataBits = nutFile.AsString( DataBits, "8"); + mReadType = nutFile.AsString( ReadType, "0"); + mCType = nutFile.AsString( CType, ""); + mMinWeight = nutFile.AsDecimal( MinWeight, 25m); + mMaxWeight = nutFile.AsDecimal( MaxWeight, 300m); + + } + } + public const string StartTime = "StartTime"; + public const string Seconds = "Seconds"; + public const string CType = "CType"; + public const string ComName = "ComName"; + public const string BaundRate = "BaundRate"; + public const string DataBits = "DataBits"; + public const string Assignment = "Assignment"; + public const string MinWeight = "MinWeight"; + public const string MaxWeight = "MaxWeight"; + public const string ReadType = "ReadType"; + public const string LastUser = "LastUser"; + + public static string LogFilePath; + + public static short mSeconds; + public static short BaseCount; + + public static string mComName; + public static string mBaundRate; + public static string mDataBits; + public static string mReadType; + public static string mAssignment; + public static decimal mMinWeight; + public static decimal mMaxWeight; + public static int mStartTime; + public static string mCType; + } +} diff --git a/BWPClientForTianRou/FormProcessBar.Designer.cs b/BWPClientForTianRou/FormProcessBar.Designer.cs new file mode 100644 index 0000000..4554e2c --- /dev/null +++ b/BWPClientForTianRou/FormProcessBar.Designer.cs @@ -0,0 +1,65 @@ +namespace BWPClientForTianRou { + partial class FormProcessBar { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) { + if (disposing && (components != null)) { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() { + this.label1 = new System.Windows.Forms.Label(); + this.prcBar = new System.Windows.Forms.ProgressBar(); + this.SuspendLayout(); + // + // label1 + // + this.label1.Location = new System.Drawing.Point(274, 9); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(44, 18); + this.label1.TabIndex = 2; + this.label1.Text = "0"; + this.label1.TextAlign = System.Drawing.ContentAlignment.TopCenter; + // + // prcBar + // + this.prcBar.Location = new System.Drawing.Point(1, 4); + this.prcBar.Name = "prcBar"; + this.prcBar.Size = new System.Drawing.Size(267, 28); + this.prcBar.TabIndex = 3; + // + // FormProcessBar + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(321, 38); + this.Controls.Add(this.label1); + this.Controls.Add(this.prcBar); + this.Name = "FormProcessBar"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "信息同步中,请稍后……"; + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Label label1; + private System.Windows.Forms.ProgressBar prcBar; + } +} \ No newline at end of file diff --git a/BWPClientForTianRou/FormProcessBar.cs b/BWPClientForTianRou/FormProcessBar.cs new file mode 100644 index 0000000..561d433 --- /dev/null +++ b/BWPClientForTianRou/FormProcessBar.cs @@ -0,0 +1,25 @@ +using System.Windows.Forms; + +namespace BWPClientForTianRou { + public partial class FormProcessBar : Form { + public FormProcessBar() { + InitializeComponent(); + } + + public bool Increase(int nValue) { + if (nValue > 0) { + if (prcBar.Value + nValue < prcBar.Maximum) { + prcBar.Value += nValue; + label1.Text = prcBar.Value + "/100"; + return true; + } else { + prcBar.Value = prcBar.Maximum; + label1.Text = string.Empty; + this.Close(); + return false; + } + } + return false; + } + } +} diff --git a/BWPClientForTianRou/FormProcessBar.resx b/BWPClientForTianRou/FormProcessBar.resx new file mode 100644 index 0000000..29dcb1b --- /dev/null +++ b/BWPClientForTianRou/FormProcessBar.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/BWPClientForTianRou/Image/u15.png b/BWPClientForTianRou/Image/u15.png new file mode 100644 index 0000000..a55b9ae Binary files /dev/null and b/BWPClientForTianRou/Image/u15.png differ diff --git a/BWPClientForTianRou/Image/u17.png b/BWPClientForTianRou/Image/u17.png new file mode 100644 index 0000000..a3f328d Binary files /dev/null and b/BWPClientForTianRou/Image/u17.png differ diff --git a/BWPClientForTianRou/Image/u19.png b/BWPClientForTianRou/Image/u19.png new file mode 100644 index 0000000..fc9347e Binary files /dev/null and b/BWPClientForTianRou/Image/u19.png differ diff --git a/BWPClientForTianRou/Image/u37.png b/BWPClientForTianRou/Image/u37.png new file mode 100644 index 0000000..2533129 Binary files /dev/null and b/BWPClientForTianRou/Image/u37.png differ diff --git a/BWPClientForTianRou/KeyPad.csproj b/BWPClientForTianRou/KeyPad.csproj new file mode 100644 index 0000000..9fc6e61 --- /dev/null +++ b/BWPClientForTianRou/KeyPad.csproj @@ -0,0 +1,125 @@ + + + + Debug + x86 + 8.0.30703 + 2.0 + {3ADBFF38-915C-4115-9CDD-81C0CAD9733A} + Library + Properties + KeyPad + KeyPad + v4.0 + Client + 512 + {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 4 + BwpApp + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + x86 + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + true + bin\Debug\ + DEBUG;TRACE + full + AnyCPU + prompt + MinimumRecommendedRules.ruleset + + + bin\Release\ + TRACE + true + pdbonly + AnyCPU + prompt + MinimumRecommendedRules.ruleset + + + False + False + False + FalseFalse + False + False + False + + + FalseFalse + False + False + False + + + Hardware_version.cs + + VirtualKeyboard.xaml + + + MSBuild:Compile + Designer + + + Keypad.xaml + Code + + + 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/BWPClientForTianRou/KeyPad/Converter/BoolToVisibilityConverter.cs b/BWPClientForTianRou/KeyPad/Converter/BoolToVisibilityConverter.cs new file mode 100644 index 0000000..fef428e --- /dev/null +++ b/BWPClientForTianRou/KeyPad/Converter/BoolToVisibilityConverter.cs @@ -0,0 +1,21 @@ +using System; +using System.Globalization; +using System.Windows.Data; + +namespace KeyPad.Converter +{ + class BoolToVisibilityConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if ((bool?)value == true) + return System.Windows.Visibility.Visible; + return System.Windows.Visibility.Collapsed; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/BWPClientForTianRou/KeyPad/KeyPad.csproj b/BWPClientForTianRou/KeyPad/KeyPad.csproj new file mode 100644 index 0000000..a0d7755 --- /dev/null +++ b/BWPClientForTianRou/KeyPad/KeyPad.csproj @@ -0,0 +1,148 @@ + + + + Debug + x86 + 8.0.30703 + 2.0 + {3ADBFF38-915C-4115-9CDD-81C0CAD9733A} + Library + Properties + KeyPad + KeyPad + v4.0 + Client + 512 + {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 4 + BwpApp + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + x86 + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + true + bin\Debug\ + DEBUG;TRACE + full + AnyCPU + prompt + MinimumRecommendedRules.ruleset + + + bin\Release\ + TRACE + true + pdbonly + AnyCPU + prompt + MinimumRecommendedRules.ruleset + + + + False + + + False + + + False + + + False + False + + + False + + + False + + + False + + + False + False + + + False + + + False + + + False + + + + + + VirtualKeyboard.xaml + + + MSBuild:Compile + Designer + + + Keypad.xaml + Code + + + 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/BWPClientForTianRou/KeyPad/Keypad.xaml b/BWPClientForTianRou/KeyPad/Keypad.xaml new file mode 100644 index 0000000..a7e9896 --- /dev/null +++ b/BWPClientForTianRou/KeyPad/Keypad.xaml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +