1

これは私が見逃している愚かなものになるだろうと感じています。これは、SQL Server データベースを作成し、C# と WPF を使用して接続する最初の試みです。

View があり、DataContextViewModelです。ViewModel内に、PatientData.Patientsデータセットがあります。

View DataContextPatientData.Patientに設定すると、グリッド内のフィールドに患者データが表示されますが、バインドされたコントロール (次/前/最初/最後) が機能しません。DataContextViewModelに設定すると、バインドされたコントロールは機能しますが、DATASETは機能しません。

私は、Patients バインド コントロールのDataContextを含む Grid をPatientData.Patientに設定する必要があると思いますが、その方法がわかりません。

View DataContextViewModelに設定すると、すべてのコントロールが機能します。ViewModelの一部であるPatientData.Patientsデータセットを参照するにはどうすればよいでしょうか?

これは患者のクラスです

public class PatientRecord
{
    public int PatientID { get; set; }
    public string LastName { get; set; }
    public string LastFirstName { get; set; }
    public string FirstName { get; set; }
    public string FirstLastName { get; set; }
    public string Addr1 { get; set; }
    public string Addr2 { get; set; }
    public string City { get; set; }
    public string State { get; set; }
    public string ZipCode { get; set; }
    public string Phone { get; set; }
    public DateTime DOB { get; set; }
    public string MaritalStatus { get; set; }
    public string Sex { get; set; }
    public string Race { get; set; }
    public bool HealthIns { get; set; }
    public bool OutsidePCP { get; set; }
    public string PrimaryCareProvider { get; set; }
    public object Modified { get; set; }
}

患者レコードと一致する患者からデータを取得するデータセットがあるので、データをレコードに読み込むことができます。患者編集画面のコンストラクターで、現在選択されている患者の記録を患者に渡します。現在のレコードを編集してから、他のレコードに移動できるようにしたい

    public PatientMaintenanceViewModel( ObservableCollection<PatientRecord> patients, PatientRecord selectedPatient )
    {
        try
        {
            Patients = patients;
            SelectedPatient = selectedPatient;
            taPatients.Fill( dsPatient.Patients );
        }
        catch ( Exception ex )
        {
            MessageBox.Show( ex.Message, "PatientMaintenanceViewModel" );
            var errors = dsPatient.Patients.GetErrors();
        }
        taManager.PatientsTableAdapter = taPatients;

        //          DataContext = PatientData.Patient;
        View = (CollectionView)CollectionViewSource.GetDefaultView( dsPatient.Patients );
        MaritalStatuses = _patientRepo.GetMaritalStatuses();
        Races = _patientRepo.GetRaces();
    }

![患者編集画面][1]

それで、私はこれに間違ったアプローチをしていますか、それとも正しい道をたどっていますが、コードが台無しになっていますか?

私は患者のデータセット データと患者の ObservableCollection をコードで持ち歩いています。

4

0 に答える 0