// FOR SUBMIT BUTTON public void checkEmptyAndSave() { if (StudentNameText.Text.Length <= 2) { this.ShowMessageAsync("Empty", "Student Name Box is empty!"); StudentNameText.Focus(); } else if (DOBText.Text.Length < 8) { this.ShowMessageAsync("Empty or Missing", "DOB is empty!"); DOBText.Focus(); } else if (FatherCNICText.Text.Length <= 2) { this.ShowMessageAsync("Empty", "Father CNIC Box is empty!"); FatherCNICText.Focus(); } //else if (HomeAddressText.Text.Length <= 2) //{ // this.ShowMessageAsync("Empty", "Address Box is empty!"); // HomeAddressText.Focus(); //} else if (EmergencyText.Text.Length <= 2) { this.ShowMessageAsync("Empty", "Mobile Number Box is empty!"); EmergencyText.Focus(); } else { saveNewStudent(); } }
// FOR UPDATE BUTTON public void emptyBoxes() { if (StudentNameText.Text.Length <= 2) { this.ShowMessageAsync("Empty", "Student Name Box is empty!"); StudentNameText.Focus(); } else if (DOBText.Text.Length < 8) { this.ShowMessageAsync("Empty or Missing", "DOB is empty!"); DOBText.Focus(); } else if (FatherCNICText.Text.Length <= 2) { this.ShowMessageAsync("Empty", "Father CNIC Box is empty!"); FatherCNICText.Focus(); } //else if (HomeAddressText.Text.Length <= 2) //{ // this.ShowMessageAsync("Empty", "Address Box is empty!"); // HomeAddressText.Focus(); //} else if (EmergencyText.Text.Length <= 2) { this.ShowMessageAsync("Empty", "Mobile Number Box is empty!"); EmergencyText.Focus(); } else { try { //3. Mark entity as modified context.Entry(search).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); this.ShowMessageAsync("Student Updated", "Student updated successfully"); clearAll(); nextAdmission(); UpdateButton.Visibility = Visibility.Hidden; SubmitButton.Visibility = Visibility.Visible; Grade.SelectedIndex = 0; onLoad(); } catch (DbEntityValidationException err) { foreach (var eve in err.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } } } }
private void DOBText_KeyUp(object sender, KeyEventArgs e) { if (DOBText.Text.Length == 2) { DOBText.AppendText("/"); DOBText.Focus(); //DOBText.SelectionStart = DOBText.Text.Length; DOBText.CaretIndex = DOBText.Text.Length; } else if (DOBText.Text.Length == 5) { DOBText.AppendText("/"); DOBText.Focus(); //DOBText.SelectionStart = DOBText.Text.Length; DOBText.CaretIndex = DOBText.Text.Length; } }