sc 2 years ago
parent
commit
c16e2e6f8d
  1. 4
      MainWindow.xaml
  2. 2
      MainWindow.xaml.cs
  3. 4
      ViewModel/StuffViewModel.cs
  4. 10
      Windows/Stuff.xaml
  5. 78
      Windows/Stuff.xaml.cs

4
MainWindow.xaml

@ -96,9 +96,9 @@
Margin="5,325,5,80" d:ItemsSource="{d:SampleData ItemCount=99}" AutoGenerateColumns="False" MinColumnWidth="30" Margin="5,325,5,80" d:ItemsSource="{d:SampleData ItemCount=99}" AutoGenerateColumns="False" MinColumnWidth="30"
HorizontalGridLinesBrush="#FFC9C9C9" VerticalGridLinesBrush="#FFC9C9C9" GridLinesVisibility="All" BorderBrush="#CCCCCC" HorizontalGridLinesBrush="#FFC9C9C9" VerticalGridLinesBrush="#FFC9C9C9" GridLinesVisibility="All" BorderBrush="#CCCCCC"
BorderThickness="1,1,1,1" ColumnHeaderHeight="40" HorizontalContentAlignment="Right" Grid.ColumnSpan="2" BorderThickness="1,1,1,1" ColumnHeaderHeight="40" HorizontalContentAlignment="Right" Grid.ColumnSpan="2"
CanUserReorderColumns="False" CanUserSortColumns="False" CanUserReorderColumns="False" CanUserSortColumns="False" CanUserResizeRows="False"
CanUserAddRows="False" CanUserDeleteRows="False" CanUserAddRows="False" CanUserDeleteRows="False"
Background="White" SelectionMode="Single" FontSize="15" CanUserResizeRows="False"> Background="White" SelectionMode="Single" FontSize="15" >
<DataGrid.RowStyle > <DataGrid.RowStyle >
<Style TargetType="{x:Type DataGridRow}"> <Style TargetType="{x:Type DataGridRow}">
<Style.Triggers> <Style.Triggers>

2
MainWindow.xaml.cs

@ -252,7 +252,7 @@ namespace formula_manage
} }
} }
private void Proportion(object sender, TextChangedEventArgs e) // private void Proportion(object sender, TextChangedEventArgs e) //浴比输入
{ {
float a, b, c; float a, b, c;
b = float.Parse(list_Proportion.Text); b = float.Parse(list_Proportion.Text);

4
ViewModel/StuffViewModel.cs

@ -49,14 +49,14 @@ namespace formula_manage.ViewModel
void Tick_Event(object sender, EventArgs e)//Tick_Event周期执行事件 void Tick_Event(object sender, EventArgs e)//Tick_Event周期执行事件
{ {
if (Stuff.Button_sql == true)//获取按钮状态 // if (Stuff.Button_sql == true)//获取按钮状态
{ {
// if (Stuff.Buttontype_sql == -1) Product = new ProductProvider().Select(); // if (Stuff.Buttontype_sql == -1) Product = new ProductProvider().Select();
// if (Stuff.Buttontype_sql == 0) Product = new ProductProvider().Selects0(); // if (Stuff.Buttontype_sql == 0) Product = new ProductProvider().Selects0();
// if (Stuff.Buttontype_sql == 1) Product = new ProductProvider().Selects1(); // if (Stuff.Buttontype_sql == 1) Product = new ProductProvider().Selects1();
// if (Stuff.Buttontype_sql == 2) Product = new ProductProvider().Selects2(); // if (Stuff.Buttontype_sql == 2) Product = new ProductProvider().Selects2();
// if (Stuff.Buttontype_sql == 3) Product = new ProductProvider().Selects3(); // if (Stuff.Buttontype_sql == 3) Product = new ProductProvider().Selects3();
Stuff.Button_sql = false;//清除按钮状态 // Stuff.Button_sql = false;//清除按钮状态
} }
} }
} }

10
Windows/Stuff.xaml

