SolvedPrivate

Linq query and convertall,, need to format

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

760 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

15 Experts available now in Live!

Get 1:1 Help Now