0

我首先使用 Visual Studio 2015 C#、WPF/MVVM、Devexpress、EntityFramework6 和代码到 Oracle 数据库。

我的数据库中有两个表(Transport 和 Journal),我需要从 Journal 表中按 TransportID 获取分组的日志列表,并在将传输详细信息添加到此列表时,然后使用这两个列表创建一个 GridControl。你能指导我吗,我做错了什么

首先我创建了实体:

public partial class Transport
    {

        [Key]
        public int TransportID { get; set; }
        public string Brand { get; set; }
        public string Model { get; set; }

 public class Journal
    {
        [Key]
        public int JournalID { get; set; }
        public int TransportID { get; set; }
        [ForeignKey("TransportID")]
        public virtual Transport Transport { get; set; }
        public DateTime JournalDate { get; set; }
    }

 public class JournalGrouped
    {
        public int JournalID { get; set; }
        public int TransportID { get; set; }
        public string Brand { get; set; }
        public string Model { get; set; }
        public DateTime JournalDate { get; set; }
        public List<Journal> TransportJournal { get; set; }
    }

然后在 ViewModel 我正在构建列表:

var journal = dbContext.Journals.AsQueryable();

var groupedList = journal.GroupBy(j => new { j.TransportID}).ToList();
var filteredList = journal.Where(j => j.TransportID.Equals(searchParam)).ToList();

分组列表结果:

transport1
transport2
...
transportN

过滤列表结果:

transport1 JournalDate1 Brand Model
transport2 JournalDate1 Brand Model
transport1 JournalDate2 Brand Model
transport2 JournalDate2 Brand Model
...

从这两个列表中,我需要一个这样的结构:

分组列表 + 过滤列表

transport1 Brand Model
  journal1 JournalDate
  journal2 JournalDate
  ...
  journalN JournalDate

transport2 Brand Model
  journal1 JournalDate
  journal2 JournalDate
  ...
  journalN JournalDate

...

transportN Brand Model
  journal1 JournalDate
  journal2 JournalDate
  ...
  journalN JournalDate

为了获得包含一些数据的 GroupedList,我这样做:

GroupedlList = new List<JournalGrouped>();
    foreach (var t in groupedList)
      {
         Transport transportDetail = DBContext.Transports.Where(tr => tr.TransportID.Equals(t.Key.TransportID)).FirstOrDefault();

         JournalGrouped journalTransport = new JournalGrouped
                        {
                            TransportID = transportDetail.TransportID,
                            Brand = transportDetail.BrandName,
                            Model = transportDetail.ModelName,
                            **TransportJournal** = new List<Journal>()

                        };
            }

我不知道如何让这个TransportJournal列表按 TransportID 过滤这将是我的 FilteredList 作为我的 GroupedList 的详细描述符

(如果我通过添加过滤器 TransportID 直接从 Journal 构建它,一切正常)我得到两个列表,将它们放在我的表单中的两个不同网格中,一切看起来都不错,但我想要上面描述的 shuch 列表结构

XAML 代码如下所示:

<dxg:GridControl x:Name="grid" ItemsSource="{Binding Path=GroupedJournalList}" 
                <dxg:GridControl.View>
                    <dxg:TableView ShowGroupPanel="False" ShowSearchPanelMode="Never" AllowGrouping="False"/>
                </dxg:GridControl.View>
                <dxg:GridControl.Columns>

                    <dxg:GridColumn FieldName="Brand"/>
                    <dxg:GridColumn FieldName="Model"/>

                </dxg:GridControl.Columns>
                <dxg:GridControl.DetailDescriptor>
                    <dxg:DataControlDetailDescriptor ItemsSourceBinding="{Binding TransportJournal}" ShowHeader="True">
                        <dxg:GridControl>
                            <dxg:GridControl.Columns>
                                <dxg:GridColumn FieldName="JournalDate"/>
                            </dxg:GridControl.Columns>
                        </dxg:GridControl>
                    </dxg:DataControlDetailDescriptor>
                </dxg:GridControl.DetailDescriptor>
            </dxg:GridControl>
4

1 回答 1

1

您可以使用 MultiBindingPropery 获取 currentSlected {Transport and Journal}

<MultiBinding Converter="{StaticResource "FileterName"}">
<Binding Path="CurentColumnFilter"  RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}" Mode="TwoWay" />
<Binding Path="TransactionTypes" RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}" Mode="TwoWay"/>


有关更多信息,您可以参考此链接 https://www.devexpress.com/Support/Center/Question/Details/Q491120

于 2016-06-26T07:48:19.873 回答