using System; using System.Windows.Forms; using DevComponents.DotNetBar; namespace Cyberpipe { public partial class FrmAppUSERRESET : Office2007Form { int dbid; string username; string age; string sex; string phonenum; string password; string status; public FrmAppUSERRESET() { InitializeComponent(); buttonX1.Text = "确定"; comboBoxsex.Items.Add("男"); comboBoxsex.Items.Add("女"); comboBoxisroot.Items.Add("是"); comboBoxisroot.Items.Add("否"); } public FrmAppUSERRESET(int dbid, string username, string age, string password, string sex, string phonenum,string status) { InitializeComponent(); comboBoxsex.Items.Add("男"); comboBoxsex.Items.Add("女"); comboBoxisroot.Items.Add("是"); comboBoxisroot.Items.Add("否"); buttonX1.Text = "保存"; this.dbid = dbid; this.username = username; this.age = age; this.sex = sex; this.phonenum = phonenum; this.password = password; this.status = status; } private void FrmAppUSERRESET_Load(object sender, EventArgs e) { if (buttonX1.Text == "保存") { Text = "人员信息修改"; textBoxusername.Text = username; textBoxage.Text = age; textBoxpassword.Text = password; comboBoxsex.Text = sex; textBoxphonenum.Text = phonenum; comboBoxisroot.Text = status; } else { Text = "增加人员"; textBoxusername.Text = ""; textBoxage.Text = ""; textBoxpassword.Text = ""; comboBoxsex.Text = "男"; textBoxphonenum.Text = ""; comboBoxisroot.Text = "是"; } } private void buttonX1_Click(object sender, EventArgs e) { if (textBoxusername.Text == "") { MessageBox.Show("用户名不能为空!", "提示"); return; } if (textBoxpassword.Text == "") { MessageBox.Show("密码不能为空!", "提示"); return; } if (textBoxphonenum.Text == "") { MessageBox.Show("电话号码不能为空!", "提示"); return; } if (textBoxage.Text == "") { MessageBox.Show("年龄不能为空!", "提示"); return; } if (!bolNum(textBoxage.Text)||int.Parse(textBoxage.Text)>100||int.Parse(textBoxage.Text)<0) { MessageBox.Show("请输入正确的年龄!", "提示"); return; } if (!bolNum(textBoxphonenum.Text) || textBoxphonenum.Text.Length != 11) { MessageBox.Show("请输入正确的电话号码!", "提示"); return; } if (buttonX1.Text == "保存") { string sql = "update casic_app_patroler set USERNAME ='" + textBoxusername.Text.Trim() + "',PASSWORD ='" + textBoxpassword.Text.Trim() + "' ,AGE = '" + textBoxage.Text.Trim() + "',SEX ='" + comboBoxsex.Text.Trim() + "',PHONENUMBER ='" + textBoxphonenum.Text.Trim() + "',STATUS = '" + comboBoxisroot.Text.Trim() + "' where DBID =" + dbid; try { OledbHelper.sqlExecuteNonQuery(sql); { MessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult = DialogResult.OK; Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "提示"); } } if (buttonX1.Text == "确定") { string sql = "insert into casic_app_patroler (USERNAME,AGE,PASSWORD,SEX,PHONENUMBER,STATUS) values ('" + textBoxusername.Text.Trim() + "','" + textBoxage.Text.Trim() + "','" + textBoxpassword.Text.Trim() + "','" + comboBoxsex.Text.Trim() + "','" + textBoxphonenum.Text.Trim() + "','" + comboBoxisroot.Text.Trim() + "')"; try { OledbHelper.sqlExecuteNonQuery(sql); { MessageBox.Show("人员增加成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "提示"); } } } private void buttonX2_Click(object sender, EventArgs e) { Close(); } public bool bolNum(string temp) { for (int i = 0; i < temp.Length; i++) { byte tempByte = Convert.ToByte(temp[i]); if ((tempByte < 48) || (tempByte > 57)) return false; } return true; } } }