private bool ValidateInput() { if (TxtLoginId.Text == "") { MessageBox.Show("请输入用户名", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Information); TxtLoginId.Focus(); return(false); } if (TxtLoginPwdAgain.Text == "") { MessageBox.Show("请输入密码", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Information); TxtLoginPwdAgain.Focus(); return(false); } if (TxtLoginPwdAgain.Text == "") { MessageBox.Show("请输入密码", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Information); TxtLoginPwdAgain.Focus(); return(false); } if (!(TxtLoginPwd.Text == TxtLoginPwdAgain.Text)) { MessageBox.Show("两次输入密码不一致", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Information); TxtLoginPwdAgain.Focus(); return(false); } if (!RadioActive.Checked && !RadioInActive.Checked) { MessageBox.Show("请设置用户状态", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Information); RadioActive.Focus(); return(false); } if (TxtStudentName.Text == "") { MessageBox.Show("请输入学员姓名", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Information); TxtStudentName.Focus(); return(false); } if (TxtId.Text == "") { MessageBox.Show("请输入学员学号", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Information); TxtId.Focus(); return(false); } if (!RadioMale.Checked && !RadioFemale.Checked) { MessageBox.Show("请选择学员性别", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Information); RadioMale.Focus(); return(false); } if (CboClass.Text == "") { MessageBox.Show("请选择学员班级", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Information); CboClass.Focus(); return(false); } return(true); }
private void BtnAddStudent_Click(object sender, RoutedEventArgs e) { try { //if ( string.IsNullOrEmpty(TxtStudentName.Text) || string.IsNullOrEmpty(TxtMatricNo.Text) || string.IsNullOrEmpty(TxtTagId.Text) ) if (string.IsNullOrEmpty(TxtStudentName.Text) || string.IsNullOrEmpty(TxtMatricNo.Text)) { MessageBox.Show(@"All field required"); return; } if (IsMatricNo(TxtMatricNo.Text.Trim()) == false) { MessageBox.Show("Enter a valid MatricNo!"); return; } // TODO: save to tag //WRITE string cmd = "WRITE"; SendMessage(cmd); MessageBox.Show("Place card on RFID reader"); Thread.Sleep(1000); // wait for (1sec) before saving to database //Thread.Sleep(TimeSpan.FromSeconds(1)); //Task.Delay(100) --wait for a particular seconds before saving to db var res = _receivedData; var student = new Student { Name = TxtStudentName.Text.Trim(), MatricNo = TxtMatricNo.Text.Trim(), //TagID = TxtTagId.Text.Trim(), TagID = _receivedData, Department = StudentDept.Text }; var maxId = (_db.Students.Select(p => (int?)p.ID).Max() ?? 0) + 1; student.ID = maxId; try { _db.Students.AddObject(student); } catch { _repo.Students = new List <Student> { student }; } _db.SaveChanges(); //MessageBox.Show("Created successfully"); Refresh(); itemListView.ScrollIntoView(student); TxtStudentName.Clear(); TxtMatricNo.Clear(); TxtTagId.Clear(); /*_db.SaveChanges(); * Refresh(); * itemListView.ScrollIntoView(student); * * // TODO: successful account * //ACCOUNT_CREATED * string cmd = "ACCOUNT_CREATED"; * SendMessage(cmd); * TxtStudentName.Clear(); * TxtMatricNo.Clear(); * TxtTagId.Clear();*/ } catch (Exception ex) { MessageBox.Show(ex.Message); } }