private void btnOK_Click(object sender, RoutedEventArgs e) { if (dgCases.SelectedItems.Count != 1) { return; } CaseViewModel caseVM = dgCases.SelectedItem as CaseViewModel; if (caseVM != null) { if (caseVM.IsLocked) { MessageBox.Show("Either this case or contacts of this case are locked for editing. Please wait until other users have released this lock before proceeding.", "Record locked", MessageBoxButton.OK, MessageBoxImage.Information); return; } if (dgCases.Visibility == System.Windows.Visibility.Visible) { dateContact.SelectedDate = null; dgCases.Visibility = System.Windows.Visibility.Collapsed; panelInfo.Visibility = System.Windows.Visibility.Visible; txtBorderHeading.Text = Properties.Resources.RelationshipInformation; casesSearchBox.Visibility = System.Windows.Visibility.Collapsed; txtName.Text = CaseVM.Surname + ", " + CaseVM.OtherNames; if (CaseVM.Age.HasValue) { txtAge.Text = CaseVM.Age.Value.ToString(); } //txtSex.Text = CaseVM.Gender; Converters.GenderConverter converter = new Converters.GenderConverter(); txtSex.Text = converter.Convert(CaseVM.Gender, null, false, null).ToString(); // CaseVM.Gender; txtRelationship.Text = String.Empty; dateContact.DisplayDate = DateTime.Now; cbxEstimated.IsChecked = false; cbxCon1.IsChecked = false; cbxCon2.IsChecked = false; cbxCon3.IsChecked = false; cbxCon4.IsChecked = false; } else if (Click != null) { dgCases.Visibility = System.Windows.Visibility.Visible; casesSearchBox.Visibility = System.Windows.Visibility.Visible; panelInfo.Visibility = System.Windows.Visibility.Collapsed; txtBorderHeading.Text = "All cases"; RoutedEventArgs args = new RoutedEventArgs(ConvertToContact.OkClickEvent); Click(this, args); } } else { MessageBox.Show("No case selected.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } }
private void btnOK_Click(object sender, RoutedEventArgs e) { if (dgCases.SelectedItems.Count != 1) { return; } if (CaseVM.IsLocked) { MessageBox.Show("Either this case or contacts of this case are locked for editing. Please wait until other users have released this lock before proceeding.", "Record locked", MessageBoxButton.OK, MessageBoxImage.Information); return; } if (dgCases.Visibility == System.Windows.Visibility.Visible) { if (ExposedCaseVM != null && (ExposedCaseVM == CaseVM || ExposedCaseVM.RecordId == CaseVM.RecordId)) { MessageBox.Show("A case cannot be its own source case.", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } if (DataHelper.CheckForCircularRelationship(CaseVM, ExposedCaseVM) == true) { MessageBox.Show("The selected case (" + CaseVM.ID + ") was exposed by " + ExposedCaseVM.ID + ". Two cases cannot be each other's source case.", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } if (DataHelper.CheckForDuplicateCaseToCaseRelationship(CaseVM, ExposedCaseVM)) { MessageBox.Show("The selected case (" + CaseVM.ID + ") is already a source case of " + ExposedCaseVM.ID + ". ", "Cannot add case", MessageBoxButton.OK, MessageBoxImage.Information); return; } dateContact.SelectedDate = null; //if (ExposedCaseVM != null) //{ // IDbDriver db = DataHelper.Project.CollectedData.GetDatabase(); // Query selectQuery = db.CreateQuery("SELECT * FROM [metaLinks] WHERE [FromRecordGuid] = @FromRecordGuid AND [FromViewId] = @FromViewId AND [ToViewId] = @ToViewId"); // selectQuery.Parameters.Add(new QueryParameter("@FromRecordGuid", DbType.String, caseVM.RecordId)); // selectQuery.Parameters.Add(new QueryParameter("@FromViewId", DbType.Int32, DataHelper.CaseFormId)); // selectQuery.Parameters.Add(new QueryParameter("@ToViewId", DbType.Int32, CaseFormId)); // DataTable dt = db.Select(selectQuery); // var query = from cepVM in DataHelper.CurrentExposureCollection // where cepVM.ExposedCaseVM == CaseVM && cepVM.SourceCaseVM == ExposedCaseVM // select cepVM; // int foundCount = query.Count(); // if (foundCount > 0) // { // CaseExposurePairViewModel cepVM = query.First(); // MessageBox.Show("Case " + cepVM.SourceCaseVM + " is already a source case for " + cepVM.ExposedCaseVM + ".", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation); // return; // } //} dgCases.Visibility = System.Windows.Visibility.Collapsed; panelInfo.Visibility = System.Windows.Visibility.Visible; txtBorderHeading.Text = Properties.Resources.RelationshipInformation; casesSearchBox.Visibility = System.Windows.Visibility.Collapsed; txtName.Text = CaseVM.Surname + ", " + CaseVM.OtherNames; if (CaseVM.Age.HasValue) { txtAge.Text = CaseVM.Age.Value.ToString(); } Converters.GenderConverter converter = new Converters.GenderConverter(); txtSex.Text = converter.Convert(CaseVM.Gender, null, false, null).ToString(); // CaseVM.Gender; txtRelationship.Text = String.Empty; dateContact.DisplayDate = DateTime.Now; cbxTentative.IsChecked = false; cbxEstimated.IsChecked = false; cbxCon1.IsChecked = false; cbxCon2.IsChecked = false; cbxCon3.IsChecked = false; cbxCon4.IsChecked = false; } else if (Click != null) { if (dateContact.SelectedDate.HasValue) { dgCases.Visibility = System.Windows.Visibility.Visible; casesSearchBox.Visibility = System.Windows.Visibility.Visible; panelInfo.Visibility = System.Windows.Visibility.Collapsed; txtBorderHeading.Text = "All cases"; ExposedCaseVM = null; RoutedEventArgs args = new RoutedEventArgs(ExistingCase.OkClickEvent); Click(this, args); } else { MessageBox.Show("Must have a date of last contact to proceed."); return; } } }