123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333 |
- namespace GDNXFD.Alert.Config.Views
- {
- using GalaSoft.MvvmLight.Command;
- using GDNXFD.Alert.Config.Helpers;
- using GDNXFD.Alert.Config.ViewModel;
- using GDNXFD.Data;
- using GDNXFD.Data.Repositories;
- using Model;
- using System;
- using System.Collections.Generic;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- /// <summary>
- /// Interaction logic for TravelList.xaml
- /// </summary>
- public partial class DIList : UserControl
- {
- private List<PageItem> pageList;
- private PaginationConfig pageConfig;
- string station = string.Empty;
- string rank = string.Empty;
- string category = string.Empty;
- string tagDesc = string.Empty;
- string status = string.Empty;
- private List<string> _statusList;
- private List<string> _rankList;
- private List<string> _stationList;
- bool isLoading = true;
- /// <summary>
- /// Travel List constructor
- /// </summary>
- public DIList()
- {
- InitializeComponent();
- pageConfig = new PaginationConfig(0, 54);
- InitializeLists();
- NavigateToPage(1);
- isLoading = false;
- }
- private void InitializeLists()
- {
- _statusList = new List<string> { "升压站", "光伏" };
- _rankList = new List<string> { "高", "中高" ,"中","中低","低"};
- _stationList = new List<string> { "麻黄山风场", "牛首山风场", "青山风场", "石板泉风场", "香山风场", "大武口光伏电站", "平罗光伏电站", "宣和光伏电站", "马场湖光伏电站" };
- var statusViewSource = ((CollectionViewSource)(FindResource("statusViewSource")));
- statusViewSource.Source = _statusList;
- var rankViewSource = ((CollectionViewSource)(FindResource("rankViewSource")));
- rankViewSource.Source = _rankList;
- var stationViewSource = ((CollectionViewSource)(FindResource("stationViewSource")));
- stationViewSource.Source = _stationList;
- }
- private void TextBoxKeyboard_LostFocus(object sender, System.Windows.RoutedEventArgs e)
- {
- TabtipHelper tabtipHelper = TabtipHelper.Instance;
- tabtipHelper.TryKillTabtipProcess();
- }
- private void btnRefresh_Click(object sender, System.Windows.RoutedEventArgs e)
- {
- NavigateToPage(1);
- }
- private void btnNew_Click(object sender, System.Windows.RoutedEventArgs e)
- {
- dgDIList.CanUserAddRows = true;
- }
- private void txtFilter_TextChanged(object sender, TextChangedEventArgs e)
- {
- tagDesc = txtFilter.Text.Trim();
- }
- private void cmbCategory_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- var item = cmbCategory.SelectedItem as ComboBoxItem;
- if (item == null || item.Tag == null)
- category = string.Empty;
- else
- category = item.Tag.ToString();
- }
- private void cmbRank_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- var item = cmbRank.SelectedItem as ComboBoxItem;
- if (item == null || item.Tag == null)
- rank = string.Empty;
- else
- rank = item.Tag.ToString();
- }
- private void cmbStation_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- var item = cmbStation.SelectedItem as ComboBoxItem;
- if (item == null || item.Tag == null)
- station = string.Empty;
- else
- station = item.Tag.ToString();
- }
- private void cmbConfirmStatus_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- var item = cmbConfirmStatus.SelectedItem as ComboBoxItem;
- if (item == null || item.Tag == null)
- status = string.Empty;
- else
- status = item.Tag.ToString();
- }
- private void chkChanged(object sender, RoutedEventArgs e)
- {
- if (isLoading == true)
- return;
- var chk = e.OriginalSource as CheckBox;
- if (chk == null)
- return;
- var model = chk.DataContext as IFixBJTestingPointDI;
- if (model == null)
- return;
- if (ValidateModel(model) == true)
- {
- IFixBJTestingPointDI obj = AlertSnapRepository.GetIFixBjModel(model.PointKey);
- if (obj != null)
- {
- if (string.IsNullOrEmpty(model.Id) || obj.Id != model.Id)
- {
- MessageBox.Show("测点已存在: " + obj.PointKey);
- return;
- }
- if (obj.Enabled == model.Enabled)
- return;
- AlertSnapRepository.UpdateIFixBj(model);
- }
- }
- }
- #region 分页操作
- private void PrePage_Click(object sender, RoutedEventArgs e)
- {
- if (this.pageConfig.CanGoPrevious)
- {
- this.pageConfig.NumberOfPageSelected = this.pageConfig.NumberOfPageSelected - 1;
- NavigateToPage(this.pageConfig.NumberOfPageSelected);
- }
- }
- private void NextPage_Click(object sender, RoutedEventArgs e)
- {
- if (this.pageConfig.CanGoNext)
- {
- this.pageConfig.NumberOfPageSelected = this.pageConfig.NumberOfPageSelected + 1;
- NavigateToPage(this.pageConfig.NumberOfPageSelected);
- }
- }
- private void FirstPage_Click(object sender, RoutedEventArgs e)
- {
- this.pageConfig.NumberOfPageSelected = 1;
- NavigateToPage(1);
- }
- private void LastPage_Click(object sender, RoutedEventArgs e)
- {
- this.pageConfig.NumberOfPageSelected = this.pageConfig.NumberOfPages;
- NavigateToPage(this.pageConfig.NumberOfPages);
- }
- public List<PageItem> GetPagesList()
- {
- var pagesList = new List<PageItem>();
- pagesList.Add(new PageItem((1).ToString(), true, true));
- for (int i = 2; i <= 5; i++)
- {
- pagesList.Add(new PageItem((i).ToString(), false, true));
- }
- return pagesList;
- }
- private List<PageItem> CalculatePaginator()
- {
- var pages = new List<PageItem>();
- int firstPage = (int)Math.Floor((double)this.pageConfig.NumberOfPageSelected / 12) * 12;
- if (firstPage > 0)
- firstPage = firstPage - 2;
- for (int i = firstPage; i < (firstPage + Math.Min(12, this.pageConfig.NumberOfPages)) && (i < this.pageConfig.NumberOfPages); i++)
- {
- var isSelected = false;
- if (this.pageConfig.NumberOfPageSelected == i + 1)
- isSelected = true;
- PageItem page = new PageItem((i + 1).ToString(), isSelected, true);
- page.PageSelected += PageSelectedChanged;
- pages.Add(page);
- }
- if (this.pageConfig.NumberOfPages > this.pageConfig.PageSize && int.Parse(pages[pages.Count - 1].Page) != this.pageConfig.NumberOfPages)
- {
- pages.Add(new PageItem("...", false, false));
- var lastPage = new PageItem(this.pageConfig.NumberOfPages.ToString(), false, true);
- pages.Add(lastPage);
- lastPage.PageSelected += PageSelectedChanged;
- }
- return pages;
- }
- private void PageSelectedChanged(object sender, EventArgs args)
- {
- this.pageConfig.PageSelected = (PageItem)sender;
- NavigateToPage(this.pageConfig.NumberOfPageSelected);
- }
- private void ResetPaginator()
- {
- if (this.pageList != null)
- {
- foreach (var page in this.pageList)
- {
- page.PageSelected -= PageSelectedChanged;
- }
- }
- }
- private void NavigateToPage(int pageToNavigate)
- {
- isLoading = true;
- try
- {
- ResetPaginator();
- // 1.查询数据绑定到listview
- string filter = CreateFilter();
- int total = 0;
- var alerts = AlertSnapRepository.GetIFixBjPage(filter, pageToNavigate, pageConfig.PageSize, ref total);
- this.dgDIList.ItemsSource = alerts;
- // 2.构造分页器绑定到PageList
- pageConfig.ItemsCounted = total;
- pageList = CalculatePaginator();
- this.icPages.ItemsSource = pageList;
- }
- catch (Exception ex)
- {
- //logger.Error("查询历史报警时发生异常:" + ex.Message);
- }
- isLoading = false;
- }
- private string CreateFilter()
- {
- return String.Format("{0},{1},{2},{3},{4}",
- station, rank, category, status, tagDesc);
- }
- #endregion
- private void dgDIList_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
- {
- if (e.AddedCells.Count == 0) return;
- var currentCell = e.AddedCells[0];
- string header = (string)currentCell.Column.Header;
- if (currentCell.Column == dgDIList.Columns[0]
- || currentCell.Column == dgDIList.Columns[3]
- || currentCell.Column == dgDIList.Columns[4])
- {
- dgDIList.BeginEdit();
- }
- }
- private void dgDIList_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
- {
- var model = e.Row.Item as IFixBJTestingPointDI;
- if (ValidateModel(model) == true)
- {
- IFixBJTestingPointDI obj = AlertSnapRepository.GetIFixBjModel(model.PointKey);
- if (obj != null)
- {
- if (string.IsNullOrEmpty(model.Id) || obj.Id != model.Id)
- {
- MessageBox.Show("测点已存在: " + obj.PointKey);
- return;
- }
- AlertSnapRepository.UpdateIFixBj(model);
- }
- else
- {
- AlertSnapRepository.AddIFixBj(model);
- }
- }
- //dgDIList.CanUserAddRows = false;
- return;
- }
- private bool ValidateModel(IFixBJTestingPointDI model)
- {
- if (model == null)
- return false;
- if (string.IsNullOrWhiteSpace(model.PointKey) ||
- string.IsNullOrWhiteSpace(model.Description) ||
- string.IsNullOrWhiteSpace(model.StationId))
- return false;
- if (string.IsNullOrWhiteSpace(model.LevelId))
- model.LevelId = "MEDIUM";
- if (string.IsNullOrWhiteSpace(model.Area1))
- model.Area1 = "SYZ";
- return true;
- }
- }
- }
|