sc 2 years ago
parent
commit
13b13e817a
  1. 6
      MainWindow.xaml
  2. 74
      MainWindow.xaml.cs
  3. 80
      ViewModel/MainWindowViewModel.cs

6
MainWindow.xaml

@ -9,7 +9,9 @@
DataContext="{Binding Source={StaticResource Locator}, Path=Main}" DataContext="{Binding Source={StaticResource Locator}, Path=Main}"
BorderBrush="White" Background="#FFE0E0E0"> BorderBrush="White" Background="#FFE0E0E0">
<Window.Resources> <Window.Resources>
<CollectionViewSource x:Key="UnitList" Source="{Binding Path=UnitList}"/>
<CollectionViewSource x:Key="BarCollectionSource" Source="{Binding Path=BarCollection}"/> <CollectionViewSource x:Key="BarCollectionSource" Source="{Binding Path=BarCollection}"/>
<CollectionViewSource x:Key="defaultView" Source="{Binding Path=defaultView}"/>
</Window.Resources> </Window.Resources>
<Grid> <Grid>
@ -163,10 +165,8 @@
<DataGridTemplateColumn.CellTemplate> <DataGridTemplateColumn.CellTemplate>
<DataTemplate> <DataTemplate>
<ComboBox x:Name="CP_PRODUCT_CODE" BorderThickness="0,0,0,0" <ComboBox x:Name="CP_PRODUCT_CODE" BorderThickness="0,0,0,0"
ItemsSource="{Binding Path=DataContext.BarCollection, RelativeSource={RelativeSource AncestorType={x:Type Window}}}"
DisplayMemberPath="Name"
SelectedItem="{Binding Bar, UpdateSourceTrigger=LostFocus}"
ItemsSource="{Binding Source={StaticResource BarCollectionSource}}"
Text="{Binding PRODUCT_CODE}" 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"

74
MainWindow.xaml.cs

