Commit 7cc119ae authored by 潘栩锋's avatar 潘栩锋 🚴

修复 称重加载 weighter.weightSystemClient.json 出错时, 没有画面

修复 称重每次开机 都重写 weighter.weightSystemClient.json
parent fbbe03aa
...@@ -126,25 +126,51 @@ namespace FLY.Weight.Client ...@@ -126,25 +126,51 @@ namespace FLY.Weight.Client
void Load() { void Load() {
if (!File.Exists(filePath)) if (!File.Exists(filePath))
return; return;
string json =File.ReadAllText(filePath); try
var p = Newtonsoft.Json.JsonConvert.DeserializeObject< WeightSystemClientJsonDb>(json); {
string json = File.ReadAllText(filePath);
var p = Newtonsoft.Json.JsonConvert.DeserializeObject<WeightSystemClientJsonDb>(json);
BinCnts = p.BinCnts; BinCnts = p.BinCnts;
} }
catch {
//失败就算了。。。
}
}
private void WeightSystemClient_PropertyChanged(object sender, PropertyChangedEventArgs e) private void WeightSystemClient_PropertyChanged(object sender, PropertyChangedEventArgs e)
{ {
if (e.PropertyName == "BinCnts") if (e.PropertyName == "BinCnts")
{ {
if (IsBinCntsChanged()) {
ResetItems(); ResetItems();
Save(); Save();
} }
} }
}
bool IsBinCntsChanged() {
var binCnts = Items.Select(i => i.BinCnt).ToArray();
if (binCnts.Count() != BinCnts.Count())
return true;
else
{
for (int i = 0; i < binCnts.Count(); i++)
if (binCnts[i] != BinCnts[i])
{
return true;
}
}
return false;
}
/// <summary> /// <summary>
/// 重新创建 Items /// 重新创建 Items
/// </summary> /// </summary>
void ResetItems() void ResetItems()
{ {
int last_itemcnt = Items.Count(); int last_itemcnt = Items.Count();
for (int i = 0; i < Items.Count(); i++) for (int i = 0; i < Items.Count(); i++)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment