|
|
@ -1,5 +1,6 @@ |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.ComponentModel; |
|
|
|
using System.Data; |
|
|
|
using System.Data.SqlClient; |
|
|
|
using System.Linq; |
|
|
@ -7,6 +8,7 @@ using System.Security.Cryptography; |
|
|
|
using System.Text; |
|
|
|
using System.Threading; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using System.Windows; |
|
|
|
|
|
|
|
namespace ProcessManage |
|
|
|
{ |
|
|
@ -22,6 +24,9 @@ namespace ProcessManage |
|
|
|
private static Timer _timer; |
|
|
|
private static int Count = 0; |
|
|
|
private static readonly int _intervalMs = int.Parse( Configini.IniReadvalue("SQL_SERVER", "SQL6")); |
|
|
|
private static DataTable Product = new DataTable(); |
|
|
|
private static DataTable Gram = new DataTable(); |
|
|
|
|
|
|
|
static void Main(string[] args) |
|
|
|
{ |
|
|
|
Console.WriteLine("Process选择功能启动"); |
|
|
@ -40,31 +45,74 @@ namespace ProcessManage |
|
|
|
private static void EXTask(object state) |
|
|
|
{ |
|
|
|
string Connstr_SC; |
|
|
|
string DyelotsBulkedRecipe_sql = "SELECT * FROM [dbo].[DyelotsBulkedRecipe] WHERE Created > '" |
|
|
|
+ DateTime.Now.AddDays(-1).ToString("yyyy/MM/dd") + "' AND Process IS NULL"; |
|
|
|
string DyelotsBulkedRecipe_sql = |
|
|
|
"SELECT * FROM [dbo].[DyelotsBulkedRecipe] WHERE Created > '" + DateTime.Now.AddDays(-1).ToString("yyyy/MM/dd") + |
|
|
|
"' AND ProductType = '1' AND Process IS NULL AND StepNumber IS NOT NULL AND ProductCode IS NOT NULL AND ReDye IS NOT 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(); |
|
|
|
|
|
|
|
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); |
|
|
|
conn_SC.Close(); |
|
|
|
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); |
|
|
|
Console.Write(ex.ToString()); |
|
|
|
} |
|
|
|
|
|
|
|
gram += row.Field<double>("Grams"); |
|
|
|
row.Delete(); |
|
|
|
row.AcceptChanges(); |
|
|
|
} |
|
|
|
string NAME = "Process"; |
|
|
|
try |
|
|
|
{ |
|
|
|
NAME = Gram.Select("Type='" + type_id + "' and min<=" + (int)gram + " and max>" + (int)gram + "").First().Field<string>("name"); |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
LogGing.ERRDATA(ex); |
|
|
|
Console.Write(ex.ToString()); |
|
|
|
} |
|
|
|
|
|
|
|
Console.Write("\n"+DateTime.Now.ToString("yyyy/MM/dd-HH:mm:ss")+$"转换{Count}条"); |
|
|
|
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++; |
|
|
|
Console.Write("\n" + DateTime.Now.ToString("yyyy/MM/dd-HH:mm:ss") + |
|
|
|
" 转换工单:" + Dyelot + "-重染:" + ReDye + "-步骤:" + StepNumber + "\n影响行数" + |
|
|
|
DyelotsBulkedRecipe_UP.ExecuteNonQuery() + "-流程:" + NAME); |
|
|
|
LogGing.LogGingDATA("转换工单:" + Dyelot + "重染" + ReDye + "步骤" + StepNumber + "流程:" + NAME); |
|
|
|
} |
|
|
|
// Console.Write("\n" + DateTime.Now.ToString("yyyy/MM/dd-HH:mm:ss") + $" 转换完成{Count}条");
|
|
|
|
Count = 0; |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
@ -74,9 +122,10 @@ namespace ProcessManage |
|
|
|
} |
|
|
|
finally |
|
|
|
{ |
|
|
|
conn_SC.Close(); |
|
|
|
_timer.Change( |
|
|
|
dueTime: _intervalMs, |
|
|
|
period: Timeout.Infinite);//设定下次触发
|
|
|
|
dueTime: _intervalMs, |
|
|
|
period: Timeout.Infinite);//设定下次触发
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|