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

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

修复 称重每次开机 都重写 weighter.weightSystemClient.json
parent fbbe03aa
......@@ -126,25 +126,51 @@ namespace FLY.Weight.Client
void Load() {
if (!File.Exists(filePath))
return;
string json =File.ReadAllText(filePath);
var p = Newtonsoft.Json.JsonConvert.DeserializeObject< WeightSystemClientJsonDb>(json);
BinCnts = p.BinCnts;
try
{
string json = File.ReadAllText(filePath);
var p = Newtonsoft.Json.JsonConvert.DeserializeObject<WeightSystemClientJsonDb>(json);
BinCnts = p.BinCnts;
}
catch {
//失败就算了。。。
}
}
private void WeightSystemClient_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "BinCnts")
{
ResetItems();
Save();
if (IsBinCntsChanged()) {
ResetItems();
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>
/// 重新创建 Items
/// </summary>
void ResetItems()
{
int last_itemcnt = Items.Count();
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