public void del(int id) { db tdb = new db(); var h = MessageBox.Show("确认删除", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (h.ToString().ToUpper() == "YES") { try { string sql = "select classify from [user] where [id] ={0}"; sql = string.Format(sql, id); int t = int.Parse(tdb.dbfile(sql).Tables[0].Rows[0]["classify"].ToString()); sql = "delete from [user] where [id] ={0}"; sql = string.Format(sql, id); tdb.dbfile(sql); MessageBox.Show("删除成功"); Class_ = t; TWebBrowser.DocumentText = this.zy("js.index.html"); this.panel1.Show(); this.panel2.Hide(); this.panel3.Hide(); } catch { } } }
public string _SQl(string sql) { db tdb = new db(); DataSet rs = tdb.dbfile(sql); try { string result = JsonConvert.SerializeObject(rs.Tables, new DataTableConverter()); return(result); } catch (Exception e) { return(e.ToString()); } }
public void showWin(int id) { this.groupBox1.Text = "修改用户"; this.panel1.Hide(); this.panel2.Show(); this.panel3.Hide(); db tdb = new db(); string sql = "select * from [user] where [id] ={0}"; sql = string.Format(sql, id); DataRow rs = tdb.dbfile(sql).Tables[0].Rows[0]; TTAddUserSelect[0].Text = TAddUserIdentityConfig[(int)rs["identity"]]; int zf = 65 + (int)rs["classify"] - 1; string word = char.ConvertFromUtf32(zf); TTAddUserSelect[1].Text = word; TAddUser[0].Text = rs["user"].ToString(); TAddUser[1].Text = rs["password"].ToString(); TIsUpdate = true; TUserId = id; TSubmit[1].Text = "修改"; }
/// <summary> /// 添加用户/修改用户 数据提交部分 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void TSubmit_Submit_Click(object sender, EventArgs e) { db tdb = new db(); string TName = TAddUser[0].Text; string TPassword = TAddUser[1].Text; string TLogin = TTAddUserSelect[0].Text; string TClass = TTAddUserSelect[1].Text; string p = null; string sql = null; if (string.IsNullOrEmpty(TName)) { MessageBox.Show(TAddUserConfig[0] + "不能为空"); return; } if (string.IsNullOrEmpty(TPassword)) { MessageBox.Show(TAddUserConfig[1] + "不能为空"); return; } if (string.IsNullOrEmpty(TLogin)) { MessageBox.Show(TAddUserConfig[2] + "不能为空"); return; } if (string.IsNullOrEmpty(TClass)) { MessageBox.Show(TAddUserConfig[2] + "不能为空"); return; } byte[] array = System.Text.Encoding.ASCII.GetBytes(TClass); int IClass = (short)(array[0]) - 65 + 1; int ILogin = (TLogin == "身份证" ? 0 : 1); if (!TIsUpdate) { try { sql = "select count(id) as ic from [user] where [user] ='{0}'"; sql = string.Format(sql, TName); try { int rs = int.Parse(tdb.dbfile(sql).Tables[0].Rows[0]["ic"].ToString()); if (rs > 0) { MessageBox.Show("用户已存在"); return; } } catch { return; } sql = "INSERT INTO [user] ([user],[password],[identity],[classify]) VALUES('{0}','{1}','{2}','{3}')"; sql = string.Format(sql, TName, TPassword, ILogin, IClass); p = "添加成功"; Class_ = IClass; } catch { MessageBox.Show("内容不完整"); } } else { try { sql = "update [user] set [user]='{0}' , [password]='{1}',[identity]='{2}',[classify]='{3}' where id = {4}"; sql = string.Format(sql, TName, TPassword, ILogin, IClass, TUserId); p = "修改成功"; Class_ = IClass; } catch { MessageBox.Show("内容不完整"); } } try { tdb.dbfile(sql); MessageBox.Show(p); } catch { MessageBox.Show("程序出错"); } }