You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

142 lines
4.9 KiB
C#

using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;
using System.Collections.Generic;
using System.Windows.Forms;
using ZJ_BYD.DB;
using ZJ_BYD.Model;
namespace ZJ_BYD.UserControls.MachineType
{
public partial class MachineType : XtraUserControl
{
private int pagesize = 30; //每页显示行数
private int totalCount = 0; //总记录数
private int pageCurrent = 1; //当前页号
public MachineType()
{
InitializeComponent();
gridView1.CustomDrawRowIndicator += GridView1_CustomDrawRowIndicator;
gridPage1.williamPagerEvent += GridPage1_williamPagerEvent;
gridView1.IndicatorWidth = 35;
GetData();
}
private void btnsearch_Click(object sender, System.EventArgs e)
{
splashScreenManager1.ShowWaitForm();
GetData();
splashScreenManager1.CloseWaitForm();
}
private void btnadd_Click(object sender, System.EventArgs e)
{
EditMachineType editMachineType = new EditMachineType();
var result = editMachineType.ShowDialog();
if (result == DialogResult.OK)
{
GetData();
}
}
private void btndel_Click(object sender, System.EventArgs e)
{
splashScreenManager1.ShowWaitForm();
var ids = new List<int>();
var rowsNumber = this.gridView1.GetSelectedRows();
if (rowsNumber.Length <= 0)
{
XtraMessageBox.Show("请选择数据行!");
splashScreenManager1.CloseWaitForm();
return;
}
foreach (var rownumber in rowsNumber)
{
var t_Station = this.gridView1.GetRow(rownumber) as T_MachineType;
ids.Add(t_Station.Id);
}
if (ids.Count > 0)
{
var rows = MachineTypeHelper.DelMachineTypeByIds(ids);
if (rows > 0)
{
XtraMessageBox.Show("操作成功!");
GetData();
}
else
{
XtraMessageBox.Show("操作失败!");
}
}
splashScreenManager1.CloseWaitForm();
}
private void MachineType_Load(object sender, System.EventArgs e)
{
this.repositoryItemHyperLinkEdit1.ButtonClick += new ButtonPressedEventHandler(repositoryItemHyperLinkEdit_ButtonClick);
}
private void repositoryItemHyperLinkEdit_ButtonClick(object sender, ButtonPressedEventArgs e)
{
var rowHandle = gridView1.FocusedRowHandle;
var model = gridView1.GetRow(rowHandle) as T_MachineType;
EditMachineType editMachineType = new EditMachineType(model.Id);
var result = editMachineType.ShowDialog();
if (result == DialogResult.OK)
{
GetData();
}
}
private void GetData(int pageCurrent = 1)
{
var list = DataSource();
this.GridMak.DataSource = list;
gridPage1.RefreshPager(pagesize, totalCount, pageCurrent);
}
/// <summary>
/// 数据源
/// </summary>
/// <param name="isPage"></param>
/// <returns></returns>
private List<T_MachineType> DataSource(bool isPage = true)
{
var keyWord = this.txtkeyword.Text.Trim();
var data = MachineTypeHelper.QueryActiveMachines();
if (isPage)
{
return data.WhereIF(!string.IsNullOrWhiteSpace(keyWord), m => m.MachineTypeCode.ToLower().Contains(keyWord.ToLower()) || m.MachineTypeName.ToLower().Contains(keyWord.ToLower()))
.ToPageList(pageCurrent, pagesize, ref totalCount);
}
return data.WhereIF(!string.IsNullOrWhiteSpace(keyWord), m => m.MachineTypeCode.ToLower().Contains(keyWord.ToLower()) || m.MachineTypeName.ToLower().Contains(keyWord.ToLower()))
.ToList();
}
/// <summary>
/// 分页事件
/// </summary>
/// <param name="curPage"></param>
/// <param name="pageSize"></param>
private void GridPage1_williamPagerEvent(int curPage, int pageSize)
{
pageCurrent = curPage;
pagesize = pageSize;
GetData(curPage);
}
/// <summary>
/// 行号
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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();
}
}
}
}