@ -18,9 +18,9 @@
<DataGrid x:Name="DataGridStuff" MouseDoubleClick="DataGridStuff_MouseDoubleClick" SelectionMode="Single" AlternationCount="2" IsReadOnly="True" <DataGrid x:Name="DataGridStuff" MouseDoubleClick="DataGridStuff_MouseDoubleClick" SelectionMode="Single" AlternationCount="2" IsReadOnly="True"
HorizontalAlignment="Left" Margin="15,15,0,150" d:ItemsSource="{d:SampleData ItemCount=200}" AutoGenerateColumns="False" MinColumnWidth="30" 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" HorizontalGridLinesBrush="#FFC9C9C9" VerticalGridLinesBrush="#FFC9C9C9" GridLinesVisibility="All" BorderBrush="#CCCCCC"
BorderThickness="1,1,1,1" ColumnHeaderHeight="40" HorizontalContentAlignment="Right" Grid.ColumnSpan="2" CanUserReorderColumns="False" BorderThickness="1,1,1,1" ColumnHeaderHeight="40" HorizontalContentAlignment="Right" Grid.ColumnSpan="2"
CanUserResizeRows="False" CanUserSortColumns="False" CanUserResizeColumns="False" CanUserResizeRows="False" CanUserAddRows="False" CanUserDeleteRows="False" CanUserReorderColumns="False"
CanUserAddRows="False" CanUserDeleteRows="False"> CanUserResizeColumns="False" CanUserSortColumns="False">
<DataGrid.RowStyle > <DataGrid.RowStyle >
<Style TargetType="{x:Type DataGridRow}"> <Style TargetType="{x:Type DataGridRow}">
<Style.Triggers> <Style.Triggers>
@ -28,7 +28,7 @@
<Setter Property="Background" Value="#FFFFFFFF" /> <Setter Property="Background" Value="#FFFFFFFF" />
</Trigger> </Trigger>
<Trigger Property="ItemsControl.AlternationIndex" Value="1"> <Trigger Property="ItemsControl.AlternationIndex" Value="1">
<Setter Property="Background" Value="#FFF5F5F5" /> <Setter Property="Background" Value="#FFF0F0F0" />
</Trigger> </Trigger>
<Trigger Property="IsMouseOver" Value="False"> <Trigger Property="IsMouseOver" Value="False">
</Trigger> </Trigger>
@ -133,7 +133,7 @@
VerticalAlignment="Bottom" Width="45" FontSize="20"/> VerticalAlignment="Bottom" Width="45" FontSize="20"/>
<!--浓度--> <!--浓度-->
<TextBox x:Name="stuff_Concentration" HorizontalAlignment="Left" Height="30" Margin="585,0,0,50" Text="100" <TextBox x:Name="stuff_Concentration" HorizontalAlignment="Left" Height="30" Margin="585,0,0,50" Text="100"
VerticalAlignment="Bottom" Width="50" FontSize="22" MaxLines="1" MaxLength="5" VerticalAlignment="Bottom" Width="50" FontSize="22" MaxLines="1" MaxLength="7"
InputMethod.IsInputMethodEnabled="False"/> InputMethod.IsInputMethodEnabled="False"/>
<TextBlock HorizontalAlignment="Left" Height="30" Margin="540,0,0,50" TextWrapping="Wrap" Text="浓度" <TextBlock HorizontalAlignment="Left" Height="30" Margin="540,0,0,50" TextWrapping="Wrap" Text="浓度"
VerticalAlignment="Bottom" Width="45" FontSize="20"/> VerticalAlignment="Bottom" Width="45" FontSize="20"/>

78
Windows/Stuff.xaml.cs

