private void Button_Click(object sender, RoutedEventArgs e) { if (SubjectField.Text.Length > 16) { MessageBox.Show("Subject name must not contain more than 16 letters ", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (String.IsNullOrWhiteSpace(MarkField.Text) || String.IsNullOrWhiteSpace(SubjectField.Text)) { MessageBox.Show("Please, fill all fields", "Error", MessageBoxButton.OK, MessageBoxImage.Error); MarkField.Clear(); SubjectField.Clear(); return; } if (Convert.ToInt32(MarkField.Text) > 10 || Convert.ToInt32(MarkField.Text) < 0) { MessageBox.Show("In the mark field number should be between 0 to 10", "Error", MessageBoxButton.OK, MessageBoxImage.Error); MarkField.Clear(); return; } Student.struct_marks res = new Student.struct_marks { Mark = Convert.ToInt32(MarkField.Text), Subject = SubjectField.Text }; marks.marks.Add(res); prevWindow.Table.Items.Refresh(); Close(); }
private void Upload_Click(object sender, EventArgs e) { Main mn = new Main(); string NM, Gnr; NM = NameField.Text; Gnr = GenreField.Text; String Mrk; Mrk = MarkField.Text; var context = new Films_dbEntities(); var t = new Film //Make sure you have a table called test in DB { Name = NM, Mark = Mrk, Genre = Gnr }; context.Films.Add(t); context.SaveChanges(); NameField.ResetText(); GenreField.ResetText(); MarkField.ResetText(); var form = new Main(); form.Refresh(); mn.loadTable(); MessageBox.Show("Film " + NM + " is added"); }