Browse Source

修改。

master
yibo 8 years ago
parent
commit
0082abccbf
16 changed files with 601 additions and 30 deletions
  1. +1
    -0
      BO/BO.csproj
  2. +13
    -0
      BO/BO/Bill/GradeAndWeight/DetailLastIndex.cs
  3. +8
    -8
      BO/Utils/AfterLoginUtil.cs
  4. +1
    -1
      BO/Utils/ButcherAppContext.cs
  5. +19
    -0
      BO/Utils/LoginRpcUtil.cs
  6. +7
    -0
      BO/Utils/LoginUserInfo.cs
  7. +3
    -1
      BO/Utils/XmlUtil.cs
  8. +4
    -0
      BWP.WinFormControl/BWP.WinFormControl.csproj
  9. BIN
      BWP.WinFormControl/Images/stop.png
  10. BIN
      BWP.WinFormControl/Images/working.png
  11. +23
    -5
      ButcherManageClient/Login.cs
  12. +15
    -0
      WeighAndGrading/GradeFrom.Designer.cs
  13. +315
    -15
      WeighAndGrading/GradeFrom.cs
  14. +63
    -0
      WeighAndGrading/Properties/Resources.Designer.cs
  15. +120
    -0
      WeighAndGrading/Properties/Resources.resx
  16. +9
    -0
      WeighAndGrading/WeighAndGrading.csproj

+ 1
- 0
BO/BO.csproj View File

@ -55,6 +55,7 @@
<ItemGroup>
<Compile Include="BO\BackRpcObj.cs" />
<Compile Include="BO\BaseInfo\BodyDiscontItem.cs" />
<Compile Include="BO\Bill\GradeAndWeight\DetailLastIndex.cs" />
<Compile Include="BO\Bill\GradeAndWeight\GradeAndWeight.cs" />
<Compile Include="BO\Bill\GradeAndWeight\GradeAndWeight_Detail.cs" />
<Compile Include="BO\Bill\OrderDetail\HurryRecord.cs" />


+ 13
- 0
BO/BO/Bill/GradeAndWeight/DetailLastIndex.cs View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BO.BO.Bill
{
public class DetailLastIndex
{
public int Index { get; set; }
}
}

+ 8
- 8
BO/Utils/AfterLoginUtil.cs View File

