private void btSave_Click(object sender, EventArgs e) { if (txtName.Text == "" || txtId.Text == "") { DialogResult resulet = MessageBox.Show(this, "请输入完整信息");//保证录入数据的完整性 return; } Form_home form_home = (Form_home)this.Owner; int i; for (i = 0; i < form_home.total; i++) { if (form_home.player[i].getId() == txtId.Text) { DialogResult resulet = MessageBox.Show(this, "不能输入重复的编号"); //保持主键唯一 txtName.Text = ""; txtId.Text = ""; txtId.Focus(); break; } } if (i == form_home.total) { Players p = new Players(txtName.Text, txtId.Text); form_home.getPlayer(p); if (form_home.total >= Convert.ToInt32(txtNumPlayer.Text)) { btSave.Enabled = false; txtName.Enabled = false; txtId.Enabled = false; btSearch.Focus(); } txtName.Text = ""; txtId.Text = ""; txtId.Focus(); } }
private void txtName_KeyDown(object sender, KeyEventArgs e) { Keys k = e.KeyCode; if (k == Keys.Enter) { Form_home form_home = (Form_home)this.Owner; int i; for (i = 0; i < form_home.total; i++) { if (form_home.player[i].getId() == txtId.Text) { DialogResult resulet = MessageBox.Show(this, "不能输入重复的编号"); //保持主键唯一 txtName.Text = ""; txtId.Text = ""; txtId.Focus(); break; } } if (i == form_home.total) { Players p = new Players(txtName.Text, txtId.Text); form_home.getPlayer(p); if (form_home.total >= Convert.ToInt32(txtNumPlayer.Text)) { btSave.Enabled = false; txtName.Enabled = false; txtId.Enabled = false; btSearch.Focus(); } txtName.Text = ""; txtId.Text = ""; txtId.Focus(); } } }