diff --git a/Windows/Stuff.xaml b/Windows/Stuff.xaml index f26495b..9fb8805 100644 --- a/Windows/Stuff.xaml +++ b/Windows/Stuff.xaml @@ -121,8 +121,7 @@ VerticalAlignment="Bottom" Width="50" FontSize="20"/> + VerticalAlignment="Bottom" Width="130" FontSize="22" MaxLines="1" MaxLength="25"/> diff --git a/Windows/Stuff.xaml.cs b/Windows/Stuff.xaml.cs index 45b2819..df9beb1 100644 --- a/Windows/Stuff.xaml.cs +++ b/Windows/Stuff.xaml.cs @@ -131,12 +131,12 @@ namespace formula_manage.Windows int int_stuff_ProductType = 0; int ColorCode_SQL; string Stuff_sql; - string Product_Code = stuff_ProductCode.Text; - string Product_Name = stuff_ProductName.Text; - string _Price = stuff_Price.Text; - string _SUPPLIER = stuff_SUPPLIER.Text; - string _Concentration = stuff_Concentration.Text; - string _GRAVITY = stuff_GRAVITY.Text; + string Product_Code = stuff_ProductCode.Text.ToString(); + string Product_Name = stuff_ProductName.Text.ToString(); + string _Price = stuff_Price.Text.ToString(); + string _SUPPLIER = stuff_SUPPLIER.Text.ToString(); + string _Concentration = stuff_Concentration.Text.ToString(); + string _GRAVITY = stuff_GRAVITY.Text.ToString(); if (this.stuff_ProductType.Text == "染料") //原料类型0。染料,1助剂,2粉体 int_stuff_ProductType = 0; @@ -147,71 +147,76 @@ 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 (re_char.IsMatch(this.stuff_ProductCode.Text) == false) - System.Windows.MessageBox.Show("ERR.C0101:无效的原料信息", "错误");//检查原料代码 + System.Windows.MessageBox.Show("ERR:无效的原料信息", "错误");//检查原料代码 else if (string.IsNullOrEmpty(this.stuff_ProductName.Text)) - System.Windows.MessageBox.Show("ERR.C0101-2:无效的原料信息", "错误");//检查原料名称 + System.Windows.MessageBox.Show("ERR:无效的原料名称", "错误");//检查原料名称 else if (string.IsNullOrEmpty(this.stuff_ProductType.Text)) - System.Windows.MessageBox.Show("ERR.C0101-3:无效的原料信息", "错误");//检查原料类型 + System.Windows.MessageBox.Show("ERR:无效的原料类型", "错误");//检查原料类型 else if (string.IsNullOrEmpty(this.stuff_GRAVITY.Text)) - System.Windows.MessageBox.Show("ERR.C0101-1:无效的原料信息", "错误");//检查原料比重 + System.Windows.MessageBox.Show("ERR:无效的比重", "错误");//检查原料比重 else if (re_number.IsMatch(this.stuff_GRAVITY.Text) == false) - System.Windows.MessageBox.Show("ERR.C0102-1:原料信息错误", "错误");//检查比重输入信息 + System.Windows.MessageBox.Show("ERR:比重信息错误", "错误");//检查比重输入信息 else if (re_number.IsMatch(this.stuff_Concentration.Text) == false) - System.Windows.MessageBox.Show("ERR.C0102-3:原料信息错误", "错误");//检查浓度输入信息 + System.Windows.MessageBox.Show("ERR:浓度错误", "错误");//检查浓度输入信息 else if (float.Parse(this.stuff_GRAVITY.Text) < 0 || float.Parse(this.stuff_GRAVITY.Text) > 5) - System.Windows.MessageBox.Show("ERR.C0102-2:原料信息错误", "错误");//检查比重输入数值 + System.Windows.MessageBox.Show("ERR:比重错误", "错误");//检查比重输入数值 else if (float.Parse(this.stuff_Concentration.Text) < 0 || float.Parse(this.stuff_Concentration.Text) > 100) - System.Windows.MessageBox.Show("ERR.C0102-4:原料信息错误", "错误");//检查浓度输入数值 - else - { - - if (int_stuff_ProductType == 0 || int_stuff_ProductType == 3)//判断是否为染料,非染料写空 - { - string colorValue = stuff_Color.Background.ToString();//获取色彩框背景色"#FFC1C2C3" - string StuffColor_R = string.Format("{0:X2}", colorValue.Substring(3, 2));//获取红色参数C1 - string StuffColor_G = string.Format("{0:X2}", colorValue.Substring(5, 2));//获取绿色参数C2 - string StuffColor_B = string.Format("{0:X2}", colorValue.Substring(7, 2));//获取蓝色参数C3 - string StuffColor = StuffColor_B + StuffColor_G + StuffColor_R;//合并16进制rgb参数 - ColorCode_SQL = Convert.ToInt32(StuffColor, 16);//16进制转10进制 - if (ColorCode_SQL < 0) ColorCode_SQL = 16777215;//判断色彩数据是否有效 - } - else - { - ColorCode_SQL = 16777215; - } - - if (stuff_SUPPLIER.Text == null) _SUPPLIER = "null"; - if (stuff_Price.Text == null) _Price = "null"; - - SqlConnection conn_SC = new SqlConnection(Connstr_SC); //实例化 - Stuff_sql = "SELECT ProductCode FROM [Dispensing].[dbo].[PRODUCT] WHERE ProductCode = '" + Product_Code + " '";//查询语句 - - await conn_SC.OpenAsync(); //打开数据连接 - SqlCommand cmd = new SqlCommand(Stuff_sql, conn_SC); //查询记录数 - int count = Convert.ToInt32(cmd.ExecuteScalar()); //显示记录数 - conn_SC.Close(); //关闭连接 - - if (count == 0) - { - Stuff_sql = "INSERT INTO[Dispensing].[dbo].[PRODUCT](ProductCode ,ProductName , Price , SUPPLIER ,ProductType ,Color ,Concentration , GRAVITY ) " + - "VALUES (" + Product_Code + "," + Product_Name + "," + _Price + "," + _SUPPLIER + "," + int_stuff_ProductType + "," + ColorCode_SQL + "," + _Concentration + "," + _GRAVITY + ")"; + System.Windows.MessageBox.Show("ERR:浓度错误", "错误");//检查浓度输入数值 + else + { + try + { + if (int_stuff_ProductType == 0 || int_stuff_ProductType == 3)//判断是否为染料,非染料写空 + { + string colorValue = stuff_Color.Background.ToString();//获取色彩框背景色"#FFC1C2C3" + string StuffColor_R = string.Format("{0:X2}", colorValue.Substring(3, 2));//获取红色参数C1 + string StuffColor_G = string.Format("{0:X2}", colorValue.Substring(5, 2));//获取绿色参数C2 + string StuffColor_B = string.Format("{0:X2}", colorValue.Substring(7, 2));//获取蓝色参数C3 + string StuffColor = StuffColor_B + StuffColor_G + StuffColor_R;//合并16进制rgb参数 + ColorCode_SQL = Convert.ToInt32(StuffColor, 16);//16进制转10进制 + if (ColorCode_SQL < 0) ColorCode_SQL = 16777215;//判断色彩数据是否有效 + } + else + { + ColorCode_SQL = 16777215; + } + + SqlConnection conn_SC = new SqlConnection(Connstr_SC); //实例化 + Stuff_sql = "SELECT ProductCode FROM [Dispensing].[dbo].[PRODUCT] WHERE ProductCode = '" + Product_Code + " '";//查询语句 + await conn_SC.OpenAsync(); //打开数据连 + SqlCommand cmd = new SqlCommand(Stuff_sql, conn_SC); //查询记录数 + int count = Convert.ToInt32(cmd.ExecuteScalar()); //显示记录数 + conn_SC.Close(); //关闭连接 + if (count == 0) + { + Stuff_sql = string.Format( "INSERT INTO[Dispensing].[dbo].[PRODUCT](ProductCode ,ProductName , Price , SUPPLIER ,ProductType ,Color ,Concentration , GRAVITY ) " + + "VALUES ('" + Product_Code + "','" + Product_Name + "','" + _Price + "','" + _SUPPLIER + "','" + int_stuff_ProductType + "','" + ColorCode_SQL + "','" + _Concentration + "','" + _GRAVITY + "')"); + await conn_SC.OpenAsync(); //打开数据连接 + SqlCommand INSERT_cmd = new SqlCommand(Stuff_sql, conn_SC); //执行语句 + int INSERT_count = Convert.ToInt32(INSERT_cmd.ExecuteScalar()); //显示记录数 + conn_SC.Close(); //关闭连接 + } + else + { - await conn_SC.OpenAsync(); //打开数据连接 - SqlCommand INSERT_cmd = new SqlCommand(Stuff_sql, conn_SC); //查询记录数 - int INSERT_count = Convert.ToInt32(INSERT_cmd.ExecuteScalar()); //显示记录数 - conn_SC.Close(); //关闭连接 + + } } - else + catch (Exception) { - + System.Windows.MessageBox.Show("请求原料信息失败,检查连接"); + return; } } /* else