|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NorthwindBusinessServices
{
public class Utilities
{
/// <summary>
/// Calculate Total Pages
/// </summary>
/// <param name="numberOfRecords"></param>
/// <param name="pageSize"></param>
/// <returns></returns>
public static int CalculateTotalPages(long numberOfRecords, Int32 pageSize)
{
long result;
int totalPages;
Math.DivRem(numberOfRecords, pageSize, out result);
if (result > 0)
totalPages = (int)((numberOfRecords / pageSize)) + 1;
else
totalPages = (int)(numberOfRecords / pageSize);
return totalPages;
}
/// <summary>
/// Check if date is a valid format
/// </summary>
/// <param name="date"></param>
/// <returns></returns>
public static Boolean IsDate(string date)
{
DateTime dateTime;
return DateTime.TryParse(date, out dateTime);
}
/// <summary>
/// IsNumeric
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
public static Boolean IsNumeric(object entity)
{
if (entity == null) return false;
int result;
return int.TryParse(entity.ToString(), out result);
}
/// <summary>
/// IsDouble
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
public static Boolean IsDouble(object entity)
{
if (entity == null) return false;
string e = entity.ToString();
// Loop through all instances of the string 'text'.
int count = 0;
int i = 0;
while ((i = e.IndexOf(".", i)) != -1)
{
i += ".".Length;
count++;
}
if (count > 1) return false;
e = e.Replace(".", "");
int result;
return int.TryParse(e, out result);
}
public static List<String> Message(string message)
{
List<String> returnMessage = new List<String>();
returnMessage.Add(message);
return returnMessage;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Mark Caplin has specialized in Information Technology solutions for the past 30 years. Specializing in full life-cycle development projects for both enterprise-wide systems and Internet/Intranet based solutions.
For the past fifteen years, Mark has specialized in the Microsoft .NET framework using C# as his tool of choice. For the past four years Mark has been implementing Single Page Applications using the Angular platform.
When not coding, Mark enjoys playing tennis, listening to U2 music, watching Miami Dolphins football and watching movies in Blu-Ray technology.
In between all this, his wife of over 25 years, feeds him well with some great home cooked meals.
You can contact Mark at mark.caplin@gmail.com
...