Browse Source

修改。

master
yibo 8 years ago
parent
commit
733501cfd4
17 changed files with 454 additions and 393 deletions
  1. +2
    -2
      BO/BO.csproj
  2. +17
    -5
      BO/BO/Bill/GradeAndWeight/GradeAndWeight_Detail.cs
  3. +1
    -3
      BO/BO/Bill/WeightBill/WeightBill.cs
  4. +120
    -24
      BO/Utils/BillRpc/GradeAndWeightRpc.cs
  5. +65
    -5
      BO/Utils/LoginRpcUtil.cs
  6. +2
    -0
      BO/Utils/ServerUrlConfig.cs
  7. +1
    -1
      BWP.WinFormControl/BWP.WinFormControl.csproj
  8. +0
    -8
      ButcherManageClient/ButcherManageClient.csproj
  9. +29
    -4
      ButcherManageClient/SettingForm.Designer.cs
  10. +4
    -0
      ButcherManageClient/SettingForm.cs
  11. +0
    -12
      ButcherWeight/ButcherWeight.csproj
  12. +0
    -1
      OrderConfirm/OrderConfirm.csproj
  13. +20
    -3
      WeighAndGrading/BodyDiscontSetting.cs
  14. +85
    -84
      WeighAndGrading/GradeFrom.Designer.cs
  15. +107
    -239
      WeighAndGrading/GradeFrom.cs
  16. +1
    -1
      WeighAndGrading/GradeFrom.resx
  17. +0
    -1
      WeighAndGrading/WeighAndGrading.csproj

+ 2
- 2
BO/BO.csproj View File

@ -32,7 +32,7 @@
<ItemGroup> <ItemGroup>
<Reference Include="Forks.EnterpriseServices, Version=3.1.0.0, Culture=neutral, PublicKeyToken=7254430f49d10aae, processorArchitecture=MSIL"> <Reference Include="Forks.EnterpriseServices, Version=3.1.0.0, Culture=neutral, PublicKeyToken=7254430f49d10aae, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>D:\BwpB3Project\tsref\Debug\Forks.EnterpriseServices.dll</HintPath>
<HintPath>..\..\..\tsref\Debug\Forks.EnterpriseServices.dll</HintPath>
</Reference> </Reference>
<Reference Include="Forks.JsonRpc.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7254430f49d10aae, processorArchitecture=MSIL"> <Reference Include="Forks.JsonRpc.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7254430f49d10aae, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
@ -40,7 +40,7 @@
</Reference> </Reference>
<Reference Include="Forks.Utils, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7254430f49d10aae, processorArchitecture=MSIL"> <Reference Include="Forks.Utils, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7254430f49d10aae, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>D:\BwpB3Project\tsref\Debug\Forks.Utils.dll</HintPath>
<HintPath>..\..\..\tsref\Debug\Forks.Utils.dll</HintPath>
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />


+ 17
- 5
BO/BO/Bill/GradeAndWeight/GradeAndWeight_Detail.cs View File

@ -1,4 +1,5 @@
using System;
using Forks.EnterpriseServices.DomainObjects2;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -6,10 +7,16 @@ using System.Threading.Tasks;
namespace BO.BO.Bill namespace BO.BO.Bill
{ {
[MapToTable("GradeAndWeight_Detail")]
[KeyField("SID", KeyGenType.identity)]
public class GradeAndWeight_Detail public class GradeAndWeight_Detail
{ {
public long ID { get; set; }
/// <summary>
/// 本地ID
/// </summary>
public long SID { get; set; }
[NonDmoProperty]
public bool ReadWeight { get; set; } public bool ReadWeight { get; set; }
public long? OrderDetail_ID { get; set; } public long? OrderDetail_ID { get; set; }
@ -18,11 +25,11 @@ namespace BO.BO.Bill
public DateTime Date { get; set; } public DateTime Date { get; set; }
public short Technics { get; set; }
public short? Technics { get; set; }
public string Technics_Name { 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; } public string Livestock_Name { get; set; }
@ -30,6 +37,11 @@ namespace BO.BO.Bill
public DateTime Time { get; set; } public DateTime Time { get; set; }
public DateTime TempTime { get { return Time; } }
/// <summary>
/// ServerID
/// </summary>
public long ID { get; set; }
public bool Sync { get; set; }
} }
} }

+ 1
- 3
BO/BO/Bill/WeightBill/WeightBill.cs View File

