/// <summary> /// GetAutoExportFileName /// </summary> /// <param name="autoExportSetting">資料</param> /// <param name="autoNumber">目前自動編號</param> /// <param name="defaultPrefix">預設前置詞</param> /// <returns></returns> public static string GetAutoExportFileName(AutoExportArgument autoExportSetting, int autoNumber, string defaultPrefix) { var postfix = ""; var postfixFormat = autoExportSetting.PostfixFormat; switch (autoExportSetting.PostfixType) { case AutoExportArgumentPostfixType.AutoNumber: postfix = String.Format(postfixFormat, autoNumber); break; case AutoExportArgumentPostfixType.DateTime: postfix = String.Format(postfixFormat, DateTime.Now); break; case AutoExportArgumentPostfixType.Mixed: postfix = String.Format(postfixFormat, DateTime.Now, autoNumber); break; } var prefix = autoExportSetting.PrefixType == AutoExportArgumentPrefixType.Default ? defaultPrefix : autoExportSetting.Prefix; var filename = prefix + postfix + autoExportSetting.ExtensionName; return(Path.Combine(autoExportSetting.OutputDirectory, filename)); }
/// <summary> /// 取得自動輸出參數設定 /// </summary> /// <returns></returns> public static AutoExportArgument GetAutoExportArgument() { var _settingPath = ConfigurationManager.AppSettings["AutoExportSettingFilepath"].ToString(); AutoExportArgument _autoExportSettings = new AutoExportArgument(); var fileExists = File.Exists(_settingPath); if (fileExists) { var lines = File.ReadAllLines(_settingPath, Encoding.UTF8); var line = lines.Skip(1).Take(1).SingleOrDefault(); string exportStyle = lines.Skip(2).Take(1).SingleOrDefault(); if (exportStyle != null) { _autoExportSettings.IsMahrExport = (exportStyle == "Mahr"); } if (line != null) { var parts = line.Split(','); var postfixType = (parts[3] == "AutoNumber") ? AutoExportArgumentPostfixType.AutoNumber : (parts[3] == "DateTime") ? AutoExportArgumentPostfixType.DateTime : AutoExportArgumentPostfixType.Mixed; var postFixFormat = (parts[3] == "AutoNumber") ? "{0:0000}" : (parts[3] == "DateTime") ? "{0:yyyyMMddHHmmss}" : "{0:yyyyMMddHHmmss}-{1:0000}"; if (parts.Length >= 5) { _autoExportSettings.OutputDirectory = parts[0]; _autoExportSettings.PrefixType = parts[1] == "Default" ? AutoExportArgumentPrefixType.Default : AutoExportArgumentPrefixType.Custom; _autoExportSettings.Prefix = parts[2]; _autoExportSettings.PostfixType = postfixType; _autoExportSettings.ExtensionName = parts[4]; _autoExportSettings.PostfixFormat = postFixFormat; } } } return(_autoExportSettings); }