SolvedPrivate

Linq query and convertall,, need to format

Posted on 2014-01-14
4
27 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 62

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 62

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 62

Expert Comment

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

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
This code tracks birthdays 3 59
coded character set iptc field within a jpeg 1 68
Host asp.net pages 5 25
Connection String 16 43
Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

911 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now