public void TestSearch() { using (new TransactionScope()) { var service = new MarkSixRecordService(); var rows = service.Search(new MarkSixRecordSearchDto { StartIndex = 0, PageSize = 20 }); Assert.IsTrue(rows.Count > 0); } }
private DataTable Search() { //每页数量 var pageSize = 0; int.TryParse(tlscombo.Text, out pageSize); //页码开始数 var pageIndex = 1; int.TryParse(bdnPositionItem.Text, out pageIndex); //开始位置 var startIndex = pageSize * (pageIndex - 1); if (startIndex < 0) { startIndex = 0; } var searchDto = new MarkSixRecordSearchDto { StartIndex = startIndex, PageSize = pageSize }; if (tbStartDateTime.Text.Trim().Length > 0) { var strDate = tbStartDateTime.Text.Trim(); DateTime dt; if (DateTime.TryParse(strDate, out dt)) { searchDto.StartDateTime = dt; } } if (tbEndDateTime.Text.Trim().Length > 0) { var strDate = tbEndDateTime.Text.Trim(); DateTime dt; if (DateTime.TryParse(strDate, out dt)) { searchDto.EndDateTime = dt; } } searchDto.Times = tbTimes.Text; var service = new MarkSixRecordService(); try { var rows = service.Search(searchDto); if (rows.Count == 0) { MessageBox.Show( "没有找到符合条件的数据!", "失败", MessageBoxButtons.OK, MessageBoxIcon.Error ); frmMdi.tsslInfo.Text = "查询内容为空!"; frmMdi.tsslInfo.BackColor = Color.Yellow; return(null); } frmMdi.tsslInfo.Text = "查询完成!"; frmMdi.tsslInfo.BackColor = frmMdi.BackColor; var table = rows.ConvertDataTable(properties => { var rowVersionProperty = properties.FirstOrDefault(p => p.Name == nameof(MarkSixRecord.RowVersion)); if (rowVersionProperty != null) { properties.Remove(rowVersionProperty); } var idProperty = properties.FirstOrDefault(p => p.Name == nameof(MarkSixRecord.Id)); if (idProperty != null) { properties.Remove(idProperty); } properties.Insert(0, idProperty); }); dgvMarksixRecordList.DataSource = table; var pageCount = searchDto.PageCount; bdnCountItem.Text = pageCount.ToString(); if (pageIndex <= 1) { bdnMoveFirstItem.Enabled = false; bdnMovePreviousItem.Enabled = false; } else { bdnMoveFirstItem.Enabled = true; bdnMovePreviousItem.Enabled = true; } if (pageIndex == pageCount) { bdnMoveNextItem.Enabled = false; bdnMoveLastItem.Enabled = false; } else { bdnMoveNextItem.Enabled = true; bdnMoveLastItem.Enabled = true; } return(table); } catch (Exception ex) { MessageBox.Show( "查询发生错误," + ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error ); frmMdi.tsslInfo.Text = "查询失败!"; frmMdi.tsslInfo.BackColor = Color.Yellow; return(null); } }