249 lines
7.7 KiB
C#
249 lines
7.7 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Collections.ObjectModel;
|
|||
|
|
using System.ComponentModel;
|
|||
|
|
using System.Data;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Text;
|
|||
|
|
using System.Threading;
|
|||
|
|
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;
|
|||
|
|
using 垂直剖面动态观测系统.Common;
|
|||
|
|
using 垂直剖面动态观测系统.ViewModel;
|
|||
|
|
|
|||
|
|
namespace 垂直剖面动态观测系统.View
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// ParameterView.xaml 的交互逻辑
|
|||
|
|
/// </summary>
|
|||
|
|
public partial class ParameterView : UserControl
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
GlobalValues globalValues = new GlobalValues();
|
|||
|
|
ObservableCollection<para> paraList = new ObservableCollection<para>();
|
|||
|
|
public ParameterView()
|
|||
|
|
{
|
|||
|
|
InitializeComponent();
|
|||
|
|
|
|||
|
|
this.DataContext = globalValues;
|
|||
|
|
|
|||
|
|
|
|||
|
|
for (int i = 0; i < GlobalValues.Para_Model.DateTime.Count; i++)
|
|||
|
|
{
|
|||
|
|
paraList.Add(new para() { _datetime = GlobalValues.Para_Model.DateTime[i], _para = GlobalValues.Para_Model.Para[i] });
|
|||
|
|
}
|
|||
|
|
//dataGrid.ItemsSource = paraList;
|
|||
|
|
ShowPages(dataGrid, tools.ToDataTable(paraList), 12);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
private DataTable _dt = new DataTable();
|
|||
|
|
//每页显示多少条
|
|||
|
|
private int pageNum = 10;
|
|||
|
|
//当前是第几页
|
|||
|
|
private int pIndex = 1;
|
|||
|
|
//对象
|
|||
|
|
private DataGrid grdList;
|
|||
|
|
//最大页数
|
|||
|
|
private int MaxIndex = 1;
|
|||
|
|
//一共多少条
|
|||
|
|
private int allNum = 0;
|
|||
|
|
|
|||
|
|
#region 初始化数据
|
|||
|
|
public void ShowPages(DataGrid grd, DataTable dt, int Num)
|
|||
|
|
{
|
|||
|
|
if (dt == null || dt.Rows.Count == 0)
|
|||
|
|
{
|
|||
|
|
this.Visibility = Visibility.Hidden;
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
this._dt = dt.Clone();
|
|||
|
|
|
|||
|
|
this.grdList = grd;
|
|||
|
|
this.pageNum = Num;
|
|||
|
|
this.pIndex = 1;
|
|||
|
|
foreach (DataRow dr in dt.Rows)
|
|||
|
|
this._dt.ImportRow(dr);
|
|||
|
|
SetMaxIndex();
|
|||
|
|
ReadDataTable();
|
|||
|
|
}
|
|||
|
|
public void ShowPages(int Num)
|
|||
|
|
{
|
|||
|
|
this.pageNum = Num;
|
|||
|
|
this.pIndex = 1;
|
|||
|
|
SetMaxIndex();
|
|||
|
|
ReadDataTable();
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region 画数据
|
|||
|
|
/// <summary>
|
|||
|
|
/// 画数据
|
|||
|
|
/// </summary>
|
|||
|
|
private void ReadDataTable()
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
page.Text = this.pIndex.ToString();
|
|||
|
|
countPage.Text = "页/共" + MaxIndex + "页";
|
|||
|
|
DataTable tmpTable = new DataTable();
|
|||
|
|
tmpTable = this._dt.Clone();
|
|||
|
|
int first = this.pageNum * (this.pIndex - 1);
|
|||
|
|
first = (first > 0) ? first : 0;
|
|||
|
|
//如何总数量大于每页显示数量
|
|||
|
|
if (this._dt.Rows.Count >= this.pageNum * this.pIndex)
|
|||
|
|
{
|
|||
|
|
for (int i = first; i < pageNum * this.pIndex; i++)
|
|||
|
|
tmpTable.ImportRow(this._dt.Rows[i]);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
for (int i = first; i < this._dt.Rows.Count; i++)
|
|||
|
|
tmpTable.ImportRow(this._dt.Rows[i]);
|
|||
|
|
}
|
|||
|
|
this.grdList.ItemsSource = tmpTable.DefaultView;
|
|||
|
|
|
|||
|
|
tmpTable.Dispose();
|
|||
|
|
}
|
|||
|
|
catch
|
|||
|
|
{
|
|||
|
|
MessageBox.Show("错误");
|
|||
|
|
}
|
|||
|
|
finally
|
|||
|
|
{
|
|||
|
|
DisplayPagingInfo();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region 画每页显示等数据
|
|||
|
|
/// <summary>
|
|||
|
|
/// 画每页显示等数据
|
|||
|
|
/// </summary>
|
|||
|
|
private void DisplayPagingInfo()
|
|||
|
|
{
|
|||
|
|
SolidColorBrush brush = new SolidColorBrush(Colors.Gray);
|
|||
|
|
SolidColorBrush brush2 = new SolidColorBrush(Color.FromArgb(255, 1, 84, 74));
|
|||
|
|
if (this.pIndex == 1)
|
|||
|
|
{
|
|||
|
|
this.btnPrev.IsEnabled = false;
|
|||
|
|
this.btnPrev.Foreground = brush;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
this.btnPrev.IsEnabled = true;
|
|||
|
|
this.btnPrev.Foreground = brush2;
|
|||
|
|
}
|
|||
|
|
if (this.pIndex == this.MaxIndex)
|
|||
|
|
{
|
|||
|
|
this.btnNext.IsEnabled = false;
|
|||
|
|
|
|||
|
|
this.btnNext.Foreground = brush;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
this.btnNext.IsEnabled = true;
|
|||
|
|
this.btnNext.Foreground = brush2;
|
|||
|
|
}
|
|||
|
|
int first = (this.pIndex - 4) > 0 ? (this.pIndex - 4) : 1;
|
|||
|
|
int last = (first + 9) > this.MaxIndex ? this.MaxIndex : (first + 9);
|
|||
|
|
// this.grid.Children.Clear();
|
|||
|
|
//for (int i = first; i <= last; i++)
|
|||
|
|
//{
|
|||
|
|
// ColumnDefinition cdf = new ColumnDefinition();
|
|||
|
|
// this.grid.ColumnDefinitions.Add(cdf);
|
|||
|
|
// TextBlock tbl = new TextBlock();
|
|||
|
|
// tbl.Text = i.ToString();
|
|||
|
|
// tbl.MouseLeftButtonUp += new MouseButtonEventHandler(tbl_MouseLeftButtonUp);
|
|||
|
|
// if (i == this.pIndex)
|
|||
|
|
// tbl.IsEnabled = false;
|
|||
|
|
// Grid.SetColumn(tbl, this.grid.ColumnDefinitions.Count - 1);
|
|||
|
|
// Grid.SetRow(tbl, 0);
|
|||
|
|
// this.grid.Children.Add(tbl);
|
|||
|
|
//}
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region 设置最多大页面
|
|||
|
|
/// <summary>
|
|||
|
|
/// 设置最多大页面
|
|||
|
|
/// </summary>
|
|||
|
|
private void SetMaxIndex()
|
|||
|
|
{
|
|||
|
|
//多少页
|
|||
|
|
int Pages = this._dt.Rows.Count / pageNum;
|
|||
|
|
if (this._dt.Rows.Count != (Pages * pageNum))
|
|||
|
|
{
|
|||
|
|
if (_dt.Rows.Count < (Pages * pageNum))
|
|||
|
|
Pages--;
|
|||
|
|
else
|
|||
|
|
Pages++;
|
|||
|
|
}
|
|||
|
|
this.MaxIndex = Pages;
|
|||
|
|
this.allNum = this._dt.Rows.Count;
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
/// <summary>
|
|||
|
|
/// 上一页
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="sender"></param>
|
|||
|
|
/// <param name="e"></param>
|
|||
|
|
private void btnPrev_MouseDown(object sender, MouseButtonEventArgs e)
|
|||
|
|
{
|
|||
|
|
if (this.pIndex <= 1)
|
|||
|
|
return;
|
|||
|
|
this.pIndex--;
|
|||
|
|
ReadDataTable();
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// 下一页
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="sender"></param>
|
|||
|
|
/// <param name="e"></param>
|
|||
|
|
private void btnNext_MouseDown(object sender, MouseButtonEventArgs e)
|
|||
|
|
{
|
|||
|
|
if (this.pIndex >= this.MaxIndex)
|
|||
|
|
return;
|
|||
|
|
this.pIndex++;
|
|||
|
|
ReadDataTable();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void btnGO_Click(object sender, RoutedEventArgs e)
|
|||
|
|
{
|
|||
|
|
if (page.Text == "")
|
|||
|
|
return;
|
|||
|
|
if (Convert.ToInt32(page.Text) <= 1)
|
|||
|
|
return;
|
|||
|
|
this.pIndex = Convert.ToInt32(page.Text);
|
|||
|
|
ReadDataTable();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public class para
|
|||
|
|
{
|
|||
|
|
public string _datetime { get; set; }
|
|||
|
|
public float _para { get; set; }
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private async void Button_Click(object sender, RoutedEventArgs e)
|
|||
|
|
{
|
|||
|
|
await Task.Delay(1000);
|
|||
|
|
paraList = new ObservableCollection<para>();
|
|||
|
|
for (int i = 0; i < GlobalValues.Para_Model.DateTime.Count; i++)
|
|||
|
|
{
|
|||
|
|
paraList.Add(new para() { _datetime = GlobalValues.Para_Model.DateTime[i], _para = GlobalValues.Para_Model.Para[i] });
|
|||
|
|
}
|
|||
|
|
ShowPages(dataGrid, tools.ToDataTable(paraList), 12);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|