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

19
MainWindow.xaml

@ -9,11 +9,8 @@
DataContext="{Binding Source={StaticResource Locator}, Path=Main}"
BorderBrush="White" Background="#FFE0E0E0">
<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>
<Grid>
<Menu IsTabStop="False">
<MenuItem x:Name="tab" Header="_文件" FontSize="16" Focusable ="False" >
@ -165,10 +162,15 @@
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<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}"
BorderBrush="{x:Null}" Background="{x:Null}" IsEditable="True" KeyDown="CP_PRODUCT_CODE_KeyUp"
>
</ComboBox>
@ -195,7 +197,10 @@
<DataGridTemplateColumn Header="原料名称" Width="200" MaxWidth="400" MinWidth="100" CellStyle="{StaticResource CellStyle}">
<DataGridTemplateColumn.CellTemplate>
<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>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

120
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<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; }
// this.Product.DataContext
// this.DataContext = STUFFdataTable;
}
private ObservableCollection<string> _selectionList = new ObservableCollection<string>(); //这个是实现的重要一步
/* 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)
{
var cb = (sender as System.Windows.Controls.ComboBox);

94
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<BarModel>
{
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<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, },
};*/
FooCollection = new ObservableCollection<FooViewModel>
/* 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 FooViewModel{ Id = 1, },
new FooViewModel{ Id = 2, },
new FooViewModel{ Id = 3, },
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
{
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;
}
}
/// <summary>
/// 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="代码"
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"
InputMethod.IsInputMethodEnabled="False"/>
<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();
}
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);//生效配置读取
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();//定位第列
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(); //执行语句

1
packages.config

@ -5,4 +5,5 @@
<package id="ModernUI.WPF" version="1.0.9" 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="System.ObjectModel" version="4.3.0" targetFramework="net46" />
</packages>
Loading…
Cancel
Save