using System; using System.Collections.Generic; using System.Drawing; using System.IO; using System.Linq; using System.Text; namespace cn.sancainet.Resident.health.register.Utils { public class Common { public static int GetAgeByBirthdate(DateTime birthdate, DateTime now) { int age = now.Year - birthdate.Year; string ageflag = sysParms.getPram("ageflag", "1", "年龄计算方式,1当前年减出生日期,2过生日算", "通用"); if (ageflag == "2") if (now.Month < birthdate.Month || (now.Month == birthdate.Month && now.Day < birthdate.Day)) { age--; } return age < 0 ? 0 : age; } internal static DateTime getBirthByIDNo(string IDNo) { //throw new NotImplementedException(); //370612198509165018 DateTime csrq; string s_csrq = ""; s_csrq=IDNo.Substring(6,4)+"-"+IDNo.Substring(10, 2) +"-"+IDNo.Substring(12, 2); DateTime.TryParse(s_csrq, out csrq); return csrq; } /// /// 根据身份证生成性别 /// /// /// internal static string getSexByIDNo(string IdNo) { //throw new NotImplementedException(); int x = int.Parse(IdNo.Substring(16, 1)) % 2; if(x==1) { return "男"; } else { return "女"; } } internal static byte[] getqm(string path,string xm) { if (string.IsNullOrEmpty(path)) { Bitmap b = new Bitmap(60, 20); var g = Graphics.FromImage(b); g.FillRectangle(Brushes.White, 0, 0, 60, 20); g.DrawString(xm, new Font("宋体", 14), Brushes.Black, new PointF(2, 2)); MemoryStream ms = new MemoryStream(); b.Save(ms, System.Drawing.Imaging.ImageFormat.Png); return ms.ToArray(); } else { if (File.Exists(path)) { System.Drawing.Bitmap b = new System.Drawing.Bitmap(path); MemoryStream ms = new MemoryStream(); b.Save(ms, System.Drawing.Imaging.ImageFormat.Png); return ms.ToArray(); } else { Bitmap b = new Bitmap(60, 20); var g = Graphics.FromImage(b); g.FillRectangle(Brushes.White, 0, 0, 60, 20); g.DrawString(xm, new Font("宋体", 14), Brushes.Black, new PointF(2, 2)); MemoryStream ms = new MemoryStream(); b.Save(ms, System.Drawing.Imaging.ImageFormat.Png); return ms.ToArray(); } } } } }