From 14a8165cfa6212d6d7698b9774a252e0e9a9c6fd Mon Sep 17 00:00:00 2001 From: robin Date: Mon, 26 Jun 2017 14:39:35 +0800 Subject: [PATCH] .. --- BLUtil/DbUtil.cs | 47 ++-- BLUtil/LoginRpc.cs | 1 + BWPClientForTianRou/AppDb.mdb | Bin 299008 -> 299008 bytes BWPClientForTianRou/ConfigUtil.cs | 3 +- BWPClientForTianRou/MainForm.Designer.cs | 117 ++++++--- BWPClientForTianRou/MainForm.cs | 235 +++++++++++++++--- .../Properties/AssemblyInfo.cs | 4 +- 7 files changed, 301 insertions(+), 106 deletions(-) diff --git a/BLUtil/DbUtil.cs b/BLUtil/DbUtil.cs index c8bcdc5..5468eb6 100644 --- a/BLUtil/DbUtil.cs +++ b/BLUtil/DbUtil.cs @@ -139,40 +139,21 @@ namespace BLUtil { } } - 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( ) { + using (var sqlUtil = DbFactory.GetSqlUtil(ConnectionStr, DbProviderType.OleDb)) { + var sql = String.Format( + "Update Weight set [Finish] = 1 where [Finish]=0"); + sqlUtil.ExecuteNonQuery(sql ); + sqlUtil.Commit(); + } } - //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(); - // } - //} + public static void Delete(object id ) { + using (var sqlUtil = DbFactory.GetSqlUtil(ConnectionStr, DbProviderType.OleDb)) { + var sql = String.Format("delete FROM [Weight] where id = {0}", id); + sqlUtil.ExecuteNonQuery(sql ); + sqlUtil.Commit(); + } + } } } diff --git a/BLUtil/LoginRpc.cs b/BLUtil/LoginRpc.cs index df40473..63c344e 100644 --- a/BLUtil/LoginRpc.cs +++ b/BLUtil/LoginRpc.cs @@ -7,6 +7,7 @@ namespace BLUtil { 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 const string InsertInStore = "/MainSystem/B3Butchery/Rpcs/ClientRpc/InsertProductInStore"; public static string OnLineLoadNameByCode(string code, out string error) { try { error = string.Empty; diff --git a/BWPClientForTianRou/AppDb.mdb b/BWPClientForTianRou/AppDb.mdb index 19bb2f9e9ac5342396a45f1e8bdae66ac8cec419..4b351bddfb3c68b4d661ee5f74fbb78ea9a95f93 100644 GIT binary patch delta 1504 zcmZWoZD?Cn7(VYkH)&Fndy_P4o6a<8WuwAy`DnVdw#&y&I+1K$!4F*9HA{6`rgUf( z|CnBoPSYW#WbD9xEo@jU^_>d**n{3^`s$6(<1$4{{ihA?E#b8maYmK-?eea`#5 z?{nV!o_pkrHu<8hzzI0P0YYI0f@Xj&u6-vuM$9t2 z==}0-_3P?lb+meCV{PM&jiHTy*Gtl@qa(eN zB*o)Vuit-QH0Td*PsSaRMtY;ZsAn+X_a2D&eaZ|5X!;x&gomdQ>I^N&2qhT^E8qkJ z5e1|eh$>))0jZcDHP}TH=6^DkzW^tO5b0ir z>2^s8v@V>SeRg8}@Jp{G*+0k5B)N6yv#7<`7RH{LRlSj7K42=>pyG09x2f4lmh~H; za3{U71=qzUeuDA+Mih3CQ%f+k#(i3WR(hqv{WE6OBs4okzRSSD^A_wj-DQI%q9d(H zNA_9pB|xNR!94~e;*k#7^yIb$|CPJt>1y{O(4FvIo=VwjF0eUe>lQS{uXH#HL;xBOfopk#Z7OM2Gf@HOsD3ZTW6` zV-8<;HStNtD=mLeZFxD1iy^C)tJ##=>v9d#W_|X{skJ$2?Pu(%fFMB<& zO;7d>ejNxQHddnbs10pIo6s(FOTK7Ap~?01_jq_bcVmZQ zb+NQ^i>LL6;GV%~ZoRFrb4!kZZwS*xM_@Cje_T5XQO>p>$5+U4Rjm{esS~ErXeaE( zT`3#6(ha+sg3(}|Ec?S@IT8uS{X>Q?pl1_`&Z5zl5>g0tz|l^Feqfj@WNv`;`_H z8bdZ8hMJ4q)qXJ0zJBgUgJa>R;ZjS2*S-abKntP4C zl4OC;qTYI}&~j;|&q5z`@B!m#-kbf56>)_8a_#z~FwZpd9s%IJNf(~ZdU`t_x5drz iyZVz>&H{Dp;J?^ymn?c9kEl1vujbOJ8Bn-IVg3tW^tD$2 diff --git a/BWPClientForTianRou/ConfigUtil.cs b/BWPClientForTianRou/ConfigUtil.cs index f0c61ca..4f3adb6 100644 --- a/BWPClientForTianRou/ConfigUtil.cs +++ b/BWPClientForTianRou/ConfigUtil.cs @@ -6,8 +6,7 @@ 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); diff --git a/BWPClientForTianRou/MainForm.Designer.cs b/BWPClientForTianRou/MainForm.Designer.cs index 4687568..51eb40f 100644 --- a/BWPClientForTianRou/MainForm.Designer.cs +++ b/BWPClientForTianRou/MainForm.Designer.cs @@ -31,7 +31,7 @@ namespace BWPClientForTianRou { System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle(); - this.button1 = new System.Windows.Forms.Button(); + this.logoutButton = new System.Windows.Forms.Button(); this.lblDisplay = new System.Windows.Forms.Label(); this.dataGridView = new System.Windows.Forms.DataGridView(); this.ID = new System.Windows.Forms.DataGridViewTextBoxColumn(); @@ -44,6 +44,9 @@ namespace BWPClientForTianRou { this.DeleteDetail = new System.Windows.Forms.DataGridViewButtonColumn(); this.GoodsIDCol = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.splitContainer1 = new System.Windows.Forms.SplitContainer(); + this.startRec = new System.Windows.Forms.Button(); + this.noticeLabel = new System.Windows.Forms.Label(); + this.button3 = new System.Windows.Forms.Button(); this.syncButton = new System.Windows.Forms.Button(); this.tbxSequence = new System.Windows.Forms.TextBox(); this.lblNumber = new System.Windows.Forms.Label(); @@ -60,16 +63,16 @@ namespace BWPClientForTianRou { this.splitContainer1.SuspendLayout(); this.SuspendLayout(); // - // button1 + // logoutButton // - this.button1.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.button1.Location = new System.Drawing.Point(346, 4); - this.button1.Name = "button1"; - this.button1.Size = new System.Drawing.Size(112, 30); - this.button1.TabIndex = 0; - this.button1.Text = "注销"; - this.button1.UseVisualStyleBackColor = true; - this.button1.Click += new System.EventHandler(this.button1_Click); + this.logoutButton.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.logoutButton.Location = new System.Drawing.Point(260, 3); + this.logoutButton.Name = "logoutButton"; + this.logoutButton.Size = new System.Drawing.Size(92, 32); + this.logoutButton.TabIndex = 0; + this.logoutButton.Text = "注销"; + this.logoutButton.UseVisualStyleBackColor = true; + this.logoutButton.Click += new System.EventHandler(this.button1_Click); // // lblDisplay // @@ -78,11 +81,10 @@ namespace BWPClientForTianRou { this.lblDisplay.BackColor = System.Drawing.Color.Black; this.lblDisplay.Font = new System.Drawing.Font("宋体", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.lblDisplay.ForeColor = System.Drawing.Color.LimeGreen; - this.lblDisplay.Location = new System.Drawing.Point(3, 201); + this.lblDisplay.Location = new System.Drawing.Point(4, 221); this.lblDisplay.Name = "lblDisplay"; - this.lblDisplay.Size = new System.Drawing.Size(447, 50); + this.lblDisplay.Size = new System.Drawing.Size(341, 50); this.lblDisplay.TabIndex = 4; - this.lblDisplay.Text = "24.56"; this.lblDisplay.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // dataGridView @@ -112,12 +114,13 @@ namespace BWPClientForTianRou { this.DeleteDetail, this.GoodsIDCol}); this.dataGridView.Font = new System.Drawing.Font("宋体", 10F); - this.dataGridView.Location = new System.Drawing.Point(-1, 40); + this.dataGridView.Location = new System.Drawing.Point(-1, 8); this.dataGridView.Name = "dataGridView"; this.dataGridView.RowTemplate.Height = 30; - this.dataGridView.Size = new System.Drawing.Size(817, 718); + this.dataGridView.Size = new System.Drawing.Size(923, 750); this.dataGridView.TabIndex = 5; this.dataGridView.TabStop = false; + this.dataGridView.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView_CellContentClick); // // ID // @@ -207,48 +210,82 @@ namespace BWPClientForTianRou { // splitContainer1.Panel1 // this.splitContainer1.Panel1.Controls.Add(this.dataGridView); - this.splitContainer1.Panel1.Controls.Add(this.syncButton); // // splitContainer1.Panel2 // + this.splitContainer1.Panel2.Controls.Add(this.startRec); + this.splitContainer1.Panel2.Controls.Add(this.noticeLabel); + this.splitContainer1.Panel2.Controls.Add(this.button3); + this.splitContainer1.Panel2.Controls.Add(this.syncButton); this.splitContainer1.Panel2.Controls.Add(this.tbxSequence); this.splitContainer1.Panel2.Controls.Add(this.lblNumber); this.splitContainer1.Panel2.Controls.Add(this.readBt); this.splitContainer1.Panel2.Controls.Add(this.selectStoreBt); this.splitContainer1.Panel2.Controls.Add(this.button2); this.splitContainer1.Panel2.Controls.Add(this.userLabel); - this.splitContainer1.Panel2.Controls.Add(this.button1); + this.splitContainer1.Panel2.Controls.Add(this.logoutButton); this.splitContainer1.Panel2.Controls.Add(this.storeLable); this.splitContainer1.Panel2.Controls.Add(this.goodsLabel); this.splitContainer1.Panel2.Controls.Add(this.lblDisplay); this.splitContainer1.Size = new System.Drawing.Size(1292, 749); - this.splitContainer1.SplitterDistance = 825; + this.splitContainer1.SplitterDistance = 931; this.splitContainer1.TabIndex = 6; // + // startRec + // + this.startRec.Font = new System.Drawing.Font("宋体", 12F); + this.startRec.Location = new System.Drawing.Point(196, 123); + this.startRec.Name = "startRec"; + this.startRec.Size = new System.Drawing.Size(92, 32); + this.startRec.TabIndex = 15; + this.startRec.Text = "开始接收"; + this.startRec.UseVisualStyleBackColor = true; + this.startRec.Click += new System.EventHandler(this.startRec_Click); + // + // noticeLabel + // + this.noticeLabel.Font = new System.Drawing.Font("宋体", 12F); + this.noticeLabel.ForeColor = System.Drawing.Color.Red; + this.noticeLabel.Location = new System.Drawing.Point(7, 41); + this.noticeLabel.Name = "noticeLabel"; + this.noticeLabel.Size = new System.Drawing.Size(345, 40); + this.noticeLabel.TabIndex = 14; + // + // button3 + // + this.button3.Font = new System.Drawing.Font("宋体", 12F); + this.button3.Location = new System.Drawing.Point(122, 417); + this.button3.Name = "button3"; + this.button3.Size = new System.Drawing.Size(111, 32); + this.button3.TabIndex = 13; + this.button3.Text = "创建单据"; + this.button3.UseVisualStyleBackColor = true; + this.button3.Click += new System.EventHandler(this.button3_Click); + // // syncButton // - this.syncButton.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.syncButton.Location = new System.Drawing.Point(705, 4); + this.syncButton.Font = new System.Drawing.Font("宋体", 11F); + this.syncButton.Location = new System.Drawing.Point(66, 123); this.syncButton.Name = "syncButton"; - this.syncButton.Size = new System.Drawing.Size(112, 30); + this.syncButton.Size = new System.Drawing.Size(105, 32); this.syncButton.TabIndex = 7; - this.syncButton.Text = "同步信息"; + this.syncButton.Text = "同步基础信息"; this.syncButton.UseVisualStyleBackColor = true; this.syncButton.Click += new System.EventHandler(this.syncButton_Click); // // tbxSequence // this.tbxSequence.Font = new System.Drawing.Font("宋体", 20F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.tbxSequence.Location = new System.Drawing.Point(95, 261); + this.tbxSequence.Location = new System.Drawing.Point(87, 288); this.tbxSequence.Name = "tbxSequence"; this.tbxSequence.ReadOnly = true; - this.tbxSequence.Size = new System.Drawing.Size(138, 38); + this.tbxSequence.Size = new System.Drawing.Size(165, 38); this.tbxSequence.TabIndex = 11; // // lblNumber // this.lblNumber.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.lblNumber.Location = new System.Drawing.Point(6, 273); + this.lblNumber.Location = new System.Drawing.Point(6, 288); this.lblNumber.Name = "lblNumber"; this.lblNumber.Size = new System.Drawing.Size(83, 27); this.lblNumber.TabIndex = 12; @@ -256,21 +293,22 @@ namespace BWPClientForTianRou { // // readBt // + this.readBt.Enabled = false; this.readBt.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.readBt.Location = new System.Drawing.Point(335, 264); + this.readBt.Location = new System.Drawing.Point(258, 292); this.readBt.Name = "readBt"; - this.readBt.Size = new System.Drawing.Size(115, 37); + this.readBt.Size = new System.Drawing.Size(92, 32); this.readBt.TabIndex = 8; - this.readBt.Text = "读入"; + this.readBt.Text = "手工读入"; this.readBt.UseVisualStyleBackColor = true; this.readBt.Click += new System.EventHandler(this.readBt_Click); // // selectStoreBt // this.selectStoreBt.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.selectStoreBt.Location = new System.Drawing.Point(335, 146); + this.selectStoreBt.Location = new System.Drawing.Point(260, 359); this.selectStoreBt.Name = "selectStoreBt"; - this.selectStoreBt.Size = new System.Drawing.Size(115, 37); + this.selectStoreBt.Size = new System.Drawing.Size(92, 32); this.selectStoreBt.TabIndex = 7; this.selectStoreBt.Text = "选择仓库"; this.selectStoreBt.UseVisualStyleBackColor = true; @@ -279,9 +317,9 @@ namespace BWPClientForTianRou { // button2 // this.button2.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.button2.Location = new System.Drawing.Point(335, 97); + this.button2.Location = new System.Drawing.Point(259, 168); this.button2.Name = "button2"; - this.button2.Size = new System.Drawing.Size(115, 37); + this.button2.Size = new System.Drawing.Size(92, 37); this.button2.TabIndex = 7; this.button2.Text = "选择产品"; this.button2.UseVisualStyleBackColor = true; @@ -293,7 +331,7 @@ namespace BWPClientForTianRou { this.userLabel.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.userLabel.Location = new System.Drawing.Point(3, 8); this.userLabel.Name = "userLabel"; - this.userLabel.Size = new System.Drawing.Size(101, 20); + this.userLabel.Size = new System.Drawing.Size(168, 20); this.userLabel.TabIndex = 5; this.userLabel.Text = "用户:"; // @@ -301,9 +339,9 @@ namespace BWPClientForTianRou { // this.storeLable.BackColor = System.Drawing.SystemColors.MenuBar; this.storeLable.Font = new System.Drawing.Font("宋体", 15F); - this.storeLable.Location = new System.Drawing.Point(3, 146); + this.storeLable.Location = new System.Drawing.Point(4, 354); this.storeLable.Name = "storeLable"; - this.storeLable.Size = new System.Drawing.Size(327, 37); + this.storeLable.Size = new System.Drawing.Size(249, 37); this.storeLable.TabIndex = 5; // // goodsLabel @@ -311,9 +349,9 @@ namespace BWPClientForTianRou { this.goodsLabel.BackColor = System.Drawing.SystemColors.MenuBar; this.goodsLabel.Cursor = System.Windows.Forms.Cursors.Default; this.goodsLabel.Font = new System.Drawing.Font("宋体", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.goodsLabel.Location = new System.Drawing.Point(3, 97); + this.goodsLabel.Location = new System.Drawing.Point(6, 168); this.goodsLabel.Name = "goodsLabel"; - this.goodsLabel.Size = new System.Drawing.Size(326, 37); + this.goodsLabel.Size = new System.Drawing.Size(247, 37); this.goodsLabel.TabIndex = 5; // // MainForm @@ -338,7 +376,7 @@ namespace BWPClientForTianRou { #endregion - private System.Windows.Forms.Button button1; + private System.Windows.Forms.Button logoutButton; private System.Windows.Forms.Label lblDisplay; private System.Windows.Forms.DataGridView dataGridView; private System.Windows.Forms.SplitContainer splitContainer1; @@ -360,5 +398,8 @@ namespace BWPClientForTianRou { private System.Windows.Forms.DataGridViewTextBoxColumn UnitCol; private System.Windows.Forms.DataGridViewButtonColumn DeleteDetail; private System.Windows.Forms.DataGridViewTextBoxColumn GoodsIDCol; + private System.Windows.Forms.Button button3; + private System.Windows.Forms.Label noticeLabel; + private System.Windows.Forms.Button startRec; } } \ No newline at end of file diff --git a/BWPClientForTianRou/MainForm.cs b/BWPClientForTianRou/MainForm.cs index c295d89..467ea0d 100644 --- a/BWPClientForTianRou/MainForm.cs +++ b/BWPClientForTianRou/MainForm.cs @@ -3,12 +3,13 @@ using System.Collections.Generic; using System.Configuration; using System.Data; using System.Drawing; +using System.Net; +using System.Net.Sockets; +using System.Text; using System.Threading; using System.Windows.Forms; using BLUtil; -using Forks.EnterpriseServices; using Forks.JsonRpc.Client.Data; -using Forks.Utils.Data; namespace BWPClientForTianRou { public partial class MainForm : Form { @@ -18,7 +19,7 @@ namespace BWPClientForTianRou { readonly AutoSizeFormClass _asc = new AutoSizeFormClass(); private DataSet _resultDataSet = new DataSet(); private BaseInforObj _currentGoods; - private BaseInforObj CurrentStore; + private BaseInforObj _currentStore; private readonly object _queLocker = new object(); private readonly ManualResetEvent _rwSychEvent = new ManualResetEvent(false); private const int WmQueryData = 0x0500 + 10; @@ -26,19 +27,42 @@ namespace BWPClientForTianRou { private const int WmUpdLanStateMessage = 0x0500 + 12; private bool _mainProcessIsRun; private string _displayValue; + + Socket _socket; + + private FormProcessBar _myProcessBar; + private delegate bool IncreaseHandle(int nValue); + private IncreaseHandle _myIncrease; + private int _handle; + private Thread receiveThread; private readonly Thread _insertThread;//后台插入称重 + bool mEnableConnect = false; + protected int MainHandle { + get { + if (_handle == 0) { + _handle = WinApiSendMessage.FindWindow(null, @"青花瓷客户端"); + } + return _handle; + } + } + private string ip; + private int port = 80; public MainForm() { InitializeComponent(); userLabel.Text = "用户:" + EncodeString.UserName; _currentGoods = new BaseInforObj(); - CurrentStore = new BaseInforObj(); - + _currentStore = new BaseInforObj(); + _mainProcessIsRun = true; CheckForIllegalCrossThreadCalls = false; _insertThread = new Thread(DoInser) { IsBackground = true }; _insertThread.Start(new object()); + receiveThread = new Thread(StartReceiveThread); + receiveThread.Start(); + thread = new Thread(StartThread); + thread.Start(); ID.Width = 30; Sequence.Width = 20; DateTime.Width = 110; @@ -47,6 +71,9 @@ namespace BWPClientForTianRou { Weight.Width = 45; UnitCol.Width = 35; DeleteDetail.Width = 50; + ip = ConfigurationManager.AppSettings["IP"]; + var portStr = ConfigurationManager.AppSettings["Port"]; + port = int.Parse(portStr); } protected override void OnClosed(EventArgs e) { @@ -62,8 +89,8 @@ namespace BWPClientForTianRou { _asc.ControllInitializeSize(this); WindowState = FormWindowState.Maximized; InitSequenceText(); - GetWeightData(); - _displayValue = "display"; + GetWeightData(); + _displayValue = ""; } //消息处理 @@ -89,21 +116,6 @@ namespace BWPClientForTianRou { #region 进度条 - private FormProcessBar _myProcessBar; - private delegate bool IncreaseHandle(int nValue); - private IncreaseHandle _myIncrease; - private Thread _syncBaseInfoThread; - private int _handle; - - protected int MainHandle { - get { - if (_handle == 0) { - _handle = WinApiSendMessage.FindWindow(null, @"青花瓷客户端"); - } - return _handle; - } - } - private void ShowProcessBar() { _myProcessBar = new FormProcessBar(); _myIncrease = _myProcessBar.Increase; @@ -126,10 +138,9 @@ namespace BWPClientForTianRou { } private void syncButton_Click(object sender, EventArgs e) { - - _syncBaseInfoThread = new Thread(BaseInfosSync); - _syncBaseInfoThread.IsBackground = true; - _syncBaseInfoThread.Start(); + var syncBaseInfoThread = new Thread(BaseInfosSync); + syncBaseInfoThread.IsBackground = true; + syncBaseInfoThread.Start(); ShowProcessBar(); } @@ -161,7 +172,7 @@ namespace BWPClientForTianRou { return; } - CurrentStore = info; + _currentStore = info; storeLable.Text = info.Name; @@ -191,10 +202,166 @@ namespace BWPClientForTianRou { } + private void startRec_Click(object sender, EventArgs e) { + if (_currentGoods == null || _currentGoods.ID == 0) { + MessageBox.Show("请选择产品!"); + return; + } + mEnableConnect = true; + } + + private void dataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e) { + if (DeleteDetail.Index == e.ColumnIndex) { + if (MessageBox.Show("确定要删除吗?", "删除", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) + return; + object strID = dataGridView.Rows[e.RowIndex].Cells["ID"].Value; + DbUtil.Delete(strID); + dataGridView.Rows.RemoveAt(e.RowIndex); + InitSequenceText(); + } + } + #endregion + private void button3_Click(object sender, EventArgs e) { + + if (_resultDataSet == null || _resultDataSet.Tables[0].Rows.Count == 0) + MessageBox.Show("没有称重记录"); + else { + if (_currentStore == null || _currentStore.ID == 0) { + MessageBox.Show("请选择仓库!"); + return; + } + + var bill = new RpcObject("/MainSystem/B3Butchery/BO/ProductInStore"); + bill.Set("Store_ID", _currentStore.ID); + bill.Set("Department_ID", 1L); + bill.Set("Store_Name", _currentStore.Name); + bill.Set("Remark", "称重客户端上传"); + var details = new ManyList("/MainSystem/B3Butchery/BO/ProductInStore_Detail"); + foreach (DataRow row in _resultDataSet.Tables[0].Rows) { + var detail1 = new RpcObject("/MainSystem/B3Butchery/BO/ProductInStore_Detail"); + detail1.Set("Goods_ID", long.Parse(row["Goods_ID"].ToString())); + detail1.Set("Goods_Name", row["Goods_Name"]); + detail1.Set("Number", row["Weight"]); + details.Add(detail1); + } + bill.Set("Details", details); + var id = RpcUtil.Call(RpcUtil.InsertInStore, bill); + DbUtil.UpdateState(); + GetWeightData(); + MessageBox.Show("创建成品入库单No." + id); + } + } + #region 方法 + object recievLocker = new object(); + void StartReceiveThread() { + while (true) { + Thread.Sleep(1000); + + if (_socket == null || !_socket.Connected) { + continue; + } + + if (Monitor.TryEnter(recievLocker)) { + try { + Receive(_socket); + } catch (Exception ex) { + if (IsHandleCreated) { + Invoke(new EventHandler((sender, e) => { + noticeLabel.ForeColor = Color.Red; + noticeLabel.Text = string.Format("接收数据错误:{0}", ex.Message); + })); + } + } finally { + Monitor.Exit(recievLocker); + } + } + } + } + + private Thread thread; + + void StartThread() { + while (true) { + Connect(); + } + } + + private void Connect() { + if (mEnableConnect) { + if (_socket == null || !_socket.Connected) { + try { + _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); + var ipEndPornt = new IPEndPoint(IPAddress.Parse(ip), port); + _socket.Connect(ipEndPornt); + if (IsHandleCreated) { + Invoke(new EventHandler((sender, e) => { + noticeLabel.ForeColor = Color.Blue; + noticeLabel.Text = string.Format("连接到 {0}:{1}成功", ip, port); + })); + } + } catch (Exception ex) { + if (IsHandleCreated) { + Invoke(new EventHandler((sender, e) => { + noticeLabel.ForeColor = Color.Red; + noticeLabel.Text = string.Format("连接到 {0}:{1}失败:{2}", ip, port, + ex.Message); + })); + } + } + } + Thread.Sleep(5000); + } else { + if (_socket != null) { + _socket.Dispose(); + _socket = null; + } + Thread.Sleep(1000); + } + + } + + private void Receive(Socket socket) { + + var buffer = new byte[4096]; + + var received = socket.Receive(buffer); + + if (received > 0) { + var newByte = new byte[received]; + for (int i = 0; i < received; i++) { + newByte[i] = buffer[i]; + } + + if (IsHandleCreated) { + var info = Encoding.ASCII.GetString(buffer, 0, received); + decimal w = 0m; + lblDisplay.Text = info.Trim(); + var str = info.Replace("毛重", "").Replace("kg", "").Replace("KG", ""); + if (decimal.TryParse(str, out w)) { + var bo = new WeightTable(); + bo.DateTime = System.DateTime.Now; + bo.Weight = w; + if (_currentGoods != null) { + bo.Goods_Code = _currentGoods.Code; + bo.Goods_Name = _currentGoods.Name; + bo.Goods_ID = _currentGoods.ID; + bo.Unit = _currentGoods.Unit; + } + + long sq; + if (long.TryParse(tbxSequence.Text, out sq)) + bo.Sequence = sq; + EnQueue(bo); + } + } + } + + } + private void QueryResult() { // 查询出数据 lock (EncodeString.RwLocker) { @@ -260,8 +427,8 @@ namespace BWPClientForTianRou { obj.Spell = goods.Get("Spell"); list.Add(obj); //测试时值读取少量数据 - if (list.Count >= 1202) - break; + //if (list.Count >= 1202) + // break; } Invoke(_myIncrease, new object[] { 5 }); var count = list.Count; @@ -329,8 +496,14 @@ namespace BWPClientForTianRou { _resultDataSet = DbUtil.GetWeight(); } } - if (!string.IsNullOrEmpty(err)) - MessageBox.Show(err); + if (!string.IsNullOrEmpty(err)) { + if (IsHandleCreated) { + Invoke(new EventHandler((sender, e) => { + noticeLabel.ForeColor = Color.Red; + noticeLabel.Text = string.Format("记录称重数据错误:{0}", err); + })); + } + } // 同步主线程 WinApiSendMessage.SendMessage(MainHandle, WmQueryData, 0, 0); } diff --git a/BWPClientForTianRou/Properties/AssemblyInfo.cs b/BWPClientForTianRou/Properties/AssemblyInfo.cs index f26129d..74ebc48 100644 --- a/BWPClientForTianRou/Properties/AssemblyInfo.cs +++ b/BWPClientForTianRou/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值, // 方法是按如下所示使用“*”: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyVersion("17.06.19.1")] +[assembly: AssemblyFileVersion("17.06.19.1")]