private void BtnAddVisitor_Click(object sender, RoutedEventArgs e) { VisitorsWindow newVisitorWindow = new VisitorsWindow(ds.Tables["Countries"].Rows); if (newVisitorWindow.ShowDialog().Value) { //Add to the database Visitor v = newVisitorWindow.VisitorInfo; string command = "INSERT INTO Visitors " + "(FullName, Major, Country, Status, Speaker, CheckinDate, ConferenceID) VALUES (" + @"'" + v.FullName + @"', " + @"'" + v.Major + @"', " + @"'" + v.Country + @"', " + @"'" + v.VisitorStatus.ToString() + @"', " + @"'" + v.IsSpeaker + @"', " + @"'" + v.CheckInDate + @"', " + conferenceID + ")"; ExecuteNonQuery(command); } }
private void BtnEditVisitorInfo_Click(object sender, RoutedEventArgs e) { if (gridDbData.SelectedIndex >= 0 && gridDbData.SelectedIndex != gridDbData.Items.Count) { DataRowView r = gridDbData.SelectedItem as DataRowView; Visitor existing = GetVisitorObject(r); /*new Visitor() * { * FullName = r["FullName"].ToString(), * Major = r["Major"].ToString(), * Country = r["Country"].ToString(), * VisitorStatus = r["Status"].ToString() == Status.Teacher.ToString() ? Status.Teacher : * r["Status"].ToString() == Status.Student.ToString() ? Status.Student : Status.Proffessional, * IsSpeaker = bool.Parse(r["Speaker"].ToString()), * CheckInDate = DateTime.Parse(r["CheckinDate"].ToString()) * };*/ //MessageBox.Show(gridDbData.SelectedItem.ToString()); VisitorsWindow modifyVisitor = new VisitorsWindow(ds.Tables["Countries"].Rows, existing); if (modifyVisitor.ShowDialog().Value) { Visitor v = modifyVisitor.VisitorInfo; string command = "UPDATE Visitors SET " + @"FullName ='" + v.FullName + @"', " + @"Major ='" + v.Major + @"', " + @"Country ='" + v.Country + @"', " + @"Status ='" + v.VisitorStatus.ToString() + @"', " + @"Speaker ='" + v.IsSpeaker + @"', " + @"CheckinDate ='" + v.CheckInDate + @"' WHERE Id=" + r["Id"]; ExecuteNonQuery(command); } } else { MessageBox.Show("Please select a record first", "No Selection", MessageBoxButton.OK, MessageBoxImage.Warning); } }