Commit f6bf79a1 authored by 潘栩锋's avatar 潘栩锋 🚴

优化 只有 一执行ParamDictionary.SetValue 就会Save() 不再需要主动调用 Save()

parent 540d14b2
...@@ -30,6 +30,7 @@ namespace Misc ...@@ -30,6 +30,7 @@ namespace Misc
cell.IsConverted = true; cell.IsConverted = true;
cells.Add(cell); cells.Add(cell);
ValueChanged?.Invoke(this, new ParamDictionaryValueChangedEventArgs() { Key = key, Value = value }); ValueChanged?.Invoke(this, new ParamDictionaryValueChangedEventArgs() { Key = key, Value = value });
Save();
} }
else else
{ {
...@@ -37,8 +38,8 @@ namespace Misc ...@@ -37,8 +38,8 @@ namespace Misc
if (cell.Value != value) if (cell.Value != value)
{ {
cell.Value = value; cell.Value = value;
//cell.Type = value.GetType();
ValueChanged?.Invoke(this, new ParamDictionaryValueChangedEventArgs() { Key = key, Value = value }); ValueChanged?.Invoke(this, new ParamDictionaryValueChangedEventArgs() { Key = key, Value = value });
Save();
} }
} }
} }
...@@ -181,7 +182,7 @@ namespace Misc ...@@ -181,7 +182,7 @@ namespace Misc
this.path = path; this.path = path;
Load(); Load();
} }
public void Load() void Load()
{ {
if (!File.Exists(path)) if (!File.Exists(path))
return; return;
......
...@@ -148,20 +148,24 @@ namespace FLY.Thick.Base.UI ...@@ -148,20 +148,24 @@ namespace FLY.Thick.Base.UI
{ {
this.jsonDist.SetValue(JSONDIST_KEY, JObject.FromObject(db)); this.jsonDist.SetValue(JSONDIST_KEY, JObject.FromObject(db));
} }
/// <summary> /// <summary>
/// 输入密码,确认密码权限是否满足要求, level越大,要求权限越大 /// 输入密码,确认密码权限是否满足要求, level越大,要求权限越大
/// </summary> /// </summary>
/// <param name="pw"></param> /// <param name="pw">密码</param>
/// <param name="level"></param> /// <param name="level">要求级别</param>
/// <param name="pw_lv">输入密码的级别</param>
/// <returns></returns> /// <returns></returns>
public AUTHORIZE_RESULT Authorize(string pw, int level) public AUTHORIZE_RESULT Authorize(string pw, int level, out int pw_lv)
{ {
pw_lv = 0;
if (level <= 0) if (level <= 0)
return AUTHORIZE_RESULT.OK; return AUTHORIZE_RESULT.OK;
var v = from p in Db.Pws where p.Password == pw select p; var v = from p in Db.Pws where p.Password == pw select p;
if (v.Count() > 0) if (v.Count() > 0)
{ {
pw_lv = v.First().Level;
if (v.First().Level >= level) if (v.First().Level >= level)
return AUTHORIZE_RESULT.OK; return AUTHORIZE_RESULT.OK;
else else
...@@ -175,9 +179,9 @@ namespace FLY.Thick.Base.UI ...@@ -175,9 +179,9 @@ namespace FLY.Thick.Base.UI
/// <param name="pw"></param> /// <param name="pw"></param>
/// <param name="uiName">界面名称</param> /// <param name="uiName">界面名称</param>
/// <returns></returns> /// <returns></returns>
public AUTHORIZE_RESULT Authorize(string pw, string uiName) public AUTHORIZE_RESULT Authorize(string pw, string uiName, out int pw_lv)
{ {
return Authorize(pw, GetLv(uiName)); return Authorize(pw, GetLv(uiName),out pw_lv);
} }
/// <summary> /// <summary>
/// 获取授权级别, 0级不需要密码就能通过 /// 获取授权级别, 0级不需要密码就能通过
......
...@@ -28,7 +28,5 @@ ...@@ -28,7 +28,5 @@
<StackPanel x:Name="spSections"> <StackPanel x:Name="spSections">
</StackPanel> </StackPanel>
</ScrollViewer> </ScrollViewer>
<Button Style="{StaticResource ButtonStyle_apply}" VerticalAlignment="Bottom" Margin="0,0,20,-45"
Click="btnApplyClick"/>
</Grid> </Grid>
</Page> </Page>
...@@ -45,12 +45,5 @@ namespace FLY.Thick.Base.UI ...@@ -45,12 +45,5 @@ namespace FLY.Thick.Base.UI
spSections.Children.Add(uc); spSections.Children.Add(uc);
} }
} }
private void btnApplyClick(object sender, RoutedEventArgs e)
{
paramDictionary.Save();
FLY.ControlLibrary.Window_Tip.Show("成功", "",
TimeSpan.FromSeconds(2));
return;
}
} }
} }
...@@ -51,12 +51,12 @@ namespace FLY.Thick.Base.UI ...@@ -51,12 +51,12 @@ namespace FLY.Thick.Base.UI
//窗口显示数据条数 //窗口显示数据条数
int windowSize = this.paramDictionary.GetValue<int>(ParamDistItemKeys.WindowSize, 30); int windowSize = this.paramDictionary.GetValue<int>(ParamDistItemKeys.WindowSize, 30);
mWindow = new BufferWindow<FlyData_WarningHistory>(this.warningService.NewestList, windowSize); mWindow = new BufferWindow<FlyData_WarningHistory>(this.warningService.NewestList, windowSize);
mWindow.PropertyChanged += (s, e) => mWindow.PropertyChanged += (s, e) =>
{ {
if (e.PropertyName == "Size") if (e.PropertyName == "Size")
{ {
this.paramDictionary.SetValue(ParamDistItemKeys.WindowSize, mWindow.Size); this.paramDictionary.SetValue(ParamDistItemKeys.WindowSize, mWindow.Size);
this.paramDictionary.Save();
} }
}; };
......
...@@ -38,6 +38,10 @@ namespace FLY.Thick.Base.UI ...@@ -38,6 +38,10 @@ namespace FLY.Thick.Base.UI
/// </summary> /// </summary>
int Level = 0; int Level = 0;
/// <summary>
/// 输入密码,查询到的级别
/// </summary>
public int PwLv { get; private set; }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
...@@ -45,6 +49,18 @@ namespace FLY.Thick.Base.UI ...@@ -45,6 +49,18 @@ namespace FLY.Thick.Base.UI
/// <returns></returns> /// <returns></returns>
public static bool Authorize(string uiName) public static bool Authorize(string uiName)
{ {
return Authorize(uiName, out int pwLv);
}
/// <summary>
///
/// </summary>
/// <param name="uiName">界面</param>
/// <param name="pwLv">当密码正确时,密码的级别</param>
/// <returns></returns>
public static bool Authorize(string uiName, out int pwLv)
{
pwLv = 0;
//从容器获取 //从容器获取
var container = Application.Current.Properties["container"] as IUnityContainer; var container = Application.Current.Properties["container"] as IUnityContainer;
if (container == null) if (container == null)
...@@ -52,13 +68,41 @@ namespace FLY.Thick.Base.UI ...@@ -52,13 +68,41 @@ namespace FLY.Thick.Base.UI
var passwordAuthorize = container.Resolve<PasswordAuthorize>(); var passwordAuthorize = container.Resolve<PasswordAuthorize>();
int level = passwordAuthorize.GetLv(uiName); int level = passwordAuthorize.GetLv(uiName);
if (level <= 0) if (level <= 0)
return true; return true;
WdPassword w = new WdPassword();
w.Init(passwordAuthorize, level);
w.Owner = Application.Current.MainWindow;
bool ret = (bool)w.ShowDialog();
pwLv = w.PwLv;
return ret;
}
/// <summary>
///
/// </summary>
/// <param name="level">要求的级别</param>
/// <param name="pwLv">当密码正确时,密码的级别</param>
/// <returns></returns>
public static bool Authorize(int level, out int pwLv)
{
pwLv = 0;
//从容器获取
var container = Application.Current.Properties["container"] as IUnityContainer;
if (container == null)
return true;
var passwordAuthorize = container.Resolve<PasswordAuthorize>();
if (level <= 0)
return true;
WdPassword w = new WdPassword(); WdPassword w = new WdPassword();
w.Init(passwordAuthorize,level); w.Init(passwordAuthorize, level);
w.Owner = Application.Current.MainWindow; w.Owner = Application.Current.MainWindow;
return (bool)w.ShowDialog(); bool ret = (bool)w.ShowDialog();
pwLv = w.PwLv;
return ret;
} }
private void button_apply_Click(object sender, RoutedEventArgs e) private void button_apply_Click(object sender, RoutedEventArgs e)
{ {
...@@ -70,7 +114,8 @@ namespace FLY.Thick.Base.UI ...@@ -70,7 +114,8 @@ namespace FLY.Thick.Base.UI
} }
AUTHORIZE_RESULT r = passwordAuthorize.Authorize(passwordbox.Password, Level); AUTHORIZE_RESULT r = passwordAuthorize.Authorize(passwordbox.Password, Level, out int pwLv);
PwLv = pwLv;
switch (r) switch (r)
{ {
case AUTHORIZE_RESULT.OK: case AUTHORIZE_RESULT.OK:
......
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