添加数据库设置
This commit is contained in:
commit
b998ce1e35
2 files changed
+91
-26
No files matched your search
@@ -5,9 +5,36 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:ProcessManageUI"
|
||||
mc:Ignorable="d"
|
||||
Title="MainWindow" Height="450" Width="800">
|
||||
ResizeMode="NoResize"
|
||||
Title="ProcessManage" Height="450" Width="800" >
|
||||
<Grid>
|
||||
<TextBox x:Name="Datalog" Margin="30,30,300,30"/>
|
||||
|
||||
<TextBox x:Name="Datalog" Margin="30,30,300,30" IsReadOnly="True" VerticalScrollBarVisibility="Visible" />
|
||||
<Grid Margin="0,30,0,0" Width="300" HorizontalAlignment="Right" Height="220" VerticalAlignment="Top" Background="#FFE4E4E4">
|
||||
<TextBox HorizontalAlignment="Right" Height="20" Margin="0,10,20,0" TextWrapping="NoWrap" VerticalAlignment="Top" Width="200"
|
||||
FontSize="14" x:Name="IP"/>
|
||||
<TextBox HorizontalAlignment="Right" Height="20" Margin="0,40,20,0" TextWrapping="NoWrap" VerticalAlignment="Top" Width="200"
|
||||
FontSize="14" x:Name="MOD" IsEnabled="False"/>
|
||||
<TextBox HorizontalAlignment="Right" Height="20" Margin="0,70,20,0" TextWrapping="NoWrap" VerticalAlignment="Top" Width="200"
|
||||
FontSize="14" x:Name="NAME"/>
|
||||
<TextBox HorizontalAlignment="Right" Height="20" Margin="0,100,20,0" TextWrapping="NoWrap" VerticalAlignment="Top" Width="200"
|
||||
FontSize="14" x:Name="USER"/>
|
||||
<TextBox HorizontalAlignment="Right" Height="20" Margin="0,130,20,0" TextWrapping="NoWrap" VerticalAlignment="Top" Width="200"
|
||||
FontSize="14" x:Name="PAW"/>
|
||||
<TextBox HorizontalAlignment="Right" Height="20" Margin="0,160,20,0" TextWrapping="NoWrap" VerticalAlignment="Top" Width="200"
|
||||
FontSize="14" x:Name="TIMEMS"/>
|
||||
<TextBlock HorizontalAlignment="Right" Height="20" Margin="0,10,240,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="50"
|
||||
Text="地址" FontSize="16"/>
|
||||
<TextBlock HorizontalAlignment="Right" Height="20" Margin="0,40,240,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="50"
|
||||
Text="类型" FontSize="16"/>
|
||||
<TextBlock HorizontalAlignment="Right" Height="20" Margin="0,70,240,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="50"
|
||||
Text="数据库" FontSize="16"/>
|
||||
<TextBlock HorizontalAlignment="Right" Height="20" Margin="0,100,240,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="50"
|
||||
Text="账号" FontSize="16"/>
|
||||
<TextBlock HorizontalAlignment="Right" Height="20" Margin="0,130,240,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="50"
|
||||
Text="密码" FontSize="16"/>
|
||||
<TextBlock HorizontalAlignment="Right" Height="20" Margin="0,160,240,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="50"
|
||||
Text="周期(ms)" FontSize="16"/>
|
||||
<Button Content="保存" HorizontalAlignment="Right" Height="21" Margin="0,0,20,5" VerticalAlignment="Bottom" Width="100" Click="Button_Click"/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
@@ -16,6 +17,7 @@ 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;
|
||||
|
||||
@@ -49,40 +51,48 @@ namespace ProcessManageUI
|
||||
{
|
||||
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;
|
||||
|
||||
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();
|
||||
Datalog.AppendText(DateTime.Now.ToString("yyyy/MM/dd-HH:mm:ss") +" 开始转换");
|
||||
DyelotsBulkedRecipe_.Fill(DyelotsBulkedRecipe);
|
||||
|
||||
for (int i = DyelotsBulkedRecipe.Rows.Count; i > 0; i--)
|
||||
@@ -90,9 +100,11 @@ namespace ProcessManageUI
|
||||
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 + "'");//行
|
||||
DataRow[] rowdat = DyelotsBulkedRecipe.Select("Dyelot ='" + Dyelot + "' AND ReDye='"+ ReDye+ "' AND StepNumber ='"+ StepNumber+"'");//行
|
||||
|
||||
foreach (DataRow row in rowdat)//删除指定信息行
|
||||
{
|
||||
@@ -101,22 +113,37 @@ namespace ProcessManageUI
|
||||
int a = Product.Select("ProductCode = " + row.Field<string>("ProductCode")).First().Field<int>("ProductType");
|
||||
if (a > type_id) type_id = a;
|
||||
}
|
||||
catch (Exception) { }
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogGing.ERRDATA(ex);
|
||||
Datalog.AppendText(ex.ToString());
|
||||
}
|
||||
|
||||
gram += row.Field<double>("Grams");
|
||||
row.Delete();
|
||||
row.AcceptChanges();
|
||||
}
|
||||
string NAME = Gram.Select("Type='"+type_id +"' and min<'"+gram+"' and max>'"+gram+"'").First().Field<string>("name");
|
||||
|
||||
|
||||
|
||||
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 + "流程:"+ NAME);
|
||||
LogGing.LogGingDATA( "转换工单:" + Dyelot + "流程:");
|
||||
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}条");
|
||||
Datalog.AppendText("\n" + DateTime.Now.ToString("yyyy/MM/dd-HH:mm:ss") + $" 转换完成{Count}条");
|
||||
Count = 0;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -126,8 +153,19 @@ namespace ProcessManageUI
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user