@ -19,13 +19,13 @@ namespace BO.Utils
public static class AfterLoginUtil
{
// static List<Tuple<string, string>> roleToAssemblies = new List<Tuple<string, string>>(){new Tuple<string,string>("排宰员",@"C:\BwpB3Project\src\B3ButcherManageClient\ButcherOrder\bin\Debug\ButcherOrder"),
//new Tuple<string,string>("过磅员",@"C:\BwpB3Project\src\B3ButcherManageClient\ButcherWeight\bin\Debug\ButcherWeight"),
// new Tuple<string,string>("验质员",@"C:\BwpB3Project\src\B3ButcherManageClient\QualityAndOrder\bin\Debug\QualityAndOrder"),new Tuple<string,string>("定级员",@"C:\BwpB3Project\src\B3ButcherManageClient\WeighAndGrading\bin\Debug\WeighAndGrading"),new Tuple<string,string>("窒晕员",@"C:\BwpB3Project\src\B3ButcherManageClient\OrderConfirm\bin\Debug\OrderConfirm")};
static List<Tuple<string, string>> roleToAssemblies = new List<Tuple<string, string>>(){new Tuple<string,string>("排宰员",@"C:\BwpB3Project\src\B3ButcherManageClient\ButcherOrder\bin\Debug\ButcherOrder"),
new Tuple<string,string>("过磅员",@"C:\BwpB3Project\src\B3ButcherManageClient\ButcherWeight\bin\Debug\ButcherWeight"),
new Tuple<string,string>("验质员",@"C:\BwpB3Project\src\B3ButcherManageClient\QualityAndOrder\bin\Debug\QualityAndOrder"),new Tuple<string,string>("定级员",@"C:\BwpB3Project\src\B3ButcherManageClient\WeighAndGrading\bin\Debug\WeighAndGrading"),new Tuple<string,string>("窒晕员",@"C:\BwpB3Project\src\B3ButcherManageClient\OrderConfirm\bin\Debug\OrderConfirm")};
static List<Tuple<string, string>> roleToAssemblies = new List<Tuple<string, string>>(){new Tuple<string,string>("排宰员",@"ButcherOrder"),
new Tuple<string,string>("过磅员",@"ButcherWeight"),
new Tuple<string,string>("验质员",@"QualityAndOrder"),new Tuple<string,string>("定级员",@"WeighAndGrading"),new Tuple<string,string>("窒晕员",@"OrderConfirm")};
//static List<Tuple<string, string>> roleToAssemblies = new List<Tuple<string, string>>(){new Tuple<string,string>("排宰员",@"ButcherOrder"),
//new Tuple<string,string>("过磅员",@"ButcherWeight"),
// new Tuple<string,string>("验质员",@"QualityAndOrder"),new Tuple<string,string>("定级员",@"WeighAndGrading"),new Tuple<string,string>("窒晕员",@"OrderConfirm")};
public static Form CreateForm(string role)
@ -34,10 +34,10 @@ namespace BO.Utils
if (first == null)
throw new Exception("未注册的角色");
//#if debug
// var filePath = string.Format("{0}.dll", first.Item2);
var filePath = string.Format("{0}.dll", first.Item2);
//#endif
//#if !debug
var filePath = Path.Combine(Application.StartupPath, string.Format("{0}.dll", first.Item2));
//var filePath = Path.Combine(Application.StartupPath, string.Format("{0}.dll", first.Item2));
//#endif
if (!File.Exists(filePath))
throw new Exception("相关模块不存在");


+ 1
- 1
BO/Utils/ButcherAppContext.cs View File

@ -24,7 +24,7 @@ namespace BO.Utils
set;
}
private ButcherAppContext()
public ButcherAppContext()
{
UrlConfig = new ServerUrlConfig();
UserConfig = new LoginUserInfo();


+ 19
- 0
BO/Utils/LoginRpcUtil.cs View File

@ -3,6 +3,7 @@ using Forks.JsonRpc.Client.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
@ -43,5 +44,23 @@ namespace BO.Utils
userInfo.Role = obj.Get<string>("Role");
}
}
public static bool TestConnection()
{
var url = ButcherAppContext.Context.UrlConfig.ServerUrl;
if (string.IsNullOrEmpty(url))
return false;
try
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
return resp.StatusCode == HttpStatusCode.OK;
}
catch
{
return false;
}
}
}
}

+ 7
- 0
BO/Utils/LoginUserInfo.cs View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
namespace BO.Utils
{
@ -27,5 +28,11 @@ namespace BO.Utils
public string Employee_Name { get; set; }
public string Role { get; set; }
[XmlIgnore]
public bool Connection { get; set; }
[XmlIgnore]
public string PWD { get; set; }
}
}

+ 3
- 1
BO/Utils/XmlUtil.cs View File

