@@ -80,6 +80,13 @@ namespace CNAS_RunSync | |||||
this.lblTitleLastUpdateTime.Text = $"最近上传时间:{times[this.syncInstrumentItem.Code]}"; | this.lblTitleLastUpdateTime.Text = $"最近上传时间:{times[this.syncInstrumentItem.Code]}"; | ||||
} | } | ||||
//获取配置 | |||||
SystemFormatConfig systemConfig = FileOperation.GetSystemFormatConfigData(this.syncInstrumentItem.Code); | |||||
if (null != systemConfig) | |||||
{ | |||||
this.delayDays = systemConfig.ShowDelayDays; | |||||
} | |||||
//清空现有绑定 | //清空现有绑定 | ||||
DictComboBox.Clear(); | DictComboBox.Clear(); | ||||
dictSource.Clear(); | dictSource.Clear(); | ||||
@@ -165,7 +172,14 @@ namespace CNAS_RunSync | |||||
dtSource = instrumentData.GetInstrumentDataByDate(); | dtSource = instrumentData.GetInstrumentDataByDate(); | ||||
DataView dv = dtSource.DefaultView; | DataView dv = dtSource.DefaultView; | ||||
dv.Sort = $"{query[0].SourceField} DESC"; | |||||
try | |||||
{ | |||||
dv.Sort = $"{query[0].SourceField} DESC"; | |||||
} | |||||
catch | |||||
{ | |||||
} | |||||
dtSource = dv.ToTable(); | dtSource = dv.ToTable(); | ||||
} | } | ||||
@@ -5,6 +5,7 @@ using CnasSynchrousModel; | |||||
using System; | using System; | ||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Data; | using System.Data; | ||||
using System.IO; | |||||
using System.Linq; | using System.Linq; | ||||
using System.Text; | using System.Text; | ||||
@@ -24,36 +25,60 @@ namespace CnasSynchronusClient | |||||
public ExcelFormatConfig ExcelFormat { get; set; } | public ExcelFormatConfig ExcelFormat { get; set; } | ||||
/// <summary> | |||||
/// 如果配置读取的是文件夹,该属性用来记录需要读取所有文件的缓冲路径 | |||||
/// </summary> | |||||
public List<string> LstFileFullName { get; set; } | |||||
public ExcelInstrumentData(InstrumentDataSourceInfo dataSourceInfo, object[] vs) | public ExcelInstrumentData(InstrumentDataSourceInfo dataSourceInfo, object[] vs) | ||||
{ | { | ||||
if (dataSourceInfo.Path == null) return; | |||||
if (dataSourceInfo.Path == null) | |||||
{ | |||||
return; | |||||
} | |||||
this.ExcelFormat = FileOperation.GetFormatConfigData<ExcelFormatConfig>("ExcelFormatConfig.xml"); | |||||
try | try | ||||
{ | { | ||||
ExcelFormat = FileOperation.GetFormatConfigData<ExcelFormatConfig>("ExcelFormatConfig.xml"); | |||||
LstFileFullName = new List<string>(); | |||||
// 此时为读取“文件”模式,指定要读取的具体文件 | |||||
if (ExcelFormat.ReadExcelFileMode == "0") | if (ExcelFormat.ReadExcelFileMode == "0") | ||||
{ | { | ||||
RemoteFileCopy remoteFileCopy = new RemoteFileCopy(dataSourceInfo); | RemoteFileCopy remoteFileCopy = new RemoteFileCopy(dataSourceInfo); | ||||
remoteFileCopy.CopyFileFromRemote(".xls"); | remoteFileCopy.CopyFileFromRemote(".xls"); | ||||
this.StrLocalPath = FileHelper.getBasePath() + "\\Cache\\" + System.Text.RegularExpressions.Regex.Replace(dataSourceInfo.Path, "[ \\[ \\] \\^ \\-_*×――(^)|'$%~!@#$…&%¥—+=<>《》!!???::•`·、。,;,.;\"‘’“”-]", "").Replace(@"\", "") + ".xls"; | |||||
this.strTableName = vs[0].ToString(); | |||||
this.StrLocalPath = FileHelper.getBasePath() + "\\Cache\\" + System.Text.RegularExpressions.Regex.Replace(dataSourceInfo.Path, "[ \\[ \\] \\^ \\-_*×――(^)|'$%~!@#$…&%¥—+=<>《》!!???::•`·、。,;,.;\"‘’“”-]", "").Replace(@"\", "") + ".xls"; | |||||
this.strTableName = vs[0].ToString(); | |||||
this.strDateColumn = vs[1].ToString(); | this.strDateColumn = vs[1].ToString(); | ||||
this.strDate = vs[2].ToString(); | |||||
this.strDate = vs[2].ToString(); | |||||
LstFileFullName.Add(StrLocalPath); | |||||
} | } | ||||
// 此时为读取“文件夹”模式,指定要读取的具体文件 | |||||
else | else | ||||
{ | { | ||||
string strFileName = DateTime.Now.ToString(ExcelFormat.ExcelFileNameFormat); | |||||
if (strFileName != "") | |||||
DirectoryInfo root = new DirectoryInfo($"{dataSourceInfo.Path}"); | |||||
foreach (FileInfo f in root.GetFiles()) | |||||
{ | { | ||||
RemoteFileCopy remoteFileCopy = new RemoteFileCopy(dataSourceInfo); | |||||
remoteFileCopy.CopyFileFromRemote(".xls", strFileName + ".xls"); | |||||
string name = f.Name; | |||||
string fullName = f.FullName; | |||||
string type = f.Extension; | |||||
this.StrLocalPath = FileHelper.getBasePath() + "\\Cache\\" + System.Text.RegularExpressions.Regex.Replace(dataSourceInfo.Path+ strFileName + ".xls", "[ \\[ \\] \\^ \\-_*×――(^)|'$%~!@#$…&%¥—+=<>《》!!???::•`·、。,;,.;\"‘’“”-]", "").Replace(@"\", "") + ".xls"; | |||||
this.strTableName = $"'{strFileName}$'"; | |||||
this.strDateColumn = vs[1].ToString(); | |||||
this.strDate = vs[2].ToString(); | |||||
//“今天”产生的数据,并且格式是xls | |||||
if ((type.ToLower() == ".xls".ToLower() || type.ToLower() == ".xlsx".ToLower()) && | |||||
name.StartsWith(DateTime.Now.ToString(ExcelFormat.ExcelFileNameFormat))) | |||||
{ | |||||
RemoteFileCopy remoteFileCopy = new RemoteFileCopy(dataSourceInfo); | |||||
remoteFileCopy.CopyFileFromRemote(".xls", $"{name}"); | |||||
LstFileFullName.Add(FileHelper.getBasePath() + "\\Cache\\" + System.Text.RegularExpressions.Regex.Replace(dataSourceInfo.Path + $"{name}", "[ \\[ \\] \\^ \\-_*×――(^)|'$%~!@#$…&%¥—+=<>《》!!???::•`·、。,;,.;\"‘’“”-]", "").Replace(@"\", "") + ".xls"); | |||||
} | |||||
} | } | ||||
this.strTableName = vs[0].ToString(); | |||||
this.strDateColumn = vs[1].ToString(); | |||||
this.strDate = vs[2].ToString(); | |||||
} | } | ||||
} | } | ||||
catch (Exception ex) | catch (Exception ex) | ||||
@@ -64,33 +89,117 @@ namespace CnasSynchronusClient | |||||
public override Dictionary<string, DataTable> GetInstrumentData() | public override Dictionary<string, DataTable> GetInstrumentData() | ||||
{ | { | ||||
if (StrLocalPath == null || ExcelFormat == null || ExcelFormat == null) | |||||
return new Dictionary<string, DataTable>(); | |||||
Dictionary<string, DataTable> excels = new Dictionary<string, DataTable>(); | |||||
return dataBaseService.GetInstrumentData( | |||||
new ExcelOpenParams | |||||
//读取数据 | |||||
foreach (var item in LstFileFullName) | |||||
{ | |||||
try | |||||
{ | { | ||||
StrPath = StrLocalPath, | |||||
ExcelFileVersion = ExcelFormat.ExcelFileVersion, | |||||
autoSql = ExcelFormat.AutoSql | |||||
}); | |||||
Dictionary<string, DataTable> datas = dataBaseService.GetInstrumentData( | |||||
new ExcelOpenParams | |||||
{ | |||||
StrPath = item, | |||||
ExcelFileVersion = ExcelFormat.ExcelFileVersion, | |||||
autoSql = ExcelFormat.AutoSql | |||||
}); | |||||
foreach (var key in datas.Keys) | |||||
{ | |||||
if (false == excels.ContainsKey(key)) | |||||
{ | |||||
excels.Add(key, datas[key]); | |||||
} | |||||
else | |||||
{ | |||||
foreach (DataRow dr in datas[key].Rows) | |||||
{ | |||||
DataRow drNew = excels[key].NewRow(); | |||||
drNew.ItemArray = dr.ItemArray; | |||||
excels[key].Rows.Add(drNew); | |||||
} | |||||
} | |||||
} | |||||
} | |||||
catch | |||||
{ | |||||
} | |||||
} | |||||
return excels; | |||||
} | } | ||||
public override DataTable GetInstrumentDataByDate() | public override DataTable GetInstrumentDataByDate() | ||||
{ | { | ||||
return dataBaseService.GetInstrumentDataByDate( | |||||
new ExcelOpenParams | |||||
DataTable dtCompine = new DataTable(); | |||||
try | |||||
{ | |||||
//读取数据 | |||||
List<DataTable> dataTables = new List<DataTable>(); | |||||
foreach (var item in LstFileFullName) | |||||
{ | { | ||||
StrPath = StrLocalPath, | |||||
ExcelFileVersion = ExcelFormat.ExcelFileVersion, | |||||
autoSql = ExcelFormat.AutoSql | |||||
}, | |||||
new ConditionParams | |||||
DataTable dt = dataBaseService.GetInstrumentDataByDate( | |||||
new ExcelOpenParams | |||||
{ | |||||
StrPath = item, | |||||
ExcelFileVersion = ExcelFormat.ExcelFileVersion, | |||||
autoSql = ExcelFormat.AutoSql | |||||
}, | |||||
new ConditionParams | |||||
{ | |||||
TableName = strTableName, | |||||
DateColumn = strDateColumn, | |||||
DateValue = strDate | |||||
}); | |||||
dataTables.Add(dt); | |||||
} | |||||
//合并数据 | |||||
if (dataTables.Count > 0) | |||||
{ | { | ||||
TableName = strTableName, | |||||
DateColumn = strDateColumn, | |||||
DateValue = strDate | |||||
}); | |||||
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.ToString().ToLower() == strDateColumn.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(), ExcelFormat.ExcelFileDateColumnFormat, 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.Info("读取数据时发生异常"); | |||||
AppLog.Error(ex.Message); | |||||
} | |||||
AppLog.Info("读取数据完成,准备返回"); | |||||
return dtCompine; | |||||
} | } | ||||
public override DataTable GetInstrumentDataStruct() | public override DataTable GetInstrumentDataStruct() | ||||
@@ -35,16 +35,23 @@ namespace CnasSynchronusClient | |||||
public TXTInstrumentData(InstrumentDataSourceInfo dataSourceInfo, object[] vs) | public TXTInstrumentData(InstrumentDataSourceInfo dataSourceInfo, object[] vs) | ||||
{ | { | ||||
normalFileFormat= FileOperation.GetFormatConfigData<NormalFileFormatConfig>("NormalFileFormatConfig.xml"); | |||||
if (dataSourceInfo.Path == null) | |||||
{ | |||||
return; | |||||
} | |||||
this.normalFileFormat = FileOperation.GetFormatConfigData<NormalFileFormatConfig>("NormalFileFormatConfig.xml"); | |||||
string strSuffix = normalFileFormat.NormalFileSuffix; | string strSuffix = normalFileFormat.NormalFileSuffix; | ||||
try | try | ||||
{ | { | ||||
LstFileFullName = new List<string>(); | LstFileFullName = new List<string>(); | ||||
if (normalFileFormat.ReadNormalFileMode == "0") //此时为读取“文件”模式,指定要读取的具体文件 | |||||
if (normalFileFormat.ReadNormalFileMode == "0") | |||||
{ | { | ||||
RemoteFileCopy remoteFileCopy = new RemoteFileCopy(dataSourceInfo); | RemoteFileCopy remoteFileCopy = new RemoteFileCopy(dataSourceInfo); | ||||
remoteFileCopy.CopyFileFromRemote(strSuffix); | remoteFileCopy.CopyFileFromRemote(strSuffix); | ||||
this.StrLocalPath = FileHelper.getBasePath() + "\\Cache\\" + System.Text.RegularExpressions.Regex.Replace(dataSourceInfo.Path, "[ \\[ \\] \\^ \\-_*×――(^)|'$%~!@#$…&%¥—+=<>《》!!???::•`·、。,;,.;\"‘’“”-]", "").Replace(@"\", "") + strSuffix; | this.StrLocalPath = FileHelper.getBasePath() + "\\Cache\\" + System.Text.RegularExpressions.Regex.Replace(dataSourceInfo.Path, "[ \\[ \\] \\^ \\-_*×――(^)|'$%~!@#$…&%¥—+=<>《》!!???::•`·、。,;,.;\"‘’“”-]", "").Replace(@"\", "") + strSuffix; | ||||
this.strTableName = vs[0].ToString(); | this.strTableName = vs[0].ToString(); | ||||
this.strDateColumn = vs[1].ToString(); | this.strDateColumn = vs[1].ToString(); | ||||
@@ -52,7 +59,8 @@ namespace CnasSynchronusClient | |||||
LstFileFullName.Add(StrLocalPath); | LstFileFullName.Add(StrLocalPath); | ||||
} | } | ||||
else //此时为读取“文件夹”模式,指定要读取的具体文件 | |||||
//此时为读取“文件夹”模式,指定要读取的具体文件 | |||||
else | |||||
{ | { | ||||
//遍历当前路径,找到所有“今天”的数据文件,复制形成缓冲文件 | //遍历当前路径,找到所有“今天”的数据文件,复制形成缓冲文件 | ||||
//string strYear = DateTime.Now.Year.ToString(); | //string strYear = DateTime.Now.Year.ToString(); | ||||
@@ -27,8 +27,12 @@ namespace CnasSynchronusClient | |||||
public void CopyFileFromRemote(string strPathSuffix,string stAutoFileName=null) | public void CopyFileFromRemote(string strPathSuffix,string stAutoFileName=null) | ||||
{ | { | ||||
if (SyncInstrumentDSInfo.Path == null) return; | |||||
string[] strRemoteHostMsgs=SyncInstrumentDSInfo.Path.Split(new char[1] { '\\'}, StringSplitOptions.RemoveEmptyEntries); | |||||
if (SyncInstrumentDSInfo.Path == null) | |||||
{ | |||||
return; | |||||
} | |||||
string[] strRemoteHostMsgs = SyncInstrumentDSInfo.Path.Split(new char[1] { '\\'}, StringSplitOptions.RemoveEmptyEntries); | |||||
if (strRemoteHostMsgs.Length > 0) | if (strRemoteHostMsgs.Length > 0) | ||||
{ | { | ||||
AppLog.Error("CopyFileFromRemote打印日志 "+ SyncInstrumentDSInfo.DsPathType); | AppLog.Error("CopyFileFromRemote打印日志 "+ SyncInstrumentDSInfo.DsPathType); | ||||
@@ -36,22 +40,30 @@ namespace CnasSynchronusClient | |||||
AppLog.Error("CopyFileFromRemote打印日志 " + SyncInstrumentDSInfo.RemoteUser); | AppLog.Error("CopyFileFromRemote打印日志 " + SyncInstrumentDSInfo.RemoteUser); | ||||
AppLog.Error("CopyFileFromRemote打印日志 " + SyncInstrumentDSInfo.RemoteUser); | AppLog.Error("CopyFileFromRemote打印日志 " + SyncInstrumentDSInfo.RemoteUser); | ||||
AppLog.Error("CopyFileFromRemote打印日志 " + strRemoteHostMsgs[0]); | AppLog.Error("CopyFileFromRemote打印日志 " + strRemoteHostMsgs[0]); | ||||
//执行net user,否则没有权限 | //执行net user,否则没有权限 | ||||
if (SyncInstrumentDSInfo.DsPathType == PathType.Remote) | if (SyncInstrumentDSInfo.DsPathType == PathType.Remote) | ||||
Connect(@"\\"+strRemoteHostMsgs[0], SyncInstrumentDSInfo.RemoteUser, SyncInstrumentDSInfo.RemoteUser); | |||||
{ | |||||
Connect(@"\\" + strRemoteHostMsgs[0], SyncInstrumentDSInfo.RemoteUser, SyncInstrumentDSInfo.RemoteUser); | |||||
} | |||||
AppLog.Error("CopyFileFromRemote打印日志 " + PathType.Remote); | AppLog.Error("CopyFileFromRemote打印日志 " + PathType.Remote); | ||||
//执行复制 | //执行复制 | ||||
string strPath = SyncInstrumentDSInfo.Path; | |||||
string strCatchPath = FileHelper.getBasePath() + "\\Cache\\"; | |||||
string strCopyPath = System.Text.RegularExpressions.Regex.Replace(SyncInstrumentDSInfo.Path, "[ \\[ \\] \\^ \\-_*×――(^)|'$%~!@#$…&%¥—+=<>《》!!???::•`·、。,;,.;\"‘’“”-]", "").Replace(@"\", "") + strPathSuffix; | |||||
string strPath = SyncInstrumentDSInfo.Path; | |||||
string strCatchPath = Path.Combine(FileHelper.getBasePath(), "Cache"); | |||||
string strCopyPath = System.Text.RegularExpressions.Regex.Replace(SyncInstrumentDSInfo.Path, "[ \\[ \\] \\^ \\-_*×――(^)|'$%~!@#$…&%¥—+=<>《》!!???::•`·、。,;,.;\"‘’“”-]", "").Replace(@"\", "") + strPathSuffix; | |||||
if (stAutoFileName != null) | if (stAutoFileName != null) | ||||
{ | { | ||||
if(Path.GetExtension(strPath)=="") | if(Path.GetExtension(strPath)=="") | ||||
{ | |||||
strPath = strPath + "\\" + stAutoFileName; | strPath = strPath + "\\" + stAutoFileName; | ||||
} | |||||
strCopyPath = System.Text.RegularExpressions.Regex.Replace(strPath, "[ \\[ \\] \\^ \\-_*×――(^)|'$%~!@#$…&%¥—+=<>《》!!???::•`·、。,;,.;\"‘’“”-]", "").Replace(@"\", "") + strPathSuffix; | strCopyPath = System.Text.RegularExpressions.Regex.Replace(strPath, "[ \\[ \\] \\^ \\-_*×――(^)|'$%~!@#$…&%¥—+=<>《》!!???::•`·、。,;,.;\"‘’“”-]", "").Replace(@"\", "") + strPathSuffix; | ||||
if (File.Exists(strCatchPath+strCopyPath)) | if (File.Exists(strCatchPath+strCopyPath)) | ||||
File.Delete(strCatchPath+strCopyPath); | |||||
{ | |||||
File.Delete(strCatchPath + strCopyPath); | |||||
} | |||||
} | } | ||||
Transport(strPath, strCatchPath, strCopyPath); | Transport(strPath, strCatchPath, strCopyPath); | ||||
} | } | ||||
@@ -150,6 +162,7 @@ namespace CnasSynchronusClient | |||||
AppLog.Error("CopyFileFromRemote src 打印日志 " + src); | AppLog.Error("CopyFileFromRemote src 打印日志 " + src); | ||||
AppLog.Error("CopyFileFromRemote dst 打印日志 " + dst); | AppLog.Error("CopyFileFromRemote dst 打印日志 " + dst); | ||||
AppLog.Error("CopyFileFromRemote fileName 打印日志 " + fileName); | AppLog.Error("CopyFileFromRemote fileName 打印日志 " + fileName); | ||||
try | try | ||||
{ | { | ||||
FileStream inFileStream = new FileStream(src, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); | FileStream inFileStream = new FileStream(src, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); | ||||
@@ -157,8 +170,9 @@ namespace CnasSynchronusClient | |||||
{ | { | ||||
Directory.CreateDirectory(dst); | Directory.CreateDirectory(dst); | ||||
} | } | ||||
dst = dst + fileName; | |||||
dst = Path.Combine(dst, fileName); | |||||
AppLog.Error("CopyFileFromRemote dst 打印日志 " + dst); | AppLog.Error("CopyFileFromRemote dst 打印日志 " + dst); | ||||
FileStream outFileStream = new FileStream(dst, FileMode.OpenOrCreate); | FileStream outFileStream = new FileStream(dst, FileMode.OpenOrCreate); | ||||
byte[] buf = new byte[inFileStream.Length]; | byte[] buf = new byte[inFileStream.Length]; | ||||
int byteCount; | int byteCount; | ||||