using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Security.Cryptography; namespace PatientMan { internal static class common { public static DateTime testdate { get; set; } public static DateTime visitdate { get; set; } public static DateTime MaxDate(DateTime a, DateTime b) { return a > b ? a : b; } public static DateTime MinDate(DateTime a, DateTime b) { return a > b ? b : a; } public static string MD5Hash(string text) { MD5 md5 = new MD5CryptoServiceProvider(); //compute hash from the bytes of text md5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(text)); //get hash result after compute it byte[] result = md5.Hash; StringBuilder strBuilder = new StringBuilder(); for (int i = 0; i < result.Length; i++) { //change it into 2 hexadecimal digits //for each byte strBuilder.Append(result[i].ToString("x2")); } return strBuilder.ToString(); } public static int MonthDiff( DateTime EndDate,DateTime startDate) { int retVal = 0; if (startDate.Month < EndDate.Month) { retVal = (startDate.Month + 12) - EndDate.Month; retVal += ((startDate.Year - 1) - EndDate.Year) * 12; } else { retVal = startDate.Month - EndDate.Month; retVal += (startDate.Year - EndDate.Year) * 12; } //// Calculate the number of years represented and multiply by 12 //// Substract the month number from the total //// Substract the difference of the second month and 12 from the total //retVal = (d1.Year - d2.Year) * 12; //retVal = retVal - d1.Month; //retVal = retVal - (12 - d2.Month); return retVal; } public static int GetQuarter(DateTime date) { if (date.Month >= 4 && date.Month <= 6) return 2; else if (date.Month >= 7 && date.Month <= 9) return 3; else if (date.Month >= 10 && date.Month <= 12) return 4; else return 1; } } }