|
|
|
@ -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<GradeAndWeight> tangList; |
|
|
|
@ -44,15 +48,17 @@ namespace WeighAndGrading |
|
|
|
List<GradeAndWeight_Detail> details; |
|
|
|
|
|
|
|
List<long> localTang, localMao; |
|
|
|
string maoFilePath, tangFilePath; |
|
|
|
|
|
|
|
bool connection = false; |
|
|
|
|
|
|
|
SerialPort weightPort; |
|
|
|
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 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<CTuple<long, string, short>>(); |
|
|
|
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<List<CTuple<long, string, short>>>("Livestocks.xml"); |
|
|
|
livestocks = XmlUtil.DeserializeFromFile<List<CTuple<long, string, short>>>(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<List<long>>("maoList.xml"); |
|
|
|
localTang = XmlUtil.DeserializeFromFile<List<long>>("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<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); |
|
|
|
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<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); |
|
|
|
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<BodyDiscontItem>(); |
|
|
|
if (!firstLoad) |
|
|
|
VerifyConnection(); |
|
|
|
if (connection) |
|
|
|
{ |
|
|
|
disconts = GradeAndWeightRpc.GetBodyDiscontItem(); |
|
|
|
XmlUtil.SerializerObjToFile(disconts, "Disconts.xml"); |
|
|
|
XmlUtil.SerializerObjToFile(disconts, fileName); |
|
|
|
} |
|
|
|
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(); |
|
|
|
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<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) |
|
|
|
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; |
|
|
|
} |
|
|
|
} |
|
|
|
} |