|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- using CnasSynchronousCommon;
- using CnasSynchronusDAL;
- using CnasSynchronusIDAL;
- using CnasSynchrousModel;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.IO;
- using System.Linq;
- using System.Text;
-
- namespace CnasSynchronusClient
- {
- internal class FoxProInstrumentData : InstrumentData
- {
- public string StrLocalPath { get; set; }
-
- public string StrUser { get; set; }
-
- public string StrPwd { get; set; }
-
- public string strTableName { get; set; }
-
- public string strDateColumn { get; set; }
-
- public string strDate { get; set; }
-
- public IFoxProService foxproDatabaseService { get { return new FoxProDBService(); } }
-
- /// <summary>
- /// 如果配置读取的是文件夹,该属性用来记录需要读取所有文件的缓冲路径
- /// </summary>
- public List<string> LstFileFullName { get; set; }
-
- public List<string> LstFileName { get; set; }
-
- //public SystemFormatConfig SystemFormat { get; set; }
-
- public FoxProFormatConfig FoxProFormat { get; set; }
-
- public FoxProInstrumentData(InstrumentDataSourceInfo dataSourceInfo, object[] vs)
- {
- try
- {
- //加载配置信息
- FoxProFormat = FileOperation.GetFormatConfigData<FoxProFormatConfig>("FoxProFormatConfig.xml");
-
- //初始化变量
- LstFileFullName = new List<string>();
- LstFileName = new List<string>();
-
- if (FoxProFormat.ReadFoxProFileMode == "0")
- {
- RemoteFileCopy remoteFileCopy = new RemoteFileCopy(dataSourceInfo);
- remoteFileCopy.CopyFileFromRemote(".dbf");
- this.StrLocalPath = FileHelper.getBasePath() + "\\Cache\\" + System.Text.RegularExpressions.Regex.Replace(dataSourceInfo.Path, "[ \\[ \\] \\^ \\-_*×――(^)|'$%~!@#$…&%¥—+=<>《》!!???::•`·、。,;,.;\"‘’“”-]", "").Replace(@"\", "") + ".dbf";
- this.strTableName = vs[0].ToString();
- this.strDateColumn = vs[1].ToString();
- this.strDate = vs[2].ToString();
-
- LstFileFullName.Add(StrLocalPath);
- LstFileName.Add(System.Text.RegularExpressions.Regex.Replace(dataSourceInfo.Path, "[ \\[ \\] \\^ \\-_*×――(^)|'$%~!@#$…&%¥—+=<>《》!!???::•`·、。,;,.;\"‘’“”-]", "").Replace(@"\", ""));
- }
- else
- {
- //遍历当前路径,找到所有“今天”的数据文件,复制形成缓冲文件
- string strSuffix = ".dbf";
- DirectoryInfo root = new DirectoryInfo(dataSourceInfo.Path);
- foreach (FileInfo f in root.GetFiles())
- {
- string name = f.Name;
- string fullName = f.FullName;
- string type = f.Extension;
- if (type.ToLower() == strSuffix.ToLower() && name.StartsWith(DateTime.Now.ToString(FoxProFormat.FoxProFileNameFormat))) //“今天”产生的数据
- {
- RemoteFileCopy remoteFileCopy = new RemoteFileCopy(dataSourceInfo);
- remoteFileCopy.CopyFileFromRemote(strSuffix, name);
- LstFileFullName.Add(FileHelper.getBasePath() + "\\Cache\\" + System.Text.RegularExpressions.Regex.Replace(dataSourceInfo.Path + name, "[ \\[ \\] \\^ \\-_*×――(^)|'$%~!@#$…&%¥—+=<>《》!!???::•`·、。,;,.;\"‘’“”-]", "").Replace(@"\", "") + strSuffix);
- LstFileName.Add(System.Text.RegularExpressions.Regex.Replace(dataSourceInfo.Path + name, "[ \\[ \\] \\^ \\-_*×――(^)|'$%~!@#$…&%¥—+=<>《》!!???::•`·、。,;,.;\"‘’“”-]", "").Replace(@"\", ""));
- }
- }
-
- this.strTableName = vs[0].ToString();
- this.strDateColumn = vs[1].ToString();
- this.strDate = vs[2].ToString();
- }
- }
- catch (Exception ex)
- {
- AppLog.Error(ex.Message);
- }
- }
-
- public override Dictionary<string, DataTable> GetInstrumentData()
- {
- Dictionary<string, DataTable> dictReturn = new Dictionary<string, DataTable>();
- try
- {
- foreach (string strPath in LstFileFullName)
- {
- Dictionary<string, DataTable> dictCurrent = foxproDatabaseService.GetInstrumentData
- (
- new FoxProOpenParams
- {
- StrPath = strPath,
- StrPwd = StrPwd,
- specialMethod = FoxProFormat.SpecialDtOpera
- }
- );
- if (dictCurrent.Count > 0)
- {
- foreach (var item in dictCurrent)
- {
- if (!dictReturn.ContainsKey(item.Key)) //如果不包含,则直接增加
- {
- dictReturn.Add(item.Key, item.Value);
- }
- else //如果已经存在相同名字的表单,则合并数据
- {
- DataTable dtCompine = item.Value.Clone();
- foreach (DataRow drs in item.Value.Rows)
- {
- DataRow drNew = dictReturn[item.Key].NewRow();
- drNew.ItemArray = drs.ItemArray;
- dictReturn[item.Key].Rows.Add(drNew);
- }
- }
- }
- }
- }
- }
- catch (Exception ex)
- {
- AppLog.Error(ex.Message);
- }
- return dictReturn;
- }
-
- public override DataTable GetInstrumentDataByDate()
- {
- DataTable dtCompine = new DataTable();
- try
- {
- List<DataTable> dataTables = new List<DataTable>();
- for (int i = 0; i < LstFileFullName.Count; i++)
- {
- DataTable dt = foxproDatabaseService.GetInstrumentDataByDate(
- new FoxProOpenParams
- {
- StrPath = LstFileFullName[i],
- StrUser = StrUser,
- StrPwd = StrPwd,
- timeFormat = FoxProFormat.FoxProFileDateColumnFormat,
- autosql = FoxProFormat.AutoSql,
- specialMethod = FoxProFormat.SpecialDtOpera
- },
- new ConditionParams
- {
- TableName = LstFileName[i],
- DateColumn = strDateColumn,
- DateValue = strDate
- });
-
- dataTables.Add(dt);
- }
- if (dataTables.Count > 0)
- {
- dtCompine = dataTables[0].Clone();
- foreach (DataTable dt1 in dataTables)
- {
- foreach (DataRow dr in dt1.Rows)
- {
- DataRow drNew = dtCompine.NewRow();
- foreach (DataColumn dc in dtCompine.Columns)
- {
- if (dc.ColumnName.Trim().ToLower() == strDateColumn.Trim().ToLower())
- {
- DateTime dt = DateTime.Now;
- if (DateTime.TryParse(dr[dc.ColumnName].ToString(), out dt))
- {
- drNew[dc.ColumnName] = dr[dc.ColumnName].ToString();
- }
- else
- {
- DateTime dtTime = DateTime.ParseExact(dr[dc.ColumnName].ToString().Trim(), FoxProFormat.FoxProFileDateColumnFormat, new System.Globalization.CultureInfo("zh-CN", true));
- if (dtTime.ToString("HH:mm:ss") == "00:00:00")
- drNew[dc.ColumnName] = dtTime.ToString("yyyy-MM-dd");
- else
- drNew[dc.ColumnName] = dtTime.ToString("yyyy-MM-dd HH:mm:ss");
- }
- }
- else
- {
- drNew[dc.ColumnName] = dr[dc.ColumnName];
- }
- }
- dtCompine.Rows.Add(drNew);
- }
- }
- }
- }
- catch (Exception ex)
- {
- AppLog.Error(ex.Message);
- }
- return dtCompine;
- }
-
- public override DataTable GetInstrumentDataStruct()
- {
- //认为所有表的表结构是一样的
- return foxproDatabaseService.GetInstrumentDataStruct(
- new FoxProOpenParams
- {
- StrPath = LstFileFullName[0],
- StrUser = StrUser,
- StrPwd = StrPwd,
- autosql = FoxProFormat.AutoSql,
- specialMethod = FoxProFormat.SpecialDtOpera
- },
- new ConditionParams
- {
- TableName = LstFileName[0]
- });
- }
- }
- }
|