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.

579 lines
22 KiB

using formula_manage.Windows;
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.Globalization;
2 years ago
using System.IO;
using System.Linq;
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 Xceed.Wpf.Toolkit.PropertyGrid.Attributes;
using static System.Net.Mime.MediaTypeNames;
//using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace formula_manage
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
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"; //配置文件路径
string TEXT_SQLIP;
string TEXT_SQLNAME;
string TEXT_SQMOD;
string TEXT_SQLUSER;
string TEXT_SQLPASWOR;
string Connstr_SC;
public MainWindow()
{
// DataContext =new MainWindow();
int ID_N = 1;
WindowStartupLocation = WindowStartupLocation.CenterScreen;
2 years ago
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_();//查询stuff表
Permissions_(); //权限管理
2 years ago
CountDown();//执行循环方法
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_()
{
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(); //关闭连接
//DataGridStuff.ItemsSource = dataTable.DefaultView; //数据加入表格
}
catch (Exception)
{
System.Windows.MessageBox.Show("请求原料信息失败,检查连接");
return;
}
Machine.ItemsSource = MACHINEdataTable.DefaultView; // MACHINEdataTable数据集传递到ComboBox:machine
Workflow.ItemsSource = DissolvedataTable.DefaultView; // DissolvedataTable数据集传递到ComboBox:Workflow
}
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";//查询语句
try
{
await conn_SC.OpenAsync(); //打开数据连接
SqlDataAdapter Stuff_data = new SqlDataAdapter(user_sql, Connstr_SC); //查询
Stuff_data.Fill(logindataTable); //查询结果存入缓存
conn_SC.Close(); //关闭连接
}
catch (Exception)
{
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 '"; //查询字符
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;
}
}
}
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) //窗口关闭事件
2 years ago
{
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)
{
MessageBoxResult result = System.Windows.MessageBox.Show("您确定要退出吗?", "SUNLIGHT", MessageBoxButton.OKCancel, MessageBoxImage.None, MessageBoxResult.Cancel);
if (result == MessageBoxResult.Cancel) //判断是否确认
{
e.Cancel = true; // 中断点击事件
}
}
2 years ago
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();
2 years ago
}
private DispatcherTimer disTimer = new DispatcherTimer();//循环功能
public void DisTimer_Tick(object sender, EventArgs e)//循环事件
{
USERTIME.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
2 years ago
}
2 years ago
public void CountDown()
{
//设置定时器
disTimer.Tick += new EventHandler(DisTimer_Tick);//每一秒执行的方法
disTimer.Interval = new TimeSpan(1000000); //时间间隔为一秒。
2 years ago
disTimer.Start();//计时开始
}
private void SearchBox_OnKeyDownd(object sender, System.Windows.Input.KeyEventArgs e) //回车跳转功能
{
if (e.Key == Key.Enter)
{
UserClass.PressKey.PressKeys(Keys.Tab, false);
UserClass.PressKey.PressKeys(Keys.Tab, true);
}
}
string Prepose; //料单前置
string PreposeT; //料单时间
string PreposeS; //料单序列格式
int PreposeSl;
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"); //自定义料单格式
Number_Event();
//Number.Text = Prepose + System.DateTime.Now.ToString(PreposeT); //生成料单号
}
private void Number_Event() //生成料单号事件
{
int preposeL = PreposeS.Length;
PreposeSl = PreposeSl + 1;
string str = String.Format("{0:D"+ preposeL + "}", PreposeSl);
Number.Text = Prepose + System.DateTime.Now.ToString(PreposeT) + str; //生成料单号
}
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);
}
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)
{
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;
}
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)
{
//string dsa= CP_PRODUCT_CODE //Grid_RRODUCT.SelectedItems[0].ToString();
// int index = Grid_RRODUCT.CurrentCell;
// DataGridTemplateColumn templeColumn = Grid_RRODUCT.Columns[1] as DataGridTemplateColumn;
/* for (int k = 0; k < this.Grid_RRODUCT.Items.Count; k++)
{
//首先获取DataGridTemplateColumn所在列
DataGridTemplateColumn tempColumn = this.Grid_RRODUCT.Columns[9] as DataGridTemplateColumn;
//然后获取DataGridTemplateColumn单元格元素
FrameworkElement element = this.Grid_RRODUCT.Columns[9].GetCellContent(this.Grid_RRODUCT.Items[k]);
if (element != null)
{
//把单元格元素转换为相应的控件,再从该控件中取值
System.Windows.Controls.CheckBox ck = Grid_RRODUCT.SelectedItems[1].CellTemplate.FindName("CP_PRODUCT_CODE", element) as System.Windows.Controls.CheckBox;
if (ck.IsChecked.Value)
{
//do something here
}
}
}*/
if (e.Key == Key.Enter)
{
UserClass.PressKey.PressKeys(Keys.Right, false);
UserClass.PressKey.PressKeys(Keys.Right, true);
UserClass.PressKey.PressKeys(Keys.Up, false);
UserClass.PressKey.PressKeys(Keys.Up, true);
UserClass.PressKey.PressKeys(Keys.Tab, false);
UserClass.PressKey.PressKeys(Keys.Tab, true);
}
}
private void CP_CONC_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
UserClass.PressKey.PressKeys(Keys.Left, false);
UserClass.PressKey.PressKeys(Keys.Left, true);
UserClass.PressKey.PressKeys(Keys.Tab, false);
UserClass.PressKey.PressKeys(Keys.Tab, true);
}
}
}
}