首页 > 代码库 > 实习以来 唯一一次 没有因需求变更 代码被改面目全非的一次(期待各位对代码细节提提建议)

实习以来 唯一一次 没有因需求变更 代码被改面目全非的一次(期待各位对代码细节提提建议)

  according the source and template to genetate bulk file.(there is four type diff source and template now.)



1
using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using Ric.Core; 6 using System.ComponentModel; 7 using System.Windows; 8 using System.IO; 9 using Ric.Util; 10 using Microsoft.Office.Interop.Excel; 11 12 namespace Ric.Tasks.HongKong 13 { 14 [ConfigStoredInDB] 15 class HKFutureDatingConfig 16 { 17 [StoreInDB] 18 [Category("IA Template")] 19 [DisplayName("IA Template File Path.")] 20 [Description("F:\\work\\xxx.csv")] 21 public string IATemplatePath { get; set; } 22 23 [StoreInDB] 24 [Category("BulkFile")] 25 [DisplayName("Bulk File Output Folder")] 26 [Description("F:\\work\\xxx")] 27 public string OutputFolder { get; set; } 28 29 [StoreInDB] 30 [Category("HShareIPO")] 31 [DisplayName("SourcePath")] 32 [Description("F:\\work\\xxx.xls")] 33 public string SourcePathHShareIPO { get; set; } 34 [StoreInDB] 35 [Category("HShareIPO")] 36 [DisplayName("TemplatePath")] 37 [Description("F:\\work\\xxx.csv")] 38 public string TemplatePathHShareIPO { get; set; } 39 40 [StoreInDB] 41 [Category("IPO")] 42 [DisplayName("SourcePath")] 43 [Description("F:\\work\\xxx.xls")] 44 public string SourcePathIPO { get; set; } 45 [StoreInDB] 46 [Category("IPO")] 47 [DisplayName("TemplatePath")] 48 [Description("F:\\work\\xxx.csv")] 49 public string TemplatePathIPO { get; set; } 50 51 [StoreInDB] 52 [Category("Parellel trading")] 53 [DisplayName("SourcePath")] 54 [Description("F:\\work\\xxx.xls")] 55 public string SourcePathParellel { get; set; } 56 [StoreInDB] 57 [Category("Parellel trading")] 58 [DisplayName("TemplatePath")] 59 [Description("F:\\work\\xxx.csv")] 60 public string TemplatePathParellel { get; set; } 61 62 [StoreInDB] 63 [Category("RIGHTS")] 64 [DisplayName("SourcePath")] 65 [Description("F:\\work\\xxx.xls")] 66 public string SourcePathRIGHTS { get; set; } 67 [StoreInDB] 68 [Category("RIGHTS")] 69 [DisplayName("TemplatePath")] 70 [Description("F:\\work\\xxx.csv")] 71 public string TemplatePathRIGHTS { get; set; } 72 73 [Category("FileCategory")] 74 [DisplayName("FileType")] 75 [Description("select file type to run.")] 76 public FileCategory FileType { get; set; } 77 } 78 79 enum FileCategory : int { AllType, HShareIPO, IPO, ParellelTrading, RIGHTS } 80 81 class HKFutureDating : GeneratorBase 82 { 83 private static HKFutureDatingConfig configObj; 84 private List<List<string>> iaTemplate = null; 85 protected override void Initialize() 86 { 87 configObj = Config as HKFutureDatingConfig; 88 } 89 90 protected override void Start() 91 { 92 if (!CheckConfig()) 93 return; 94 95 #region [HShareIPO] 96 if (configObj.FileType.Equals(FileCategory.AllType) || configObj.FileType.Equals(FileCategory.HShareIPO)) 97 { 98 LogMessage(string.Format("start to generate {0} bulk file.", FileCategory.HShareIPO.ToString())); 99 string folder = Path.Combine(configObj.OutputFolder, Path.Combine("HShareIPO", DateTime.Now.ToString("MM-dd-yyyy")));100 List<List<string>> source = ReadExcel(configObj.SourcePathHShareIPO, 1);101 List<List<string>> qaTemplate = ReadExcel(configObj.TemplatePathHShareIPO, 1);102 SourceTemplate sourceTemplate = FormatSource(source);103 FillQATemplate(qaTemplate, sourceTemplate, FileCategory.HShareIPO);104 FillIATemplate(iaTemplate, sourceTemplate, FileCategory.HShareIPO);105 106 string pathQA = Path.Combine(folder, string.Format("Quote_Future_Add_{0}(HShareIPO).csv", sourceTemplate.OfficialCode));107 GenerateFile(pathQA, qaTemplate);108 AddResult("Quote_Future_Add_HShareIPO.csv", pathQA, "qa bulk file");109 110 string pathIA = Path.Combine(folder, string.Format("Issue_Future_Add_{0}(HShareIPO).csv", sourceTemplate.OfficialCode));111 GenerateFile(pathIA, iaTemplate);112 AddResult("Issue_Future_Add_HShareIPO.csv", pathIA, "ia bulk file");113 }114 #endregion115 116 #region [IPO]117 if (configObj.FileType.Equals(FileCategory.AllType) || configObj.FileType.Equals(FileCategory.IPO))118 {119 LogMessage(string.Format("start to generate {0} bulk file.", FileCategory.IPO.ToString()));120 string folder = Path.Combine(configObj.OutputFolder, Path.Combine("IPO", DateTime.Now.ToString("MM-dd-yyyy")));121 List<List<string>> source = ReadExcel(configObj.SourcePathIPO, 1);122 List<List<string>> qaTemplate = ReadExcel(configObj.TemplatePathIPO, 1);123 SourceTemplate sourceTemplate = FormatSource(source);124 FillQATemplate(qaTemplate, sourceTemplate, FileCategory.IPO);125 FillIATemplate(iaTemplate, sourceTemplate, FileCategory.IPO);126 127 string pathQA = Path.Combine(folder, string.Format("Quote_Future_Add_{0}(IPO).csv", sourceTemplate.OfficialCode));128 GenerateFile(pathQA, qaTemplate);129 AddResult("Quote_Future_Add_IPO.csv", pathQA, "qa bulk file");130 131 string pathIA = Path.Combine(folder, string.Format("Issue_Future_Add_{0}(IPO).csv", sourceTemplate.OfficialCode));132 GenerateFile(pathIA, iaTemplate);133 AddResult("Issue_Future_Add_IPO.csv", pathIA, "ia bulk file");134 }135 #endregion136 137 #region [ParaellelTrading]138 if (configObj.FileType.Equals(FileCategory.AllType) || configObj.FileType.Equals(FileCategory.ParellelTrading))139 {140 LogMessage(string.Format("start to generate {0} bulk file.", FileCategory.ParellelTrading.ToString()));141 string folder = Path.Combine(configObj.OutputFolder, Path.Combine("ParellelTrading", DateTime.Now.ToString("MM-dd-yyyy")));142 List<List<string>> source = ReadExcel(configObj.SourcePathParellel, 1);143 List<List<string>> qaTemplate = ReadExcel(configObj.TemplatePathParellel, 1);144 SourceTemplate sourceTemplate = FormatSource(source);145 FillQATemplate(qaTemplate, sourceTemplate, FileCategory.ParellelTrading);146 FillIATemplate(iaTemplate, sourceTemplate, FileCategory.ParellelTrading);147 148 string pathQA = Path.Combine(folder, string.Format("Quote_Future_Add_{0}(Parellel trading).csv", sourceTemplate.OfficialCodeNew));149 GenerateFile(pathQA, qaTemplate);150 AddResult("Quote_Future_Add_Parellel trading.csv", pathQA, "qa bulk file");151 152 string pathIA = Path.Combine(folder, string.Format("Issue_Future_Add_{0}(Parellel trading)(Parellel trading).csv", sourceTemplate.OfficialCodeNew));153 GenerateFile(pathIA, iaTemplate);154 AddResult("Issue_Future_Add_Parellel trading.csv", pathIA, "ia bulk file");155 }156 #endregion157 158 #region [RIGHTS]159 if (configObj.FileType.Equals(FileCategory.AllType) || configObj.FileType.Equals(FileCategory.RIGHTS))160 {161 LogMessage(string.Format("start to generate {0} bulk file.", FileCategory.RIGHTS.ToString()));162 string folder = Path.Combine(configObj.OutputFolder, Path.Combine("RIGHTS", DateTime.Now.ToString("MM-dd-yyyy")));163 List<List<string>> source = ReadExcel(configObj.SourcePathRIGHTS, 1);164 List<List<string>> qaTemplate = ReadExcel(configObj.TemplatePathRIGHTS, 1);165 SourceTemplate sourceTemplate = FormatSource(source);166 FillQATemplate(qaTemplate, sourceTemplate, FileCategory.RIGHTS);167 FillIATemplate(iaTemplate, sourceTemplate, FileCategory.RIGHTS);168 169 string pathQA = Path.Combine(folder, string.Format("Quote_Future_Add_{0}(RIGHTS).csv", sourceTemplate.OfficialCode));170 GenerateFile(pathQA, qaTemplate);171 AddResult("Quote_Future_Add_RIGHTS.csv", pathQA, "qa bulk file");172 173 string pathIA = Path.Combine(folder, string.Format("Issue_Future_Add_{0}(RIGHTS).csv", sourceTemplate.OfficialCode));174 GenerateFile(pathIA, iaTemplate);175 AddResult("Issue_Future_Add_RIGHTS.csv", pathIA, "ia bulk file");176 }177 #endregion178 }179 180 private void FillIATemplate(List<List<string>> iaTemplate, SourceTemplate sourceTemplate, FileCategory category)181 {182 try183 {184 if (sourceTemplate == null)185 {186 LogMessage("there is no data in the ParellelTrading source file.");187 return;188 }189 190 List<List<string>> propertyName = GetPropertyName(iaTemplate);191 if (propertyName == null || propertyName.Count == 0)192 {193 LogMessage("ParellelTrading QATemplate is emptyt.");194 return;195 }196 197 for (int i = 0; i < propertyName[0].Count; i++)198 {199 iaTemplate[i + 1][3] = GetIAEffectiveDate(sourceTemplate, category);200 iaTemplate[i + 1][2] = GetIAPropertyValue(sourceTemplate, propertyName[0][i], iaTemplate[i + 1][2], category);201 iaTemplate[i + 1][5] = GetIAChangeOffset(sourceTemplate, propertyName[0][i], category);202 iaTemplate[i + 1][6] = GetIAChangeTrigger(sourceTemplate, propertyName[0][i], category);203 }204 205 }206 catch (Exception ex)207 {208 string msg = string.Format("\r\n ClassName: {0}\r\n MethodName: {1}\r\n Message: {2}",209 System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(),210 System.Reflection.MethodBase.GetCurrentMethod().Name,211 ex.Message);212 Logger.Log(msg, Logger.LogType.Error);213 }214 }215 216 private void FillQATemplate(List<List<string>> qaTemplate, SourceTemplate sourceTemplate, FileCategory category)217 {218 try219 {220 if (sourceTemplate == null)221 {222 LogMessage("there is no data in the ParellelTrading source file.");223 return;224 }225 226 List<List<string>> propertyName = GetPropertyName(qaTemplate);227 if (propertyName == null || propertyName.Count == 0)228 {229 LogMessage("ParellelTrading is emptyt.");230 return;231 }232 233 Dictionary<int, string> endString = new Dictionary<int, string>();234 endString.Add(0, ".HK");235 endString.Add(1, "stat.HK");236 endString.Add(2, "ta.HK");237 238 int index;239 for (int i = 0; i < propertyName.Count; i++)240 {241 for (int j = 0; j < propertyName[i].Count; j++)242 {243 index = GetIndex(i, j, propertyName);244 qaTemplate[index][0] = string.Format("{0}{1}", GetQAUnderlying(sourceTemplate, category), endString[i]);245 qaTemplate[index][2] = GetQAPropertyValue(sourceTemplate, propertyName[i][j], endString[i], category);246 qaTemplate[index][3] = GetQAEffectiveDate(sourceTemplate, category);247 qaTemplate[index][5] = GetQAChangeOffset(sourceTemplate, propertyName[i][j], category);248 qaTemplate[index][6] = GetQAChangeTrigger(sourceTemplate, propertyName[i][j], category);249 }250 }251 }252 catch (Exception ex)253 {254 string msg = string.Format("\r\n ClassName: {0}\r\n MethodName: {1}\r\n Message: {2}",255 System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(),256 System.Reflection.MethodBase.GetCurrentMethod().Name,257 ex.Message);258 Logger.Log(msg, Logger.LogType.Error);259 }260 }261 262 private string GetIAPropertyValue(SourceTemplate sourceTemplate, string propertyName, string propertyValueInTemplate, FileCategory category)263 {264 try265 {266 if ((propertyName + "").Trim().Length == 0)267 return GetIAEmptyPropertyName(sourceTemplate, category);268 269 if (propertyName.Contains("HONG KONG CODE"))270 return GetIAOfficialCode(sourceTemplate, category);271 272 if (propertyName.Contains("ASSET COMMON NAME"))273 return GetIADisplayname(sourceTemplate, category);274 275 if (propertyName.Contains("RCS ASSET CLASS"))276 return propertyValueInTemplate;277 }278 catch (Exception ex)279 {280 string msg = string.Format("\r\n ClassName: {0}\r\n MethodName: {1}\r\n Message: {2}",281 System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(),282 System.Reflection.MethodBase.GetCurrentMethod().Name,283 ex.Message);284 Logger.Log(msg, Logger.LogType.Error);285 }286 287 return string.Empty;288 }289 290 private string GetQAPropertyValue(SourceTemplate sourceTemplate, string propertyName, string endString, FileCategory category)291 {292 try293 {294 if ((propertyName + "").Trim().Length == 0)295 return string.Empty;296 297 if (propertyName.Contains("RIC"))298 return string.Format("{0}{1}", GetQAUnderlying(sourceTemplate, category), endString);299 300 if (propertyName.Contains("ASSET COMMON NAME"))301 return GetQADisplayname(sourceTemplate, category);302 303 if (propertyName.Contains("ROUND LOT SIZE"))304 return GetQALotSize(sourceTemplate, category);305 306 if (propertyName.Contains("TICKER SYMBOL"))307 return GetQAOfficialCode(sourceTemplate, category);308 }309 catch (Exception ex)310 {311 string msg = string.Format("\r\n ClassName: {0}\r\n MethodName: {1}\r\n Message: {2}",312 System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(),313 System.Reflection.MethodBase.GetCurrentMethod().Name,314 ex.Message);315 Logger.Log(msg, Logger.LogType.Error);316 }317 318 return string.Empty;319 }320 321 #region [QA]322 private string GetQAChangeTrigger(SourceTemplate sourceTemplate, string propertyName, FileCategory category)323 {324 if (category.Equals(FileCategory.HShareIPO) || category.Equals(FileCategory.IPO) || category.Equals(FileCategory.RIGHTS))325 {326 if ((propertyName + "").Trim().Length == 0)327 return string.Empty;328 else329 return "PEO";330 }331 332 return string.Empty;333 }334 335 private string GetQAChangeOffset(SourceTemplate sourceTemplate, string propertyName, FileCategory category)336 {337 if (category.Equals(FileCategory.RIGHTS))338 {339 if ((propertyName + "").Contains("RIC"))340 return "23";341 else342 return string.Empty;343 }344 345 return string.Empty;346 }347 348 private string GetQAEmptyPropertyName(SourceTemplate sourceTemplate, FileCategory category)349 {350 return string.Empty;351 }352 353 private string GetQAUnderlying(SourceTemplate sourceTemplate, FileCategory category)354 {355 if (category.Equals(FileCategory.ParellelTrading))356 return sourceTemplate.UnderlyingRICNew;357 else358 return sourceTemplate.UnderlyingRIC;359 }360 361 private string GetQAOfficialCode(SourceTemplate sourceTemplate, FileCategory category)362 {363 if (category.Equals(FileCategory.ParellelTrading))364 return sourceTemplate.OfficialCodeNew;365 else366 return sourceTemplate.OfficialCode;367 }368 369 private string GetQALotSize(SourceTemplate sourceTemplate, FileCategory category)370 {371 if (category.Equals(FileCategory.ParellelTrading))372 return sourceTemplate.LotSizeNew;373 else374 return sourceTemplate.LotSize;375 }376 377 private string GetQADisplayname(SourceTemplate sourceTemplate, FileCategory category)378 {379 if (category.Equals(FileCategory.HShareIPO))380 return string.Format("{0} ORD H", sourceTemplate.Displayname.Replace("<--NOT YET CFM", "").Trim());381 382 if (category.Equals(FileCategory.IPO))383 return string.Format("{0} ORD", sourceTemplate.Displayname.Replace("<--NOT YET CFM", "").Trim());384 385 if (category.Equals(FileCategory.ParellelTrading))386 return string.Format("{0} ORD(TEMP)", sourceTemplate.Displayname.Replace("<--NOT YET CFM", "").Trim());387 388 if (category.Equals(FileCategory.RIGHTS))389 return sourceTemplate.Displayname.Replace("<--NOT YET CFM", "").Trim();390 391 return string.Empty;392 }393 394 private string GetQAEffectiveDate(SourceTemplate sourceTemplate, FileCategory category)395 {396 return sourceTemplate.EffectiveDate;397 }398 #endregion399 400 #region [IA]401 private string GetIAChangeTrigger(SourceTemplate sourceTemplate, string propertyName, FileCategory category)402 {403 if (category.Equals(FileCategory.HShareIPO) || category.Equals(FileCategory.IPO) || category.Equals(FileCategory.RIGHTS))404 {405 if ((propertyName + "").Trim().Length == 0)406 return string.Empty;407 else408 return "PEO";409 }410 411 return string.Empty;412 }413 414 private string GetIAChangeOffset(SourceTemplate sourceTemplate, string propertyName, FileCategory category)415 {416 if (category.Equals(FileCategory.RIGHTS))417 {418 if ((propertyName + "").Trim().Length == 0)419 return string.Empty;420 else421 return "23";422 }423 424 return string.Empty;425 }426 427 private string GetIAEmptyPropertyName(SourceTemplate sourceTemplate, FileCategory category)428 {429 return string.Empty;430 }431 432 private string GetIAUnderlying(SourceTemplate sourceTemplate, FileCategory category)433 {434 if (category.Equals(FileCategory.ParellelTrading))435 return sourceTemplate.UnderlyingRICNew;436 else437 return sourceTemplate.UnderlyingRIC;438 }439 440 private string GetIAOfficialCode(SourceTemplate sourceTemplate, FileCategory category)441 {442 if (category.Equals(FileCategory.ParellelTrading))443 return sourceTemplate.OfficialCodeNew;444 else445 return sourceTemplate.OfficialCode;446 }447 448 private string GetIALotSize(SourceTemplate sourceTemplate, FileCategory category)449 {450 if (category.Equals(FileCategory.ParellelTrading))451 return sourceTemplate.LotSizeNew;452 else453 return sourceTemplate.LotSize;454 }455 456 private string GetIADisplayname(SourceTemplate sourceTemplate, FileCategory category)457 {458 if (category.Equals(FileCategory.HShareIPO))459 return string.Format("{0} Ord Shs H", sourceTemplate.LegalRegisteredName.Replace("Company", "").Replace("Limited", "").Trim());460 461 if (category.Equals(FileCategory.IPO))462 return string.Format("{0} Ord Shs", sourceTemplate.LegalRegisteredName.Replace("Company", "").Replace("Limited", "").Trim());463 464 if (category.Equals(FileCategory.ParellelTrading))465 return string.Format("{0} Ord Shs(Temp)", sourceTemplate.LegalRegisteredName.Replace("Company", "").Replace("Limited", "").Trim());466 467 if (category.Equals(FileCategory.RIGHTS))468 return string.Format("{0} Rights", sourceTemplate.LegalRegisteredName.Replace("Company", "").Replace("Limited", "").Trim());469 470 return string.Empty;471 }472 473 private string GetIAEffectiveDate(SourceTemplate sourceTemplate, FileCategory category)474 {475 return sourceTemplate.EffectiveDate;476 }477 #endregion478 479 private int GetIndex(int lineCount, int valueCount, List<List<string>> propertyName)480 {481 int result = valueCount + 1;482 483 try484 {485 for (int i = 0; i < lineCount; i++)486 result += propertyName[i].Count;487 488 return result;489 }490 catch (Exception ex)491 {492 string msg = string.Format("\r\n ClassName: {0}\r\n MethodName: {1}\r\n Message: {2}",493 System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(),494 System.Reflection.MethodBase.GetCurrentMethod().Name,495 ex.Message);496 Logger.Log(msg, Logger.LogType.Error);497 498 return 0;499 }500 }501 502 private void GenerateFile(string path, List<List<string>> template)503 {504 try505 {506 if (!Directory.Exists(Path.GetDirectoryName(path)))507 Directory.CreateDirectory(Path.GetDirectoryName(path));508 509 if (File.Exists(path))510 File.Delete(path);511 512 XlsOrCsvUtil.GenerateStringCsv(path, template);513 }514 catch (Exception ex)515 {516 string msg = string.Format("\r\n ClassName: {0}\r\n MethodName: {1}\r\n Message: {2}",517 System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(),518 System.Reflection.MethodBase.GetCurrentMethod().Name,519 ex.Message);520 Logger.Log(msg, Logger.LogType.Error);521 }522 }523 524 private List<List<string>> GetPropertyName(List<List<string>> qaTemplate)525 {526 List<List<string>> result = new List<List<string>>();527 List<string> line = null;528 529 try530 {531 for (int i = 1; i < qaTemplate.Count; i++)532 {533 if (i == 1)534 line = new List<string>();535 536 if (line.Contains(qaTemplate[i][1]))537 {538 result.Add(line);539 line = new List<string>();540 }541 542 line.Add(qaTemplate[i][1]);543 }544 545 result.Add(line);546 return result;547 }548 catch (Exception ex)549 {550 string msg = string.Format("\r\n ClassName: {0}\r\n MethodName: {1}\r\n Message: {2}",551 System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(),552 System.Reflection.MethodBase.GetCurrentMethod().Name,553 ex.Message);554 Logger.Log(msg, Logger.LogType.Error);555 556 return null;557 }558 }559 560 private SourceTemplate FormatSource(List<List<string>> listSource)561 {562 SourceTemplate sourceTemplate = new SourceTemplate();563 564 try565 {566 foreach (var line in listSource)567 {568 if (line == null || line.Count < 2)569 continue;570 571 if ((line[0] + "").Trim().Length == 0)572 continue;573 574 string name = line[0].Trim();575 string value = http://www.mamicode.com/(line[1] + "").Replace("<-- NOT YET CFM", "").Trim();576 if (name.Contains("Effective Date:") && value.Length != 0)577 sourceTemplate.EffectiveDate = ConvertDateNumber(value);578 579 if (name.Contains("Effective Date (NEW):") && value.Length != 0)580 sourceTemplate.EffectiveDateNew = ConvertDateNumber(value);581 582 if (name.Contains("Underlying RIC:") && value.Length != 0)583 sourceTemplate.UnderlyingRIC = value.Substring(0, value.Length - 3);584 585 if (name.Contains("Underlying RIC (NEW):") && value.Length != 0)586 sourceTemplate.UnderlyingRICNew = value.Substring(0, value.Length - 3);587 588 if (name.Contains("Displayname:") && value.Length != 0)589 sourceTemplate.Displayname = value;590 591 if (name.Contains("Displayname (NEW):") && value.Length != 0)592 sourceTemplate.DisplaynameNew = value;593 594 if (name.Contains("Official Code:") && value.Length != 0)595 sourceTemplate.OfficialCode = value;596 597 if (name.Contains("Official Code (NEW):") && value.Length != 0)598 sourceTemplate.OfficialCodeNew = value;599 600 if (name.Contains("Lot Size:") && value.Length != 0)601 sourceTemplate.LotSize = value;602 603 if (name.Contains("Lot Size (NEW):") && value.Length != 0)604 sourceTemplate.LotSizeNew = value;605 606 if (name.Contains("Legal Registered Name:") && value.Length != 0)607 sourceTemplate.LegalRegisteredName = value;608 609 if (name.Contains("Legal Registered Name (NEW):") && value.Length != 0)610 sourceTemplate.LegalRegisteredNameNew = value;611 }612 613 return sourceTemplate;614 }615 catch (Exception ex)616 {617 string msg = string.Format("\r\n ClassName: {0}\r\n MethodName: {1}\r\n Message: {2}",618 System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(),619 System.Reflection.MethodBase.GetCurrentMethod().Name,620 ex.Message);621 Logger.Log(msg, Logger.LogType.Error);622 623 return null;624 }625 }626 627 private string ConvertDateNumber(string value)628 {629 try630 {631 return Convert.ToDateTime("1900-01-01").AddDays(Convert.ToInt32(value.Trim()) - 2).ToString("dd-MMM-yy");632 }633 catch (Exception ex)634 {635 string msg = string.Format("\r\n ClassName: {0}\r\n MethodName: {1}\r\n Message: {2}",636 System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(),637 System.Reflection.MethodBase.GetCurrentMethod().Name,638 ex.Message);639 Logger.Log(msg, Logger.LogType.Error);640 641 return string.Empty;642 }643 }644 645 private bool CheckConfig()646 {647 if ((configObj.IATemplatePath + "").Trim().Length == 0 || !File.Exists(configObj.IATemplatePath))648 {649 LogMessage("IATemplate path invalid .");650 return false;651 }652 653 if ((configObj.OutputFolder + "").Trim().Length == 0)654 {655 LogMessage("Output folder invalid .");656 return false;657 }658 659 if (configObj.FileType.Equals(FileCategory.AllType) || configObj.FileType.Equals(FileCategory.IPO))660 {661 if (!CheckPath(configObj.SourcePathIPO, configObj.TemplatePathIPO))662 {663 LogMessage("IPO config setting invalid .");664 return false;665 }666 667 }668 669 if (configObj.FileType.Equals(FileCategory.AllType) || configObj.FileType.Equals(FileCategory.ParellelTrading))670 {671 if (!CheckPath(configObj.SourcePathParellel, configObj.TemplatePathParellel))672 {673 LogMessage("ParellelTading config setting invalid .");674 return false;675 }676 }677 678 if (configObj.FileType.Equals(FileCategory.AllType) || configObj.FileType.Equals(FileCategory.RIGHTS))679 {680 if (!CheckPath(configObj.SourcePathRIGHTS, configObj.TemplatePathRIGHTS))681 {682 LogMessage("RIGHTS config setting invalid .");683 return false;684 }685 }686 687 try688 {689 if (!Directory.Exists(configObj.OutputFolder))690 Directory.CreateDirectory(configObj.OutputFolder);691 692 iaTemplate = ReadExcel(configObj.IATemplatePath, 1);693 }694 catch (Exception ex)695 {696 string msg = string.Format("\r\n ClassName: {0}\r\n MethodName: {1}\r\n Message: {2}",697 System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(),698 System.Reflection.MethodBase.GetCurrentMethod().Name,699 ex.Message);700 Logger.Log(msg, Logger.LogType.Error);701 return false;702 }703 704 return true;705 }706 707 private List<List<string>> ReadExcel(string path, int position)708 {709 try710 {711 using (ExcelApp excelApp = new ExcelApp(false, false))712 {713 return ExcelUtil.CreateOrOpenExcelFile(excelApp, path).ToList(position);714 }715 716 }717 catch (Exception ex)718 {719 string msg = string.Format("\r\n ClassName: {0}\r\n MethodName: {1}\r\n Message: {2}",720 System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(),721 System.Reflection.MethodBase.GetCurrentMethod().Name,722 ex.Message);723 Logger.Log(msg, Logger.LogType.Error);724 }725 726 return null;727 }728 729 private bool CheckPath(string source, string template)730 {731 if ((source + "").Trim().Length == 0 || !File.Exists(source))732 return false;733 734 if ((template + "").Trim().Length == 0 || !File.Exists(source))735 return false;736 737 return true;738 }739 }740 741 class SourceTemplate742 {743 public string EffectiveDate { get; set; }744 public string UnderlyingRIC { get; set; }745 public string Displayname { get; set; }746 public string OfficialCode { get; set; }747 public string LotSize { get; set; }748 public string LegalRegisteredName { get; set; }749 750 public string EffectiveDateNew { get; set; }751 public string UnderlyingRICNew { get; set; }752 public string DisplaynameNew { get; set; }753 public string OfficialCodeNew { get; set; }754 public string LotSizeNew { get; set; }755 public string LegalRegisteredNameNew { get; set; }756 }757 }

自己封装一些集合产生文件类库。
希望各位大神多提提代码细节方面意见。