@ -86,42 +86,59 @@ namespace formula_manage.Windows
/// </summary> /// </summary>
private void DataGridEquipment_LoadingRow(object sender, DataGridRowEventArgs e) private void DataGridEquipment_LoadingRow(object sender, DataGridRowEventArgs e)
{ {
e.Row.Header = e.Row.GetIndex() + 1; // e.Row.Header = e.Row.GetIndex() + 1;
} }
public static Boolean Button_sql = true; private async void Radiobutton(object sender, EventArgs e)
public static int Buttontype_sql = -1;
private void Radiobutton(object sender, EventArgs e)
{ {
string Stuff_sql = null;
System.Windows.Controls.RadioButton Radiobutton = (sender as System.Windows.Controls.RadioButton); System.Windows.Controls.RadioButton Radiobutton = (sender as System.Windows.Controls.RadioButton);
string radiobutton = Radiobutton.Content.ToString(); string radiobutton = Radiobutton.Content.ToString();
if (radiobutton == "全部原料") Buttontype_sql = -1; if (radiobutton == "全部原料")
if (radiobutton == "染料") Buttontype_sql = 0; Stuff_sql = "SELECT ProductCode ,ProductName , Price , SUPPLIER ,ProductType ,Color ,Concentration , GRAVITY FROM [Dispensing].[dbo].[PRODUCT]";//查询语句
if (radiobutton == "助剂") Buttontype_sql = 1; else if (radiobutton == "染料")
if (radiobutton == "粉体助剂") Buttontype_sql = 2; Stuff_sql = "SELECT ProductCode ,ProductName , Price , SUPPLIER ,ProductType ,Color ,Concentration , GRAVITY FROM [Dispensing].[dbo].[PRODUCT] Where ProductType = '0' ";
if (radiobutton == "液体染料") Buttontype_sql = 3; else if (radiobutton == "助剂")
Button_sql = true; Stuff_sql = "SELECT ProductCode ,ProductName , Price , SUPPLIER ,ProductType ,Color ,Concentration , GRAVITY FROM [Dispensing].[dbo].[PRODUCT] Where ProductType = '1' ";
else if (radiobutton == "粉体助剂")
Stuff_sql = "SELECT ProductCode ,ProductName , Price , SUPPLIER ,ProductType ,Color ,Concentration , GRAVITY FROM [Dispensing].[dbo].[PRODUCT] Where ProductType = '2' ";
else if (radiobutton == "液体染料")
Stuff_sql = "SELECT ProductCode ,ProductName , Price , SUPPLIER ,ProductType ,Color ,Concentration , GRAVITY FROM [Dispensing].[dbo].[PRODUCT] Where ProductType = '3' ";
SqlConnection conn_SC = new SqlConnection(Connstr_SC); //实例化
try
{
await conn_SC.OpenAsync(); //打开数据连接
SqlDataAdapter Stuff_data = new SqlDataAdapter(Stuff_sql, Connstr_SC); //查询
DataTable dataTable = new DataTable(); //建立缓存
Stuff_data.Fill(dataTable); //查询结果存入缓存
conn_SC.Close(); //关闭连接
DataGridStuff.ItemsSource = dataTable.DefaultView; //数据加入表格
}
catch (Exception)
{
System.Windows.MessageBox.Show("请求原料信息失败,检查连接");
return;
}
} }
private void Button_Preservation(object sender, RoutedEventArgs e)//保存按钮事件 private async void Button_Preservation(object sender, RoutedEventArgs e)//保存按钮事件
{ {
Regex re_number = new Regex(@"^[0-9]+(.[0-9]{1,2})?$");//校验用正则表达式有1~2位小数的正实数 Regex re_number = new Regex(@"^[0-9]+(.[0-9]{1,2})?$");//校验用正则表达式有1~2位小数的正实数
Regex re_char = new Regex(@"^[A-Za-z0-9\s@()()/+!!_-]+$");//校验用正则表达式由数字,26个英文字母,空白字符和@()()/+!!_-组成的字符串 Regex re_char = new Regex(@"^[A-Za-z0-9\s@()()/+!!_-]+$");//校验用正则表达式由数字,26个英文字母,空白字符和@()()/+!!_-组成的字符串
int int_stuff_ProductType = 0; int int_stuff_ProductType;
String Stuff_sql;
if (this.stuff_ProductType.Text == "染料") //原料类型0。染料,1助剂,2粉体 if (this.stuff_ProductType.Text == "染料") //原料类型0。染料,1助剂,2粉体
{
int_stuff_ProductType = 0; int_stuff_ProductType = 0;
this.stuff_Concentration.Text = "100"; else if (this.stuff_ProductType.Text == "助剂")
}
if (this.stuff_ProductType.Text == "助剂")
int_stuff_ProductType = 1; int_stuff_ProductType = 1;
if (this.stuff_ProductType.Text == "粉体助剂") else if (this.stuff_ProductType.Text == "粉体助剂")
{
int_stuff_ProductType = 2; int_stuff_ProductType = 2;
this.stuff_Concentration.Text = "100"; else if (this.stuff_ProductType.Text == "液体染料")
}
if (this.stuff_ProductType.Text == "液体染料")
int_stuff_ProductType = 3; int_stuff_ProductType = 3;
if (re_char.IsMatch(this.stuff_ProductCode.Text) == false) if (re_char.IsMatch(this.stuff_ProductCode.Text) == false)
System.Windows.MessageBox.Show("ERR.C0101:无效的原料信息", "错误");//检查原料代码 System.Windows.MessageBox.Show("ERR.C0101:无效的原料信息", "错误");//检查原料代码
else else
@ -145,6 +162,25 @@ namespace formula_manage.Windows
else else
if (float.Parse(this.stuff_Concentration.Text) < 0 || float.Parse(this.stuff_Concentration.Text) > 100) if (float.Parse(this.stuff_Concentration.Text) < 0 || float.Parse(this.stuff_Concentration.Text) > 100)
System.Windows.MessageBox.Show("ERR.C0102-4:原料信息错误", "错误");//检查浓度输入数值 System.Windows.MessageBox.Show("ERR.C0102-4:原料信息错误", "错误");//检查浓度输入数值
else
{
SqlConnection conn_SC = new SqlConnection(Connstr_SC); //实例化
Stuff_sql = "SELECT ProductCode FROM [Dispensing].[dbo].[PRODUCT] WHERE ProductCode = '" + stuff_ProductCode.Text +" '";//查询语句
await conn_SC.OpenAsync(); //打开数据连接
SqlCommand cmd = new SqlCommand(Stuff_sql, conn_SC); //查询记录数
int count = Convert.ToInt32(cmd.ExecuteScalar()); //显示记录数
conn_SC.Close(); //关闭连接
if (count == 0)
{
}
else
{
}
}
/* else /* else
{ {
product.ProductCode = this.stuff_ProductCode.Text;//写入原料代码 product.ProductCode = this.stuff_ProductCode.Text;//写入原料代码

Loading…
Cancel
Save