sc 2 years ago
parent
commit
92e5e0e268
  1. 602
      MainWindow.xaml.cs
  2. 588
      ViewModel/MainWindowViewModel.cs

602
MainWindow.xaml.cs

@ -1,7 +1,4 @@
using formula_manage.SQLModels;
using formula_manage.ViewModel;
using formula_manage.Windows;
using GalaSoft.MvvmLight;
using formula_manage.Windows;
using System;
using System.Collections;
using System.Collections.Generic;
@ -9,48 +6,47 @@ using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
using System.Xml.Linq;
using formula_manage.ViewModel;
using Xceed.Wpf.Toolkit.PropertyGrid.Attributes;
using static System.Net.Mime.MediaTypeNames;
using formula_manage.UserClass;
namespace formula_manage.ViewModel
namespace formula_manage
{
public class ViewModelBase : INotifyPropertyChanged
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
if (this.PropertyChanged != null)
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
///<Summary>
///
///
///</Summary>
///
public class MainWindowViewModel : ViewModelBase
{
DataTable DissolvedataTable = new DataTable(); //建立Dissolve缓存
DataTable STUFFdataTable = new DataTable(); //建立STUFF缓存
DataTable MACHINEdataTable = new DataTable(); //建立Machine缓存
bool quit = false;
// 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"; //配置文件路径
public string sys_Time; //显示系统时间
public string Sys_Time //通知UI控件参数改变
{
get { return sys_Time; }
set { sys_Time = value; OnPropertyChanged("Sys_Time"); }
}
string TEXT_SQLIP;
string TEXT_SQLNAME;
@ -58,8 +54,76 @@ namespace formula_manage.ViewModel
string TEXT_SQLUSER;
string TEXT_SQLPASWOR;
string Connstr_SC;
int ID_N = 1;
public MainWindow()
{
DataContext = new MainWindowViewModel();
WindowStartupLocation = WindowStartupLocation.CenterScreen;
InitializeComponent();
this.Closing += Window_Closing; //添加窗口关闭事件
USER.Text = App.USER_Purview;
RecipedataTable.Columns.Add("DYELOT", typeof(int));
RecipedataTable.Columns.Add("STEP", typeof(string));
RecipedataTable.Columns.Add("PRODUCT_CODE", typeof(string));
RecipedataTable.Columns.Add("CONC", typeof(string));
RecipedataTable.Columns.Add("SHIFT", typeof(string));
RecipedataTable.Columns.Add("PRODUCT_NAME", typeof(string));
RecipedataTable.Columns.Add("TARGET_WT", typeof(float));
RecipedataTable.Columns.Add("UNIT", typeof(string));
RecipedataTable.Columns.Add("REMARK", typeof(string));
RRODUCTdataTable.Columns.Add("ID", typeof(int));
RRODUCTdataTable.Columns.Add("STEP", typeof(string));
RRODUCTdataTable.Columns.Add("PRODUCT_CODE", typeof(string));
RRODUCTdataTable.Columns.Add("CONC", typeof(string));
RRODUCTdataTable.Columns.Add("SHIFT", typeof(string));
RRODUCTdataTable.Columns.Add("PRODUCT_NAME", typeof(string));
RRODUCTdataTable.Columns.Add("TARGET_WT", typeof(float));
RRODUCTdataTable.Columns.Add("UNIT", typeof(string));
RRODUCTdataTable.Columns.Add("REMARK", typeof(string));
if (USER.Text == "ENGINEER") //工程师允许功能
{
_SQL.IsEnabled = true;
_SQLBAK.IsEnabled = true;
_SOFTWARE_SET.IsEnabled = true;
_USER_SET.IsEnabled = true;
_RECIPE.IsEnabled = true;
_PROCESS.IsEnabled = true;
_WORKFLOW.IsEnabled = true;
_MAC_SET.IsEnabled = true;
_STUFF.IsEnabled = true;
_fabric.IsEnabled = true;
_variety.IsEnabled = true;
_client.IsEnabled = true;
_color.IsEnabled = true;
_statistics.IsEnabled = true;
}
sql_();
Permissions_(); //权限管理
DataRow row = RRODUCTdataTable.NewRow(); //ID列
row["ID"] = ID_N;
row["STEP"] = Procedures_P.Text;
RRODUCTdataTable.Rows.Add(row);
/* for (ID_N = 2; ID_N <= 64; ID_N++)
{
row = RRODUCTdataTable.NewRow();
row["ID"] = ID_N;
// row["STEP"] = Procedures_P.Text;
RRODUCTdataTable.Rows.Add(row);
}*/
Grid_RRODUCT.ItemsSource = RRODUCTdataTable.DefaultView;
}
private async void Sql_()
private void sql_()
{
UserClass.IniFile.IniFiles Configini = new UserClass.IniFile.IniFiles(INIPath);//生效配置读取
TEXT_SQLIP = Configini.IniReadvalue("SQL_SERVER", "SQL1"); //读配置文件
@ -75,151 +139,405 @@ namespace formula_manage.ViewModel
{
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 ,Capacity ,Volume FROM [Dispensing].[dbo].[MACHINE] order by Name asc";//查询machine语句
string Dissolve_sql = "SELECT DissolveCode ,DissolveName ,MaterialType ,WeightMIN ,WeightMAX REMARK FROM [Dispensing].[dbo].[Dissolve]";//查询语句
private async void Permissions_()
{
DataTable logindataTable = new DataTable(); //建立login缓存
SqlConnection conn_SC = new SqlConnection(Connstr_SC);
string user_sql = "SELECT UserCode ,PassWord ,UserSetup ,Capacity ,GROUP_CODE ,Note FROM [Dispensing].[dbo].[UserAccount] WHERE Capacity != 0";//查询语句
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); //Dissolve_data查询结果存入缓存
conn_SC.Close(); //关闭连接
SqlDataAdapter Stuff_data = new SqlDataAdapter(user_sql, Connstr_SC); //查询
Stuff_data.Fill(logindataTable); //查询结果存入缓存
conn_SC.Close(); //关闭连接
}
catch (Exception)
{
System.Windows.MessageBox.Show("请求原料信息失败,检查连接");
System.Windows.MessageBox.Show("请求信息失败,检查连接");
return;
}
}
public MainWindowViewModel()
{
CountDown();
Sql_();
string var_POWERUSER = "[UserCode]='" + USER.Text + "' and [GROUP_CODE] ='POWERUSER '"; //查询字符
string var_CHIEF = "[UserCode]='" + USER.Text + "' and [GROUP_CODE] ='CHIEF '"; //查询字符
stuff_Product = ToObservableCollection<Product>(STUFFdataTable); //stuff_Product表转换
mac_Machine = ToObservableCollection<Machine>(MACHINEdataTable);
flow_Workflow = ToObservableCollection<Workflow>(DissolvedataTable);
var CHIEF = logindataTable.Select(var_CHIEF).FirstOrDefault(); //查询账号信息是否正确,不正确返回null
if (CHIEF != null)
{
_SQL.IsEnabled = true;
_SQLBAK.IsEnabled = true;
_SOFTWARE_SET.IsEnabled = true;
_USER_SET.IsEnabled = true;
_RECIPE.IsEnabled = true;
_PROCESS.IsEnabled = true;
_WORKFLOW.IsEnabled = true;
_MAC_SET.IsEnabled = true;
_STUFF.IsEnabled = true;
_fabric.IsEnabled = true;
_variety.IsEnabled = true;
_client.IsEnabled = true;
_color.IsEnabled = true;
_statistics.IsEnabled = true;
}
else
{
var POWERUSER = logindataTable.Select(var_POWERUSER).FirstOrDefault(); //查询账号信息是否正确,不正确返回null
if (POWERUSER != null)
{
_SQLBAK.IsEnabled = true;
_RECIPE.IsEnabled = true;
_PROCESS.IsEnabled = true;
_WORKFLOW.IsEnabled = true;
_MAC_SET.IsEnabled = true;
_STUFF.IsEnabled = true;
_fabric.IsEnabled = true;
_variety.IsEnabled = true;
_client.IsEnabled = true;
_color.IsEnabled = true;
_statistics.IsEnabled = true;
}
}
}
public ObservableCollection<Product> stuff_Product { get; set; } //stuff_Product动态表实力化
public ObservableCollection<Machine> mac_Machine { get; set; } //mac_Machine动态表实力化
public ObservableCollection<Workflow> flow_Workflow { get; set; } //Dissolve动态表实力化
public ObservableCollection<T> ToObservableCollection<T>(DataTable dt) where T : class, new() //DataTable FOR ObservableCollection转换器
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) //窗口关闭事件
{
Type t = typeof(T);
PropertyInfo[] propertys = t.GetProperties();
ObservableCollection<T> lst = new ObservableCollection<T>();
string typeName = string.Empty;
foreach (DataRow dr in dt.Rows)
string logpath = System.Environment.CurrentDirectory + "\\Log";//日志文件目录
string logPath = "" + System.Environment.CurrentDirectory + "\\Log\\Log.txt";//日志文件
string Log_time = "[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "]:";
if (!quit)
{
T entity = new T();
foreach (PropertyInfo pi in propertys)
MessageBoxResult result = System.Windows.MessageBox.Show("您确定要退出吗?", "SUNLIGHT", MessageBoxButton.OKCancel, MessageBoxImage.None, MessageBoxResult.Cancel);
if (result == MessageBoxResult.Cancel) //判断是否确认
{
typeName = pi.Name;
if (dt.Columns.Contains(typeName))
{
if (!pi.CanWrite) continue;
object value = dr[typeName];
if (value == DBNull.Value) continue;
if (pi.PropertyType == typeof(string))
{
pi.SetValue(entity, value.ToString(), null);
}
else if (pi.PropertyType == typeof(int) || pi.PropertyType == typeof(int?))
{
pi.SetValue(entity, int.Parse(value.ToString()), null);
}
else if (pi.PropertyType == typeof(DateTime?) || pi.PropertyType == typeof(DateTime))
{
pi.SetValue(entity, DateTime.Parse(value.ToString()), null);
}
else if (pi.PropertyType == typeof(float))
{
pi.SetValue(entity, float.Parse(value.ToString()), null);
}
else if (pi.PropertyType == typeof(double))
{
pi.SetValue(entity, double.Parse(value.ToString()), null);
}
else
{
pi.SetValue(entity, value, null);
}
}
e.Cancel = true; // 中断点击事件
}
lst.Add(entity);
}
return lst;
} //DataTable FOR ObservableCollection转换器
/// <summary>
/// 循环事件设定
/// </summary>
public void CountDown()
System.IO.DirectoryInfo log = new System.IO.DirectoryInfo(@logpath);//生成日志文件目录
FileStream fs = new FileStream(logPath, FileMode.Append, FileAccess.Write);
StreamWriter wr = new StreamWriter(fs);//创建文件
wr.WriteLine(Log_time + "FORMULA_STOP");
wr.Close();
}
private void SearchBox_OnKeyDownd(object sender, System.Windows.Input.KeyEventArgs e) //回车跳转功能
{
DispatcherTimer timer = new DispatcherTimer//初始化循环,每0.5秒调用一次Tick_Event
if (e.Key == Key.Enter)
{
Interval = TimeSpan.FromSeconds(0.5)
};
timer.Tick += Tick_Event;
timer.Start();
UserClass.PressKey.PressKeys(Keys.Tab, false);
UserClass.PressKey.PressKeys(Keys.Tab, true);
}
}
string Prepose; //料单前置
string PreposeT; //料单时间
string PreposeS; //料单序列格式
int PreposeSl;
string str_Prepose;
bool Loginprint;
bool Loginanew;
private void Window_MIN(object sender, RoutedEventArgs e)
{
UserClass.IniFile.IniFiles Configini = new UserClass.IniFile.IniFiles(INIPath);
Loginprint = Boolean.Parse(Configini.IniReadvalue("SOFTWARE_SET", "L2")); //是否立即打印料单
Loginanew = Boolean.Parse(Configini.IniReadvalue("SOFTWARE_SET", "L3")); //是否立即打印料单
Machine.IsReadOnly = Boolean.Parse(Configini.IniReadvalue("SOFTWARE_SET", "L4")); //允许自定义机台
Prepose = Configini.IniReadvalue("SOFTWARE_SET", "T1"); //自定义料单前缀
PreposeT = Configini.IniReadvalue("SOFTWARE_SET", "T2"); //自定义料单时间
PreposeS = Configini.IniReadvalue("SOFTWARE_SET", "T3"); //自定义料单格式
PreposeSl = int.Parse(PreposeS);
//设置定时器
// disTimer.Tick += new EventHandler(DisTimer_Tick);//每一秒执行的方法
// disTimer.Interval = new TimeSpan(10000000); //时间间隔为一秒。
// disTimer.Start();//计时开始
Number_Event();
//Number.Text = Prepose + System.DateTime.Now.ToString(PreposeT); //生成料单号
}
void Tick_Event(object sender, EventArgs e)//Tick_Event周期执行事件
private void Number_Event() //生成料单号事件
{
Sys_Time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
int preposeL = PreposeS.Length;
PreposeSl = PreposeSl + 1;
str_Prepose = String.Format("{0:D" + preposeL + "}", PreposeSl);
Number.Text = Prepose + System.DateTime.Now.ToString(PreposeT) + str_Prepose; //生成料单号
}
}
public class Product //stuff_Product
{
public string ProductCode { get; set; }
public string ProductName { get; set; }
public int ProductType { get; set; }
public int Concentration { get; set; }
private void Tb_KeyPress(object sender, TextCompositionEventArgs e)//输入事件
{
public override string ToString()
//Regex re = new Regex("[^0-9.-]+");
Regex re = new Regex(@"^[0-9]+(.[0-9]{1,3})?$");// 非零的正整数
e.Handled = !re.IsMatch(e.Text);
}
private void Tb_KeyFloating(object sender, TextCompositionEventArgs e)//输入事件
{
return ProductCode;
//Regex re = new Regex("[^0-9.-]+");
Regex re = new Regex(@"^[.][0-9]+$|^[0-9]*[.]{0,1}[0-9]*$");// 非负浮点数
e.Handled = !re.IsMatch(e.Text);
}
}
public class Machine //mac
{
public string Name { get; set; }
public float Volume { get; set; }
public float Capacity { get; set; }
public override string ToString()
private void logout(object sender, RoutedEventArgs e)
{
return Name;
quit = true;
Window window = Window.GetWindow(this);
Login login = new Login();
window.Close();
login.ShowDialog();//实例化并置顶打开登录窗口
}
}
public class Workflow //Dissolve
{
public string DissolveName { get; set; }
public int MaterialType { get; set; }
public int WeightMIN { get; set; }
public int WeightMAX { get; set; }
public override string ToString()
private void SQL(object sender, RoutedEventArgs e)
{
return DissolveName;
System.Windows.MessageBox.Show("进入数据库设置请您明确操作目的及可能需承担的后果", "警告");
Windows.Sql sql = new Windows.Sql();
sql.ShowDialog();//实例化并置顶打开数据库设置窗口
}
}
private void SQLBAK(object sender, RoutedEventArgs e)
{
MessageBoxResult sql_bak = System.Windows.MessageBox.Show("注意此功能仅作用与本地数据库(Dispensing)对于远端数据库的操作可能失败如果需要继续操作单击确定", "SQL", MessageBoxButton.OKCancel, MessageBoxImage.Exclamation); //连接失败提示
if (sql_bak == MessageBoxResult.OK)
{
Windows.SQL_BAK sqlbak = new Windows.SQL_BAK();
sqlbak.ShowDialog();//实例化并置顶打开数据库备份窗口
}
}
private void SOFTWARE_SET(object sender, RoutedEventArgs e)
{
Windows.APP_set APP_set = new Windows.APP_set();
APP_set.ShowDialog();//实例化并置顶打开设置窗口
}
private void USER_SET(object sender, RoutedEventArgs e)
{
Windows.User user_set = new Windows.User();
user_set.ShowDialog();//实例化并置顶打开用户窗口
}
private void HELP(object sender, RoutedEventArgs e)
{
Help help_page = new Help();
help_page.ShowDialog();//实例化并置顶打开信息窗口
}
private void MAC_SET(object sender, RoutedEventArgs e)
{
Windows.Machine mac = new Windows.Machine();
mac.ShowDialog();//实例化并置顶打开设置窗口
}
private void STUFF(object sender, RoutedEventArgs e)
{
Windows.Stuff stuff = new Windows.Stuff();
stuff.ShowDialog();//实例化并置顶打开设置窗口
}
private void RECIPE(object sender, RoutedEventArgs e)
{
}
private void PROCESS(object sender, RoutedEventArgs e)
{
}
private void WORKFLOW(object sender, RoutedEventArgs e)
{
Windows.Dissolve dissolve = new Windows.Dissolve();
dissolve.ShowDialog();//实例化并置顶打开设置窗口
}
private void print(object sender, RoutedEventArgs e)
{
}
private void fabric(object sender, RoutedEventArgs e)
{
}
private void variety(object sender, RoutedEventArgs e)
{
}
private void color(object sender, RoutedEventArgs e)
{
}
private void client(object sender, RoutedEventArgs e)
{
}
private void confirm(object sender, RoutedEventArgs e)
{
}
private void delete(object sender, RoutedEventArgs e)
{
}
private void save(object sender, RoutedEventArgs e) //保存按钮
{
if (int.Parse(Procedures_N.Text) > int.Parse(Procedures_P.Text))
{
MessageBoxResult result = System.Windows.MessageBox.Show("当前步骤与总步骤设定不符是否继续", "注意", MessageBoxButton.OKCancel, MessageBoxImage.Question, MessageBoxResult.Cancel);
if (result == MessageBoxResult.OK) { } else return;
}
Procedures_N.Text = "1";
Procedures_P.Text = "1";
RecipedataTable = RRODUCTdataTable;
UserClass.IniFile.IniFiles Configini = new UserClass.IniFile.IniFiles(INIPath); //记录当前单序号
Configini.IniWritevalue("SOFTWARE_SET", " T3", str_Prepose);
}
private void Button_NewOrder(object sender, RoutedEventArgs e) //新料单按钮
{
Number_Event();
}
private void Button_up(object sender, RoutedEventArgs e)
{
int i = int.Parse(Procedures_N.Text);
if (i < 999) Procedures_N.Text = (i + 1).ToString();
}
private void Button_dow(object sender, RoutedEventArgs e)
{
int i = int.Parse(Procedures_N.Text);
int P = int.Parse(Procedures_P.Text);
if (i > 1) Procedures_N.Text = (i - 1).ToString();
if (P >= i) Procedures_P.Text = Procedures_N.Text;
}
private void Button_StepUp(object sender, RoutedEventArgs e)
{
int I = int.Parse(Procedures_N.Text);
int P = int.Parse(Procedures_P.Text);
if (P < I) Procedures_P.Text = (P + 1).ToString();
}
private void Button_StepDow(object sender, RoutedEventArgs e)
{
int P = int.Parse(Procedures_P.Text);
if (P > 1) Procedures_P.Text = (P - 1).ToString();
}
private void Button_Technology(object sender, RoutedEventArgs e)
{
Deputy.Content = new View.ViewProcess(); //打开工艺选择
}
private void Button_Formula(object sender, RoutedEventArgs e)
{
Deputy.Content = new View.Formula(); //打开配方选择
}
private void DataGrid_InitializingNewItem(object sender, InitializingNewItemEventArgs e) //DetailedGrid生成行事件
{
}
private void Weight(object sender, TextChangedEventArgs e) //重量输入框
{
float a, b, c;
a = float.Parse(list_Weight.Text);
if (list_Proportion.Text != "") //判断比例是否有效
{
b = float.Parse(list_Proportion.Text);
c = a * b;
string listtotal = c.ToString();
list_Total.Text = listtotal;
}
}
private void Proportion(object sender, TextChangedEventArgs e) //浴比输入
{
float a, b, c;
b = float.Parse(list_Proportion.Text);
if (list_Weight.Text != "") //判断比例是否有效
{
a = float.Parse(list_Weight.Text);
c = a * b;
string listtotal = c.ToString();
list_Total.Text = listtotal;
}
}
private void CP_PRODUCT_CODE_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
PressKey.PressKeys(Keys.Right, false);
PressKey.PressKeys(Keys.Right, true);
// PressKey.PressKeys(Keys.Up, false);
// PressKey.PressKeys(Keys.Up, true);
PressKey.PressKeys(Keys.Tab, false);
PressKey.PressKeys(Keys.Tab, true);
// System.Windows.Controls.ComboBox curComboBox = sender as System.Windows.Controls.ComboBox;
// curComboBox.SelectedIndex = -1;
}
DataGridHelper.SetRealTimeCommit(Grid_RRODUCT, true); //实时更新datagrid
}
private void CP_CONC_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
{
double ang;
System.Windows.Controls.TextBox curTextBox = sender as System.Windows.Controls.TextBox;
if (!double.TryParse(curTextBox.Text, out ang) && curTextBox.Text != "")
{
System.Windows.MessageBox.Show("数值错误,重新输入");
curTextBox.Text = "";
}
else
{
if (e.Key == Key.Enter)
{
PressKey.PressKeys(Keys.Left, false);
PressKey.PressKeys(Keys.Left, true);
PressKey.PressKeys(Keys.Tab, false);
PressKey.PressKeys(Keys.Tab, true);
DataRow row = RRODUCTdataTable.NewRow(); //ID列
row = RRODUCTdataTable.NewRow();
ID_N++;
row["ID"] = ID_N;
// row["STEP"] = Procedures_P.Text;
RRODUCTdataTable.Rows.Add(row);
}
DataGridHelper.SetRealTimeCommit(Grid_RRODUCT, true); //实时更新datagrid
}
}
}
}

