using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using ZJ_BYD.DB;
using ZJ_BYD.ViewModel;
namespace ZJ_BYD.UserControls.AHeadPara
{
public partial class AheadParaConfig : XtraUserControl
{
private int pagesize = 30; //每页显示行数
private int totalCount = 0; //总记录数
private int pageCurrent = 1; //当前页号
public AheadParaConfig()
{
InitializeComponent();
gridcontrol.CustomDrawRowIndicator += GridView1_CustomDrawRowIndicator;
gridPage1.williamPagerEvent += GridPage1_williamPagerEvent;
gridcontrol.IndicatorWidth = 35;
GetData();
}
private void GetData(int pageCurrent = 1)
{
var list = DataSource();
this.aheadParaGrid.DataSource = list;
gridPage1.RefreshPager(pagesize, totalCount, pageCurrent);
}
///
/// 数据源
///
///
///
private List DataSource(bool isPage = true)
{
var keyWord = this.txtkeyword.Text.Trim();
var data = AheadParaHelper.QueryAheadParaVM(keyWord).Distinct();
if (isPage)
{
return data.ToPageList(pageCurrent, pagesize, ref totalCount);
}
return data.ToList();
}
private void AheadParaConfig_Load(object sender, EventArgs e)
{
this.repositoryItemHyperLinkEdit1.ButtonClick += new ButtonPressedEventHandler(repositoryItemHyperLinkEdit_ButtonClick);
}
private void repositoryItemHyperLinkEdit_ButtonClick(object sender, ButtonPressedEventArgs e)
{
var rowHandle = gridcontrol.FocusedRowHandle;
var model = gridcontrol.GetRow(rowHandle) as AheadParaVM;
EditAheadPara editAheadPara = new EditAheadPara(model.Id);
var result = editAheadPara.ShowDialog();
if (result == DialogResult.OK)
{
GetData();
}
}
private void btnsearch_Click(object sender, EventArgs e)
{
splashScreenManager1.ShowWaitForm();
GetData();
splashScreenManager1.CloseWaitForm();
}
private void btnAdd_Click(object sender, EventArgs e)
{
EditAheadPara editAheadPara = new EditAheadPara();
var result = editAheadPara.ShowDialog();
if (result == DialogResult.OK)
{
GetData();
}
}
private void btnDel_Click(object sender, EventArgs e)
{
var ids = new List();
var rowsNumber = this.gridcontrol.GetSelectedRows();
if (rowsNumber.Length <= 0)
{
XtraMessageBox.Show("请选择数据行!");
return;
}
splashScreenManager1.ShowWaitForm();
foreach (var rownumber in rowsNumber)
{
var aheadPara = this.gridcontrol.GetRow(rownumber) as AheadParaVM;
ids.Add(aheadPara.Id);
}
if (ids.Count > 0)
{
var rows = AheadParaHelper.DoDelAheadParaByIds(ids);
if (rows > 0)
{
splashScreenManager1.CloseWaitForm();
XtraMessageBox.Show("操作成功!");
GetData();
}
else
{
splashScreenManager1.CloseWaitForm();
XtraMessageBox.Show("操作失败!");
}
}
else
{
splashScreenManager1.CloseWaitForm();
}
}
///
/// 分页事件
///
///
///
private void GridPage1_williamPagerEvent(int curPage, int pageSize)
{
pageCurrent = curPage;
pagesize = pageSize;
GetData(curPage);
}
///
/// 行号
///
///
///
private void GridView1_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
{
if (e.Info.IsRowIndicator && e.RowHandle > -1)
{
e.Info.DisplayText = (e.RowHandle + 1).ToString();
}
}
}
}