@ -1,10 +1,8 @@
using Forks.EnterpriseServices.DomainObjects2;
using System;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using TSingSoft.WebPluginFramework;
namespace BO.BO namespace BO.BO
{ {


+ 120
- 24
BO/Utils/BillRpc/GradeAndWeightRpc.cs View File

@ -1,5 +1,8 @@
using BO.BO.BaseInfo; using BO.BO.BaseInfo;
using BO.BO.Bill; using BO.BO.Bill;
using Forks.EnterpriseServices.DomainObjects2;
using Forks.EnterpriseServices.DomainObjects2.DQuery;
using Forks.EnterpriseServices.SqlDoms;
using Forks.JsonRpc.Client; using Forks.JsonRpc.Client;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -7,6 +10,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Web.Script.Serialization; using System.Web.Script.Serialization;
using TSingSoft.WebPluginFramework;
namespace BO.Utils.BillRpc namespace BO.Utils.BillRpc
{ {
@ -14,33 +18,13 @@ namespace BO.Utils.BillRpc
{ {
static JavaScriptSerializer serializer = new JavaScriptSerializer(); static JavaScriptSerializer serializer = new JavaScriptSerializer();
public static List<GradeAndWeight> GetGradeAndWeightList(DateTime date,bool isTang)
public static List<GradeAndWeight> GetGradeAndWeightList(DateTime date, bool isTang)
{ {
const string method = "/MainSystem/B3ClientService/Rpcs/BillRpc/GradeAndWeightRpc/GetGradeAndWeightList"; const string method = "/MainSystem/B3ClientService/Rpcs/BillRpc/GradeAndWeightRpc/GetGradeAndWeightList";
var result = RpcFacade.Call<string>(method, date, isTang); var result = RpcFacade.Call<string>(method, date, isTang);
return serializer.Deserialize<List<GradeAndWeight>>(result); return serializer.Deserialize<List<GradeAndWeight>>(result);
} }
public static List<GradeAndWeight_Detail> GetDetails(DateTime date, int top = 15)
{
const string method = "/MainSystem/B3ClientService/Rpcs/BillRpc/GradeAndWeightRpc/GetDetailsList";
var result = RpcFacade.Call<string>(method, date, top);
result = result.ESerializeDateTime();
return serializer.Deserialize<List<GradeAndWeight_Detail>>(result);
}
public static void UpdateOrInsertDetail(GradeAndWeight_Detail detail, bool fillTechnics = false)
{
const string method = "/MainSystem/B3ClientService/Rpcs/BillRpc/GradeAndWeightRpc/UpdateOrInsertDetail";
detail.ID = RpcFacade.Call<long>(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<int>(method, id, liveStockID, liveStockName, technics, technicsName);
}
public static void SetGradeFinish(long orderDetailID, short technics) public static void SetGradeFinish(long orderDetailID, short technics)
{ {
const string method = "/MainSystem/B3ClientService/Rpcs/BillRpc/GradeAndWeightRpc/SetGradeFinish"; 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"; const string method = "/MainSystem/B3ClientService/Rpcs/BillRpc/GradeAndWeightRpc/SaveBodyDiscontItemSetting";
RpcFacade.Call<int>(method, serializer.Serialize(list)); RpcFacade.Call<int>(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<GradeAndWeight_Detail> 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<GradeAndWeight_Detail>().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<long>(method, serializer.Serialize(detail));
SetDetailSynced(detail, id);
}
}
static IEnumerable<GradeAndWeight_Detail> 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<GradeAndWeight_Detail>();
}
}
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<int>(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();
}
} }
} }
} }

+ 65
- 5
BO/Utils/LoginRpcUtil.cs View File

@ -4,6 +4,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Net.NetworkInformation;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -50,17 +51,76 @@ namespace BO.Utils
var url = ButcherAppContext.Context.UrlConfig.ServerUrl; var url = ButcherAppContext.Context.UrlConfig.ServerUrl;
if (string.IsNullOrEmpty(url)) if (string.IsNullOrEmpty(url))
return false; 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 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; return false;
} }
finally
{
client.Close();
}
} }
} }
} }

+ 2
- 0
BO/Utils/ServerUrlConfig.cs View File

@ -9,5 +9,7 @@ namespace BO.Utils
public class ServerUrlConfig public class ServerUrlConfig
{ {
public string ServerUrl { get; set; } public string ServerUrl { get; set; }
public string OfflineSqlConnection { get; set; }
} }
} }

+ 1
- 1
BWP.WinFormControl/BWP.WinFormControl.csproj View File

@ -32,7 +32,7 @@
<ItemGroup> <ItemGroup>
<Reference Include="Forks.JsonRpc.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7254430f49d10aae, processorArchitecture=MSIL"> <Reference Include="Forks.JsonRpc.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7254430f49d10aae, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\BwpB3Project\tsref\Debug\Forks.JsonRpc.Client.dll</HintPath>
<HintPath>..\..\..\tsref\Debug\Forks.JsonRpc.Client.dll</HintPath>
</Reference> </Reference>
<Reference Include="PresentationCore" /> <Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" /> <Reference Include="PresentationFramework" />


