CNAS取数仪器端升级
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

FoxProInstrumentData.cs 8.3KB

před 5 roky
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. internal class FoxProInstrumentData : 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 IFoxProService foxproDatabaseService { get { return new FoxProDBService(); } }
  22. /// <summary>
  23. /// 如果配置读取的是文件夹,该属性用来记录需要读取所有文件的缓冲路径
  24. /// </summary>
  25. public List<string> LstFileFullName { get; set; }
  26. public List<string> LstFileName { get; set; }
  27. //public SystemFormatConfig SystemFormat { get; set; }
  28. public FoxProFormatConfig FoxProFormat { get; set; }
  29. public FoxProInstrumentData(InstrumentDataSourceInfo dataSourceInfo, object[] vs)
  30. {
  31. //加载配置信息
  32. FoxProFormat = FileOperation.GetFormatConfigData<FoxProFormatConfig>("FoxProFormatConfig.xml");
  33. //初始化变量
  34. LstFileFullName = new List<string>();
  35. LstFileName = new List<string>();
  36. if (FoxProFormat.ReadFoxProFileMode == "0")
  37. {
  38. RemoteFileCopy remoteFileCopy = new RemoteFileCopy(dataSourceInfo);
  39. remoteFileCopy.CopyFileFromRemote(".dbf");
  40. this.StrLocalPath = FileHelper.getBasePath() + "\\Cache\\" + System.Text.RegularExpressions.Regex.Replace(dataSourceInfo.Path, "[ \\[ \\] \\^ \\-_*×――(^)|'$%~!@#$…&%¥—+=<>《》!!???::•`·、。,;,.;\"‘’“”-]", "").Replace(@"\", "") + ".dbf";
  41. this.strTableName = vs[0].ToString();
  42. this.strDateColumn = vs[1].ToString();
  43. this.strDate = vs[2].ToString();
  44. LstFileFullName.Add(StrLocalPath);
  45. LstFileName.Add(System.Text.RegularExpressions.Regex.Replace(dataSourceInfo.Path, "[ \\[ \\] \\^ \\-_*×――(^)|'$%~!@#$…&%¥—+=<>《》!!???::•`·、。,;,.;\"‘’“”-]", "").Replace(@"\", ""));
  46. }
  47. else
  48. {
  49. //遍历当前路径,找到所有“今天”的数据文件,复制形成缓冲文件
  50. string strSuffix = ".dbf";
  51. DirectoryInfo root = new DirectoryInfo(dataSourceInfo.Path);
  52. foreach (FileInfo f in root.GetFiles())
  53. {
  54. string name = f.Name;
  55. string fullName = f.FullName;
  56. string type = f.Extension;
  57. if (type.ToLower() == strSuffix.ToLower() && name.StartsWith(DateTime.Now.ToString(FoxProFormat.FoxProFileNameFormat))) //“今天”产生的数据
  58. {
  59. RemoteFileCopy remoteFileCopy = new RemoteFileCopy(dataSourceInfo);
  60. remoteFileCopy.CopyFileFromRemote(strSuffix, name);
  61. LstFileFullName.Add(FileHelper.getBasePath() + "\\Cache\\" + System.Text.RegularExpressions.Regex.Replace(dataSourceInfo.Path + name, "[ \\[ \\] \\^ \\-_*×――(^)|'$%~!@#$…&%¥—+=<>《》!!???::•`·、。,;,.;\"‘’“”-]", "").Replace(@"\", "") + strSuffix);
  62. LstFileName.Add(System.Text.RegularExpressions.Regex.Replace(dataSourceInfo.Path + name, "[ \\[ \\] \\^ \\-_*×――(^)|'$%~!@#$…&%¥—+=<>《》!!???::•`·、。,;,.;\"‘’“”-]", "").Replace(@"\", ""));
  63. }
  64. }
  65. this.strTableName = vs[0].ToString();
  66. this.strDateColumn = vs[1].ToString();
  67. this.strDate = vs[2].ToString();
  68. }
  69. }
  70. public override Dictionary<string, DataTable> GetInstrumentData()
  71. {
  72. Dictionary<string, DataTable> dictReturn = new Dictionary<string, DataTable>();
  73. foreach (string strPath in LstFileFullName)
  74. {
  75. Dictionary<string, DataTable> dictCurrent= foxproDatabaseService.GetInstrumentData
  76. (
  77. new FoxProOpenParams
  78. {
  79. StrPath = strPath,
  80. StrPwd = StrPwd,
  81. specialMethod = FoxProFormat.SpecialDtOpera
  82. }
  83. );
  84. if (dictCurrent.Count > 0)
  85. {
  86. foreach (var item in dictCurrent)
  87. {
  88. if (!dictReturn.ContainsKey(item.Key)) //如果不包含,则直接增加
  89. {
  90. dictReturn.Add(item.Key, item.Value);
  91. }
  92. else //如果已经存在相同名字的表单,则合并数据
  93. {
  94. DataTable dtCompine = item.Value.Clone();
  95. foreach (DataRow drs in item.Value.Rows)
  96. {
  97. DataRow drNew = dictReturn[item.Key].NewRow();
  98. drNew.ItemArray = drs.ItemArray;
  99. dictReturn[item.Key].Rows.Add(drNew);
  100. }
  101. }
  102. }
  103. }
  104. }
  105. return dictReturn;
  106. }
  107. public override DataTable GetInstrumentDataByDate()
  108. {
  109. DataTable dtCompine = new DataTable();
  110. List<DataTable> dataTables = new List<DataTable>();
  111. for (int i=0;i<LstFileFullName.Count;i++)
  112. {
  113. DataTable dt = foxproDatabaseService.GetInstrumentDataByDate(
  114. new FoxProOpenParams
  115. {
  116. StrPath = LstFileFullName[i],
  117. StrUser = StrUser,
  118. StrPwd = StrPwd,
  119. timeFormat=FoxProFormat.FoxProFileDateColumnFormat,
  120. autosql = FoxProFormat.AutoSql,
  121. specialMethod=FoxProFormat.SpecialDtOpera
  122. },
  123. new ConditionParams
  124. {
  125. TableName = LstFileName[i],
  126. DateColumn = strDateColumn,
  127. DateValue = strDate
  128. });
  129. dataTables.Add(dt);
  130. }
  131. if (dataTables.Count > 0)
  132. {
  133. dtCompine = dataTables[0].Clone();
  134. foreach (DataTable dt1 in dataTables)
  135. {
  136. foreach (DataRow dr in dt1.Rows)
  137. {
  138. DataRow drNew = dtCompine.NewRow();
  139. foreach (DataColumn dc in dtCompine.Columns)
  140. {
  141. if (dc.ColumnName.Trim().ToLower() == strDateColumn.Trim().ToLower())
  142. {
  143. DateTime dtTime = DateTime.ParseExact(dr[dc.ColumnName].ToString(), FoxProFormat.FoxProFileDateColumnFormat, new System.Globalization.CultureInfo("zh-CN", true));
  144. drNew[dc.ColumnName] = dtTime.ToString("yyyy-MM-dd HH:mm:ss");
  145. }
  146. else
  147. {
  148. drNew[dc.ColumnName] = dr[dc.ColumnName];
  149. }
  150. }
  151. dtCompine.Rows.Add(drNew);
  152. }
  153. }
  154. }
  155. return dtCompine;
  156. }
  157. public override DataTable GetInstrumentDataStruct()
  158. {
  159. //认为所有表的表结构是一样的
  160. return foxproDatabaseService.GetInstrumentDataStruct(
  161. new FoxProOpenParams
  162. {
  163. StrPath = LstFileFullName[0],
  164. StrUser = StrUser,
  165. StrPwd = StrPwd,
  166. autosql = FoxProFormat.AutoSql,
  167. specialMethod = FoxProFormat.SpecialDtOpera
  168. },
  169. new ConditionParams
  170. {
  171. TableName = LstFileName[0]
  172. });
  173. }
  174. }
  175. }