Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9250767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:31:34+00:00 2026-06-18T10:31:34+00:00

I am working on the source code of a restaurant POS (Samba pos), and

  • 0

I am working on the source code of a restaurant POS (Samba pos), and I have 2 problems how the output is formatted when printing a ticket.

The code below collects the tags of products, make headers of them, and sort the products below the header.

Problem 1: I have no influence in the order of headers so the output looks like:

Main course

Steak 22,50

Drinks

Cola 2,00

Starters

Soup 3,50

The right order should be Starters –> Main course –> Desserts –> Drinks
If I could sort the headers alphabetically I would be helped very much. I would change the group tags into: 1 Starters, 2 Maincourse etc etc

Problem 2:

The products are grouped in an earlier stage of the program. Due to choices of the programmer the grouping doesn’t work well for me. I have a long list on the ticket like:

1 x Cola 2,00

2 x Cola 4,00

Is there a way to group products here so that I will have:

3 x cola 6,00

Here is the piece of code:

if (template.GroupTemplate.Contains("{PRODUCT TAG}"))
{
    var groups = lines.GroupBy(GetMenuItemTag);
    var result = new List<string>();
    foreach (var grp in groups)
    {
        var grpSep = template.GroupTemplate.Replace("{PRODUCT TAG}", grp.Key);
        result.AddRange(grpSep.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries));
        result.AddRange(grp.SelectMany(x => FormatLines(template, x).Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)));
    }
    return result;
}

I have to sort var groups. The problem is that the text {PRODUCT TAG} is replaced with grp.Key within the loop, so ordering var groups before the loop probably won’t work (do I need an extra loop?).

Adding the products to the headers is done on the 3 line of the loop. Is it possible to group items here?

I have dumped the whole file here:
http://pastebin.com/qFr5wN28

Edit:

This piece of code is for producing a ticket on a ticketprinter. A ticket would look like this:

BON
Datum: 2-2-2013
Tijd: 18:35    
Tafel nr.: B22    
Bon nr: 2    
------------------------------------------    
Breakfast    
- 1 Toast and Jam 1,50    
- 1 Egg, Bacon Cheese 3,99    
- 1 Toasted Bagel Cheese 2,25    
- 1 Toasted Bagel Jam 1,50    
- 2 Toast and Jam 1,50    
- 1 Egg, Bacon Cheese 3,99    
- 1 Bacon and Cheese 3,49    
- 1 Bacon and Tomato 3,49    
Deserts    
- 1 Rice Pudding 2,25    
- 1 Fruit Danish 1,50    
Main course    
- 1 Chicken Garden Wrap 5,25    
- 1 Chicken Caesar Wrap 5,75    
- 1 Canadian Wrap 6,99    
- 1 Chicken Greek Wrap 6,99

The headers are tags that I can add to products.
There are several things wrong: the headers above the articles (Deserts, Main Course) appear randomly. I would like to sort them. Not all articles are grouped, for example "toast and jam". If I could sort the headers, I would change the tags a bit. A desired output would be like this:

------------------------------------------    
1 Breakfast    
- 3 Toast and Jam 1,50    
- 2 Egg, Bacon Cheese 3,99    
- 1 Toasted Bagel Cheese 2,25    
- 1 Toasted Bagel Jam 1,50    
- 1 Bacon and Cheese 3,49    
- 1 Bacon and Tomato 3,49    
2 Main course    
- 1 Chicken Garden Wrap 5,25    
- 1 Chicken Caesar Wrap 5,75    
- 1 Canadian Wrap 6,99    
- 1 Chicken Greek Wrap 6,99    
3 Deserts    
- 1 Rice Pudding 2,25    
- 1 Fruit Danish 1,50
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T10:31:36+00:00Added an answer on June 18, 2026 at 10:31 am

    You can order your lines using OrderBy like so:

    var groups = lines.GroupBy(GetMenuItemTag).OrderBy(l => l.Key);
    

    You also loop through the groups and amend the value of your key. This could be done by adding a Select projection to your group.

    var groups = lines.GroupBy(GetMenuItemTag)
                      .Select(l => new { Key = template.GroupTemplate.Replace("{PRODUCT TAG}", grp.Key)
                                       , l.Value } )
                      .OrderBy(l => l.Key);
    

    EDIT:

    After thinking about this I realised I was being a little dumb yesterday. I think the following will help you:

    //dummy data for testing purposes
    List<Tuple<string, string>> items = new List<Tuple<string, string>>();
    items.Add(new Tuple<string, string>("Dinner", "steak"));
    items.Add(new Tuple<string, string>("Dinner", "chicken"));
    items.Add(new Tuple<string, string>("Dinner", "chicken"));
    items.Add(new Tuple<string, string>("Desert", "chocolate"));
    
    var groups = (from t in items
                 group t by new {Course = t.Item1, Item = t.Item2}
                 into grp
                     select new
                     {
                         grp.Key.Course,
                         grp.Key.Item,
                         Quantity = grp.Count()
                     })
                 .OrderBy(g => g.Course);
    
    foreach (var g in groups)
              Console.WriteLine(string.Format("{0} {1} {2}", g.Course, g.Item, g.Quantity));
    

    OUTPUT:

    Dinner steak 1
    Dinner chicken 2
    Desert chocolate 1
    

    Obviously you will need to modify the datatypes, etc, but the query itself should give you what you need.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working in VS2005, I have a part of freeimage source code. I
Hi I have a source code working fine when compiled using vs2008, in 32
I have some code working perfectly on a specific source solution which references jQuery
we have obfuscated our java source code and currently working on it, so make
I have download sample tablelayout source code it's working fine. I am trying to
I am working with Visual C++. I have the source code of a library,
I'm working on this project where we don't have the source code for large
While working with ASP.NET using Visual Studio (2008) I have discomfort issue: source code
I was digging into some source code I am working on. I found a
I am working on Ginger Bread source code. First time compilation require 3 to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.