private void button1_Click(object sender, System.EventArgs e) { if (conn.KickOut(textBox_UserName.Text) == "") { MessageBox.Show("必须输入用户名!", "警告!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } if (conn.KickOut(textBox_PassWord.Text) == "") { MessageBox.Show("必须输入密码!", "警告!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } if (conn.Sniffer_In(textBox_PassWord.Text) || conn.Sniffer_In(textBox_UserName.Text)) { MessageBox.Show("用户名或密码不得用空格或者'\"?%=空格!", "警告!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } //去除'"?%=空格,修改用户表 string errorstring = "", str_ReadOnly, str_Sql; if (checkBox_ReadOnly.Checked == true) { str_ReadOnly = "1"; } else { str_ReadOnly = "0"; } str_Sql = "Update Users SET PassWord='******',ReadOnly=" + str_ReadOnly + " Where UserName='******'"; errorstring = conn.ExeSql(str_Sql); if (errorstring != "OK") { MessageBox.Show("未成功修改!请检查数据库!" + errorstring, "提醒!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); button1.Enabled = false; return; } MessageBox.Show("成功修改!", "提醒!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); //刷新DataGrid显示,置空各信息项,等待选中新的有效项 str_Sql = "SELECT UserName AS 用户名,PassWord AS 密码,ReadOnly AS 仅为只读用户 FROM Users"; conn.Fill(str_Sql); DataGrid1.SetDataBinding(conn.ds, "TableIn"); textBox_UserName.Text = ""; textBox_PassWord.Text = ""; checkBox_ReadOnly.Checked = true; button1.Enabled = false; }
private void button1_Click(object sender, System.EventArgs e) { config connFirst = new config(); //测试数据库连接 string str_Sql = "SELECT School_Type_ID As 学校类别代码,School_Type_Name As 学校类别名,School_Type_Year As 学校类别学制 FROM School_Type"; string errorstring = connFirst.Fill(str_Sql); if (errorstring != "OK") { MessageBox.Show("请检查数据库!" + errorstring, "提醒!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); connFirst.Close(); return; } //特殊字符不能用 if (connFirst.Sniffer_In(textBox_User.Text) || connFirst.Sniffer_In(textBox_PassWord.Text)) { MessageBox.Show("用户名或密码不得用空格或者'\"?%=等特殊字符!" + errorstring, "提醒!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); connFirst.Close(); return; } //判断用户合法 str_Sql = "Select * FROM Users WHERE UserName= '******' AND PassWord='******'"; if (connFirst.GetRowCount(str_Sql) != 1) { MessageBox.Show("错误的用户名或密码!" + errorstring, "提醒!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); connFirst.Close(); button1.Enabled = true; return; } else { str_User_login = textBox_User.Text; this.Close(); } }
private void button1_Click(object sender, System.EventArgs e) { if (conn.KickOut(textBox_UserName.Text) == "") { MessageBox.Show("必须输入用户名!", "警告!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } if (textBox_UserName.Text.Length > 20) { MessageBox.Show("请不要超长输入用户名!", "警告!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } bool bool_UserName_Had = true; try { bool_UserName_Had = conn.UserName_Had(textBox_UserName.Text); } catch { MessageBox.Show("数据库错误!!", "警告!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } if (bool_UserName_Had == true) { MessageBox.Show("请不要输入重复的用户名!", "警告!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } if (textBox_PassWord.Text == "") { MessageBox.Show("必须输入密码!", "警告!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } if (textBox_PassWord.Text.Length > 20) { MessageBox.Show("请不要超长输入密码!", "警告!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } if (conn.Sniffer_In(textBox_PassWord.Text) || conn.Sniffer_In(textBox_UserName.Text)) { MessageBox.Show("用户名或密码不得用空格或者'\"?%=空格!", "警告!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } //去除'"?%=空格,插入办事处表 string errorstring = "", str_ReadOnly, str_Sql; if (checkBox_ReadOnly.Checked == true) { str_ReadOnly = "1"; } else { str_ReadOnly = "0"; } str_Sql = "insert into Users (UserName,PassWord,ReadOnly) values ('" + conn.KickOut(textBox_UserName.Text) + "','" + conn.KickOut(textBox_PassWord.Text) + "'," + str_ReadOnly + ")"; errorstring = conn.ExeSql(str_Sql); if (errorstring != "OK") { MessageBox.Show("未成功添加!请检查数据库!" + errorstring, "提醒!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); button1.Enabled = false; return; } MessageBox.Show("成功添加!", "提醒!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); //刷新DataGrid显示 str_Sql = "SELECT UserName AS 用户名,PassWord AS 密码,ReadOnly AS 仅为只读用户 FROM Users"; try { errorstring = conn.Fill(str_Sql); } catch { MessageBox.Show(errorstring, "提醒!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); conn.Close(); } DataGrid1.SetDataBinding(conn.ds, "TableIn"); textBox_UserName.Text = ""; textBox_PassWord.Text = ""; checkBox_ReadOnly.Checked = true; }
private void button1_Click(object sender, System.EventArgs e) { if (checkBox_First.Checked == true) { try { string path = "SchoolManage.exe.config"; XmlDocument xd = new XmlDocument(); xd.Load(path); //判断节点是否存在,如果存在则修改当前节点 foreach (XmlNode xn1 in xd.SelectNodes("/configuration/appSettings/add")) { if (xn1.Attributes["key"].Value == "Database") { xn1.Attributes["value"].Value = textBox_Database.Text; //break; } if (xn1.Attributes["key"].Value == "DatabaseServer") { xn1.Attributes["value"].Value = textBox_DBServer.Text; //break; } if (xn1.Attributes["key"].Value == "DatabaseUser") { xn1.Attributes["value"].Value = textBox_DbUser.Text; break; } /*if(xn1.Attributes["key"].Value=="DatabasePassword") * { * xn1.Attributes["value"].Value=textBox_DbPassWord.Text; * break; * }*/ } //保存web.config xd.Save(path); //return true; MessageBox.Show("成功修改!", "提醒!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } catch { //return false; throw new Exception("Config设置文件读取失败!"); } } //测试数据库连接 string str_Sql, errorstring; str_Sql = "SELECT School_Type_ID As 学校类别代码,School_Type_Name As 学校类别名,School_Type_Year As 学校类别学制 FROM School_Type"; errorstring = conn.Fill(str_Sql); if (errorstring != "OK") { MessageBox.Show("请检查数据库!" + errorstring, "提醒!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); conn.Close(); return; } //特殊字符不能用 if (conn.Sniffer_In(textBox_User.Text) || conn.Sniffer_In(textBox_PassWord.Text)) { MessageBox.Show("用户名或密码不得用空格或者'\"?%=等特殊字符!" + errorstring, "提醒!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); conn.Close(); return; } //判断用户合法 str_Sql = "Select * FROM Users WHERE UserName= '******' AND PassWord='******'"; if (conn.GetRowCount(str_Sql) != 1) { MessageBox.Show("错误的用户名或密码!" + errorstring, "提醒!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); conn.Close(); button1.Enabled = true; return; } else { str_User_login = textBox_User.Text; this.Close(); } }