CNAS取数仪器端升级
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

133 行
4.9KB

  1. using CnasSynchronousCommon;
  2. using CnasSynchronusDAL;
  3. using CnasSynchronusIDAL;
  4. using CnasSynchrousModel;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Data;
  8. using System.Linq;
  9. using System.Text;
  10. namespace CnasSynchronusClient
  11. {
  12. public class AccessInstrumentData : InstrumentData
  13. {
  14. public string StrLocalPath { get; set; }
  15. public string StrUser { get; set; }
  16. public string StrPwd { get; set; }
  17. public string strTableName { get; set; }
  18. public string strDateColumn { get; set; }
  19. public string strDate { get; set; }
  20. public IAccessService accessDatabaseService { get { return new AccessDBService(); } }
  21. public AccessFormatConfig AccessFormat { get; set; }
  22. public AccessInstrumentData(InstrumentDataSourceInfo dataSourceInfo, object[] vs)
  23. {
  24. //加载配置信息
  25. AccessFormat = FileOperation.GetFormatConfigData<AccessFormatConfig>("AccessFormatConfig.xml");
  26. RemoteFileCopy remoteFileCopy = new RemoteFileCopy(dataSourceInfo);
  27. remoteFileCopy.CopyFileFromRemote(".mdb");
  28. this.StrLocalPath = FileHelper.getBasePath() + "\\Cache\\" + System.Text.RegularExpressions.Regex.Replace(dataSourceInfo.Path, "[ \\[ \\] \\^ \\-_*×――(^)|'$%~!@#$…&%¥—+=<>《》!!???::•`·、。,;,.;\"‘’“”-]", "").Replace(@"\", "") + ".mdb";
  29. this.StrUser = dataSourceInfo.UserId;
  30. this.StrPwd = dataSourceInfo.UserPwd;
  31. this.strTableName = vs[0].ToString();
  32. this.strDateColumn = vs[1].ToString();
  33. this.strDate = vs[2].ToString();
  34. }
  35. public override Dictionary<string, DataTable> GetInstrumentData()
  36. {
  37. return accessDatabaseService.GetInstrumentData(
  38. new AccessOpenParams
  39. {
  40. StrPath = StrLocalPath,
  41. StrPwd = StrPwd,
  42. AccessVersionInfo = AccessFormat.AccessFileVersion
  43. }
  44. );
  45. }
  46. public override DataTable GetInstrumentDataByDate()
  47. {
  48. /*获取数据源数据*/
  49. DataTable dt = accessDatabaseService.GetInstrumentDataByDate(
  50. new AccessOpenParams
  51. {
  52. StrPath = StrLocalPath,
  53. StrUser = StrUser,
  54. StrPwd = StrPwd,
  55. AccessVersionInfo = AccessFormat.AccessFileVersion,
  56. AccessSpecialDateFormat = AccessFormat.AccessFileDateColumnFormat,
  57. autoSql = AccessFormat.AutoSql
  58. },
  59. new ConditionParams
  60. {
  61. TableName = strTableName,
  62. DateColumn = strDateColumn,
  63. DateValue = strDate
  64. }
  65. );
  66. /*如果日期关键字段格式不合法,将不无法使用,此时需要将其转换为可识别的格式*/
  67. DataTable dtReturn = new DataTable();
  68. try
  69. {
  70. if (AccessFormat.AccessFileDateColumnFormat != "")
  71. {
  72. dtReturn = dt.Clone();
  73. foreach (DataRow dr in dt.Rows)
  74. {
  75. DataRow drNew = dtReturn.NewRow();
  76. foreach (DataColumn dc in dtReturn.Columns)
  77. {
  78. if (dc.ColumnName.Trim().ToLower() == strDateColumn.Trim().ToLower())
  79. {
  80. DateTime dtTime = DateTime.ParseExact(dr[dc.ColumnName].ToString(), AccessFormat.AccessFileDateColumnFormat, new System.Globalization.CultureInfo("zh-CN", true));
  81. drNew[dc.ColumnName] = dtTime.ToString("yyyy-MM-dd HH:mm:ss");
  82. }
  83. else
  84. {
  85. drNew[dc.ColumnName] = dr[dc.ColumnName];
  86. }
  87. }
  88. dtReturn.Rows.Add(drNew);
  89. }
  90. }
  91. else
  92. dtReturn = dt;
  93. }
  94. catch (Exception ex)
  95. {
  96. AppLog.Error(ex.Message);
  97. }
  98. return dtReturn;
  99. }
  100. public override DataTable GetInstrumentDataStruct()
  101. {
  102. return accessDatabaseService.GetInstrumentDataStruct(
  103. new AccessOpenParams
  104. {
  105. StrPath = StrLocalPath,
  106. StrUser = StrUser,
  107. StrPwd = StrPwd,
  108. AccessVersionInfo = AccessFormat.AccessFileVersion,
  109. autoSql = AccessFormat.AutoSql
  110. },
  111. new ConditionParams
  112. {
  113. TableName = strTableName
  114. }
  115. );
  116. }
  117. }
  118. }