using System; using System.Data; using System.Windows.Forms; using DevComponents.DotNetBar; namespace Cyberpipe { public delegate void ReloadPatrolerGrid(int pageIndex); public partial class FrmPatrolerEdit : Office2007Form { public event ReloadPatrolerGrid reloadGrid; public FrmPatrolerEdit() { InitializeComponent(); } public FrmPatrolerEdit(string dbid, string name, string age, string sex, string phone) { InitializeComponent(); lab_dbid.Text = dbid; txt_name.Text = name; txt_age.Value = int.Parse(age); if (sex.Equals("男")) { combo_sex.SelectedIndex = 0; } else if (sex.Equals("女")) { combo_sex.SelectedIndex = 1; } //combo_sex.SelectedItem = sex; //combo_sex.SelectedItem = 1; txt_phone.Text = phone; } private void btn_save_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(txt_name.Text.Trim())) { MessageBox.Show("姓名不能为空!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); txt_name.Focus(); return; } if (combo_sex.SelectedItem == null ||String.IsNullOrEmpty(combo_sex.SelectedItem.ToString())) { MessageBox.Show("性别不能为空!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); combo_sex.Focus(); return; } try { string sqlCount = "select count(*) from patroler where username='"+txt_name.Text.Trim()+"'"; int rows = 0; rows = int.Parse(OracleUtils.ExecuteScalar(OracleUtils.ConnectionString, CommandType.Text, sqlCount).ToString()); if (rows>0) { MessageBox.Show("巡检人员已存在,请更换用户名", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (String.IsNullOrEmpty(lab_dbid.Text.Trim())) { String sql = "insert into patroler t (t.username,t.sex,t.age,t.phonenum,t.accountstate,t.password) values ('" + txt_name.Text.Trim() + "','" + combo_sex.SelectedItem.ToString() + "','" + txt_age.Value.ToString() + "','" + txt_phone.Text.Trim() + "','OFFLINE','" + Utility.MD5Encrypt3("111111") + "')"; OracleUtils.ExecuteNonQuery(OracleUtils.ConnectionString, CommandType.Text, sql); if (reloadGrid != null) reloadGrid(1); restForm(); } else { String sql = "update patroler t set t.username='" + txt_name.Text.Trim() + "',t.sex='" + combo_sex.SelectedItem.ToString() + "',t.age='" + txt_age.Value.ToString() + "',t.phonenum='" + txt_phone.Text.Trim() + "' where t.dbid=" + lab_dbid.Text.Trim(); OracleUtils.ExecuteNonQuery(OracleUtils.ConnectionString, CommandType.Text, sql); if (reloadGrid != null) reloadGrid(1); this.Close(); } MessageBox.Show("巡检人员信息保存成功!", "结果", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show("巡检人员信息保存失败:" + ex.ToString(), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void restForm() { this.txt_name.Text = ""; this.txt_age.Value = 17; this.combo_sex.ResetText(); this.txt_phone.Text = ""; this.txt_name.Focus(); } private void txt_phone_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar != 8 && !Char.IsDigit(e.KeyChar)) { e.Handled = true; } else { } } } }