1 year ago
parent 3badf598e3
commit d62c511406

Binary file not shown.

Binary file not shown.

@ -4,11 +4,9 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:local="clr-namespace:Aucma.Core.PrintTo.Views"
xmlns:uc="clr-namespace:Aucma.Core.PrintTo.Views.Page"
mc:Ignorable="d" mc:Ignorable="d"
d:DesignHeight="600" d:DesignHeight="600"
d:DesignWidth="800"> d:DesignWidth="1500">
<UserControl.Resources> <UserControl.Resources>
<Style x:Key="DataGridTextColumnCenterSytle" TargetType="{x:Type TextBlock}"> <Style x:Key="DataGridTextColumnCenterSytle" TargetType="{x:Type TextBlock}">
<Setter Property="VerticalAlignment" Value="Center" /> <Setter Property="VerticalAlignment" Value="Center" />
@ -99,7 +97,7 @@
<Setter Property="Focusable" Value="false" /> <Setter Property="Focusable" Value="false" />
<Setter Property="IsTabStop" Value="false" /> <Setter Property="IsTabStop" Value="false" />
<Setter Property="Padding" Value="0" /> <Setter Property="Padding" Value="0" />
<Setter Property="Width" Value="20" /> <Setter Property="Width" Value="30" />
</Style> </Style>
</Style.Resources> </Style.Resources>
<Setter Property="Stylus.IsPressAndHoldEnabled" Value="false" /> <Setter Property="Stylus.IsPressAndHoldEnabled" Value="false" />
@ -126,10 +124,10 @@
<KeyBinding Gesture="PageDown" Command="{x:Static Slider.DecreaseLarge}" /> <KeyBinding Gesture="PageDown" Command="{x:Static Slider.DecreaseLarge}" />
</TextBox.InputBindings> </TextBox.InputBindings>
</TextBox> </TextBox>
<RepeatButton Grid.Row="0" Grid.Column="1" Command="{x:Static Slider.IncreaseSmall}" Style="{StaticResource RepeatButtonStyle}"> <RepeatButton Grid.Row="0" Grid.Column="1" Command="{x:Static Slider.IncreaseSmall}" Style="{StaticResource RepeatButtonStyle}">
<Path Data="M4,0 L0,4 8,4 Z" Fill="Black" /> <Path Data="M4,0 L0,4 8,4 Z" Fill="Black" />
</RepeatButton> </RepeatButton>
<RepeatButton Grid.Row="1" Grid.Column="1" Command="{x:Static Slider.DecreaseSmall}" Style="{StaticResource RepeatButtonStyle}"> <RepeatButton Grid.Row="1" Grid.Column="1" Command="{x:Static Slider.DecreaseSmall}" Style="{StaticResource RepeatButtonStyle}">
<Path Data="M0,0 L4,4 8,0 Z" Fill="Black" /> <Path Data="M0,0 L4,4 8,0 Z" Fill="Black" />
</RepeatButton> </RepeatButton>
<!-- 由于Slider的内部实现要求存在这些必要组件,所以必须保留,但是设置为隐藏即可 --> <!-- 由于Slider的内部实现要求存在这些必要组件,所以必须保留,但是设置为隐藏即可 -->
@ -206,46 +204,51 @@
<WrapPanel Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0 15"> <WrapPanel Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0 15">
<TextBlock Text="产品编码" FontSize="15" Foreground="white" HorizontalAlignment="Center" VerticalAlignment="Center" /> <TextBlock Text="产品编码" FontSize="15" Foreground="white" HorizontalAlignment="Center" VerticalAlignment="Center" />
<TextBox x:Name="ProductNo" Foreground="white" Text="{Binding SelectedItem.ProductCode, ElementName=dgvMH}" IsReadOnly="True" Margin="15 0 0 0 " FontSize="15" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Width="300" <TextBox x:Name="ProductNo" Foreground="white" Text="{Binding SelectedItem.ProductCode, ElementName=dgvMH}" IsReadOnly="True" Margin="15 0 0 0 " FontSize="15" VerticalContentAlignment="Center" HorizontalContentAlignment="Left" Width="300"
materialDesign:HintAssist.Hint="产品编码" /> materialDesign:HintAssist.Hint="产品编码" />
</WrapPanel> </WrapPanel>
<WrapPanel Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0 15"> <WrapPanel Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0 15">
<TextBlock Text="产品名称" FontSize="15" Foreground="white" HorizontalAlignment="Center" VerticalAlignment="Center" /> <TextBlock Text="产品名称" FontSize="15" Foreground="white" HorizontalAlignment="Center" VerticalAlignment="Center" />
<TextBox x:Name="ProductName" Foreground="white" Text="{Binding SelectedItem.ProductName, ElementName=dgvMH}" IsReadOnly="True" Margin="15 0 0 0" FontSize="15" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Width="{Binding Path=ActualWidth, ElementName=ProductNo}" <TextBox x:Name="ProductName" Foreground="white" Text="{Binding SelectedItem.ProductName, ElementName=dgvMH}" IsReadOnly="True" Margin="15 0 0 0" FontSize="15" VerticalContentAlignment="Center" HorizontalContentAlignment="Left" Width="{Binding Path=ActualWidth, ElementName=ProductNo}"
materialDesign:HintAssist.Hint="产品名称" /> materialDesign:HintAssist.Hint="产品名称" />
</WrapPanel> </WrapPanel>
<WrapPanel Grid.Row="2" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0 15"> <WrapPanel Grid.Row="2" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0 15">
<TextBlock Text="物料名称" FontSize="15" Foreground="white" HorizontalAlignment="Center" VerticalAlignment="Center" /> <TextBlock Text="物料名称" FontSize="15" Foreground="white" HorizontalAlignment="Center" VerticalAlignment="Center" />
<TextBox x:Name="MaterialName" Foreground="white" Text="{Binding SelectedItem.MaterialName, ElementName=dgvMH}" IsReadOnly="True" Margin="15 0 0 0" FontSize="15" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Width="{Binding Path=ActualWidth, ElementName=ProductNo}" <TextBox x:Name="MaterialName" Foreground="white" Text="{Binding SelectedItem.MaterialName, ElementName=dgvMH}" IsReadOnly="True" Margin="15 0 0 0" FontSize="15" VerticalContentAlignment="Center" HorizontalContentAlignment="Left" Width="{Binding Path=ActualWidth, ElementName=ProductNo}"
materialDesign:HintAssist.Hint="物料名称" /> materialDesign:HintAssist.Hint="物料名称" />
</WrapPanel> </WrapPanel>
<WrapPanel Grid.Row="3" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0 15"> <WrapPanel Grid.Row="3" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0 15">
<TextBlock Text="打印数量" FontSize="15" Foreground="white" HorizontalAlignment="Center" VerticalAlignment="Center" /> <TextBlock Text="打印数量" FontSize="15" Foreground="white" HorizontalAlignment="Center" VerticalAlignment="Center" />
<!--<TextBox x:Name="PlanAmount" Foreground="white" Text="{Binding SelectedItem.StandardAmount, ElementName=dgvMH}" Margin="15 0 0 0" FontSize="15" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Width="{Binding Path=ActualWidth, ElementName=ProductNo}" <!--<TextBox x:Name="PlanAmount" Foreground="white" Text="{Binding SelectedItem.StandardAmount, ElementName=dgvMH}" Margin="15 0 0 0" FontSize="15" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Width="{Binding Path=ActualWidth, ElementName=ProductNo}"
materialDesign:HintAssist.Hint="打印数量"/>--> materialDesign:HintAssist.Hint="打印数量"/>-->
<Slider x:Name="PlanAmount" Foreground="white" Margin="15 0 0 0" FontSize="15" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Width="{Binding Path=ActualWidth, ElementName=ProductNo}"/> <Slider x:Name="PlanAmount" Minimum="0" Maximum="500" Value="{Binding SelectedItem.StandardAmount, ElementName=dgvMH}" Foreground="white" Height="30" VerticalContentAlignment="Center" HorizontalContentAlignment="Left" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="15 0 0 0" FontSize="15" Width="240"/>
<TextBlock Text="1~500" Width="50" Margin="10 0 0 0" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</WrapPanel> </WrapPanel>
<Border Grid.Row="4" BorderBrush="#0288d1" BorderThickness="1" CornerRadius="5" Margin="30 5"> <Border Grid.Row="4" BorderBrush="#0288d1" BorderThickness="1" CornerRadius="5" Margin="30 5" >
<StackPanel > <StackPanel >
<WrapPanel Height="110"> <WrapPanel Height="110">
<RadioButton Content="内胆" Foreground="white" FontSize="15" x:Name="内胆" Margin="10 5" Command="{Binding RadioQueryCommand}" CommandParameter="{Binding Name, ElementName=内胆}"/> <RadioButton Content="内胆码-L" Foreground="white" FontSize="15" x:Name="内胆" Margin="10 5" Command="{Binding RadioQueryCommand}" CommandParameter="{Binding Name, ElementName=内胆}"/>
<RadioButton Content="U壳" Foreground="white" FontSize="15" x:Name="U壳" Margin="10 5" Command="{Binding RadioQueryCommand}" CommandParameter="{Binding Name,ElementName=U壳}"/> <RadioButton Content="箱体码-B" Foreground="white" FontSize="15" x:Name="U壳" Margin="10 5" Command="{Binding RadioQueryCommand}" CommandParameter="{Binding Name,ElementName=U壳}"/>
</WrapPanel> </WrapPanel>
<Button Content="添加" Foreground="White" BorderBrush="#0288d1" Background="#4285DE" HorizontalAlignment="Right" VerticalAlignment="Bottom" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" /> <!--<Button Content="添加" Foreground="White" BorderBrush="#0288d1" Background="#4285DE" HorizontalAlignment="Right" VerticalAlignment="Bottom" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" />-->
</StackPanel> </StackPanel>
</Border> </Border>
<WrapPanel Grid.Row="5" HorizontalAlignment="Center"> <WrapPanel Grid.Row="5" HorizontalAlignment="Center">
<Button <Button
Background="#4285DE" Background="#4285DE"
Content="打印" Margin="0 0" Command="{Binding PrintCommand}" CommandParameter="{Binding ElementName=ProductNo,Path=Text}"/> Content="打印" Width="100" Margin="0 10 0 0" Command="{Binding PrintCommand}" CommandParameter="{Binding ElementName=ProductNo,Path=Text}"/>
<Button <Button
Background="#4285DE" Background="#4285DE"
Content="补打" Margin="10 0 0 0" Command="{Binding SupplementPrintCommand}" CommandParameter="{Binding ElementName=ProductNo,Path=Text}" Content="补打" Margin="10 10 0 0" Width="100" Command="{Binding SupplementPrintCommand}" CommandParameter="{Binding ElementName=ProductNo,Path=Text}"
IsEnabled="{Binding DataContext.ControlsEnabled, RelativeSource={RelativeSource FindAncestor, AncestorType=Window}}"/> IsEnabled="{Binding DataContext.ControlsEnabled, RelativeSource={RelativeSource FindAncestor, AncestorType=Window}}"/>
<Button <Button
Background="#4285DE" Background="#4285DE"
Content="续打" Margin="10 0 0 0" Command="{Binding SupplementPrintCommand}" Content="续打" Margin="10 10 0 0" Width="100" Command="{Binding SupplementPrintCommand}"
IsEnabled="{Binding DataContext.ControlsEnabled, RelativeSource={RelativeSource FindAncestor, AncestorType=Window}}" CommandParameter="{Binding ElementName=ProductNo,Path=Text}"/>
<Button
Background="#4285DE"
Content="设备" Margin="10 10 0 0" Width="100" Command="{Binding SupplementPrintCommand}"
IsEnabled="{Binding DataContext.ControlsEnabled, RelativeSource={RelativeSource FindAncestor, AncestorType=Window}}" CommandParameter="{Binding ElementName=ProductNo,Path=Text}"/> IsEnabled="{Binding DataContext.ControlsEnabled, RelativeSource={RelativeSource FindAncestor, AncestorType=Window}}" CommandParameter="{Binding ElementName=ProductNo,Path=Text}"/>
</WrapPanel> </WrapPanel>

