|
@@ -0,0 +1,251 @@
|
|
|
+using MeterVision.Config;
|
|
|
+using MeterVision.db;
|
|
|
+using MeterVision.model;
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Collections.ObjectModel;
|
|
|
+using System.ComponentModel;
|
|
|
+using System.Linq;
|
|
|
+using System.Text;
|
|
|
+using System.Threading.Tasks;
|
|
|
+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 MeterVision.Station
|
|
|
+{
|
|
|
+ /// <summary>
|
|
|
+ /// UCVpsGrid.xaml 的交互逻辑
|
|
|
+ /// </summary>
|
|
|
+ public partial class UCVpsGrid : UserControl, INotifyPropertyChanged
|
|
|
+ {
|
|
|
+ public event PropertyChangedEventHandler PropertyChanged;
|
|
|
+
|
|
|
+ protected void OnPropertyChanged(string propertyName)
|
|
|
+ {
|
|
|
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
|
+ }
|
|
|
+
|
|
|
+ public ObservableCollection<VPatchStation> StationItemList { get; set; }
|
|
|
+
|
|
|
+ public event Action<VPatchStation> OnItemChanged;
|
|
|
+
|
|
|
+ private VPatchStation _selectedItem;
|
|
|
+
|
|
|
+ public VPatchStation SelectedItem
|
|
|
+ {
|
|
|
+ get => _selectedItem;
|
|
|
+ set
|
|
|
+ {
|
|
|
+ if(_selectedItem != value)
|
|
|
+ {
|
|
|
+ _selectedItem = value;
|
|
|
+ OnPropertyChanged(nameof(SelectedItem));
|
|
|
+ OnItemChanged?.Invoke(value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //要查找的站点ID
|
|
|
+ private string _findStationId;
|
|
|
+ public string FindStationId
|
|
|
+ {
|
|
|
+ get => _findStationId;
|
|
|
+ private set
|
|
|
+ {
|
|
|
+ if (_findStationId != value)
|
|
|
+ {
|
|
|
+ _findStationId = value;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private string _patchId;
|
|
|
+ public string PatchId
|
|
|
+ {
|
|
|
+ get => _patchId;
|
|
|
+ private set
|
|
|
+ {
|
|
|
+ if (_patchId != value)
|
|
|
+ {
|
|
|
+ _patchId = value;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void ChangeFind(string stationId, string patchId)
|
|
|
+ {
|
|
|
+ bool blChangeFindStationId = false;
|
|
|
+ bool blChangePatchId = false;
|
|
|
+
|
|
|
+ if (stationId != _findStationId)
|
|
|
+ {
|
|
|
+ FindStationId = stationId;
|
|
|
+ blChangeFindStationId = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (patchId != _patchId)
|
|
|
+ {
|
|
|
+ PatchId = patchId;
|
|
|
+ blChangePatchId = true;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (blChangeFindStationId || blChangePatchId)
|
|
|
+ {
|
|
|
+ StationPage.InitDefaulValue();
|
|
|
+ LoadStationItemList(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public CfginiItem mConfigItem { get; set; }
|
|
|
+
|
|
|
+ public PageModel StationPage { get; set; }
|
|
|
+
|
|
|
+ private int _totalRecords;
|
|
|
+ public int TotalRecords
|
|
|
+ {
|
|
|
+ get => _totalRecords;
|
|
|
+ set
|
|
|
+ {
|
|
|
+ if (_totalRecords != value)
|
|
|
+ {
|
|
|
+ _totalRecords = value;
|
|
|
+ OnPropertyChanged(nameof(TotalRecords));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public UCVpsGrid()
|
|
|
+ {
|
|
|
+ InitializeComponent();
|
|
|
+ StationItemList = new ObservableCollection<VPatchStation>();
|
|
|
+ dgStation.ItemsSource = StationItemList;
|
|
|
+
|
|
|
+ mConfigItem = CfginiItem.GetConfigItem();
|
|
|
+
|
|
|
+ StationPage = new PageModel
|
|
|
+ {
|
|
|
+ PageSize = mConfigItem.PatchPageSize,
|
|
|
+ PageNumber = 1
|
|
|
+ };
|
|
|
+
|
|
|
+ mConfigItem.OnPatchPageSizeChanged += MConfigItem_OnPatchPageSizeChanged;
|
|
|
+
|
|
|
+ this.DataContext = this;
|
|
|
+ }
|
|
|
+ private void MConfigItem_OnPatchPageSizeChanged(int pageSize)
|
|
|
+ {
|
|
|
+ StationPage.InitDefaulValue(pageSize);
|
|
|
+ LoadStationItemList(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ private async void LoadStationItemList(bool scrollTop)
|
|
|
+ {
|
|
|
+ StationItemList.Clear();
|
|
|
+
|
|
|
+ if (FindStationId == null)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var result = await Task.Run(() =>
|
|
|
+ {
|
|
|
+ return DBPatch.GetPagedPatchStations(StationPage.PageNumber, StationPage.PageSize,PatchId);
|
|
|
+ });
|
|
|
+
|
|
|
+ //更新分页信息
|
|
|
+ TotalRecords = result.Item1;
|
|
|
+ StationPage.PageCount = result.Item2;
|
|
|
+ List<VPatchStation> stationList = result.Item3;
|
|
|
+
|
|
|
+ //在主线中更新数据
|
|
|
+ Application.Current.Dispatcher.Invoke(() =>
|
|
|
+ {
|
|
|
+ int index = 0;
|
|
|
+ foreach (VPatchStation station in stationList)
|
|
|
+ {
|
|
|
+ index++;
|
|
|
+ //StationItem item = new StationItem(station);
|
|
|
+ //item.Index = index + ((StationPage.PageNumber - 1) * StationPage.PageSize);
|
|
|
+ //StationItemList.Add(item);
|
|
|
+ station.Index = index + ((StationPage.PageNumber - 1) * StationPage.PageSize);
|
|
|
+ }
|
|
|
+
|
|
|
+ SelectedItem = null;
|
|
|
+ if (StationItemList.Count > 0 && scrollTop)
|
|
|
+ {
|
|
|
+ dgStation.ScrollIntoView(dgStation.Items[0]);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ MessageBox.Show(Application.Current.MainWindow,
|
|
|
+ $"加载数据是发生错误:{ex.Message}", "错误",
|
|
|
+ MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
+ }
|
|
|
+ SelectedItem = null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void NextPage()
|
|
|
+ {
|
|
|
+ if (StationPage.PageNumber < StationPage.PageCount)
|
|
|
+ {
|
|
|
+ StationPage.PageNumber += 1;
|
|
|
+ LoadStationItemList(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void PrePage()
|
|
|
+ {
|
|
|
+ if (StationPage.PageNumber > 1)
|
|
|
+ {
|
|
|
+ StationPage.PageNumber -= 1;
|
|
|
+ LoadStationItemList(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void FirstPage()
|
|
|
+ {
|
|
|
+ if (StationPage.PageNumber > 1)
|
|
|
+ {
|
|
|
+ StationPage.PageNumber = 1;
|
|
|
+ LoadStationItemList(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void LastPage()
|
|
|
+ {
|
|
|
+ if (StationPage.PageNumber < StationPage.PageCount)
|
|
|
+ {
|
|
|
+ StationPage.PageNumber = StationPage.PageCount;
|
|
|
+ LoadStationItemList(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void SpeciPage(int pageNumber)
|
|
|
+ {
|
|
|
+ if (pageNumber != StationPage.PageNumber &&
|
|
|
+ pageNumber > 0 && pageNumber <= StationPage.PageCount)
|
|
|
+ {
|
|
|
+ StationPage.PageNumber = pageNumber;
|
|
|
+ LoadStationItemList(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //---------------------------------------------------------------------
|
|
|
+ }
|
|
|
+}
|