Go Premium for a chance to win a PS4. Enter to Win

x
?
SolvedPrivate

Linq query and convertall,, need to format

Posted on 2014-01-14
4
Medium Priority
?
34 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 64

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 64

Accepted Solution

by:
Fernando Soto earned 2000 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 64

Expert Comment

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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

916 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