sc 2 years ago
parent
commit
c884ef0c34
  1. 17
      MainWindow.xaml
  2. 12
      MainWindow.xaml.cs
  3. 72
      ViewModel/MainWindowViewModel.cs
  4. 2
      Windows/Dissolve.xaml
  5. 10
      Windows/Dissolve.xaml.cs
  6. 1
      packages.config

17
MainWindow.xaml

@ -9,11 +9,8 @@
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="defaultView" Source="{Binding Path=defaultView}"/>
</Window.Resources>
</Window.Resources>
<Grid> <Grid>
<Menu IsTabStop="False"> <Menu IsTabStop="False">
<MenuItem x:Name="tab" Header="_文件" FontSize="16" Focusable ="False" > <MenuItem x:Name="tab" Header="_文件" FontSize="16" Focusable ="False" >
@ -165,10 +162,15 @@
<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}}}" ItemsSource="{Binding DataContext._product , RelativeSource={RelativeSource AncestorType={x:Type Window}}}"
DisplayMemberPath="ProductCode"
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"
> >
</ComboBox> </ComboBox>
@ -195,7 +197,10 @@
<DataGridTemplateColumn Header="原料名称" Width="200" MaxWidth="400" MinWidth="100" CellStyle="{StaticResource CellStyle}"> <DataGridTemplateColumn Header="原料名称" Width="200" MaxWidth="400" MinWidth="100" CellStyle="{StaticResource CellStyle}">
<DataGridTemplateColumn.CellTemplate> <DataGridTemplateColumn.CellTemplate>
<DataTemplate> <DataTemplate>
<ComboBox x:Name="CP_PRODUCT_NAME" BorderThickness="0,0,0,0" Text="{Binding PRODUCT_NAME}" BorderBrush="{x:Null}" Background="{x:Null}" IsEditable="True" IsReadOnly="True" Focusable="True" IsTabStop="False"/> <ComboBox x:Name="CP_PRODUCT_NAME" BorderThickness="0,0,0,0"
ItemsSource="{Binding DataContext._product , RelativeSource={RelativeSource AncestorType={x:Type Window}}}"
DisplayMemberPath="ProductName"
Text="{Binding PRODUCT_NAME}" BorderBrush="{x:Null}" Background="{x:Null}" IsEditable="True" IsReadOnly="True" Focusable="True" IsTabStop="False"/>
</DataTemplate> </DataTemplate>
</DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn> </DataGridTemplateColumn>

12
MainWindow.xaml.cs

