ntminer 5 years ago
parent
commit
bba94d39d6

+ 14 - 45
src/AppModels/MinerStudio/Vms/GpuNamesViewModel.cs

@@ -7,11 +7,8 @@ using System.Windows.Input;
 
 namespace NTMiner.MinerStudio.Vms {
     public class GpuNamesViewModel : ViewModelBase {
-        private List<GpuNameViewModel> _gpuNames;
-        private int _pageIndex = 1;
-        private int _pageSize = 100;
+        private List<GpuNameViewModel> _gpuNames = new List<GpuNameViewModel>();
         private string _keyword;
-        private PagingViewModel _pagingVm;
 
         public ICommand Add { get; private set; }
         public ICommand Remove { get; private set; }
@@ -26,7 +23,6 @@ namespace NTMiner.MinerStudio.Vms {
         private readonly Action _onQueryResponsed;
         public GpuNamesViewModel(Action onQueryResponsed) {
             _onQueryResponsed = onQueryResponsed;
-            this._pagingVm = new PagingViewModel(() => this.PageIndex, () => this.PageSize);
             this.Add = new DelegateCommand(() => {
                 VirtualRoot.Execute(new AddGpuNameCommand(new GpuNameViewModel(new GpuName {
                     GpuType = Core.GpuType.AMD,
@@ -54,74 +50,38 @@ namespace NTMiner.MinerStudio.Vms {
                 }));
             });
             this.Search = new DelegateCommand(() => {
-                this.PageIndex = 1;
+                this.OnPropertyChanged(nameof(QueryResults));
             });
             this.ClearKeyword = new DelegateCommand(() => {
                 Keyword = string.Empty;
             });
-            this.PageSub = new DelegateCommand(() => {
-                this.PageIndex -= 1;
-            });
-            this.PageAdd = new DelegateCommand(() => {
-                this.PageIndex += 1;
-            });
             this.Query();
         }
 
         public void Query() {
-            RpcRoot.OfficialServer.GpuNameService.QueryGpuNamesAsync(new QueryGpuNamesRequest {
-                PageIndex = this.PageIndex,
-                PageSize = this.PageSize,
-                Keyword = this.Keyword
-            }, (response, e) => {
+            RpcRoot.OfficialServer.GpuNameService.QueryGpuNamesAsync((response, e) => {
                 if (response.IsSuccess()) {
                     this.GpuNames = response.Data.OrderBy(a => a.GpuType.GetDescription() + a.Name).Select(a => new GpuNameViewModel(a)).ToList();
-                    _pagingVm.Init(response.Total);
                 }
                 else {
                     this.GpuNames = new List<GpuNameViewModel>();
-                    _pagingVm.Init(0);
                 }
+                this.OnPropertyChanged(nameof(QueryResults));
                 _onQueryResponsed?.Invoke();
             });
         }
 
-        public int PageIndex {
-            get => _pageIndex;
-            set {
-                // 注意PageIndex任何时候都应刷新而不是不等时才刷新
-                _pageIndex = value;
-                OnPropertyChanged(nameof(PageIndex));
-                this.Query();
-            }
-        }
-
-        public int PageSize {
-            get => _pageSize;
-            set {
-                if (_pageSize != value) {
-                    _pageSize = value;
-                    OnPropertyChanged(nameof(PageSize));
-                    this.PageIndex = 1;
-                }
-            }
-        }
-
         public string Keyword {
             get => _keyword;
             set {
                 if (_keyword != value) {
                     _keyword = value;
                     OnPropertyChanged(nameof(Keyword));
-                    this.PageIndex = 1;
+                    
                 }
             }
         }
 
-        public PagingViewModel PagingVm {
-            get { return _pagingVm; }
-        }
-
         public List<GpuNameViewModel> GpuNames {
             get => _gpuNames;
             set {
@@ -131,5 +91,14 @@ namespace NTMiner.MinerStudio.Vms {
                 }
             }
         }
+
+        public List<GpuNameViewModel> QueryResults {
+            get {
+                if (string.IsNullOrEmpty(this.Keyword)) {
+                    return this.GpuNames;
+                }
+                return this.GpuNames.Where(a => a.Name.Contains(this.Keyword)).ToList();
+            }
+        }
     }
 }

+ 9 - 112
src/AppViews0/MinerStudio/Views/Ucs/GpuNames.xaml

@@ -58,7 +58,7 @@
 		<DataGrid 
             Grid.Row="1"
             Margin="0" 
-            ItemsSource="{Binding GpuNames}" 
+            ItemsSource="{Binding QueryResults}" 
 			BorderThickness="0">
 			<DataGrid.Resources>
 				<controls:BindingProxy x:Key="proxy" Data="{Binding}" />
@@ -144,116 +144,13 @@
                 </DataGridTemplateColumn>
             </DataGrid.Columns>
 		</DataGrid>
-        <TextBlock Grid.Row="1" Visibility="{Binding GpuNames,Converter={StaticResource NoRecordVisibilityConverter}}" Foreground="Red" HorizontalAlignment="Center" VerticalAlignment="Center">没有记录</TextBlock>
-        <WrapPanel Grid.Row="2">
-            <Button x:Name="ButtonLeft" IsEnabled="{Binding PagingVm.CanPageSub}" Command="{Binding PageSub}">
-                <Button.Template>
-                    <ControlTemplate>
-                        <Border 
-							x:Name="Content"
-							BorderThickness="1"
-							Background="Transparent">
-                            <Path
-								x:Name="Icon"
-								Width="22"
-								Height="22"
-								Data="{StaticResource Icon_Page-}"
-								Fill="#676767"
-								Stretch="Fill">
-                            </Path>
-                        </Border>
-                        <ControlTemplate.Triggers>
-                            <Trigger Property="IsEnabled" Value="False">
-                                <Setter Property="Opacity" Value="0.5"></Setter>
-                            </Trigger>
-                            <Trigger Property="IsMouseOver" Value="true">
-                                <Setter TargetName="Icon" Property="Fill" Value="{StaticResource BtnBackground}"/>
-                            </Trigger>
-                        </ControlTemplate.Triggers>
-                    </ControlTemplate>
-                </Button.Template>
-            </Button>
-            <ListBox 
-				Margin="4"
-				Background="Transparent"
-				ItemsSource="{Binding PagingVm.PageNumbers}"
-				SelectedItem="{Binding PageIndex}"
-				BorderThickness="0">
-                <ListBox.ItemContainerStyle>
-                    <Style TargetType="ListBoxItem">
-                        <Setter Property="Template">
-                            <Setter.Value>
-                                <ControlTemplate TargetType="ListBoxItem">
-                                    <Border 
-										BorderThickness="1"
-										BorderBrush="{StaticResource LightLineColor}"
-										Margin="4 0"
-										Background="{TemplateBinding Background}" 
-										Width="24" 
-										Height="24" 
-										CornerRadius="12">
-                                        <TextBlock 
-											HorizontalAlignment="Center"
-											VerticalAlignment="Center"
-											Foreground="{TemplateBinding Foreground}"
-											Text="{Binding}"/>
-                                    </Border>
-                                    <ControlTemplate.Triggers>
-                                        <Trigger Property="IsSelected" Value="true">
-                                            <Setter Property="Background" Value="{StaticResource BtnBackground}"/>
-                                            <Setter Property="Foreground" Value="{StaticResource BtnForeground}"/>
-                                        </Trigger>
-                                        <Trigger Property="IsMouseOver" Value="true">
-                                            <Setter Property="Background" Value="{StaticResource BtnBackground}"/>
-                                            <Setter Property="Foreground" Value="{StaticResource BtnForeground}"/>
-                                        </Trigger>
-                                    </ControlTemplate.Triggers>
-                                </ControlTemplate>
-                            </Setter.Value>
-                        </Setter>
-                    </Style>
-                </ListBox.ItemContainerStyle>
-                <ListBox.ItemsPanel>
-                    <ItemsPanelTemplate>
-                        <WrapPanel>
-                        </WrapPanel>
-                    </ItemsPanelTemplate>
-                </ListBox.ItemsPanel>
-            </ListBox>
-            <Button x:Name="ButtonRight" Margin="2 0 0 0" IsEnabled="{Binding PagingVm.CanPageAdd}" Command="{Binding PageAdd}">
-                <Button.Template>
-                    <ControlTemplate>
-                        <Border 
-							x:Name="Content"
-							BorderThickness="1"
-							Background="Transparent">
-                            <Path
-								x:Name="Icon"
-								Width="22"
-								Height="22"
-								Data="{StaticResource Icon_Page+}"
-								Fill="#676767"
-								Stretch="Fill">
-                            </Path>
-                        </Border>
-                        <ControlTemplate.Triggers>
-                            <Trigger Property="IsEnabled" Value="False">
-                                <Setter Property="Opacity" Value="0.5"></Setter>
-                            </Trigger>
-                            <Trigger Property="IsMouseOver" Value="true">
-                                <Setter TargetName="Icon" Property="Fill" Value="{StaticResource BtnBackground}"/>
-                            </Trigger>
-                        </ControlTemplate.Triggers>
-                    </ControlTemplate>
-                </Button.Template>
-            </Button>
-            <TextBlock Margin="10 0 0 0" Foreground="{StaticResource LableColor}" VerticalAlignment="Center" Text="每页"></TextBlock>
-            <TextBlock Padding="4 0" VerticalAlignment="Center" Text="{Binding PageSize}"></TextBlock>
-            <TextBlock VerticalAlignment="Center" Foreground="{StaticResource LableColor}" Text="条,"></TextBlock>
-
-            <TextBlock VerticalAlignment="Center" Foreground="{StaticResource LableColor}" Text="共"></TextBlock>
-            <TextBlock Padding="4 0" VerticalAlignment="Center" Text="{Binding PagingVm.Total}"></TextBlock>
-            <TextBlock VerticalAlignment="Center" Foreground="{StaticResource LableColor}" Text="条"></TextBlock>
-        </WrapPanel>
+        <TextBlock Grid.Row="1" Visibility="{Binding QueryResults,Converter={StaticResource NoRecordVisibilityConverter}}" Foreground="Red" HorizontalAlignment="Center" VerticalAlignment="Center">没有记录</TextBlock>
+        <Border Grid.Row="2" Height="35">
+            <WrapPanel VerticalAlignment="Center">
+                <TextBlock Margin="4 0 0 0" Foreground="{StaticResource LableColor}" Text="共"></TextBlock>
+                <TextBlock Padding="4 0" Text="{Binding GpuNames.Count}"></TextBlock>
+                <TextBlock Foreground="{StaticResource LableColor}" Text="条"></TextBlock>
+            </WrapPanel>
+        </Border>
     </Grid>
 </UserControl>

+ 2 - 3
src/NTMinerRpcClient/Services/Official/GpuNameService.cs

@@ -1,7 +1,6 @@
 using NTMiner.Controllers;
 using NTMiner.Core.Gpus;
 using System;
-using System.Collections.Generic;
 
 namespace NTMiner.Services.Official {
     public class GpuNameService {
@@ -9,8 +8,8 @@ namespace NTMiner.Services.Official {
 
         public GpuNameService() { }
 
-        public void QueryGpuNamesAsync(QueryGpuNamesRequest request, Action<QueryGpuNamesResponse, Exception> callback) {
-            JsonRpcRoot.PostAsync(RpcRoot.OfficialServerHost, RpcRoot.OfficialServerPort, _controllerName, nameof(IGpuNameController.QueryGpuNames), request, callback, timeountMilliseconds: 5 * 1000);
+        public void QueryGpuNamesAsync(Action<QueryGpuNamesResponse, Exception> callback) {
+            JsonRpcRoot.PostAsync(RpcRoot.OfficialServerHost, RpcRoot.OfficialServerPort, _controllerName, nameof(IGpuNameController.QueryGpuNames), new object(), callback, timeountMilliseconds: 5 * 1000);
         }
 
         public void QueryGpuNameCountsAsync(QueryGpuNameCountsRequest request, Action<QueryGpuNameCountsResponse, Exception> callback) {