private void but_ad_delectuser_Click(object sender, RoutedEventArgs e) { DbTools.sqlExecuteNonQuery("delete from dbo.UserSignIn where UsID='" + text_ad_cardid.Text + "'"); DbTools.sqlExecuteNonQuery("delete from dbo.Users where UsID='" + text_ad_cardid.Text + "'"); MessageBox.Show("删除成功!"); but_ad_delectuser.IsEnabled = false; }
public static string sqlSelectUserAndInsertMessage(string CardID, DateTime time) { string username = null; try { using (SqlConnection sqlcon = new SqlConnection("Server=.;user=sa;pwd=123456;database=myIotDb")) { sqlcon.Open(); SqlCommand sql = new SqlCommand("select UsName from dbo.Users where UsID='" + CardID + "'", sqlcon); SqlDataReader reader = sql.ExecuteReader(); if (reader.Read() == true) { username = reader.GetString(0); } else { username = "******"; } } DbTools.sqlExecuteNonQuery("insert into dbo.UserSignIn(UsID, UsSignInTime) values('" + CardID + "', '" + time.ToString() + "')"); } catch { username = "******"; } return(username); }
private void but_ad_insert_Click(object sender, RoutedEventArgs e) { if (text_ad_x_pad.Text.Trim() == "") { MessageBox.Show("请输入密码!"); } else { DbTools.sqlExecuteNonQuery("insert dbo.Administrators(AdName,AdPassword,AdLevel) values('" + text_ad_adname.Text + "','" + text_ad_x_pad.Text + "','普通管理员')"); MessageBox.Show("新增管理员成功!"); } }
private void but_ad_delete_Click(object sender, RoutedEventArgs e) { if (text_ad_adname.Text == "admin") { MessageBox.Show("不能删除超级管理员!"); } else { DbTools.sqlExecuteNonQuery("delete from dbo.Administrators where AdName='" + text_ad_adname.Text + "'"); MessageBox.Show("删除成功!"); } }
void updatePad() { if (DbTools.sqlSelectAdminPad(text_name.Text, text_y_pad.Text)) { DbTools.sqlExecuteNonQuery("update dbo.Administrators set AdPassword='******' where AdName='" + text_name.Text + "'"); MessageBox.Show("修改成功!"); } else { MessageBox.Show("密码错误!"); } }
void insertUser() { if (text_CardID.Text.Trim() != "" && text_user.Text.Trim() != "") { try { DbTools.sqlExecuteNonQuery("insert into dbo.Users(UsID,UsName,UsCreateTime) values('" + text_CardID.Text + "','" + text_user.Text + "','" + DateTime.Now.ToString() + "')"); MessageBox.Show("信息录入成功!"); } catch { MessageBox.Show("信息录入失败!"); } } else { MessageBox.Show("请完整填写信息!"); } }
private void but_ad_update_Click(object sender, RoutedEventArgs e) { DbTools.sqlExecuteNonQuery("update dbo.Administrators set AdPassword='******' where AdName='" + text_ad_adname.Text + "'"); MessageBox.Show("密码更改成功!"); }