Merge branch 'master' of http://www.scserverddns.top:13000/sc/formula_manage
This commit is contained in:
commit
020fdc37c8
5 files changed
+154
-117
No files matched your search
+11
-13
@@ -10,7 +10,7 @@
|
||||
DataContext="{Binding Source={StaticResource Locator}, Path=Main}"
|
||||
BorderBrush="White" Background="#FFE0E0E0">
|
||||
<Window.Resources>
|
||||
<ViewModel:MainWindowViewModel x:Key="mvm"/>
|
||||
<ViewModel:MainWindowViewModel x:Key="MainWindowViewModel"/>
|
||||
</Window.Resources>
|
||||
<Grid>
|
||||
<Menu IsTabStop="False">
|
||||
@@ -71,7 +71,8 @@
|
||||
<TextBox x:Name="Anew" HorizontalAlignment="Left" Height="30" Margin="300,35,0,0" TextWrapping="Wrap" Text="0" VerticalAlignment="Top" Width="30" FontSize="20"
|
||||
MaxLines="1" MaxLength="2" PreviewTextInput="Tb_KeyPress" InputMethod.IsInputMethodEnabled="False" Focusable ="False"/>
|
||||
<TextBox HorizontalAlignment="Left" Height="30" Margin="95,105,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="200" FontSize="20" KeyUp="SearchBox_OnKeyDownd" IsTabStop="False"/>
|
||||
<ComboBox x:Name="Machine" DisplayMemberPath="Name" HorizontalAlignment="Left" Height="30" Margin="95,140,0,0" VerticalAlignment="Top" Width="120" FontSize="20" KeyUp="SearchBox_OnKeyDownd" IsEditable="True"/>
|
||||
<ComboBox x:Name="Machine" DisplayMemberPath="Name" ItemsSource="{Binding mac_Machine, Source={StaticResource MainWindowViewModel}}"
|
||||
HorizontalAlignment="Left" Height="30" Margin="95,140,0,0" VerticalAlignment="Top" Width="120" FontSize="20" KeyUp="SearchBox_OnKeyDownd" IsEditable="True"/>
|
||||
<ComboBox x:Name="OrderType" Text="正常单" HorizontalAlignment="Left" Height="30" Margin="95,175,0,0" VerticalAlignment="Top" Width="120" FontSize="20" IsTabStop="True" KeyUp="SearchBox_OnKeyDownd" IsEditable="True">
|
||||
<ComboBoxItem Content="正常单"></ComboBoxItem>
|
||||
<ComboBoxItem Content="追加单"></ComboBoxItem>
|
||||
@@ -97,7 +98,8 @@
|
||||
<Button Content="-" HorizontalAlignment="Left" Height="15" Width="20" Margin="140,20,0,0" VerticalAlignment="Top" FontSize="10"
|
||||
Background="#FFF1F1F1" BorderBrush="#FFC5C5C5" Padding="0,0,0,0" IsTabStop="False" Click="Button_StepDow" Focusable ="False"/>
|
||||
<TextBlock HorizontalAlignment="Left" Height="35" Margin="170,5,0,0" TextWrapping="Wrap" Text="流程:" VerticalAlignment="Top" Width="45" FontSize="20"/>
|
||||
<ComboBox Name="Workflow" DisplayMemberPath="DissolveName" HorizontalAlignment="Left" Height="30" Margin="225,5,0,0" Text="" VerticalAlignment="Top" Width="175" FontSize="20" IsEditable="True" Grid.ColumnSpan="2"/>
|
||||
<ComboBox Name="Workflow" DisplayMemberPath="DissolveName" ItemsSource="{Binding flow_Workflow, Source={StaticResource MainWindowViewModel}}"
|
||||
HorizontalAlignment="Left" Height="30" Margin="225,5,0,0" Text="" VerticalAlignment="Top" Width="175" FontSize="20" IsEditable="True" Grid.ColumnSpan="2"/>
|
||||
<TextBlock HorizontalAlignment="Left" Height="35" Margin="0,40,0,0" TextWrapping="Wrap" Text="配方代码:" VerticalAlignment="Top" Width="90" FontSize="20"/>
|
||||
<TextBox HorizontalAlignment="Left" Height="30" Margin="90,40,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="125" FontSize="20" KeyUp="SearchBox_OnKeyDownd"/>
|
||||
<TextBox HorizontalAlignment="Left" Height="30" Margin="225,40,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="140" FontSize="20" Focusable ="False" Grid.ColumnSpan="2"/>
|
||||
@@ -164,16 +166,11 @@
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<ComboBox x:Name="CP_PRODUCT_CODE" BorderThickness="0,0,0,0"
|
||||
|
||||
ItemsSource="{Binding DataContext.STUFFdataTable , RelativeSource={RelativeSource AncestorType={x:Type Window}}}"
|
||||
|
||||
|
||||
ItemsSource="{Binding stuff_Product, Source={StaticResource MainWindowViewModel}}"
|
||||
DisplayMemberPath="ProductCode"
|
||||
|
||||
|
||||
Text="{Binding PRODUCT_CODE}"
|
||||
BorderBrush="{x:Null}" Background="{x:Null}" IsEditable="True" KeyDown="CP_PRODUCT_CODE_KeyUp"
|
||||
>
|
||||
BorderBrush="{x:Null}" Background="{x:Null}" IsEditable="True" KeyDown="CP_PRODUCT_CODE_KeyUp" >
|
||||
|
||||
</ComboBox>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
@@ -199,9 +196,10 @@
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<ComboBox x:Name="CP_PRODUCT_NAME" BorderThickness="0,0,0,0"
|
||||
ItemsSource="{Binding STUFFdataTable }"
|
||||
ItemsSource="{Binding stuff_Product, Source={StaticResource MainWindowViewModel}}"
|
||||
DisplayMemberPath="ProductName"
|
||||
Text="{Binding PRODUCT_NAME}" BorderBrush="{x:Null}" Background="{x:Null}" IsEditable="True" IsReadOnly="True" Focusable="True" IsTabStop="False"/>
|
||||
Text="{Binding PRODUCT_NAME}"
|
||||
BorderBrush="{x:Null}" Background="{x:Null}" IsEditable="True" IsReadOnly="True" Focusable="True" IsTabStop="False"/>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
|
||||
+1
-34
@@ -104,7 +104,7 @@ namespace formula_manage
|
||||
_statistics.IsEnabled = true;
|
||||
}
|
||||
|
||||
sql_();//查询stuff表
|
||||
sql_();
|
||||
Permissions_(); //权限管理
|
||||
CountDown();//执行循环方法
|
||||
|
||||
@@ -122,11 +122,6 @@ namespace formula_manage
|
||||
}
|
||||
|
||||
Grid_RRODUCT.ItemsSource = RRODUCTdataTable.DefaultView;
|
||||
|
||||
//this.DataContext = Grid_RRODUCT;
|
||||
// this.DataContext = STUFFdataTable.DefaultView;
|
||||
|
||||
Grid_RRODUCT.DataContext = this;
|
||||
}
|
||||
|
||||
private async void sql_()
|
||||
@@ -145,34 +140,6 @@ namespace formula_manage
|
||||
{
|
||||
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 ,MacGroup ,Capacity ,Volume ,Industry ,Categories ,Note 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); //machine查询结果存入缓存
|
||||
|
||||
conn_SC.Close(); //关闭连接
|
||||
//DataGridStuff.ItemsSource = dataTable.DefaultView; //数据加入表格
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
System.Windows.MessageBox.Show("请求原料信息失败,检查连接");
|
||||
return;
|
||||
}
|
||||
|
||||
Machine.ItemsSource = MACHINEdataTable.DefaultView; // MACHINEdataTable数据集传递到ComboBox:machine
|
||||
Workflow.ItemsSource = DissolvedataTable.DefaultView; // DissolvedataTable数据集传递到ComboBox:Workflow
|
||||
}
|
||||
|
||||
private async void Permissions_()
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace formula_manage.UserClass
|
||||
{
|
||||
internal class DataTableToObservableCollection
|
||||
{
|
||||
public ObservableCollection<T> ToObservableCollection<T>(DataTable dt) where T : class, new()
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -58,7 +58,7 @@ public class MainWindowViewModel : ViewModelBase
|
||||
}
|
||||
|
||||
string Stuff_sql = "SELECT ProductCode ,ProductName ,ProductType ,Concentration FROM [Dispensing].[dbo].[PRODUCT] order by ProductCode asc";//查询STUFF语句
|
||||
string MAC_sql = "SELECT Name ,MacGroup ,Capacity ,Volume ,Industry ,Categories ,Note FROM [Dispensing].[dbo].[MACHINE] order by Name asc";//查询machine语句
|
||||
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); //实例化
|
||||
@@ -71,96 +71,82 @@ public class MainWindowViewModel : ViewModelBase
|
||||
|
||||
Stuff_data.Fill(STUFFdataTable); //stuff查询结果存入缓存
|
||||
Mac_data.Fill(MACHINEdataTable); //machine查询结果存入缓存
|
||||
Dissolve_data.Fill(DissolvedataTable); //machine查询结果存入缓存
|
||||
Dissolve_data.Fill(DissolvedataTable); //Dissolve_data查询结果存入缓存
|
||||
|
||||
conn_SC.Close(); //关闭连接
|
||||
|
||||
|
||||
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
System.Windows.MessageBox.Show("请求原料信息失败,检查连接");
|
||||
return;
|
||||
}
|
||||
|
||||
// IEnumerable STUFFdata = STUFFdataTable.DefaultView;
|
||||
// Machine.ItemsSource = MACHINEdataTable.DefaultView; // MACHINEdataTable数据集传递到ComboBox:machine
|
||||
// Workflow.ItemsSource = DissolvedataTable.DefaultView; // DissolvedataTable数据集传递到ComboBox:Workflow
|
||||
}
|
||||
|
||||
|
||||
|
||||
public MainWindowViewModel()
|
||||
{
|
||||
sql_();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// public ObservableCollection (System.Collections.Generic.List<T> list);
|
||||
// BarCollection = (ObservableCollection<BarModel>)STUFFdataTable.AsDataView();
|
||||
// var qwe = STUFFdataTable.DefaultView;
|
||||
// var product = STUFFdataTable.DefaultView;
|
||||
|
||||
|
||||
// BarCollection = (ObservableCollection<Product>)STUFFdata;
|
||||
|
||||
|
||||
|
||||
/* BarCollection = new ObservableCollection<Product>
|
||||
{
|
||||
new Product { ProductCode = "Bar 10", },
|
||||
new Product { ProductCode = "Bar 20", },
|
||||
new Product { ProductCode = "Bar 30", },
|
||||
};*/
|
||||
|
||||
/* FooCollection = new ObservableCollection<FooViewModel>
|
||||
{
|
||||
new FooViewModel{ Id = 1, },
|
||||
new FooViewModel{ Id = 2, },
|
||||
new FooViewModel{ Id = 3, },
|
||||
|
||||
};*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* product = new ObservableCollection<Product>;
|
||||
foreach (DataRow row in STUFFdataTable.Rows)
|
||||
{
|
||||
product.Add(new Product((int)row[0], (string)row[1], (string)row[2]));
|
||||
|
||||
} */
|
||||
|
||||
// _product = new ObservableCollection<Product>((IEnumerable<Product>));
|
||||
// {
|
||||
// new Product{ ProductCode= STUFFdataTable.Rows,ProductName= "123", ProductType= 12,Concentration= 12}
|
||||
// };
|
||||
|
||||
stuff_Product = ToObservableCollection<Product>(STUFFdataTable); //stuff_Product表转换
|
||||
mac_Machine = ToObservableCollection<Machine>(MACHINEdataTable);
|
||||
flow_Workflow = ToObservableCollection<Workflow>(DissolvedataTable);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// private ObservableCollection<string> _selectionList = new ObservableCollection<string>(); //这个是实现的重要一步
|
||||
|
||||
public ObservableCollection<Product> _product { get; set; }
|
||||
// public ObservableCollection<FooViewModel> FooCollection { get; set; }
|
||||
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()
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* public class FooViewModel : ViewModelBase
|
||||
{
|
||||
private BarModel _bar;
|
||||
|
||||
public int Id { get; set; }
|
||||
public BarModel Bar { get => _bar; set => Set(ref _bar, value); }
|
||||
}*/
|
||||
|
||||
public class Product
|
||||
public class Product //stuff_Product
|
||||
{
|
||||
public string ProductCode { get; set; }
|
||||
public string ProductName { get; set; }
|
||||
@@ -172,7 +158,29 @@ public class MainWindowViewModel : ViewModelBase
|
||||
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;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// StuffViewModeldl
|
||||
/// </summary>
|
||||
|
||||
@@ -178,6 +178,7 @@
|
||||
<Compile Include="SQLModels\STUFF_Product.cs" />
|
||||
<Compile Include="UserClass\IniFile.cs" />
|
||||
<Compile Include="UserClass\PressKey.cs" />
|
||||
<Compile Include="UserClass\DataTableForToObservableCollection.cs" />
|
||||
<Compile Include="ViewModel\MainWindowViewModel.cs" />
|
||||
<Compile Include="ViewModel\ViewModelLocator.cs" />
|
||||
<Compile Include="View\Formula.xaml.cs">
|
||||
|
||||
Reference in new issue
Block a user