private void BtnAdd_Click(object sender, EventArgs e) { var name = txtName.Text.Trim(); var url = txtUrl.Text.Trim(); if (string.IsNullOrEmpty(name)) { MessageBox.Show("名称不能为空"); txtName.Focus(); return; } if (string.IsNullOrEmpty(url)) { MessageBox.Show("地址不能为空"); txtUrl.Focus(); return; } try { WeixinRobot robot = new WeixinRobot(); robot.Name = name; robot.Url = url; WeixinRobot.Insert(robot); LoadRobot(); } catch (Exception ex) { MessageBox.Show("添加微信机器人失败:" + ex.ToString()); } }