Commit 3a186c04 authored by 潘栩锋's avatar 潘栩锋 🚴

1. 添加 密码添加描述。 当警告权限不足够时,显示密码的 描述

2. 添加 保存的 Password.json 文件,密码是 被转为 byte[]  再保存的。 解决密码被人看懂的问题
3. 添加 grid调试界面 可以设置 调试速度
parent 5973902a
...@@ -102,7 +102,7 @@ namespace FLY.Thick.Base.UI ...@@ -102,7 +102,7 @@ namespace FLY.Thick.Base.UI
if (Db.Pws.Count() == 0) { if (Db.Pws.Count() == 0) {
foreach (var pw in DbDefault.Pws) foreach (var pw in DbDefault.Pws)
{ {
Db.Pws.Add(new PasswordCell() { Password = pw.Password, Level=pw.Level }); Db.Pws.Add(new PasswordCell() { Password = pw.Password, Level=pw.Level, Description = pw.Description });
} }
} }
} }
...@@ -158,15 +158,30 @@ namespace FLY.Thick.Base.UI ...@@ -158,15 +158,30 @@ namespace FLY.Thick.Base.UI
/// <param name="pw_lv">输入密码的级别</param> /// <param name="pw_lv">输入密码的级别</param>
/// <returns></returns> /// <returns></returns>
public AUTHORIZE_RESULT Authorize(string pw, int level, out int pw_lv) public AUTHORIZE_RESULT Authorize(string pw, int level, out int pw_lv)
{
return Authorize(pw, level, out pw_lv, out string pw_description);
}
/// <summary>
/// 输入密码,确认密码权限是否满足要求, level越大,要求权限越大
/// </summary>
/// <param name="pw">密码</param>
/// <param name="level">要求级别</param>
/// <param name="pw_lv">输入密码的级别</param>
/// <returns></returns>
public AUTHORIZE_RESULT Authorize(string pw, int level, out int pw_lv, out string pw_description)
{ {
pw_lv = 0; pw_lv = 0;
pw_description = null;
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; var pwCell = v.First();
pw_lv = pwCell.Level;
pw_description = pwCell.Description;
if (v.First().Level >= level) if (v.First().Level >= level)
return AUTHORIZE_RESULT.OK; return AUTHORIZE_RESULT.OK;
else else
...@@ -219,19 +234,70 @@ namespace FLY.Thick.Base.UI ...@@ -219,19 +234,70 @@ namespace FLY.Thick.Base.UI
} }
void Save() void Save()
{ {
//把密码都转为 byte 的数组。 再保存
PasswordJsonDb db = null;
{
string json = Newtonsoft.Json.JsonConvert.SerializeObject(Db);
db = Newtonsoft.Json.JsonConvert.DeserializeObject<PasswordJsonDb>(json);
};
PasswordEncrypt(db);
PasswordJsonDb2 p = new PasswordJsonDb2 PasswordJsonDb2 p = new PasswordJsonDb2
{ {
Db = Db, Time = Time,
Time = Time Db = db
}; };
string json = Newtonsoft.Json.JsonConvert.SerializeObject(p, Newtonsoft.Json.Formatting.Indented);
try {
string json = Newtonsoft.Json.JsonConvert.SerializeObject(p, Newtonsoft.Json.Formatting.Indented);
try
{
File.WriteAllText(file_path, json);
}
catch
{
}
}
}
/// <summary>
/// 密码加密
/// </summary>
void PasswordEncrypt(PasswordJsonDb db)
{
foreach (var pw in db.Pws)
{ {
File.WriteAllText(file_path, json); string password = pw.Password;
if (!string.IsNullOrEmpty(password))
{
byte[] bs = System.Text.Encoding.ASCII.GetBytes(password);
pw.Password = Newtonsoft.Json.JsonConvert.SerializeObject(bs);
}
} }
catch }
/// <summary>
/// 密码解密
/// </summary>
void PasswordDecrypt(PasswordJsonDb db)
{
foreach (var pw in db.Pws)
{ {
string password = pw.Password;
if (!string.IsNullOrEmpty(password))
{
try
{
byte[] bs = Newtonsoft.Json.JsonConvert.DeserializeObject<byte[]>(password);
password = System.Text.Encoding.ASCII.GetString(bs);
pw.Password = password;
}
catch
{
}
}
} }
} }
void LoadDefault() { void LoadDefault() {
...@@ -240,8 +306,10 @@ namespace FLY.Thick.Base.UI ...@@ -240,8 +306,10 @@ namespace FLY.Thick.Base.UI
string json = File.ReadAllText(file_default_path); string json = File.ReadAllText(file_default_path);
try try
{ {
var p = Newtonsoft.Json.JsonConvert.DeserializeObject<PasswordJsonDb>(json); var db = Newtonsoft.Json.JsonConvert.DeserializeObject<PasswordJsonDb>(json);
DbDefault = p; //翻译密码
PasswordDecrypt(db);
DbDefault = db;
} }
catch catch
{ {
...@@ -263,9 +331,11 @@ namespace FLY.Thick.Base.UI ...@@ -263,9 +331,11 @@ namespace FLY.Thick.Base.UI
string json = File.ReadAllText(file_path); string json = File.ReadAllText(file_path);
try try
{ {
var p = Newtonsoft.Json.JsonConvert.DeserializeObject<PasswordJsonDb2>(json); var db = Newtonsoft.Json.JsonConvert.DeserializeObject<PasswordJsonDb2>(json);
Db = p.Db; //翻译密码
Time = p.Time; PasswordDecrypt(db.Db);
Db = db.Db;
Time = db.Time;
check_db(); check_db();
} }
catch { catch {
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
<ToggleButton Style="{StaticResource Styles.ToggleButton.Check}" HorizontalAlignment="Left" IsChecked="{Binding IsADMode}" Width="30" Height="auto" Foreground="White" Background="#02FFFFFF" /> <ToggleButton Style="{StaticResource Styles.ToggleButton.Check}" HorizontalAlignment="Left" IsChecked="{Binding IsADMode}" Width="30" Height="auto" Foreground="White" Background="#02FFFFFF" />
</StackPanel> </StackPanel>
</StackPanel> </StackPanel>
</StackPanel> </StackPanel>
<local:CtMicroGage Grid.Column="1" x:Name="mircoGage" Background="Transparent" VerticalAlignment="Bottom"/> <local:CtMicroGage Grid.Column="1" x:Name="mircoGage" Background="Transparent" VerticalAlignment="Bottom"/>
</Grid> </Grid>
...@@ -52,17 +52,27 @@ ...@@ -52,17 +52,27 @@
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Grid > <Grid >
<StackPanel Orientation="Horizontal" Visibility="{Binding IsCanDownload,Converter={StaticResource visbilityconv}}"> <StackPanel Orientation="Horizontal" Visibility="{Binding IsCanDownload,Converter={StaticResource visbilityconv}}">
<StackPanel Margin="{StaticResource ControlMargin}">
<TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable}" Text="调试速度" />
<StackPanel Orientation="Horizontal">
<TextBox Style="{StaticResource Styles.Text.FieldContent.Input.Card}" Text="{Binding VJog}" />
<TextBlock Style="{StaticResource Styles.Text.FieldContent.Separator}" />
<TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}">
<Run Text="{Binding VJogMm,Mode=OneWay}"/>mm
</TextBlock>
</StackPanel>
</StackPanel>
<StackPanel Margin="{StaticResource ControlMargin}"> <StackPanel Margin="{StaticResource ControlMargin}">
<TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable}" Text="目标位置" /> <TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable}" Text="目标位置" />
<StackPanel Orientation="Horizontal" > <StackPanel Orientation="Horizontal" >
<TextBox HorizontalAlignment="Left" MaxWidth="150" Style="{StaticResource Styles.Text.FieldContent.Input}" <TextBox HorizontalAlignment="Left" MaxWidth="150" Style="{StaticResource Styles.Text.FieldContent.Input.Card}"
Text="{Binding TargetPos}" /> Text="{Binding TargetPos}" />
<StackPanel Orientation="Horizontal" > <StackPanel Orientation="Horizontal" >
<TextBlock Style="{StaticResource Styles.Text.FieldContent.Separator}" /> <TextBlock Style="{StaticResource Styles.Text.FieldContent.Separator}" />
<TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}"> <TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}">
<Run Text="{Binding TargetMm,Mode=OneWay}"/><Run Text="mm"/> <Run Text="{Binding TargetMm,Mode=OneWay}"/>mm
</TextBlock> </TextBlock>
</StackPanel> </StackPanel>
</StackPanel> </StackPanel>
</StackPanel> </StackPanel>
...@@ -78,7 +88,7 @@ ...@@ -78,7 +88,7 @@
<StackPanel Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Top"> <StackPanel Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Top">
<Button Content="删除" Style="{StaticResource Styles.Button.Square2}" Command="{Binding ClearCmd}" Background="{StaticResource MahApps.Brushes.ValidationSummary3}"/> <Button Content="删除" Style="{StaticResource Styles.Button.Square2}" Command="{Binding ClearCmd}" Background="{StaticResource MahApps.Brushes.ValidationSummary3}"/>
<Button Content="保存" Style="{StaticResource Styles.Button.Square2}" Command="{Binding SaveCmd}"/> <Button Content="保存" Style="{StaticResource Styles.Button.Square2}" Command="{Binding SaveCmd}"/>
</StackPanel> </StackPanel>
</Grid> </Grid>
</Border> </Border>
...@@ -117,9 +127,9 @@ ...@@ -117,9 +127,9 @@
<Button Content="获取正向" Style="{StaticResource Styles.Button.Square.Accent2}" Command="{Binding GetFDataCmd}" /> <Button Content="获取正向" Style="{StaticResource Styles.Button.Square.Accent2}" Command="{Binding GetFDataCmd}" />
<Button Content="获取反向" Style="{StaticResource Styles.Button.Square2}" Command="{Binding GetBDataCmd}" /> <Button Content="获取反向" Style="{StaticResource Styles.Button.Square2}" Command="{Binding GetBDataCmd}" />
</StackPanel> </StackPanel>
</Grid> </Grid>
<Grid> <Grid>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
...@@ -178,7 +188,7 @@ ...@@ -178,7 +188,7 @@
LowerValue="{Binding XLower}" LowerValue="{Binding XLower}"
UpperValue="{Binding XUpper}" /> UpperValue="{Binding XUpper}" />
</Grid> </Grid>
</StackPanel> </StackPanel>
</Border> </Border>
<Border Style="{StaticResource Styles.Card.Border}"> <Border Style="{StaticResource Styles.Card.Border}">
...@@ -191,12 +201,12 @@ ...@@ -191,12 +201,12 @@
<StackPanel Margin="{StaticResource ControlMargin}"> <StackPanel Margin="{StaticResource ControlMargin}">
<TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable}" Text="测量位置" /> <TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable}" Text="测量位置" />
<StackPanel Orientation="Horizontal" > <StackPanel Orientation="Horizontal" >
<TextBox HorizontalAlignment="Left" MaxWidth="150" Style="{StaticResource Styles.Text.FieldContent.Input}" <TextBox HorizontalAlignment="Left" MaxWidth="150" Style="{StaticResource Styles.Text.FieldContent.Input.Card}"
Text="{Binding MeasureValuePos}" /> Text="{Binding MeasureValuePos}" />
<StackPanel Orientation="Horizontal" > <StackPanel Orientation="Horizontal" >
<TextBlock Style="{StaticResource Styles.Text.FieldContent.Separator}" /> <TextBlock Style="{StaticResource Styles.Text.FieldContent.Separator}" />
<TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}"> <TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}">
<Run Text="{Binding MeasureValueMm,Mode=OneWay}"/><Run Text="mm"/> <Run Text="{Binding MeasureValueMm,Mode=OneWay}"/>mm
</TextBlock> </TextBlock>
</StackPanel> </StackPanel>
...@@ -205,12 +215,12 @@ ...@@ -205,12 +215,12 @@
<StackPanel Margin="{StaticResource ControlMargin}"> <StackPanel Margin="{StaticResource ControlMargin}">
<TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable}" Text="测量宽度" /> <TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable}" Text="测量宽度" />
<StackPanel Orientation="Horizontal" > <StackPanel Orientation="Horizontal" >
<TextBox HorizontalAlignment="Left" MaxWidth="150" Style="{StaticResource Styles.Text.FieldContent.Input}" <TextBox HorizontalAlignment="Left" MaxWidth="150" Style="{StaticResource Styles.Text.FieldContent.Input.Card}"
Text="{Binding MeasureWidthPos}" /> Text="{Binding MeasureWidthPos}" />
<StackPanel Orientation="Horizontal" > <StackPanel Orientation="Horizontal" >
<TextBlock Style="{StaticResource Styles.Text.FieldContent.Separator}" /> <TextBlock Style="{StaticResource Styles.Text.FieldContent.Separator}" />
<TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}"> <TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}">
<Run Text="{Binding MeasureWidthMm,Mode=OneWay}"/><Run Text="mm"/> <Run Text="{Binding MeasureWidthMm,Mode=OneWay}"/>mm
</TextBlock> </TextBlock>
</StackPanel> </StackPanel>
...@@ -218,7 +228,7 @@ ...@@ -218,7 +228,7 @@
</StackPanel> </StackPanel>
<Button Content="测量" Style="{StaticResource Styles.Button.Square.Accent2}" Command="{Binding MeasureCmd}"/> <Button Content="测量" Style="{StaticResource Styles.Button.Square.Accent2}" Command="{Binding MeasureCmd}"/>
</StackPanel> </StackPanel>
<ItemsControl ItemsSource="{Binding SeriesInfos}" Grid.Column="1" Margin="{StaticResource ControlMargin}"> <ItemsControl ItemsSource="{Binding SeriesInfos}" Grid.Column="1" Margin="{StaticResource ControlMargin}">
......
...@@ -23,6 +23,15 @@ namespace FLY.Thick.Base.UI ...@@ -23,6 +23,15 @@ namespace FLY.Thick.Base.UI
public event PropertyChangedEventHandler PropertyChanged; public event PropertyChangedEventHandler PropertyChanged;
#region IPgGridVm Property #region IPgGridVm Property
/// <summary>
/// 调试速度 单位:脉冲/秒
/// </summary>
public UInt32 VJog { get; set; }
/// <summary>
/// 调试速度 单位:m/min
/// </summary>
public double VJogMm => VJog* Mmpp * Speed1Scale / 1000 * 60;
/// <summary> /// <summary>
/// 目标位置 单位:脉冲 /// 目标位置 单位:脉冲
/// </summary> /// </summary>
...@@ -97,9 +106,10 @@ namespace FLY.Thick.Base.UI ...@@ -97,9 +106,10 @@ namespace FLY.Thick.Base.UI
public int PosOfGrid { get; set; } = 10; public int PosOfGrid { get; set; } = 10;
public double Mmpp { get; set; } = 0.1; public double Mmpp { get; set; } = 0.1;
public double Speed1Scale { get; set; } = 4;
ITDGageService gageService; ITDGageService gageService;
IFlyADService flyAdService; IFlyADService flyAdService;
IInitParamService initParam;
public PgGridVm() public PgGridVm()
{ {
#region 与数据无关界面参数 #region 与数据无关界面参数
...@@ -158,12 +168,15 @@ namespace FLY.Thick.Base.UI ...@@ -158,12 +168,15 @@ namespace FLY.Thick.Base.UI
IFlyADService flyADService IFlyADService flyADService
) )
{ {
var initparam = initParam; this.initParam = initParam;
this.gageService = gageService; this.gageService = gageService;
this.flyAdService = flyADService; this.flyAdService = flyADService;
Misc.BindingOperations.SetBinding(initparam, nameof(initParam.Encoder1_mmpp), this, nameof(Mmpp)); Misc.BindingOperations.SetBinding(this.initParam, nameof(initParam.Encoder1_mmpp), this, nameof(Mmpp));
Misc.BindingOperations.SetBinding(initparam, nameof(initParam.PosOfGrid), this, nameof(PosOfGrid)); Misc.BindingOperations.SetBinding(this.initParam, nameof(initParam.PosOfGrid), this, nameof(PosOfGrid));
Misc.BindingOperations.SetBinding(this.initParam, nameof(initParam.Speed1Scale), this, nameof(Speed1Scale));
Misc.BindingOperations.SetBinding(this.initParam, nameof(initParam.VJOG), this, nameof(VJog));
} }
...@@ -180,6 +193,10 @@ namespace FLY.Thick.Base.UI ...@@ -180,6 +193,10 @@ namespace FLY.Thick.Base.UI
{ {
RunToCmd = new RelayCommand(() => RunToCmd = new RelayCommand(() =>
{ {
if (VJog != initParam.VJOG) {
initParam.VJOG = VJog;
initParam.Apply();
}
gageService.StartP2(STARTP2_MODE.RUNTO, TargetPos); gageService.StartP2(STARTP2_MODE.RUNTO, TargetPos);
}); });
......
...@@ -90,7 +90,7 @@ ...@@ -90,7 +90,7 @@
<StackPanel Margin="{StaticResource ControlMargin}"> <StackPanel Margin="{StaticResource ControlMargin}">
<TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable}" Text="编码器2比例" /> <TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable}" Text="编码器2比例" />
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<TextBox Style="{StaticResource Styles.Text.FieldContent.Input.Card}" Text="{Binding Encoder2_mmpp}" HorizontalAlignment="Left"/> <TextBox Style="{StaticResource Styles.Text.FieldContent.Input.Card}" Text="{Binding Encoder2_mmpp,StringFormat={}{0:F5}}" HorizontalAlignment="Left"/>
<TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}" > <TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}" >
<Run Text="mm/脉冲"/> <Run Text="mm/脉冲"/>
</TextBlock> </TextBlock>
...@@ -203,14 +203,14 @@ ...@@ -203,14 +203,14 @@
<TextBox Style="{StaticResource Styles.Text.FieldContent.Input.Card}" Text="{Binding VJOG}" /> <TextBox Style="{StaticResource Styles.Text.FieldContent.Input.Card}" Text="{Binding VJOG}" />
<TextBlock Style="{StaticResource Styles.Text.FieldContent.Separator}" /> <TextBlock Style="{StaticResource Styles.Text.FieldContent.Separator}" />
<TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}" > <TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}" >
<Run> <Run>
<MultiBinding Converter="{StaticResource outsp2mpminconv}" Mode="OneWay" StringFormat="{}{0:F1}"> <MultiBinding Converter="{StaticResource outsp2mpminconv}" Mode="OneWay" StringFormat="{}{0:F1}">
<Binding Path="VJOG" /> <Binding Path="VJOG" />
<Binding Path="Encoder1_mmpp" /> <Binding Path="Encoder1_mmpp" />
<Binding Path="Speed1Scale" /> <Binding Path="Speed1Scale" />
</MultiBinding> </MultiBinding>
</Run> </Run>
<Run Text="m/min" /> <Run Text="m/min" />
</TextBlock> </TextBlock>
</StackPanel> </StackPanel>
</StackPanel> </StackPanel>
......
...@@ -34,6 +34,14 @@ ...@@ -34,6 +34,14 @@
</Style> </Style>
</DataGrid.CellStyle> </DataGrid.CellStyle>
<DataGrid.Columns> <DataGrid.Columns>
<DataGridTextColumn CanUserReorder="False" Binding="{Binding Description}" >
<DataGridTextColumn.Header>
<StackPanel Orientation="Horizontal">
<TextBlock Style="{StaticResource Styles.Text.FieldHeader}"
Text="描述"/>
</StackPanel>
</DataGridTextColumn.Header>
</DataGridTextColumn>
<DataGridTextColumn CanUserReorder="False" Binding="{Binding Level}" > <DataGridTextColumn CanUserReorder="False" Binding="{Binding Level}" >
<DataGridTextColumn.Header> <DataGridTextColumn.Header>
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
......
...@@ -69,7 +69,7 @@ namespace FLY.Thick.Base.UI ...@@ -69,7 +69,7 @@ namespace FLY.Thick.Base.UI
foreach (var c in this.passwordAuthorize.Db.Pws) foreach (var c in this.passwordAuthorize.Db.Pws)
{ {
Pws.Add(new PasswordCell() { Password = c.Password, Level = c.Level }); Pws.Add(new PasswordCell() { Password = c.Password, Level = c.Level, Description = c.Description });
} }
} }
if (this.passwordAuthorize.Db.UiLvs != null) if (this.passwordAuthorize.Db.UiLvs != null)
......
...@@ -114,7 +114,7 @@ namespace FLY.Thick.Base.UI ...@@ -114,7 +114,7 @@ namespace FLY.Thick.Base.UI
} }
AUTHORIZE_RESULT r = passwordAuthorize.Authorize(passwordbox.Password, Level, out int pwLv); AUTHORIZE_RESULT r = passwordAuthorize.Authorize(passwordbox.Password, Level, out int pwLv, out string pwDesp);
PwLv = pwLv; PwLv = pwLv;
switch (r) switch (r)
{ {
...@@ -127,7 +127,7 @@ namespace FLY.Thick.Base.UI ...@@ -127,7 +127,7 @@ namespace FLY.Thick.Base.UI
} }
case AUTHORIZE_RESULT.ERR_LEVEL: case AUTHORIZE_RESULT.ERR_LEVEL:
{ {
FLY.ControlLibrary.Window_WarningTip.Show("错误", $"权限不足 需要Lv{Level}以上密码", FLY.ControlLibrary.Window_WarningTip.Show("错误", $"{pwDesp}权限不足 需要Lv{Level}以上密码",
TimeSpan.FromSeconds(2)); TimeSpan.FromSeconds(2));
return; return;
} }
......
...@@ -17,6 +17,10 @@ namespace FLY.Thick.Base.Common ...@@ -17,6 +17,10 @@ namespace FLY.Thick.Base.Common
/// </summary> /// </summary>
public int Level { get; set; } public int Level { get; set; }
/// <summary>
/// 描述,例如 "管理员"
/// </summary>
public string Description { get; set; }
public event PropertyChangedEventHandler PropertyChanged; public event PropertyChangedEventHandler PropertyChanged;
} }
/// <summary> /// <summary>
......
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