588
ViewModel/MainWindowViewModel.cs

@ -1,4 +1,7 @@
using formula_manage.Windows;
using formula_manage.SQLModels;
using formula_manage.ViewModel;
using formula_manage.Windows;
using GalaSoft.MvvmLight;
using System;
using System.Collections;
using System.Collections.Generic;
@ -6,42 +9,35 @@ using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
using formula_manage.ViewModel;
using Xceed.Wpf.Toolkit.PropertyGrid.Attributes;
using static System.Net.Mime.MediaTypeNames;
using formula_manage.UserClass;
//using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using System.Xml.Linq;
namespace formula_manage
namespace formula_manage.ViewModel
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
bool quit = false;
public class ViewModelBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
if (this.PropertyChanged != null)
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
///<Summary>
///
///
///</Summary>
///
public class MainWindowViewModel : ViewModelBase
{
DataTable DissolvedataTable = new DataTable(); //建立Dissolve缓存
DataTable STUFFdataTable = new DataTable(); //建立STUFF缓存
DataTable MACHINEdataTable = new DataTable(); //建立Machine缓存
@ -49,6 +45,12 @@ namespace formula_manage
DataTable RecipedataTable = new DataTable(); //建立Recipe缓存
public string INIPath = Convert.ToString(System.AppDomain.CurrentDomain.BaseDirectory) + "formula.ini"; //配置文件路径
public string sys_Time; //显示系统时间
public string Sys_Time //通知UI控件参数改变
{
get { return sys_Time; }
set { sys_Time = value; OnPropertyChanged("Sys_Time"); }
}
string TEXT_SQLIP;
string TEXT_SQLNAME;
@ -56,76 +58,8 @@ namespace formula_manage
string TEXT_SQLUSER;
string TEXT_SQLPASWOR;
string Connstr_SC;
int ID_N = 1;
public MainWindow()
{
DataContext = new MainWindowViewModel();
WindowStartupLocation = WindowStartupLocation.CenterScreen;
InitializeComponent();
this.Closing += Window_Closing; //添加窗口关闭事件
USER.Text = App.USER_Purview;
RecipedataTable.Columns.Add("DYELOT", typeof(int));
RecipedataTable.Columns.Add("STEP", typeof(string));
RecipedataTable.Columns.Add("PRODUCT_CODE", typeof(string));
RecipedataTable.Columns.Add("CONC", typeof(string));
RecipedataTable.Columns.Add("SHIFT", typeof(string));
RecipedataTable.Columns.Add("PRODUCT_NAME", typeof(string));
RecipedataTable.Columns.Add("TARGET_WT", typeof(float));
RecipedataTable.Columns.Add("UNIT", typeof(string));
RecipedataTable.Columns.Add("REMARK", typeof(string));
RRODUCTdataTable.Columns.Add("ID", typeof(int));
RRODUCTdataTable.Columns.Add("STEP", typeof(string));
RRODUCTdataTable.Columns.Add("PRODUCT_CODE", typeof(string));
RRODUCTdataTable.Columns.Add("CONC", typeof(string));
RRODUCTdataTable.Columns.Add("SHIFT", typeof(string));
RRODUCTdataTable.Columns.Add("PRODUCT_NAME", typeof(string));
RRODUCTdataTable.Columns.Add("TARGET_WT", typeof(float));
RRODUCTdataTable.Columns.Add("UNIT", typeof(string));
RRODUCTdataTable.Columns.Add("REMARK", typeof(string));
if (USER.Text == "ENGINEER") //工程师允许功能
{
_SQL.IsEnabled = true;
_SQLBAK.IsEnabled = true;
_SOFTWARE_SET.IsEnabled = true;
_USER_SET.IsEnabled = true;
_RECIPE.IsEnabled = true;
_PROCESS.IsEnabled = true;
_WORKFLOW.IsEnabled = true;
_MAC_SET.IsEnabled = true;
_STUFF.IsEnabled = true;
_fabric.IsEnabled = true;
_variety.IsEnabled = true;
_client.IsEnabled = true;
_color.IsEnabled = true;
_statistics.IsEnabled = true;
}
sql_();
Permissions_(); //权限管理
DataRow row = RRODUCTdataTable.NewRow(); //ID列
row["ID"] = ID_N;
row["STEP"] = Procedures_P.Text;
RRODUCTdataTable.Rows.Add(row);
/* for (ID_N = 2; ID_N <= 64; ID_N++)
{
row = RRODUCTdataTable.NewRow();
row["ID"] = ID_N;
// row["STEP"] = Procedures_P.Text;
RRODUCTdataTable.Rows.Add(row);
}*/
Grid_RRODUCT.ItemsSource = RRODUCTdataTable.DefaultView;
}
private void sql_()
private async void Sql_()
{
UserClass.IniFile.IniFiles Configini = new UserClass.IniFile.IniFiles(INIPath);//生效配置读取
TEXT_SQLIP = Configini.IniReadvalue("SQL_SERVER", "SQL1"); //读配置文件
@ -141,393 +75,151 @@ namespace formula_manage
{
Connstr_SC = "server=" + TEXT_SQLIP + ";database=" + TEXT_SQLNAME + ";User ID=" + TEXT_SQLUSER + ";Password=" + TEXT_SQLPASWOR;
}
}
private async void Permissions_()
{
DataTable logindataTable = new DataTable(); //建立login缓存
SqlConnection conn_SC = new SqlConnection(Connstr_SC);
string user_sql = "SELECT UserCode ,PassWord ,UserSetup ,Capacity ,GROUP_CODE ,Note FROM [Dispensing].[dbo].[UserAccount] WHERE Capacity != 0";//查询语句
string Stuff_sql = "SELECT ProductCode ,ProductName ,ProductType ,Concentration FROM [Dispensing].[dbo].[PRODUCT] order by ProductCode asc";//查询STUFF语句
string MAC_sql = "SELECT Name ,Capacity ,Volume 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(user_sql, Connstr_SC); //查询
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); //Dissolve_data查询结果存入缓存
conn_SC.Close(); //关闭连接
Stuff_data.Fill(logindataTable); //查询结果存入缓存
conn_SC.Close(); //关闭连接
}
catch (Exception)
{
System.Windows.MessageBox.Show("请求信息失败,检查连接");
System.Windows.MessageBox.Show("请求原料信息失败,检查连接");
return;
}
}
string var_POWERUSER = "[UserCode]='" + USER.Text + "' and [GROUP_CODE] ='POWERUSER '"; //查询字符
string var_CHIEF = "[UserCode]='" + USER.Text + "' and [GROUP_CODE] ='CHIEF '"; //查询字符
public MainWindowViewModel()
{
CountDown();
Sql_();
var CHIEF = logindataTable.Select(var_CHIEF).FirstOrDefault(); //查询账号信息是否正确,不正确返回null
stuff_Product = ToObservableCollection<Product>(STUFFdataTable); //stuff_Product表转换
mac_Machine = ToObservableCollection<Machine>(MACHINEdataTable);
flow_Workflow = ToObservableCollection<Workflow>(DissolvedataTable);
if (CHIEF != null)
{
_SQL.IsEnabled = true;
_SQLBAK.IsEnabled = true;
_SOFTWARE_SET.IsEnabled = true;
_USER_SET.IsEnabled = true;
_RECIPE.IsEnabled = true;
_PROCESS.IsEnabled = true;
_WORKFLOW.IsEnabled = true;
_MAC_SET.IsEnabled = true;
_STUFF.IsEnabled = true;
_fabric.IsEnabled = true;
_variety.IsEnabled = true;
_client.IsEnabled = true;
_color.IsEnabled = true;
_statistics.IsEnabled = true;
}
else
{
var POWERUSER = logindataTable.Select(var_POWERUSER).FirstOrDefault(); //查询账号信息是否正确,不正确返回null
if (POWERUSER != null)
{
_SQLBAK.IsEnabled = true;
_RECIPE.IsEnabled = true;
_PROCESS.IsEnabled = true;
_WORKFLOW.IsEnabled = true;
_MAC_SET.IsEnabled = true;
_STUFF.IsEnabled = true;
_fabric.IsEnabled = true;
_variety.IsEnabled = true;
_client.IsEnabled = true;
_color.IsEnabled = true;
_statistics.IsEnabled = true;
}
}
}
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) //窗口关闭事件
public ObservableCollection<Product> stuff_Product { get; set; } //stuff_Product动态表实力化
public ObservableCollection<Machine> mac_Machine { get; set; } //mac_Machine动态表实力化
public ObservableCollection<Workflow> flow_Workflow { get; set; } //Dissolve动态表实力化
public ObservableCollection<T> ToObservableCollection<T>(DataTable dt) where T : class, new() //DataTable FOR ObservableCollection转换器
{
string logpath = System.Environment.CurrentDirectory + "\\Log";//日志文件目录
string logPath = "" + System.Environment.CurrentDirectory + "\\Log\\Log.txt";//日志文件
string Log_time = "[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "]:";
if (!quit)
Type t = typeof(T);
PropertyInfo[] propertys = t.GetProperties();
ObservableCollection<T> lst = new ObservableCollection<T>();
string typeName = string.Empty;
foreach (DataRow dr in dt.Rows)
{
MessageBoxResult result = System.Windows.MessageBox.Show("您确定要退出吗?", "SUNLIGHT", MessageBoxButton.OKCancel, MessageBoxImage.None, MessageBoxResult.Cancel);
if (result == MessageBoxResult.Cancel) //判断是否确认
T entity = new T();
foreach (PropertyInfo pi in propertys)
{
e.Cancel = true; // 中断点击事件
typeName = pi.Name;
if (dt.Columns.Contains(typeName))
{
if (!pi.CanWrite) continue;
object value = dr[typeName];
if (value == DBNull.Value) continue;
if (pi.PropertyType == typeof(string))
{
pi.SetValue(entity, value.ToString(), null);
}
else if (pi.PropertyType == typeof(int) || pi.PropertyType == typeof(int?))
{
pi.SetValue(entity, int.Parse(value.ToString()), null);
}
else if (pi.PropertyType == typeof(DateTime?) || pi.PropertyType == typeof(DateTime))
{
pi.SetValue(entity, DateTime.Parse(value.ToString()), null);
}
else if (pi.PropertyType == typeof(float))
{
pi.SetValue(entity, float.Parse(value.ToString()), null);
}
else if (pi.PropertyType == typeof(double))
{
pi.SetValue(entity, double.Parse(value.ToString()), null);
}
else
{
pi.SetValue(entity, value, null);
}
}
}
lst.Add(entity);
}
System.IO.DirectoryInfo log = new System.IO.DirectoryInfo(@logpath);//生成日志文件目录
FileStream fs = new FileStream(logPath, FileMode.Append, FileAccess.Write);
StreamWriter wr = new StreamWriter(fs);//创建文件
wr.WriteLine(Log_time + "FORMULA_STOP");
wr.Close();
}
private void SearchBox_OnKeyDownd(object sender, System.Windows.Input.KeyEventArgs e) //回车跳转功能
{
if (e.Key == Key.Enter)
return lst;
} //DataTable FOR ObservableCollection转换器
/// <summary>
/// 循环事件设定
/// </summary>
public void CountDown()
{
DispatcherTimer timer = new DispatcherTimer//初始化循环,每0.5秒调用一次Tick_Event
{
UserClass.PressKey.PressKeys(Keys.Tab, false);
UserClass.PressKey.PressKeys(Keys.Tab, true);
}
}
string Prepose; //料单前置
string PreposeT; //料单时间
string PreposeS; //料单序列格式
int PreposeSl;
string str_Prepose;
bool Loginprint;
bool Loginanew;
Interval = TimeSpan.FromSeconds(0.5)
};
timer.Tick += Tick_Event;
timer.Start();
private void Window_MIN(object sender, RoutedEventArgs e)
{
UserClass.IniFile.IniFiles Configini = new UserClass.IniFile.IniFiles(INIPath);
Loginprint = Boolean.Parse(Configini.IniReadvalue("SOFTWARE_SET", "L2")); //是否立即打印料单
Loginanew = Boolean.Parse(Configini.IniReadvalue("SOFTWARE_SET", "L3")); //是否立即打印料单
Machine.IsReadOnly = Boolean.Parse(Configini.IniReadvalue("SOFTWARE_SET", "L4")); //允许自定义机台
Prepose = Configini.IniReadvalue("SOFTWARE_SET", "T1"); //自定义料单前缀
PreposeT = Configini.IniReadvalue("SOFTWARE_SET", "T2"); //自定义料单时间
PreposeS = Configini.IniReadvalue("SOFTWARE_SET", "T3"); //自定义料单格式
PreposeSl = int.Parse(PreposeS);
Number_Event();
//Number.Text = Prepose + System.DateTime.Now.ToString(PreposeT); //生成料单号
}
private void Number_Event() //生成料单号事件
{
int preposeL = PreposeS.Length;
PreposeSl = PreposeSl + 1;
str_Prepose = String.Format("{0:D" + preposeL + "}", PreposeSl);
Number.Text = Prepose + System.DateTime.Now.ToString(PreposeT) + str_Prepose; //生成料单号
}
private void Tb_KeyPress(object sender, TextCompositionEventArgs e)//输入事件
{
//Regex re = new Regex("[^0-9.-]+");
Regex re = new Regex(@"^[0-9]+(.[0-9]{1,3})?$");// 非零的正整数
e.Handled = !re.IsMatch(e.Text);
//设置定时器
// disTimer.Tick += new EventHandler(DisTimer_Tick);//每一秒执行的方法
// disTimer.Interval = new TimeSpan(10000000); //时间间隔为一秒。
// disTimer.Start();//计时开始
}
private void Tb_KeyFloating(object sender, TextCompositionEventArgs e)//输入事件
{
//Regex re = new Regex("[^0-9.-]+");
Regex re = new Regex(@"^[.][0-9]+$|^[0-9]*[.]{0,1}[0-9]*$");// 非负浮点数
e.Handled = !re.IsMatch(e.Text);
}
private void logout(object sender, RoutedEventArgs e)
{
quit = true;
Window window = Window.GetWindow(this);
Login login = new Login();
window.Close();
login.ShowDialog();//实例化并置顶打开登录窗口
}
private void SQL(object sender, RoutedEventArgs e)
{
System.Windows.MessageBox.Show("进入数据库设置请您明确操作目的及可能需承担的后果", "警告");
Windows.Sql sql = new Windows.Sql();
sql.ShowDialog();//实例化并置顶打开数据库设置窗口
}
private void SQLBAK(object sender, RoutedEventArgs e)
void Tick_Event(object sender, EventArgs e)//Tick_Event周期执行事件
{
MessageBoxResult sql_bak = System.Windows.MessageBox.Show("注意此功能仅作用与本地数据库(Dispensing)对于远端数据库的操作可能失败如果需要继续操作单击确定", "SQL", MessageBoxButton.OKCancel, MessageBoxImage.Exclamation); //连接失败提示
if (sql_bak == MessageBoxResult.OK)
{
Windows.SQL_BAK sqlbak = new Windows.SQL_BAK();
sqlbak.ShowDialog();//实例化并置顶打开数据库备份窗口
}
Sys_Time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
}
private void SOFTWARE_SET(object sender, RoutedEventArgs e)
{
Windows.APP_set APP_set = new Windows.APP_set();
APP_set.ShowDialog();//实例化并置顶打开设置窗口
}
private void USER_SET(object sender, RoutedEventArgs e)
{
Windows.User user_set = new Windows.User();
user_set.ShowDialog();//实例化并置顶打开用户窗口
}
private void HELP(object sender, RoutedEventArgs e)
{
Help help_page = new Help();
help_page.ShowDialog();//实例化并置顶打开信息窗口
}
private void MAC_SET(object sender, RoutedEventArgs e)
{
Windows.Machine mac = new Windows.Machine();
mac.ShowDialog();//实例化并置顶打开设置窗口
}
private void STUFF(object sender, RoutedEventArgs e)
{
Windows.Stuff stuff = new Windows.Stuff();
stuff.ShowDialog();//实例化并置顶打开设置窗口
}
private void RECIPE(object sender, RoutedEventArgs e)
{
}
private void PROCESS(object sender, RoutedEventArgs e)
{
}
private void WORKFLOW(object sender, RoutedEventArgs e)
{
Windows.Dissolve dissolve = new Windows.Dissolve();
dissolve.ShowDialog();//实例化并置顶打开设置窗口
}
private void print(object sender, RoutedEventArgs e)
{
}
private void fabric(object sender, RoutedEventArgs e)
{
}
private void variety(object sender, RoutedEventArgs e)
{
}
private void color(object sender, RoutedEventArgs e)
{
}
private void client(object sender, RoutedEventArgs e)
{
}
private void confirm(object sender, RoutedEventArgs e)
{
}
private void delete(object sender, RoutedEventArgs e)
{
}
private void save(object sender, RoutedEventArgs e) //保存按钮
{
if (int.Parse(Procedures_N.Text) > int.Parse(Procedures_P.Text))
{
MessageBoxResult result = System.Windows.MessageBox.Show("当前步骤与总步骤设定不符是否继续", "注意", MessageBoxButton.OKCancel, MessageBoxImage.Question, MessageBoxResult.Cancel);
if (result == MessageBoxResult.OK) { } else return;
}
Procedures_N.Text = "1";
Procedures_P.Text = "1";
RecipedataTable = RRODUCTdataTable;
UserClass.IniFile.IniFiles Configini = new UserClass.IniFile.IniFiles(INIPath); //记录当前单序号
Configini.IniWritevalue("SOFTWARE_SET", " T3", str_Prepose);
}
private void Button_NewOrder(object sender, RoutedEventArgs e) //新料单按钮
{
Number_Event();
}
private void Button_up(object sender, RoutedEventArgs e)
{
int i = int.Parse(Procedures_N.Text);
if (i < 999) Procedures_N.Text = (i + 1).ToString();
}
private void Button_dow(object sender, RoutedEventArgs e)
{
int i = int.Parse(Procedures_N.Text);
int P = int.Parse(Procedures_P.Text);
if (i > 1) Procedures_N.Text = (i - 1).ToString();
if (P >= i) Procedures_P.Text = Procedures_N.Text;
}
private void Button_StepUp(object sender, RoutedEventArgs e)
{
int I = int.Parse(Procedures_N.Text);
int P = int.Parse(Procedures_P.Text);
if (P < I) Procedures_P.Text = (P + 1).ToString();
}
private void Button_StepDow(object sender, RoutedEventArgs e)
{
int P = int.Parse(Procedures_P.Text);
if (P > 1) Procedures_P.Text = (P - 1).ToString();
}
private void Button_Technology(object sender, RoutedEventArgs e)
{
Deputy.Content = new View.ViewProcess(); //打开工艺选择
}
private void Button_Formula(object sender, RoutedEventArgs e)
{
Deputy.Content = new View.Formula(); //打开配方选择
}
private void DataGrid_InitializingNewItem(object sender, InitializingNewItemEventArgs e) //DetailedGrid生成行事件
{
}
}
public class Product //stuff_Product
{
public string ProductCode { get; set; }
public string ProductName { get; set; }
public int ProductType { get; set; }
public int Concentration { get; set; }
private void Weight(object sender, TextChangedEventArgs e) //重量输入框
public override string ToString()
{
float a, b, c;
a = float.Parse(list_Weight.Text);
if (list_Proportion.Text != "") //判断比例是否有效
{
b = float.Parse(list_Proportion.Text);
c = a * b;
string listtotal = c.ToString();
list_Total.Text = listtotal;
}
}
private void Proportion(object sender, TextChangedEventArgs e) //浴比输入
{
float a, b, c;
b = float.Parse(list_Proportion.Text);
if (list_Weight.Text != "") //判断比例是否有效
{
a = float.Parse(list_Weight.Text);
c = a * b;
string listtotal = c.ToString();
list_Total.Text = listtotal;
}
return ProductCode;
}
}
public class Machine //mac
{
public string Name { get; set; }
public float Volume { get; set; }
public float Capacity { get; set; }
private void CP_PRODUCT_CODE_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
public override string ToString()
{
if (e.Key == Key.Enter)
{
PressKey.PressKeys(Keys.Right, false);
PressKey.PressKeys(Keys.Right, true);
// PressKey.PressKeys(Keys.Up, false);
// PressKey.PressKeys(Keys.Up, true);
PressKey.PressKeys(Keys.Tab, false);
PressKey.PressKeys(Keys.Tab, true);
System.Windows.Controls.ComboBox curComboBox = sender as System.Windows.Controls.ComboBox;
curComboBox.SelectedIndex = -1;
}
DataGridHelper.SetRealTimeCommit(Grid_RRODUCT, true); //实时更新datagrid
return Name;
}
}
public class Workflow //Dissolve
{
public string DissolveName { get; set; }
public int MaterialType { get; set; }
public int WeightMIN { get; set; }
public int WeightMAX { get; set; }
private void CP_CONC_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
public override string ToString()
{
if (e.Key == Key.Enter)
{
PressKey.PressKeys(Keys.Left, false);
PressKey.PressKeys(Keys.Left, true);
PressKey.PressKeys(Keys.Tab, false);
PressKey.PressKeys(Keys.Tab, true);
DataRow row = RRODUCTdataTable.NewRow(); //ID列
row = RRODUCTdataTable.NewRow();
ID_N++;
row["ID"] = ID_N;
// row["STEP"] = Procedures_P.Text;
RRODUCTdataTable.Rows.Add(row);
}
DataGridHelper.SetRealTimeCommit(Grid_RRODUCT, true); //实时更新datagrid
return DissolveName;
}
}
}

Loading…
Cancel
Save