diff --git a/MainWindow.xaml b/MainWindow.xaml index 9333017..10aac5c 100644 --- a/MainWindow.xaml +++ b/MainWindow.xaml @@ -9,11 +9,8 @@ DataContext="{Binding Source={StaticResource Locator}, Path=Main}" BorderBrush="White" Background="#FFE0E0E0"> - - - + - @@ -165,10 +162,15 @@ @@ -195,7 +197,10 @@ - + diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index 9d628ea..cdbfc31 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -1,5 +1,6 @@ using formula_manage.Windows; using System; +using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; @@ -122,7 +123,7 @@ namespace formula_manage Grid_RRODUCT.ItemsSource = RRODUCTdataTable.DefaultView; - DataView defaultView = MACHINEdataTable.DefaultView; + // DataContext defaultView = MACHINEdataTable.DefaultView; // UnitList = defaultView; @@ -138,67 +139,70 @@ namespace formula_manage /* 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 pair in gunNameTypeDic) - { - if (pair.ToString().Equals(value)) //对比键值对 - { - selectedIndex = pair.Key; - } - } - G_TypeNameDicNo = selectedIndex; - } - } - - private Dictionary gunNameTypeDic; - public Dictionary GunNameTypeDic - { - get - { - return gunNameTypeDic; - } - } - - public ObservableCollection SelectionList //ObservableCollection这是一个类,需引用(using System.Collections.ObjectModel) - - { - - get { return _selectionList; } - - set { _selectionList = value; } - + // this.Product.DataContext + // this.DataContext = STUFFdataTable; } + - private ObservableCollection _selectionList = new ObservableCollection(); //这个是实现的重要一步 + /* 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 pair in gunNameTypeDic) + { + if (pair.ToString().Equals(value)) //对比键值对 + { + selectedIndex = pair.Key; + } + } + G_TypeNameDicNo = selectedIndex; + } + } + + private Dictionary gunNameTypeDic; + public Dictionary GunNameTypeDic + { + get + { + return gunNameTypeDic; + } + } + + 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); diff --git a/ViewModel/MainWindowViewModel.cs b/ViewModel/MainWindowViewModel.cs index cd77a7f..0b8849b 100644 --- a/ViewModel/MainWindowViewModel.cs +++ b/ViewModel/MainWindowViewModel.cs @@ -3,15 +3,18 @@ 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; @@ -72,64 +75,97 @@ public class MainWindowViewModel : ViewModelBase Dissolve_data.Fill(DissolvedataTable); //machine查询结果存入缓存 conn_SC.Close(); //关闭连接 - //DataGridStuff.ItemsSource = dataTable.DefaultView; //数据加入表格 } catch (Exception) { System.Windows.MessageBox.Show("请求原料信息失败,检查连接"); return; } - DataView defaultView = MACHINEdataTable.DefaultView; + + // IEnumerable STUFFdata = STUFFdataTable.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", }, - new BarModel { Id = 2, Name = "Bar 2", }, - new BarModel { Id = 3, Name = "Bar 3", }, - }; + // public ObservableCollection (System.Collections.Generic.List list); + // BarCollection = (ObservableCollection)STUFFdataTable.AsDataView(); + // var qwe = STUFFdataTable.DefaultView; + var product = STUFFdataTable.DefaultView; + + + // BarCollection = (ObservableCollection)STUFFdata; + + + + /* BarCollection = new ObservableCollection + { + new Product { ProductCode = "Bar 10", }, + new Product { ProductCode = "Bar 20", }, + new Product { ProductCode = "Bar 30", }, + };*/ + + /* FooCollection = new ObservableCollection + { + new FooViewModel{ Id = 1, }, + new FooViewModel{ Id = 2, }, + new FooViewModel{ Id = 3, }, + + };*/ + + - FooCollection = new ObservableCollection + + + /* product = new ObservableCollection; + foreach (DataRow row in STUFFdataTable.Rows) + { + product.Add(new Product((int)row[0], (string)row[1], (string)row[2])); + + } */ + + _product = new ObservableCollection { - new FooViewModel{ Id = 1, }, - new FooViewModel{ Id = 2, }, - new FooViewModel{ Id = 3, }, + new Product{ ProductCode= "132",ProductName= "123", ProductType= 12,Concentration= 12} }; + } - - public ObservableCollection BarCollection { get; set; } - public ObservableCollection FooCollection { get; set; } + + + + // private ObservableCollection _selectionList = new ObservableCollection(); //这个是实现的重要一步 + + public ObservableCollection _product { get; set; } + // public ObservableCollection FooCollection { get; set; } } - public class FooViewModel : ViewModelBase - { - private BarModel _bar; + /* public class FooViewModel : ViewModelBase + { + private BarModel _bar; - public int Id { get; set; } - public BarModel Bar { get => _bar; set => Set(ref _bar, value); } - } + public int Id { get; set; } + public BarModel Bar { get => _bar; set => Set(ref _bar, value); } + }*/ - public class BarModel + public class Product { - public int Id { get; set; } - public string Name { get; set; } + 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 Name; + return ProductCode; } - + } /// /// StuffViewModeldl @@ -150,5 +186,5 @@ public class MainWindowViewModel : ViewModelBase }*/ - } + } diff --git a/Windows/Dissolve.xaml b/Windows/Dissolve.xaml index 82a70f5..1eedeab 100644 --- a/Windows/Dissolve.xaml +++ b/Windows/Dissolve.xaml @@ -78,7 +78,7 @@ - (this.DataGridEquipment_LoadingRow);//生成序列号 @@ -105,7 +105,7 @@ namespace formula_manage.Windows { /*定位选中行及指定列单元格文本信息*/ Code.Text = (DatagridDissolve.Columns[1].GetCellContent(DatagridDissolve.Items[rownum]) as TextBlock).Text.Trim();//定位第列 - Name.Text = (DatagridDissolve.Columns[2].GetCellContent(DatagridDissolve.Items[rownum]) as TextBlock).Text.Trim();// + name.Text = (DatagridDissolve.Columns[2].GetCellContent(DatagridDissolve.Items[rownum]) as TextBlock).Text.Trim();// ion.Text = (DatagridDissolve.Columns[3].GetCellContent(DatagridDissolve.Items[rownum]) as TextBlock).Text.Trim();// min.Text = (DatagridDissolve.Columns[4].GetCellContent(DatagridDissolve.Items[rownum]) as TextBlock).Text.Trim();// max.Text = (DatagridDissolve.Columns[5].GetCellContent(DatagridDissolve.Items[rownum]) as TextBlock).Text.Trim();// @@ -127,7 +127,7 @@ namespace formula_manage.Windows string Dissolve_sql; int int_ion = 0; - if ((Name.Text == "") ||(Code.Text == "")) + if ((name.Text == "") ||(Code.Text == "")) { System.Windows.MessageBox.Show("请输入代码或名称"); return; @@ -173,7 +173,7 @@ namespace formula_manage.Windows if (count == 0) { Dissolve_sql = string.Format("INSERT INTO[Dispensing].[dbo].[Dissolve](DissolveCode ,DissolveName ,REMARK ,MaterialType ,WeightMIN ,WeightMAX) " + - "VALUES ('" + Code.Text + "','" + Name.Text + "','" + Remark.Text + "','" + int_ion + "','"+ min.Text + "','" + max.Text + "')"); + "VALUES ('" + Code.Text + "','" + name.Text + "','" + Remark.Text + "','" + int_ion + "','"+ min.Text + "','" + max.Text + "')"); await conn_SC.OpenAsync(); //打开数据连接 SqlCommand INSERT_cmd = new SqlCommand(Dissolve_sql, conn_SC); int sql_in = INSERT_cmd.ExecuteNonQuery(); //执行语句 @@ -190,7 +190,7 @@ namespace formula_manage.Windows } else { - Dissolve_sql = string.Format("UPDATE [dbo].[Dissolve] SET DissolveName ='" + Name.Text + "',REMARK='" + Remark.Text + "',MaterialType='" + int_ion + "',WeightMIN='" + min.Text + "',WeightMAX='" + max.Text + "' Where DissolveCode ='" + Code.Text + "'"); + Dissolve_sql = string.Format("UPDATE [dbo].[Dissolve] SET DissolveName ='" + name.Text + "',REMARK='" + Remark.Text + "',MaterialType='" + int_ion + "',WeightMIN='" + min.Text + "',WeightMAX='" + max.Text + "' Where DissolveCode ='" + Code.Text + "'"); await conn_SC.OpenAsync(); //打开数据连接 SqlCommand INSERT_cmd = new SqlCommand(Dissolve_sql, conn_SC); int sql_in = INSERT_cmd.ExecuteNonQuery(); //执行语句 diff --git a/packages.config b/packages.config index f7e5d14..abe5b98 100644 --- a/packages.config +++ b/packages.config @@ -5,4 +5,5 @@ + \ No newline at end of file