CNAS取数仪器端升级
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

263 rindas
12KB

  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.IO;
  9. using System.Linq;
  10. using System.Text;
  11. namespace CnasSynchronusClient
  12. {
  13. public class AccessInstrumentData : InstrumentData
  14. {
  15. public string StrLocalPath { get; set; }
  16. public string StrUser { get; set; }
  17. public string StrPwd { get; set; }
  18. public string strTableName { get; set; }
  19. public string strDateColumn { get; set; }
  20. public string strDate { get; set; }
  21. public IAccessService accessDatabaseService { get { return new AccessDBService(); } }
  22. public AccessFormatConfig AccessFormat { get; set; }
  23. public List<string> LstFileFullName { get; set; }
  24. public List<string> LstFileName { get; set; }
  25. public AccessInstrumentData(InstrumentDataSourceInfo dataSourceInfo, object[] vs)
  26. {
  27. try
  28. {
  29. //加载配置信息
  30. AccessFormat = FileOperation.GetFormatConfigData<AccessFormatConfig>("AccessFormatConfig.xml");
  31. //初始化
  32. LstFileFullName = new List<string>();
  33. LstFileName = new List<string>();
  34. this.StrUser = dataSourceInfo.UserId;
  35. this.StrPwd = dataSourceInfo.UserPwd;
  36. if (AccessFormat.ReadAccessFileMode == "0")
  37. {
  38. string strSuffix = Path.GetExtension(dataSourceInfo.Path);
  39. string strFileName = Path.GetFileName(dataSourceInfo.Path);
  40. RemoteFileCopy remoteFileCopy = new RemoteFileCopy(dataSourceInfo);
  41. remoteFileCopy.CopyFileFromRemote(strSuffix, strFileName);
  42. this.StrLocalPath = FileHelper.getBasePath() + "\\Cache\\" + System.Text.RegularExpressions.Regex.Replace(dataSourceInfo.Path, "[ \\[ \\] \\^ \\-_*×――(^)|'$%~!@#$…&%¥—+=<>《》!!???::•`·、。,;,.;\"‘’“”-]", "").Replace(@"\", "") + strSuffix;
  43. this.strTableName = vs[0].ToString();
  44. this.strDateColumn = vs[1].ToString();
  45. this.strDate = vs[2].ToString();
  46. LstFileFullName.Add(StrLocalPath);
  47. LstFileName.Add(System.Text.RegularExpressions.Regex.Replace(dataSourceInfo.Path, "[ \\[ \\] \\^ \\-_*×――(^)|'$%~!@#$…&%¥—+=<>《》!!???::•`·、。,;,.;\"‘’“”-]", "").Replace(@"\", ""));
  48. AppLog.Error("打印日志 " + this.strTableName);
  49. AppLog.Error("打印日志 " + this.strDateColumn);
  50. AppLog.Error("打印日志 " + this.strDate);
  51. AppLog.Error("打印日志 " + this.StrPwd);
  52. AppLog.Error("打印日志 " + this.StrUser);
  53. AppLog.Error("打印日志 " + this.StrLocalPath);
  54. AppLog.Error("打印日志 " + FileHelper.getBasePath());
  55. AppLog.Error("打印日志 " + dataSourceInfo.Path);
  56. }
  57. else
  58. {
  59. //遍历当前路径,找到所有“今天”的数据文件,复制形成缓冲文件
  60. string strSuffix = AccessFormat.AccessSuffix;
  61. if (dataSourceInfo.Path == "") return;
  62. DirectoryInfo root = new DirectoryInfo(dataSourceInfo.Path);
  63. foreach (FileInfo f in root.GetFiles())
  64. {
  65. string name = f.Name;
  66. string fullName = f.FullName;
  67. string type = f.Extension;
  68. if (type.ToLower() == strSuffix.ToLower() && name.StartsWith(DateTime.Now.ToString(AccessFormat.AccessFileNameFormat))) //“今天”产生的数据
  69. {
  70. RemoteFileCopy remoteFileCopy = new RemoteFileCopy(dataSourceInfo);
  71. remoteFileCopy.CopyFileFromRemote(".mdb", name);
  72. LstFileFullName.Add(FileHelper.getBasePath() + "\\Cache\\" + System.Text.RegularExpressions.Regex.Replace(dataSourceInfo.Path + name, "[ \\[ \\] \\^ \\-_*×――(^)|'$%~!@#$…&%¥—+=<>《》!!???::•`·、。,;,.;\"‘’“”-]", "").Replace(@"\", "") + ".mdb");
  73. LstFileName.Add(System.Text.RegularExpressions.Regex.Replace(dataSourceInfo.Path + name, "[ \\[ \\] \\^ \\-_*×――(^)|'$%~!@#$…&%¥—+=<>《》!!???::•`·、。,;,.;\"‘’“”-]", "").Replace(@"\", ""));
  74. }
  75. }
  76. //this.strTableName = AccessFormat.AccessFileTableNameFormat == null ? vs[0].ToString() : AccessFormat.AccessFileTableNameFormat;
  77. this.strTableName = vs[0].ToString();
  78. this.strDateColumn = vs[1].ToString();
  79. this.strDate = vs[2].ToString();
  80. }
  81. }
  82. catch (Exception ex)
  83. {
  84. AppLog.Error(ex.Message);
  85. }
  86. }
  87. public override Dictionary<string, DataTable> GetInstrumentData()
  88. {
  89. //return accessDatabaseService.GetInstrumentData(
  90. // new AccessOpenParams
  91. // {
  92. // StrPath = StrLocalPath,
  93. // StrPwd = StrPwd,
  94. // AccessVersionInfo = AccessFormat.AccessFileVersion
  95. // }
  96. // );
  97. Dictionary<string, DataTable> dictReturn = new Dictionary<string, DataTable>();
  98. try
  99. {
  100. foreach (string strPath in LstFileFullName)
  101. {
  102. Dictionary<string, DataTable> dictCurrent = accessDatabaseService.GetInstrumentData(
  103. new AccessOpenParams
  104. {
  105. StrPath = strPath,
  106. StrPwd = StrPwd,
  107. AccessVersionInfo = AccessFormat.AccessFileVersion
  108. }
  109. );
  110. if (dictCurrent.Count > 0)
  111. {
  112. foreach (var item in dictCurrent)
  113. {
  114. if (!dictReturn.ContainsKey(item.Key)) //如果不包含,则直接增加
  115. {
  116. dictReturn.Add(item.Key, item.Value);
  117. }
  118. //else //如果已经存在相同名字的表单,则合并数据
  119. //{
  120. // DataTable dtCompine = item.Value.Clone();
  121. // foreach (DataRow drs in item.Value.Rows)
  122. // {
  123. // DataRow drNew = dictReturn[item.Key].NewRow();
  124. // drNew.ItemArray = drs.ItemArray;
  125. // dictReturn[item.Key].Rows.Add(drNew);
  126. // }
  127. //}
  128. }
  129. }
  130. }
  131. }
  132. catch (Exception ex)
  133. {
  134. AppLog.Error(ex.Message);
  135. }
  136. return dictReturn;
  137. }
  138. public override DataTable GetInstrumentDataByDate()
  139. {
  140. DataTable dtCompine = new DataTable();
  141. List<DataTable> dataTables = new List<DataTable>();
  142. for (int i = 0; i < LstFileFullName.Count; i++)
  143. {
  144. DataTable dt = accessDatabaseService.GetInstrumentDataByDate(
  145. new AccessOpenParams
  146. {
  147. StrPath = LstFileFullName[i],
  148. StrUser = StrUser,
  149. StrPwd = StrPwd,
  150. AccessVersionInfo = AccessFormat.AccessFileVersion,
  151. AccessSpecialDateFormat = AccessFormat.AccessFileDateColumnFormat,
  152. autoSql = AccessFormat.AutoSql
  153. },
  154. new ConditionParams
  155. {
  156. TableName = strTableName,
  157. DateColumn = strDateColumn,
  158. DateValue = strDate
  159. }
  160. );
  161. dataTables.Add(dt);
  162. }
  163. if (dataTables.Count > 0)
  164. {
  165. if (dataTables.Count == 1) //如果只有一个表,不需要再重复循环一次了
  166. dtCompine = dataTables[0];
  167. else
  168. {
  169. dtCompine = dataTables[0].Clone();
  170. try
  171. {
  172. foreach (DataTable dt1 in dataTables)
  173. {
  174. foreach (DataRow dr in dt1.Rows)
  175. {
  176. DataRow drNew = dtCompine.NewRow();
  177. foreach (DataColumn dc in dtCompine.Columns)
  178. {
  179. //if (dc.ColumnName.Trim().ToLower() == strDateColumn.Trim().ToLower())
  180. //{
  181. // DateTime dt = DateTime.Now;
  182. // //AppLog.Info("4-" + dr[dc.ColumnName].ToString());
  183. // if (DateTime.TryParse(dr[dc.ColumnName].ToString(), out dt))
  184. // {
  185. // drNew[dc.ColumnName] = dr[dc.ColumnName].ToString();
  186. // }
  187. // else
  188. // {
  189. // //AppLog.Info("5-" + AccessFormat.AccessFileDateColumnFormat);
  190. // DateTime dtTime = DateTime.ParseExact(dr[dc.ColumnName].ToString(), AccessFormat.AccessFileDateColumnFormat, new System.Globalization.CultureInfo("zh-CN", true));
  191. // if (dtTime.ToString("HH:mm:ss") == "00:00:00")
  192. // drNew[dc.ColumnName] = dtTime.ToString("yyyy-MM-dd");
  193. // else
  194. // drNew[dc.ColumnName] = dtTime.ToString("yyyy-MM-dd HH:mm:ss");
  195. // }
  196. //}
  197. //else
  198. //{
  199. // drNew[dc.ColumnName] = dr[dc.ColumnName];
  200. //}
  201. drNew[dc.ColumnName] = dr[dc.ColumnName];
  202. }
  203. dtCompine.Rows.Add(drNew);
  204. }
  205. }
  206. }
  207. catch (Exception ex)
  208. {
  209. AppLog.Error(ex.Message);
  210. }
  211. }
  212. }
  213. return dtCompine;
  214. }
  215. public override DataTable GetInstrumentDataStruct()
  216. {
  217. return accessDatabaseService.GetInstrumentDataStruct(
  218. new AccessOpenParams
  219. {
  220. StrPath = LstFileFullName[0],
  221. StrUser = StrUser,
  222. StrPwd = StrPwd,
  223. AccessVersionInfo = AccessFormat.AccessFileVersion,
  224. autoSql = AccessFormat.AutoSql
  225. },
  226. new ConditionParams
  227. {
  228. TableName = strTableName
  229. }
  230. );
  231. }
  232. public override DataTable GetInstrumentDataStruct(string Tablename)
  233. {
  234. throw new NotImplementedException();
  235. }
  236. }
  237. }