@ -1,104 +0,0 @@
<UserControl x:Class="Aucma.Core.PrintTo.Views.Page.NumUpDown"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Aucma.Core.PrintTo.Views.Page"
mc:Ignorable="d"
d:DesignHeight="36" d:DesignWidth="100">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="6*" MinWidth="20"/>
<ColumnDefinition Width="9*" MinWidth="36"/>
<ColumnDefinition Width="6*" MinWidth="20"/>
</Grid.ColumnDefinitions>
<RepeatButton Grid.Column="0" x:Name="btnSub" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Content=" - " Margin="0 0 0 0" Click="btnSubClick" FontSize="20"
ClickMode="Press"
Delay="500"
Interval="80">
<RepeatButton.Style>
<Style TargetType="RepeatButton">
<Setter Property="Background" Value="#DDDDDD"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type RepeatButton}">
<Border BorderBrush="{TemplateBinding Control.BorderBrush}" Background="{TemplateBinding Background}" BorderThickness="0.5 0.5 0 0.5" CornerRadius="6 0 0 6">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#87CEFA"/>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Background" Value="#30BCFA"/>
<Setter Property="Foreground" Value="#FFFFFF"/>
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Background" Value="WhiteSmoke"/>
</Trigger>
</Style.Triggers>
</Style>
</RepeatButton.Style>
</RepeatButton>
<TextBox
Grid.Column="2"
x:Name="tbContent"
Margin="0 0 0 0"
FontSize="12"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"
TextChanged="tbContentTextChanged"
GotFocus="tbContentGotFocus"
LostFocus="tbCntLostFocus"
Text="0">
<TextBox.Style>
<Style TargetType="TextBox">
<Setter Property="Background" Value="#FFFFFF"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#F0F8FF"/>
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Background" Value="#FFFFFF"/>
</Trigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
<RepeatButton Grid.Column="3" x:Name="btnAdd" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Content=" + " Margin="0 0 0 0" Click="btnAddClick" FontSize="20"
ClickMode="Press"
Delay="500"
Interval="80">
<RepeatButton.Style>
<Style TargetType="RepeatButton">
<Setter Property="Background" Value="#DDDDDD"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type RepeatButton}">
<Border BorderBrush="{TemplateBinding Control.BorderBrush}" Background="{TemplateBinding Background}" BorderThickness="0 0.5 0.5 0.5" CornerRadius="0 6 6 0">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#87CEFA"/>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Background" Value="#30BCFA"/>
<Setter Property="Foreground" Value="#FFFFFF"/>
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Background" Value="WhiteSmoke"/>
</Trigger>
</Style.Triggers>
</Style>
</RepeatButton.Style>
</RepeatButton>
</Grid>
</UserControl>

