<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      WPF MVVM, SqlSugar access MySQL batch by batch

      Install-Package NewtonSoft.Json;
      Install-Package MySQL.Data;
      Install-Package SqlSugar;

       

      mysql> show create table t1;
      +-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
      | Table | Create Table                                                                                                                                                                                                                                                                                                          |
      +-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
      | t1    | CREATE TABLE `t1` (
        `id` int NOT NULL AUTO_INCREMENT,
        `firstname` varchar(100) NOT NULL DEFAULT '',
        `lastname` varchar(100) NOT NULL DEFAULT '',
        PRIMARY KEY (`id`),
        KEY `fn_ln_index` (`firstname`,`lastname`)
      ) ENGINE=InnoDB AUTO_INCREMENT=458600003 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |
      +-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
      1 row in set (0.01 sec)

       

      image

       

       

      public class BookService
      {
          private readonly SqlSugarScope db;
          public BookService()
          {
              db = DatabaseConfig.GetSqlSugarClient();
          }
      
          public Book GetBookById(int id)
          {
              return db.Queryable<Book>().Where(x => x.Id == id).First();
          }
      
          public List<Book> GetBooksRangeList(int startId, int endId)
          {
              return db.Queryable<Book>().Where(x => x.Id >= startId && x.Id <= endId).ToList();
          }
      
          public List<Book> GetUsersByConditions(string fnValue, string lnValue)
          {
              return db.Queryable<Book>()
                  .Where(x => string.Equals(x.FirstName, fnValue, StringComparison.InvariantCultureIgnoreCase)
                  || string.Equals(x.LastName, lnValue, StringComparison.InvariantCultureIgnoreCase)).ToList();
          }
      
      
          public (List<Book> Data, int Total) GetBooksPaged(int pageIdx, int pageSize)
          {
              int total = 0;
              var data = db.Queryable<Book>()
                  .ToPageList(pageIdx, pageSize, ref total);
              return (data, total);
          }
      }
      
      
        private void NextCommandExecuted(object? obj)
        {
            ++batchIdx;
            BooksCollection = new ObservableCollection<Book>(bookService.GetBooksRangeList(batchIdx * batchSize+1, (batchIdx + 1) * batchSize));
            MainTitle = $"Loaded from{batchIdx * batchSize + 1} to {(batchIdx + 1) * batchSize}";
        }

       

      image

       

       

       

       

      image

       

       

       

       

      image

       

      image

       

       

      <Application x:Class="WpfApp33.App"
                   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                   xmlns:local="clr-namespace:WpfApp33"
                   StartupUri="MainWindow.xaml">
          <Application.Resources>
              <Style TargetType="Button">
                  <Setter Property="FontSize" Value="50"/>
                  <Style.Triggers>
                      <Trigger Property="IsMouseOver" Value="True">
                          <Setter Property="Foreground" Value="Red"/>
                      </Trigger>
                  </Style.Triggers>
              </Style>
          </Application.Resources>
      </Application>
      
      
      <Window x:Class="WpfApp33.MainWindow"
              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
              xmlns:local="clr-namespace:WpfApp33"
              mc:Ignorable="d"
              WindowState="Maximized"
              Title="{Binding MainTitle}" Height="450" Width="800">
          <Grid>
              <Grid.RowDefinitions>
                  <RowDefinition/>
                  <RowDefinition Height="Auto"/>
              </Grid.RowDefinitions>
              <Grid.ColumnDefinitions>
                  <ColumnDefinition/>
                  <ColumnDefinition/>
              </Grid.ColumnDefinitions>
              <DataGrid Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2"
                        ItemsSource="{Binding BooksCollection,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
                        VirtualizingPanel.IsVirtualizing="True"
                        VirtualizingPanel.VirtualizationMode="Recycling"
                        VirtualizingPanel.CacheLengthUnit="Item"
                        VirtualizingPanel.CacheLength="2,2"
                        ScrollViewer.IsDeferredScrollingEnabled="True"
                        ScrollViewer.CanContentScroll="True"
                        AutoGenerateColumns="False"
                        CanUserAddRows="False">
                  <DataGrid.Columns>
                      <DataGridTemplateColumn>
                          <DataGridTemplateColumn.CellTemplate>
                              <DataTemplate>
                                  <Grid Width="{Binding DataContext.GridWidth,RelativeSource={RelativeSource AncestorType=Window}}"
                                        Height="{Binding DataContext.GridHeight,RelativeSource={RelativeSource AncestorType=Window}}">
                                      <Grid.Resources>
                                          <Style TargetType="TextBlock">
                                              <Setter Property="FontSize" Value="30"/>
                                              <Style.Triggers>
                                                  <Trigger Property="IsMouseOver" Value="True">
                                                      <Setter Property="FontSize" Value="50"/>
                                                      <Setter Property="Foreground" Value="Red"/>
                                                  </Trigger>
                                              </Style.Triggers>
                                          </Style>
                                      </Grid.Resources>
                                      <Grid.ColumnDefinitions>
                                          <ColumnDefinition/>
                                          <ColumnDefinition/>
                                          <ColumnDefinition/>
                                      </Grid.ColumnDefinitions>
                                      <TextBlock Grid.Column="0" Text="{Binding Id}"/>
                                      <TextBlock Grid.Column="1" Text="{Binding FirstName}"/>
                                      <TextBlock Grid.Column="2" Text="{Binding LastName}"/>
                                  </Grid>
                              </DataTemplate>
                          </DataGridTemplateColumn.CellTemplate>
                      </DataGridTemplateColumn>
                  </DataGrid.Columns>
              </DataGrid>
              <Grid Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2">
                  <Grid.ColumnDefinitions>
                      <ColumnDefinition/>
                      <ColumnDefinition/>
                  </Grid.ColumnDefinitions>
                  <Button Grid.Column="0" Content="Prev" Command="{Binding PrevCommand}"/>
                  <Button Grid.Column="1" Content="Next" Command="{Binding NextCommand}"/>
              </Grid>
          </Grid>
      </Window>
      
      using SqlSugar;
      using System.Collections.ObjectModel;
      using System.ComponentModel;
      using System.Runtime.CompilerServices;
      using System.Text;
      using System.Windows;
      using System.Windows.Controls;
      using System.Windows.Data;
      using System.Windows.Documents;
      using System.Windows.Input;
      using System.Windows.Media;
      using System.Windows.Media.Imaging;
      using System.Windows.Navigation;
      using System.Windows.Shapes;
      
      namespace WpfApp33
      {
          /// <summary>
          /// Interaction logic for MainWindow.xaml
          /// </summary>
          public partial class MainWindow : Window
          {
              public MainWindow()
              {
                  InitializeComponent();
                  var vm = new MainVM();
                  this.DataContext = vm;
                  this.Loaded += async (s, e) =>
                  {
                      await vm.InitBooksCollection();
                      vm.GridWidth = this.ActualWidth;
                      vm.GridHeight= this.ActualHeight/10;
                  };
              }
          }
      
          public class MainVM : INotifyPropertyChanged
          {
              int batchSize = 1_000_000;
              int batchIdx = 0;
              private BookService bookService;
      
              public MainVM()
              {
                  bookService = new BookService();
                  PrevCommand = new DelCommand(PrevCommandExecuted);
                  NextCommand = new DelCommand(NextCommandExecuted);
              }
      
              private void NextCommandExecuted(object? obj)
              {
                  ++batchIdx;
                  BooksCollection = new ObservableCollection<Book>(bookService.GetBooksRangeList(batchIdx * batchSize+1, (batchIdx + 1) * batchSize));
                  MainTitle = $"Loaded from{batchIdx * batchSize + 1} to {(batchIdx + 1) * batchSize}";
              }
      
              private void PrevCommandExecuted(object? obj)
              {
                  if (--batchIdx >= 0)
                  {
                      BooksCollection = new ObservableCollection<Book>(bookService.GetBooksRangeList(batchIdx * batchSize+1, (batchIdx + 1) * batchSize));
                      MainTitle = $"Loaded from{batchIdx * batchSize + 1} to {(batchIdx + 1) * batchSize}";
                  }
              }
      
              public async Task InitBooksCollection()
              {
                  BooksCollection = new ObservableCollection<Book>(bookService.GetBooksRangeList(batchIdx * batchSize+1, (batchIdx + 1) * batchSize));
                  MainTitle = $"Loaded from{batchIdx * batchSize + 1} to {(batchIdx + 1) * batchSize}";
              }
      
              public event PropertyChangedEventHandler? PropertyChanged;
              private void OnPropertyChanged([CallerMemberName] string propName = "")
              {
                  var handler = PropertyChanged;
                  if (handler != null)
                  {
                      handler?.Invoke(this, new PropertyChangedEventArgs(propName));
                  }
              }
      
      
              private ObservableCollection<Book> booksCollection;
              public ObservableCollection<Book> BooksCollection
              {
                  get
                  {
                      return booksCollection;
                  }
                  set
                  {
                      if (value != booksCollection)
                      {
                          booksCollection = value;
                          OnPropertyChanged(nameof(BooksCollection));
                      }
                  }
              }
      
      
              private double gridWidth;
              public double GridWidth
              {
                  get
                  {
                      return gridWidth;
                  }
                  set
                  {
                      if(value != gridWidth)
                      {
                          gridWidth = value;
                          OnPropertyChanged();
                      }
                  }
              }
      
              private double gridHeight;
              public double GridHeight
              {
                  get
                  {
                      return gridHeight;
                  }
                  set
                  {
                      if(value!=gridHeight)
                      {
                          gridHeight = value;
                          OnPropertyChanged();
                      }
                  }
              }
      
              private string mainTitle;
              public string MainTitle
              {
                  get
                  {
                      return mainTitle; 
                  }
                  set
                  {
                      if(value!=mainTitle)
                      {
                          mainTitle = value;
                          OnPropertyChanged();
                      }
                  }
              }
      
              public ICommand PrevCommand { get; set; }
              public ICommand NextCommand { get; set; }
          }
      
      
          [SugarTable("t1")]
          public class Book
          {
              [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
              public int Id { get; set; }
              public string FirstName { get; set; }
              public string LastName { get; set; }
          }
      
      
          public class BookService
          {
              private readonly SqlSugarScope db;
              public BookService()
              {
                  db = DatabaseConfig.GetSqlSugarClient();
              }
      
              public Book GetBookById(int id)
              {
                  return db.Queryable<Book>().Where(x => x.Id == id).First();
              }
      
              public List<Book> GetBooksRangeList(int startId, int endId)
              {
                  var resultList= db.Queryable<Book>().Where(x => x.Id >= startId && x.Id <= endId).ToList();
                  if (resultList == null || !resultList.Any())
                  {
                      MessageBox.Show("No proper data set retrieved!");
                      return null;
                  }
                  return resultList;
              }
      
              public List<Book> GetUsersByConditions(string fnValue, string lnValue)
              {
                  return db.Queryable<Book>()
                      .Where(x => string.Equals(x.FirstName, fnValue, StringComparison.InvariantCultureIgnoreCase)
                      || string.Equals(x.LastName, lnValue, StringComparison.InvariantCultureIgnoreCase)).ToList();
              }
      
      
              public (List<Book> Data, int Total) GetBooksPaged(int pageIdx, int pageSize)
              {
                  int total = 0;
                  var data = db.Queryable<Book>()
                      .ToPageList(pageIdx, pageSize, ref total);
                  return (data, total);
              }
          }
      
      
          public class DatabaseConfig
          {
              public static SqlSugarScope GetSqlSugarClient()
              {
                  return new SqlSugarScope(new ConnectionConfig()
                  {
                      ConnectionString = "Server=localhost;Database=databasename;Uid=uidvalue;Pwd=passwordValue",
                      DbType = DbType.MySql,
                      IsAutoCloseConnection = true,
                      InitKeyType = InitKeyType.Attribute
                  });
              }
          }
      
      
          public class DelCommand : ICommand
          {
              private Action<object?> execute;
              private Predicate<object?> canExecute;
      
              public DelCommand(Action<object?> executeValue, Predicate<object?> canExecuteValue = null)
              {
                  execute = executeValue;
                  canExecute = canExecuteValue;
              }
      
              public event EventHandler? CanExecuteChanged
              {
                  add
                  {
                      CommandManager.RequerySuggested += value;
                  }
                  remove
                  {
                      CommandManager.RequerySuggested -= value;
                  }
              }
      
              public bool CanExecute(object? parameter)
              {
                  return canExecute == null ? true : canExecute(parameter);
              }
      
              public void Execute(object? parameter)
              {
                  execute(parameter);
              }
          }
      }

       

      posted @ 2025-10-17 09:46  FredGrit  閱讀(5)  評論(0)    收藏  舉報(bào)
      主站蜘蛛池模板: 特克斯县| 午夜高清福利在线观看| 亚洲精品专区永久免费区| 鹿泉市| 亚洲国产精品综合久久2007| 天堂亚洲免费视频| 韩国免费A级毛片久久| 日本人一区二区在线观看| 国产精品人妻在线观看| 国产精品免费无遮挡无码永久视频| 国产无遮挡吃胸膜奶免费看| 国内精品亚洲成av人片| 利津县| 2021国产成人精品久久 | 亚洲人成日韩中文字幕不卡| 亚洲欧美人成人综合在线播放 | 中文字幕日本一区二区在线观看| 一区二区中文字幕久久| 97在线视频人妻无码| 一面膜上边一面膜下边视频| 后入内射无码人妻一区| 国产视频一区二区三区麻豆| 久久99国产精品尤物| 爱性久久久久久久久| 亚洲一区在线观看青青蜜臀| 亚洲日韩国产精品第一页一区| 久久一级精品久熟女人妻| 亚洲 日本 欧洲 欧美 视频| 狠狠做五月深爱婷婷天天综合 | 亚洲五月丁香综合视频| 九九热视频在线观看一区| 在厨房拨开内裤进入在线视频| 亚洲一级片一区二区三区| 老王亚洲AV综合在线观看| 囯产精品久久久久久久久久妞妞 | 午夜福利电影| 亚洲中文字幕第一页在线| 亚洲成av人片天堂网| 蜜臀久久99精品久久久久久 | 亚洲av第一区二区三区| 亚洲欧洲精品一区二区|