FixDBManager.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace Core.LZMes.Client.UIL
  6. {
  7. public class FixDBManager
  8. {
  9. public static object[] FixValues(object[] values)
  10. {
  11. for (int i = 0; i < values.Length; i++)
  12. {
  13. if (values[i] == null)
  14. {
  15. values[i] = DBNull.Value;
  16. }
  17. else if (values[i].GetType().FullName == "System.String")
  18. {
  19. values[i] = ((string)values[i]).Length != 0 ? values[i] : DBNull.Value;
  20. }
  21. }
  22. return values;
  23. }
  24. public static string CheckNullStr(object obj)
  25. {
  26. if (obj == null || obj.GetType() == typeof(System.DBNull))
  27. {
  28. return "";
  29. }
  30. else
  31. {
  32. return Convert.ToString(obj);
  33. }
  34. }
  35. public static int CheckNullInt(object obj)
  36. {
  37. if (obj == null || obj.GetType() == typeof(System.DBNull))
  38. {
  39. return 0;
  40. }
  41. else
  42. {
  43. return Convert.ToInt32(obj);
  44. }
  45. }
  46. public static System.Decimal CheckNullDecimal(object obj)
  47. {
  48. if (obj == null || obj.GetType() == typeof(System.DBNull))
  49. {
  50. return 0;
  51. }
  52. else
  53. {
  54. return Convert.ToDecimal(obj);
  55. }
  56. }
  57. }
  58. }