@ -1,418 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Aucma.Core.PrintTo.Views.Page
{
/// <summary>
/// NumUpDown.xaml 的交互逻辑
/// </summary>
public partial class NumUpDown : UserControl
{
public NumUpDown()
{
InitializeComponent();
}
/// <summary>
/// 当前值
/// </summary>
private decimal AvaliableVal = 0;
/// <summary>
/// Sync Resource
/// </summary>
private static object lockObj = new object();
/// <summary>
/// label 显示内容
/// </summary>
public string LabeContent
{
get { return GetValue(LabeContentProperty).ToString(); }
set { SetValue(LabeContentProperty, value); }
}
/// <summary>
/// 最小值
/// </summary>
public decimal MinValue
{
get { return Convert.ToDecimal(GetValue(MinValueProperty)); }
set { SetValue(MinValueProperty, value); }
}
/// <summary>
/// 最大值
/// </summary>
public decimal MaxValue
{
get { return Convert.ToDecimal(GetValue(MaxValueProperty)); }
set
{
SetValue(MaxValueProperty, value);
}
}
/// <summary>
/// 默认值
/// </summary>
public decimal DefaultValue
{
get { return Convert.ToDecimal(GetValue(DefaultValueProperty)); }
set
{
SetValue(DefaultValueProperty, value);
NumericValue = DefaultValue;
}
}
/// <summary>
/// 是否整数
/// </summary>
public bool IsInteger
{
get { return Convert.ToBoolean(GetValue(IsIntegerProperty)); }
set { SetValue(IsIntegerProperty, value); }
}
/// <summary>
/// 步长
/// </summary>
public decimal OffsetValue
{
get { return Convert.ToDecimal(GetValue(OffsetValueProperty)); }
set { SetValue(OffsetValueProperty, value); }
}
/// <summary>
/// 输入框值
/// </summary>
public decimal NumericValue
{
get { return Convert.ToDecimal(GetValue(NumericValueProperty)); }
set
{
SetValue(NumericValueProperty, value);
}
}
/// <summary>
/// 左侧的Label的宽度
/// </summary>
public double LabelWidth
{
get { return Convert.ToDouble(GetValue(LabelWidthValueProperty)); }
set { SetValue(LabelWidthValueProperty, value); }
}
/// <summary>
/// 标签的可见性
/// </summary>
public string LabelVisibility
{
get { return Convert.ToString(GetValue(LabelVisibilityValueProperty)); }
set { SetValue(LabelVisibilityValueProperty, value); }
}
public static readonly DependencyProperty LabeContentProperty =
DependencyProperty.Register("LabeContent",
typeof(string),
typeof(NumUpDown),
new PropertyMetadata("", new PropertyChangedCallback(LabelContentCallback))
);
private static void LabelContentCallback(DependencyObject obj, DependencyPropertyChangedEventArgs e)
{
NumUpDown control = obj as NumUpDown;
//control.myNumLabelName.Content = e.NewValue.ToString();
}
public static readonly DependencyProperty MinValueProperty =
DependencyProperty.Register("MinValue",
typeof(decimal),
typeof(NumUpDown),
new PropertyMetadata(-1m, null)
);
public static readonly DependencyProperty MaxValueProperty =
DependencyProperty.Register("MaxValue",
typeof(decimal),
typeof(NumUpDown),
new PropertyMetadata(-1m, new PropertyChangedCallback(MaxValueChangedCallback))
);
public static readonly DependencyProperty DefaultValueProperty =
DependencyProperty.Register("DefaultValue",
typeof(decimal),
typeof(NumUpDown)
);
public static readonly DependencyProperty IsIntegerProperty =
DependencyProperty.Register("IsInteger",
typeof(bool),
typeof(NumUpDown), new PropertyMetadata(false)
);
public static readonly DependencyProperty OffsetValueProperty =
DependencyProperty.Register("OffsetValue",
typeof(decimal),
typeof(NumUpDown), new PropertyMetadata(1m)
);
public static readonly DependencyProperty NumericValueProperty =
DependencyProperty.Register("NumericValue",
typeof(decimal),
typeof(NumUpDown),
new PropertyMetadata(new PropertyChangedCallback(NumericValueChangedCallback))
);
public static readonly DependencyProperty LabelWidthValueProperty =
DependencyProperty.Register("LabelWidth",
typeof(double),
typeof(NumUpDown),
new PropertyMetadata(0.0, new PropertyChangedCallback(LabelWidthCallback))
);
public static readonly DependencyProperty LabelVisibilityValueProperty =
DependencyProperty.Register("LabelVisibility",
typeof(string),
typeof(NumUpDown),
new PropertyMetadata("Visible", new PropertyChangedCallback(LabelVisibilityCallback))
);
private static void LabelWidthCallback(DependencyObject obj, DependencyPropertyChangedEventArgs e)
{
NumUpDown control = obj as NumUpDown;
//control.myNumLabelName.Width = double.Parse(string.IsNullOrEmpty(e.NewValue.ToString()) ? "0" : e.NewValue.ToString());
}
private static void LabelVisibilityCallback(DependencyObject obj, DependencyPropertyChangedEventArgs e)
{
NumUpDown control = obj as NumUpDown;
string visi = e.NewValue.ToString();
//if (visi.Equals(Visibility.Visible.ToString()))
// control.myNumLabelName.Visibility = Visibility.Visible;
//else if (visi.Equals(Visibility.Hidden.ToString()))
// control.myNumLabelName.Visibility = Visibility.Hidden;
//else
// control.myNumLabelName.Visibility = Visibility.Collapsed;
}
private static void MaxValueChangedCallback(DependencyObject obj, DependencyPropertyChangedEventArgs e)
{
NumUpDown control = obj as NumUpDown;
control.tbContent.MaxLength = e.NewValue.ToString().Length;
}
private static void NumericValueChangedCallback(DependencyObject obj, DependencyPropertyChangedEventArgs e)
{
NumUpDown control = obj as NumUpDown;
control.AvaliableVal = Convert.ToDecimal(e.NewValue);
control.tbContent.Text = e.NewValue.ToString();
control.tbContent.SelectionStart = control.tbContent.Text.Length;
}
/// <summary>
/// 增加按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnAddClick(object sender, RoutedEventArgs e)
{
decimal offsetValue = OffsetValue;
AvaliableVal = Convert.ToDecimal(tbContent.Text);
decimal newValue;
if (AvaliableVal > MaxValue)
{
NumericValue = MaxValue;
return;
}
if (AvaliableVal + offsetValue > MaxValue)
{
NumericValue = MaxValue;
return;
}
newValue = AvaliableVal + offsetValue;
if (newValue < MinValue)
{
NumericValue = MinValue;
return;
}
if (IsInteger)
newValue = decimal.Parse(newValue.ToString("0"));
else
newValue = decimal.Parse(newValue.ToString("0.######"));
tbContent.Text = newValue.ToString();
NumericValue = newValue;
}
/// <summary>
/// 减少按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnSubClick(object sender, RoutedEventArgs e)
{
AvaliableVal = Convert.ToDecimal(tbContent.Text);
if (AvaliableVal < MinValue)
{
NumericValue = MinValue;
return;
}
if (AvaliableVal - OffsetValue < MinValue)
{
NumericValue = MinValue;
return;
}
if (AvaliableVal > MaxValue)
{
NumericValue = MaxValue;
return;
}
decimal newValue;
newValue = AvaliableVal - OffsetValue;
if (IsInteger)
newValue = decimal.Parse(newValue.ToString("0"));
else
newValue = decimal.Parse(newValue.ToString("0.######"));
tbContent.Text = newValue.ToString();
NumericValue = newValue;
}
/// <summary>
/// 获取焦点
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tbContentGotFocus(object sender, RoutedEventArgs e)
{
TextBox tb = sender as System.Windows.Controls.TextBox;
this.AvaliableVal = Convert.ToDecimal(tb.Text);
}
/// <summary>
/// 是否数字
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
private bool IsNumber(string input)
{
string pattern = "^-?\\d+$|^(-?\\d+)(\\.\\d+)?$";
Regex regex = new Regex(pattern);
return regex.IsMatch(input);
}
/// <summary>
/// 是否整数
/// </summary>
/// <param name="strNumber"></param>
/// <returns></returns>
private bool IsWholeNumber(string strNumber)
{
Regex g = new Regex(@"^[0-9]\d*$");
return g.IsMatch(strNumber);
}
/// <summary>
/// 数字Text变动Event
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tbContentTextChanged(object sender, TextChangedEventArgs e)
{
lock (lockObj)
{
TextBox tb = sender as TextBox;
if (tb != null)
{
bool isNumeric = IsNumber(tb.Text);
if (isNumeric)
{
var vv = Convert.ToDecimal(tb.Text);
if (vv > MaxValue && MaxValue != -1)
{
//此句为了解决实际应用时数据刷新的问题
NumericValue = MaxValue - 1;
try
{
System.Threading.Thread.Sleep(0);
}
catch { }
NumericValue = MaxValue;
return;
}
NumericValue = vv;
}
else
{
//NumericValue = null;
}
}
}
}
/// <summary>
/// Lost焦点事件处理
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tbCntLostFocus(object sender, RoutedEventArgs e)
{
lock (lockObj)
{
TextBox tb = sender as TextBox;
bool isNumeric = IsNumber(tb.Text);
if (isNumeric && IsInteger)
{
isNumeric = IsWholeNumber(tb.Text);
}
decimal oldValue = this.AvaliableVal;
if (isNumeric)
{
decimal ctrlValue = Convert.ToDecimal(tb.Text);
if (ctrlValue < MinValue)
{
if (oldValue <= MaxValue && oldValue >= MinValue)
NumericValue = oldValue;
else
NumericValue = MinValue;
AvaliableVal = NumericValue;
}
else if (ctrlValue > MaxValue)
{
if (oldValue <= MaxValue && oldValue >= MinValue)
NumericValue = oldValue;
else
NumericValue = MaxValue;
AvaliableVal = NumericValue;
}
else
{
AvaliableVal = ctrlValue;
NumericValue = AvaliableVal;
}
}
else
{
if (oldValue > MaxValue || oldValue < MinValue)
oldValue = DefaultValue;
tb.Text = oldValue.ToString();
NumericValue = oldValue;
}
}
}
}
}

@ -1 +1 @@
e45d70deaceb948101b4b7a7b5089f50e6660b96 597401e34e9a3074c66c6b568d2f987ded092c0e

@ -584,8 +584,6 @@ D:\gitea\AUCMA\AUCMA_SCADA\Aucma.Core.PrintTo\bin\Debug\net6.0-windows\FastRepor
D:\gitea\AUCMA\AUCMA_SCADA\Aucma.Core.PrintTo\bin\Debug\net6.0-windows\HslCommunication.dll D:\gitea\AUCMA\AUCMA_SCADA\Aucma.Core.PrintTo\bin\Debug\net6.0-windows\HslCommunication.dll
D:\gitea\AUCMA\AUCMA_SCADA\Aucma.Core.PrintTo\bin\Debug\net6.0-windows\MvCodeReaderSDK.Net.dll D:\gitea\AUCMA\AUCMA_SCADA\Aucma.Core.PrintTo\bin\Debug\net6.0-windows\MvCodeReaderSDK.Net.dll
D:\gitea\AUCMA\AUCMA_SCADA\Aucma.Core.PrintTo\bin\Debug\net6.0-windows\Aucma.Core.Scanner.pdb D:\gitea\AUCMA\AUCMA_SCADA\Aucma.Core.PrintTo\bin\Debug\net6.0-windows\Aucma.Core.Scanner.pdb
D:\gitea\AUCMA\AUCMA_SCADA\Aucma.Core.PrintTo\obj\Debug\net6.0-windows\Views\Page\NumUpDown.g.cs
D:\gitea\AUCMA\AUCMA_SCADA\Aucma.Core.PrintTo\obj\Debug\net6.0-windows\Views\Page\NumUpDown.baml
D:\gitea\AUCMA\AUCMA_SCADA\Aucma.Core.PrintTo\bin\Debug\net6.0-windows\Aucma.Core.PLc.dll D:\gitea\AUCMA\AUCMA_SCADA\Aucma.Core.PrintTo\bin\Debug\net6.0-windows\Aucma.Core.PLc.dll
D:\gitea\AUCMA\AUCMA_SCADA\Aucma.Core.PrintTo\bin\Debug\net6.0-windows\Aucma.Core.RunPlc.dll D:\gitea\AUCMA\AUCMA_SCADA\Aucma.Core.PrintTo\bin\Debug\net6.0-windows\Aucma.Core.RunPlc.dll
D:\gitea\AUCMA\AUCMA_SCADA\Aucma.Core.PrintTo\bin\Debug\net6.0-windows\Aucma.Core.PLc.pdb D:\gitea\AUCMA\AUCMA_SCADA\Aucma.Core.PrintTo\bin\Debug\net6.0-windows\Aucma.Core.PLc.pdb

