SolvedPrivate

Linq query and convertall,, need to format

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
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 demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

770 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