忱 沈 4 years ago
parent
commit
98b2c6d733
  1. 20
      View/StuffView.xaml
  2. 35
      View/StuffView.xaml.cs
  3. 2
      ViewModel/StuffViewModel.cs

20
View/StuffView.xaml

@ -93,7 +93,7 @@
<!--原料代码-->
<TextBox x:Name="stuff_ProductCode" HorizontalAlignment="Left" Height="30" Margin="105,0,0,100" Text=""
VerticalAlignment="Bottom" Width="130" FontSize="16" MaxLines="1" MaxLength="25"
InputMethod.IsInputMethodEnabled="False"/>
InputMethod.IsInputMethodEnabled="False" xml:space="preserve"/>
<TextBlock HorizontalAlignment="Left" Height="30" Margin="15,0,0,100" TextWrapping="Wrap" Text="原料代码"
VerticalAlignment="Bottom" Width="100" FontSize="20"/>
<!--原料名称-->
@ -119,31 +119,37 @@
<!--供应商-->
<TextBox x:Name="stuff_ProductUnit" HorizontalAlignment="Left" Height="30" Margin="105,0,0,50" Text=""
VerticalAlignment="Bottom" Width="130" FontSize="16" MaxLines="1" MaxLength="25"
InputMethod.IsInputMethodEnabled="False" PreviewTextInput="Limitnumber"/>
InputMethod.IsInputMethodEnabled="False"/>
<TextBlock HorizontalAlignment="Left" Height="30" Margin="15,0,0,50" TextWrapping="Wrap" Text="供应商"
VerticalAlignment="Bottom" Width="80" FontSize="20"/>
<!--价格-->
<TextBox x:Name="stuff_Price" HorizontalAlignment="Left" Height="30" Margin="305,0,0,50" Text=""
VerticalAlignment="Bottom" Width="80" FontSize="16" MaxLines="1" MaxLength="25"
InputMethod.IsInputMethodEnabled="False" PreviewTextInput="Limitnumber"/>
InputMethod.IsInputMethodEnabled="False"/>
<TextBlock HorizontalAlignment="Left" Height="30" Margin="255,0,0,50" TextWrapping="Wrap" Text="价格"
VerticalAlignment="Bottom" Width="45" FontSize="20"/>
<!--浓度-->
<TextBox x:Name="stuff_Concentration" HorizontalAlignment="Left" Height="30" Margin="585,0,0,50" Text="0"
VerticalAlignment="Bottom" Width="50" FontSize="16" MaxLines="1" MaxLength="25"
InputMethod.IsInputMethodEnabled="False" PreviewTextInput="Limitnumber"/>
VerticalAlignment="Bottom" Width="50" FontSize="16" MaxLines="1" MaxLength="5"
InputMethod.IsInputMethodEnabled="False"/>
<TextBlock HorizontalAlignment="Left" Height="30" Margin="540,0,0,50" TextWrapping="Wrap" Text="浓度"
VerticalAlignment="Bottom" Width="45" FontSize="20"/>
<!--比重-->
<TextBox x:Name="stuff_GRAVITY" HorizontalAlignment="Left" Height="30" Margin="695,0,0,50" Text="1"
VerticalAlignment="Bottom" Width="50" FontSize="16" MaxLines="1" MaxLength="25"
InputMethod.IsInputMethodEnabled="False" PreviewTextInput="Limitnumber"/>
VerticalAlignment="Bottom" Width="50" FontSize="16" MaxLines="1" MaxLength="4"
InputMethod.IsInputMethodEnabled="False"/>
<TextBlock HorizontalAlignment="Left" Height="30" Margin="650,0,0,50" TextWrapping="Wrap" Text="比重"
VerticalAlignment="Bottom" Width="45" FontSize="20"/>
<!--存储按钮-->
<Button Content="存储" HorizontalAlignment="Left" Height="65" Margin="795,0,0,60"
VerticalAlignment="Bottom" Width="145" FontSize="40" BorderBrush="{x:Null}" Background="#FFCECECE"
Click="Button_Preservation">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseUp">
<i:InvokeCommandAction Command="{Binding CommandToBindTo}"
CommandParameter="{Binding CommandParameterToBindTo}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
<!--删除按钮-->
<Button Content="删除" HorizontalAlignment="Left" Height="65" Margin="975,0,0,60"

