SolvedPrivate

Linq query and convertall,, need to format

Posted on 2014-01-14
4
29 Views
Last Modified: 2016-02-10
I need to format ' Aht = x.Aht,'  to HH:MM:SS
How can I access a function 'ConvertToHHMMSS' to do this?  


 var AllTotals = (from g in AllData
                             group g by new
                             
                             {
                                 g.dbGrp
                             } into g
                             orderby g.Key.dbGrp
                             select new
                             {
                                 Grp = g.Key.dbGrp,
                                 Aht = Math.Round(AllData.Average(item => item.dbAHT), 2),
                                 Efficiency = Math.Round(AllData.Average(item => item.dbEffeciency), 2),
                                 Credit = Math.Round(AllData.Average(item => item.dbCredit), 2),
                                 Monitor = Math.Round(AllData.Average(item => item.dbMonitor), 2),
                                 Scoreadhere = Math.Round(AllData.Average(item => item.dbScoreAdhere), 2),
                                 OverallS = Math.Round(AllData.Average(item => item.dbOverAll), 2)
                             }).ToList();

            CurrentOverallOutput = AllTotals.ConvertAll(x => new Overall { Grp = x.Grp, Aht = x.Aht, Efficiency = x.Efficiency, Credit = x.Credit, Monitor = x.Monitor, Scoreadhere = x.Scoreadhere, OverallS = x.OverallS });

            dgMasterGrid.ItemsSource = CurrentOverallOutput;

Open in new window




public string ConvertToHHMMSS(decimal ahtC)
        {
            double dSeconds = double.Parse(ahtC.ToString());
            int ihours = (int)Math.Floor((dSeconds / 3600));
            int imins = (int)Math.Floor(((dSeconds - (ihours * 3600)) / 60));
            int isecs = (int)Math.Floor((dSeconds - ((ihours * 3600) + (imins * 60))));
            return ihours.ToString() + ":" + ("00" + imins.ToString()).Substring(Math.Max(0, ("00" + imins.ToString()).Length - 2)) + ":" + ("00" + isecs.ToString()).Substring(Math.Max(0, ("00" + isecs.ToString()).Length - 2));

        }

Open in new window


public class Overall
    {
        public string Grp { get; set; }

        public decimal Aht { get; set; }

        public string AhtFormat { get; set; }

        public decimal Efficiency { get; set; }

        public decimal Credit { get; set; }

        public decimal Monitor { get; set; }

        public decimal Scoreadhere { get; set; }

        public decimal OverallS { get; set; }


    }

Open in new window

0
Comment
Question by:petel2k
  • 3
4 Comments
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 39780599
Hi petel2k;

I am assuming that this is a Linq to Object query and NOT a Linq to SQL or Linq to EF then the following should work.

Aht = ConvertToHHMMSS(Math.Round(AllData.Average(item => item.dbAHT), 2)),

Open in new window

0
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 39780615
Upon closer inspection of your query please note that the following lines in the select statement will be the same for each of the groups in the result set Because they all operate on the whole collection.

Aht = Math.Round(AllData.Average(item => item.dbAHT), 2),
Efficiency = Math.Round(AllData.Average(item => item.dbEffeciency), 2),
Credit = Math.Round(AllData.Average(item => item.dbCredit), 2),
Monitor = Math.Round(AllData.Average(item => item.dbMonitor), 2),
Scoreadhere = Math.Round(AllData.Average(item => item.dbScoreAdhere), 2),
OverallS = Math.Round(AllData.Average(item => item.dbOverAll), 2)

Open in new window

0
 

Author Closing Comment

by:petel2k
ID: 39783169
Thanks
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 39783366
Not a problem, glad to help.
0

Featured Post

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Batch file or script with password 22 69
How do I bind WPF Telerik radMenuItems to commands in XAML ControlTemplate ? 1 24
Expression Evaluater 3 38
Easy filter aspnet 2 27
It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question