@ -1,5 +1,6 @@
using formula_manage.Windows; using formula_manage.Windows;
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.ComponentModel; using System.ComponentModel;
@ -122,7 +123,7 @@ namespace formula_manage
Grid_RRODUCT.ItemsSource = RRODUCTdataTable.DefaultView; Grid_RRODUCT.ItemsSource = RRODUCTdataTable.DefaultView;
DataView defaultView = MACHINEdataTable.DefaultView; // DataContext defaultView = MACHINEdataTable.DefaultView;
// UnitList = defaultView; // UnitList = defaultView;
@ -138,11 +139,14 @@ namespace formula_manage
/* SelectionList.Add("Name1"); /* SelectionList.Add("Name1");
SelectionList.Add("Name2");*/ SelectionList.Add("Name2");*/
// this.Product.DataContext
// this.DataContext = STUFFdataTable;
}
}
public string[] UnitList { get; set; }
/* public string[] UnitList { get; set; }
private int g_TypeNameDicNo =123; //枪型号名 private int g_TypeNameDicNo =123; //枪型号名
@ -198,7 +202,7 @@ namespace formula_manage
private ObservableCollection<string> _selectionList = new ObservableCollection<string>(); //这个是实现的重要一步 private ObservableCollection<string> _selectionList = new ObservableCollection<string>(); //这个是实现的重要一步
*/
/* private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) /* private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{ {
var cb = (sender as System.Windows.Controls.ComboBox); var cb = (sender as System.Windows.Controls.ComboBox);

72
ViewModel/MainWindowViewModel.cs

@ -3,15 +3,18 @@ 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;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.ComponentModel; using System.ComponentModel;
using System.Data; using System.Data;
using System.Data.SqlClient; using System.Data.SqlClient;
using System.Linq; using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Threading; using System.Windows.Threading;
@ -72,14 +75,14 @@ public class MainWindowViewModel : ViewModelBase
Dissolve_data.Fill(DissolvedataTable); //machine查询结果存入缓存 Dissolve_data.Fill(DissolvedataTable); //machine查询结果存入缓存
conn_SC.Close(); //关闭连接 conn_SC.Close(); //关闭连接
//DataGridStuff.ItemsSource = dataTable.DefaultView; //数据加入表格
} }
catch (Exception) catch (Exception)
{ {
System.Windows.MessageBox.Show("请求原料信息失败,检查连接"); System.Windows.MessageBox.Show("请求原料信息失败,检查连接");
return; return;
} }
DataView defaultView = MACHINEdataTable.DefaultView;
// IEnumerable STUFFdata = STUFFdataTable.DefaultView;
// Machine.ItemsSource = MACHINEdataTable.DefaultView; // MACHINEdataTable数据集传递到ComboBox:machine // Machine.ItemsSource = MACHINEdataTable.DefaultView; // MACHINEdataTable数据集传递到ComboBox:machine
// Workflow.ItemsSource = DissolvedataTable.DefaultView; // DissolvedataTable数据集传递到ComboBox:Workflow // Workflow.ItemsSource = DissolvedataTable.DefaultView; // DissolvedataTable数据集传递到ComboBox:Workflow
} }
@ -90,46 +93,79 @@ public class MainWindowViewModel : ViewModelBase
{ {
sql_(); 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<BarModel>
/* BarCollection = new ObservableCollection<Product>
{ {
new BarModel { Id = 1, Name = "Bar 1", }, new Product { ProductCode = "Bar 10", },
new BarModel { Id = 2, Name = "Bar 2", }, new Product { ProductCode = "Bar 20", },
new BarModel { Id = 3, Name = "Bar 3", }, new Product { ProductCode = "Bar 30", },
}; };*/
FooCollection = new ObservableCollection<FooViewModel> /* FooCollection = new ObservableCollection<FooViewModel>
{ {
new FooViewModel{ Id = 1, }, new FooViewModel{ Id = 1, },
new FooViewModel{ Id = 2, }, new FooViewModel{ Id = 2, },
new FooViewModel{ Id = 3, }, 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>
{
new Product{ ProductCode= "132",ProductName= "123", ProductType= 12,Concentration= 12}
}; };
} }
public ObservableCollection<BarModel> BarCollection { get; set; }
public ObservableCollection<FooViewModel> FooCollection { get; set; }
// private ObservableCollection<string> _selectionList = new ObservableCollection<string>(); //这个是实现的重要一步
public ObservableCollection<Product> _product { get; set; }
// public ObservableCollection<FooViewModel> FooCollection { get; set; }
} }
public class FooViewModel : ViewModelBase /* public class FooViewModel : ViewModelBase
{ {
private BarModel _bar; private BarModel _bar;
public int Id { get; set; } public int Id { get; set; }
public BarModel Bar { get => _bar; set => Set(ref _bar, value); } public BarModel Bar { get => _bar; set => Set(ref _bar, value); }
} }*/
public class BarModel public class Product
{ {
public int Id { get; set; } public string ProductCode { get; set; }
public string Name { get; set; } public string ProductName { get; set; }
public int ProductType { get; set; }
public int Concentration { get; set; }
public override string ToString() public override string ToString()
{ {
return Name; return ProductCode;
}
} }
/// <summary> /// <summary>
/// StuffViewModeldl /// StuffViewModeldl
@ -150,5 +186,5 @@ public class MainWindowViewModel : ViewModelBase
}*/ }*/
}
} }

2
Windows/Dissolve.xaml

@ -78,7 +78,7 @@
<TextBlock HorizontalAlignment="Left" Height="30" Margin="15,0,0,100" TextWrapping="Wrap" Text="代码" <TextBlock HorizontalAlignment="Left" Height="30" Margin="15,0,0,100" TextWrapping="Wrap" Text="代码"
VerticalAlignment="Bottom" Width="40" FontSize="20"/> VerticalAlignment="Bottom" Width="40" FontSize="20"/>
<!--名称--> <!--名称-->
<TextBox x:Name="Name" HorizontalAlignment="Left" Height="30" Margin="255,0,0,100" Text="" <TextBox x:Name="name" HorizontalAlignment="Left" Height="30" Margin="255,0,0,100" Text=""
VerticalAlignment="Bottom" Width="120" FontSize="22" MaxLines="1" MaxLength="25" VerticalAlignment="Bottom" Width="120" FontSize="22" MaxLines="1" MaxLength="25"
InputMethod.IsInputMethodEnabled="False"/> InputMethod.IsInputMethodEnabled="False"/>
<TextBlock HorizontalAlignment="Left" Height="30" Margin="205,0,0,100" TextWrapping="Wrap" Text="名称" <TextBlock HorizontalAlignment="Left" Height="30" Margin="205,0,0,100" TextWrapping="Wrap" Text="名称"

