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

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

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