diff --git a/MainWindow.xaml b/MainWindow.xaml
index fddcb79..9333017 100644
--- a/MainWindow.xaml
+++ b/MainWindow.xaml
@@ -9,7 +9,9 @@
DataContext="{Binding Source={StaticResource Locator}, Path=Main}"
BorderBrush="White" Background="#FFE0E0E0">
+
+
@@ -163,11 +165,9 @@
diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs
index e576edc..9d628ea 100644
--- a/MainWindow.xaml.cs
+++ b/MainWindow.xaml.cs
@@ -28,6 +28,7 @@ using Xceed.Wpf.Toolkit.PropertyGrid.Attributes;
using static System.Net.Mime.MediaTypeNames;
//using static System.Windows.Forms.VisualStyles.VisualStyleElement;
+
namespace formula_manage
{
///
@@ -54,12 +55,14 @@ namespace formula_manage
public MainWindow()
{
+ // DataContext =new MainWindow();
+
int ID_N = 1;
WindowStartupLocation = WindowStartupLocation.CenterScreen;
InitializeComponent();
this.Closing += Window_Closing; //添加窗口关闭事件
-
+
USER.Text = App.USER_Purview;
RecipedataTable.Columns.Add("DYELOT", typeof(int));
@@ -119,84 +122,151 @@ namespace formula_manage
Grid_RRODUCT.ItemsSource = RRODUCTdataTable.DefaultView;
- this.DataContext = STUFFdataTable;
+ DataView defaultView = MACHINEdataTable.DefaultView;
+ // UnitList = defaultView;
- /* DataGridTemplateColumn tempColumn = Grid_RRODUCT.Columns[1] as DataGridTemplateColumn;
- 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;
+
+ // DataContext = MACHINEdataTable.DefaultView;
- comboBox1.ItemsSource = STUFFdataTable.DefaultView;*/
- }
+ // CP_PRODUCT_CODE.ItemsSource= STUFFdataTable.;
+ /* DataGridTemplateColumn tempColumn = Grid_RRODUCT.Columns[1] as DataGridTemplateColumn;
+ 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;
+ comboBox1.ItemsSource = STUFFdataTable.DefaultView;*/
- /* private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- var cb = (sender as System.Windows.Controls.ComboBox);
- if (cb == null || cb.Tag == null) return;
- int idx = int.Parse(cb.Tag.ToString());
- // var bindDataGridDatas = this.Grid_RRODUCT.ItemsSource as BindDataGridData[];//成员变量和这里转换都可以。
- // bindDataGridDatas[idx].UnitStr = (string)cb.SelectedItem;//手动保存到数据结构
- // bindDataGridDatas[idx].UpdateKBValue(); //联动CoefK值
- }
+ /* SelectionList.Add("Name1");
- public event PropertyChangedEventHandler PropertyChanged;
+ SelectionList.Add("Name2");*/
+
- private void PropertiesC([CallerMemberName] string propertyName = "")
- {
- this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
- public int Idx { get; set; } = 0;
+ public string[] UnitList { get; set; }
- string unitstr = "Pa";
+ private int g_TypeNameDicNo =123; //枪型号名
- public string UnitStr
+ public int G_TypeNameDicNo
{
get
{
- return this.unitstr;
+ return g_TypeNameDicNo;
}
set
{
- this.unitstr = value;
- this.PropertiesC();
+ g_TypeNameDicNo = value;
}
}
-
- public string[] UnitList { get; set; } = new string[] { "Pa", "kPa", "MPa" };
-
- public static readonly float[][] KBList = new float[][] { new float[] { 1, 1 }, new float[] { 1000, 2 }, new float[] { 1000000, 3 } };
-
- float coefK { get; set; } = 1f;
-
- public float CoefK
+ public string G_TypeNameDicNoStr
{
get
{
- return this.coefK;
+ return gunNameTypeDic[g_TypeNameDicNo]; //查找Dictionary返回它的Value
}
set
{
- this.coefK = value;
- this.PropertiesC();
+ int selectedIndex = 0;
+ foreach (KeyValuePair pair in gunNameTypeDic)
+ {
+ if (pair.ToString().Equals(value)) //对比键值对
+ {
+ selectedIndex = pair.Key;
+ }
+ }
+ G_TypeNameDicNo = selectedIndex;
}
}
- public void UpdateKBValue()
+ private Dictionary gunNameTypeDic;
+ public Dictionary GunNameTypeDic
{
- int idx = -1;
- for (int j = 0; j < this.UnitList.Length; j++)
+ get
{
- if (this.UnitList[j] == this.unitstr)
- {
- idx = j; break;
- }
+ return gunNameTypeDic;
}
- if (idx == -1) return;
- //throw new System.Exception("no Unit in UnitList: unit " + this.UnitStr + " UnitList {" + string.Join(", ", this.UnitList)+"}");
+ }
+
+ public ObservableCollection SelectionList //ObservableCollection这是一个类,需引用(using System.Collections.ObjectModel)
+
+ {
+
+ get { return _selectionList; }
+
+ set { _selectionList = value; }
+
+ }
+
+
+ private ObservableCollection _selectionList = new ObservableCollection(); //这个是实现的重要一步
+
+ /* private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
+ {
+ var cb = (sender as System.Windows.Controls.ComboBox);
+ if (cb == null || cb.Tag == null) return;
+ int idx = int.Parse(cb.Tag.ToString());
+ // var bindDataGridDatas = this.Grid_RRODUCT.ItemsSource as BindDataGridData[];//成员变量和这里转换都可以。
+ // bindDataGridDatas[idx].UnitStr = (string)cb.SelectedItem;//手动保存到数据结构
+ // bindDataGridDatas[idx].UpdateKBValue(); //联动CoefK值
+ }
+
+ public event PropertyChangedEventHandler PropertyChanged;
+
+ private void PropertiesC([CallerMemberName] string propertyName = "")
+ {
+ this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
+ }
+
+ public int Idx { get; set; } = 0;
+
+ string unitstr = "Pa";
+
+ public string UnitStr
+ {
+ get
+ {
+ return this.unitstr;
+ }
+ set
+ {
+ this.unitstr = value;
+ this.PropertiesC();
+ }
+ }
+
+ public string[] UnitList { get; set; } = new string[] { "Pa", "kPa", "MPa" };
+
+ public static readonly float[][] KBList = new float[][] { new float[] { 1, 1 }, new float[] { 1000, 2 }, new float[] { 1000000, 3 } };
+
+ float coefK { get; set; } = 1f;
+
+ public float CoefK
+ {
+ get
+ {
+ return this.coefK;
+ }
+ set
+ {
+ this.coefK = value;
+ this.PropertiesC();
+ }
+ }
+
+ public void UpdateKBValue()
+ {
+ int idx = -1;
+ for (int j = 0; j < this.UnitList.Length; j++)
+ {
+ if (this.UnitList[j] == this.unitstr)
+ {
+ idx = j; break;
+ }
+ }
+ if (idx == -1) return;
+ //throw new System.Exception("no Unit in UnitList: unit " + this.UnitStr + " UnitList {" + string.Join(", ", this.UnitList)+"}");
- //this.CoefK = BindDataGridData.KBList[idx][0];
- }*/
+ //this.CoefK = BindDataGridData.KBList[idx][0];
+ }*/
@@ -520,7 +590,7 @@ namespace formula_manage
Procedures_N.Text = "1";
Procedures_P.Text = "1";
- // RecipedataTable = RRODUCTdataTable;
+ RecipedataTable = RRODUCTdataTable;
}
private void Button_NewOrder(object sender, RoutedEventArgs e) //新料单按钮
diff --git a/ViewModel/MainWindowViewModel.cs b/ViewModel/MainWindowViewModel.cs
index 91b7331..cd77a7f 100644
--- a/ViewModel/MainWindowViewModel.cs
+++ b/ViewModel/MainWindowViewModel.cs
@@ -1,25 +1,96 @@
using formula_manage.SQLModels;
+using formula_manage.ViewModel;
using formula_manage.Windows;
using GalaSoft.MvvmLight;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
+using System.ComponentModel;
+using System.Data;
+using System.Data.SqlClient;
using System.Linq;
+using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Threading;
+
namespace formula_manage.ViewModel
{
- ///
- /// RRODUCTiewModel
- ///
- public class MainWindowViewModel : ViewModelBase
+///
+/// RRODUCTiewModel
+///
+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()
{
+ sql_();
+
+
BarCollection = new ObservableCollection
{
new BarModel { Id = 1, Name = "Bar 1", },
@@ -35,9 +106,10 @@ namespace formula_manage.ViewModel
};
}
-
+
public ObservableCollection BarCollection { get; set; }
public ObservableCollection FooCollection { get; set; }
+
}
public class FooViewModel : ViewModelBase