using Api.Framework; using Api.Framework.Tools; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using 监听违规.Entitys; namespace 监听违规 { public partial class AddForm : Form { public AddForm() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { try { var username = tb_username.Text; if (string.IsNullOrWhiteSpace(username)) throw new Exception("用户账号不能为空"); var session = ApiClient.GetSession(); var user = session.FindSingle("wxid = @wxid", new { wxid = username }); if (user != null) throw new Exception("已经存在该用户,无需重复添加"); var utype = (UserType)Enum.Parse(typeof(UserType), cb_usertype.Text); var nick = tb_nick.Text; user = new UserLists_db() { wxid = username, user_type = utype, nick_name = nick }; session.Insertable(user).ExecuteCommand(); Common.FlushWhiteUserListsCache(true); MessageBox.Show("添加成功"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } }