@ -60,19 +60,20 @@ namespace formula_manage.Windows
Connstr_SC = "server=" + TEXT_SQLIP + ";database=" + TEXT_SQLNAME + ";User ID=" + TEXT_SQLUSER + ";Password=" + TEXT_SQLPASWOR ;
Connstr_SC = "server=" + TEXT_SQLIP + ";database=" + TEXT_SQLNAME + ";User ID=" + TEXT_SQLUSER + ";Password=" + TEXT_SQLPASWOR ;
}
}
string Stuff _sql = "SELECT Name ,MacGroup ,Capacity ,Volume ,Industry ,Categories ,Note FROM [Dispensing].[dbo].[MACHINE]" ; //查询语句
string MAC _sql = "SELECT Name ,MacGroup ,Capacity ,Volume ,Industry ,Categories ,Note FROM [Dispensing].[dbo].[MACHINE]" ; //查询语句
SqlConnection conn_SC = new SqlConnection ( Connstr_SC ) ; //实例化
SqlConnection conn_SC = new SqlConnection ( Connstr_SC ) ; //实例化
try
try
{
{
await conn_SC . OpenAsync ( ) ; //打开数据连接
await conn_SC . OpenAsync ( ) ; //打开数据连接
SqlDataAdapter Stuff_data = new SqlDataAdapter ( Stuff _sql, Connstr_SC ) ; //查询
SqlDataAdapter Stuff_data = new SqlDataAdapter ( MAC _sql, Connstr_SC ) ; //查询
DataTable dataTable = new DataTable ( ) ; //建立缓存
DataTable dataTable = new DataTable ( ) ; //建立缓存
Stuff_data . Fill ( dataTable ) ; //查询结果存入缓存
Stuff_data . Fill ( dataTable ) ; //查询结果存入缓存
conn_SC . Close ( ) ; //关闭连接
conn_SC . Close ( ) ; //关闭连接
DataGridMac . ItemsSource = dataTable . DefaultView ; //数据加入表格
DataGridMac . ItemsSource = dataTable . DefaultView ; //数据加入表格
DataGridMac . DisplayMemberPath = "Name" ;
}
}
catch ( Exception )
catch ( Exception )
{
{
@ -94,14 +95,14 @@ namespace formula_manage.Windows
/// </summary>
/// </summary>
private async void GridSql ( )
private async void GridSql ( )
{
{
string Stuff _sql = "SELECT Name ,MacGroup ,Capacity ,Volume ,Industry ,Categories ,Note FROM [Dispensing].[dbo].[MACHINE]" ; //查询语句
string MAC _sql = "SELECT Name ,MacGroup ,Capacity ,Volume ,Industry ,Categories ,Note FROM [Dispensing].[dbo].[MACHINE]" ; //查询语句
SqlConnection conn_SC = new SqlConnection ( Connstr_SC ) ; //实例化
SqlConnection conn_SC = new SqlConnection ( Connstr_SC ) ; //实例化
try
try
{
{
await conn_SC . OpenAsync ( ) ; //打开数据连接
await conn_SC . OpenAsync ( ) ; //打开数据连接
SqlDataAdapter Stuff_data = new SqlDataAdapter ( Stuff _sql, Connstr_SC ) ; //查询
SqlDataAdapter Stuff_data = new SqlDataAdapter ( MAC _sql, Connstr_SC ) ; //查询
DataTable dataTable = new DataTable ( ) ; //建立缓存
DataTable dataTable = new DataTable ( ) ; //建立缓存
Stuff_data . Fill ( dataTable ) ; //查询结果存入缓存
Stuff_data . Fill ( dataTable ) ; //查询结果存入缓存
@ -150,7 +151,7 @@ namespace formula_manage.Windows
string Mac_industry = mac_Industry . Text ;
string Mac_industry = mac_Industry . Text ;
string Mac_categories = mac_Categories . Text ;
string Mac_categories = mac_Categories . Text ;
string Mac_note = mac_Note . Text ;
string Mac_note = mac_Note . Text ;
string Stuff _sql;
string MAC _sql;
if ( Mac_industry = = "浸染" ) Mac_industry = "0" ;
if ( Mac_industry = = "浸染" ) Mac_industry = "0" ;
else if ( Mac_industry = = "连染" ) Mac_industry = "1" ;
else if ( Mac_industry = = "连染" ) Mac_industry = "1" ;
@ -174,18 +175,18 @@ namespace formula_manage.Windows
try
try
{
{
SqlConnection conn_SC = new SqlConnection ( Connstr_SC ) ; //实例化
SqlConnection conn_SC = new SqlConnection ( Connstr_SC ) ; //实例化
Stuff _sql = "SELECT count(*) FROM [Dispensing].[dbo].[MACHINE] WHERE Name = '" + Mac_name + " '" ; //查询语句
MAC _sql = "SELECT count(*) FROM [Dispensing].[dbo].[MACHINE] WHERE Name = '" + Mac_name + " '" ; //查询语句
await conn_SC . OpenAsync ( ) ; //打开数据连
await conn_SC . OpenAsync ( ) ; //打开数据连
SqlCommand cmd = new SqlCommand ( Stuff _sql, conn_SC ) ; //查询记录数
SqlCommand cmd = new SqlCommand ( MAC _sql, conn_SC ) ; //查询记录数
int count = Convert . ToInt32 ( cmd . ExecuteScalar ( ) ) ; //显示记录数
int count = Convert . ToInt32 ( cmd . ExecuteScalar ( ) ) ; //显示记录数
conn_SC . Close ( ) ; //关闭连接
conn_SC . Close ( ) ; //关闭连接
if ( count = = 0 )
if ( count = = 0 )
{
{
Stuff _sql = string . Format ( "INSERT INTO[Dispensing].[dbo].[MACHINE](Name ,MacGroup ,Capacity ,Volume ,Industry ,Categories ,Note ) " +
MAC _sql = string . Format ( "INSERT INTO[Dispensing].[dbo].[MACHINE](Name ,MacGroup ,Capacity ,Volume ,Industry ,Categories ,Note ) " +
"VALUES ('" + Mac_name + "','" + Mac_group + "'," + Mac_capacity + "," + Mac_volume + "," + Mac_industry + "," + Mac_categories + ",'" + Mac_note + "')" ) ;
"VALUES ('" + Mac_name + "','" + Mac_group + "'," + Mac_capacity + "," + Mac_volume + "," + Mac_industry + "," + Mac_categories + ",'" + Mac_note + "')" ) ;
await conn_SC . OpenAsync ( ) ; //打开数据连接
await conn_SC . OpenAsync ( ) ; //打开数据连接
SqlCommand INSERT_cmd = new SqlCommand ( Stuff _sql, conn_SC ) ;
SqlCommand INSERT_cmd = new SqlCommand ( MAC _sql, conn_SC ) ;
int sql_in = INSERT_cmd . ExecuteNonQuery ( ) ; //执行语句
int sql_in = INSERT_cmd . ExecuteNonQuery ( ) ; //执行语句
conn_SC . Close ( ) ; //关闭连接
conn_SC . Close ( ) ; //关闭连接
if ( sql_in = = 0 )
if ( sql_in = = 0 )
@ -199,9 +200,9 @@ namespace formula_manage.Windows
}
}
else
else
{
{
Stuff _sql = string . Format ( "UPDATE [dbo].[MACHINE] SET MacGroup ='" + Mac_group + "',Capacity=" + Mac_capacity + " ,Volume=" + Mac_volume + " ,Industry=" + Mac_industry + " ,Categories=" + Mac_categories + " ,Note='" + Mac_note + "' Where Name ='" + Mac_name + "'" ) ;
MAC _sql = string . Format ( "UPDATE [dbo].[MACHINE] SET MacGroup ='" + Mac_group + "',Capacity=" + Mac_capacity + " ,Volume=" + Mac_volume + " ,Industry=" + Mac_industry + " ,Categories=" + Mac_categories + " ,Note='" + Mac_note + "' Where Name ='" + Mac_name + "'" ) ;
await conn_SC . OpenAsync ( ) ; //打开数据连接
await conn_SC . OpenAsync ( ) ; //打开数据连接
SqlCommand INSERT_cmd = new SqlCommand ( Stuff _sql, conn_SC ) ;
SqlCommand INSERT_cmd = new SqlCommand ( MAC _sql, conn_SC ) ;
int sql_in = INSERT_cmd . ExecuteNonQuery ( ) ; //执行语句
int sql_in = INSERT_cmd . ExecuteNonQuery ( ) ; //执行语句
conn_SC . Close ( ) ; //关闭连接
conn_SC . Close ( ) ; //关闭连接