Compare commits

..
4 Commits
4 changed files with 113 additions and 20 deletions

No files matched your search

+7
View File
@@ -33,8 +33,11 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="PresentationFramework" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
@@ -52,11 +55,15 @@
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="ProcessManage.db" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Data.SQLite">
<Version>1.0.119</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Content Include="sunlight_logo.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
Binary file not shown.
+106 -20
View File
@@ -1,17 +1,36 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Forms;
namespace ProcessManage
{
internal class Program
{
[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int cmdShow);
[DllImport("kernel32.dll")]
static extern IntPtr GetConsoleWindow();
const int SW_HIDE = 0;
const int SW_SHOW = 5;
const int SW_MINIMIZE = 6;
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");
@@ -19,13 +38,36 @@ namespace ProcessManage
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 Timer _timer;
private static System.Threading.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)
{
var handle = GetConsoleWindow();
// ShowWindow(handle, SW_MINIMIZE);
ShowWindow(handle, SW_HIDE);
// 托盘图标部分
var notifyIcon = new NotifyIcon();
notifyIcon.Icon = new System.Drawing.Icon("./sunlight_logo.ico");
notifyIcon.Visible = true;
notifyIcon.Text = "Process选择";
notifyIcon.MouseClick += (s, e) =>
{
if (e.Button == MouseButtons.Left)
{
ShowWindow(handle, SW_SHOW);
//Process.GetCurrentProcess().MainWindowHandle; // 强制刷新焦点
}
};
Console.WriteLine("Process选择功能启动");
_timer = new Timer(
_timer = new System.Threading.Timer(
callback: EXTask,
state: null,
dueTime: 100,
@@ -40,31 +82,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 +159,10 @@ namespace ProcessManage
}
finally
{
conn_SC.Close();
_timer.Change(
dueTime: _intervalMs,
period: Timeout.Infinite);//设定下次触发
dueTime: _intervalMs,
period: Timeout.Infinite);//设定下次触发
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB