|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- using CnasSynchronousCommon;
- using CnasSynchronusDAL;
- using CnasSynchronusIDAL;
- using CnasSynchrousModel;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Linq;
- using System.Text;
-
- namespace CnasSynchronusClient
- {
- public class AccessInstrumentData : 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 IAccessService accessDatabaseService { get { return new AccessDBService(); } }
-
- public AccessFormatConfig AccessFormat { get; set; }
-
- public AccessInstrumentData(InstrumentDataSourceInfo dataSourceInfo, object[] vs)
- {
- //加载配置信息
- AccessFormat = FileOperation.GetFormatConfigData<AccessFormatConfig>("AccessFormatConfig.xml");
-
- RemoteFileCopy remoteFileCopy = new RemoteFileCopy(dataSourceInfo);
- remoteFileCopy.CopyFileFromRemote(".mdb");
- this.StrLocalPath = FileHelper.getBasePath() + "\\Cache\\" + System.Text.RegularExpressions.Regex.Replace(dataSourceInfo.Path, "[ \\[ \\] \\^ \\-_*×――(^)|'$%~!@#$…&%¥—+=<>《》!!???::•`·、。,;,.;\"‘’“”-]", "").Replace(@"\", "") + ".mdb";
- this.StrUser = dataSourceInfo.UserId;
- this.StrPwd = dataSourceInfo.UserPwd;
-
- this.strTableName = vs[0].ToString();
- this.strDateColumn = vs[1].ToString();
- this.strDate = vs[2].ToString();
- }
-
- public override Dictionary<string, DataTable> GetInstrumentData()
- {
- return accessDatabaseService.GetInstrumentData(
- new AccessOpenParams
- {
- StrPath = StrLocalPath,
- StrPwd = StrPwd,
- AccessVersionInfo = AccessFormat.AccessFileVersion
- }
- );
- }
-
- public override DataTable GetInstrumentDataByDate()
- {
- /*获取数据源数据*/
- DataTable dt = accessDatabaseService.GetInstrumentDataByDate(
- new AccessOpenParams
- {
- StrPath = StrLocalPath,
- StrUser = StrUser,
- StrPwd = StrPwd,
- AccessVersionInfo = AccessFormat.AccessFileVersion,
- AccessSpecialDateFormat = AccessFormat.AccessFileDateColumnFormat,
- autoSql = AccessFormat.AutoSql
- },
- new ConditionParams
- {
- TableName = strTableName,
- DateColumn = strDateColumn,
- DateValue = strDate
- }
- );
- /*如果日期关键字段格式不合法,将不无法使用,此时需要将其转换为可识别的格式*/
- DataTable dtReturn = new DataTable();
- try
- {
- if (AccessFormat.AccessFileDateColumnFormat != "")
- {
- dtReturn = dt.Clone();
- foreach (DataRow dr in dt.Rows)
- {
- DataRow drNew = dtReturn.NewRow();
- foreach (DataColumn dc in dtReturn.Columns)
- {
- if (dc.ColumnName.Trim().ToLower() == strDateColumn.Trim().ToLower())
- {
- DateTime dtTime = DateTime.ParseExact(dr[dc.ColumnName].ToString(), AccessFormat.AccessFileDateColumnFormat, new System.Globalization.CultureInfo("zh-CN", true));
- drNew[dc.ColumnName] = dtTime.ToString("yyyy-MM-dd HH:mm:ss");
- }
- else
- {
- drNew[dc.ColumnName] = dr[dc.ColumnName];
- }
- }
- dtReturn.Rows.Add(drNew);
- }
- }
- else
- dtReturn = dt;
- }
- catch (Exception ex)
- {
- AppLog.Error(ex.Message);
- }
- return dtReturn;
- }
-
- public override DataTable GetInstrumentDataStruct()
- {
- return accessDatabaseService.GetInstrumentDataStruct(
- new AccessOpenParams
- {
- StrPath = StrLocalPath,
- StrUser = StrUser,
- StrPwd = StrPwd,
- AccessVersionInfo = AccessFormat.AccessFileVersion,
- autoSql = AccessFormat.AutoSql
- },
- new ConditionParams
- {
- TableName = strTableName
- }
- );
- }
- }
- }
|