@ -16,6 +16,7 @@ namespace BO.Utils
{
fileName = obj.GetType().Name + ".xml";
}
var ser = new XmlSerializer(obj.GetType());
using (var stream = File.Open(fileName, FileMode.Create))
{
@ -24,6 +25,7 @@ namespace BO.Utils
}
public static T DeserializeFromFile<T>(string fileName = "")
where T : new()
{
if (string.IsNullOrWhiteSpace(fileName))
{
@ -31,7 +33,7 @@ namespace BO.Utils
}
if (!File.Exists(fileName))
{
throw new FileNotFoundException("不存在文件:" + fileName);
return new T();
}
using (var reader = new StreamReader(fileName))
{


+ 4
- 0
BWP.WinFormControl/BWP.WinFormControl.csproj View File

@ -120,6 +120,10 @@
<DependentUpon>WeightControl.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Images\stop.png" />
<EmbeddedResource Include="Images\working.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.


BIN
BWP.WinFormControl/Images/stop.png View File

Before After
Width: 30  |  Height: 30  |  Size: 380 B

BIN
BWP.WinFormControl/Images/working.png View File

Before After
Width: 30  |  Height: 30  |  Size: 516 B

+ 23
- 5
ButcherManageClient/Login.cs View File

@ -8,6 +8,7 @@ using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
@ -48,10 +49,22 @@ namespace ButcherManageClient
if (string.IsNullOrEmpty(username))
throw new Exception("请输入用户名");
IniteRpcFacade();
await Task.Factory.StartNew(() => RpcFacade.Login(username, pwd));
LoginRpcUtil.FillUserEmpInfo(username, ButcherAppContext.Context.UserConfig);
ButcherAppContext.Context.Save();
ButcherAppContext.Context.UserConfig.PWD = pwd;
if (LoginRpcUtil.TestConnection())
{
await Task.Factory.StartNew(() => RpcFacade.Login(username, pwd));
LoginRpcUtil.FillUserEmpInfo(username, ButcherAppContext.Context.UserConfig);
ButcherAppContext.Context.Save();
ButcherAppContext.Context.UserConfig.Connection = true;
}
else
{
if (ButcherAppContext.Context.UserConfig.Role != "定级员")
throw new Exception("无法连接到服务器");
if (username != ButcherAppContext.Context.UserConfig.UserName)
throw new Exception("离线状态请保持与上次用户名一致");
ButcherAppContext.Context.UserConfig.Connection = false;
}
var form = AfterLoginUtil.CreateForm(ButcherAppContext.Context.UserConfig.Role);
if (form == null)
throw new Exception("权限不符");
@ -111,6 +124,11 @@ namespace ButcherManageClient
if (string.IsNullOrEmpty(versionInfo.ServerUrl))
versionInfo.ServerUrl = serUri;
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(versionInfo.ServerUrl);
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
if (resp.StatusCode != HttpStatusCode.OK)
return;
var down = new System.Net.WebClient();
var serverVersion = XmlUtil.XmlDeserializeObject<ClientVersion>(down.DownloadString(versionInfo.ServerUrl));
if (versionInfo.Version == serverVersion.Version)
@ -122,7 +140,7 @@ namespace ButcherManageClient
private void Login_Load(object sender, EventArgs e)
{
AutoUpdate();
//AutoUpdate();
}
}
}

+ 15
- 0
WeighAndGrading/GradeFrom.Designer.cs View File

@ -94,6 +94,7 @@
this.cancelBtn = new System.Windows.Forms.Button();
this.discontBtn = new System.Windows.Forms.Button();
this.discontPanel = new System.Windows.Forms.FlowLayoutPanel();
this.statePic = new System.Windows.Forms.PictureBox();
this.groupBox1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.tangGridView)).BeginInit();
this.groupBox2.SuspendLayout();
@ -102,6 +103,7 @@
((System.ComponentModel.ISupportInitialize)(this.historyGrid)).BeginInit();
this.panel1.SuspendLayout();
this.modifyPanel.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.statePic)).BeginInit();
this.SuspendLayout();
//
// label1
@ -706,11 +708,22 @@
this.discontPanel.Size = new System.Drawing.Size(71, 656);
this.discontPanel.TabIndex = 33;
//
// statePic
//
this.statePic.ErrorImage = null;
this.statePic.InitialImage = null;
this.statePic.Location = new System.Drawing.Point(219, 89);
this.statePic.Name = "statePic";
this.statePic.Size = new System.Drawing.Size(30, 30);
this.statePic.TabIndex = 38;
this.statePic.TabStop = false;
//
// GradeFrom
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1379, 865);
this.Controls.Add(this.statePic);
this.Controls.Add(this.discontPanel);
this.Controls.Add(this.discontBtn);
this.Controls.Add(this.modifyPanel);
@ -748,6 +761,7 @@
this.panel1.PerformLayout();
this.modifyPanel.ResumeLayout(false);
this.modifyPanel.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.statePic)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
@ -808,5 +822,6 @@
private System.Windows.Forms.DataGridViewTextBoxColumn M_Number;
private System.Windows.Forms.DataGridViewTextBoxColumn M_Already;
private System.Windows.Forms.DataGridViewButtonColumn M_FinishBtn;
private System.Windows.Forms.PictureBox statePic;
}
}

+ 315
- 15
WeighAndGrading/GradeFrom.cs View File