35
View/StuffView.xaml.cs

@ -34,25 +34,18 @@ namespace Audit.View
InitializeComponent();
}
/// <summary>
/// 输入限制
/// 仅允许数字及小数点
/// </summary>
public void Limitnumber(object sender, TextCompositionEventArgs e)
{
Regex re = new Regex("[^0-9]+.");//实例化输入信息白名单
e.Handled = re.IsMatch(e.Text);//检查输入信息并匹配白名单
}
private Product product = new Product();
private Product product_Codetemp = new Product();
private void Button_Preservation(object sender, RoutedEventArgs e)//保存按钮事件
{
Regex re_number = new Regex(@"^[0-9]+(.[0-9]{1,2})?$");//校验用正则表达式有1~2位小数的正实数
Regex re_char = new Regex(@"^[A-Za-z0-9\s@()()/+!!_-]+$");//校验用正则表达式由数字,26个英文字母,空白字符和@()()/+!!_-组成的字符串
int int_stuff_ProductType = 0;
if (this.stuff_ProductType.Text == "染料") int_stuff_ProductType = 0;//原料类型0。染料,1助剂,2粉体
if (this.stuff_ProductType.Text == "助剂") int_stuff_ProductType = 1;
if (this.stuff_ProductType.Text == "粉体助剂") int_stuff_ProductType = 2;
if (string.IsNullOrEmpty(this.stuff_ProductCode.Text)) System.Windows.MessageBox.Show("ERR.C0101:无效的原料信息", "错误");//检查原料代码
if (re_char.IsMatch(this.stuff_ProductCode.Text) == false) System.Windows.MessageBox.Show("ERR.C0101:无效的原料信息", "错误");//检查原料代码
else
if (string.IsNullOrEmpty(this.stuff_ProductName.Text)) System.Windows.MessageBox.Show("ERR.C0101-2:无效的原料信息", "错误");//检查原料名称
else
@ -60,9 +53,13 @@ namespace Audit.View
else
if (string.IsNullOrEmpty(this.stuff_GRAVITY.Text)) System.Windows.MessageBox.Show("ERR.C0101-1:无效的原料信息", "错误");//检查原料比重
else
if (float.Parse(this.stuff_GRAVITY.Text) < 0 || float.Parse(this.stuff_GRAVITY.Text) > 5) System.Windows.MessageBox.Show("ERR.C0102-1:原料信息错误", "错误");//检查比重输入数值
if (re_number.IsMatch(this.stuff_GRAVITY.Text) == false) System.Windows.MessageBox.Show("ERR.C0102-1:原料信息错误", "错误");//检查比重输入信息
else
if (re_number.IsMatch(this.stuff_Concentration.Text) == false) System.Windows.MessageBox.Show("ERR.C0102-3:原料信息错误", "错误");//检查浓度输入信息
else
if (float.Parse(this.stuff_GRAVITY.Text) < 0 || float.Parse(this.stuff_GRAVITY.Text) > 5) System.Windows.MessageBox.Show("ERR.C0102-2:原料信息错误", "错误");//检查比重输入数值
else
if(float.Parse(this.stuff_Concentration.Text) < 0 || float.Parse(this.stuff_Concentration.Text) > 100) System.Windows.MessageBox.Show("ERR.C0102-2:原料信息错误", "错误");//检查浓度输入数值
if(float.Parse(this.stuff_Concentration.Text) < 0 || float.Parse(this.stuff_Concentration.Text) > 100) System.Windows.MessageBox.Show("ERR.C0102-4:原料信息错误", "错误");//检查浓度输入数值
else
{
if (int_stuff_ProductType == 0)//判断是否为染料,非染料写空
@ -80,7 +77,7 @@ namespace Audit.View
product.GRAVITY = Double.Parse(this.stuff_GRAVITY.Text);//写入原料比重
product.Concentration = Double.Parse(this.stuff_Concentration.Text);//写入原料浓度
product.ProductType = int_stuff_ProductType;//写入原料类型
new ProductProvider().Delete(product);//删除数据库原目标信息。
var countwd = new ProductProvider().Delete(product_Codetemp);//删除数据库原目标信息。
var count = new ProductProvider().Insert(product);//添加数据库信息。
if (count == 0)//判断执行是否成功
{
@ -96,7 +93,7 @@ namespace Audit.View
private void Button_Delete(object sender, RoutedEventArgs e)//删除按钮事件
{
product.ProductCode = this.stuff_ProductCode.Text;//原料代码
string ShowProductName = "是否删除" + this.stuff_ProductName.Text;//获取原料并拼接提示字符串
string ShowProductName = "是否删除" + this.stuff_ProductCode.Text + "" + this.stuff_ProductName.Text;//获取原料信息并拼接提示字符串
MessageBoxResult showProductName = System.Windows.MessageBox.Show(ShowProductName, "提示", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.Yes);//弹窗提示是否删除目标原料
if (showProductName == MessageBoxResult.Yes)//判断是否删除原料
{
@ -138,6 +135,7 @@ namespace Audit.View
{
stuff_Color.Background = new SolidColorBrush(System.Windows.Media.Color.FromArgb(255, 255, 255, 255));//白色传递至色彩框背景色
}
product_Codetemp.ProductCode = stuff_ProductCode.Text;
}
}
@ -146,7 +144,6 @@ namespace Audit.View
///存储色彩变量
/// </summary>
public static int ColorCode_SQL;
private List<Product> Product;
private void Stuff_Color_MouseDoubleClick(object sender, MouseButtonEventArgs e)//色彩框双击事件
{
@ -159,8 +156,8 @@ namespace Audit.View
System.Windows.Media.Color MColor = System.Windows.Media.Color.FromArgb(DColor.A, DColor.R, DColor.G, DColor.B);//转换并配置ARGB参数
stuff_Color.Background = new SolidColorBrush(MColor);//ARGB参数输出至stuff_Color的背景色
stuff_Color.Foreground = new SolidColorBrush(MColor);//ARGB参数输出至stuff_Color的前景色
string colorCode = Convert.ToString(DColor.B,16) + Convert.ToString(DColor.G,16) + Convert.ToString(DColor.R,16);//反向十六进制RGB
//string colorCode = Convert.ToString(DColor.R,16) + Convert.ToString(DColor.G,16) + Convert.ToString(DColor.B,16);//正向十六进制RGB
string colorCode = string.Format("{0:X2}", DColor.B) + string.Format("{0:X2}", DColor.G) + string.Format("{0:X2}", DColor.R);//反向十六进制RGB
//string colorCode = string.Format("{0:X2}", DColor.R) + string.Format("{0:X2}", DColor.G) + string.Format("{0:X2}", DColor.B);//正向十六进制RGB
ColorCode_SQL = Convert.ToInt32(colorCode, 16);//十六进制RGB转存储数值
}
}

2
ViewModel/StuffViewModel.cs

@ -43,7 +43,7 @@ namespace Audit.ViewModel
{
products = new ProductProvider().Select();
DispatcherTimer timer = new DispatcherTimer();//每5秒调用一次Tick_Event
timer.Interval = TimeSpan.FromSeconds(5);
timer.Interval = TimeSpan.FromSeconds(1);
timer.Tick += Tick_Event;
timer.Start();
}

Loading…
Cancel
Save