10
Windows/Dissolve.xaml.cs

@ -41,7 +41,7 @@ namespace formula_manage.Windows
InitializeComponent(); InitializeComponent();
} }
private async void Dissolve_Loaded(object sender, RoutedEventArgs e)//打开页面执行 private void Dissolve_Loaded(object sender, RoutedEventArgs e)//打开页面执行
{ {
UserClass.IniFile.IniFiles Configini = new UserClass.IniFile.IniFiles(INIPath);//生效配置读取 UserClass.IniFile.IniFiles Configini = new UserClass.IniFile.IniFiles(INIPath);//生效配置读取
this.DatagridDissolve.LoadingRow += new EventHandler<DataGridRowEventArgs>(this.DataGridEquipment_LoadingRow);//生成序列号 this.DatagridDissolve.LoadingRow += new EventHandler<DataGridRowEventArgs>(this.DataGridEquipment_LoadingRow);//生成序列号
@ -105,7 +105,7 @@ namespace formula_manage.Windows
{ {
/*定位选中行及指定列单元格文本信息*/ /*定位选中行及指定列单元格文本信息*/
Code.Text = (DatagridDissolve.Columns[1].GetCellContent(DatagridDissolve.Items[rownum]) as TextBlock).Text.Trim();//定位第列 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();// 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();// 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();// max.Text = (DatagridDissolve.Columns[5].GetCellContent(DatagridDissolve.Items[rownum]) as TextBlock).Text.Trim();//
@ -127,7 +127,7 @@ namespace formula_manage.Windows
string Dissolve_sql; string Dissolve_sql;
int int_ion = 0; int int_ion = 0;
if ((Name.Text == "") ||(Code.Text == "")) if ((name.Text == "") ||(Code.Text == ""))
{ {
System.Windows.MessageBox.Show("请输入代码或名称"); System.Windows.MessageBox.Show("请输入代码或名称");
return; return;
@ -173,7 +173,7 @@ namespace formula_manage.Windows
if (count == 0) if (count == 0)
{ {
Dissolve_sql = string.Format("INSERT INTO[Dispensing].[dbo].[Dissolve](DissolveCode ,DissolveName ,REMARK ,MaterialType ,WeightMIN ,WeightMAX) " + 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(); //打开数据连接 await conn_SC.OpenAsync(); //打开数据连接
SqlCommand INSERT_cmd = new SqlCommand(Dissolve_sql, conn_SC); SqlCommand INSERT_cmd = new SqlCommand(Dissolve_sql, conn_SC);
int sql_in = INSERT_cmd.ExecuteNonQuery(); //执行语句 int sql_in = INSERT_cmd.ExecuteNonQuery(); //执行语句
@ -190,7 +190,7 @@ namespace formula_manage.Windows
} }
else 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(); //打开数据连接 await conn_SC.OpenAsync(); //打开数据连接
SqlCommand INSERT_cmd = new SqlCommand(Dissolve_sql, conn_SC); SqlCommand INSERT_cmd = new SqlCommand(Dissolve_sql, conn_SC);
int sql_in = INSERT_cmd.ExecuteNonQuery(); //执行语句 int sql_in = INSERT_cmd.ExecuteNonQuery(); //执行语句

1
packages.config

@ -5,4 +5,5 @@
<package id="ModernUI.WPF" version="1.0.9" targetFramework="net46" /> <package id="ModernUI.WPF" version="1.0.9" targetFramework="net46" />
<package id="MvvmLightLibs" version="5.4.1.1" targetFramework="net46" /> <package id="MvvmLightLibs" version="5.4.1.1" targetFramework="net46" />
<package id="SamOatesGames.ModernUI.Xceed.Toolkit" version="1.0.1905191936" targetFramework="net46" /> <package id="SamOatesGames.ModernUI.Xceed.Toolkit" version="1.0.1905191936" targetFramework="net46" />
<package id="System.ObjectModel" version="4.3.0" targetFramework="net46" />
</packages> </packages>
Loading…
Cancel
Save