@ -1,4 +1,5 @@
using BO;
using BO.BO.BaseInfo;
using BO.BO.Bill;
using BO.Utils;
using BO.Utils.BillRpc;
@ -10,8 +11,10 @@ using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.IO.Ports;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
@ -33,19 +36,23 @@ namespace WeighAndGrading
}
#endregion
private delegate void InvokeHandler();
const string DETAIL_PATH = "WeightDetailData";
const short TANG_TECH = 0;
const short MAO_TECH = 1;
List<GradeAndWeight> tangList;
List<GradeAndWeight> maoList;
List<GradeAndWeight_Detail> details;
List<long> localTang, localMao;
bool connection = false;
SerialPort weightPort;
int maxIndex = 0;
ConcurrentQueue<GradeAndWeight_Detail> noLivestockList = new ConcurrentQueue<GradeAndWeight_Detail>();
ConcurrentQueue<GradeAndWeight_Detail> noWeightList = new ConcurrentQueue<GradeAndWeight_Detail>();
Thread syncWork;
#region weightNeed
private IDataFormat _dataFormat;
private Thread _inQueryThread;
@ -62,6 +69,7 @@ namespace WeighAndGrading
maoGridView.AutoGenerateColumns = false;
maoGridView.DataSource = null;
historyGrid.AutoGenerateColumns = false;
connection = ButcherAppContext.Context.UserConfig.Connection;
AddLivestockBtn();
BuildDiscontPanel();
weightPort = new SerialPort();
@ -78,7 +86,14 @@ namespace WeighAndGrading
void AddLivestockBtn()
{
var livestocks = BaseInfoRpcUtil.GetLivestockList();
var livestocks = new List<CTuple<long, string, short>>();
if (connection)
{
livestocks = BaseInfoRpcUtil.GetLivestockList();
XmlUtil.SerializerObjToFile(livestocks, "Livestocks.xml");
}
else
livestocks = XmlUtil.DeserializeFromFile<List<CTuple<long, string, short>>>("Livestocks.xml");
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) };
@ -98,7 +113,25 @@ namespace WeighAndGrading
modifyDetail.Livestock_Name = livestockTag.Item2;
modifyDetail.Technics = livestockTag.Item3;
modifyDetail.Technics_Name = livestockTag.Item3 == TANG_TECH ? "烫褪" : "毛剥";
GradeAndWeightRpc.UpdateLivestock(modifyDetail.ID, modifyDetail.Livestock_ID, modifyDetail.Livestock_Name, modifyDetail.Technics, modifyDetail.Technics_Name);
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);
}
historyGrid.Refresh();
modifyDetail = null;
modifyPanel.Hide();
@ -137,13 +170,27 @@ namespace WeighAndGrading
private void syncBtn_Click(object sender, EventArgs e)
{
details = GradeAndWeightRpc.GetDetails(butcherTimeInput.Date.Value, 50);
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();
FillQueue();
BindDetailGrid();
if (details.Any())
{
maxIndex = details.First().Index;
SaveLastIndex(maxIndex);
}
else
maxIndex = GetLastIndex();
if (syncWork == null || !syncWork.IsAlive)
{
localMao = XmlUtil.DeserializeFromFile<List<long>>("maoList.xml");
localTang = XmlUtil.DeserializeFromFile<List<long>>("tangList.xml");
syncWork = new Thread(Sync);
syncWork.Start();
syncBtn.BackColor = Color.FromArgb(15, 215, 107);
@ -163,8 +210,15 @@ namespace WeighAndGrading
{
this.Invoke(new InvokeHandler(delegate()
{
connection = LoginRpcUtil.TestConnection();
SetImage();
BindTangGrid();
BindMaoGrid();
if (connection)
{
SyncLocalDetails();
SyncLocalMainFinish();
}
}));
Thread.Sleep(5000);
}
@ -194,7 +248,13 @@ namespace WeighAndGrading
void BindTangGrid()
{
tangList = GradeAndWeightRpc.GetGradeAndWeightList(butcherTimeInput.Date.Value, true);
if (connection)
tangList = GradeAndWeightRpc.GetGradeAndWeightList(butcherTimeInput.Date.Value, true);
else
{
if (tangList == null)
tangList = new List<GradeAndWeight>();
}
tangGridView.DataSource = tangList.OrderBy(x => x.Order).OrderBy(x => x.Finish).ToList();
if (tangEntity == null && tangGridView.CurrentRow != null)
{
@ -231,7 +291,13 @@ namespace WeighAndGrading
void BindMaoGrid()
{
maoList = GradeAndWeightRpc.GetGradeAndWeightList(butcherTimeInput.Date.Value, false);
if (connection)
maoList = GradeAndWeightRpc.GetGradeAndWeightList(butcherTimeInput.Date.Value, false);
else
{
if (maoList == null)
maoList = new List<GradeAndWeight>();
}
maoGridView.DataSource = maoList.OrderBy(x => x.Order).OrderBy(x => x.Finish).ToList();
if (maoEntity == null && maoGridView.CurrentRow != null)
{
@ -551,12 +617,34 @@ namespace WeighAndGrading
SetBtnUnCheck(disBtn);
disBtn = null;
}
GradeAndWeightRpc.UpdateOrInsertDetail(first, true);
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);
}
historyGrid.Refresh();
}
else//add
{
maxIndex++;
SaveLastIndex(maxIndex);
var entity = new GradeAndWeight_Detail();
entity.Index = maxIndex;
if (currentRow != null)
@ -577,7 +665,16 @@ namespace WeighAndGrading
if (details.Count == 50)
details.RemoveAt(49);
details.Insert(0, entity);
GradeAndWeightRpc.UpdateOrInsertDetail(entity, true);
connection = LoginRpcUtil.TestConnection();
SetImage();
if (connection)
GradeAndWeightRpc.UpdateOrInsertDetail(entity, true);
else
{
var local = GetCurrentDetail();
local.Add(entity);
SaveDetailToLocal(local, null);
}
noWeightList.Enqueue(entity);
BindDetailGrid();
}
@ -609,12 +706,26 @@ namespace WeighAndGrading
first.Weight = (first.Weight ?? 0) + weight;
else
first.Weight = weight;
GradeAndWeightRpc.UpdateOrInsertDetail(first);
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);
}
historyGrid.Refresh();
}
else//add
{
maxIndex++;
SaveLastIndex(maxIndex);
var entity = new GradeAndWeight_Detail();
entity.Index = maxIndex;
entity.Weight = (entity.Weight ?? 0) + weight;
@ -623,7 +734,16 @@ namespace WeighAndGrading
if (details.Count == 50)
details.RemoveAt(49);
details.Insert(0, entity);
GradeAndWeightRpc.UpdateOrInsertDetail(entity);
connection = LoginRpcUtil.TestConnection();
SetImage();
if (connection)
GradeAndWeightRpc.UpdateOrInsertDetail(entity);
else
{
var local = GetCurrentDetail();
local.Add(entity);
SaveDetailToLocal(local, null);
}
noLivestockList.Enqueue(entity);
BindDetailGrid();
}
@ -713,7 +833,17 @@ namespace WeighAndGrading
if (entity.Finish)
return;
entity.Finish = true;
GradeAndWeightRpc.SetGradeFinish(entity.OrderDetail_ID, TANG_TECH);
connection = LoginRpcUtil.TestConnection();
SetImage();
if (connection)
GradeAndWeightRpc.SetGradeFinish(entity.OrderDetail_ID, TANG_TECH);
else
{
SaveEntityToLocal(localTang, entity.OrderDetail_ID, true);
var f = tangList.FirstOrDefault(x => x.OrderDetail_ID == entity.OrderDetail_ID);
if (f != null)
f.Finish = true;
}
BindTangGrid();
}
@ -750,7 +880,18 @@ namespace WeighAndGrading
if (entity.Finish)
return;
entity.Finish = true;
GradeAndWeightRpc.SetGradeFinish(entity.OrderDetail_ID, MAO_TECH);
connection = LoginRpcUtil.TestConnection();
SetImage();
if (connection)
GradeAndWeightRpc.SetGradeFinish(entity.OrderDetail_ID, MAO_TECH);
else
{
SaveEntityToLocal(localMao, entity.OrderDetail_ID, false);
var f = maoList.FirstOrDefault(x => x.OrderDetail_ID == entity.OrderDetail_ID);
if (f != null)
f.Finish = true;
}
BindMaoGrid();
}
@ -763,7 +904,16 @@ namespace WeighAndGrading
Button disBtn = null;
void BuildDiscontPanel()
{
var disconts = GradeAndWeightRpc.GetBodyDiscontItem().Where(x => x.Discont > 0).OrderBy(x => x.ID);
var disconts = new List<BodyDiscontItem>();
if (connection)
{
disconts = GradeAndWeightRpc.GetBodyDiscontItem();
XmlUtil.SerializerObjToFile(disconts, "Disconts.xml");
}
else
disconts = XmlUtil.DeserializeFromFile<List<BodyDiscontItem>>("Disconts.xml");
disconts = disconts.Where(x => x.Discont > 0).OrderBy(x => x.ID).ToList();
discontPanel.Controls.Clear();
foreach (var item in disconts)
{
@ -785,7 +935,20 @@ namespace WeighAndGrading
else
{
modifyDetail.Weight = (modifyDetail.Weight ?? 0) - Convert.ToDecimal(btn.Tag);
GradeAndWeightRpc.UpdateWeight(modifyDetail.ID, modifyDetail.Weight);
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);
}
historyGrid.Refresh();
modifyDetail = null;
modifyPanel.Hide();
@ -852,5 +1015,142 @@ namespace WeighAndGrading
historyGrid.FirstDisplayedScrollingRowIndex = rightRoll;
};
}
void SaveEntityToLocal(List<long> list, long? orderDetailID, bool tang)
{
lock (_obj)
{
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);
}
}
void SaveDetailToLocal(List<GradeAndWeight_Detail> details, string fileName)
{
lock (_obj)
{
if (string.IsNullOrEmpty(fileName))
fileName = Path.Combine(DETAIL_PATH, string.Format("{0:yyyyMMdd}_Data.xml", butcherTimeInput.Date.Value));
XmlUtil.SerializerObjToFile(details, fileName);
}
}
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();
var r = new List<GradeAndWeight_Detail>();
foreach (var item in q)
{
r.Add(item);
if (r.Count == 50)
break;
}
return r;
}
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)
{
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;
}
void SyncLocalMainFinish()
{
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);
}
}
void SyncLocalDetails()
{
var currentTime = string.Format("{0:yyyyMMdd}_Data.xml", butcherTimeInput.Date.Value);
var files = Directory.GetFiles(DETAIL_PATH, "_Data.xml");
foreach (var file in files)
{
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)
{
GradeAndWeightRpc.UpdateOrInsertDetail(item);
var first = details.First(x => x.Index == item.Index);
details.Remove(first);
SaveDetailToLocal(details, file);
if (math)
{
var showTag = details.FirstOrDefault(x => x.Index == item.Index);
if (showTag != null)
{
if (!needRefsh)
needRefsh = true;
showTag.ID = item.ID;
}
}
historyGrid.Refresh();
}
if (!math)
File.Delete(file);
}
}
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;
}
}
}

