You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
190 lines
6.8 KiB
190 lines
6.8 KiB
using formula_manage.SQLModels;
|
|
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;
|
|
|
|
|
|
namespace formula_manage.ViewModel
|
|
{
|
|
///<Summary>
|
|
/// RRODUCTiewModel
|
|
///</Summary>
|
|
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(); //关闭连接
|
|
}
|
|
catch (Exception)
|
|
{
|
|
System.Windows.MessageBox.Show("请求原料信息失败,检查连接");
|
|
return;
|
|
}
|
|
|
|
// IEnumerable STUFFdata = STUFFdataTable.DefaultView;
|
|
// Machine.ItemsSource = MACHINEdataTable.DefaultView; // MACHINEdataTable数据集传递到ComboBox:machine
|
|
// Workflow.ItemsSource = DissolvedataTable.DefaultView; // DissolvedataTable数据集传递到ComboBox:Workflow
|
|
}
|
|
|
|
|
|
|
|
public MainWindowViewModel()
|
|
{
|
|
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<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, },
|
|
|
|
};*/
|
|
|
|
|
|
|
|
|
|
|
|
/* 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}
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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 int Id { get; set; }
|
|
public BarModel Bar { get => _bar; set => Set(ref _bar, value); }
|
|
}*/
|
|
|
|
public class Product
|
|
{
|
|
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 ProductCode;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// StuffViewModeldl
|
|
/// </summary>
|
|
/* public RRODUCTiewModel()
|
|
{
|
|
//products = new ProductProvider().Select();
|
|
DispatcherTimer timer = new DispatcherTimer//初始化循环,每0.5秒调用一次Tick_Event
|
|
{
|
|
Interval = TimeSpan.FromSeconds(0.1)
|
|
};
|
|
timer.Tick += Tick_Event;
|
|
timer.Start();
|
|
}
|
|
|
|
void Tick_Event(object sender, EventArgs e)//Tick_Event周期执行事件
|
|
{
|
|
|
|
}*/
|
|
|
|
|
|
}
|
|
|