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.TestItem { public partial class TestItems : XtraUserControl { private int pagesize = 30; //每页显示行数 private int totalCount = 0; //总记录数 private int pageCurrent = 1; //当前页号 public TestItems() { InitializeComponent(); gridcontrol.CustomDrawRowIndicator += GridView1_CustomDrawRowIndicator; gridPage1.williamPagerEvent += GridPage1_williamPagerEvent; gridcontrol.IndicatorWidth = 35; GetData(); } private void TestItems_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 TestItemVM; EditTestItem editStation = new EditTestItem(model.Id); var result = editStation.ShowDialog(); if (result == DialogResult.OK) { GetData(); } } private void GetData(int pageCurrent = 1) { var list = DataSource(); this.gridview1.DataSource = list; gridPage1.RefreshPager(pagesize, totalCount, pageCurrent); } private void btnsearch_Click(object sender, EventArgs e) { splashScreenManager1.ShowWaitForm(); GetData(); splashScreenManager1.CloseWaitForm(); } private void btnChangeMachineType_Click(object sender, EventArgs e) { splashScreenManager1.ShowWaitForm(); var rowsNumbers = gridcontrol.GetSelectedRows(); if (rowsNumbers.Length <= 0 || rowsNumbers.Length > 1) { XtraMessageBox.Show("请选择一行记录!"); splashScreenManager1.CloseWaitForm(); return; } var testItemVM = gridcontrol.GetRow(rowsNumbers[0]) as TestItemVM; var result = TestItemHelper.UpdateTestItemUsedById(testItemVM.Id); if (result) { XtraMessageBox.Show("操作成功!"); GetData(); } else { XtraMessageBox.Show("操作失败!"); } splashScreenManager1.CloseWaitForm(); } /// /// 数据源 /// /// /// private List DataSource(bool isPage = true) { var keyWord = this.txtkeyword.Text.Trim(); var data = TestItemHelper.QueryTestItemVM(); if (isPage) { return data.WhereIF(!string.IsNullOrWhiteSpace(keyWord), a => a.PointCode.ToLower().Contains(keyWord.ToLower()) || a.PointName.ToLower().Contains(keyWord.ToLower()) || a.MachineTypeCode.ToLower().Contains(keyWord.ToLower()) || a.MachineTypeName.ToLower().Contains(keyWord.ToLower())) .ToPageList(pageCurrent, pagesize, ref totalCount); } return data.WhereIF(!string.IsNullOrWhiteSpace(keyWord), a => a.PointCode.ToLower().Contains(keyWord.ToLower()) || a.PointName.ToLower().Contains(keyWord.ToLower()) || a.MachineTypeCode.ToLower().Contains(keyWord.ToLower()) || a.MachineTypeName.ToLower().Contains(keyWord.ToLower())) .ToList(); } /// /// 分页事件 /// /// /// 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(); } } } }