diff --git a/ConvertMoels/UserSQLConvert.cs b/ConvertMoels/UserSQLConvert.cs
new file mode 100644
index 0000000..8872d2e
--- /dev/null
+++ b/ConvertMoels/UserSQLConvert.cs
@@ -0,0 +1,48 @@
+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 UserSQLConvert : IValueConverter
+ {
+ public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ string Capacity = System.Convert.ToString(value);
+ if (Capacity == "0")//类型
+ {
+ return "停用";
+ }
+ else
+ {
+ if (Capacity == "1")
+ {
+ return "限制";
+ }
+ else
+ {
+ if (Capacity == "2")
+ {
+ 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 4b9924d..e004355 100644
--- a/MainWindow.xaml
+++ b/MainWindow.xaml
@@ -52,7 +52,6 @@
-
@@ -150,7 +149,9 @@
-
+
+
diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs
index f411c27..2438989 100644
--- a/MainWindow.xaml.cs
+++ b/MainWindow.xaml.cs
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
+using System.Collections.ObjectModel;
using System.Data;
+using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Text;
@@ -31,6 +33,15 @@ namespace formula_manage
DataTable STUFFdataTable = new DataTable(); //建立STUFF缓存
+ 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 MainWindow()
{
int ID_N = 1;
@@ -41,6 +52,14 @@ namespace formula_manage
USER.Text = App.USER_Purview;
+ sql_Stuff();//查询stuff表
+
+ //bindDataGridDatas
+ //SelectionList = STUFFdataTable;
+ // Grid_RRODUCT.ItemsSource
+
+ //Grid_RRODUCT.ItemsSource = STUFFdataTable.DefaultView; //new ObservableCollection();
+
CountDown();//执行循环方法
DataTable dataTable = new DataTable();
@@ -67,7 +86,47 @@ namespace formula_manage
Grid_RRODUCT.ItemsSource = dataTable.DefaultView;
}
- private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) //窗口关闭事件
+
+
+
+ private async void sql_Stuff()
+ {
+ UserClass.IniFile.IniFiles Configini = new UserClass.IniFile.IniFiles(INIPath);//生效配置读取
+ 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;
+ }
+
+ string Stuff_sql = "SELECT ProductCode ,ProductName ,ProductType ,Concentration FROM [Dispensing].[dbo].[PRODUCT]";//查询语句
+
+ SqlConnection conn_SC = new SqlConnection(Connstr_SC); //实例化
+ try
+ {
+ await conn_SC.OpenAsync(); //打开数据连接
+ SqlDataAdapter Stuff_data = new SqlDataAdapter(Stuff_sql, Connstr_SC); //查询
+
+ //DataTable dataTable = new DataTable(); //建立缓存
+ Stuff_data.Fill(STUFFdataTable); //查询结果存入缓存
+ conn_SC.Close(); //关闭连接
+ //DataGridStuff.ItemsSource = dataTable.DefaultView; //数据加入表格
+ }
+ catch (Exception)
+ {
+ System.Windows.MessageBox.Show("请求原料信息失败,检查连接");
+ return;
+ }
+ }
+
+ private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) //窗口关闭事件
{
string logpath = System.Environment.CurrentDirectory + "\\Log";//日志文件目录
string logPath = "" + System.Environment.CurrentDirectory + "\\Log\\Log.txt";//日志文件
@@ -103,8 +162,6 @@ namespace formula_manage
}
}
- public string INIPath = Convert.ToString(System.AppDomain.CurrentDomain.BaseDirectory) + "formula.ini";
-
string Prepose; //料单前置
string PreposeT; //料单时间
@@ -155,7 +212,8 @@ namespace formula_manage
private void USER_SET(object sender, RoutedEventArgs e)
{
-
+ Windows.User user_set = new Windows.User();
+ user_set.ShowDialog();//实例化并置顶打开用户窗口
}
private void HELP(object sender, RoutedEventArgs e)
diff --git a/Windows/User.xaml b/Windows/User.xaml
new file mode 100644
index 0000000..d7edc93
--- /dev/null
+++ b/Windows/User.xaml
@@ -0,0 +1,111 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Windows/User.xaml.cs b/Windows/User.xaml.cs
new file mode 100644
index 0000000..da9ae84
--- /dev/null
+++ b/Windows/User.xaml.cs
@@ -0,0 +1,248 @@
+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 User : 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 User()
+ {
+ WindowStartupLocation = WindowStartupLocation.CenterScreen;
+ InitializeComponent();
+ }
+
+ private async void user_Loaded(object sender, RoutedEventArgs e)//打开页面执行
+ {
+ UserClass.IniFile.IniFiles Configini = new UserClass.IniFile.IniFiles(INIPath);//生效配置读取
+
+ 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;
+ }
+
+ string Stuff_sql = "SELECT UserCode ,PassWord ,UserSetup ,Capacity ,GROUP_CODE ,Note FROM [Dispensing].[dbo].[UserAccount]";//查询语句
+
+ SqlConnection conn_SC = new SqlConnection(Connstr_SC); //实例化
+ try
+ {
+ await conn_SC.OpenAsync(); //打开数据连接
+ SqlDataAdapter Stuff_data = new SqlDataAdapter(Stuff_sql, Connstr_SC); //查询
+
+ DataTable dataTable = new DataTable(); //建立缓存
+ Stuff_data.Fill(dataTable); //查询结果存入缓存
+ conn_SC.Close(); //关闭连接
+
+ DataGriduser.ItemsSource = dataTable.DefaultView; //数据加入表格
+ }
+ catch (Exception)
+ {
+ System.Windows.MessageBox.Show("请求信息失败,检查连接");
+ return;
+ }
+ }
+
+ ///
+ /// 查询数据库的方法
+ ///
+ private async void GridSql()
+ {
+ string Stuff_sql = "SELECT UserCode ,PassWord ,Capacity ,GROUP_CODE ,Note FROM [Dispensing].[dbo].[UserAccount]";//查询语句
+
+ SqlConnection conn_SC = new SqlConnection(Connstr_SC); //实例化
+
+ try
+ {
+ await conn_SC.OpenAsync(); //打开数据连接
+ SqlDataAdapter Stuff_data = new SqlDataAdapter(Stuff_sql, Connstr_SC); //查询
+
+ DataTable dataTable = new DataTable(); //建立缓存
+ Stuff_data.Fill(dataTable); //查询结果存入缓存
+ conn_SC.Close(); //关闭连接
+
+ DataGriduser.ItemsSource = dataTable.DefaultView; //数据加入表格
+ }
+ catch (Exception)
+ {
+ System.Windows.MessageBox.Show("请求信息失败,检查连接");
+ return;
+ }
+ }
+
+ 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 void DataGridMac_MouseDoubleClick(object sender, MouseButtonEventArgs e)//数据表双击事件
+ {
+ int rownum = DataGriduser.SelectedIndex;//获取鼠标选中行并定义变量
+ if (rownum != -1)//判断鼠标定位是否有效
+ {
+ /*定位选中行及指定列单元格文本信息*/
+ _Name.Text = (DataGriduser.Columns[0].GetCellContent(DataGriduser.Items[rownum]) as TextBlock).Text.Trim();//定位第列
+ GROUP.Text = (DataGriduser.Columns[1].GetCellContent(DataGriduser.Items[rownum]) as TextBlock).Text.Trim();
+ Capacity.Text = (DataGriduser.Columns[2].GetCellContent(DataGriduser.Items[rownum]) as TextBlock).Text.Trim();
+ Note.Text = (DataGriduser.Columns[3].GetCellContent(DataGriduser.Items[rownum]) as TextBlock).Text.Trim();
+ }
+ }
+
+ 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 name = _Name.Text;
+ string password = Pasword.Text;
+ string Group = GROUP.Text;
+ int Cap = 0;
+ string note = Note.Text;
+ string Stuff_sql;
+
+ if(Capacity.Text == "停用") Cap = 0;
+ else if (Capacity.Text == "限制") Cap = 1;
+ else if (Capacity.Text == "启用") Cap = 2;
+
+ if (name != "")
+ {
+ try
+ {
+ SqlConnection conn_SC = new SqlConnection(Connstr_SC); //实例化
+ Stuff_sql = "SELECT count(*) FROM [Dispensing].[dbo].[UserAccount] WHERE UserCode = '" + name + " '";//查询语句
+ await conn_SC.OpenAsync(); //打开数据连
+ SqlCommand cmd = new SqlCommand(Stuff_sql, conn_SC); //查询记录数
+ int count = Convert.ToInt32(cmd.ExecuteScalar()); //显示记录数
+ conn_SC.Close(); //关闭连接
+
+ if (count == 0)
+ {
+ if (password == "")
+ {
+ Stuff_sql = "INSERT INTO[Dispensing].[dbo].[UserAccount](UserCode ,PassWord ,GROUP_CODE ,Capacity ,Note ) " +
+ "VALUES ('" + name + "',null,'" + Group + "'," + Cap + ",'" + note + "')";
+ }
+ else
+ {
+ Stuff_sql = "INSERT INTO[Dispensing].[dbo].[UserAccount](UserCode ,PassWord ,GROUP_CODE ,Capacity ,Note ) " +
+ "VALUES ('" + name + "'," + password + ",'" + Group + "'," + Cap + ",'" + note + "')";
+ }
+
+ 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
+ {
+ GridSql();
+ }
+ }
+ else
+ {
+
+ if (password == "")
+ {
+ Stuff_sql = string.Format("UPDATE [dbo].[UserAccount] SET PassWord=null ,GROUP_CODE='" + Group + " ',Capacity=" + Cap + " ,Note='" + note + "' Where UserCode ='" + name + "'");
+ }
+ else
+ {
+ Stuff_sql = string.Format("UPDATE [dbo].[UserAccount] SET PassWord=" + password + " ,GROUP_CODE='" + Group + "' ,Capacity=" + Cap + " ,Note='" + note + "' Where UserCode ='" + name + "'");
+ }
+ 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
+ {
+ GridSql();
+ }
+ }
+ }
+ catch (Exception)
+ {
+ System.Windows.MessageBox.Show("请求失败,检查连接");
+ return;
+ }
+ }
+ }
+
+ private async void Button_Delete(object sender, RoutedEventArgs e)//删除按钮事件
+ {
+ string Mac_name = "是否删除账号【" + this._Name.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].[UserAccount] WHERE UserCode ='" + _Name.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/formula_manage.csproj b/formula_manage.csproj
index 20442ed..f25b604 100644
--- a/formula_manage.csproj
+++ b/formula_manage.csproj
@@ -126,6 +126,7 @@
+
Login.xaml
@@ -143,6 +144,9 @@
APP_set.xaml
+
+ User.xaml
+
Machine.xaml
@@ -190,6 +194,10 @@
Designer
MSBuild:Compile
+
+ MSBuild:Compile
+ Designer
+
Designer
MSBuild:Compile