Merge branch 'master' of http://www.scserverddns.top:13000/sc/formula_manage
This commit is contained in:
commit
97bef42947
1 file changed
+115
-81
+115
-81
@@ -17,6 +17,8 @@ using formula_manage.SQLModels;
|
||||
using System.Data.SqlClient;
|
||||
using System.Data;
|
||||
using System.Windows.Forms;
|
||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Button;
|
||||
using Xceed.Wpf.AvalonDock.Themes;
|
||||
|
||||
namespace formula_manage.Windows
|
||||
{
|
||||
@@ -27,6 +29,7 @@ namespace formula_manage.Windows
|
||||
{
|
||||
|
||||
public string INIPath = Convert.ToString(System.AppDomain.CurrentDomain.BaseDirectory) + "formula.ini"; //配置文件路径
|
||||
int Button_ID = 0;
|
||||
|
||||
string TEXT_SQLIP;
|
||||
string TEXT_SQLNAME;
|
||||
@@ -35,7 +38,7 @@ namespace formula_manage.Windows
|
||||
string TEXT_SQLPASWOR;
|
||||
string Connstr_SC;
|
||||
|
||||
public Stuff()
|
||||
public Stuff()
|
||||
{
|
||||
WindowStartupLocation = WindowStartupLocation.CenterScreen;
|
||||
InitializeComponent();
|
||||
@@ -66,7 +69,7 @@ namespace formula_manage.Windows
|
||||
try
|
||||
{
|
||||
await conn_SC.OpenAsync(); //打开数据连接
|
||||
SqlDataAdapter Stuff_data = new SqlDataAdapter(Stuff_sql,Connstr_SC); //查询
|
||||
SqlDataAdapter Stuff_data = new SqlDataAdapter(Stuff_sql, Connstr_SC); //查询
|
||||
|
||||
DataTable dataTable = new DataTable(); //建立缓存
|
||||
Stuff_data.Fill(dataTable); //查询结果存入缓存
|
||||
@@ -78,34 +81,59 @@ namespace formula_manage.Windows
|
||||
{
|
||||
System.Windows.MessageBox.Show("请求原料信息失败,检查连接");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 生成序列号的方法
|
||||
/// </summary>
|
||||
private void DataGridEquipment_LoadingRow(object sender, DataGridRowEventArgs e)
|
||||
{
|
||||
// e.Row.Header = e.Row.GetIndex() + 1;
|
||||
// e.Row.Header = e.Row.GetIndex() + 1;
|
||||
}
|
||||
|
||||
private async void Radiobutton(object sender, EventArgs e)
|
||||
private void Radiobutton(object sender, EventArgs e)
|
||||
{
|
||||
string Stuff_sql = null;
|
||||
System.Windows.Controls.RadioButton Radiobutton = (sender as System.Windows.Controls.RadioButton);
|
||||
string radiobutton = Radiobutton.Content.ToString();
|
||||
if (radiobutton == "全部原料")
|
||||
Stuff_sql = "SELECT ProductCode ,ProductName , Price , SUPPLIER ,ProductType ,Color ,Concentration , GRAVITY FROM [Dispensing].[dbo].[PRODUCT]";//查询语句
|
||||
else if (radiobutton == "染料")
|
||||
Stuff_sql = "SELECT ProductCode ,ProductName , Price , SUPPLIER ,ProductType ,Color ,Concentration , GRAVITY FROM [Dispensing].[dbo].[PRODUCT] Where ProductType = '0' ";
|
||||
else if (radiobutton == "助剂")
|
||||
Stuff_sql = "SELECT ProductCode ,ProductName , Price , SUPPLIER ,ProductType ,Color ,Concentration , GRAVITY FROM [Dispensing].[dbo].[PRODUCT] Where ProductType = '1' ";
|
||||
else if (radiobutton == "粉体助剂")
|
||||
Stuff_sql = "SELECT ProductCode ,ProductName , Price , SUPPLIER ,ProductType ,Color ,Concentration , GRAVITY FROM [Dispensing].[dbo].[PRODUCT] Where ProductType = '2' ";
|
||||
else if (radiobutton == "液体染料")
|
||||
Stuff_sql = "SELECT ProductCode ,ProductName , Price , SUPPLIER ,ProductType ,Color ,Concentration , GRAVITY FROM [Dispensing].[dbo].[PRODUCT] Where ProductType = '3' ";
|
||||
{
|
||||
GridSql(0);
|
||||
Button_ID = 0;
|
||||
}
|
||||
else if (radiobutton == "染料")
|
||||
{
|
||||
GridSql(1);
|
||||
Button_ID = 1;
|
||||
}
|
||||
else if (radiobutton == "助剂")
|
||||
{
|
||||
GridSql(2);
|
||||
Button_ID = 2;
|
||||
}
|
||||
else if (radiobutton == "粉体助剂")
|
||||
{
|
||||
GridSql(3);
|
||||
Button_ID = 3;
|
||||
}
|
||||
else if (radiobutton == "液体染料")
|
||||
{
|
||||
GridSql(4);
|
||||
Button_ID = 4;
|
||||
}
|
||||
}
|
||||
|
||||
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' ";
|
||||
|
||||
SqlConnection conn_SC = new SqlConnection(Connstr_SC); //实例化
|
||||
|
||||
try
|
||||
{
|
||||
await conn_SC.OpenAsync(); //打开数据连接
|
||||
@@ -193,93 +221,99 @@ namespace formula_manage.Windows
|
||||
}
|
||||
|
||||
SqlConnection conn_SC = new SqlConnection(Connstr_SC); //实例化
|
||||
Stuff_sql = "SELECT ProductCode FROM [Dispensing].[dbo].[PRODUCT] WHERE ProductCode = '" + Product_Code + " '";//查询语句
|
||||
Stuff_sql = "SELECT count(*) 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(); //关闭连接
|
||||
SqlCommand INSERT_cmd = new SqlCommand(Stuff_sql, conn_SC);
|
||||
int sql_in = INSERT_cmd.ExecuteNonQuery(); //执行语句
|
||||
conn_SC.Close(); //关闭连接
|
||||
if (sql_in == 0)
|
||||
{
|
||||
System.Windows.MessageBox.Show("添加失败");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Button_ID == 0) GridSql(0);
|
||||
else if (Button_ID == 1) GridSql(1);
|
||||
else if (Button_ID == 2) GridSql(2);
|
||||
else if (Button_ID == 3) GridSql(3);
|
||||
else if (Button_ID == 4) GridSql(4);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
|
||||
Stuff_sql = string.Format("UPDATE [dbo].[PRODUCT] SET ProductName='" + Product_Name + "',Price='" + _Price + "',SUPPLIER='" + _SUPPLIER + "',ProductType=" + int_stuff_ProductType + ",Color=" + ColorCode_SQL + ",Concentration=" + _Concentration + ",GRAVITY=" + _GRAVITY + " Where ProductCode='"+ Product_Code+"'");
|
||||
await conn_SC.OpenAsync(); //打开数据连接
|
||||
SqlCommand INSERT_cmd = new SqlCommand(Stuff_sql, conn_SC);
|
||||
int sql_in = INSERT_cmd.ExecuteNonQuery(); //执行语句
|
||||
conn_SC.Close(); //关闭连接
|
||||
if (sql_in == 0)
|
||||
{
|
||||
System.Windows.MessageBox.Show("修改失败");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Button_ID == 0) GridSql(0);
|
||||
else if (Button_ID == 1) GridSql(1);
|
||||
else if (Button_ID == 2) GridSql(2);
|
||||
else if (Button_ID == 3) GridSql(3);
|
||||
else if (Button_ID == 4) GridSql(4);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
System.Windows.MessageBox.Show("请求原料信息失败,检查连接");
|
||||
System.Windows.MessageBox.Show("请求失败,检查连接");
|
||||
return;
|
||||
}
|
||||
}
|
||||
/* else
|
||||
{
|
||||
product.ProductCode = this.stuff_ProductCode.Text;//写入原料代码
|
||||
product.ProductName = this.stuff_ProductName.Text;//写入原料名称
|
||||
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参数
|
||||
int ColorCode_SQL = Convert.ToInt32(StuffColor, 16);//16进制转10进制
|
||||
if (ColorCode_SQL >= 0) product.Color = ColorCode_SQL;//判断色彩数据是否有效,有效写入
|
||||
}
|
||||
else
|
||||
{
|
||||
product.Color = null;//色彩栏写空
|
||||
}
|
||||
if (string.IsNullOrEmpty(this.stuff_Price.Text) == false)
|
||||
product.Price = Double.Parse(this.stuff_Price.Text);//判断价格数据是否有效,有效写入
|
||||
if (string.IsNullOrEmpty(this.stuff_SUPPLIER.Text) == false)
|
||||
product.SUPPLIER = this.stuff_SUPPLIER.Text;//判断供应商数据是否有效,有效写
|
||||
product.GRAVITY = Double.Parse(this.stuff_GRAVITY.Text);//写入原料比重
|
||||
if (this.stuff_ProductType.Text == "染料" || this.stuff_ProductType.Text == "粉体助剂")
|
||||
product.Concentration = 0;
|
||||
else
|
||||
product.Concentration = Double.Parse(this.stuff_Concentration.Text);//写入原料浓度
|
||||
product.ProductType = int_stuff_ProductType;//写入原料类型
|
||||
product.ProductCode = this.stuff_ProductCode.Text;//写入原料代码
|
||||
if (new ProductProvider().Selectsql(product).Count == 0)//判断数据库设定目标信息是否存在。
|
||||
{
|
||||
var count = new ProductProvider().Insert(product);//添加数据库信息。
|
||||
if (count == 0)
|
||||
System.Windows.MessageBox.Show("ERR.C0110-1:添加失败", "错误");//判断执行是否成功
|
||||
else
|
||||
Button_sql = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
var count = new ProductProvider().Update(product);//添加数据库信息。
|
||||
if (count == 0)
|
||||
System.Windows.MessageBox.Show("ERR.C0102-5:更新失败", "错误");//执行是否成功
|
||||
else
|
||||
Button_sql = true;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
private void Button_Delete(object sender, RoutedEventArgs e)//删除按钮事件
|
||||
{
|
||||
/* product.ProductCode = this.stuff_ProductCode.Text;//原料代码
|
||||
string ShowProductName = "是否删除原料【" + this.stuff_ProductName.Text + "】" + this.stuff_ProductCode.Text;//获取原料信息并拼接提示字符串
|
||||
MessageBoxResult showProductName = System.Windows.MessageBox.Show(ShowProductName, "提示", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.Yes);//弹窗提示是否删除目标原料
|
||||
if (showProductName == MessageBoxResult.Yes)//判断是否删除原料
|
||||
{
|
||||
var count = new ProductProvider().Delete(product);//删除数据库目标信息。
|
||||
if (count == 0) System.Windows.MessageBox.Show("ERR.C0110-2:删除失败", "错误");//判断执行是否成功
|
||||
else Button_sql = true;}
|
||||
*/
|
||||
private async void Button_Delete(object sender, RoutedEventArgs e)//删除按钮事件
|
||||
{
|
||||
string ShowProductName = "是否删除原料【" + this.stuff_ProductName.Text + "】" + this.stuff_ProductCode.Text;//获取原料信息并拼接提示字符串
|
||||
MessageBoxResult showProductName = System.Windows.MessageBox.Show(ShowProductName, "提示", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.Yes);//弹窗提示是否删除目标原料
|
||||
if (showProductName == MessageBoxResult.Yes)//判断是否删除原料
|
||||
{
|
||||
|
||||
string Stuff_sql = string.Format("DELETE FROM [dbo].[PRODUCT] WHERE ProductCode ='" + stuff_ProductCode.Text.ToString() + "'");
|
||||
|
||||
SqlConnection conn_SC = new SqlConnection(Connstr_SC); //实例化
|
||||
try
|
||||
{
|
||||
await conn_SC.OpenAsync(); //打开数据连接
|
||||
SqlCommand INSERT_cmd = new SqlCommand(Stuff_sql, conn_SC);
|
||||
int sql_in = INSERT_cmd.ExecuteNonQuery(); //执行语句
|
||||
conn_SC.Close(); //关闭连接
|
||||
if (sql_in == 0)
|
||||
{
|
||||
System.Windows.MessageBox.Show("ERR.C0110-2:删除失败", "错误");//判断执行是否成功
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Button_ID == 0) GridSql(0);
|
||||
else if (Button_ID == 1) GridSql(1);
|
||||
else if (Button_ID == 2) GridSql(2);
|
||||
else if (Button_ID == 3) GridSql(3);
|
||||
else if (Button_ID == 4) GridSql(4);
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
System.Windows.MessageBox.Show("请求失败,检查连接");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DataGridStuff_MouseDoubleClick(object sender, MouseButtonEventArgs e)//数据表双击事件
|
||||
|
||||
Reference in new issue
Block a user