diff --git a/ConvertMoels/IonSQLConvert.cs b/ConvertMoels/IonSQLConvert.cs new file mode 100644 index 0000000..8e15f10 --- /dev/null +++ b/ConvertMoels/IonSQLConvert.cs @@ -0,0 +1,74 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Data; + +namespace formula_manage.ConvertMoels +{ + internal class IonSQLConvert : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + string stuff_ion = System.Convert.ToString(value); + if (stuff_ion == "0")//类型 + { + return "分散"; + } + else + { + if (stuff_ion == "1") + { + return "酸性"; + } + else + { + if (stuff_ion == "2") + { + return "活性"; + } + else + { + if (stuff_ion == "3") + { + return "硫化"; + } + else + { + if (stuff_ion == "4") + { + return "阳离子"; + } + else + { + if (stuff_ion == "5") + { + return "酞菁"; + } + else + { + if (stuff_ion == "6") + { + return "直接"; + } + else + { + return "未知类型"; + } + } + } + } + } + } + } + } + /// + /// + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + return null; + } + } +} diff --git a/MainWindow.xaml b/MainWindow.xaml index f0b2242..91d2646 100644 --- a/MainWindow.xaml +++ b/MainWindow.xaml @@ -158,7 +158,7 @@ - @@ -171,6 +171,7 @@ + diff --git a/Windows/Stuff.xaml b/Windows/Stuff.xaml index 1a7200f..122baee 100644 --- a/Windows/Stuff.xaml +++ b/Windows/Stuff.xaml @@ -7,12 +7,13 @@ xmlns:ConvertMoels="clr-namespace:formula_manage.ConvertMoels" xmlns:viewmodel="clr-namespace:formula_manage.ViewModel" mc:Ignorable="d" Loaded="Stuff_Loaded" - Title="Stuff" Height="720" Width="1100" MaxHeight="720" MaxWidth="1100" MinHeight="720" MinWidth="1100" + Title="Stuff" Height="720" Width="1200" MaxHeight="720" MaxWidth="1200" MinHeight="720" MinWidth="1200" BorderBrush="White" Background="#FFE0E0E0"> + @@ -60,9 +61,7 @@ - - - + - + + + + + + + - - - + + + + + - - - - - - - + + + + + + + + + + + @@ -132,24 +154,24 @@ - - - - - - diff --git a/Windows/Stuff.xaml.cs b/Windows/Stuff.xaml.cs index 04c264b..da643c1 100644 --- a/Windows/Stuff.xaml.cs +++ b/Windows/Stuff.xaml.cs @@ -62,7 +62,7 @@ namespace formula_manage.Windows Connstr_SC = "server=" + TEXT_SQLIP + ";database=" + TEXT_SQLNAME + ";User ID=" + TEXT_SQLUSER + ";Password=" + TEXT_SQLPASWOR; } - string Stuff_sql = "SELECT ProductCode ,ProductName , Price , SUPPLIER ,ProductType ,Color ,Concentration , GRAVITY FROM [Dispensing].[dbo].[PRODUCT]";//查询语句 + string Stuff_sql = "SELECT ProductCode ,ProductName , Price , SUPPLIER ,ProductType ,Color ,Concentration , GRAVITY ,ProductIon_Type FROM [Dispensing].[dbo].[PRODUCT]";//查询语句 SqlConnection conn_SC = new SqlConnection(Connstr_SC); //实例化 try @@ -128,11 +128,11 @@ namespace formula_manage.Windows private async void GridSql(int e ) { string Stuff_sql = null; - if (e == 0) Stuff_sql = "SELECT ProductCode ,ProductName , Price , SUPPLIER ,ProductType ,Color ,Concentration , GRAVITY FROM [Dispensing].[dbo].[PRODUCT]";//查询语句 - else if (e == 1) Stuff_sql = "SELECT ProductCode ,ProductName , Price , SUPPLIER ,ProductType ,Color ,Concentration , GRAVITY FROM [Dispensing].[dbo].[PRODUCT] Where ProductType = '0' "; - else if (e == 2) Stuff_sql = "SELECT ProductCode ,ProductName , Price , SUPPLIER ,ProductType ,Color ,Concentration , GRAVITY FROM [Dispensing].[dbo].[PRODUCT] Where ProductType = '1' "; - else if (e == 3) Stuff_sql = "SELECT ProductCode ,ProductName , Price , SUPPLIER ,ProductType ,Color ,Concentration , GRAVITY FROM [Dispensing].[dbo].[PRODUCT] Where ProductType = '2' "; - else if (e == 4) Stuff_sql = "SELECT ProductCode ,ProductName , Price , SUPPLIER ,ProductType ,Color ,Concentration , GRAVITY FROM [Dispensing].[dbo].[PRODUCT] Where ProductType = '3' "; + if (e == 0) Stuff_sql = "SELECT ProductCode ,ProductName , Price , SUPPLIER ,ProductType ,Color ,Concentration , GRAVITY ,ProductIon_Type FROM [Dispensing].[dbo].[PRODUCT]";//查询语句 + else if (e == 1) Stuff_sql = "SELECT ProductCode ,ProductName , Price , SUPPLIER ,ProductType ,Color ,Concentration , GRAVITY ,ProductIon_Type FROM [Dispensing].[dbo].[PRODUCT] Where ProductType = '0' "; + else if (e == 2) Stuff_sql = "SELECT ProductCode ,ProductName , Price , SUPPLIER ,ProductType ,Color ,Concentration , GRAVITY ,ProductIon_Type FROM [Dispensing].[dbo].[PRODUCT] Where ProductType = '1' "; + else if (e == 3) Stuff_sql = "SELECT ProductCode ,ProductName , Price , SUPPLIER ,ProductType ,Color ,Concentration , GRAVITY ,ProductIon_Type FROM [Dispensing].[dbo].[PRODUCT] Where ProductType = '2' "; + else if (e == 4) Stuff_sql = "SELECT ProductCode ,ProductName , Price , SUPPLIER ,ProductType ,Color ,Concentration , GRAVITY ,ProductIon_Type FROM [Dispensing].[dbo].[PRODUCT] Where ProductType = '3' "; SqlConnection conn_SC = new SqlConnection(Connstr_SC); //实例化 @@ -159,6 +159,7 @@ namespace formula_manage.Windows Regex re_number = new Regex(@"^[0-9]+(.[0-9]{1,2})?$");//校验用正则表达式有1~2位小数的正实数 Regex re_char = new Regex(@"^[A-Za-z0-9\s@()()/+!!_-]+$");//校验用正则表达式由数字,26个英文字母,空白字符和@()()/+!!_-组成的字符串 int int_stuff_ProductType = 0; + int int_stuff_ion = 0; int ColorCode_SQL; string Stuff_sql; string Product_Code = stuff_ProductCode.Text.ToString(); @@ -177,8 +178,16 @@ namespace formula_manage.Windows else if (this.stuff_ProductType.Text == "液体染料") int_stuff_ProductType = 3; - if ((re_number.IsMatch(this.stuff_Price.Text) == false)&&(stuff_Price.Text != "")) - System.Windows.MessageBox.Show("ERR:价格信息错误", "错误");//检查价格输入信息 + if(stuff_ion.Text == "分散") int_stuff_ion = 0; + else if (stuff_ion.Text == "酸性") int_stuff_ion = 1; + else if (stuff_ion.Text == "活性") int_stuff_ion = 2; + else if (stuff_ion.Text == "硫化") int_stuff_ion = 3; + else if (stuff_ion.Text == "阳离子") int_stuff_ion = 4; + else if (stuff_ion.Text == "酞菁") int_stuff_ion = 5; + else if (stuff_ion.Text == "直接") int_stuff_ion = 6; + + if ((re_number.IsMatch(this.stuff_Price.Text) == false) && (stuff_Price.Text != "")) + System.Windows.MessageBox.Show("ERR:价格信息错误", "错误");//检查价格输入信息 if (re_char.IsMatch(this.stuff_ProductCode.Text) == false) System.Windows.MessageBox.Show("ERR:无效的原料信息", "错误");//检查原料代码 else @@ -235,6 +244,11 @@ namespace formula_manage.Windows await conn_SC.OpenAsync(); //打开数据连接 SqlCommand INSERT_cmd = new SqlCommand(Stuff_sql, conn_SC); int sql_in = INSERT_cmd.ExecuteNonQuery(); //执行语句 + + if(stuff_ion.Text !="")Stuff_sql = string.Format("UPDATE [dbo].[PRODUCT] SET [ProductIon_Type] ="+ int_stuff_ion + " Where ProductCode='" + Product_Code + "'"); + SqlCommand Stuff_sql_cmd = new SqlCommand(Stuff_sql, conn_SC); + INSERT_cmd.ExecuteNonQuery(); //执行语句 + conn_SC.Close(); //关闭连接 if (sql_in == 0) { @@ -255,6 +269,11 @@ namespace formula_manage.Windows await conn_SC.OpenAsync(); //打开数据连接 SqlCommand INSERT_cmd = new SqlCommand(Stuff_sql, conn_SC); int sql_in = INSERT_cmd.ExecuteNonQuery(); //执行语句 + + if (stuff_ion.Text != "") Stuff_sql = string.Format("UPDATE [dbo].[PRODUCT] SET [ProductIon_Type] =" + int_stuff_ion + " Where ProductCode='" + Product_Code + "'"); + SqlCommand Stuff_sql_cmd = new SqlCommand(Stuff_sql, conn_SC); + INSERT_cmd.ExecuteNonQuery(); //执行语句 + conn_SC.Close(); //关闭连接 if (sql_in == 0) { @@ -323,19 +342,20 @@ namespace formula_manage.Windows /*定位选中行及指定列单元格文本信息*/ string DataGridStuff_ProductCode = (DataGridStuff.Columns[1].GetCellContent(DataGridStuff.Items[rownum]) as TextBlock).Text;//定位第0列,原料代码 string DataGridStuff_ProductName = (DataGridStuff.Columns[2].GetCellContent(DataGridStuff.Items[rownum]) as TextBlock).Text;//定位第1列,原料名称 - string DataGridStuff_Price = (DataGridStuff.Columns[3].GetCellContent(DataGridStuff.Items[rownum]) as TextBlock).Text;//定位第2列,价格 - string DataGridstuff_SUPPLIER = (DataGridStuff.Columns[4].GetCellContent(DataGridStuff.Items[rownum]) as TextBlock).Text;//定位第3列,供应商 - string DataGridStuff_ProductType = (DataGridStuff.Columns[5].GetCellContent(DataGridStuff.Items[rownum]) as TextBlock).Text;//定位第4列,类型 - //string DataGridStuff_Color = (DataGridStuff.Columns[6].GetCellContent(DataGridStuff.Items[rownum])as TextBlock).Text;//定位第5列,色彩 - string DataGridStuff_Concentration = (DataGridStuff.Columns[7].GetCellContent(DataGridStuff.Items[rownum]) as TextBlock).Text;//定位第6列选中行单元格文本信息并去除空白字符,浓度 - string DataGridStuff_GRAVITY = (DataGridStuff.Columns[8].GetCellContent(DataGridStuff.Items[rownum]) as TextBlock).Text;//定位第7列,比重 - /*stuff_Color.Background = (DataGridStuff.Columns[6].GetCellContent(DataGridStuff.Items[rownum]) as TextBlock).Background;//定位第5列,色彩,背景色传递至色彩框背景色*/ + string DataGridStuff_Price = (DataGridStuff.Columns[8].GetCellContent(DataGridStuff.Items[rownum]) as TextBlock).Text;//定位,价格 + string DataGridstuff_SUPPLIER = (DataGridStuff.Columns[9].GetCellContent(DataGridStuff.Items[rownum]) as TextBlock).Text;//定位,供应商 + string DataGridStuff_ProductType = (DataGridStuff.Columns[3].GetCellContent(DataGridStuff.Items[rownum]) as TextBlock).Text;//定位,类型 //string DataGridStuff_Color = (DataGridStuff.Columns[6].GetCellContent(DataGridStuff.Items[rownum])as TextBlock).Text;//定位,色彩 + string DataGridStuff_Concentration = (DataGridStuff.Columns[6].GetCellContent(DataGridStuff.Items[rownum]) as TextBlock).Text;//定位选中行单元格文本信息 + string DataGridStuff_stuff_ion = (DataGridStuff.Columns[4].GetCellContent(DataGridStuff.Items[rownum]) as TextBlock).Text;//定位选中行单元格文本信息并去除空白字符,浓度 + string DataGridStuff_GRAVITY = (DataGridStuff.Columns[7].GetCellContent(DataGridStuff.Items[rownum]) as TextBlock).Text;//定位,比重 + /*stuff_Color.Background = (DataGridStuff.Columns[6].GetCellContent(DataGridStuff.Items[rownum]) as TextBlock).Background;//定位,色彩,背景色传递至色彩框背景色*/ /*填写信息至指定文本框*/ //product_temp.ProductCode = DataGridStuff_ProductCode;//写入sql实体缓存 stuff_ProductCode.Text = DataGridStuff_ProductCode.Trim();//原料代码,去除空白字符 stuff_ProductName.Text = DataGridStuff_ProductName.Trim();//原料名称,去除空白字符 stuff_Price.Text = DataGridStuff_Price;//价格 stuff_ProductType.Text = DataGridStuff_ProductType;//类型 + stuff_ion.Text = DataGridStuff_stuff_ion; stuff_SUPPLIER.Text = DataGridstuff_SUPPLIER;//供应商 /*stuff_Color.Text = DataGridStuff_Color;//色彩数据*/ stuff_Concentration.Text = DataGridStuff_Concentration;//浓度 @@ -343,9 +363,9 @@ namespace formula_manage.Windows /*if (DataGridStuff_ProductType.ToString() == "0") stuff_ProductType.Text = "染料";//判断类型1-染料。2-助剂。3-粉体助剂。 if (DataGridStuff_ProductType.ToString() == "1") stuff_ProductType.Text = "助剂"; if (DataGridStuff_ProductType.ToString() == "2") stuff_ProductType.Text = "粉体助剂";*/ - if ((DataGridStuff.Columns[6].GetCellContent(DataGridStuff.Items[rownum]) as TextBlock).Background != null) //定位第5列选中行单元格,色彩,判断参数是否有效 + if ((DataGridStuff.Columns[5].GetCellContent(DataGridStuff.Items[rownum]) as TextBlock).Background != null) //定位选中行单元格,色彩,判断参数是否有效 { - stuff_Color.Background = (DataGridStuff.Columns[6].GetCellContent(DataGridStuff.Items[rownum]) as TextBlock).Background; //定位第5列选中行单元格,色彩,有效背景色传递至色彩框背景色 + stuff_Color.Background = (DataGridStuff.Columns[5].GetCellContent(DataGridStuff.Items[rownum]) as TextBlock).Background; //定位选中行单元格,色彩,有效背景色传递至色彩框背景色 } else { diff --git a/formula_manage.csproj b/formula_manage.csproj index 3689c05..2285f2c 100644 --- a/formula_manage.csproj +++ b/formula_manage.csproj @@ -166,6 +166,7 @@ +