忱 沈 4 years ago
parent
commit
57aa8b1c6c
  1. 2
      View/StuffView.xaml
  2. 22
      View/StuffView.xaml.cs
  3. 14
      ViewModel/StuffViewModel.cs

2
View/StuffView.xaml

@ -23,7 +23,7 @@
</Border>
<Grid Grid.Row="0"/>
<Grid Grid.Row="1">
<DataGrid x:Name="DataGridStuff" MouseDoubleClick="DataGridStuff_MouseDoubleClick" ItemsSource="{Binding Product}" SelectionMode="Single" AlternationCount="2" IsReadOnly="True" HorizontalAlignment="Left" Margin="15,15,0,150" d:ItemsSource="{d:SampleData ItemCount=200}" AutoGenerateColumns="False" MinColumnWidth="30" HorizontalGridLinesBrush="#FFC9C9C9" VerticalGridLinesBrush="#FFC9C9C9" GridLinesVisibility="All" BorderBrush="#CCCCCC" BorderThickness="1,1,1,1" ColumnHeaderHeight="40" HorizontalContentAlignment="Right" Grid.ColumnSpan="2" CanUserReorderColumns="False">
<DataGrid x:Name="DataGridStuff" MouseDoubleClick="DataGridStuff_MouseDoubleClick" ItemsSource="{Binding Product, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" SelectionMode="Single" AlternationCount="2" IsReadOnly="True" HorizontalAlignment="Left" Margin="15,15,0,150" d:ItemsSource="{d:SampleData ItemCount=200}" AutoGenerateColumns="False" MinColumnWidth="30" HorizontalGridLinesBrush="#FFC9C9C9" VerticalGridLinesBrush="#FFC9C9C9" GridLinesVisibility="All" BorderBrush="#CCCCCC" BorderThickness="1,1,1,1" ColumnHeaderHeight="40" HorizontalContentAlignment="Right" Grid.ColumnSpan="2" CanUserReorderColumns="False">
<DataGrid.RowStyle >
<Style TargetType="{x:Type DataGridRow}">
<Style.Triggers>

22
View/StuffView.xaml.cs

@ -1,4 +1,5 @@
using System;
using GalaSoft.MvvmLight;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -16,6 +17,7 @@ using System.Windows.Forms;
using System.Drawing;
using System.Text.RegularExpressions;
using Models;
using Audit.ViewModel;
namespace Audit.View
{
@ -44,7 +46,6 @@ namespace Audit.View
}
private Product product = new Product();
private void Button_Preservation(object sender, RoutedEventArgs e)//保存按钮事件
{
int int_stuff_ProductType = 0;
@ -72,16 +73,16 @@ namespace Audit.View
product.GRAVITY = Double.Parse(this.stuff_GRAVITY.Text);//写入原料比重
product.Concentration = Double.Parse(this.stuff_Concentration.Text);//写入原料浓度
product.ProductType = int_stuff_ProductType;//写入原料类型
var count = new ProductProvider().Insert(product);//实例化并添加数据库信息。
if (count == 0)//判断执行是否成功
{
var count = new ProductProvider().Insert(product);//实例化并添加数据库信息。
if (count == 0)//判断执行是否成功
{
System.Windows.MessageBox.Show("ERR.C0110-1:添加失败");
}
else
{
System.Windows.MessageBox.Show("添加完成");
}
}
}
else
{
System.Windows.MessageBox.Show("添加完成");
}
}
}
private void Button_Delete(object sender, RoutedEventArgs e)
@ -130,6 +131,7 @@ namespace Audit.View
///存储色彩变量
/// </summary>
public static int ColorCode_SQL;
private void Stuff_Color_MouseDoubleClick(object sender, MouseButtonEventArgs e)//色彩框双击事件
{

14
ViewModel/StuffViewModel.cs

@ -9,6 +9,7 @@ using System.Threading.Tasks;
using System.Web.Services.Description;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Threading;
namespace Audit.ViewModel
{
@ -18,7 +19,7 @@ namespace Audit.ViewModel
public class StuffViewModel : ViewModelBase
{
private List<Product> products = new List<Product>();
/// <summary>
/// 所有原料
/// </summary>
@ -36,11 +37,20 @@ namespace Audit.ViewModel
}
/// <summary>
/// 查询数据
/// StuffViewModeldl
/// </summary>
public StuffViewModel()
{
products = new ProductProvider().Select();
DispatcherTimer timer = new DispatcherTimer();//每5秒调用一次Tick_Event
timer.Interval = TimeSpan.FromSeconds(5);
timer.Tick += Tick_Event;
timer.Start();
}
void Tick_Event(object sender, EventArgs e)
{
Product = new ProductProvider().Select();//扫描数据库
}
}
}

Loading…
Cancel
Save