FixDBManager.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System;
  2. namespace Core.XgMes.Server.JGKC.SteelPlateManager
  3. {
  4. /// <summary>
  5. /// FixDBManager 的摘要说明。
  6. /// </summary>
  7. public sealed class FixDBManager
  8. {
  9. public FixDBManager()
  10. {
  11. //
  12. // TODO: 在此处添加构造函数逻辑
  13. //
  14. }
  15. public static object[] FixValues(object[] values)
  16. {
  17. for ( int i = 0 ;i< values.Length ;i++)
  18. {
  19. if (values[i] == null)
  20. {
  21. values[i] = DBNull.Value ;
  22. }
  23. else if(values[i].GetType().FullName == "System.String")
  24. {
  25. values[i] = ((string)values[i]).Length != 0? values[i]: DBNull.Value;
  26. }
  27. }
  28. return values;
  29. }
  30. public static string CheckNullStr(object obj)
  31. {
  32. if(obj == null || obj.GetType() == typeof(System.DBNull))
  33. {
  34. return "";
  35. }
  36. else
  37. {
  38. return Convert.ToString(obj);
  39. }
  40. }
  41. public static int CheckNullInt(object obj)
  42. {
  43. if(obj == null || obj.GetType() == typeof(System.DBNull))
  44. {
  45. return 0;
  46. }
  47. else
  48. {
  49. return Convert.ToInt32(obj);
  50. }
  51. }
  52. public static System.Decimal CheckNullDecimal(object obj)
  53. {
  54. if(obj == null || obj.GetType() == typeof(System.DBNull))
  55. {
  56. return 0;
  57. }
  58. else
  59. {
  60. return Convert.ToDecimal(obj);
  61. }
  62. }
  63. }
  64. }