Utils.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7. using System.Data;
  8. using Logs;
  9. namespace cuidian.Common
  10. {
  11. public class Utils
  12. {
  13. public static string GetColData(DataRow dr, string col)
  14. {
  15. if (dr.IsNull(col)) return null;
  16. if (dr[col].GetType() == typeof(bool))
  17. {
  18. bool o = Convert.ToBoolean(dr[col]);
  19. return o ? "1" : "0";
  20. }
  21. else
  22. {
  23. if (dr[col].ToString() == string.Empty) return null;
  24. }
  25. //if (dr[col].ToString() == string.Empty) return null;
  26. return dr[col].ToString().Replace("&", "&amp;").Replace("'", "&apos;").Replace(">", "&gt;").Replace("<", "&lt;").Replace("&quot;", "\"") ;
  27. }
  28. /// <summary>
  29. /// 获得百分比
  30. /// </summary>
  31. /// <param name="current"></param>
  32. /// <param name="total"></param>
  33. /// <returns></returns>
  34. public static int GetPrecent(int current, int total)
  35. {
  36. int max = 100;
  37. int precent = Convert.ToInt16(((float)current / (float)total) * 100);
  38. precent = (precent >= max) ? max : precent;
  39. return precent;
  40. }
  41. /// <summary>
  42. /// 建立日志目录
  43. /// </summary>
  44. public static void CreateLogDirectory()
  45. {
  46. string path = Environment.CurrentDirectory;
  47. path = path + "\\logs";
  48. if (!Directory.Exists(path))
  49. {
  50. LogHelper.Debug("创建日志目录:" + path);
  51. Directory.CreateDirectory(path);
  52. }
  53. }
  54. }
  55. }