diff --git a/MainWindow.xaml b/MainWindow.xaml index 0eef930..a4a9fb9 100644 --- a/MainWindow.xaml +++ b/MainWindow.xaml @@ -92,7 +92,7 @@ + + + + diff --git a/Windows/Dissolve.xaml.cs b/Windows/Dissolve.xaml.cs new file mode 100644 index 0000000..5d875c1 --- /dev/null +++ b/Windows/Dissolve.xaml.cs @@ -0,0 +1,249 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; +using GalaSoft.MvvmLight; +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 +{ + /// + /// Machine.xaml 的交互逻辑 + /// + public partial class Dissolve : Window + { + public string INIPath = Convert.ToString(System.AppDomain.CurrentDomain.BaseDirectory) + "formula.ini"; //配置文件路径 + + string TEXT_SQLIP; + string TEXT_SQLNAME; + string TEXT_SQMOD; + string TEXT_SQLUSER; + string TEXT_SQLPASWOR; + string Connstr_SC; + public Dissolve() + { + WindowStartupLocation = WindowStartupLocation.CenterScreen; + InitializeComponent(); + } + + private async void Dissolve_Loaded(object sender, RoutedEventArgs e)//打开页面执行 + { + UserClass.IniFile.IniFiles Configini = new UserClass.IniFile.IniFiles(INIPath);//生效配置读取 + this.DatagridDissolve.LoadingRow += new EventHandler(this.DataGridEquipment_LoadingRow);//生成序列号 + + TEXT_SQLIP = Configini.IniReadvalue("SQL_SERVER", "SQL1"); //读配置文件 + TEXT_SQLNAME = Configini.IniReadvalue("SQL_SERVER", "SQL2"); + TEXT_SQMOD = Configini.IniReadvalue("SQL_SERVER", "SQL3"); + TEXT_SQLUSER = Configini.IniReadvalue("SQL_SERVER", "SQL4"); + TEXT_SQLPASWOR = Configini.IniReadvalue("SQL_SERVER", "SQL5"); + if (TEXT_SQMOD == "0") //判断连接方式 + { + Connstr_SC = "server=" + TEXT_SQLIP + ";database=" + TEXT_SQLNAME + ";Trusted_Connection=SSPI"; + } + else + { + Connstr_SC = "server=" + TEXT_SQLIP + ";database=" + TEXT_SQLNAME + ";User ID=" + TEXT_SQLUSER + ";Password=" + TEXT_SQLPASWOR; + } + + GridSql(); + } + + /// + /// 生成序列号的方法 + /// + private void DataGridEquipment_LoadingRow(object sender, DataGridRowEventArgs e) + { + e.Row.Header = e.Row.GetIndex() + 1; + } + + /// + /// 查询数据库的方法 + /// + private async void GridSql() + { + string Dissolve_sql = "SELECT DissolveCode ,DissolveName ,REMARK ,MaterialType ,WeightMIN ,WeightMAX FROM [Dispensing].[dbo].[Dissolve]";//查询语句 + + SqlConnection conn_SC = new SqlConnection(Connstr_SC); //实例化 + + try + { + await conn_SC.OpenAsync(); //打开数据连接 + SqlDataAdapter Stuff_data = new SqlDataAdapter(Dissolve_sql, Connstr_SC); //查询 + + DataTable dataTable = new DataTable(); //建立缓存 + Stuff_data.Fill(dataTable); //查询结果存入缓存 + conn_SC.Close(); //关闭连接 + + DatagridDissolve.ItemsSource = dataTable.DefaultView; //数据加入表格 + } + catch (Exception) + { + System.Windows.MessageBox.Show("请求信息失败,检查连接"); + return; + } + } + + private void Dissolve_MouseDoubleClick(object sender, MouseButtonEventArgs e)//数据表双击事件 + { + int rownum = DatagridDissolve.SelectedIndex;//获取鼠标选中行并定义变量 + if (rownum != -1)//判断鼠标定位是否有效 + { + /*定位选中行及指定列单元格文本信息*/ + Code.Text = (DatagridDissolve.Columns[1].GetCellContent(DatagridDissolve.Items[rownum]) as TextBlock).Text.Trim();//定位第列 + Name.Text = (DatagridDissolve.Columns[2].GetCellContent(DatagridDissolve.Items[rownum]) as TextBlock).Text.Trim();// + ion.Text = (DatagridDissolve.Columns[3].GetCellContent(DatagridDissolve.Items[rownum]) as TextBlock).Text.Trim();// + min.Text = (DatagridDissolve.Columns[4].GetCellContent(DatagridDissolve.Items[rownum]) as TextBlock).Text.Trim();// + max.Text = (DatagridDissolve.Columns[5].GetCellContent(DatagridDissolve.Items[rownum]) as TextBlock).Text.Trim();// + Remark.Text = (DatagridDissolve.Columns[6].GetCellContent(DatagridDissolve.Items[rownum]) as TextBlock).Text.Trim();// + } + } + + private void Tb_KeyFloating(object sender, TextCompositionEventArgs e)//输入事件 + { + //Regex re = new Regex("[^0-9.-]+"); + Regex re = new Regex(@"^[.][0-9]+$|^[0-9]*[.]{0,1}[0-9]*$");// 非负浮点数 + e.Handled = !re.IsMatch(e.Text); + } + + private async void Button_Preservation(object sender, RoutedEventArgs e)//保存按钮事件 + { + Regex re_number = new Regex(@"^[0-9]+(.[0-9]{1,2})?$");//校验用正则表达式有1~2位小数的正实数 + Regex re_char = new Regex(@"^[A-Za-z0-9\s@()()/+!!_-]+$");//校验用正则表达式由数字,26个英文字母,空白字符和@()()/+!!_-组成的字符串 + string Dissolve_sql; + int int_ion = 0; + + if ((Name.Text == "") ||(Code.Text == "")) + { + System.Windows.MessageBox.Show("请输入代码或名称"); + return; + } + if ((min.Text == "") || (max.Text == "")) + { + System.Windows.MessageBox.Show("请确认最用量"); + return; + } + else if (int.Parse(min.Text) > int.Parse(max.Text)) + { + System.Windows.MessageBox.Show("用量错误"); + return; + } + + if (ion.Text == "") + { + System.Windows.MessageBox.Show("请确认用途"); + return; + } + else if (ion.Text == "分散") int_ion = 0; + else if (ion.Text == "酸性") int_ion = 1; + else if (ion.Text == "活性") int_ion = 2; + else if (ion.Text == "中性") int_ion = 3; + else if (ion.Text == "硫化") int_ion = 4; + else if (ion.Text == "阳离子") int_ion = 5; + else if (ion.Text == "阴离子") int_ion = 6; + else if (ion.Text == "非离子") int_ion = 7; + else if (ion.Text == "酞菁") int_ion = 8; + else if (ion.Text == "直接") int_ion = 9; + + if (Code.Text != null) + { + try + { + SqlConnection conn_SC = new SqlConnection(Connstr_SC); //实例化 + Dissolve_sql = "SELECT count(*) FROM [Dispensing].[dbo].[Dissolve] WHERE DissolveCode = '" + Code.Text + " '";//查询语句 + await conn_SC.OpenAsync(); //打开数据连 + SqlCommand cmd = new SqlCommand(Dissolve_sql, conn_SC); //查询记录数 + int count = Convert.ToInt32(cmd.ExecuteScalar()); //显示记录数 + conn_SC.Close(); //关闭连接 + + if (count == 0) + { + Dissolve_sql = string.Format("INSERT INTO[Dispensing].[dbo].[Dissolve](DissolveCode ,DissolveName ,REMARK ,MaterialType ,WeightMIN ,WeightMAX) " + + "VALUES ('" + Code.Text + "','" + Name.Text + "','" + Remark.Text + "','" + int_ion + "','"+ min.Text + "','" + max.Text + "')"); + await conn_SC.OpenAsync(); //打开数据连接 + SqlCommand INSERT_cmd = new SqlCommand(Dissolve_sql, conn_SC); + int sql_in = INSERT_cmd.ExecuteNonQuery(); //执行语句 + conn_SC.Close(); //关闭连接 + if (sql_in == 0) + { + System.Windows.MessageBox.Show("添加失败"); + } + else + { + GridSql(); + System.Windows.MessageBox.Show("添加完成");// + } + } + else + { + Dissolve_sql = string.Format("UPDATE [dbo].[Dissolve] SET DissolveName ='" + Name.Text + "',REMARK='" + Remark.Text + "',MaterialType='" + int_ion + "',WeightMIN='" + min.Text + "',WeightMAX='" + max.Text + "' Where DissolveCode ='" + Code.Text + "'"); + await conn_SC.OpenAsync(); //打开数据连接 + SqlCommand INSERT_cmd = new SqlCommand(Dissolve_sql, conn_SC); + int sql_in = INSERT_cmd.ExecuteNonQuery(); //执行语句 + conn_SC.Close(); //关闭连接 + + if (sql_in == 0) + { + System.Windows.MessageBox.Show("修改失败"); + } + else + { + GridSql(); + System.Windows.MessageBox.Show("修改完成");// + } + } + } + catch (Exception) + { + System.Windows.MessageBox.Show("请求失败,检查连接"); + return; + } + } + } + + private async void Button_Delete(object sender, RoutedEventArgs e)//删除按钮事件 + { + string Mac_name = "是否删除【" + this.Code.Text + "】";//获取信息并拼接提示字符串 + MessageBoxResult mac_name = System.Windows.MessageBox.Show(Mac_name, "提示", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.Yes);//弹窗提示是否删除目标 + if (mac_name == MessageBoxResult.Yes)//判断是否删除原料 + { + string Stuff_sql = string.Format("DELETE FROM [dbo].[Dissolve] WHERE Name ='" + Code.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 + { + GridSql(); + } + } + catch (Exception) + { + System.Windows.MessageBox.Show("请求失败,检查连接"); + return; + } + } + } + } +} diff --git a/Windows/Machine.xaml b/Windows/Machine.xaml index c46ad6c..469b64b 100644 --- a/Windows/Machine.xaml +++ b/Windows/Machine.xaml @@ -93,7 +93,7 @@ VerticalAlignment="Bottom" Width="45" FontSize="20"/> + VerticalAlignment="Bottom" Width="100" FontSize="20" IsReadOnly="True" IsEditable="True"> @@ -102,7 +102,7 @@ VerticalAlignment="Bottom" Width="45" FontSize="20"/> + VerticalAlignment="Bottom" Width="100" FontSize="20" IsReadOnly="True" IsEditable="True"> diff --git a/Windows/Stuff.xaml b/Windows/Stuff.xaml index 6f920e4..eebe0b0 100644 --- a/Windows/Stuff.xaml +++ b/Windows/Stuff.xaml @@ -115,7 +115,7 @@ VerticalAlignment="Bottom" Width="100" FontSize="20"/> + VerticalAlignment="Bottom" Width="100" FontSize="20" IsReadOnly="True" IsEditable="True"> @@ -125,7 +125,7 @@ VerticalAlignment="Bottom" Width="100" FontSize="20"/> + VerticalAlignment="Bottom" Width="100" FontSize="20" IsReadOnly="True" IsEditable="True"> diff --git a/formula_manage.csproj b/formula_manage.csproj index f1a372d..2534dbc 100644 --- a/formula_manage.csproj +++ b/formula_manage.csproj @@ -188,6 +188,9 @@ APP_set.xaml + + Dissolve.xaml + User.xaml @@ -238,6 +241,10 @@ Designer MSBuild:Compile + + MSBuild:Compile + Designer + MSBuild:Compile Designer