Calculating template page numbers I have a function which sets the text to a label displaying current active "products" and current active pages. The label displays "X products, Y pages/page" depending on the amount of products active in the template. Products is the same as rows really, the client wants to call it products.

The template consists of a number of tags, activeTags, which holds the tags that are not deleted. One row consists of a number of tags, perhaps 2 or 3, in the property _selectedTemplateConfiguration.TemplateConfigurationTagsPerRow. Every template page can hold a number of products/rows, _selectedTemplateConfiguration.TemplateConfigurationRowsPerPage.

Let's say I have 41 rows and the template takes 20 rows on each page. This means I have 3 pages active. When I made the function I could not get it to work without the use of the divisionRestvariable, ie. when I had 40 rows it still said it was 3 active pages, due to Math.Ceiling.

The _currentTagCollectionconsists really of a number of Telerik RadDocks with a text input, the idea with the whole template is that the client can enter textvalues into a template online, which is the printed.

I probably missed something, but this is a function that I feel could be made different. Feel free to ask if I need to clarify anything. I'm using .NET 4.0.



private string displayTemplateNumbers()
{
  int totalPagesActive;
  var activeTags = _currentTagCollection.Count - totalAmountOfDeletedTags();

  var divisionRest = (Convert.ToDouble(activeTags / _selectedTemplateConfiguration.TemplateConfigurationTagsPerRow) % _selectedTemplateConfiguration.TemplateConfigurationRowsPerPage);

  if (divisionRest == 0) //Math.Ceiling thinks it's 3 pages when it's only 2, have to check divisionRest like this
  {
       totalPagesActive = Convert.ToInt32((activeTags / _selectedTemplateConfiguration.TemplateConfigurationRowsPerPage) / _selectedTemplateConfiguration.TemplateConfigurationTagsPerRow);
  }
  else
  {
       totalPagesActive = Convert.ToInt32(Math.Ceiling((Convert.ToDouble(activeTags) / Convert.ToDouble(_selectedTemplateConfiguration.TemplateConfigurationRowsPerPage)) / Convert.ToDouble(_selectedTemplateConfiguration.TemplateConfigurationTagsPerRow)).ToString());
  }
  var pages =  totalPagesActive &gt; 1 ? string.Format("{0} pages", totalPagesActive) : string.Format("{0} page", 1);
  return string.Format("{0} products, {1}", activeTags / _selectedTemplateConfiguration.TemplateConfigurationTagsPerRow, pages);
}

private int totalAmountOfDeletedTags()
{
 int counter = 0;
 foreach (var tag in _currentTagCollection)
 {
   if (tag.Deleted)
   {
      counter++;
   }
 }
 return counter;
}
Your method names do not follow capitalization standards, they should be PascalCase. 

However, what's worse is that their names do not correspond to that they do: 


displayTemplateNumbers() returns a formatted string (and thus doesn't "display" anything), 
totalAmountOfDeletedTags() feels like it should be a property instead of a method.


And totalAmountOfDeletedTags() isn't even necessary, since it can be replaced by simple LINQ: _currentTagCollection.Count(x =&gt; x.Deleted);. And since you only need the active tags, you can simply do var activeTags = _currentTagCollection.Count(x =&gt; !x.Deleted); (h/t to @RobertSnyder).



At the end of displayTemplateNumbers() you twice call string.Format(). Instead you should do this once:

return string.Format("{0} products, {1} page{2}", 
    activeTags / _selectedTemplateConfiguration.TemplateConfigurationTagsPerRow, 
    totalPagesActive,
    (totalPagesActive &gt; 1 ? "s" : string.Empty));