添加RECIPE配方管理页面
This commit is contained in:
commit
292e41a5c4
6 files changed
+842
No files matched your search
@@ -339,6 +339,8 @@ namespace formula_manage
|
||||
}
|
||||
private void RECIPE(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Windows.RECIPE rECIPE = new Windows.RECIPE();
|
||||
rECIPE.ShowDialog();//实例化并置顶打开设置窗口
|
||||
}
|
||||
|
||||
private void PROCESS(object sender, RoutedEventArgs e)
|
||||
|
||||
@@ -0,0 +1,230 @@
|
||||
using formula_manage.SQLModels;
|
||||
using formula_manage.ViewModel;
|
||||
using formula_manage.Windows;
|
||||
using GalaSoft.MvvmLight;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using System.Windows.Threading;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace formula_manage.ViewModel
|
||||
{
|
||||
|
||||
/* public class ViewModelBase : INotifyPropertyChanged
|
||||
{
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
protected virtual void OnPropertyChanged(string propertyName)
|
||||
{
|
||||
if (this.PropertyChanged != null)
|
||||
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}*/
|
||||
///<Summary>
|
||||
///
|
||||
///
|
||||
///</Summary>
|
||||
///
|
||||
public class RECIPEViewModel : ViewModelBase
|
||||
{
|
||||
DataTable DissolvedataTable = new DataTable(); //建立Dissolve
|
||||
DataTable STUFFdataTable = new DataTable(); //建立STUFF
|
||||
DataTable MACHINEdataTable = new DataTable(); //建立Machine
|
||||
DataTable RRODUCTdataTable = new DataTable(); //建立RRODUCT
|
||||
DataTable RecipedataTable = new DataTable(); //建立Recipe
|
||||
|
||||
public static DataTable STUFFdatatemp = new DataTable(); //建立STUFF缓存
|
||||
public static DataTable MACHINEdatatemp = new DataTable(); //建立Machine缓存
|
||||
|
||||
public string INIPath = Convert.ToString(System.AppDomain.CurrentDomain.BaseDirectory) + "formula.ini"; //配置文件路径
|
||||
public string sys_Time; //显示系统时间
|
||||
public string Sys_Time //通知UI控件参数改变
|
||||
{
|
||||
get { return sys_Time; }
|
||||
set { sys_Time = value; OnPropertyChanged("Sys_Time"); }
|
||||
}
|
||||
|
||||
string TEXT_SQLIP;
|
||||
string TEXT_SQLNAME;
|
||||
string TEXT_SQMOD;
|
||||
string TEXT_SQLUSER;
|
||||
string TEXT_SQLPASWOR;
|
||||
string Connstr_SC;
|
||||
|
||||
private async void Sql_()
|
||||
{
|
||||
UserClass.IniFile.IniFiles Configini = new UserClass.IniFile.IniFiles(INIPath);//生效配置读取
|
||||
TEXT_SQLIP = Configini.IniReadvalue("SQL_SERVER", "SQL1"); //读配置文件
|
||||
TEXT_SQLNAME = Configini.IniReadvalue("SQL_SERVER", "SQL2");
|
||||
TEXT_SQMOD = Configini.IniReadvalue("SQL_SERVER", "SQL3");
|
||||
TEXT_SQLUSER = Configini.IniReadvalue("SQL_SERVER", "SQL4");
|
||||
TEXT_SQLPASWOR = Configini.IniReadvalue("SQL_SERVER", "SQL5");
|
||||
if (TEXT_SQMOD == "0") //判断连接方式
|
||||
{
|
||||
Connstr_SC = "server=" + TEXT_SQLIP + ";database=" + TEXT_SQLNAME + ";Trusted_Connection=SSPI";
|
||||
}
|
||||
else
|
||||
{
|
||||
Connstr_SC = "server=" + TEXT_SQLIP + ";database=" + TEXT_SQLNAME + ";User ID=" + TEXT_SQLUSER + ";Password=" + TEXT_SQLPASWOR;
|
||||
}
|
||||
|
||||
string Stuff_sql = "SELECT ProductCode ,ProductName ,ProductType ,Concentration FROM [Dispensing].[dbo].[PRODUCT] order by ProductCode asc";//查询STUFF语句
|
||||
string MAC_sql = "SELECT Name ,Capacity ,Volume FROM [Dispensing].[dbo].[MACHINE] order by Name asc";//查询machine语句
|
||||
string Dissolve_sql = "SELECT DissolveCode ,DissolveName ,MaterialType ,WeightMIN ,WeightMAX REMARK FROM [Dispensing].[dbo].[Dissolve]";//查询语句
|
||||
|
||||
SqlConnection conn_SC = new SqlConnection(Connstr_SC); //实例化
|
||||
try
|
||||
{
|
||||
await conn_SC.OpenAsync(); //打开数据连接
|
||||
SqlDataAdapter Stuff_data = new SqlDataAdapter(Stuff_sql, Connstr_SC); //查询stuff
|
||||
SqlDataAdapter Mac_data = new SqlDataAdapter(MAC_sql, Connstr_SC); //查询machine
|
||||
SqlDataAdapter Dissolve_data = new SqlDataAdapter(Dissolve_sql, Connstr_SC); //查询Dissolve
|
||||
|
||||
Stuff_data.Fill(STUFFdataTable); //stuff查询结果存入缓存
|
||||
Mac_data.Fill(MACHINEdataTable); //machine查询结果存入缓存
|
||||
Dissolve_data.Fill(DissolvedataTable); //Dissolve_data查询结果存入缓存
|
||||
|
||||
conn_SC.Close(); //关闭连接
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
System.Windows.MessageBox.Show("请求原料信息失败,检查连接");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public RECIPEViewModel()
|
||||
{
|
||||
CountDown();
|
||||
Sql_();
|
||||
|
||||
stuff_Product = ToObservableCollection<Product>(STUFFdataTable); //stuff_Product表转换
|
||||
mac_Machine = ToObservableCollection<Machine>(MACHINEdataTable);
|
||||
flow_Workflow = ToObservableCollection<Workflow>(DissolvedataTable);
|
||||
|
||||
STUFFdatatemp = STUFFdataTable;
|
||||
MACHINEdatatemp = MACHINEdataTable;
|
||||
|
||||
}
|
||||
|
||||
public ObservableCollection<Product> stuff_Product { get; set; } //stuff_Product动态表实力化
|
||||
public ObservableCollection<Machine> mac_Machine { get; set; } //mac_Machine动态表实力化
|
||||
public ObservableCollection<Workflow> flow_Workflow { get; set; } //Dissolve动态表实力化
|
||||
public ObservableCollection<T> ToObservableCollection<T>(DataTable dt) where T : class, new() //DataTable FOR ObservableCollection转换器
|
||||
{
|
||||
Type t = typeof(T);
|
||||
PropertyInfo[] propertys = t.GetProperties();
|
||||
ObservableCollection<T> lst = new ObservableCollection<T>();
|
||||
string typeName = string.Empty;
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
T entity = new T();
|
||||
foreach (PropertyInfo pi in propertys)
|
||||
{
|
||||
typeName = pi.Name;
|
||||
if (dt.Columns.Contains(typeName))
|
||||
{
|
||||
if (!pi.CanWrite) continue;
|
||||
object value = dr[typeName];
|
||||
if (value == DBNull.Value) continue;
|
||||
if (pi.PropertyType == typeof(string))
|
||||
{
|
||||
pi.SetValue(entity, value.ToString(), null);
|
||||
}
|
||||
else if (pi.PropertyType == typeof(int) || pi.PropertyType == typeof(int?))
|
||||
{
|
||||
pi.SetValue(entity, int.Parse(value.ToString()), null);
|
||||
}
|
||||
else if (pi.PropertyType == typeof(DateTime?) || pi.PropertyType == typeof(DateTime))
|
||||
{
|
||||
pi.SetValue(entity, DateTime.Parse(value.ToString()), null);
|
||||
}
|
||||
else if (pi.PropertyType == typeof(float))
|
||||
{
|
||||
pi.SetValue(entity, float.Parse(value.ToString()), null);
|
||||
}
|
||||
else if (pi.PropertyType == typeof(double))
|
||||
{
|
||||
pi.SetValue(entity, double.Parse(value.ToString()), null);
|
||||
}
|
||||
else
|
||||
{
|
||||
pi.SetValue(entity, value, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
lst.Add(entity);
|
||||
}
|
||||
return lst;
|
||||
} //DataTable FOR ObservableCollection转换器
|
||||
/// <summary>
|
||||
/// 循环事件设定
|
||||
/// </summary>
|
||||
public void CountDown()
|
||||
{
|
||||
DispatcherTimer timer = new DispatcherTimer//初始化循环,每0.5秒调用一次Tick_Event
|
||||
{
|
||||
Interval = TimeSpan.FromSeconds(0.5)
|
||||
};
|
||||
timer.Tick += Tick_Event;
|
||||
timer.Start();
|
||||
|
||||
//设置定时器
|
||||
// disTimer.Tick += new EventHandler(DisTimer_Tick);//每一秒执行的方法
|
||||
// disTimer.Interval = new TimeSpan(10000000); //时间间隔为一秒。
|
||||
// disTimer.Start();//计时开始
|
||||
}
|
||||
void Tick_Event(object sender, EventArgs e)//Tick_Event周期执行事件
|
||||
{
|
||||
Sys_Time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
}
|
||||
}
|
||||
|
||||
/* public class Product //stuff_Product
|
||||
{
|
||||
public string ProductCode { get; set; }
|
||||
public string ProductName { get; set; }
|
||||
public int ProductType { get; set; }
|
||||
public int Concentration { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return ProductCode;
|
||||
}
|
||||
}
|
||||
public class Machine //mac
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public float Volume { get; set; }
|
||||
public float Capacity { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
public class Workflow //Dissolve
|
||||
{
|
||||
public string DissolveName { get; set; }
|
||||
public int MaterialType { get; set; }
|
||||
public int WeightMIN { get; set; }
|
||||
public int WeightMAX { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return DissolveName;
|
||||
}
|
||||
}*/
|
||||
|
||||
}
|
||||
@@ -27,6 +27,7 @@ namespace formula_manage.ViewModel
|
||||
////}
|
||||
|
||||
SimpleIoc.Default.Register<MainWindowViewModel>();
|
||||
SimpleIoc.Default.Register<RECIPEViewModel>();
|
||||
}
|
||||
|
||||
public MainWindowViewModel Main
|
||||
@@ -37,6 +38,13 @@ namespace formula_manage.ViewModel
|
||||
}
|
||||
}
|
||||
|
||||
public RECIPEViewModel Recipev
|
||||
{
|
||||
get
|
||||
{
|
||||
return ServiceLocator.Current.GetInstance<RECIPEViewModel>();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
<Window x:Class="formula_manage.Windows.RECIPE"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:formula_manage.Windows"
|
||||
xmlns:ConvertMoels="clr-namespace:formula_manage.ConvertMoels"
|
||||
xmlns:ViewModel="clr-namespace:formula_manage.ViewModel"
|
||||
mc:Ignorable="d" Loaded="RECIPE_Loaded"
|
||||
Title="RECIPE_SET" Height="720" Width="1100" MaxHeight="720" MaxWidth="1100" MinHeight="720" MinWidth="1100"
|
||||
DataContext="{Binding Source={StaticResource Locator}, Path=Recipev}"
|
||||
BorderBrush="White" Background="#FFE0E0E0">
|
||||
<Window.Resources>
|
||||
<ViewModel:RECIPEViewModel x:Key="RECIPEViewModel"/>
|
||||
</Window.Resources>
|
||||
<Grid>
|
||||
<!--设备表-->
|
||||
<DataGrid x:Name="DatagridDissolve" MouseDoubleClick="Dissolve_MouseDoubleClick" SelectionMode="Single" AlternationCount="2" IsReadOnly="True"
|
||||
Margin="15,0,15,150" d:ItemsSource="{d:SampleData ItemCount=999}" AutoGenerateColumns="False" MinColumnWidth="30"
|
||||
HorizontalGridLinesBrush="#FFC9C9C9" VerticalGridLinesBrush="#FFC9C9C9" GridLinesVisibility="All" BorderBrush="#CCCCCC"
|
||||
BorderThickness="1,1,1,1" ColumnHeaderHeight="40" HorizontalContentAlignment="Right" Grid.ColumnSpan="2"
|
||||
CanUserResizeRows="False" CanUserAddRows="False" CanUserDeleteRows="False" CanUserReorderColumns="False"
|
||||
CanUserResizeColumns="False" CanUserSortColumns="False" HeadersVisibility ="Column" VerticalAlignment="Bottom" Height="250">
|
||||
<DataGrid.RowStyle >
|
||||
<Style TargetType="{x:Type DataGridRow}">
|
||||
<Style.Triggers>
|
||||
<Trigger Property="ItemsControl.AlternationIndex" Value="0">
|
||||
<Setter Property="Background" Value="#FFFFFFFF" />
|
||||
</Trigger>
|
||||
<Trigger Property="ItemsControl.AlternationIndex" Value="1">
|
||||
<Setter Property="Background" Value="#FFF0F0F0" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsMouseOver" Value="False">
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</DataGrid.RowStyle>
|
||||
<DataGrid.CellStyle>
|
||||
<Style TargetType="DataGridCell">
|
||||
<Setter Property="BorderThickness" Value="0"/>
|
||||
<Setter Property="MinWidth" Value="20"/>
|
||||
<Style.Triggers>
|
||||
<Trigger Property="IsSelected" Value="True">
|
||||
<Setter Property="Background" Value="#FFC0C0C0"/>
|
||||
<Setter Property="BorderBrush" Value="#FFC0C0C0"/>
|
||||
<Setter Property="Foreground" Value="#000000"/>
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</DataGrid.CellStyle>
|
||||
<DataGrid.Columns>
|
||||
<!--列信息绑定-->
|
||||
<DataGridTextColumn Header="配方代码" Width="100" FontSize="15" MaxWidth="400" MinWidth="100" CanUserReorder="False"/>
|
||||
<DataGridTextColumn Header="配方名称" Width="200" FontSize="15" MaxWidth="400" MinWidth="100" CanUserReorder="False"/>
|
||||
<DataGridTextColumn Header="颜色名" Width="100" FontSize="15" MaxWidth="400" MinWidth="100" CanUserReorder="False"/>
|
||||
<DataGridTextColumn Header="颜色代码" Width="100" FontSize="15" MaxWidth="400" MinWidth="100" CanUserReorder="False"/>
|
||||
<DataGridTextColumn Header="客户代码" Width="100" FontSize="15" MaxWidth="400" MinWidth="100" CanUserReorder="False"/>
|
||||
<DataGridTextColumn Header="客户名称" Width="200" FontSize="15" MaxWidth="400" MinWidth="100" CanUserReorder="False"/>
|
||||
<DataGridTextColumn Header="备注" Width="800" FontSize="15" MinWidth="80" CanUserReorder="False"/>
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
<!--代码-->
|
||||
<TextBox x:Name="Code" HorizontalAlignment="Left" Height="30" Margin="65,0,0,100" Text=""
|
||||
VerticalAlignment="Bottom" Width="120" FontSize="22" MaxLines="1" MaxLength="25"
|
||||
InputMethod.IsInputMethodEnabled="False"/>
|
||||
<TextBlock HorizontalAlignment="Left" Height="30" Margin="15,0,0,100" TextWrapping="Wrap" Text="代码"
|
||||
VerticalAlignment="Bottom" Width="40" FontSize="20"/>
|
||||
<!--名称-->
|
||||
<TextBox x:Name="name" HorizontalAlignment="Left" Height="30" Margin="255,0,0,100" Text=""
|
||||
VerticalAlignment="Bottom" Width="120" FontSize="22" MaxLines="1" MaxLength="25"
|
||||
InputMethod.IsInputMethodEnabled="False"/>
|
||||
<TextBlock HorizontalAlignment="Left" Height="30" Margin="205,0,0,100" TextWrapping="Wrap" Text="名称"
|
||||
VerticalAlignment="Bottom" Width="45" FontSize="20"/>
|
||||
<!--备注-->
|
||||
<TextBox x:Name="Remark" HorizontalAlignment="Left" Height="30" Margin="255,0,0,50"
|
||||
VerticalAlignment="Bottom" Width="305" FontSize="22" MaxLines="1"/>
|
||||
<TextBlock HorizontalAlignment="Left" Height="30" Margin="205,0,0,50" TextWrapping="Wrap" Text="备注"
|
||||
VerticalAlignment="Bottom" Width="40" FontSize="20"/>
|
||||
|
||||
<!--存储按钮-->
|
||||
<Button Content="存储" HorizontalAlignment="Left" Height="50" Margin="795,0,0,60"
|
||||
VerticalAlignment="Bottom" Width="100" FontSize="30" Background="#FFEFEFEF" BorderBrush="White"
|
||||
Click="Button_Preservation">
|
||||
</Button>
|
||||
<!--删除按钮-->
|
||||
<Button Content="删除" HorizontalAlignment="Left" Height="50" Margin="935,0,0,60"
|
||||
VerticalAlignment="Bottom" Width="100" FontSize="30" Background="#FFEFEFEF" BorderBrush="White"
|
||||
Click="Button_Delete">
|
||||
</Button>
|
||||
<DataGrid x:Name="Grid_RRODUCT" AlternationCount="2" IsReadOnly="False"
|
||||
Margin="15,15,15,405" d:ItemsSource="{d:SampleData ItemCount=99}" AutoGenerateColumns="False" MinColumnWidth="30"
|
||||
HorizontalGridLinesBrush="#FFC9C9C9" VerticalGridLinesBrush="#FFC9C9C9" GridLinesVisibility="All" BorderBrush="#CCCCCC"
|
||||
BorderThickness="1,1,1,1" ColumnHeaderHeight="40" HorizontalContentAlignment="Right"
|
||||
CanUserReorderColumns="False" CanUserSortColumns="False" CanUserResizeRows="False"
|
||||
CanUserAddRows="False" CanUserDeleteRows="False" HeadersVisibility ="Column"
|
||||
Background="White" SelectionMode="Single" FontSize="15" >
|
||||
<DataGrid.Resources>
|
||||
<Style x:Key="CellStyle" TargetType="{x:Type DataGridCell}">
|
||||
<Setter Property="Focusable" Value="False"/>
|
||||
<Setter Property="Background" Value="#FFFFFFFF"/>
|
||||
<Setter Property="BorderBrush" Value="#FFFFFFFF"/>
|
||||
<Setter Property="Foreground" Value="#000000"/>
|
||||
<Setter Property="DataContext" Value="{Binding Main, Source={StaticResource Locator}}"/>
|
||||
</Style>
|
||||
</DataGrid.Resources>
|
||||
<DataGrid.RowStyle >
|
||||
<Style TargetType="{x:Type DataGridRow}">
|
||||
<Style.Triggers>
|
||||
<Trigger Property="ItemsControl.AlternationIndex" Value="0">
|
||||
<Setter Property="Background" Value="#FFFFFFFF" />
|
||||
</Trigger>
|
||||
<Trigger Property="ItemsControl.AlternationIndex" Value="1">
|
||||
<Setter Property="Background" Value="#FFFFFFFF" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsMouseOver" Value="False"/>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</DataGrid.RowStyle>
|
||||
<DataGrid.CellStyle>
|
||||
<Style TargetType="{x:Type DataGridCell}">
|
||||
<Setter Property="BorderThickness" Value="0"/>
|
||||
<Setter Property="MinWidth" Value="20"/>
|
||||
<Style.Triggers>
|
||||
<Trigger Property="IsSelected" Value="True">
|
||||
<Setter Property="Background" Value="#FFFFFFFF"/>
|
||||
<Setter Property="BorderBrush" Value="#FFFFFFFF"/>
|
||||
<Setter Property="Foreground" Value="#000000"/>
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</DataGrid.CellStyle>
|
||||
<DataGrid.Columns>
|
||||
<!--列信息绑定-->
|
||||
<DataGridTextColumn Header="序" Width="30" FontSize="15" MaxWidth="30" MinWidth="30" Binding="{Binding ID}" IsReadOnly="True" CellStyle="{StaticResource CellStyle}"/>
|
||||
<DataGridTemplateColumn Header="原料代码" Width="200" MaxWidth="400" MinWidth="100" IsReadOnly="False">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<ComboBox x:Name="CP_PRODUCT_CODE" BorderThickness="0,0,0,0"
|
||||
ItemsSource="{Binding stuff_Product, Source={StaticResource RECIPEViewModel}}"
|
||||
DisplayMemberPath="ProductCode"
|
||||
Text="{Binding PRODUCT_CODE}" IsTextSearchEnabled="True" StaysOpenOnEdit="True"
|
||||
BorderBrush="{x:Null}" Background="{x:Null}" IsEditable="True"
|
||||
KeyDown="CP_PRODUCT_CODE_KeyUp"
|
||||
DropDownClosed="CP_PRODUCT_CODE_DropDownClosed"/>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
<DataGridTemplateColumn Header="目标饱和度(%)" Width="200" MaxWidth="400" MinWidth="100" >
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<TextBox x:Name="CP_CONC" BorderThickness="0,0,0,0" Text="{Binding CONC}"
|
||||
BorderBrush="{x:Null}" Background="{x:Null}"
|
||||
KeyDown="CP_CONC_KeyUp"/>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
<DataGridTextColumn Header="计算单位" Width="80" MaxWidth="80" MinWidth="80" CellStyle="{StaticResource CellStyle}" Binding="{Binding SHIFT}"/>
|
||||
<DataGridTemplateColumn Header="原料名称" Width="200" MaxWidth="400" MinWidth="100" CellStyle="{StaticResource CellStyle}">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<ComboBox x:Name="CP_PRODUCT_NAME" BorderThickness="0,0,0,0"
|
||||
ItemsSource="{Binding stuff_Product, Source={StaticResource RECIPEViewModel}}"
|
||||
DisplayMemberPath="ProductName"
|
||||
Text="{Binding PRODUCT_NAME}"
|
||||
DropDownClosed="CP_PRODUCT_NAME_DropDownClosed"
|
||||
BorderBrush="{x:Null}" Background="{x:Null}" IsEditable="True" IsReadOnly="True" Focusable="True" IsTabStop="False"/>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
<DataGridTextColumn Header="单位" Width="80" FontSize="15" MaxWidth="80" MinWidth="80" IsReadOnly="True" Binding="{Binding UNIT}" CellStyle="{StaticResource CellStyle}"/>
|
||||
<DataGridTextColumn Header="备注" Width="600" FontSize="15" MinWidth="600" Binding="{Binding REMARK}" CellStyle="{StaticResource CellStyle}" IsReadOnly="False"/>
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -0,0 +1,419 @@
|
||||
using formula_manage.Windows;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Forms;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
using System.Windows.Threading;
|
||||
using formula_manage.ViewModel;
|
||||
using Xceed.Wpf.Toolkit.PropertyGrid.Attributes;
|
||||
using static System.Net.Mime.MediaTypeNames;
|
||||
using formula_manage.UserClass;
|
||||
using System.Drawing;
|
||||
using System.Diagnostics;
|
||||
using System.Printing;
|
||||
using System.Drawing.Printing;
|
||||
using static System.Drawing.Printing.PrinterSettings;
|
||||
using formula_manage.View;
|
||||
using FastReport.DevComponents.AdvTree;
|
||||
|
||||
namespace formula_manage.Windows
|
||||
{
|
||||
/// <summary>
|
||||
/// Machine.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class RECIPE : Window
|
||||
{
|
||||
// DataTable DissolvedataTable = new DataTable(); //建立Dissolve缓存
|
||||
// DataTable STUFFdataTable = new DataTable(); //建立STUFF缓存
|
||||
// DataTable MACHINEdataTable = new DataTable(); //建立Machine缓存
|
||||
DataTable RRODUCTdataTable = new DataTable(); //建立RRODUCT缓存
|
||||
// DataTable RecipedataTable = new DataTable(); //建立Recipe缓存
|
||||
|
||||
public string INIPath = Convert.ToString(System.AppDomain.CurrentDomain.BaseDirectory) + "formula.ini"; //配置文件路径
|
||||
|
||||
string TEXT_SQLIP;
|
||||
string TEXT_SQLNAME;
|
||||
string TEXT_SQMOD;
|
||||
string TEXT_SQLUSER;
|
||||
string TEXT_SQLPASWOR;
|
||||
string Connstr_SC;
|
||||
int ID_N = 1;
|
||||
|
||||
public RECIPE()
|
||||
{
|
||||
DataContext = new RECIPEViewModel();
|
||||
WindowStartupLocation = WindowStartupLocation.CenterScreen;
|
||||
InitializeComponent();
|
||||
|
||||
RRODUCTdataTable.Columns.Add("ID", typeof(int));
|
||||
RRODUCTdataTable.Columns.Add("DYELOT", typeof(string));
|
||||
RRODUCTdataTable.Columns.Add("ReDye", typeof(int));
|
||||
RRODUCTdataTable.Columns.Add("STEP", typeof(int));
|
||||
RRODUCTdataTable.Columns.Add("PRODUCT_CODE", typeof(string));
|
||||
RRODUCTdataTable.Columns.Add("CONC", typeof(float));
|
||||
RRODUCTdataTable.Columns.Add("SHIFT", typeof(string));
|
||||
RRODUCTdataTable.Columns.Add("PRODUCT_NAME", typeof(string));
|
||||
RRODUCTdataTable.Columns.Add("TARGET_WT", typeof(float));
|
||||
RRODUCTdataTable.Columns.Add("UNIT", typeof(string));
|
||||
RRODUCTdataTable.Columns.Add("Process", typeof(string));
|
||||
RRODUCTdataTable.Columns.Add("REMARK", typeof(string));
|
||||
|
||||
DataRow row = RRODUCTdataTable.NewRow(); //ID列
|
||||
row["ID"] = ID_N;
|
||||
row["UNIT"] = "g";
|
||||
RRODUCTdataTable.Rows.Add(row);
|
||||
|
||||
Grid_RRODUCT.ItemsSource = RRODUCTdataTable.DefaultView;
|
||||
}
|
||||
|
||||
private void RECIPE_Loaded(object sender, RoutedEventArgs e)//打开页面执行
|
||||
{
|
||||
UserClass.IniFile.IniFiles Configini = new UserClass.IniFile.IniFiles(INIPath);//生效配置读取
|
||||
this.DatagridDissolve.LoadingRow += new EventHandler<DataGridRowEventArgs>(this.DataGridEquipment_LoadingRow);//生成序列号
|
||||
|
||||
TEXT_SQLIP = Configini.IniReadvalue("SQL_SERVER", "SQL1"); //读配置文件
|
||||
TEXT_SQLNAME = Configini.IniReadvalue("SQL_SERVER", "SQL2");
|
||||
TEXT_SQMOD = Configini.IniReadvalue("SQL_SERVER", "SQL3");
|
||||
TEXT_SQLUSER = Configini.IniReadvalue("SQL_SERVER", "SQL4");
|
||||
TEXT_SQLPASWOR = Configini.IniReadvalue("SQL_SERVER", "SQL5");
|
||||
if (TEXT_SQMOD == "0") //判断连接方式
|
||||
{
|
||||
Connstr_SC = "server=" + TEXT_SQLIP + ";database=" + TEXT_SQLNAME + ";Trusted_Connection=SSPI";
|
||||
}
|
||||
else
|
||||
{
|
||||
Connstr_SC = "server=" + TEXT_SQLIP + ";database=" + TEXT_SQLNAME + ";User ID=" + TEXT_SQLUSER + ";Password=" + TEXT_SQLPASWOR;
|
||||
}
|
||||
|
||||
GridSql();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成序列号的方法
|
||||
/// </summary>
|
||||
private void DataGridEquipment_LoadingRow(object sender, DataGridRowEventArgs e)
|
||||
{
|
||||
e.Row.Header = e.Row.GetIndex() + 1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询数据库的方法
|
||||
/// </summary>
|
||||
private async void GridSql()
|
||||
{
|
||||
string Dissolve_sql = "SELECT DissolveCode ,DissolveName ,REMARK ,MaterialType ,WeightMIN ,WeightMAX FROM [Dispensing].[dbo].[Dissolve]";//查询语句
|
||||
|
||||
SqlConnection conn_SC = new SqlConnection(Connstr_SC); //实例化
|
||||
|
||||
try
|
||||
{
|
||||
await conn_SC.OpenAsync(); //打开数据连接
|
||||
SqlDataAdapter Stuff_data = new SqlDataAdapter(Dissolve_sql, Connstr_SC); //查询
|
||||
|
||||
DataTable dataTable = new DataTable(); //建立缓存
|
||||
Stuff_data.Fill(dataTable); //查询结果存入缓存
|
||||
conn_SC.Close(); //关闭连接
|
||||
|
||||
DatagridDissolve.ItemsSource = dataTable.DefaultView; //数据加入表格
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
System.Windows.MessageBox.Show("请求信息失败,检查连接");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void Dissolve_MouseDoubleClick(object sender, MouseButtonEventArgs e)//数据表双击事件
|
||||
{
|
||||
int rownum = DatagridDissolve.SelectedIndex;//获取鼠标选中行并定义变量
|
||||
if (rownum != -1)//判断鼠标定位是否有效
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void Tb_KeyFloating(object sender, TextCompositionEventArgs e)//输入事件
|
||||
{
|
||||
//Regex re = new Regex("[^0-9.-]+");
|
||||
Regex re = new Regex(@"^[.][0-9]+$|^[0-9]*[.]{0,1}[0-9]*$");// 非负浮点数
|
||||
e.Handled = !re.IsMatch(e.Text);
|
||||
}
|
||||
|
||||
private async 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个英文字母,空白字符和@()()/+!!_-组成的字符串
|
||||
string Dissolve_sql;
|
||||
int int_ion = 0;
|
||||
|
||||
|
||||
}
|
||||
|
||||
private async void Button_Delete(object sender, RoutedEventArgs e)//删除按钮事件
|
||||
{
|
||||
string Mac_name = "是否删除【" + this.Code.Text + "】";//获取信息并拼接提示字符串
|
||||
MessageBoxResult mac_name = System.Windows.MessageBox.Show(Mac_name, "提示", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.Yes);//弹窗提示是否删除目标
|
||||
if (mac_name == MessageBoxResult.Yes)//判断是否删除原料
|
||||
{
|
||||
string Stuff_sql = string.Format("DELETE FROM [dbo].[Dissolve] WHERE Name ='" + Code.Text.ToString() + "'");
|
||||
SqlConnection conn_SC = new SqlConnection(Connstr_SC); //实例化
|
||||
try
|
||||
{
|
||||
await conn_SC.OpenAsync(); //打开数据连接
|
||||
SqlCommand INSERT_cmd = new SqlCommand(Stuff_sql, conn_SC);
|
||||
int sql_in = INSERT_cmd.ExecuteNonQuery(); //执行语句
|
||||
conn_SC.Close(); //关闭连接
|
||||
if (sql_in == 0)
|
||||
{
|
||||
System.Windows.MessageBox.Show("ERR.C0110-2:删除失败", "错误");//判断执行是否成功
|
||||
}
|
||||
else
|
||||
{
|
||||
GridSql();
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
System.Windows.MessageBox.Show("请求失败,检查连接");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string Code_;
|
||||
string Name_;
|
||||
string Type_;
|
||||
string Conc_;
|
||||
double Weight_ = 0;
|
||||
|
||||
private void CP_PRODUCT_CODE_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)//原料代码输入事件
|
||||
{
|
||||
double ang;
|
||||
if (e.Key == Key.Enter)
|
||||
{
|
||||
System.Windows.Controls.ComboBox curComboBox = sender as System.Windows.Controls.ComboBox;
|
||||
int grid_row = Grid_RRODUCT.SelectedIndex; //获取当前行
|
||||
|
||||
Code_ = curComboBox.Text;
|
||||
|
||||
|
||||
DataRow[] r = MainWindowViewModel.STUFFdatatemp.Select("ProductCode ='" + Code_ + "'"); //查询判断原料代码是否有效
|
||||
if (!r.Any()) //检查原料信息
|
||||
{
|
||||
System.Windows.MessageBox.Show("原料不存在");
|
||||
curComboBox.Text = "";
|
||||
return;
|
||||
}
|
||||
|
||||
DataRow[] c = RRODUCTdataTable.Select("PRODUCT_CODE ='" + Code_ + "'");//查询判断原料代码是否重复
|
||||
if (c.Any())
|
||||
{
|
||||
System.Windows.MessageBox.Show("重复原料");
|
||||
return;
|
||||
}
|
||||
|
||||
Name_ = r[0].ItemArray[1].ToString();
|
||||
Type_ = r[0].ItemArray[2].ToString();
|
||||
Conc_ = r[0].ItemArray[3].ToString();
|
||||
|
||||
if ((Type_ == "0") || (Type_ == "3"))
|
||||
{
|
||||
Type_ = "%";
|
||||
}
|
||||
if ((Type_ == "1") || (Type_ == "2"))
|
||||
{
|
||||
Type_ = "g/L";
|
||||
}
|
||||
|
||||
if (grid_row == -1) grid_row = 0;
|
||||
DataRow row = RRODUCTdataTable.Rows[grid_row]; //ID列
|
||||
row.BeginEdit();
|
||||
row["PRODUCT_CODE"] = Code_;
|
||||
row["PRODUCT_NAME"] = Name_;
|
||||
row["SHIFT"] = Type_;
|
||||
row.EndEdit();
|
||||
if (grid_row == (ID_N - 1))
|
||||
{
|
||||
PressKey.PressKeys(Keys.Right, false);
|
||||
PressKey.PressKeys(Keys.Right, true);
|
||||
PressKey.PressKeys(Keys.Tab, false);
|
||||
PressKey.PressKeys(Keys.Tab, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
PressKey.PressKeys(Keys.Right, false);
|
||||
PressKey.PressKeys(Keys.Right, true);
|
||||
PressKey.PressKeys(Keys.Up, false);
|
||||
PressKey.PressKeys(Keys.Up, true);
|
||||
PressKey.PressKeys(Keys.Tab, false);
|
||||
PressKey.PressKeys(Keys.Tab, true);
|
||||
}
|
||||
}
|
||||
|
||||
DataGridHelper.SetRealTimeCommit(Grid_RRODUCT, true); //实时更新datagrid
|
||||
}
|
||||
private void CP_CONC_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)//目标饱和度输入事件
|
||||
{
|
||||
double ang;
|
||||
double conc = 0;
|
||||
|
||||
System.Windows.Controls.TextBox curTextBox = sender as System.Windows.Controls.TextBox;
|
||||
int grid_row = Grid_RRODUCT.SelectedIndex; //获取当前行
|
||||
|
||||
if (e.Key == Key.Enter)
|
||||
{
|
||||
if (!double.TryParse(curTextBox.Text, out ang))
|
||||
{
|
||||
System.Windows.MessageBox.Show("错误,重新输入");
|
||||
curTextBox.Text = "";
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (curTextBox.Text != "") conc = double.Parse(curTextBox.Text); //转换后判断数值输入是否异常
|
||||
if (conc > 100)
|
||||
{
|
||||
System.Windows.MessageBox.Show("比例错误");
|
||||
curTextBox.Text = "";
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
double Weight_t = Weight_ * conc;
|
||||
|
||||
DataRow row = RRODUCTdataTable.Rows[grid_row]; //ID列
|
||||
row.BeginEdit();
|
||||
row["CONC"] = string.Format("{0:N6}", conc);
|
||||
row["TARGET_WT"] = string.Format("{0:N3}", Weight_t);
|
||||
row.EndEdit();
|
||||
|
||||
if (grid_row == (ID_N - 1))
|
||||
{
|
||||
PressKey.PressKeys(Keys.Left, false);
|
||||
PressKey.PressKeys(Keys.Left, true);
|
||||
PressKey.PressKeys(Keys.Tab, false);
|
||||
PressKey.PressKeys(Keys.Tab, true);
|
||||
|
||||
DataRow rowadd = RRODUCTdataTable.NewRow(); //ID列
|
||||
//rowadd = RRODUCTdataTable.NewRow();
|
||||
ID_N++;
|
||||
rowadd["ID"] = ID_N;
|
||||
rowadd["UNIT"] = "g";
|
||||
RRODUCTdataTable.Rows.Add(rowadd);
|
||||
}
|
||||
}
|
||||
DataGridHelper.SetRealTimeCommit(Grid_RRODUCT, true); //实时更新datagrid
|
||||
}
|
||||
}
|
||||
}
|
||||
private void CP_PRODUCT_CODE_DropDownClosed(object sender, EventArgs e)//原料代码选择事件
|
||||
{
|
||||
double ang;
|
||||
|
||||
System.Windows.Controls.ComboBox curComboBox = sender as System.Windows.Controls.ComboBox;
|
||||
int grid_row = Grid_RRODUCT.SelectedIndex; //获取当前行
|
||||
|
||||
Code_ = curComboBox.Text;
|
||||
|
||||
DataRow[] r = MainWindowViewModel.STUFFdatatemp.Select("ProductCode ='" + Code_ + "'"); //查询判断原料代码是否有效
|
||||
if (!r.Any()) //检查原料信息
|
||||
{
|
||||
System.Windows.MessageBox.Show("原料不存在");
|
||||
curComboBox.Text = "";
|
||||
return;
|
||||
}
|
||||
|
||||
DataRow[] c = RRODUCTdataTable.Select("PRODUCT_CODE ='" + Code_ + "'");//查询判断原料代码是否重复
|
||||
if (c.Any())
|
||||
{
|
||||
System.Windows.MessageBox.Show("重复原料");
|
||||
return;
|
||||
}
|
||||
|
||||
Name_ = r[0].ItemArray[1].ToString();
|
||||
Type_ = r[0].ItemArray[2].ToString();
|
||||
Conc_ = r[0].ItemArray[3].ToString();
|
||||
|
||||
if ((Type_ == "0") || (Type_ == "3"))
|
||||
{
|
||||
Type_ = "%";
|
||||
}
|
||||
if ((Type_ == "1") || (Type_ == "2"))
|
||||
{
|
||||
Type_ = "g/L";
|
||||
}
|
||||
|
||||
if (grid_row == -1) grid_row = 0;
|
||||
DataRow row = RRODUCTdataTable.Rows[grid_row]; //ID列
|
||||
row.BeginEdit();
|
||||
row["PRODUCT_CODE"] = Code_;
|
||||
row["PRODUCT_NAME"] = Name_;
|
||||
row["SHIFT"] = Type_;
|
||||
row.EndEdit();
|
||||
DataGridHelper.SetRealTimeCommit(Grid_RRODUCT, true); //实时更新datagrid
|
||||
|
||||
}
|
||||
private void CP_PRODUCT_NAME_DropDownClosed(object sender, EventArgs e)//原料名选择事件
|
||||
{
|
||||
double ang;
|
||||
|
||||
System.Windows.Controls.ComboBox curComboBox = sender as System.Windows.Controls.ComboBox;
|
||||
int grid_row = Grid_RRODUCT.SelectedIndex; //获取当前行
|
||||
|
||||
if (curComboBox.Text != "")
|
||||
{
|
||||
Name_ = curComboBox.Text;
|
||||
|
||||
DataRow[] r = MainWindowViewModel.STUFFdatatemp.Select("ProductName ='" + Name_ + "'"); //查询判断原料代码是否有效
|
||||
|
||||
DataRow[] c = RRODUCTdataTable.Select("PRODUCT_NAME ='" + Name_ + "'");//查询判断原料代码是否重复
|
||||
if (c.Any())
|
||||
{
|
||||
System.Windows.MessageBox.Show("重复原料");
|
||||
return;
|
||||
}
|
||||
Code_ = r[0].ItemArray[0].ToString();
|
||||
Type_ = r[0].ItemArray[2].ToString();
|
||||
Conc_ = r[0].ItemArray[3].ToString();
|
||||
|
||||
if ((Type_ == "0") || (Type_ == "3"))
|
||||
{
|
||||
Type_ = "%";
|
||||
}
|
||||
if ((Type_ == "1") || (Type_ == "2"))
|
||||
{
|
||||
Type_ = "g/L";
|
||||
}
|
||||
if (grid_row == -1) grid_row = 0;
|
||||
DataRow row = RRODUCTdataTable.Rows[grid_row]; //ID列
|
||||
row.BeginEdit();
|
||||
row["PRODUCT_CODE"] = Code_;
|
||||
row["PRODUCT_NAME"] = Name_;
|
||||
row["SHIFT"] = Type_;
|
||||
row.EndEdit();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -211,6 +211,7 @@
|
||||
<Compile Include="UserClass\DataTableForToObservableCollection.cs" />
|
||||
<Compile Include="UserClass\PrintHelper.cs" />
|
||||
<Compile Include="UserClass\UserPrint.cs" />
|
||||
<Compile Include="ViewModel\RECIPEViewModel.cs" />
|
||||
<Compile Include="ViewModel\MainWindowViewModel.cs" />
|
||||
<Compile Include="ViewModel\ViewModelLocator.cs" />
|
||||
<Compile Include="View\Formula.xaml.cs">
|
||||
@@ -225,6 +226,9 @@
|
||||
<Compile Include="Windows\APP_set.xaml.cs">
|
||||
<DependentUpon>APP_set.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Windows\RECIPE.xaml.cs">
|
||||
<DependentUpon>RECIPE.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Windows\Dissolve.xaml.cs">
|
||||
<DependentUpon>Dissolve.xaml</DependentUpon>
|
||||
</Compile>
|
||||
@@ -289,6 +293,10 @@
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Windows\RECIPE.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
<Page Include="Windows\Dissolve.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
|
||||
Reference in new issue
Block a user