@ -28,6 +28,7 @@ using Xceed.Wpf.Toolkit.PropertyGrid.Attributes;
using static System.Net.Mime.MediaTypeNames; using static System.Net.Mime.MediaTypeNames;
//using static System.Windows.Forms.VisualStyles.VisualStyleElement; //using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace formula_manage namespace formula_manage
{ {
/// <summary> /// <summary>
@ -54,6 +55,8 @@ namespace formula_manage
public MainWindow() public MainWindow()
{ {
// DataContext =new MainWindow();
int ID_N = 1; int ID_N = 1;
WindowStartupLocation = WindowStartupLocation.CenterScreen; WindowStartupLocation = WindowStartupLocation.CenterScreen;
@ -119,15 +122,82 @@ namespace formula_manage
Grid_RRODUCT.ItemsSource = RRODUCTdataTable.DefaultView; Grid_RRODUCT.ItemsSource = RRODUCTdataTable.DefaultView;
this.DataContext = STUFFdataTable; DataView defaultView = MACHINEdataTable.DefaultView;
// UnitList = defaultView;
// DataContext = MACHINEdataTable.DefaultView;
// CP_PRODUCT_CODE.ItemsSource= STUFFdataTable.;
/* DataGridTemplateColumn tempColumn = Grid_RRODUCT.Columns[1] as DataGridTemplateColumn; /* DataGridTemplateColumn tempColumn = Grid_RRODUCT.Columns[1] as DataGridTemplateColumn;
FrameworkElement element1 = Grid_RRODUCT.Columns[1].GetCellContent(Grid_RRODUCT.Items[1]); FrameworkElement element1 = Grid_RRODUCT.Columns[1].GetCellContent(Grid_RRODUCT.Items[1]);
System.Windows.Controls.ComboBox comboBox1 = tempColumn.CellTemplate.FindName("CP_PRODUCT_CODE", element1) as System.Windows.Controls.ComboBox; System.Windows.Controls.ComboBox comboBox1 = tempColumn.CellTemplate.FindName("CP_PRODUCT_CODE", element1) as System.Windows.Controls.ComboBox;
comboBox1.ItemsSource = STUFFdataTable.DefaultView;*/ comboBox1.ItemsSource = STUFFdataTable.DefaultView;*/
/* SelectionList.Add("Name1");
SelectionList.Add("Name2");*/
}
public string[] UnitList { get; set; }
private int g_TypeNameDicNo =123; //枪型号名
public int G_TypeNameDicNo
{
get
{
return g_TypeNameDicNo;
}
set
{
g_TypeNameDicNo = value;
}
}
public string G_TypeNameDicNoStr
{
get
{
return gunNameTypeDic[g_TypeNameDicNo]; //查找Dictionary返回它的Value
} }
set
{
int selectedIndex = 0;
foreach (KeyValuePair<int, string> pair in gunNameTypeDic)
{
if (pair.ToString().Equals(value)) //对比键值对
{
selectedIndex = pair.Key;
}
}
G_TypeNameDicNo = selectedIndex;
}
}
private Dictionary<int, string> gunNameTypeDic;
public Dictionary<int, string> GunNameTypeDic
{
get
{
return gunNameTypeDic;
}
}
public ObservableCollection<string> SelectionList //ObservableCollection这是一个类,需引用(using System.Collections.ObjectModel)
{
get { return _selectionList; }
set { _selectionList = value; }
}
private ObservableCollection<string> _selectionList = new ObservableCollection<string>(); //这个是实现的重要一步
/* private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) /* private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{ {
@ -520,7 +590,7 @@ namespace formula_manage
Procedures_N.Text = "1"; Procedures_N.Text = "1";
Procedures_P.Text = "1"; Procedures_P.Text = "1";
// RecipedataTable = RRODUCTdataTable; RecipedataTable = RRODUCTdataTable;
} }
private void Button_NewOrder(object sender, RoutedEventArgs e) //新料单按钮 private void Button_NewOrder(object sender, RoutedEventArgs e) //新料单按钮

80
ViewModel/MainWindowViewModel.cs

@ -1,25 +1,96 @@
using formula_manage.SQLModels; using formula_manage.SQLModels;
using formula_manage.ViewModel;
using formula_manage.Windows; using formula_manage.Windows;
using GalaSoft.MvvmLight; using GalaSoft.MvvmLight;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Linq; using System.Linq;
using System.Runtime.CompilerServices;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Threading; using System.Windows.Threading;
namespace formula_manage.ViewModel namespace formula_manage.ViewModel
{ {
///<Summary> ///<Summary>
/// RRODUCTiewModel /// RRODUCTiewModel
///</Summary> ///</Summary>
public class MainWindowViewModel : ViewModelBase public class MainWindowViewModel : 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 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;
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 ,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;
}
DataView defaultView = MACHINEdataTable.DefaultView;
// Machine.ItemsSource = MACHINEdataTable.DefaultView; // MACHINEdataTable数据集传递到ComboBox:machine
// Workflow.ItemsSource = DissolvedataTable.DefaultView; // DissolvedataTable数据集传递到ComboBox:Workflow
}
public MainWindowViewModel() public MainWindowViewModel()
{ {
sql_();
BarCollection = new ObservableCollection<BarModel> BarCollection = new ObservableCollection<BarModel>
{ {
new BarModel { Id = 1, Name = "Bar 1", }, new BarModel { Id = 1, Name = "Bar 1", },
@ -38,6 +109,7 @@ namespace formula_manage.ViewModel
public ObservableCollection<BarModel> BarCollection { get; set; } public ObservableCollection<BarModel> BarCollection { get; set; }
public ObservableCollection<FooViewModel> FooCollection { get; set; } public ObservableCollection<FooViewModel> FooCollection { get; set; }
} }
public class FooViewModel : ViewModelBase public class FooViewModel : ViewModelBase

Loading…
Cancel
Save