/// <summary>
        ///     获取指定位置的购买记录
        /// </summary>
        /// <returns></returns>
        public List <MarkSixSpecifiedLocationPurchase> SearchSpecifiedLocation(MarkSixSpecifiedLocationPurchaseSearchDto dto)
        {
            using (var dao = new TrendDbContext())
            {
                var source = dao.Set <MarkSixSpecifiedLocationPurchase>().AsQueryable();

                source = source.WhereDateTime(nameof(MarkSixSpecifiedLocationPurchase.OnCreated), dto.StartDateTime, dto.EndDateTime);

                if (dto.Location > 0)
                {
                    source = source.Where(m => m.Location == dto.Location);
                }
                if (!string.IsNullOrWhiteSpace(dto.Times))
                {
                    source = source.Where(m => m.Times.Contains(dto.Times));
                }
                if (dto.IsGetTotalCount)
                {
                    dto.TotalCount = source.Count();
                }
                return(source.OrderBy(m => m.Times).Skip(dto.StartIndex).Take(dto.PageSize).ToList());
            }
        }
Example #2
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 MarkSixSpecifiedLocationPurchaseSearchDto {
                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;
                }
            }
            var selectedLocation = cboLocation.SelectedItem as ComboBoxItem <int>;

            if (selectedLocation != null)
            {
                searchDto.Location = selectedLocation.Value;
            }

            searchDto.Times = tbTimes.Text;
            var service = new MarkSixPurchaseService();

            try
            {
                var rows = service.SearchSpecifiedLocation(searchDto);
                if (rows.Count == 0)
                {
                    MessageBox.Show(
                        "没有找到符合条件的数据!",
                        "失败",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error
                        );
                    frmMdi.tsslInfo.Text      = "查询内容为空!";
                    frmMdi.tsslInfo.BackColor = Color.Yellow;
                    //重新绑定数据
                    var sourceTable = dgvMarksixPurchaseRecordList.DataSource as DataTable;
                    if (sourceTable != null)
                    {
                        sourceTable.Rows.Clear();
                        dgvMarksixPurchaseRecordList.DataSource = sourceTable;
                    }
                    return(null);
                }
                frmMdi.tsslInfo.Text      = "查询完成!";
                frmMdi.tsslInfo.BackColor = frmMdi.BackColor;
                var table = rows.ConvertDataTable(properties =>
                {
                    var rowVersionProperty = properties.FirstOrDefault(p => p.Name == nameof(MarkSixSpecifiedLocationPurchase.RowVersion));
                    if (rowVersionProperty != null)
                    {
                        properties.Remove(rowVersionProperty);
                    }
                    var purchasesProperty = properties.FirstOrDefault(p => p.Name == nameof(MarkSixSpecifiedLocationPurchase.Purchases));
                    if (purchasesProperty != null)
                    {
                        properties.Remove(purchasesProperty);
                    }
                    var idProperty = properties.FirstOrDefault(p => p.Name == nameof(MarkSixSpecifiedLocationPurchase.Id));
                    if (idProperty != null)
                    {
                        properties.Remove(idProperty);
                    }
                    //Id列移动到首位
                    properties.Insert(0, idProperty);
                });
                dgvMarksixPurchaseRecordList.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);
            }
        }