@ -10,11 +10,11 @@ none
false false
TRACE;DEBUG;NET;NET6_0;NETCOREAPP TRACE;DEBUG;NET;NET6_0;NETCOREAPP
D:\gitea\AUCMA\AUCMA_SCADA\Aucma.Core.PrintTo\App.xaml D:\gitea\AUCMA\AUCMA_SCADA\Aucma.Core.PrintTo\App.xaml
8-1065211271 7-1193702131
21064389523 21064389523
211934508404 20-526104487
418-123918186 418-123918186
Assets\Styles\DefaultStyles.xaml;Views\ButtomPageView.xaml;Views\HomeWindowView.xaml;Views\IndexPage.xaml;Views\MainWindow.xaml;Views\Page\NumUpDown.xaml;Views\PrintToDevView.xaml;Views\SupplementPrintPageView.xaml; Assets\Styles\DefaultStyles.xaml;Views\ButtomPageView.xaml;Views\HomeWindowView.xaml;Views\IndexPage.xaml;Views\MainWindow.xaml;Views\PrintToDevView.xaml;Views\SupplementPrintPageView.xaml;
False False

@ -10,11 +10,11 @@ none
false false
TRACE;DEBUG;NET;NET6_0;NETCOREAPP TRACE;DEBUG;NET;NET6_0;NETCOREAPP
D:\gitea\AUCMA\AUCMA_SCADA\Aucma.Core.PrintTo\App.xaml D:\gitea\AUCMA\AUCMA_SCADA\Aucma.Core.PrintTo\App.xaml
8-1065211271 7-1193702131
21064389523 21064389523
23-1295523103 22538831302
418-123918186 418-123918186
Assets\Styles\DefaultStyles.xaml;Views\ButtomPageView.xaml;Views\HomeWindowView.xaml;Views\IndexPage.xaml;Views\MainWindow.xaml;Views\Page\NumUpDown.xaml;Views\PrintToDevView.xaml;Views\SupplementPrintPageView.xaml; Assets\Styles\DefaultStyles.xaml;Views\ButtomPageView.xaml;Views\HomeWindowView.xaml;Views\IndexPage.xaml;Views\MainWindow.xaml;Views\PrintToDevView.xaml;Views\SupplementPrintPageView.xaml;
True False

@ -2,8 +2,6 @@
FD:\gitea\AUCMA\AUCMA_SCADA\Aucma.Core.PrintTo\App.xaml;; FD:\gitea\AUCMA\AUCMA_SCADA\Aucma.Core.PrintTo\App.xaml;;
FD:\gitea\AUCMA\AUCMA_SCADA\Aucma.Core.PrintTo\Views\ButtomPageView.xaml;; FD:\gitea\AUCMA\AUCMA_SCADA\Aucma.Core.PrintTo\Views\ButtomPageView.xaml;;
FD:\gitea\AUCMA\AUCMA_SCADA\Aucma.Core.PrintTo\Views\HomeWindowView.xaml;; FD:\gitea\AUCMA\AUCMA_SCADA\Aucma.Core.PrintTo\Views\HomeWindowView.xaml;;
FD:\gitea\AUCMA\AUCMA_SCADA\Aucma.Core.PrintTo\Views\IndexPage.xaml;;
FD:\gitea\AUCMA\AUCMA_SCADA\Aucma.Core.PrintTo\Views\Page\NumUpDown.xaml;;
FD:\gitea\AUCMA\AUCMA_SCADA\Aucma.Core.PrintTo\Views\PrintToDevView.xaml;; FD:\gitea\AUCMA\AUCMA_SCADA\Aucma.Core.PrintTo\Views\PrintToDevView.xaml;;
FD:\gitea\AUCMA\AUCMA_SCADA\Aucma.Core.PrintTo\Views\SupplementPrintPageView.xaml;; FD:\gitea\AUCMA\AUCMA_SCADA\Aucma.Core.PrintTo\Views\SupplementPrintPageView.xaml;;

