AppEnv.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.IO;
  5. namespace SysBaseLibs
  6. {
  7. public class AppEnv
  8. {
  9. // private static rsDBConn _DbConn = null;
  10. private static Random _random;
  11. private static bool _IsMachineValidated = false;
  12. public static int GetIntRandom()
  13. {
  14. if (_random == null)
  15. {
  16. _random = new Random(0x989680);
  17. }
  18. return _random.Next(0x989680, 0x5f5e0ff);
  19. }
  20. public static string GetRandom()
  21. {
  22. int liInt = GetIntRandom();
  23. return ("R" + liInt.ToString());
  24. }
  25. public static string GetNextDataTableName()
  26. {
  27. return ("T" + GetRandom());
  28. }
  29. public static DateTime CurrentTime
  30. {
  31. get
  32. {
  33. return DateTime.Now;
  34. }
  35. }
  36. public static string GetGUID()
  37. {
  38. return System.Guid.NewGuid().ToString("N");
  39. }
  40. public static string GetGUIDDate()
  41. {
  42. return System.Guid.NewGuid().ToString("N")+DateTime.Now.ToString("yyMMddHHmmssfff");
  43. }
  44. public static string DBConnectString
  45. {
  46. get {
  47. return SysSecLibs.AppEnv.ReadConnectionString();
  48. }
  49. }
  50. public static bool IsMachineValidated()
  51. {
  52. bool lbRetVal = _IsMachineValidated;
  53. if (!lbRetVal)
  54. {
  55. lbRetVal = SysSecLibs.MySecurity.IsMachineValidated();
  56. }
  57. _IsMachineValidated = lbRetVal;
  58. return lbRetVal;
  59. }
  60. public static bool SaveStrToFile(string pcMessage, string pcFileName)
  61. {
  62. try
  63. {
  64. StreamWriter writer1 = new StreamWriter(pcFileName, false);
  65. writer1.Write(pcMessage);
  66. writer1.Flush();
  67. writer1.Close();
  68. }
  69. catch (Exception exception1)
  70. {
  71. return false;
  72. }
  73. return true;
  74. }
  75. public static bool isExist(string TableName, string ColumName, string pcNo,DBConnSql poDBConn)
  76. {
  77. string lqSql = "select * from " + TableName + " where " + ColumName + " ='" + pcNo + "'";
  78. rsQuery loQuery = poDBConn.OpenQuery(lqSql);
  79. if (loQuery != null && loQuery.IsOpened && loQuery.RecCount > 0)
  80. {
  81. return true;
  82. }
  83. else
  84. {
  85. return false;
  86. }
  87. }
  88. }
  89. }