diff --git a/BO/BO.csproj b/BO/BO.csproj index 19cc73f..13742f3 100644 --- a/BO/BO.csproj +++ b/BO/BO.csproj @@ -32,7 +32,7 @@ False - D:\BwpB3Project\tsref\Debug\Forks.EnterpriseServices.dll + ..\..\..\tsref\Debug\Forks.EnterpriseServices.dll False @@ -40,7 +40,7 @@ False - D:\BwpB3Project\tsref\Debug\Forks.Utils.dll + ..\..\..\tsref\Debug\Forks.Utils.dll diff --git a/BO/BO/Bill/GradeAndWeight/GradeAndWeight_Detail.cs b/BO/BO/Bill/GradeAndWeight/GradeAndWeight_Detail.cs index 0d9e95e..f03f41d 100644 --- a/BO/BO/Bill/GradeAndWeight/GradeAndWeight_Detail.cs +++ b/BO/BO/Bill/GradeAndWeight/GradeAndWeight_Detail.cs @@ -1,4 +1,5 @@ -using System; +using Forks.EnterpriseServices.DomainObjects2; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -6,10 +7,16 @@ using System.Threading.Tasks; namespace BO.BO.Bill { + [MapToTable("GradeAndWeight_Detail")] + [KeyField("SID", KeyGenType.identity)] public class GradeAndWeight_Detail { - public long ID { get; set; } + /// + /// 本地ID + /// + public long SID { get; set; } + [NonDmoProperty] public bool ReadWeight { get; set; } public long? OrderDetail_ID { get; set; } @@ -18,11 +25,11 @@ namespace BO.BO.Bill public DateTime Date { get; set; } - public short Technics { get; set; } + public short? Technics { get; set; } public string Technics_Name { get; set; } - public long Livestock_ID { get; set; } + public long? Livestock_ID { get; set; } public string Livestock_Name { get; set; } @@ -30,6 +37,11 @@ namespace BO.BO.Bill public DateTime Time { get; set; } - public DateTime TempTime { get { return Time; } } + /// + /// ServerID + /// + public long ID { get; set; } + + public bool Sync { get; set; } } } diff --git a/BO/BO/Bill/WeightBill/WeightBill.cs b/BO/BO/Bill/WeightBill/WeightBill.cs index c03eca8..acaa174 100644 --- a/BO/BO/Bill/WeightBill/WeightBill.cs +++ b/BO/BO/Bill/WeightBill/WeightBill.cs @@ -1,10 +1,8 @@ -using Forks.EnterpriseServices.DomainObjects2; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using TSingSoft.WebPluginFramework; namespace BO.BO { diff --git a/BO/Utils/BillRpc/GradeAndWeightRpc.cs b/BO/Utils/BillRpc/GradeAndWeightRpc.cs index 3570431..11778d7 100644 --- a/BO/Utils/BillRpc/GradeAndWeightRpc.cs +++ b/BO/Utils/BillRpc/GradeAndWeightRpc.cs @@ -1,5 +1,8 @@ using BO.BO.BaseInfo; using BO.BO.Bill; +using Forks.EnterpriseServices.DomainObjects2; +using Forks.EnterpriseServices.DomainObjects2.DQuery; +using Forks.EnterpriseServices.SqlDoms; using Forks.JsonRpc.Client; using System; using System.Collections.Generic; @@ -7,6 +10,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Web.Script.Serialization; +using TSingSoft.WebPluginFramework; namespace BO.Utils.BillRpc { @@ -14,33 +18,13 @@ namespace BO.Utils.BillRpc { static JavaScriptSerializer serializer = new JavaScriptSerializer(); - public static List GetGradeAndWeightList(DateTime date,bool isTang) + public static List GetGradeAndWeightList(DateTime date, bool isTang) { const string method = "/MainSystem/B3ClientService/Rpcs/BillRpc/GradeAndWeightRpc/GetGradeAndWeightList"; var result = RpcFacade.Call(method, date, isTang); return serializer.Deserialize>(result); } - public static List GetDetails(DateTime date, int top = 15) - { - const string method = "/MainSystem/B3ClientService/Rpcs/BillRpc/GradeAndWeightRpc/GetDetailsList"; - var result = RpcFacade.Call(method, date, top); - result = result.ESerializeDateTime(); - return serializer.Deserialize>(result); - } - - public static void UpdateOrInsertDetail(GradeAndWeight_Detail detail, bool fillTechnics = false) - { - const string method = "/MainSystem/B3ClientService/Rpcs/BillRpc/GradeAndWeightRpc/UpdateOrInsertDetail"; - detail.ID = RpcFacade.Call(method, serializer.Serialize(detail), fillTechnics); - } - - public static void UpdateLivestock(long id, long liveStockID, string liveStockName, short technics, string technicsName) - { - const string method = "/MainSystem/B3ClientService/Rpcs/BillRpc/GradeAndWeightRpc/UpdateLivestock"; - RpcFacade.Call(method, id, liveStockID, liveStockName, technics, technicsName); - } - public static void SetGradeFinish(long orderDetailID, short technics) { const string method = "/MainSystem/B3ClientService/Rpcs/BillRpc/GradeAndWeightRpc/SetGradeFinish"; @@ -59,11 +43,123 @@ namespace BO.Utils.BillRpc const string method = "/MainSystem/B3ClientService/Rpcs/BillRpc/GradeAndWeightRpc/SaveBodyDiscontItemSetting"; RpcFacade.Call(method, serializer.Serialize(list)); } + } + + public static class LocalGradeAndWeightBL + { + static JavaScriptSerializer serializer = new JavaScriptSerializer(); + + class DmoSession + { + public static IDmoSessionWithTransaction New() + { + return Dmo.NewSession(ButcherAppContext.Context.UrlConfig.OfflineSqlConnection); + } + } + + public static bool ConnectionTest() + { + using (var session = DmoSession.New()) + { + try + { + var q = new DQueryDom(new JoinAlias(typeof(GradeAndWeight_Detail))); + q.Columns.Add(DQSelectColumn.Create(DQExpression.Value(1), "c")); + q.Range = SelectRange.Top(1); + session.ExecuteScalar(q); + return true; + } + catch + { return false; } + } + } + + public static List GetDetails(DateTime date, int top = 15) + { + var query = new DmoQuery(typeof(GradeAndWeight_Detail)); + query.Where.Conditions.Add(DQCondition.EQ("Date", date)); + query.OrderBy.Expressions.Add(DQOrderByExpression.Create("Index", true)); + query.Range = SelectRange.Top(top); + using (var session = DmoSession.New()) + { + return session.ExecuteList(query).Cast().ToList(); + } + } + + public static void Insert(GradeAndWeight_Detail detail) + { + using (var session = DmoSession.New()) + { + if (detail.SID != 0) + throw new Exception("Insert时要保证SID不为0"); + session.Insert(detail); + session.Commit(); + } + } + + public static void Update(GradeAndWeight_Detail detail, params string[] properties) + { + var type = typeof(GradeAndWeight_Detail); + using (var session = DmoSession.New()) + { + if (detail.SID == 0) + throw new Exception("Update时要保证SID不能为0"); + if (properties.Contains("ID")) + throw new Exception("ID不能通过该方法维护"); + if (properties.Length == 0) + throw new Exception("Update时要给出属性数组"); + var update = new DQUpdateDom(type); + update.Where.Conditions.Add(DQCondition.EQ("SID", detail.SID)); + foreach (var p in properties) + { + if (p == "Sync" && detail.Sync) + detail.Sync = false; + update.Columns.Add(new DQUpdateColumn(p, type.GetProperty(p).GetValue(detail))); + } + session.ExecuteNonQuery(update); + session.Commit(); + } + } + + public static void Sync() + { + var syncs = GetAllNeedSyncDetails(); + foreach (var detail in syncs) + { + const string method = "/MainSystem/B3ClientService/Rpcs/BillRpc/GradeAndWeightRpc/UpdateOrInsertDetail"; + var id = RpcFacade.Call(method, serializer.Serialize(detail)); + + SetDetailSynced(detail, id); + } + } + + static IEnumerable GetAllNeedSyncDetails() + { + using (var session = DmoSession.New()) + { + var query = new DmoQuery(typeof(GradeAndWeight_Detail)); + query.OrderBy.Expressions.Add(DQOrderByExpression.Create("SID")); + query.Range = SelectRange.Top(50); + query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("Sync", false), DQCondition.IsNotNull(DQExpression.Field("Technics")))); + return session.ExecuteList(query).Cast(); + } + } - public static void UpdateWeight(long id, decimal? weight) + static void SetDetailSynced(GradeAndWeight_Detail detail, long id) { - const string method = "/MainSystem/B3ClientService/Rpcs/BillRpc/GradeAndWeightRpc/UpdateWeight"; - RpcFacade.Call(method, id, weight); + using (var session = DmoSession.New()) + { + var update = new DQUpdateDom(typeof(GradeAndWeight_Detail)); + update.Columns.Add(new DQUpdateColumn("Sync", true)); + if (detail.ID == 0) + { + detail.ID = id; + update.Columns.Add(new DQUpdateColumn("ID", id)); + } + update.Where.Conditions.Add(DQCondition.EQ("SID", detail.SID)); + session.ExecuteNonQuery(update); + session.Commit(); + } } } } diff --git a/BO/Utils/LoginRpcUtil.cs b/BO/Utils/LoginRpcUtil.cs index e29fb4c..f091bf3 100644 --- a/BO/Utils/LoginRpcUtil.cs +++ b/BO/Utils/LoginRpcUtil.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Net; +using System.Net.NetworkInformation; using System.Text; using System.Threading.Tasks; @@ -50,17 +51,76 @@ namespace BO.Utils var url = ButcherAppContext.Context.UrlConfig.ServerUrl; if (string.IsNullOrEmpty(url)) return false; + //try + //{ + //HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); + var uri = new Uri(url); + return TestConnection(uri.Host, uri.Port, 50); + + // HttpWebResponse resp = (HttpWebResponse)req.GetResponse(); + + // return resp.StatusCode == HttpStatusCode.OK; + //} + //catch + //{ + // return false; + //} + } + + //public static bool TestConnection() + //{ + // try + // { + // Dns.GetHostEntry(ButcherAppContext.Context.UrlConfig.ServerUrl); //using System.Net; + // return true; + // } + // catch (System.Net.Sockets.SocketException ex) + // { + // return false; + // } + // //try + // //{ + // // Ping objPingSender = new Ping(); + // // PingOptions objPinOptions = new PingOptions(); + // // objPinOptions.DontFragment = true; + // // string data = ""; + // // byte[] buffer = Encoding.UTF8.GetBytes(data); + // // int intTimeout = 120; + // // PingReply objPinReply = objPingSender.Send(ButcherAppContext.Context.UrlConfig.ServerUrl, intTimeout, buffer, objPinOptions); + // // string strInfo = objPinReply.Status.ToString(); + // // if (strInfo == "Success") + // // { + // // return true; + // // } + // // else + // // { + // // return false; + // // } + // //} + // //catch (Exception) + // //{ + // // return false; + // //} + //} + + + public static bool TestConnection(string host, int port, int millisecondsTimeout) + { + var client = new System.Net.Sockets.TcpClient(); try { - HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); - HttpWebResponse resp = (HttpWebResponse)req.GetResponse(); - - return resp.StatusCode == HttpStatusCode.OK; + var ar = client.BeginConnect(host, port, null, null); + ar.AsyncWaitHandle.WaitOne(millisecondsTimeout); + return client.Connected; } - catch + catch (Exception) { return false; } + finally + { + client.Close(); + } } } } diff --git a/BO/Utils/ServerUrlConfig.cs b/BO/Utils/ServerUrlConfig.cs index ec24b2d..f017666 100644 --- a/BO/Utils/ServerUrlConfig.cs +++ b/BO/Utils/ServerUrlConfig.cs @@ -9,5 +9,7 @@ namespace BO.Utils public class ServerUrlConfig { public string ServerUrl { get; set; } + + public string OfflineSqlConnection { get; set; } } } diff --git a/BWP.WinFormControl/BWP.WinFormControl.csproj b/BWP.WinFormControl/BWP.WinFormControl.csproj index af7c412..0b6dd6f 100644 --- a/BWP.WinFormControl/BWP.WinFormControl.csproj +++ b/BWP.WinFormControl/BWP.WinFormControl.csproj @@ -32,7 +32,7 @@ False - ..\..\..\..\BwpB3Project\tsref\Debug\Forks.JsonRpc.Client.dll + ..\..\..\tsref\Debug\Forks.JsonRpc.Client.dll diff --git a/ButcherManageClient/ButcherManageClient.csproj b/ButcherManageClient/ButcherManageClient.csproj index 3e26106..eba66e0 100644 --- a/ButcherManageClient/ButcherManageClient.csproj +++ b/ButcherManageClient/ButcherManageClient.csproj @@ -35,18 +35,10 @@ pig [128x128].ico - - False - ..\..\..\..\BwpB3Project\tsref\Debug\Forks.EnterpriseServices.dll - False ..\..\..\..\BwpB3Project\tsref\Debug\Forks.JsonRpc.Client.dll - - False - ..\..\..\..\BwpB3Project\tsref\Debug\Forks.Utils.dll - diff --git a/ButcherManageClient/SettingForm.Designer.cs b/ButcherManageClient/SettingForm.Designer.cs index 5a97bb4..f2d9653 100644 --- a/ButcherManageClient/SettingForm.Designer.cs +++ b/ButcherManageClient/SettingForm.Designer.cs @@ -32,12 +32,14 @@ this.saveBtn = new System.Windows.Forms.Button(); this.uTextBoxWithPad1 = new BWP.WinFormControl.UTextBoxWithPad(); this.label1 = new System.Windows.Forms.Label(); + this.offlineSqlConInput = new BWP.WinFormControl.UTextBoxWithPad(); + this.label2 = new System.Windows.Forms.Label(); this.SuspendLayout(); // // cancelBtn // this.cancelBtn.Font = new System.Drawing.Font("宋体", 20F); - this.cancelBtn.Location = new System.Drawing.Point(241, 110); + this.cancelBtn.Location = new System.Drawing.Point(238, 164); this.cancelBtn.Name = "cancelBtn"; this.cancelBtn.Size = new System.Drawing.Size(81, 53); this.cancelBtn.TabIndex = 7; @@ -48,7 +50,7 @@ // saveBtn // this.saveBtn.Font = new System.Drawing.Font("宋体", 20F); - this.saveBtn.Location = new System.Drawing.Point(100, 110); + this.saveBtn.Location = new System.Drawing.Point(97, 164); this.saveBtn.Name = "saveBtn"; this.saveBtn.Size = new System.Drawing.Size(81, 53); this.saveBtn.TabIndex = 6; @@ -75,17 +77,38 @@ this.label1.TabIndex = 4; this.label1.Text = "服务器地址:"; // + // offlineSqlConInput + // + this.offlineSqlConInput.Font = new System.Drawing.Font("宋体", 15F); + this.offlineSqlConInput.Location = new System.Drawing.Point(140, 106); + this.offlineSqlConInput.Name = "offlineSqlConInput"; + this.offlineSqlConInput.Size = new System.Drawing.Size(246, 30); + this.offlineSqlConInput.TabIndex = 9; + this.offlineSqlConInput.Type = BWP.WinFormControl.UTextBoxWithPad.TextBoxType.Normal; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Font = new System.Drawing.Font("宋体", 15F); + this.label2.Location = new System.Drawing.Point(18, 109); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(129, 20); + this.label2.TabIndex = 8; + this.label2.Text = "离线数据库:"; + // // SettingForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(404, 205); + this.ClientSize = new System.Drawing.Size(404, 242); + this.ControlBox = false; + this.Controls.Add(this.offlineSqlConInput); + this.Controls.Add(this.label2); this.Controls.Add(this.cancelBtn); this.Controls.Add(this.saveBtn); this.Controls.Add(this.uTextBoxWithPad1); this.Controls.Add(this.label1); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; - this.MaximizeBox = false; this.Name = "SettingForm"; this.Text = "服务器配置"; this.ResumeLayout(false); @@ -99,5 +122,7 @@ private System.Windows.Forms.Button saveBtn; private BWP.WinFormControl.UTextBoxWithPad uTextBoxWithPad1; private System.Windows.Forms.Label label1; + private BWP.WinFormControl.UTextBoxWithPad offlineSqlConInput; + private System.Windows.Forms.Label label2; } } \ No newline at end of file diff --git a/ButcherManageClient/SettingForm.cs b/ButcherManageClient/SettingForm.cs index b3a08be..7448160 100644 --- a/ButcherManageClient/SettingForm.cs +++ b/ButcherManageClient/SettingForm.cs @@ -19,6 +19,9 @@ namespace ButcherManageClient { InitializeComponent(); uTextBoxWithPad1.Text = ButcherAppContext.Context.UrlConfig.ServerUrl; + offlineSqlConInput.Text = ButcherAppContext.Context.UrlConfig.OfflineSqlConnection; + if (string.IsNullOrEmpty(offlineSqlConInput.Text)) + offlineSqlConInput.Text = "Server=localhost;Database=LocalClientService;Integrated Security=true;Language=Simplified Chinese;"; mInited = rpcFacadeInited; } @@ -33,6 +36,7 @@ namespace ButcherManageClient if (string.IsNullOrEmpty(uri)) throw new Exception("请先设置服务器地址"); ButcherAppContext.Context.UrlConfig.ServerUrl = uri; + ButcherAppContext.Context.UrlConfig.OfflineSqlConnection = offlineSqlConInput.Text.Trim(); ButcherAppContext.Context.Save(); if (mInited) diff --git a/ButcherWeight/ButcherWeight.csproj b/ButcherWeight/ButcherWeight.csproj index cc1b577..3bd6761 100644 --- a/ButcherWeight/ButcherWeight.csproj +++ b/ButcherWeight/ButcherWeight.csproj @@ -34,18 +34,6 @@ False ..\..\..\tsref\Debug\BwpClientPrint.dll - - False - ..\..\..\..\BwpB3Project\tsref\Debug\Forks.EnterpriseServices.dll - - - False - ..\..\..\..\BwpB3Project\tsref\Debug\Forks.JsonRpc.Client.dll - - - False - ..\..\..\..\BwpB3Project\tsref\Debug\Forks.Utils.dll - diff --git a/OrderConfirm/OrderConfirm.csproj b/OrderConfirm/OrderConfirm.csproj index c2e0695..6ce8ff9 100644 --- a/OrderConfirm/OrderConfirm.csproj +++ b/OrderConfirm/OrderConfirm.csproj @@ -30,7 +30,6 @@ 4 - diff --git a/WeighAndGrading/BodyDiscontSetting.cs b/WeighAndGrading/BodyDiscontSetting.cs index 8ac75d1..27d4177 100644 --- a/WeighAndGrading/BodyDiscontSetting.cs +++ b/WeighAndGrading/BodyDiscontSetting.cs @@ -1,5 +1,6 @@ using BO; using BO.BO.BaseInfo; +using BO.Utils; using BO.Utils.BillRpc; using BWP.WinFormControl; using System; @@ -7,6 +8,7 @@ using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -17,10 +19,12 @@ namespace WeighAndGrading public partial class BodyDiscontSetting : Form { List list; + string fileName; public BodyDiscontSetting() { InitializeComponent(); - list = GradeAndWeightRpc.GetBodyDiscontItem().OrderBy(x => x.ID).ToList(); + fileName = Path.Combine(GradeFrom.DATA_PATH, "Disconts.xml"); + list = XmlUtil.DeserializeFromFile>(fileName); uDataGridView1.DataSource = list; uDataGridView1.Refresh(); } @@ -34,7 +38,19 @@ namespace WeighAndGrading var entity = row.DataBoundItem as BodyDiscontItem; list.Add(new CTuple(entity.ID, entity.Discont)); } - GradeAndWeightRpc.SaveBodyDiscontItem(list); + XmlUtil.SerializerObjToFile(list, fileName); + var changeFlagPath = Path.Combine(GradeFrom.DATA_PATH, "DiscontsChanged.txt"); + bool existFile = File.Exists(changeFlagPath); + + var connection = LoginRpcUtil.TestConnection(); + if (connection) + { + GradeAndWeightRpc.SaveBodyDiscontItem(list); + if (existFile) + File.Delete(changeFlagPath); + } + else if (!existFile) + File.WriteAllText(changeFlagPath, string.Empty); if (!changed) changed = true; MessageBox.Show("保存成功!"); @@ -42,7 +58,8 @@ namespace WeighAndGrading private void closeBtn_Click(object sender, EventArgs e) { - DialogResult = DialogResult.OK; + if (changed) + DialogResult = DialogResult.OK; this.Close(); } diff --git a/WeighAndGrading/GradeFrom.Designer.cs b/WeighAndGrading/GradeFrom.Designer.cs index 8aa0e03..300b598 100644 --- a/WeighAndGrading/GradeFrom.Designer.cs +++ b/WeighAndGrading/GradeFrom.Designer.cs @@ -73,14 +73,6 @@ this.vScrollBar2 = new System.Windows.Forms.VScrollBar(); this.label12 = new System.Windows.Forms.Label(); this.historyGrid = new BWP.WinFormControl.UDataGridView(); - this.H_ID = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.H_Livestock_ID = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.H_ReadWeight = new System.Windows.Forms.DataGridViewCheckBoxColumn(); - this.H_Index = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.H_Technics = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.H_Livestock_Name = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.H_Weight = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.H_Time = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.enableWeight = new System.Windows.Forms.CheckBox(); this.isPrintCheckBox = new System.Windows.Forms.CheckBox(); this.printBtn = new System.Windows.Forms.Button(); @@ -95,6 +87,14 @@ this.discontBtn = new System.Windows.Forms.Button(); this.discontPanel = new System.Windows.Forms.FlowLayoutPanel(); this.statePic = new System.Windows.Forms.PictureBox(); + this.H_SID = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.H_Livestock_ID = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.H_ReadWeight = new System.Windows.Forms.DataGridViewCheckBoxColumn(); + this.H_Index = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.H_Technics = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.H_Livestock_Name = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.H_Weight = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.H_Time = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.groupBox1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.tangGridView)).BeginInit(); this.groupBox2.SuspendLayout(); @@ -475,7 +475,7 @@ this.historyGrid.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle10; this.historyGrid.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.historyGrid.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { - this.H_ID, + this.H_SID, this.H_Livestock_ID, this.H_ReadWeight, this.H_Index, @@ -498,73 +498,6 @@ this.historyGrid.TabIndex = 0; this.historyGrid.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.historyGrid_CellClick); // - // H_ID - // - this.H_ID.DataPropertyName = "ID"; - this.H_ID.HeaderText = "ID"; - this.H_ID.Name = "H_ID"; - this.H_ID.ReadOnly = true; - this.H_ID.Visible = false; - // - // H_Livestock_ID - // - this.H_Livestock_ID.HeaderText = "Livestock_ID"; - this.H_Livestock_ID.Name = "H_Livestock_ID"; - this.H_Livestock_ID.ReadOnly = true; - this.H_Livestock_ID.Visible = false; - // - // H_ReadWeight - // - this.H_ReadWeight.DataPropertyName = "ReadWeight"; - this.H_ReadWeight.HeaderText = ""; - this.H_ReadWeight.Name = "H_ReadWeight"; - this.H_ReadWeight.ReadOnly = true; - this.H_ReadWeight.Width = 30; - // - // H_Index - // - this.H_Index.DataPropertyName = "Index"; - this.H_Index.HeaderText = "序号"; - this.H_Index.Name = "H_Index"; - this.H_Index.ReadOnly = true; - this.H_Index.Width = 65; - // - // H_Technics - // - this.H_Technics.DataPropertyName = "Technics_Name"; - this.H_Technics.HeaderText = "工艺"; - this.H_Technics.Name = "H_Technics"; - this.H_Technics.ReadOnly = true; - this.H_Technics.Width = 65; - // - // H_Livestock_Name - // - this.H_Livestock_Name.DataPropertyName = "Livestock_Name"; - this.H_Livestock_Name.HeaderText = "级别"; - this.H_Livestock_Name.Name = "H_Livestock_Name"; - this.H_Livestock_Name.ReadOnly = true; - this.H_Livestock_Name.Width = 90; - // - // H_Weight - // - this.H_Weight.DataPropertyName = "Weight"; - dataGridViewCellStyle11.Format = "#0.######"; - this.H_Weight.DefaultCellStyle = dataGridViewCellStyle11; - this.H_Weight.HeaderText = "重量"; - this.H_Weight.Name = "H_Weight"; - this.H_Weight.ReadOnly = true; - this.H_Weight.Width = 70; - // - // H_Time - // - this.H_Time.DataPropertyName = "Time"; - dataGridViewCellStyle12.Format = "MM/dd HH:mm"; - dataGridViewCellStyle12.NullValue = null; - this.H_Time.DefaultCellStyle = dataGridViewCellStyle12; - this.H_Time.HeaderText = "时间"; - this.H_Time.Name = "H_Time"; - this.H_Time.ReadOnly = true; - // // enableWeight // this.enableWeight.AutoCheck = false; @@ -718,6 +651,73 @@ this.statePic.TabIndex = 38; this.statePic.TabStop = false; // + // H_SID + // + this.H_SID.DataPropertyName = "SID"; + this.H_SID.HeaderText = "SID"; + this.H_SID.Name = "H_SID"; + this.H_SID.ReadOnly = true; + this.H_SID.Visible = false; + // + // H_Livestock_ID + // + this.H_Livestock_ID.HeaderText = "Livestock_ID"; + this.H_Livestock_ID.Name = "H_Livestock_ID"; + this.H_Livestock_ID.ReadOnly = true; + this.H_Livestock_ID.Visible = false; + // + // H_ReadWeight + // + this.H_ReadWeight.DataPropertyName = "ReadWeight"; + this.H_ReadWeight.HeaderText = ""; + this.H_ReadWeight.Name = "H_ReadWeight"; + this.H_ReadWeight.ReadOnly = true; + this.H_ReadWeight.Width = 30; + // + // H_Index + // + this.H_Index.DataPropertyName = "Index"; + this.H_Index.HeaderText = "序号"; + this.H_Index.Name = "H_Index"; + this.H_Index.ReadOnly = true; + this.H_Index.Width = 65; + // + // H_Technics + // + this.H_Technics.DataPropertyName = "Technics_Name"; + this.H_Technics.HeaderText = "工艺"; + this.H_Technics.Name = "H_Technics"; + this.H_Technics.ReadOnly = true; + this.H_Technics.Width = 65; + // + // H_Livestock_Name + // + this.H_Livestock_Name.DataPropertyName = "Livestock_Name"; + this.H_Livestock_Name.HeaderText = "级别"; + this.H_Livestock_Name.Name = "H_Livestock_Name"; + this.H_Livestock_Name.ReadOnly = true; + this.H_Livestock_Name.Width = 90; + // + // H_Weight + // + this.H_Weight.DataPropertyName = "Weight"; + dataGridViewCellStyle11.Format = "#0.######"; + this.H_Weight.DefaultCellStyle = dataGridViewCellStyle11; + this.H_Weight.HeaderText = "重量"; + this.H_Weight.Name = "H_Weight"; + this.H_Weight.ReadOnly = true; + this.H_Weight.Width = 70; + // + // H_Time + // + this.H_Time.DataPropertyName = "Time"; + dataGridViewCellStyle12.Format = "MM/dd HH:mm"; + dataGridViewCellStyle12.NullValue = null; + this.H_Time.DefaultCellStyle = dataGridViewCellStyle12; + this.H_Time.HeaderText = "时间"; + this.H_Time.Name = "H_Time"; + this.H_Time.ReadOnly = true; + // // GradeFrom // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); @@ -748,6 +748,7 @@ this.Name = "GradeFrom"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "称重定级"; + this.Load += new System.EventHandler(this.GradeFrom_Load); this.groupBox1.ResumeLayout(false); this.groupBox1.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.tangGridView)).EndInit(); @@ -799,14 +800,6 @@ private System.Windows.Forms.Button discontBtn; private System.Windows.Forms.FlowLayoutPanel discontPanel; private System.Windows.Forms.VScrollBar vScrollBar2; - private System.Windows.Forms.DataGridViewTextBoxColumn H_ID; - private System.Windows.Forms.DataGridViewTextBoxColumn H_Livestock_ID; - private System.Windows.Forms.DataGridViewCheckBoxColumn H_ReadWeight; - private System.Windows.Forms.DataGridViewTextBoxColumn H_Index; - private System.Windows.Forms.DataGridViewTextBoxColumn H_Technics; - private System.Windows.Forms.DataGridViewTextBoxColumn H_Livestock_Name; - private System.Windows.Forms.DataGridViewTextBoxColumn H_Weight; - private System.Windows.Forms.DataGridViewTextBoxColumn H_Time; private System.Windows.Forms.VScrollBar tangScrollBar; private System.Windows.Forms.VScrollBar maoScrollBar; private BWP.WinFormControl.UDataGridView maoGridView; @@ -823,5 +816,13 @@ private System.Windows.Forms.DataGridViewTextBoxColumn M_Already; private System.Windows.Forms.DataGridViewButtonColumn M_FinishBtn; private System.Windows.Forms.PictureBox statePic; + private System.Windows.Forms.DataGridViewTextBoxColumn H_SID; + private System.Windows.Forms.DataGridViewTextBoxColumn H_Livestock_ID; + private System.Windows.Forms.DataGridViewCheckBoxColumn H_ReadWeight; + private System.Windows.Forms.DataGridViewTextBoxColumn H_Index; + private System.Windows.Forms.DataGridViewTextBoxColumn H_Technics; + private System.Windows.Forms.DataGridViewTextBoxColumn H_Livestock_Name; + private System.Windows.Forms.DataGridViewTextBoxColumn H_Weight; + private System.Windows.Forms.DataGridViewTextBoxColumn H_Time; } } \ No newline at end of file diff --git a/WeighAndGrading/GradeFrom.cs b/WeighAndGrading/GradeFrom.cs index 0dd5703..ab4d1f0 100644 --- a/WeighAndGrading/GradeFrom.cs +++ b/WeighAndGrading/GradeFrom.cs @@ -32,11 +32,15 @@ namespace WeighAndGrading public Form Generate() { + if (string.IsNullOrEmpty(ButcherAppContext.Context.UrlConfig.OfflineSqlConnection)) + throw new Exception("请先设置离线数据库并保存"); + if (!LocalGradeAndWeightBL.ConnectionTest()) + throw new Exception("离线数据库连接失败"); return this; } #endregion private delegate void InvokeHandler(); - const string DETAIL_PATH = "WeightDetailData"; + public const string DATA_PATH = "G_A_W_Data"; const short TANG_TECH = 0; const short MAO_TECH = 1; List tangList; @@ -44,15 +48,17 @@ namespace WeighAndGrading List details; List localTang, localMao; + string maoFilePath, tangFilePath; bool connection = false; SerialPort weightPort; int maxIndex = 0; - ConcurrentQueue noLivestockList = new ConcurrentQueue(); + ConcurrentQueue noLivestockList; - ConcurrentQueue noWeightList = new ConcurrentQueue(); + ConcurrentQueue noWeightList; Thread syncWork; + Thread syncToServer; #region weightNeed private IDataFormat _dataFormat; private Thread _inQueryThread; @@ -69,9 +75,13 @@ namespace WeighAndGrading maoGridView.AutoGenerateColumns = false; maoGridView.DataSource = null; historyGrid.AutoGenerateColumns = false; + if (!Directory.Exists(DATA_PATH)) + Directory.CreateDirectory(DATA_PATH); + maoFilePath = Path.Combine(DATA_PATH, "MaoList.xml"); + tangFilePath = Path.Combine(DATA_PATH, "TangList.xml"); connection = ButcherAppContext.Context.UserConfig.Connection; AddLivestockBtn(); - BuildDiscontPanel(); + BuildDiscontPanel(true); weightPort = new SerialPort(); this.FormClosing += delegate { @@ -79,6 +89,8 @@ namespace WeighAndGrading DisableWeight(); if (syncWork != null && syncWork.IsAlive) syncWork.Abort(); + if (syncToServer != null && syncToServer.IsAlive) + syncToServer.Abort(); }; } @@ -87,13 +99,14 @@ namespace WeighAndGrading void AddLivestockBtn() { var livestocks = new List>(); + var fileName = Path.Combine(DATA_PATH, "Livestocks.xml"); if (connection) { livestocks = BaseInfoRpcUtil.GetLivestockList(); - XmlUtil.SerializerObjToFile(livestocks, "Livestocks.xml"); + XmlUtil.SerializerObjToFile(livestocks, fileName); } else - livestocks = XmlUtil.DeserializeFromFile>>("Livestocks.xml"); + livestocks = XmlUtil.DeserializeFromFile>>(fileName); foreach (var item in livestocks) { var btn = new Button() { Name = "_" + item.Item1, Text = item.Item2, Tag = item, Size = new Size(90, 75), TextAlign = ContentAlignment.MiddleCenter, Margin = new Padding { All = 15 }, Font = new Font("宋体", 18) }; @@ -113,25 +126,7 @@ namespace WeighAndGrading modifyDetail.Livestock_Name = livestockTag.Item2; modifyDetail.Technics = livestockTag.Item3; modifyDetail.Technics_Name = livestockTag.Item3 == TANG_TECH ? "烫褪" : "毛剥"; - connection = LoginRpcUtil.TestConnection(); - SetImage(); - if (connection) - GradeAndWeightRpc.UpdateLivestock(modifyDetail.ID, modifyDetail.Livestock_ID, modifyDetail.Livestock_Name, modifyDetail.Technics, modifyDetail.Technics_Name); - else - { - var local = GetCurrentDetail(); - var f = local.FirstOrDefault(x => x.Index == modifyDetail.Index); - if (f == null) - local.Add(modifyDetail); - else - { - f.Livestock_ID= modifyDetail.Livestock_ID; - f.Livestock_Name = modifyDetail.Livestock_Name; - f.Technics = modifyDetail.Technics; - f.Technics_Name = modifyDetail.Technics_Name; - } - SaveDetailToLocal(local, null); - } + LocalGradeAndWeightBL.Update(modifyDetail, "Livestock_ID", "Livestock_Name", "Technics", "Technics_Name"); historyGrid.Refresh(); modifyDetail = null; modifyPanel.Hide(); @@ -170,27 +165,13 @@ namespace WeighAndGrading private void syncBtn_Click(object sender, EventArgs e) { - if (!Directory.Exists(DETAIL_PATH)) - Directory.CreateDirectory(DETAIL_PATH); - connection = LoginRpcUtil.TestConnection(); - SetImage(); - if (connection) - details = GradeAndWeightRpc.GetDetails(butcherTimeInput.Date.Value, 50); - else - details = GetLocalDetail(); + details = LocalGradeAndWeightBL.GetDetails(butcherTimeInput.Date.Value, 50); FillQueue(); BindDetailGrid(); if (details.Any()) - { maxIndex = details.First().Index; - SaveLastIndex(maxIndex); - } - else - maxIndex = GetLastIndex(); if (syncWork == null || !syncWork.IsAlive) { - localMao = XmlUtil.DeserializeFromFile>("maoList.xml"); - localTang = XmlUtil.DeserializeFromFile>("tangList.xml"); syncWork = new Thread(Sync); syncWork.Start(); syncBtn.BackColor = Color.FromArgb(15, 215, 107); @@ -210,15 +191,8 @@ namespace WeighAndGrading { this.Invoke(new InvokeHandler(delegate() { - connection = LoginRpcUtil.TestConnection(); - SetImage(); BindTangGrid(); BindMaoGrid(); - if (connection) - { - SyncLocalDetails(); - SyncLocalMainFinish(); - } })); Thread.Sleep(5000); } @@ -248,6 +222,7 @@ namespace WeighAndGrading void BindTangGrid() { + VerifyConnection(); if (connection) tangList = GradeAndWeightRpc.GetGradeAndWeightList(butcherTimeInput.Date.Value, true); else @@ -291,6 +266,7 @@ namespace WeighAndGrading void BindMaoGrid() { + VerifyConnection(); if (connection) maoList = GradeAndWeightRpc.GetGradeAndWeightList(butcherTimeInput.Date.Value, false); else @@ -342,7 +318,7 @@ namespace WeighAndGrading { foreach (DataGridViewRow row in historyGrid.Rows) { - if ((long)row.Cells["H_ID"].Value == lastSelectID) + if ((long)row.Cells["H_SID"].Value == lastSelectID) { historyGrid.CurrentCell = row.Cells[row.Cells.Count - 1]; break; @@ -601,7 +577,7 @@ namespace WeighAndGrading var tech = livestock.Item3 == TANG_TECH ? "烫褪" : "毛剥"; GradeAndWeight_Detail first; - if (noLivestockList.TryPeek(out first) && first.Livestock_ID == 0) + if (noLivestockList.TryPeek(out first) && first.Livestock_ID == null) { noLivestockList.TryDequeue(out first); if (currentRow != null) @@ -617,34 +593,12 @@ namespace WeighAndGrading SetBtnUnCheck(disBtn); disBtn = null; } - connection = LoginRpcUtil.TestConnection(); - SetImage(); - if (connection) - GradeAndWeightRpc.UpdateOrInsertDetail(first, true); - else - { - var local = GetCurrentDetail(); - var f = local.FirstOrDefault(x => x.Index == first.Index); - if (f == null) - local.Add(first); - else - { - f.OrderDetail_ID = first.OrderDetail_ID; - f.Date = first.Date; - f.Livestock_ID = first.Livestock_ID; - f.Livestock_Name = first.Livestock_Name; - f.Technics = first.Technics; - f.Technics_Name = first.Technics_Name; - f.Weight = first.Weight; - } - SaveDetailToLocal(local, null); - } + LocalGradeAndWeightBL.Update(first, "OrderDetail_ID", "Date", "Livestock_ID", "Livestock_Name", "Technics", "Technics_Name", "Weight"); historyGrid.Refresh(); } else//add { maxIndex++; - SaveLastIndex(maxIndex); var entity = new GradeAndWeight_Detail(); entity.Index = maxIndex; if (currentRow != null) @@ -665,16 +619,7 @@ namespace WeighAndGrading if (details.Count == 50) details.RemoveAt(49); details.Insert(0, entity); - connection = LoginRpcUtil.TestConnection(); - SetImage(); - if (connection) - GradeAndWeightRpc.UpdateOrInsertDetail(entity, true); - else - { - var local = GetCurrentDetail(); - local.Add(entity); - SaveDetailToLocal(local, null); - } + LocalGradeAndWeightBL.Insert(entity); noWeightList.Enqueue(entity); BindDetailGrid(); } @@ -706,26 +651,12 @@ namespace WeighAndGrading first.Weight = (first.Weight ?? 0) + weight; else first.Weight = weight; - connection = LoginRpcUtil.TestConnection(); - SetImage(); - if (connection) - GradeAndWeightRpc.UpdateOrInsertDetail(first); - else - { - var local = GetCurrentDetail(); - var f = local.FirstOrDefault(x => x.Index == first.Index); - if (f == null) - local.Add(first); - else - f.Weight = first.Weight; - SaveDetailToLocal(local, null); - } + LocalGradeAndWeightBL.Update(first, "Weight"); historyGrid.Refresh(); } else//add { maxIndex++; - SaveLastIndex(maxIndex); var entity = new GradeAndWeight_Detail(); entity.Index = maxIndex; entity.Weight = (entity.Weight ?? 0) + weight; @@ -734,16 +665,7 @@ namespace WeighAndGrading if (details.Count == 50) details.RemoveAt(49); details.Insert(0, entity); - connection = LoginRpcUtil.TestConnection(); - SetImage(); - if (connection) - GradeAndWeightRpc.UpdateOrInsertDetail(entity); - else - { - var local = GetCurrentDetail(); - local.Add(entity); - SaveDetailToLocal(local, null); - } + LocalGradeAndWeightBL.Insert(entity); noLivestockList.Enqueue(entity); BindDetailGrid(); } @@ -763,10 +685,10 @@ namespace WeighAndGrading if (e.RowIndex < 0) return; var currentRow = historyGrid.CurrentRow.DataBoundItem as GradeAndWeight_Detail; - lastSelectID = currentRow.ID; + lastSelectID = currentRow.SID; if (e.ColumnIndex == 2) { - if (lastCheckItem != null && lastCheckItem.ID != currentRow.ID) + if (lastCheckItem != null && lastCheckItem.SID != currentRow.SID) lastCheckItem.ReadWeight = false; lastCheckItem = currentRow; lastCheckItem.ReadWeight = !lastCheckItem.ReadWeight; @@ -782,7 +704,7 @@ namespace WeighAndGrading foreach (var item in details) { stack.Push(item); - if (item.ID == lastCheckItem.ID) + if (item.SID == lastCheckItem.SID) break; } while (stack.Count > 0) @@ -833,13 +755,17 @@ namespace WeighAndGrading if (entity.Finish) return; entity.Finish = true; - connection = LoginRpcUtil.TestConnection(); - SetImage(); + VerifyConnection(); if (connection) GradeAndWeightRpc.SetGradeFinish(entity.OrderDetail_ID, TANG_TECH); else { - SaveEntityToLocal(localTang, entity.OrderDetail_ID, true); + localTang = XmlUtil.DeserializeFromFile>(tangFilePath); + if (!localTang.Contains(entity.OrderDetail_ID)) + { + localTang.Add(entity.OrderDetail_ID); + SaveEntityToLocal(true); + } var f = tangList.FirstOrDefault(x => x.OrderDetail_ID == entity.OrderDetail_ID); if (f != null) f.Finish = true; @@ -880,13 +806,17 @@ namespace WeighAndGrading if (entity.Finish) return; entity.Finish = true; - connection = LoginRpcUtil.TestConnection(); - SetImage(); + VerifyConnection(); if (connection) GradeAndWeightRpc.SetGradeFinish(entity.OrderDetail_ID, MAO_TECH); else { - SaveEntityToLocal(localMao, entity.OrderDetail_ID, false); + localMao = XmlUtil.DeserializeFromFile>(maoFilePath); + if (!localMao.Contains(entity.OrderDetail_ID)) + { + localMao.Add(entity.OrderDetail_ID); + SaveEntityToLocal(false); + } var f = maoList.FirstOrDefault(x => x.OrderDetail_ID == entity.OrderDetail_ID); if (f != null) f.Finish = true; @@ -898,20 +828,23 @@ namespace WeighAndGrading private void discontBtn_Click(object sender, EventArgs e) { if (new BodyDiscontSetting().ShowDialog() == DialogResult.OK) - BuildDiscontPanel(); + BuildDiscontPanel(false); } Button disBtn = null; - void BuildDiscontPanel() + void BuildDiscontPanel(bool firstLoad) { + var fileName = Path.Combine(DATA_PATH, "Disconts.xml"); var disconts = new List(); + if (!firstLoad) + VerifyConnection(); if (connection) { disconts = GradeAndWeightRpc.GetBodyDiscontItem(); - XmlUtil.SerializerObjToFile(disconts, "Disconts.xml"); + XmlUtil.SerializerObjToFile(disconts, fileName); } else - disconts = XmlUtil.DeserializeFromFile>("Disconts.xml"); + disconts = XmlUtil.DeserializeFromFile>(fileName); disconts = disconts.Where(x => x.Discont > 0).OrderBy(x => x.ID).ToList(); discontPanel.Controls.Clear(); @@ -935,20 +868,7 @@ namespace WeighAndGrading else { modifyDetail.Weight = (modifyDetail.Weight ?? 0) - Convert.ToDecimal(btn.Tag); - connection = LoginRpcUtil.TestConnection(); - SetImage(); - if (connection) - GradeAndWeightRpc.UpdateWeight(modifyDetail.ID, modifyDetail.Weight); - else - { - var local = GetCurrentDetail(); - var f = local.FirstOrDefault(x => x.Index == modifyDetail.Index); - if (f == null) - local.Add(modifyDetail); - else - f.Weight = modifyDetail.Weight; - SaveDetailToLocal(local, null); - } + LocalGradeAndWeightBL.Update(modifyDetail, "Weight"); historyGrid.Refresh(); modifyDetail = null; modifyPanel.Hide(); @@ -1016,141 +936,89 @@ namespace WeighAndGrading }; } - void SaveEntityToLocal(List list, long? orderDetailID, bool tang) + object _fileSaveObj = new object(); + void SaveEntityToLocal(bool tang) { - lock (_obj) + lock (_fileSaveObj) { - if (orderDetailID.HasValue) - { - if (!list.Contains(orderDetailID.Value)) - list.Add(orderDetailID.Value); - } - var fileName = "maoList.xml"; if (tang) - fileName = "tangList.xml"; - XmlUtil.SerializerObjToFile(list, fileName); + XmlUtil.SerializerObjToFile(localTang, tangFilePath); + else + XmlUtil.SerializerObjToFile(localMao, maoFilePath); } } - void SaveDetailToLocal(List details, string fileName) + void SyncLocalMainFinish(ref List list, bool tang) { - lock (_obj) + string path = maoFilePath; + short tech = MAO_TECH; + if (tang) { - if (string.IsNullOrEmpty(fileName)) - fileName = Path.Combine(DETAIL_PATH, string.Format("{0:yyyyMMdd}_Data.xml", butcherTimeInput.Date.Value)); - XmlUtil.SerializerObjToFile(details, fileName); + path = tangFilePath; + tech = TANG_TECH; } - } - List GetLocalDetail() - { - var fileName = Path.Combine(DETAIL_PATH, string.Format("{0:yyyyMMdd}_Data.xml", butcherTimeInput.Date.Value)); - var q = XmlUtil.DeserializeFromFile>(fileName).OrderByDescending(x => x.Index).ToList(); + list = XmlUtil.DeserializeFromFile>(path); + var count = list.Count; + if (count == 0) + return; + if (count >= 30) + count = 30; - var r = new List(); - foreach (var item in q) + var sync = list.GetRange(0, count); + foreach (var item in sync) { - r.Add(item); - if (r.Count == 50) - break; + GradeAndWeightRpc.SetGradeFinish(item, tech); + list.Remove(item); } - return r; + SaveEntityToLocal(tang); } - List GetCurrentDetail() - { - var fileName = Path.Combine(DETAIL_PATH, string.Format("{0:yyyyMMdd}_Data.xml", butcherTimeInput.Date.Value)); - return XmlUtil.DeserializeFromFile>(fileName); - } - void SaveLastIndex(int idx) + bool? last = null; + void VerifyConnection() { - lock (_obj) - { - var fileName = Path.Combine(DETAIL_PATH, string.Format("{0:yyyyMMdd}_Index.xml", butcherTimeInput.Date.Value)); - XmlUtil.SerializerObjToFile(new DetailLastIndex() { Index = idx }, fileName); - } - } - - int GetLastIndex() - { - var fileName = Path.Combine(DETAIL_PATH, string.Format("{0:yyyyMMdd}_Index.xml", butcherTimeInput.Date.Value)); - var last = XmlUtil.DeserializeFromFile(fileName); - return last.Index; + connection = LoginRpcUtil.TestConnection(); + if (last == connection) + return; + var png = "stop.png"; + if (connection) + png = "working.png"; + var imgPath = Path.Combine(Application.StartupPath, "BWP.WinFormControl.dll"); + var s = Assembly.LoadFile(imgPath).GetManifestResourceStream("BWP.WinFormControl.Images." + png); + statePic.Image = Image.FromStream(s); + statePic.Refresh(); + last = connection; } - void SyncLocalMainFinish() + private void GradeFrom_Load(object sender, EventArgs e) { - var mao = XmlUtil.DeserializeFromFile>("maoList.xml"); - if (mao.Any()) - { - foreach (var item in mao) - { - GradeAndWeightRpc.SetGradeFinish(item, MAO_TECH); - localMao.Remove(item); - } - mao.Clear(); - SaveEntityToLocal(mao, null, false); - } - var tang = XmlUtil.DeserializeFromFile>("tangList.xml"); - if (tang.Any()) - { - foreach (var item in tang) - { - GradeAndWeightRpc.SetGradeFinish(item, TANG_TECH); - localTang.Remove(item); - } - tang.Clear(); - SaveEntityToLocal(tang, null, true); - } + syncToServer = new Thread(ToServerTask); + syncToServer.Start(); } - void SyncLocalDetails() + void ToServerTask() { - var currentTime = string.Format("{0:yyyyMMdd}_Data.xml", butcherTimeInput.Date.Value); - var files = Directory.GetFiles(DETAIL_PATH, "_Data.xml"); - foreach (var file in files) + while (true) { - bool math = file.StartsWith(currentTime); - var details = XmlUtil.DeserializeFromFile>(file); - var clone = details.ToList(); - bool needRefsh = false; - foreach (var item in clone) + this.Invoke(new InvokeHandler(delegate() { - GradeAndWeightRpc.UpdateOrInsertDetail(item); - var first = details.First(x => x.Index == item.Index); - details.Remove(first); - SaveDetailToLocal(details, file); - if (math) + VerifyConnection(); + if (connection) { - var showTag = details.FirstOrDefault(x => x.Index == item.Index); - if (showTag != null) + try { - if (!needRefsh) - needRefsh = true; - showTag.ID = item.ID; + SyncLocalMainFinish(ref localTang, true); + SyncLocalMainFinish(ref localMao, false); + LocalGradeAndWeightBL.Sync(); + } + catch(Exception ex) { + File.WriteAllText(string.Format("{0:yyyyMMddHHmmss}log.txt", DateTime.Now), "错误:" + ex.Message + " \n详细信息:" + ex.StackTrace); } } - historyGrid.Refresh(); - } - if (!math) - File.Delete(file); + })); + Thread.Sleep(2000); } } - - bool last = false; - void SetImage() - { - if (last == connection) - return; - var png = "stop.png"; - if (connection) - png = "working.png"; - var imgPath = Path.Combine(Application.StartupPath, "BWP.WinFormControl.dll"); - var s = Assembly.LoadFile(imgPath).GetManifestResourceStream("BWP.WinFormControl.Images." + png); - statePic.Image = Image.FromStream(s); - statePic.Refresh(); - last = connection; - } } } diff --git a/WeighAndGrading/GradeFrom.resx b/WeighAndGrading/GradeFrom.resx index b02a311..7b5224b 100644 --- a/WeighAndGrading/GradeFrom.resx +++ b/WeighAndGrading/GradeFrom.resx @@ -153,7 +153,7 @@ True - + True diff --git a/WeighAndGrading/WeighAndGrading.csproj b/WeighAndGrading/WeighAndGrading.csproj index cddb1a0..5d66b82 100644 --- a/WeighAndGrading/WeighAndGrading.csproj +++ b/WeighAndGrading/WeighAndGrading.csproj @@ -34,7 +34,6 @@ false -