1

I have a Datagrid as Master Table and a Pie-Chart for Detail's display. I have a list of Servers with their ServerID's in the Master Table like this-

enter image description here

and my Details table is

enter image description here

I would like to display the latest value of RAM(depending on the RAM_ID)- Used & Available in the Pie chart when I click on the respective serverID.

for example the values for server 1 will be displayed as (from Ram_ID) enter image description here

for server 2

enter image description here

& for server 3

enter image description here

What I have Tried,

public override void OnApplyTemplate()
    {
        using (DB_Entities db = new DB_Entities())
        {

          var ramRow = db.UsageRAMs.OrderByDescending(c => c.ID).First();                

          var Ram = new List<UsageRAM>() { new UsageRAM() { name = "Used"  , value = ramRow.Used },
                                          new UsageRAM() { name = "Available" , value = ramRow.Available}};

          this.ramViewSource = (CollectionViewSource)this.FindResource("ramView");
          ramViewSource.Source = Ram;
        }
        base.OnApplyTemplate();
    }

XAML

<customControls:LabeledPieChart x:Name="labeledPieChartRAM" BorderBrush="Transparent" Margin="2,10,35,27" Grid.RowSpan="3" Grid.Column="1">
       <customControls:LabeledPieChart.LegendStyle>
       <Style TargetType="dv:Legend">
        <Setter Property="Width" Value="0" />
       </Style>
     </customControls:LabeledPieChart.LegendStyle>
    <customControls:LabeledPieChart.Series>
   <customControls:LabeledPieSeries x:Name="labeledPieSeriesRAM" 
      ItemsSource="{Binding Source={StaticResource ramView}}"                                                              
      PieChartLabelStyle="{StaticResource pieChartLabelStyle}" 
      PieChartLabelItemTemplate="{StaticResource pieChartLabelDataTemplate}" 
      IndependentValuePath="name" DependentValuePath="value" IsSelectionEnabled="True"
      LabelDisplayMode="ArcMidpoint" />
     </customControls:LabeledPieChart.Series>
    </customControls:LabeledPieChart>

output

enter image description here

The output for the above code displays the latest value from the details table, i.e it takes the values from RAM_ID 8, but I need values for each server when selected. how to achieve this ? kindly help

0

2 Answers 2

1

Try Something Like this

    //In this query i am grouping the record by ServerID and Selecting ServerID+ Max(Ram_ID )

     using (DB_Entities db = new DB_Entities())
     {
        var lstRamList = (from usgRam in DB.UsageRAMs 
           group usgRam  by new { usgRam.ServerID} 
           into grp
           select
           new
           {
           TMP_ID_ServerID = grp.Key.ServerID,
           TMP_MAX_RAM_ID= grp.Max(x => x.Ram_ID)}); 


 //in this lower list we save all the record from the Db.UsageRAMs where k.ServerID(from above list) == d.ServerID(from Your DB Context) && k.TMP_MAX_RAM_ID == d.Ram_ID
    var lstRAMListFinal = from d in db.UsageRAMs
    where lstRamList.Any(k =>
                        k.TMP_ID_ServerID== d.ServerID  &&
                        k.TMP_MAX_RAM_ID == d.Ram_ID)
   select d;
}
12
  • first of all thanks for the update. but I get many errors when I try this sample. did you try this ?
    – Indhi
    Apr 8, 2013 at 11:23
  • i dnt have the exact table and their column name so i didnt tried it. i made the query from the mentioned Tables and their column names..
    – YOusaFZai
    Apr 8, 2013 at 11:40
  • Yes, i will share it.. I have edited few spacing errors and now it looks fine. could you please give me some explanation about the above code by putting them in comments. so that I can try to understand
    – Indhi
    Apr 8, 2013 at 11:53
  • thanks for the comment kind of you. I have edited the above update and posted a link
    – Indhi
    Apr 8, 2013 at 12:17
  • I still have an error :( at one place.. then if I execute only I can see. but till now thank u very much
    – Indhi
    Apr 8, 2013 at 12:30
0

If i am not wrong you can simply use RECORD_DATE Column in Details table!!!enter image description here

2
  • I already have one.. I want to display depending upon the RAM_ID column (this is a auto increment coulmn)
    – Indhi
    Apr 8, 2013 at 10:29
  • Then group the Detail Table by ServerID and select the Record by Max Ram_ID
    – YOusaFZai
    Apr 8, 2013 at 10:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.