+ 0
- 8
ButcherManageClient/ButcherManageClient.csproj View File

@ -35,18 +35,10 @@
<ApplicationIcon>pig [128x128].ico</ApplicationIcon> <ApplicationIcon>pig [128x128].ico</ApplicationIcon>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Forks.EnterpriseServices, Version=3.1.0.0, Culture=neutral, PublicKeyToken=7254430f49d10aae, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\BwpB3Project\tsref\Debug\Forks.EnterpriseServices.dll</HintPath>
</Reference>
<Reference Include="Forks.JsonRpc.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7254430f49d10aae, processorArchitecture=MSIL"> <Reference Include="Forks.JsonRpc.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7254430f49d10aae, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\BwpB3Project\tsref\Debug\Forks.JsonRpc.Client.dll</HintPath> <HintPath>..\..\..\..\BwpB3Project\tsref\Debug\Forks.JsonRpc.Client.dll</HintPath>
</Reference> </Reference>
<Reference Include="Forks.Utils, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7254430f49d10aae, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\BwpB3Project\tsref\Debug\Forks.Utils.dll</HintPath>
</Reference>
<Reference Include="PresentationCore" /> <Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" /> <Reference Include="PresentationFramework" />
<Reference Include="System" /> <Reference Include="System" />


+ 29
- 4
ButcherManageClient/SettingForm.Designer.cs View File

@ -32,12 +32,14 @@
this.saveBtn = new System.Windows.Forms.Button(); this.saveBtn = new System.Windows.Forms.Button();
this.uTextBoxWithPad1 = new BWP.WinFormControl.UTextBoxWithPad(); this.uTextBoxWithPad1 = new BWP.WinFormControl.UTextBoxWithPad();
this.label1 = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label();
this.offlineSqlConInput = new BWP.WinFormControl.UTextBoxWithPad();
this.label2 = new System.Windows.Forms.Label();
this.SuspendLayout(); this.SuspendLayout();
// //
// cancelBtn // cancelBtn
// //
this.cancelBtn.Font = new System.Drawing.Font("宋体", 20F); 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.Name = "cancelBtn";
this.cancelBtn.Size = new System.Drawing.Size(81, 53); this.cancelBtn.Size = new System.Drawing.Size(81, 53);
this.cancelBtn.TabIndex = 7; this.cancelBtn.TabIndex = 7;
@ -48,7 +50,7 @@
// saveBtn // saveBtn
// //
this.saveBtn.Font = new System.Drawing.Font("宋体", 20F); 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.Name = "saveBtn";
this.saveBtn.Size = new System.Drawing.Size(81, 53); this.saveBtn.Size = new System.Drawing.Size(81, 53);
this.saveBtn.TabIndex = 6; this.saveBtn.TabIndex = 6;
@ -75,17 +77,38 @@
this.label1.TabIndex = 4; this.label1.TabIndex = 4;
this.label1.Text = "服务器地址:"; 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 // SettingForm
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 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.cancelBtn);
this.Controls.Add(this.saveBtn); this.Controls.Add(this.saveBtn);
this.Controls.Add(this.uTextBoxWithPad1); this.Controls.Add(this.uTextBoxWithPad1);
this.Controls.Add(this.label1); this.Controls.Add(this.label1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.Name = "SettingForm"; this.Name = "SettingForm";
this.Text = "服务器配置"; this.Text = "服务器配置";
this.ResumeLayout(false); this.ResumeLayout(false);
@ -99,5 +122,7 @@
private System.Windows.Forms.Button saveBtn; private System.Windows.Forms.Button saveBtn;
private BWP.WinFormControl.UTextBoxWithPad uTextBoxWithPad1; private BWP.WinFormControl.UTextBoxWithPad uTextBoxWithPad1;
private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label1;
private BWP.WinFormControl.UTextBoxWithPad offlineSqlConInput;
private System.Windows.Forms.Label label2;
} }
} }

+ 4
- 0
ButcherManageClient/SettingForm.cs View File

@ -19,6 +19,9 @@ namespace ButcherManageClient
{ {
InitializeComponent(); InitializeComponent();
uTextBoxWithPad1.Text = ButcherAppContext.Context.UrlConfig.ServerUrl; 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; mInited = rpcFacadeInited;
} }
@ -33,6 +36,7 @@ namespace ButcherManageClient
if (string.IsNullOrEmpty(uri)) if (string.IsNullOrEmpty(uri))
throw new Exception("请先设置服务器地址"); throw new Exception("请先设置服务器地址");
ButcherAppContext.Context.UrlConfig.ServerUrl = uri; ButcherAppContext.Context.UrlConfig.ServerUrl = uri;
ButcherAppContext.Context.UrlConfig.OfflineSqlConnection = offlineSqlConInput.Text.Trim();
ButcherAppContext.Context.Save(); ButcherAppContext.Context.Save();
if (mInited) if (mInited)