@ -15,7 +15,7 @@ namespace XamlGeneratedNamespace {
/// GeneratedInternalTypeHelper /// GeneratedInternalTypeHelper
/// </summary> /// </summary>
[System.Diagnostics.DebuggerNonUserCodeAttribute()] [System.Diagnostics.DebuggerNonUserCodeAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "7.0.12.0")] [System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "7.0.5.0")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public sealed class GeneratedInternalTypeHelper : System.Windows.Markup.InternalTypeHelper { public sealed class GeneratedInternalTypeHelper : System.Windows.Markup.InternalTypeHelper {

@ -1,4 +1,4 @@
#pragma checksum "..\..\..\..\Views\IndexPage.xaml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "3749AD74C5EE15C020F09690F0AF67B24ED46CDC" #pragma checksum "..\..\..\..\Views\IndexPage.xaml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "7004EF4D93767F02E48DBEEC7CAC09C6074BA678"
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// <auto-generated> // <auto-generated>
// 此代码由工具生成。 // 此代码由工具生成。
@ -9,8 +9,6 @@
// </auto-generated> // </auto-generated>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
using Aucma.Core.PrintTo.Views;
using Aucma.Core.PrintTo.Views.Page;
using MaterialDesignThemes.Wpf; using MaterialDesignThemes.Wpf;
using MaterialDesignThemes.Wpf.Converters; using MaterialDesignThemes.Wpf.Converters;
using MaterialDesignThemes.Wpf.Transitions; using MaterialDesignThemes.Wpf.Transitions;
@ -47,7 +45,7 @@ namespace Aucma.Core.PrintTo.Views {
public partial class IndexPage : System.Windows.Controls.UserControl, System.Windows.Markup.IComponentConnector { public partial class IndexPage : System.Windows.Controls.UserControl, System.Windows.Markup.IComponentConnector {
#line 161 "..\..\..\..\Views\IndexPage.xaml" #line 159 "..\..\..\..\Views\IndexPage.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.TextBox queryParam; internal System.Windows.Controls.TextBox queryParam;
@ -55,7 +53,7 @@ namespace Aucma.Core.PrintTo.Views {
#line hidden #line hidden
#line 166 "..\..\..\..\Views\IndexPage.xaml" #line 164 "..\..\..\..\Views\IndexPage.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.Primitives.UniformGrid HeightPanel; internal System.Windows.Controls.Primitives.UniformGrid HeightPanel;
@ -63,7 +61,7 @@ namespace Aucma.Core.PrintTo.Views {
#line hidden #line hidden
#line 172 "..\..\..\..\Views\IndexPage.xaml" #line 170 "..\..\..\..\Views\IndexPage.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.DataGrid dgvMH; internal System.Windows.Controls.DataGrid dgvMH;
@ -71,7 +69,7 @@ namespace Aucma.Core.PrintTo.Views {
#line hidden #line hidden
#line 209 "..\..\..\..\Views\IndexPage.xaml" #line 207 "..\..\..\..\Views\IndexPage.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.TextBox ProductNo; internal System.Windows.Controls.TextBox ProductNo;
@ -79,7 +77,7 @@ namespace Aucma.Core.PrintTo.Views {
#line hidden #line hidden
#line 215 "..\..\..\..\Views\IndexPage.xaml" #line 213 "..\..\..\..\Views\IndexPage.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.TextBox ProductName; internal System.Windows.Controls.TextBox ProductName;
@ -87,7 +85,7 @@ namespace Aucma.Core.PrintTo.Views {
#line hidden #line hidden
#line 220 "..\..\..\..\Views\IndexPage.xaml" #line 218 "..\..\..\..\Views\IndexPage.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.TextBox MaterialName; internal System.Windows.Controls.TextBox MaterialName;
@ -95,7 +93,7 @@ namespace Aucma.Core.PrintTo.Views {
#line hidden #line hidden
#line 227 "..\..\..\..\Views\IndexPage.xaml" #line 225 "..\..\..\..\Views\IndexPage.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.Slider PlanAmount; internal System.Windows.Controls.Slider PlanAmount;
@ -103,7 +101,7 @@ namespace Aucma.Core.PrintTo.Views {
#line hidden #line hidden
#line 232 "..\..\..\..\Views\IndexPage.xaml" #line 231 "..\..\..\..\Views\IndexPage.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.RadioButton ; internal System.Windows.Controls.RadioButton ;
@ -111,7 +109,7 @@ namespace Aucma.Core.PrintTo.Views {
#line hidden #line hidden
#line 233 "..\..\..\..\Views\IndexPage.xaml" #line 232 "..\..\..\..\Views\IndexPage.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.RadioButton U; internal System.Windows.Controls.RadioButton U;

@ -1,4 +1,4 @@
#pragma checksum "..\..\..\..\Views\IndexPage.xaml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "3749AD74C5EE15C020F09690F0AF67B24ED46CDC" #pragma checksum "..\..\..\..\Views\IndexPage.xaml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "7004EF4D93767F02E48DBEEC7CAC09C6074BA678"
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// <auto-generated> // <auto-generated>
// 此代码由工具生成。 // 此代码由工具生成。
@ -9,8 +9,6 @@
// </auto-generated> // </auto-generated>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
using Aucma.Core.PrintTo.Views;
using Aucma.Core.PrintTo.Views.Page;
using MaterialDesignThemes.Wpf; using MaterialDesignThemes.Wpf;
using MaterialDesignThemes.Wpf.Converters; using MaterialDesignThemes.Wpf.Converters;
using MaterialDesignThemes.Wpf.Transitions; using MaterialDesignThemes.Wpf.Transitions;
@ -47,7 +45,7 @@ namespace Aucma.Core.PrintTo.Views {
public partial class IndexPage : System.Windows.Controls.UserControl, System.Windows.Markup.IComponentConnector { public partial class IndexPage : System.Windows.Controls.UserControl, System.Windows.Markup.IComponentConnector {
#line 161 "..\..\..\..\Views\IndexPage.xaml" #line 159 "..\..\..\..\Views\IndexPage.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.TextBox queryParam; internal System.Windows.Controls.TextBox queryParam;
@ -55,7 +53,7 @@ namespace Aucma.Core.PrintTo.Views {
#line hidden #line hidden
#line 166 "..\..\..\..\Views\IndexPage.xaml" #line 164 "..\..\..\..\Views\IndexPage.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.Primitives.UniformGrid HeightPanel; internal System.Windows.Controls.Primitives.UniformGrid HeightPanel;
@ -63,7 +61,7 @@ namespace Aucma.Core.PrintTo.Views {
#line hidden #line hidden
#line 172 "..\..\..\..\Views\IndexPage.xaml" #line 170 "..\..\..\..\Views\IndexPage.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.DataGrid dgvMH; internal System.Windows.Controls.DataGrid dgvMH;
@ -71,7 +69,7 @@ namespace Aucma.Core.PrintTo.Views {
#line hidden #line hidden
#line 209 "..\..\..\..\Views\IndexPage.xaml" #line 207 "..\..\..\..\Views\IndexPage.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.TextBox ProductNo; internal System.Windows.Controls.TextBox ProductNo;
@ -79,7 +77,7 @@ namespace Aucma.Core.PrintTo.Views {
#line hidden #line hidden
#line 215 "..\..\..\..\Views\IndexPage.xaml" #line 213 "..\..\..\..\Views\IndexPage.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.TextBox ProductName; internal System.Windows.Controls.TextBox ProductName;
@ -87,7 +85,7 @@ namespace Aucma.Core.PrintTo.Views {
#line hidden #line hidden
#line 220 "..\..\..\..\Views\IndexPage.xaml" #line 218 "..\..\..\..\Views\IndexPage.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.TextBox MaterialName; internal System.Windows.Controls.TextBox MaterialName;
@ -95,7 +93,7 @@ namespace Aucma.Core.PrintTo.Views {
#line hidden #line hidden
#line 227 "..\..\..\..\Views\IndexPage.xaml" #line 225 "..\..\..\..\Views\IndexPage.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.Slider PlanAmount; internal System.Windows.Controls.Slider PlanAmount;
@ -103,7 +101,7 @@ namespace Aucma.Core.PrintTo.Views {
#line hidden #line hidden
#line 232 "..\..\..\..\Views\IndexPage.xaml" #line 231 "..\..\..\..\Views\IndexPage.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.RadioButton ; internal System.Windows.Controls.RadioButton ;
@ -111,7 +109,7 @@ namespace Aucma.Core.PrintTo.Views {
#line hidden #line hidden
#line 233 "..\..\..\..\Views\IndexPage.xaml" #line 232 "..\..\..\..\Views\IndexPage.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.RadioButton U; internal System.Windows.Controls.RadioButton U;

@ -10,6 +10,9 @@
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
using Aucma.Core.PrintTo.Views; using Aucma.Core.PrintTo.Views;
using MaterialDesignThemes.Wpf;
using MaterialDesignThemes.Wpf.Converters;
using MaterialDesignThemes.Wpf.Transitions;
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.Windows; using System.Windows;

@ -9,8 +9,9 @@
// </auto-generated> // </auto-generated>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
using Aucma.Core.PrintTo.Views; using MaterialDesignThemes.Wpf;
using Aucma.Core.PrintTo.Views.Page; using MaterialDesignThemes.Wpf.Converters;
using MaterialDesignThemes.Wpf.Transitions;
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.Windows; using System.Windows;

@ -1,360 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
namespace HwControlLib
{
/// <summary>
/// 数字输入框
/// Author
/// </summary>
class NumTextBox : TextBox
{
public static readonly DependencyProperty NumTypeProperty = DependencyProperty.Register("NumType", typeof(Type), typeof(NumTextBox));
public static readonly DependencyProperty MaxValueProperty = DependencyProperty.Register("MaxValue", typeof(decimal), typeof(NumTextBox), new FrameworkPropertyMetadata(
new PropertyChangedCallback(CheckProperty)));
public static readonly DependencyProperty MinValueProperty = DependencyProperty.Register("MinValue", typeof(decimal), typeof(NumTextBox), new FrameworkPropertyMetadata(
new PropertyChangedCallback(CheckProperty)));
public static readonly DependencyProperty PointLenthProperty = DependencyProperty.Register("PointLenth", typeof(int), typeof(NumTextBox));
public static readonly DependencyProperty NumberLengthProperty = DependencyProperty.Register("NumberLength", typeof(int), typeof(NumTextBox));
// private System.Globalization.CultureInfo cI;
public NumTextBox()
{
MinValue = decimal.MinValue;
MaxValue = decimal.MaxValue;
PointLenth = 2;
NumberLength = 13;
}
public enum Type { Decimal, UDecimal, Int, UInt }
/// <summary>
/// 设置或获取textbox的输入数据类型
/// </summary>
public Type NumType
{
get { return (Type)GetValue(NumTypeProperty); }
set { SetValue(NumTypeProperty, value); }
}
/// <summary>
/// 设定或获取最大值
/// </summary>
public decimal MaxValue
{
get { return (decimal)GetValue(MaxValueProperty); }
set { SetValue(MaxValueProperty, value); }
}
/// <summary>
/// 设定或获取最小值
/// </summary>
public decimal MinValue
{
get { return (decimal)GetValue(MinValueProperty); }
set { SetValue(MinValueProperty, value); }
}
/// <summary>
/// 设置或获取小数点前的位数
/// </summary>
public int NumberLength
{
get { return (int)GetValue(NumberLengthProperty); }
set { SetValue(NumberLengthProperty, value); }
}
/// <summary>
/// 设置或获取小数点后位数长度
/// </summary>
public int PointLenth
{
get { return (int)GetValue(PointLenthProperty); }
set { SetValue(PointLenthProperty, value); }
}
private string val = "";
/// <summary>
/// 设定最大值最小值依赖属性回调函数
/// </summary>
/// <param name="d"></param>
/// <param name="e"></param>
private static void CheckProperty(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
NumTextBox ntb = d as NumTextBox;
if (ntb.MaxValue < ntb.MinValue)
ntb.MaxValue = ntb.MinValue;
}
/// <summary>
/// 重写KeyDown事件提供与事件有关的数据过滤输入数据格式
/// </summary>
/// <param name="e"></param>
protected override void OnKeyDown(KeyEventArgs e)
{
string txt = this.Text;
int ind = this.CaretIndex;
if (txt.Contains("."))
{
// Console.WriteLine(txt.Split('.')[0] + "he " + txt.Split('.')[1]);
if (txt.Split('.')[1].Length >= PointLenth && ind > txt.Split('.')[0].Length && this.SelectionLength == 0)//控制小数点后输入位数
{
e.Handled = true;
return;
}
else if (txt.Split('.')[0].Length >= NumberLength && ind <= txt.Split('.')[0].Length)//控制小数点前输入位数(有小数点)
{
e.Handled = true;
return;
}
}
else if (txt.Length == NumberLength && e.Key != Key.Decimal && e.Key != Key.OemPeriod)//控制小数点前输入位数(无小数点)
{
e.Handled = true;
return;
}
if (e.Key == Key.Decimal || e.Key == Key.OemPeriod)
{
val = ".";
}
else
{
val = "";
}
switch (NumType)
{
case Type.UInt:
//屏蔽非法按键
if ((e.Key >= Key.NumPad0 && e.Key <= Key.NumPad9) || e.Key.ToString() == "Tab")
{
e.Handled = false;
}
else if (((e.Key >= Key.D0 && e.Key <= Key.D9)) && e.KeyboardDevice.Modifiers != ModifierKeys.Shift)
{
e.Handled = false;
}
else
{
e.Handled = true;
if (e.Key.ToString() != "RightCtrl")
{ }
}
break;
case Type.Int:
//屏蔽非法按键
if ((e.Key >= Key.NumPad0 && e.Key <= Key.NumPad9) || e.Key == Key.Subtract || e.Key.ToString() == "Tab")
{
if ((txt.Contains("-") || this.CaretIndex != 0) && e.Key == Key.Subtract)
{
e.Handled = true;
return;
}
e.Handled = false;
}
else if (((e.Key >= Key.D0 && e.Key <= Key.D9) || e.Key == Key.OemMinus) && e.KeyboardDevice.Modifiers != ModifierKeys.Shift)
{
if ((txt.Contains("-") || this.CaretIndex != 0) && e.Key == Key.OemMinus)
{
e.Handled = true;
return;
}
e.Handled = false;
}
else
{
e.Handled = true;
if (e.Key.ToString() != "RightCtrl")
{ }
}
break;
case Type.Decimal:
//屏蔽非法按键
if ((e.Key >= Key.NumPad0 && e.Key <= Key.NumPad9) || e.Key == Key.Decimal || e.Key == Key.Subtract || e.Key.ToString() == "Tab")
{
if (txt.Contains(".") && e.Key == Key.Decimal)
{
e.Handled = true;
return;
}
else if ((txt.Contains("-") || this.CaretIndex != 0) && e.Key == Key.Subtract)
{
e.Handled = true;
return;
}
e.Handled = false;
}
else if (((e.Key >= Key.D0 && e.Key <= Key.D9) || e.Key == Key.OemPeriod || e.Key == Key.OemMinus) && e.KeyboardDevice.Modifiers != ModifierKeys.Shift)
{
if (txt.Contains(".") && e.Key == Key.OemPeriod)
{
e.Handled = true;
return;
}
else if ((txt.Contains("-") || this.CaretIndex != 0) && e.Key == Key.OemMinus)
{
e.Handled = true;
return;
}
e.Handled = false;
}
else
{
e.Handled = true;
if (e.Key.ToString() != "RightCtrl")
{ }
}
break;
case Type.UDecimal:
default:
//屏蔽非法按键
if ((e.Key >= Key.NumPad0 && e.Key <= Key.NumPad9) || e.Key == Key.Decimal || e.Key.ToString() == "Tab")
{
if (txt.Contains(".") && e.Key == Key.Decimal)
{
e.Handled = true;
return;
}
e.Handled = false;
}
else if (((e.Key >= Key.D0 && e.Key <= Key.D9) || e.Key == Key.OemPeriod) && e.KeyboardDevice.Modifiers != ModifierKeys.Shift)
{
if (txt.Contains(".") && e.Key == Key.OemPeriod)
{
e.Handled = true;
return;
}
e.Handled = false;
}
else
{
e.Handled = true;
if (e.Key.ToString() != "RightCtrl")
{ }
}
break;
}
base.OnKeyDown(e);
}
/// <summary>
///粘贴内容过滤,设定最大值、最小值,限制小数点输入长度
/// </summary>
/// <param name="e"></param>
protected override void OnTextChanged(TextChangedEventArgs e)
{
int t1 = this.Text.Length;
if (t1 != 0)//用于是否可以将文本空置空
{
decimal d = 0;
if (this.Text != "-" && this.Text != "." && this.Text != "-0" && this.Text != "-." && this.Text != "-0." && val != ".")
{
if (decimal.TryParse(this.Text, out d))
{
if (NumType == Type.Decimal || NumType == Type.UDecimal)
{
if (d.ToString().Split('.')[0].Length > NumberLength)//
{
d = 0;
}
else
{
d = Math.Round(d, PointLenth, MidpointRounding.AwayFromZero);
}
}
else
if (d.ToString().Split('.')[0].Length > NumberLength)//
{
d = 0;
}
else
{
d = Math.Round(d, 0, MidpointRounding.AwayFromZero);
}
}
int t2 = d.ToString().Length;
if (Math.Abs(t1 - d.ToString().Length) > 0)
{
this.Text = d.ToString();
this.CaretIndex = d.ToString().Length;
}
else
{
this.Text = d.ToString();
}
}
if ((NumType == Type.UDecimal || NumType == Type.UInt) && this.Text.Contains("-"))
{
this.Text = Math.Abs(d).ToString();
}
if ((NumType == Type.UInt || NumType == Type.Int) && this.Text.Contains("."))
{
this.Text = int.Parse(d.ToString()).ToString();
}
}
base.OnTextChanged(e);
}
/// <summary>
///如果数据是0得到光标清空数据
/// </summary>
/// <param name="e"></param>
protected override void OnGotFocus(RoutedEventArgs e)
{
//InputMethod.SetPreferredImeState(this, InputMethodState.Off);
//cI = InputLanguageManager.GetInputLanguage(this);
//decimal d = 0;
//if (decimal.TryParse(this.Text, out d))
//{
if (this.Text == "0")
{
this.Text = "";
}
//}
//else
//{
// this.Text = "";
//}
base.OnGotFocus(e);
}
/// <summary>
///失去光标,确定最大值最小值
/// </summary>
/// <param name="e"></param>
protected override void OnLostFocus(RoutedEventArgs e)
{
decimal d = 0;
if (decimal.TryParse(this.Text, out d))
{
if (d < MinValue)
{
d = MinValue;
this.Text = d.ToString();
}
else if (d > MaxValue)
{
d = MaxValue;
this.Text = d.ToString();
}
}
else if (string.IsNullOrEmpty(this.Text))
{
this.Text = "";
}
else
{
this.Text = d.ToString();
}
base.OnLostFocus(e);
//System.Globalization.CultureInfo cI = InputLanguageManager.GetInputLanguage(this);
//InputMethod.SetPreferredImeState(this, InputMethodState.DoNotCare);
//InputLanguageManager.SetInputLanguage(this, cI);
//cI = null;
}
}
}

@ -0,0 +1,640 @@
using HwControlLib.UtilitiesHelper;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
namespace HwControlLib
{
/// <summary>
/// 数字输入框
/// Author
/// </summary>
[DefaultEvent("ValueChanged"), DefaultProperty("Value")]
[TemplatePart(Name = TextBoxTemplateName, Type = typeof(TextBox))]
[TemplatePart(Name = NumericUpTemplateName, Type = typeof(RepeatButton))]
[TemplatePart(Name = NumericDownTemplateName, Type = typeof(RepeatButton))]
public class NumericBox : Control
{
private static readonly Type _typeofSelf = typeof(NumericBox);
private const double DefaultInterval = 1d;
private const int DefaultDelay = 500;
private const string TextBoxTemplateName = "PART_TextBox";
private const string NumericUpTemplateName = "PART_NumericUp";
private const string NumericDownTemplateName = "PART_NumericDown";
private static RoutedCommand _increaseCommand = null;
private static RoutedCommand _decreaseCommand = null;
private TextBox _valueTextBox;
private RepeatButton _repeatUp;
private RepeatButton _repeatDown;
private double _internalLargeChange = DefaultInterval;
private double _intervalValueSinceReset = 0;
private double? _lastOldValue = null;
private bool _isManual;
private bool _isBusy;
static NumericBox()
{
InitializeCommands();
DefaultStyleKeyProperty.OverrideMetadata(_typeofSelf, new FrameworkPropertyMetadata(_typeofSelf));
}
#region Command
private static void InitializeCommands()
{
_increaseCommand = new RoutedCommand("Increase", _typeofSelf);
_decreaseCommand = new RoutedCommand("Decrease", _typeofSelf);
CommandManager.RegisterClassCommandBinding(_typeofSelf, new CommandBinding(_increaseCommand, OnIncreaseCommand, OnCanIncreaseCommand));
CommandManager.RegisterClassCommandBinding(_typeofSelf, new CommandBinding(_decreaseCommand, OnDecreaseCommand, OnCanDecreaseCommand));
}
public static RoutedCommand IncreaseCommand
{
get { return _increaseCommand; }
}
public static RoutedCommand DecreaseCommand
{
get { return _decreaseCommand; }
}
private static void OnIncreaseCommand(object sender, RoutedEventArgs e)
{
var numericBox = sender as NumericBox;
numericBox.ContinueChangeValue(true);
}
private static void OnCanIncreaseCommand(object sender, CanExecuteRoutedEventArgs e)
{
var numericBox = sender as NumericBox;
e.CanExecute = (!numericBox.IsReadOnly && numericBox.IsEnabled && DoubleUtil.LessThan(numericBox.Value, numericBox.Maximum));
}
private static void OnDecreaseCommand(object sender, RoutedEventArgs e)
{
var numericBox = sender as NumericBox;
numericBox.ContinueChangeValue(false);
}
private static void OnCanDecreaseCommand(object sender, CanExecuteRoutedEventArgs e)
{
var numericBox = sender as NumericBox;
e.CanExecute = (!numericBox.IsReadOnly && numericBox.IsEnabled && DoubleUtil.GreaterThan(numericBox.Value, numericBox.Minimum));
}
#endregion
#region RouteEvent
public static readonly RoutedEvent ValueChangedEvent = EventManager.RegisterRoutedEvent("ValueChanged", RoutingStrategy.Bubble, typeof(RoutedPropertyChangedEventHandler<double>), _typeofSelf);
public event RoutedPropertyChangedEventHandler<double> ValueChanged
{
add { AddHandler(ValueChangedEvent, value); }
remove { RemoveHandler(ValueChangedEvent, value); }
}
#endregion
#region Properties
public static readonly DependencyProperty DisabledValueChangedWhileBusyProperty = DependencyProperty.Register("DisabledValueChangedWhileBusy", typeof(bool), _typeofSelf,
new PropertyMetadata(false));
[Category("Common")]
[DefaultValue(true)]
public bool DisabledValueChangedWhileBusy
{
get { return (bool)GetValue(DisabledValueChangedWhileBusyProperty); }
set { SetValue(DisabledValueChangedWhileBusyProperty, value); }
}
public static readonly DependencyProperty IntervalProperty = DependencyProperty.Register("Interval", typeof(double), _typeofSelf,
new FrameworkPropertyMetadata(DefaultInterval, IntervalChanged, CoerceInterval));
[Category("Behavior")]
[DefaultValue(DefaultInterval)]
public double Interval
{
get { return (double)GetValue(IntervalProperty); }
set { SetValue(IntervalProperty, value); }
}
private static object CoerceInterval(DependencyObject d, object value)
{
var interval = (double)value;
return DoubleUtil.IsNaN(interval) ? 0 : Math.Max(interval, 0);
}
private static void IntervalChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var numericBox = (NumericBox)d;
numericBox.ResetInternal();
}
public static readonly DependencyProperty SpeedupProperty = DependencyProperty.Register("Speedup", typeof(bool), _typeofSelf,
new PropertyMetadata(true));
[Category("Common")]
[DefaultValue(true)]
public bool Speedup
{
get { return (bool)GetValue(SpeedupProperty); }
set { SetValue(SpeedupProperty, value); }
}
public static readonly DependencyProperty DelayProperty = DependencyProperty.Register("Delay", typeof(int), _typeofSelf,
new PropertyMetadata(DefaultDelay, null, CoerceDelay));
[DefaultValue(DefaultDelay)]
[Category("Behavior")]
public int Delay
{
get { return (int)GetValue(DelayProperty); }
set { SetValue(DelayProperty, value); }
}
private static object CoerceDelay(DependencyObject d, object value)
{
var delay = (int)value;
return Math.Max(delay, 0);
}
public static readonly DependencyProperty UpDownButtonsWidthProperty = DependencyProperty.Register("UpDownButtonsWidth", typeof(double), _typeofSelf,
new PropertyMetadata(20d));
[Category("Appearance")]
[DefaultValue(20d)]
public double UpDownButtonsWidth
{
get { return (double)GetValue(UpDownButtonsWidthProperty); }
set { SetValue(UpDownButtonsWidthProperty, value); }
}
public static readonly DependencyProperty TextAlignmentProperty = TextBox.TextAlignmentProperty.AddOwner(_typeofSelf);
[Category("Common")]
public TextAlignment TextAlignment
{
get { return (TextAlignment)GetValue(TextAlignmentProperty); }
set { SetValue(TextAlignmentProperty, value); }
}
public static readonly DependencyProperty IsReadOnlyProperty = TextBoxBase.IsReadOnlyProperty.AddOwner(_typeofSelf,
new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.Inherits, IsReadOnlyPropertyChangedCallback));
[Category("Appearance")]
public bool IsReadOnly
{
get { return (bool)GetValue(IsReadOnlyProperty); }
set { SetValue(IsReadOnlyProperty, value); }
}
private static void IsReadOnlyPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (e.OldValue == e.NewValue || e.NewValue == null)
return;
((NumericBox)d).ToggleReadOnlyMode((bool)e.NewValue);
}
public static readonly DependencyProperty PrecisionProperty = DependencyProperty.Register("Precision", typeof(int?), _typeofSelf,
new PropertyMetadata(null, OnPrecisionChanged, CoercePrecision));
[Category("Common")]
public int? Precision
{
get { return (int?)GetValue(PrecisionProperty); }
set { SetValue(PrecisionProperty, value); }
}
private static object CoercePrecision(DependencyObject d, object value)
{
var precision = (int?)value;
return (precision.HasValue && precision.Value < 0) ? 0 : precision;
}
private static void OnPrecisionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var numericBox = (NumericBox)d;
var newPrecision = (int?)e.NewValue;
var roundValue = numericBox.CorrectPrecision(newPrecision, numericBox.Value);
if (DoubleUtil.AreClose(numericBox.Value, roundValue))
numericBox.InternalSetText(roundValue);
else
numericBox.Value = roundValue;
}
public static readonly DependencyProperty MinimumProperty = DependencyProperty.Register("Minimum", typeof(double), _typeofSelf,
new PropertyMetadata(double.MinValue, OnMinimumChanged));
[Category("Common")]
public double Minimum
{
get { return (double)GetValue(MinimumProperty); }
set { SetValue(MinimumProperty, value); }
}
private static void OnMinimumChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var numericBox = (NumericBox)d;
numericBox.CoerceValue(MaximumProperty, numericBox.Maximum);
numericBox.CoerceValue(ValueProperty, numericBox.Value);
}
public static readonly DependencyProperty MaximumProperty = DependencyProperty.Register("Maximum", typeof(double), _typeofSelf,
new PropertyMetadata(double.MaxValue, OnMaximumChanged, CoerceMaximum));
[Category("Common")]
public double Maximum
{
get { return (double)GetValue(MaximumProperty); }
set { SetValue(MaximumProperty, value); }
}
private static object CoerceMaximum(DependencyObject d, object value)
{
var minimum = ((NumericBox)d).Minimum;
var val = (double)value;
return DoubleUtil.LessThan(val, minimum) ? minimum : val;
}
private static void OnMaximumChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var numericBox = (NumericBox)d;
numericBox.CoerceValue(ValueProperty, numericBox.Value);
}
public static readonly DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(double), _typeofSelf,
new FrameworkPropertyMetadata(0d, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnValueChanged, CoerceValue));
[Category("Common")]
public double Value
{
get { return (double)GetValue(ValueProperty); }
set { SetValue(ValueProperty, value); }
}
private static object CoerceValue(DependencyObject d, object value)
{
var numericBox = (NumericBox)d;
var val = (double)value;
if (DoubleUtil.LessThan(val, numericBox.Minimum))
return numericBox.Minimum;
if (DoubleUtil.GreaterThan(val, numericBox.Maximum))
return numericBox.Maximum;
return numericBox.CorrectPrecision(numericBox.Precision, val);
}
private static void OnValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var numericBox = (NumericBox)d;
numericBox.OnValueChanged((double)e.OldValue, (double)e.NewValue);
}
#endregion
#region Virtual
protected virtual void OnValueChanged(double oldValue, double newValue)
{
InternalSetText(newValue);
InvalidateRequerySuggested(newValue);
if ((!_isBusy || !DisabledValueChangedWhileBusy) && !DoubleUtil.AreClose(oldValue, newValue))
{
RaiseEvent(new TextBoxValueChangedEventArgs<double>(oldValue, newValue, _isManual, _isBusy, ValueChangedEvent));
}
_isManual = false;
}
#endregion
#region Override
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
UnsubscribeEvents();
_valueTextBox = GetTemplateChild(TextBoxTemplateName) as TextBox;
_repeatUp = GetTemplateChild(NumericUpTemplateName) as RepeatButton;
_repeatDown = GetTemplateChild(NumericDownTemplateName) as RepeatButton;
if (_valueTextBox == null || _repeatUp == null || _repeatDown == null)
{
throw new NullReferenceException(string.Format("You have missed to specify {0}, {1} or {2} in your template", NumericUpTemplateName, NumericDownTemplateName, TextBoxTemplateName));
}
_repeatUp.PreviewMouseUp += OnRepeatButtonPreviewMouseUp;
_repeatDown.PreviewMouseUp += OnRepeatButtonPreviewMouseUp;
ToggleReadOnlyMode(IsReadOnly);
OnValueChanged(Value, Value);
}
protected override void OnGotFocus(RoutedEventArgs e)
{
base.OnGotFocus(e);
if (Focusable && !IsReadOnly)
{
Focused();
SelectAll();
}
}
protected override void OnPreviewMouseWheel(MouseWheelEventArgs e)
{
base.OnPreviewMouseWheel(e);
if (e.Delta != 0 && (IsFocused || _valueTextBox.IsFocused))
ContinueChangeValue(e.Delta >= 0, false);
}
protected override void OnPreviewKeyDown(KeyEventArgs e)
{
base.OnPreviewKeyDown(e);
switch (e.Key)
{
case Key.Enter:
DealInputText(_valueTextBox.Text);
SelectAll();
e.Handled = true;
break;
case Key.Up:
ContinueChangeValue(true);
e.Handled = true;
break;
case Key.Down:
ContinueChangeValue(false);
e.Handled = true;
break;
}
}
protected override void OnPreviewKeyUp(KeyEventArgs e)
{
base.OnPreviewKeyUp(e);
switch (e.Key)
{
case Key.Down:
case Key.Up:
ResetInternal();
break;
}
}
#endregion
#region Event
private void OnRepeatButtonPreviewMouseUp(object sender, MouseButtonEventArgs e)
{
ResetInternal();
}
private void OnPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (Focusable && !IsReadOnly && !_valueTextBox.IsKeyboardFocusWithin)
{
e.Handled = true;
Focused();
SelectAll();
}
}
private void OnTextBoxLostFocus(object sender, RoutedEventArgs e)
{
var tb = (TextBox)sender;
DealInputText(tb.Text);
}
private void OnValueTextBoxPaste(object sender, DataObjectPastingEventArgs e)
{
var textBox = (TextBox)sender;
var textPresent = textBox.Text;
if (!e.SourceDataObject.GetDataPresent(DataFormats.Text, true))
return;
var text = e.SourceDataObject.GetData(DataFormats.Text) as string;
var newText = string.Concat(textPresent.Substring(0, textBox.SelectionStart), text, textPresent.Substring(textBox.SelectionStart + textBox.SelectionLength));
double number;
if (!double.TryParse(newText, out number))
e.CancelCommand();
}
#endregion
#region Private
private void UnsubscribeEvents()
{
if (_valueTextBox != null)
{
_valueTextBox.LostFocus -= OnTextBoxLostFocus;
_valueTextBox.PreviewMouseLeftButtonDown -= OnPreviewMouseLeftButtonDown;
DataObject.RemovePastingHandler(_valueTextBox, OnValueTextBoxPaste);
}
if (_repeatUp != null)
_repeatUp.PreviewMouseUp -= OnRepeatButtonPreviewMouseUp;
if (_repeatDown != null)
_repeatDown.PreviewMouseUp -= OnRepeatButtonPreviewMouseUp;
}
private void Focused()
{
_valueTextBox?.Focus();
}
private void SelectAll()
{
_valueTextBox?.SelectAll();
}
private void DealInputText(string inputText)
{
double convertedValue;
if (double.TryParse(inputText, out convertedValue))
{
if (DoubleUtil.AreClose(Value, convertedValue))
{
InternalSetText(Value);
return;
}
_isManual = true;
if (convertedValue > Maximum)
{
if (DoubleUtil.AreClose(Value, Maximum))
OnValueChanged(Value, Value);
else
Value = Maximum;
}
else if (convertedValue < Minimum)
{
if (DoubleUtil.AreClose(Value, Minimum))
OnValueChanged(Value, Value);
else
Value = Minimum;
}
else
Value = convertedValue;
}
else
InternalSetText(Value);
}
private void MoveFocus()
{
var request = new TraversalRequest((Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift ? FocusNavigationDirection.Previous : FocusNavigationDirection.Next);
var elementWithFocus = Keyboard.FocusedElement as UIElement;
elementWithFocus?.MoveFocus(request);
}
private void ToggleReadOnlyMode(bool isReadOnly)
{
if (_valueTextBox == null)
return;
if (isReadOnly)
{
_valueTextBox.LostFocus -= OnTextBoxLostFocus;
_valueTextBox.PreviewMouseLeftButtonDown -= OnPreviewMouseLeftButtonDown;
DataObject.RemovePastingHandler(_valueTextBox, OnValueTextBoxPaste);
}
else
{
_valueTextBox.LostFocus += OnTextBoxLostFocus;
_valueTextBox.PreviewMouseLeftButtonDown += OnPreviewMouseLeftButtonDown;
DataObject.AddPastingHandler(_valueTextBox, OnValueTextBoxPaste);
}
}
private void InternalSetText(double newValue)
{
var text = newValue.ToString(GetPrecisionFormat());
if (_valueTextBox != null && !Equals(text, _valueTextBox.Text))
_valueTextBox.Text = text;
}
private string GetPrecisionFormat()
{
return Precision.HasValue == false
? "g"
: (Precision.Value == 0
? "#0"
: ("#0.0" + string.Join("", Enumerable.Repeat("#", Precision.Value - 1))));
}
private void CoerceValue(DependencyProperty dp, object localValue)
{
SetCurrentValue(dp, localValue);
CoerceValue(dp);
}
private double CorrectPrecision(int? precision, double originValue)
{
return Math.Round(originValue, precision ?? 0, MidpointRounding.AwayFromZero);
}
private void ContinueChangeValue(bool isIncrease, bool isContinue = true)
{
if (IsReadOnly || !IsEnabled)
return;
if (isIncrease && DoubleUtil.LessThan(Value, Maximum))
{
if (!_isBusy && isContinue)
{
_isBusy = true;
if (DisabledValueChangedWhileBusy)
_lastOldValue = Value;
}
_isManual = true;
Value = (double)CoerceValue(this, Value + CalculateInterval(isContinue));
}
if (!isIncrease && DoubleUtil.GreaterThan(Value, Minimum))
{
if (!_isBusy && isContinue)
{
_isBusy = true;
if (DisabledValueChangedWhileBusy)
_lastOldValue = Value;
}
_isManual = true;
Value = (double)CoerceValue(this, Value - CalculateInterval(isContinue));
}
}
private double CalculateInterval(bool isContinue = true)
{
if (!Speedup || !isContinue)
return Interval;
if (DoubleUtil.GreaterThan((_intervalValueSinceReset += _internalLargeChange), _internalLargeChange * 100))
_internalLargeChange *= 10;
return _internalLargeChange;
}
private void ResetInternal()
{
_internalLargeChange = Interval;
_intervalValueSinceReset = 0;
_isBusy = false;
if (_lastOldValue.HasValue)
{
_isManual = true;
OnValueChanged(_lastOldValue.Value, Value);
_lastOldValue = null;
}
}
private void InvalidateRequerySuggested(double value)
{
if (_repeatUp == null || _repeatDown == null)
return;
if (DoubleUtil.AreClose(value, Maximum) && _repeatUp.IsEnabled
|| DoubleUtil.AreClose(value, Minimum) && _repeatDown.IsEnabled)
CommandManager.InvalidateRequerySuggested();
else
{
if (!_repeatUp.IsEnabled || !_repeatDown.IsEnabled)
CommandManager.InvalidateRequerySuggested();
}
}
#endregion
}
}

@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace HwControlLib.UtilitiesHelper
{
public class DoubleUtil
{
internal const double DBL_EPSILON = 2.2204460492503131e-016; /* smallest such that 1.0+DBL_EPSILON != 1.0 */
public static bool AreClose(double value1, double value2)
{
if (value1 == value2) return true;
double eps = (Math.Abs(value1) + Math.Abs(value2) + 10.0) * DBL_EPSILON;
double delta = value1 - value2;
return (-eps < delta) && (eps > delta);
}
public static bool LessThan(double value1, double value2) => (value1 < value2) && !AreClose(value1, value2);
public static bool GreaterThan(double value1, double value2) => (value1 > value2) && !AreClose(value1, value2);
public static bool LessThanOrClose(double value1, double value2) => (value1 < value2) || AreClose(value1, value2);
[StructLayout(LayoutKind.Explicit)]
private struct NanUnion
{
[FieldOffset(0)]
internal double DoubleValue;
[FieldOffset(0)]
internal UInt64 UintValue;
}
public static bool IsNaN(double value)
{
NanUnion t = new NanUnion();
t.DoubleValue = value;
UInt64 exp = t.UintValue & 0xfff0000000000000;
UInt64 man = t.UintValue & 0x000fffffffffffff;
return (exp == 0x7ff0000000000000 || exp == 0xfff0000000000000) && (man != 0);
}
}
}

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace HwControlLib.UtilitiesHelper
{
public class TextBoxValueChangedEventArgs<T> : RoutedPropertyChangedEventArgs<T>
{
public bool IsManual { get; private set; }
public bool IsBusy { get; private set; }
public TextBoxValueChangedEventArgs(T oldValue, T newValue, bool isManual, bool isBusy = false, RoutedEvent routedEvent = null)
: base(oldValue, newValue, routedEvent)
{
IsManual = isManual;
IsBusy = isBusy;
}
}
}

@ -1 +1 @@
0c361f8ade9a1be0d4981e382daecaa9bc078d09 409291fa3771d5b1b75c75258c287126201b2647

@ -12,7 +12,7 @@ TRACE;DEBUG;NET;NET6_0;NETCOREAPP
1204305769 1204305769
3-783178491 5-440531829
1941709816142 1941709816142
Themes\Generic.xaml; Themes\Generic.xaml;

@ -12,7 +12,7 @@ TRACE;DEBUG;NET;NET6_0;NETCOREAPP
1204305769 1204305769
5865645732 71208292394
1941709816142 1941709816142
Themes\Generic.xaml; Themes\Generic.xaml;

@ -15,7 +15,7 @@ namespace XamlGeneratedNamespace {
/// GeneratedInternalTypeHelper /// GeneratedInternalTypeHelper
/// </summary> /// </summary>
[System.Diagnostics.DebuggerNonUserCodeAttribute()] [System.Diagnostics.DebuggerNonUserCodeAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "7.0.12.0")] [System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "7.0.5.0")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public sealed class GeneratedInternalTypeHelper : System.Windows.Markup.InternalTypeHelper { public sealed class GeneratedInternalTypeHelper : System.Windows.Markup.InternalTypeHelper {

@ -8,4 +8,4 @@ build_property.PlatformNeutralAssembly =
build_property.EnforceExtendedAnalyzerRules = build_property.EnforceExtendedAnalyzerRules =
build_property._SupportedPlatformList = Linux,macOS,Windows build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = HwControlLib build_property.RootNamespace = HwControlLib
build_property.ProjectDir = D:\Project\gitea\AUCMA\SCADA\HwControlLib\ build_property.ProjectDir = D:\gitea\AUCMA\AUCMA_SCADA\HwControlLib\

@ -4,7 +4,7 @@
library library
C# C#
.cs .cs
D:\Project\gitea\AUCMA\SCADA\HwControlLib\obj\Release\net6.0-windows\ D:\gitea\AUCMA\AUCMA_SCADA\HwControlLib\obj\Release\net6.0-windows\
HwControlLib HwControlLib
none none
false false
@ -12,8 +12,8 @@ TRACE;RELEASE;NET;NET6_0;NETCOREAPP
1204305769 1204305769
3-783178491 5-440531829
194-2067936865 1941709816142
Themes\Generic.xaml; Themes\Generic.xaml;
True True

@ -1,4 +1,4 @@
 
FD:\Project\gitea\AUCMA\SCADA\HwControlLib\Themes\Generic.xaml;; FD:\gitea\AUCMA\AUCMA_SCADA\HwControlLib\Themes\Generic.xaml;;

Loading…
Cancel
Save