207 lines
8.9 KiB
C#
207 lines
8.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Data;
|
|
using System.Windows.Documents;
|
|
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 static ProcessManageUI.SqliteHelper;
|
|
using static System.Net.WebRequestMethods;
|
|
|
|
namespace ProcessManageUI
|
|
{
|
|
/// <summary>
|
|
/// MainWindow.xaml 的交互逻辑
|
|
/// </summary>
|
|
public partial class MainWindow : Window
|
|
{
|
|
private static IniFile.IniFiles Configini = new IniFile.IniFiles(Convert.ToString(System.AppDomain.CurrentDomain.BaseDirectory) + "ProcessManageConfigini.ini");
|
|
private static string SQLIP = Configini.IniReadvalue("SQL_SERVER", "SQL1"); //读配置文件
|
|
private static string SQLNAME = Configini.IniReadvalue("SQL_SERVER", "SQL2");
|
|
private static string SQMOD = Configini.IniReadvalue("SQL_SERVER", "SQL3");
|
|
private static string SQLUSER = Configini.IniReadvalue("SQL_SERVER", "SQL4");
|
|
private static string SQLPASWORD = Configini.IniReadvalue("SQL_SERVER", "SQL5");
|
|
private static DataTable DyelotsBulkedRecipe = new DataTable();
|
|
private static DataTable Product = new DataTable();
|
|
private static DataTable Gram = new DataTable();
|
|
private static int Count = 0;
|
|
private static readonly int _intervalMs = int.Parse(Configini.IniReadvalue("SQL_SERVER", "SQL6"));
|
|
private static SQLiteHelper SQLiteHelpers = null; //定义数据库
|
|
private readonly static string DBAddress = Environment.CurrentDirectory + "\\ProcessManage.db"; //数据库路径
|
|
private int DATAGRID_TABLE;
|
|
|
|
//设置定时器
|
|
DispatcherTimer disTimer = new DispatcherTimer
|
|
{
|
|
Interval = TimeSpan.FromMilliseconds(_intervalMs) //毫秒
|
|
};
|
|
public MainWindow()
|
|
{
|
|
InitializeComponent();
|
|
|
|
IP.Text = SQLIP;
|
|
MOD.Text = SQMOD;
|
|
NAME.Text = SQLNAME;
|
|
USER.Text = SQLUSER;
|
|
PAW.Text = SQLPASWORD;
|
|
TIMEMS.Text = _intervalMs.ToString();
|
|
|
|
Datalog.Text = "启动";
|
|
Datalog.AppendText("\n读取配置");
|
|
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
|
|
SQLiteHelpers.Open(); //打开数据库
|
|
Gram = SQLiteHelpers.ExecuteDataSet("select * from Gram", null).Tables[0]; //读取表写入缓存
|
|
Product = SQLiteHelpers.ExecuteDataSet("select * from ProcessManage", null).Tables[0];
|
|
SQLiteHelpers.Close();
|
|
|
|
Datalog.AppendText("\n设定循环时间"+ _intervalMs+"MS");
|
|
disTimer.Tick += EXTask;
|
|
disTimer.Start();//计时开始
|
|
}
|
|
|
|
private void EXTask(object sender, EventArgs e)
|
|
{
|
|
disTimer.Stop();//停止计时
|
|
string Connstr_SC;
|
|
string DyelotsBulkedRecipe_sql = "SELECT * FROM [dbo].[DyelotsBulkedRecipe] WHERE Created > '"
|
|
+ DateTime.Now.AddDays(-1).ToString("yyyy/MM/dd") + "' AND ProductType = '1' AND Process IS NULL";
|
|
if (SQMOD == "Windows Authentication")
|
|
{
|
|
Connstr_SC = "server=" + SQLIP + ";database=" + SQLNAME + ";Trusted_Connection=SSPI";
|
|
}
|
|
else
|
|
{
|
|
Connstr_SC = "server=" + SQLIP + ";database=" + SQLNAME + ";User ID=" + SQLUSER + ";Password=" + SQLPASWORD;
|
|
}
|
|
SqlConnection conn_SC = new SqlConnection(Connstr_SC);
|
|
conn_SC.OpenAsync(); //连接数据库
|
|
SqlDataAdapter DyelotsBulkedRecipe_ = new SqlDataAdapter(DyelotsBulkedRecipe_sql, Connstr_SC);
|
|
try
|
|
{
|
|
DyelotsBulkedRecipe.Clear();
|
|
Datalog.Text = null;
|
|
Datalog.AppendText(DateTime.Now.ToString("yyyy/MM/dd-HH:mm:ss") +" 开始转换");
|
|
DyelotsBulkedRecipe_.Fill(DyelotsBulkedRecipe);
|
|
|
|
for (int i = DyelotsBulkedRecipe.Rows.Count; i > 0; i--)
|
|
{
|
|
if (DyelotsBulkedRecipe.Rows.Count <= 0) { break; }//跳出循环
|
|
|
|
string Dyelot = DyelotsBulkedRecipe.Rows[0].Field<string>("Dyelot");
|
|
int ReDye = DyelotsBulkedRecipe.Rows[0].Field<int>("ReDye");
|
|
int StepNumber = DyelotsBulkedRecipe.Rows[0].Field<int>("StepNumber");
|
|
double gram = 0;
|
|
int type_id = 0;
|
|
DataRow[] rowdat = DyelotsBulkedRecipe.Select("Dyelot ='" + Dyelot + "' AND ReDye='"+ ReDye+ "' AND StepNumber ='"+ StepNumber+"'");//行
|
|
|
|
foreach (DataRow row in rowdat)//删除指定信息行
|
|
{
|
|
try
|
|
{
|
|
int a = Product.Select("ProductCode = " + row.Field<string>("ProductCode")).First().Field<int>("ProductType");
|
|
if (a > type_id) type_id = a;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogGing.ERRDATA(ex);
|
|
Datalog.AppendText(ex.ToString());
|
|
}
|
|
|
|
gram += row.Field<double>("Grams");
|
|
row.Delete();
|
|
row.AcceptChanges();
|
|
}
|
|
string NAME = "Process";
|
|
try
|
|
{
|
|
NAME = Gram.Select("Type='" + type_id + "' and min<='" + gram + "' and max>'" + gram + "'").First().Field<string>("name");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogGing.ERRDATA(ex);
|
|
Datalog.AppendText(ex.ToString());
|
|
}
|
|
|
|
string DyelotsBulkedRecipe_updata = "UPDATE [dbo].[DyelotsBulkedRecipe] SET Process ='"+NAME+
|
|
"'WHERE Dyelot ='" + Dyelot + "' AND ReDye='" + ReDye + "' AND StepNumber ='" + StepNumber + "'";
|
|
SqlCommand DyelotsBulkedRecipe_UP = new SqlCommand(DyelotsBulkedRecipe_updata, conn_SC);
|
|
Count++;
|
|
Datalog.AppendText("\n" + DateTime.Now.ToString("yyyy/MM/dd-HH:mm:ss") +
|
|
" 转换工单:" + Dyelot + "-重染:"+ReDye+"-步骤:"+StepNumber+"\n影响行数"+
|
|
DyelotsBulkedRecipe_UP.ExecuteNonQuery() + "-流程:"+ NAME);
|
|
LogGing.LogGingDATA( "转换工单:" + Dyelot + "重染" + ReDye + "步骤" + StepNumber + "流程:" + NAME);
|
|
}
|
|
Datalog.AppendText("\n" + DateTime.Now.ToString("yyyy/MM/dd-HH:mm:ss") + $" 转换完成{Count}条");
|
|
Count = 0;
|
|
}
|
|
catch (Exception ex)
|
|
{//错误处理
|
|
LogGing.ERRDATA(ex);
|
|
Datalog.AppendText(ex.ToString());
|
|
}
|
|
finally
|
|
{
|
|
conn_SC.Close();
|
|
disTimer.Start();//计时开始
|
|
}
|
|
}
|
|
|
|
private void Button_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
Configini.IniWritevalue("SQL_SERVER", "SQL1", IP.Text);
|
|
Configini.IniWritevalue("SQL_SERVER", "SQL2", NAME.Text);
|
|
Configini.IniWritevalue("SQL_SERVER", "SQL3", MOD.Text);
|
|
Configini.IniWritevalue("SQL_SERVER", "SQL4", USER.Text);
|
|
Configini.IniWritevalue("SQL_SERVER", "SQL5", PAW.Text);
|
|
Configini.IniWritevalue("SQL_SERVER", "SQL6", TIMEMS.Text);
|
|
inf.Text = "数据库设定已储存";
|
|
}
|
|
|
|
private void Button_Click_1(object sender, RoutedEventArgs e)
|
|
{
|
|
disTimer.Stop();//停止计时
|
|
data_Grid.ItemsSource = Product.DefaultView;
|
|
DATAGRID_TABLE = 1;
|
|
inf.Text = "设定染料信息";
|
|
data_Grid.Visibility = Visibility.Visible;
|
|
}
|
|
|
|
private void Button_Click_2(object sender, RoutedEventArgs e)
|
|
{
|
|
disTimer.Stop();//停止计时
|
|
data_Grid.ItemsSource = Gram.DefaultView;
|
|
DATAGRID_TABLE = 2;
|
|
inf.Text = "设定流程信息";
|
|
data_Grid.Visibility = Visibility.Visible;
|
|
}
|
|
|
|
private void Button_Click_3(object sender, RoutedEventArgs e)
|
|
{
|
|
if (DATAGRID_TABLE == 1)
|
|
{
|
|
inf.Text = "染料信息已储存";
|
|
}
|
|
else if (DATAGRID_TABLE == 2)
|
|
{
|
|
inf.Text = "流程信息已储存";
|
|
}
|
|
|
|
data_Grid.Visibility=Visibility.Collapsed;
|
|
disTimer.Start();//计时
|
|
}
|
|
}
|
|
}
|