using System.Data; using System.Dynamic; using System.Security.Cryptography; using System.Text; namespace NewPdaSqlServer.util; public static class UtilityHelper { /// /// 32位MD5加密 /// /// /// public static string MD5Encrypt32(string password) { var cl = password; var pwd = ""; var md5 = MD5.Create(); var s = md5.ComputeHash(Encoding.UTF8.GetBytes(cl)); for (var i = 0; i < s.Length; i++) pwd = pwd + s[i].ToString("X"); return pwd; } /// /// table转DynamicList /// /// /// public static List TableToDynamicList(this DataTable table) { var list = new List(); // 遍历DataTable中的每一行 foreach (DataRow row in table.Rows) { dynamic item = new ExpandoObject(); // 遍历每一列,并添加到dynamic对象中 foreach (DataColumn column in table.Columns) ((IDictionary)item)[column.ColumnName] = row[column]; list.Add(item); } return list; } /// /// row转DynamicList /// /// /// public static dynamic RowToDynamic(this DataRow row) { dynamic expando = new ExpandoObject(); if (row != null) foreach (DataColumn column in row.Table.Columns) { var value = row[column]; // 如果值为DBNull.Value,则转换为null if (value == DBNull.Value) value = null; ((IDictionary)expando)[column.ColumnName] = value; } return expando; } public static int GetBit(string v) { if (v.ToUpper() == "TRUE") return 1; if (v.ToUpper() == "1") return 1; return 0; } public static int? ToInt(string strV) { if (string.IsNullOrEmpty(strV)) return null; return int.Parse(strV); } /// /// /// 操作用户 /// 关联主键,有时候会为null /// 表名,表描述 /// 行为 /// public static StringBuilder BuildLog(string _userGuid, string _abtGuid, string _table, string _logTxt) { var sb = new StringBuilder(); sb.Append(" exec prc_log_create '" + _userGuid + "','" + _abtGuid + "','" + _table + "','" + _logTxt + "' "); return sb; } /// /// 如果guid为 Empty或者null 返回false /// /// /// public static bool CheckGuid(Guid? guid) { if (guid == Guid.Empty) return false; return guid != null; } /// /// 判断是不是guid /// /// /// public static bool CheckGuid(string? guid) { if (string.IsNullOrEmpty(guid)) return false; return guid != null; } }