private void btn_User_Click(object sender, EventArgs e) { if (comboBox1.SelectedIndex > -1) { User user = new User(); user.ID = data[comboBox1.SelectedIndex].ID; user.Username = textBox1.Text.Trim(); user.Remark = textBox2.Text; user.Password = textBox3.Text; Department dep = comboBox2.SelectedItem as Department; if (dep != null) { user.Departments.Clear(); user.Departments.Add(dep); } user.Flag = 0; ConfigEntity ce = comboBox3.SelectedItem as ConfigEntity; if (ce != null) { user.Flag = ce.extension; } UserLogic ul = UserLogic.GetInstance(); if (ul.ExistsNameOther(user.Username, user.ID)) { if (MessageBox.Show("系统中已经存在该名称,确定还要继续保存么?", "重名提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK) { if (ul.UpdateUser(user)) { data[comboBox1.SelectedIndex].Username = user.Username; data[comboBox1.SelectedIndex].Password = user.Password; data[comboBox1.SelectedIndex].Flag = user.Flag; data[comboBox1.SelectedIndex].Departments = user.Departments; data[comboBox1.SelectedIndex].Remark = user.Remark; RefreshInfo(); MessageBox.Show("修改成功!"); } } else { textBox1.Focus(); textBox1.SelectAll(); } } else { if (ul.UpdateUser(user)) { data[comboBox1.SelectedIndex].Username = user.Username; data[comboBox1.SelectedIndex].Password = user.Password; data[comboBox1.SelectedIndex].Flag = user.Flag; data[comboBox1.SelectedIndex].Departments = user.Departments; data[comboBox1.SelectedIndex].Remark = user.Remark; RefreshInfo(); MessageBox.Show("修改成功!"); } } } else { MessageBox.Show("先选定要修改的项目!"); } }