+ 0
- 12
ButcherWeight/ButcherWeight.csproj View File

@ -34,18 +34,6 @@
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\tsref\Debug\BwpClientPrint.dll</HintPath> <HintPath>..\..\..\tsref\Debug\BwpClientPrint.dll</HintPath>
</Reference> </Reference>
<Reference Include="Forks.EnterpriseServices, Version=3.1.0.0, Culture=neutral, PublicKeyToken=7254430f49d10aae, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\BwpB3Project\tsref\Debug\Forks.EnterpriseServices.dll</HintPath>
</Reference>
<Reference Include="Forks.JsonRpc.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7254430f49d10aae, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\BwpB3Project\tsref\Debug\Forks.JsonRpc.Client.dll</HintPath>
</Reference>
<Reference Include="Forks.Utils, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7254430f49d10aae, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\BwpB3Project\tsref\Debug\Forks.Utils.dll</HintPath>
</Reference>
<Reference Include="PresentationCore" /> <Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" /> <Reference Include="PresentationFramework" />
<Reference Include="System" /> <Reference Include="System" />


+ 0
- 1
OrderConfirm/OrderConfirm.csproj View File

@ -30,7 +30,6 @@
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Forks.JsonRpc.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7254430f49d10aae, processorArchitecture=MSIL" />
<Reference Include="PresentationCore" /> <Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" /> <Reference Include="PresentationFramework" />
<Reference Include="System" /> <Reference Include="System" />


+ 20
- 3
WeighAndGrading/BodyDiscontSetting.cs View File

@ -1,5 +1,6 @@
using BO; using BO;
using BO.BO.BaseInfo; using BO.BO.BaseInfo;
using BO.Utils;
using BO.Utils.BillRpc; using BO.Utils.BillRpc;
using BWP.WinFormControl; using BWP.WinFormControl;
using System; using System;
@ -7,6 +8,7 @@ using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Data; using System.Data;
using System.Drawing; using System.Drawing;
using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -17,10 +19,12 @@ namespace WeighAndGrading
public partial class BodyDiscontSetting : Form public partial class BodyDiscontSetting : Form
{ {
List<BodyDiscontItem> list; List<BodyDiscontItem> list;
string fileName;
public BodyDiscontSetting() public BodyDiscontSetting()
{ {
InitializeComponent(); InitializeComponent();
list = GradeAndWeightRpc.GetBodyDiscontItem().OrderBy(x => x.ID).ToList();
fileName = Path.Combine(GradeFrom.DATA_PATH, "Disconts.xml");
list = XmlUtil.DeserializeFromFile<List<BodyDiscontItem>>(fileName);
uDataGridView1.DataSource = list; uDataGridView1.DataSource = list;
uDataGridView1.Refresh(); uDataGridView1.Refresh();
} }
@ -34,7 +38,19 @@ namespace WeighAndGrading
var entity = row.DataBoundItem as BodyDiscontItem; var entity = row.DataBoundItem as BodyDiscontItem;
list.Add(new CTuple<long, decimal?>(entity.ID, entity.Discont)); list.Add(new CTuple<long, decimal?>(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) if (!changed)
changed = true; changed = true;
MessageBox.Show("保存成功!"); MessageBox.Show("保存成功!");
@ -42,7 +58,8 @@ namespace WeighAndGrading
private void closeBtn_Click(object sender, EventArgs e) private void closeBtn_Click(object sender, EventArgs e)
{ {
DialogResult = DialogResult.OK;
if (changed)
DialogResult = DialogResult.OK;
this.Close(); this.Close();
} }


+ 85
- 84
WeighAndGrading/GradeFrom.Designer.cs View File

@ -73,14 +73,6 @@
this.vScrollBar2 = new System.Windows.Forms.VScrollBar(); this.vScrollBar2 = new System.Windows.Forms.VScrollBar();
this.label12 = new System.Windows.Forms.Label(); this.label12 = new System.Windows.Forms.Label();
this.historyGrid = new BWP.WinFormControl.UDataGridView(); 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.enableWeight = new System.Windows.Forms.CheckBox();
this.isPrintCheckBox = new System.Windows.Forms.CheckBox(); this.isPrintCheckBox = new System.Windows.Forms.CheckBox();
this.printBtn = new System.Windows.Forms.Button(); this.printBtn = new System.Windows.Forms.Button();
@ -95,6 +87,14 @@
this.discontBtn = new System.Windows.Forms.Button(); this.discontBtn = new System.Windows.Forms.Button();
this.discontPanel = new System.Windows.Forms.FlowLayoutPanel(); this.discontPanel = new System.Windows.Forms.FlowLayoutPanel();
this.statePic = new System.Windows.Forms.PictureBox(); 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(); this.groupBox1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.tangGridView)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.tangGridView)).BeginInit();
this.groupBox2.SuspendLayout(); this.groupBox2.SuspendLayout();
@ -475,7 +475,7 @@
this.historyGrid.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle10; this.historyGrid.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle10;
this.historyGrid.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.historyGrid.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.historyGrid.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.historyGrid.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.H_ID,
this.H_SID,
this.H_Livestock_ID, this.H_Livestock_ID,
this.H_ReadWeight, this.H_ReadWeight,
this.H_Index, this.H_Index,
@ -498,73 +498,6 @@
this.historyGrid.TabIndex = 0; this.historyGrid.TabIndex = 0;
this.historyGrid.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.historyGrid_CellClick); 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 // enableWeight
// //
this.enableWeight.AutoCheck = false; this.enableWeight.AutoCheck = false;
@ -718,6 +651,73 @@
this.statePic.TabIndex = 38; this.statePic.TabIndex = 38;
this.statePic.TabStop = false; 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 // GradeFrom
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
@ -748,6 +748,7 @@
this.Name = "GradeFrom"; this.Name = "GradeFrom";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "称重定级"; this.Text = "称重定级";
this.Load += new System.EventHandler(this.GradeFrom_Load);
this.groupBox1.ResumeLayout(false); this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout(); this.groupBox1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.tangGridView)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.tangGridView)).EndInit();
@ -799,14 +800,6 @@
private System.Windows.Forms.Button discontBtn; private System.Windows.Forms.Button discontBtn;
private System.Windows.Forms.FlowLayoutPanel discontPanel; private System.Windows.Forms.FlowLayoutPanel discontPanel;
private System.Windows.Forms.VScrollBar vScrollBar2; 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 tangScrollBar;
private System.Windows.Forms.VScrollBar maoScrollBar; private System.Windows.Forms.VScrollBar maoScrollBar;
private BWP.WinFormControl.UDataGridView maoGridView; private BWP.WinFormControl.UDataGridView maoGridView;
@ -823,5 +816,13 @@
private System.Windows.Forms.DataGridViewTextBoxColumn M_Already; private System.Windows.Forms.DataGridViewTextBoxColumn M_Already;
private System.Windows.Forms.DataGridViewButtonColumn M_FinishBtn; private System.Windows.Forms.DataGridViewButtonColumn M_FinishBtn;
private System.Windows.Forms.PictureBox statePic; 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;
} }
} }

