Я пытаюсь настроить следующее. Список, в котором отображается список ежедневных хирургических операций. При щелчке по делу происходит переход на страницу содержимого, содержащую подробные сведения о деле, а также связанную сетку данных, содержащую все процедуры для этого дела. Я могу увидеть список и перейти к деталям дела. Проблема в том, что процедуры не заполняют сетку данных с помощью sxCaseId. Как мне получить сетку данных для отображения связанных процедур.
SxCaseDetailsView
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:utility="clr-namespace:QiXApp.Utility;assembly=QiXApp"
xmlns:renderers="clr-namespace:Syncfusion.SfDataGrid.XForms.Renderers;assembly=Syncfusion.SfDataGrid.XForms"
xmlns:xForms="clr-namespace:Syncfusion.SfDataGrid.XForms;assembly=Syncfusion.SfDataGrid.XForms"
mc:Ignorable="d"
x:Class="QiXApp.Views.SxCaseDetailsView"
utility:ViewModelLocator.AutoWireViewModel="True"
Title="SxCaseDetailsView New New New"
x:Name="SxCaseDetails">
<ContentPage.Content>
<ScrollView>
<StackLayout>
<Label Text="Case Details" />
<StackLayout Padding="10">
<Grid Grid.Row="0" Padding="10" x:Name="MasterGrid">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label Text="CaseId" Grid.Row="0" Grid.Column="0"/>
<Label Text="{Binding SelectedSxCase.SxCaseId}" Grid.Row="0" Grid.Column="1"/>
<Label Text="Dos" Grid.Row="1" Grid.Column="0"/>
<renderers:SfDatePicker x:Name="dos" BindingContext="{Binding SelectedSxCase.Dos}" Grid.Row="1" Grid.Column="1" HorizontalOptions="StartAndExpand"/>
<Label Text="Eye" Grid.Column="0" Grid.Row="2"/>
<Picker x:Name="EyePicker" ItemsSource="{Binding Eyes, Mode=TwoWay}"
ItemDisplayBinding="{Binding Eye1, Mode=TwoWay}"
SelectedItem="{Binding SelectedSxCase.EyeId, Mode=TwoWay}"
SelectedIndex="{Binding SelectedSxCase.EyeId, Mode=TwoWay}" Grid.Column="1" Grid.Row="2"/>
<Label Text="Facesheet" Grid.Column="0" Grid.Row="3"/>
<Entry Text="{Binding SelectedSxCase.Facesheet, Mode=TwoWay}" Grid.Column="1" Grid.Row="3"/>
<Label Text="Record" Grid.Column="0" Grid.Row="4"/>
<Entry Text="{Binding SelectedSxCase.Record, Mode=TwoWay}" Grid.Column="1" Grid.Row="4"/>
<Label Text="Complication" Grid.Column="0" Grid.Row="5"/>
<Switch IsToggled="{Binding SelectedSxCase.Complication, Mode=TwoWay}" Grid.Column="1" Grid.Row="5"/>
<Label Text="ReturnOr" Grid.Column="0" Grid.Row="6"/>
<Switch IsToggled="{Binding SelectedSxCase.ReturnOr, Mode=TwoWay}" Grid.Column="1" Grid.Row="6"/>
<Label Text="Physician" Grid.Column="0" Grid.Row="7"/>
<Picker x:Name="PhysicianPicker" ItemsSource="{Binding Physicians, Mode=TwoWay}"
ItemDisplayBinding="{Binding Physician1, Mode=TwoWay}"
SelectedItem="{Binding SelectedSxCase.PhysicianId, Mode=TwoWay}"
SelectedIndex="{Binding SelectedSxCase.PhysicianId, Mode=TwoWay}" Grid.Column="1" Grid.Row="7"/>
<Button Text="Update Case" Style="{StaticResource RegularButton}"
Command="{Binding UpdateSxCaseCommand}" Grid.Row="8" Grid.Column="0" Grid.ColumnSpan="2"
HorizontalOptions="Center"/>
<Button Text="Delete Case" Style="{StaticResource RegularButton}"
Command="{Binding DeleteSxCaseCommand}" Grid.Row="8" Grid.Column="1" Grid.ColumnSpan="2"
HorizontalOptions="Center"/>
<Button Text="Procedures" Style="{StaticResource RegularButton}"
Command="{Binding OnOpenSxCaseProceduresJoinCommand}" Grid.Row="8" Grid.Column="2" Grid.ColumnSpan="2"
HorizontalOptions="Center"/>
</Grid>
</StackLayout>
<xForms:SfDataGrid
ItemsSource="{Binding SxCaseProcedureJoins}">
</xForms:SfDataGrid>
</StackLayout>
</ScrollView>
</ContentPage.Content>
</ContentPage>
SxCaseDetailsViewModel
namespace QiXApp.ViewModels
{
public class SxCaseDetailsViewModel : ViewModelBase
{
private ISxCaseDataService _sxCaseDataService;
private ISxCaseProcedureJoinDataService _sxCaseProcedureJoinDataService;
private IEyeDataService _eyeDataService;
private IPhysicianDataService _physicianDataService;
private SxCase _selectedSxCase;
private readonly IGenericRepository _genericRepository;
private ObservableCollection<SxCase> _sxCases;
private ObservableCollection<SxCaseProcedureJoin> _sxCaseProcedureJoins;
private List<Eye> _eyes;
private Eye _selectedEye;
private List<Physician> _physicians;
private Physician _selectedPhysician;
public SxCaseDetailsViewModel(IConnectionService connectionService,
INavigationService navigationService, IDialogService dialogService,
ISxCaseProcedureJoinDataService sxCaseProcedureJoinDataService,
IEyeDataService eyeDataService, IPhysicianDataService physicianDataService,
ISxCaseDataService sxCaseDataService, IEnumerable<SxCaseProcedureJoin> sxCaseId) : base(connectionService, navigationService, dialogService)
{
_sxCaseDataService = sxCaseDataService;
_sxCaseProcedureJoinDataService = sxCaseProcedureJoinDataService;
_eyeDataService = eyeDataService;
_physicianDataService = physicianDataService;
SxCases = new ObservableCollection<SxCase>();
SxCaseProcedureJoins = new ObservableCollection<SxCaseProcedureJoin>(sxCaseId);
GetEyes();
GetPhysicians();
}
public ICommand UpdateSxCaseCommand => new Command(OnUpdateSxCase);
public SxCase SelectedSxCase
{
get => _selectedSxCase;
set
{
_selectedSxCase = value;
OnPropertyChanged();
}
}
public ObservableCollection<SxCase> SxCases
{
get => _sxCases;
set
{
_sxCases = value;
OnPropertyChanged();
}
}
public ObservableCollection<SxCaseProcedureJoin> SxCaseProcedureJoins
{
get => _sxCaseProcedureJoins;
set
{
_sxCaseProcedureJoins = value;
OnPropertyChanged();
}
}
public List<Eye> Eyes
{
get => _eyes;
set
{
_eyes = value;
OnPropertyChanged();
}
}
private async Task GetEyes()
{
Eyes = await _eyeDataService.GetEyeListAsync();
}
public List<Physician> Physicians
{
get => _physicians;
set
{
_physicians = value;
OnPropertyChanged();
}
}
private async Task GetPhysicians()
{
Physicians = await _physicianDataService.GetPhysicianListAsync();
}
//private async Task GetSxCaseProcedureJoins(int sxCaseId)
//{
// SxCaseProcedureJoins =
// (ObservableCollection<SxCaseProcedureJoin>) await _sxCaseProcedureJoinDataService.GetAllSxCaseProcedureJoinsForSxCaseAsync(sxCaseId);
//}
public override async Task InitializeAsync(object data)
{
IsBusy = true;
SxCases = (await _sxCaseDataService.GetAllSxCasesAsync()).ToObservableCollection();
SelectedSxCase = (SxCase)data;
IsBusy = false;
}
public async Task<SxCaseProcedureJoin> GetSxCaseProcedureJoins(int sxCaseId)
{
UriBuilder builder = new UriBuilder(ApiConstants.BaseApiUrl)
{
Path = $"{ApiConstants.SxCaseProcedureJoinsForSxCaseEndpoint}/{sxCaseId}"
};
var sxCaseProcedureJoins = await _genericRepository.GetAsync<SxCaseProcedureJoin>(builder.ToString());
return sxCaseProcedureJoins;
}
private async void OnUpdateSxCase(object sxCase)
{
await _sxCaseDataService.UpdateSxCase(SelectedSxCase.SxCaseId, SelectedSxCase);
OnPropertyChanged();
await _dialogService.ShowDialog("Case details updated.", "Success", "OK");
await _navigationService.NavigateToAsync<SxCaseViewModel>();
//await _navigationService.PopToRootAsync();
}
public ICommand DeleteSxCaseCommand => new Command(async () =>
{
await _sxCaseDataService.DeleteSxCase(SelectedSxCase.SxCaseId);
await _dialogService.ShowDialog("Case deleted.", "Success", "OK");
await _navigationService.NavigateToAsync<SxCaseViewModel>();
});
}
}
SxCaseDataService
namespace QiXApp.Services.Data
{
public class SxCaseDataService : BaseService, ISxCaseDataService
{
HttpClient _client;
public List<SxCase> SxCases { get; private set; }
public List<SxCase> SelectedSxCase { get; private set; }
private readonly IGenericRepository _genericRepository;
public List<Eye> Eyes { get; set; }
public SxCaseDataService(IGenericRepository genericRepository, ISxCaseProcedureJoinDataService sxCaseProcedureJoinDataService,
IBlobCache cache = null) : base(cache)
{
_genericRepository = genericRepository;
_client = new HttpClient();
}
public async Task<IEnumerable<Eye>> GetEyesAsync()
{
UriBuilder builder = new UriBuilder(ApiConstants.BaseApiUrl)
{
Path = ApiConstants.EyeEndpoint
};
var eyes = await _genericRepository.GetAsync<List<Eye>>(builder.ToString());
return eyes;
}
public async Task<IEnumerable<SxCase>> GetAllSxCasesAsync()
{
UriBuilder builder = new UriBuilder(ApiConstants.BaseApiUrl)
{
Path = ApiConstants.SxCaseEndpoint
};
var sxCases = await _genericRepository.GetAsync<List<SxCase>>(builder.ToString());
return sxCases;
}
public async Task UpdateSxCase(int sxCaseId, SxCase selectedSxCase)
{
var httpClient = new HttpClient();
var json = JsonConvert.SerializeObject(selectedSxCase);
StringContent content = new StringContent(json);
content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
UriBuilder builder = new UriBuilder(ApiConstants.BaseApiUrl)
{
Path = ApiConstants.SxCaseEndpoint
};
var result = await httpClient.PutAsync(builder.ToString() + sxCaseId, content);
//var result = await httpClient.PutAsync(Url + sxCaseId, content);
}
public async Task<SxCase> AddSxCase(SxCase sxCase)
{
UriBuilder builder = new UriBuilder(ApiConstants.BaseApiUrl)
{
Path = ApiConstants.SxCaseAddEndpoint
};
var result = await _genericRepository.PostAsync(builder.ToString(), sxCase);
return result;
}
public async Task DeleteSxCase(int sxCaseId)
{
var httpClient = new HttpClient();
UriBuilder builder = new UriBuilder(ApiConstants.BaseApiUrl)
{
Path = ApiConstants.SxCaseDeleteEndpoint
};
var result = await httpClient.DeleteAsync(builder.ToString() + sxCaseId);
}
}
}
SxCaseProcedureJoinDataService
namespace QiXApp.Services
{
public class SxCaseProcedureJoinDataService : BaseService, ISxCaseProcedureJoinDataService
{
HttpClient _client;
public List<SxCaseProcedureJoin> SelectedSxCaseProcedureJoin { get; private set; }
public List<SxCase> SelectedSxCase { get; private set; }
private readonly IGenericRepository _genericRepository;
public IEnumerable<SxCaseProcedureJoin> SxCaseProcedureJoins { get; set; }
public SxCaseProcedureJoinDataService(IGenericRepository genericRepository,
IBlobCache cache = null) : base(cache)
{
_genericRepository = genericRepository;
_client = new HttpClient();
}
public async Task<IEnumerable<SxCaseProcedureJoin>> GetAllSxCaseProcedureJoinsForSxCaseAsync(int sxCaseId)
{
UriBuilder builder = new UriBuilder(ApiConstants.BaseApiUrl)
{
Path = $"{ApiConstants.SxCaseProcedureJoinsForSxCaseEndpoint}/{sxCaseId}"
};
var sxCaseProcedureJoins = await _genericRepository.GetAsync<IEnumerable<SxCaseProcedureJoin>>(builder.ToString());
return sxCaseProcedureJoins;
}
}
}