+ 63
- 0
WeighAndGrading/Properties/Resources.Designer.cs View File

@ -0,0 +1,63 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本:4.0.30319.42000
//
// 对此文件的更改可能会导致不正确的行为,并且如果
// 重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------
namespace WeighAndGrading.Properties {
using System;
/// <summary>
/// 一个强类型的资源类,用于查找本地化的字符串等。
/// </summary>
// 此类是由 StronglyTypedResourceBuilder
// 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
// 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
// (以 /str 作为命令选项),或重新生成 VS 项目。
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// 返回此类使用的缓存的 ResourceManager 实例。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("WeighAndGrading.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// 使用此强类型资源类,为所有资源查找
/// 重写当前线程的 CurrentUICulture 属性。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
}
}

+ 120
- 0
WeighAndGrading/Properties/Resources.resx View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

+ 9
- 0
WeighAndGrading/WeighAndGrading.csproj View File

@ -70,6 +70,11 @@
<DependentUpon>GradeSettingFrom.cs</DependentUpon>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="WeightGradePrint.cs" />
</ItemGroup>
<ItemGroup>
@ -82,6 +87,10 @@
<EmbeddedResource Include="GradeSettingFrom.resx">
<DependentUpon>GradeSettingFrom.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BO\BO.csproj">


Loading…
Cancel
Save