+ 107
- 239
WeighAndGrading/GradeFrom.cs View File

@ -32,11 +32,15 @@ namespace WeighAndGrading
public Form Generate() public Form Generate()
{ {
if (string.IsNullOrEmpty(ButcherAppContext.Context.UrlConfig.OfflineSqlConnection))
throw new Exception("请先设置离线数据库并保存");
if (!LocalGradeAndWeightBL.ConnectionTest())
throw new Exception("离线数据库连接失败");
return this; return this;
} }
#endregion #endregion
private delegate void InvokeHandler(); 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 TANG_TECH = 0;
const short MAO_TECH = 1; const short MAO_TECH = 1;
List<GradeAndWeight> tangList; List<GradeAndWeight> tangList;
@ -44,15 +48,17 @@ namespace WeighAndGrading
List<GradeAndWeight_Detail> details; List<GradeAndWeight_Detail> details;
List<long> localTang, localMao; List<long> localTang, localMao;
string maoFilePath, tangFilePath;
bool connection = false; bool connection = false;
SerialPort weightPort; SerialPort weightPort;
int maxIndex = 0; int maxIndex = 0;
ConcurrentQueue<GradeAndWeight_Detail> noLivestockList = new ConcurrentQueue<GradeAndWeight_Detail>();
ConcurrentQueue<GradeAndWeight_Detail> noLivestockList;
ConcurrentQueue<GradeAndWeight_Detail> noWeightList = new ConcurrentQueue<GradeAndWeight_Detail>();
ConcurrentQueue<GradeAndWeight_Detail> noWeightList;
Thread syncWork; Thread syncWork;
Thread syncToServer;
#region weightNeed #region weightNeed
private IDataFormat _dataFormat; private IDataFormat _dataFormat;
private Thread _inQueryThread; private Thread _inQueryThread;
@ -69,9 +75,13 @@ namespace WeighAndGrading
maoGridView.AutoGenerateColumns = false; maoGridView.AutoGenerateColumns = false;
maoGridView.DataSource = null; maoGridView.DataSource = null;
historyGrid.AutoGenerateColumns = false; 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; connection = ButcherAppContext.Context.UserConfig.Connection;
AddLivestockBtn(); AddLivestockBtn();
BuildDiscontPanel();
BuildDiscontPanel(true);
weightPort = new SerialPort(); weightPort = new SerialPort();
this.FormClosing += delegate this.FormClosing += delegate
{ {
@ -79,6 +89,8 @@ namespace WeighAndGrading
DisableWeight(); DisableWeight();
if (syncWork != null && syncWork.IsAlive) if (syncWork != null && syncWork.IsAlive)
syncWork.Abort(); syncWork.Abort();
if (syncToServer != null && syncToServer.IsAlive)
syncToServer.Abort();
}; };
} }
@ -87,13 +99,14 @@ namespace WeighAndGrading
void AddLivestockBtn() void AddLivestockBtn()
{ {
var livestocks = new List<CTuple<long, string, short>>(); var livestocks = new List<CTuple<long, string, short>>();
var fileName = Path.Combine(DATA_PATH, "Livestocks.xml");
if (connection) if (connection)
{ {
livestocks = BaseInfoRpcUtil.GetLivestockList(); livestocks = BaseInfoRpcUtil.GetLivestockList();
XmlUtil.SerializerObjToFile(livestocks, "Livestocks.xml");
XmlUtil.SerializerObjToFile(livestocks, fileName);
} }
else else
livestocks = XmlUtil.DeserializeFromFile<List<CTuple<long, string, short>>>("Livestocks.xml");
livestocks = XmlUtil.DeserializeFromFile<List<CTuple<long, string, short>>>(fileName);
foreach (var item in livestocks) 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) }; 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.Livestock_Name = livestockTag.Item2;
modifyDetail.Technics = livestockTag.Item3; modifyDetail.Technics = livestockTag.Item3;
modifyDetail.Technics_Name = livestockTag.Item3 == TANG_TECH ? "烫褪" : "毛剥"; 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(); historyGrid.Refresh();
modifyDetail = null; modifyDetail = null;
modifyPanel.Hide(); modifyPanel.Hide();
@ -170,27 +165,13 @@ namespace WeighAndGrading
private void syncBtn_Click(object sender, EventArgs e) 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(); FillQueue();
BindDetailGrid(); BindDetailGrid();
if (details.Any()) if (details.Any())
{
maxIndex = details.First().Index; maxIndex = details.First().Index;
SaveLastIndex(maxIndex);
}
else
maxIndex = GetLastIndex();
if (syncWork == null || !syncWork.IsAlive) if (syncWork == null || !syncWork.IsAlive)
{ {
localMao = XmlUtil.DeserializeFromFile<List<long>>("maoList.xml");
localTang = XmlUtil.DeserializeFromFile<List<long>>("tangList.xml");
syncWork = new Thread(Sync); syncWork = new Thread(Sync);
syncWork.Start(); syncWork.Start();
syncBtn.BackColor = Color.FromArgb(15, 215, 107); syncBtn.BackColor = Color.FromArgb(15, 215, 107);
@ -210,15 +191,8 @@ namespace WeighAndGrading
{ {
this.Invoke(new InvokeHandler(delegate() this.Invoke(new InvokeHandler(delegate()
{ {
connection = LoginRpcUtil.TestConnection();
SetImage();
BindTangGrid(); BindTangGrid();
BindMaoGrid(); BindMaoGrid();
if (connection)
{
SyncLocalDetails();
SyncLocalMainFinish();
}
})); }));
Thread.Sleep(5000); Thread.Sleep(5000);
} }
@ -248,6 +222,7 @@ namespace WeighAndGrading
void BindTangGrid() void BindTangGrid()
{ {
VerifyConnection();
if (connection) if (connection)
tangList = GradeAndWeightRpc.GetGradeAndWeightList(butcherTimeInput.Date.Value, true); tangList = GradeAndWeightRpc.GetGradeAndWeightList(butcherTimeInput.Date.Value, true);
else else
@ -291,6 +266,7 @@ namespace WeighAndGrading
void BindMaoGrid() void BindMaoGrid()
{ {
VerifyConnection();
if (connection) if (connection)
maoList = GradeAndWeightRpc.GetGradeAndWeightList(butcherTimeInput.Date.Value, false); maoList = GradeAndWeightRpc.GetGradeAndWeightList(butcherTimeInput.Date.Value, false);
else else
@ -342,7 +318,7 @@ namespace WeighAndGrading
{ {
foreach (DataGridViewRow row in historyGrid.Rows) 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]; historyGrid.CurrentCell = row.Cells[row.Cells.Count - 1];
break; break;
@ -601,7 +577,7 @@ namespace WeighAndGrading
var tech = livestock.Item3 == TANG_TECH ? "烫褪" : "毛剥"; var tech = livestock.Item3 == TANG_TECH ? "烫褪" : "毛剥";
GradeAndWeight_Detail first; 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); noLivestockList.TryDequeue(out first);
if (currentRow != null) if (currentRow != null)
@ -617,34 +593,12 @@ namespace WeighAndGrading
SetBtnUnCheck(disBtn); SetBtnUnCheck(disBtn);
disBtn = null; 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(); historyGrid.Refresh();
} }
else//add else//add
{ {
maxIndex++; maxIndex++;
SaveLastIndex(maxIndex);
var entity = new GradeAndWeight_Detail(); var entity = new GradeAndWeight_Detail();
entity.Index = maxIndex; entity.Index = maxIndex;
if (currentRow != null) if (currentRow != null)
@ -665,16 +619,7 @@ namespace WeighAndGrading
if (details.Count == 50) if (details.Count == 50)
details.RemoveAt(49); details.RemoveAt(49);
details.Insert(0, entity); 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); noWeightList.Enqueue(entity);
BindDetailGrid(); BindDetailGrid();
} }
@ -706,26 +651,12 @@ namespace WeighAndGrading
first.Weight = (first.Weight ?? 0) + weight; first.Weight = (first.Weight ?? 0) + weight;
else else
first.Weight = weight; 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(); historyGrid.Refresh();
} }
else//add else//add
{ {
maxIndex++; maxIndex++;
SaveLastIndex(maxIndex);
var entity = new GradeAndWeight_Detail(); var entity = new GradeAndWeight_Detail();
entity.Index = maxIndex; entity.Index = maxIndex;
entity.Weight = (entity.Weight ?? 0) + weight; entity.Weight = (entity.Weight ?? 0) + weight;
@ -734,16 +665,7 @@ namespace WeighAndGrading
if (details.Count == 50) if (details.Count == 50)
details.RemoveAt(49); details.RemoveAt(49);
details.Insert(0, entity); 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); noLivestockList.Enqueue(entity);
BindDetailGrid(); BindDetailGrid();
} }
@ -763,10 +685,10 @@ namespace WeighAndGrading
if (e.RowIndex < 0) if (e.RowIndex < 0)
return; return;
var currentRow = historyGrid.CurrentRow.DataBoundItem as GradeAndWeight_Detail; var currentRow = historyGrid.CurrentRow.DataBoundItem as GradeAndWeight_Detail;
lastSelectID = currentRow.ID;
lastSelectID = currentRow.SID;
if (e.ColumnIndex == 2) if (e.ColumnIndex == 2)
{ {
if (lastCheckItem != null && lastCheckItem.ID != currentRow.ID)
if (lastCheckItem != null && lastCheckItem.SID != currentRow.SID)
lastCheckItem.ReadWeight = false; lastCheckItem.ReadWeight = false;
lastCheckItem = currentRow; lastCheckItem = currentRow;
lastCheckItem.ReadWeight = !lastCheckItem.ReadWeight; lastCheckItem.ReadWeight = !lastCheckItem.ReadWeight;
@ -782,7 +704,7 @@ namespace WeighAndGrading
foreach (var item in details) foreach (var item in details)
{ {
stack.Push(item); stack.Push(item);
if (item.ID == lastCheckItem.ID)
if (item.SID == lastCheckItem.SID)
break; break;
} }
while (stack.Count > 0) while (stack.Count > 0)
@ -833,13 +755,17 @@ namespace WeighAndGrading
if (entity.Finish) if (entity.Finish)
return; return;
entity.Finish = true; entity.Finish = true;
connection = LoginRpcUtil.TestConnection();
SetImage();
VerifyConnection();
if (connection) if (connection)
GradeAndWeightRpc.SetGradeFinish(entity.OrderDetail_ID, TANG_TECH); GradeAndWeightRpc.SetGradeFinish(entity.OrderDetail_ID, TANG_TECH);
else else
{ {
SaveEntityToLocal(localTang, entity.OrderDetail_ID, true);
localTang = XmlUtil.DeserializeFromFile<List<long>>(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); var f = tangList.FirstOrDefault(x => x.OrderDetail_ID == entity.OrderDetail_ID);
if (f != null) if (f != null)
f.Finish = true; f.Finish = true;
@ -880,13 +806,17 @@ namespace WeighAndGrading
if (entity.Finish) if (entity.Finish)
return; return;
entity.Finish = true; entity.Finish = true;
connection = LoginRpcUtil.TestConnection();
SetImage();
VerifyConnection();
if (connection) if (connection)
GradeAndWeightRpc.SetGradeFinish(entity.OrderDetail_ID, MAO_TECH); GradeAndWeightRpc.SetGradeFinish(entity.OrderDetail_ID, MAO_TECH);
else else
{ {
SaveEntityToLocal(localMao, entity.OrderDetail_ID, false);
localMao = XmlUtil.DeserializeFromFile<List<long>>(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); var f = maoList.FirstOrDefault(x => x.OrderDetail_ID == entity.OrderDetail_ID);
if (f != null) if (f != null)
f.Finish = true; f.Finish = true;
@ -898,20 +828,23 @@ namespace WeighAndGrading
private void discontBtn_Click(object sender, EventArgs e) private void discontBtn_Click(object sender, EventArgs e)
{ {
if (new BodyDiscontSetting().ShowDialog() == DialogResult.OK) if (new BodyDiscontSetting().ShowDialog() == DialogResult.OK)
BuildDiscontPanel();
BuildDiscontPanel(false);
} }
Button disBtn = null; Button disBtn = null;
void BuildDiscontPanel()
void BuildDiscontPanel(bool firstLoad)
{ {
var fileName = Path.Combine(DATA_PATH, "Disconts.xml");
var disconts = new List<BodyDiscontItem>(); var disconts = new List<BodyDiscontItem>();
if (!firstLoad)
VerifyConnection();
if (connection) if (connection)
{ {
disconts = GradeAndWeightRpc.GetBodyDiscontItem(); disconts = GradeAndWeightRpc.GetBodyDiscontItem();
XmlUtil.SerializerObjToFile(disconts, "Disconts.xml");
XmlUtil.SerializerObjToFile(disconts, fileName);
} }
else else
disconts = XmlUtil.DeserializeFromFile<List<BodyDiscontItem>>("Disconts.xml");
disconts = XmlUtil.DeserializeFromFile<List<BodyDiscontItem>>(fileName);
disconts = disconts.Where(x => x.Discont > 0).OrderBy(x => x.ID).ToList(); disconts = disconts.Where(x => x.Discont > 0).OrderBy(x => x.ID).ToList();
discontPanel.Controls.Clear(); discontPanel.Controls.Clear();
@ -935,20 +868,7 @@ namespace WeighAndGrading
else else
{ {
modifyDetail.Weight = (modifyDetail.Weight ?? 0) - Convert.ToDecimal(btn.Tag); 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(); historyGrid.Refresh();
modifyDetail = null; modifyDetail = null;
modifyPanel.Hide(); modifyPanel.Hide();
@ -1016,141 +936,89 @@ namespace WeighAndGrading
}; };
} }
void SaveEntityToLocal(List<long> 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) if (tang)
fileName = "tangList.xml";
XmlUtil.SerializerObjToFile(list, fileName);
XmlUtil.SerializerObjToFile(localTang, tangFilePath);
else
XmlUtil.SerializerObjToFile(localMao, maoFilePath);
} }
} }
void SaveDetailToLocal(List<GradeAndWeight_Detail> details, string fileName)
void SyncLocalMainFinish(ref List<long> 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<GradeAndWeight_Detail> GetLocalDetail()
{
var fileName = Path.Combine(DETAIL_PATH, string.Format("{0:yyyyMMdd}_Data.xml", butcherTimeInput.Date.Value));
var q = XmlUtil.DeserializeFromFile<List<GradeAndWeight_Detail>>(fileName).OrderByDescending(x => x.Index).ToList();
list = XmlUtil.DeserializeFromFile<List<long>>(path);
var count = list.Count;
if (count == 0)
return;
if (count >= 30)
count = 30;
var r = new List<GradeAndWeight_Detail>();
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<GradeAndWeight_Detail> GetCurrentDetail()
{
var fileName = Path.Combine(DETAIL_PATH, string.Format("{0:yyyyMMdd}_Data.xml", butcherTimeInput.Date.Value));
return XmlUtil.DeserializeFromFile<List<GradeAndWeight_Detail>>(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<DetailLastIndex>(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<List<long>>("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<List<long>>("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<List<GradeAndWeight_Detail>>(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;
}
} }
} }

+ 1
- 1
WeighAndGrading/GradeFrom.resx View File

@ -153,7 +153,7 @@
<metadata name="M_FinishBtn.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <metadata name="M_FinishBtn.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value> <value>True</value>
</metadata> </metadata>
<metadata name="H_ID.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<metadata name="H_SID.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value> <value>True</value>
</metadata> </metadata>
<metadata name="H_Livestock_ID.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <metadata name="H_Livestock_ID.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">


+ 0
- 1
WeighAndGrading/WeighAndGrading.csproj View File

@ -34,7 +34,6 @@
<Prefer32Bit>false</Prefer32Bit> <Prefer32Bit>false</Prefer32Bit>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Forks.JsonRpc.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7254430f49d10aae, processorArchitecture=MSIL" />
<Reference Include="PresentationCore" /> <Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" /> <Reference Include="PresentationFramework" />
<Reference Include="System" /> <Reference Include="System" />


Loading…
Cancel
Save