public static void UseGlobalExceptionHandler(this IApplicationBuilder app, ILogger logger) { app.UseExceptionHandler(appError => { appError.Run(async context => { context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; context.Response.ContentType = "application/json"; var contextFeature = context.Features.Get <IExceptionHandlerFeature>(); if (contextFeature != null) { var errorInfo = new ErrorInfoModel() { ErrorId = Guid.NewGuid(), SessionId = context.User.Claims.Where(x => x.Type == JwtRegisteredClaimNames.Jti).FirstOrDefault().Value, StatusCode = context.Response.StatusCode, Message = "Internal Server Error." }.ToString(); logger.Error($"THA_Exception: {contextFeature.Error} Info: {errorInfo}"); await context.Response.WriteAsync(errorInfo);; } }); }); }
public static void AddEinvoiceToErrorBuffer( string sKind, string einvNum, string errorMsg, int errorGroupKey, short errorLevel, ref ErrorInfoModel errorInfo, string processName, string sourceFile = null, string otherMsg = null ) { if (!errorInfo.ErrorBuffer.ContainsKey(sKind)) { errorInfo.ErrorBuffer.Add(sKind, new EinvoiceErrorMain()); } errorInfo.ErrorBuffer[sKind].Details.Add(new EinvoiceErrorDetails() { ErrorGroupKey = errorGroupKey, EinvoiceNumber = einvNum, ErrorMessage = errorMsg, ErrorLevel = errorLevel, SourceFile = sourceFile, OtherMessage = otherMsg, ProcessName = processName }); }
public override void Handle(ExceptionHandlerContext context) { var correlationId = Guid.NewGuid(); var errorInfoModel = new ErrorInfoModel { Message = context.Exception.Message, TimeStamp = DateTime.UtcNow, RequestUri = context.Request.RequestUri, ErrorId = correlationId, }; //ArgumentException is thrown for all the business validation exceptions //ArgumentNullException is thrown when an item is not found HttpResponseMessage httpResponseMessage; if (context.Exception is ArgumentException) { httpResponseMessage = context.Request.CreateResponse(HttpStatusCode.BadRequest, errorInfoModel); } else if (context.Exception is ArgumentNullException) { httpResponseMessage = context.Request.CreateResponse(HttpStatusCode.NotFound, errorInfoModel); } else { httpResponseMessage = context.Request.CreateResponse(HttpStatusCode.InternalServerError, errorInfoModel); } context.Result = new ResponseMessageResult(httpResponseMessage); }
public static bool CheckHeadHasError(string sKind0, string einvoiceNum, ErrorInfoModel errorInfo) { bool isFail = false; string kind = sKind0.Replace("D", "") + "H"; var data = errorInfo.ErrorBuffer.Where(o => o.Key == kind).ToList(); if (data.Count > 0) { isFail = (data.Where(o => o.Value.Details.Any(w => w.EinvoiceNumber == einvoiceNum)).ToList().Count > 0); } return(isFail); }
public HttpResponse NotFound(string path) { var metadata = new ErrorInfoModel { Message = "Route doesn't exist.", TimeStamp = DateTime.UtcNow, RequestUri = Request.RequestUri, ErrorId = Request.GetCorrelationId() }; return(Request.CreateResponse(HttpStatusCode.NotFound, metadata)); }
/// <summary> /// Overrides <see cref="ExceptionHandler.Handle"/> method with code that sets friendly error message to be shown in browser. /// </summary> /// <param name="context">Instance fo <see cref="ExceptionHandlerContext"/>.</param> public override void Handle(ExceptionHandlerContext context) { var metadata = new ErrorInfoModel { //Message = "An unexpected error occurred! Please use the Error ID to contact support", Message = context.Exception.ToString(), TimeStamp = DateTimeOffset.UtcNow, RequestUri = context.Request.RequestUri, }; var response = context.Request.CreateResponse(HttpStatusCode.InternalServerError, metadata); context.Result = new ResponseMessageResult(response); }
/// <summary> /// Overrides <see cref="M:System.Web.Http.ExceptionHandling.ExceptionHandler.Handle(System.Web.Http.ExceptionHandling.ExceptionHandlerContext)" /> method with code that sets friendly error message to be shown in browser. /// </summary> /// <param name="context">Instance fo <see cref="T:System.Web.Http.ExceptionHandling.ExceptionHandlerContext" />.</param> public override void Handle(ExceptionHandlerContext context) { ErrorInfoModel errorInfoModel = new ErrorInfoModel { Message = "An unexpected error occurred! Please use the Error ID to contact support", TimeStamp = DateTime.UtcNow, RequestUri = context.Request.RequestUri, ErrorId = Guid.NewGuid(), ExeptionMessage = context.Exception.Message }; HttpResponseMessage response = context.Request.CreateResponse(HttpStatusCode.InternalServerError, errorInfoModel); context.Result = new ResponseMessageResult(response); }
/// <summary> /// Overrides <see cref="ExceptionHandler.Handle"/> method with code that sets friendly error message to be shown in browser. /// </summary> /// <param name="context">Instance fo <see cref="ExceptionHandlerContext"/>.</param> public override void Handle(ExceptionHandlerContext context) { var correlationId = Guid.NewGuid(); var metadata = new ErrorInfoModel { Message = "An unexpected error occurred! Please use the Error ID to contact support", TimeStamp = DateTime.UtcNow, RequestUri = context.Request.RequestUri, ErrorId = correlationId }; var response = context.Request.CreateResponse(HttpStatusCode.InternalServerError, metadata); context.Result = new ResponseMessageResult(response); }
// GET: Error public ActionResult ApplicationError() { var ex = HttpContext.Server.GetLastError(); var app = HttpContext.ApplicationInstance; var errors = app.Context.AllErrors?.Length; var model = new ErrorInfoModel { Message = ex?.Message, Exception = ex, TipoError = "Server Error", StackTrace = $"Total errores: {errors.GetValueOrDefault()}" }; return(View(model: model)); }
/// <summary> /// Sobreescreve <see cref="ExceptionHandler.Handle"/> /// </summary> /// <param name="context">Instancia de <see cref="ExceptionHandlerContext"/>.</param> public override void Handle(ExceptionHandlerContext context) { var correlationId = Guid.NewGuid(); var metadata = new ErrorInfoModel { Message = "Um erro não esperado aconteceu!", TimeStamp = DateTime.UtcNow, RequestUri = context.Request.RequestUri, ErrorId = correlationId }; var response = context.Request.CreateResponse(HttpStatusCode.InternalServerError, metadata); context.Result = new ResponseMessageResult(response); }
public HttpResponseMessage NotFound(string path) { ErrorInfoModel errorInfoModel = new ErrorInfoModel(); errorInfoModel.Message = "Route doesn't exist."; DateTimeOffset utcNow = (DateTimeOffset)DateTime.UtcNow; errorInfoModel.TimeStamp = utcNow; Uri requestUri = this.Request.RequestUri; errorInfoModel.RequestUri = requestUri; Guid correlationId = this.Request.GetCorrelationId(); errorInfoModel.ErrorId = correlationId; return(this.Request.CreateResponse <ErrorInfoModel>(HttpStatusCode.NotFound, errorInfoModel)); }
private void ValidDetailsHasError(ErrorInfoModel errorInfo) { var detailsError = errorInfo.ErrorBuffer.Where(o => o.Key == "B0401D").ToList(); if (detailsError.Count > 0) { using (var sqlAdapter = new SQL1()) { foreach (var error in detailsError) { var detail = error.Value.Details.First(); string index = (error.Value.Details.IndexOf(detail) + 1).ToString(); sqlAdapter.GoLogsAll(error.Key, ProcessName, detail.SourceFile, detail.ErrorMessage, index, detail.ErrorLevel, false); if (detail.ErrorGroupKey == 1 || detail.ErrorGroupKey == 3) { continue; } sqlAdapter.GoToSTemp("B0401D", " MAllowanceNumber='" + detail.EinvoiceNumber + "' "); sqlAdapter.GoToSTemp("B0401H", " MAllowanceNumber='" + detail.EinvoiceNumber + "' "); } } } }
public void Begin2(string path, string sKind0, ErrorInfoModel errorInfo, string identityKey) { if (!string.IsNullOrEmpty(sKind0)) { sKind0 = sKind0.ToUpper(); } string[] sArr; using (SQL1 sqlAdapter = new SQL1()) { sqlAdapter.ReturnArr(out sArr); } string sPaPartition = sArr[3]; using (SQL1 sqlAdapter = new SQL1()) { List <EinvoiceB0401DTemp> tempData = new List <EinvoiceB0401DTemp>(); var query = sqlAdapter.Kind1SelectTbl2("*", "FILE_TEMP", " EINVOICE_TP='B0401D' and IDENT_KEY = '" + identityKey + "'", "", ""); if (query != null) { var rows = query.Table.Rows; for (int i = 0; i < rows.Count; i++) { tempData.Add(new EinvoiceB0401DTemp() { EinvoiceContent = rows[i]["FILE_CONTENT"].ToString(), EinvoiceFIlePath = rows[i]["FILE_NM"].ToString(), }); } } else { return; } string sPgSN = DateTime.Now.ToString("yyyyMMddHHmmssfff"); sqlAdapter.GoLogsAll(sPgSN, ProcessName, "FILE_TEMP", "", "", 1); //抓 B0401D*.* 的所有檔案 foreach (var data in tempData) { int index = tempData.IndexOf(data) + 1; string sourceFile = data.EinvoiceFIlePath; string einvoiceNumber = string.Empty; string einvoiceDescription = string.Empty; string errorMsg = string.Empty; try { string line = ""; List <Hashtable> einvoiceDataList = new List <Hashtable>(); line = data.EinvoiceContent; if (line.Trim() != "") { string[] CutS = { sPaPartition }; string[] charA = line.Split(CutS, StringSplitOptions.None); einvoiceNumber = charA[0]; einvoiceDescription = charA[1]; //字串尾要分號//共13個分號 if (charA.Length == 13) { #region 檢查Head有無寫入資料 有的話不寫入明細 var chkHeadHasError = EinvoiceRepository.CheckHeadHasError(sKind0, einvoiceNumber, errorInfo); if (chkHeadHasError) { errorMsg = "[正式][" + sKind0 + "]" + einvoiceNumber + "[折讓證明單Head寫入時有錯,明細資料不寫入]"; EinvoiceRepository.AddEinvoiceToErrorBuffer(sKind0, einvoiceNumber, errorMsg, 1, 51, ref errorInfo, ProcessName, sourceFile, einvoiceDescription); continue; } #endregion 檢查Head有無寫入資料 有的話不寫入明細 if (sqlAdapter.Kind1SelectTbl3("B0401DSN", "MAllowanceNumber='" + charA[0].ToString() + "' And DAllowanceSequenceNumber='" + charA[10].ToString() + "'", "B0401D") == 0) { if (charA[1].ToString().Trim() != "" && charA[2].ToString().Trim() != "") { Console.WriteLine(string.Format("{0} 寫入正式資料庫 第{1}筆 發票號碼:{2}開始.", sKind0, index, einvoiceNumber)); Hashtable hashTable = new Hashtable(); hashTable["MAllowanceNumber"] = charA[0].ToString().Trim(); hashTable["DOriginalInvoiceDate"] = charA[1].ToString().Trim(); hashTable["DOriginalInvoiceNumber"] = charA[2].ToString().Trim(); hashTable["DOriginalSequenceNumber"] = charA[3].ToString().Trim(); hashTable["DOriginalDescription"] = charA[4].ToString().Trim(); hashTable["DQuantity"] = charA[5].ToString().Trim(); hashTable["DUnit"] = charA[6].ToString().Trim(); hashTable["DUnitPrice"] = charA[7].ToString().Trim(); hashTable["DAmount"] = charA[8].ToString().Trim(); hashTable["DTax"] = charA[9].ToString().Trim(); hashTable["DAllowanceSequenceNumber"] = charA[10].ToString().Trim(); hashTable["DTaxType"] = charA[11].ToString().Trim(); hashTable["TxFileNmae"] = sourceFile; string insertMsg = sqlAdapter.InsertDataNonKey("B0401D", hashTable); #region 寫入有錯誤之處理 if (!string.IsNullOrEmpty(insertMsg)) { errorMsg = "[正式][" + sKind0 + "]" + einvoiceNumber + "[TXT寫入正式資料庫發生錯誤,資料不寫入]" + insertMsg; EinvoiceRepository.AddEinvoiceToErrorBuffer(sKind0, einvoiceNumber, errorMsg, 2, 51, ref errorInfo, ProcessName, sourceFile, einvoiceDescription); } else { Console.WriteLine(string.Format("{0} 寫入正式資料庫 第{1}筆 發票號碼:{2}結束.", sKind0, index, einvoiceNumber)); } #endregion 寫入有錯誤之處理 } else { errorMsg = "[MInvoiceNumber:" + charA[0].ToString().Trim() + "][明細排列序號:" + charA[10].ToString().Trim() + "]"; EinvoiceRepository.AddEinvoiceToErrorBuffer(sKind0, einvoiceNumber, errorMsg + "[必要欄位沒值!!][DOriginalInvoiceDate][DOriginalInvoiceNumber]", 3, 17, ref errorInfo, ProcessName, sourceFile, einvoiceDescription); } } else { errorMsg = "[MInvoiceNumber:" + charA[0].ToString().Trim() + "][明細排列序號:" + charA[10].ToString().Trim() + "]"; EinvoiceRepository.AddEinvoiceToErrorBuffer(sKind0, einvoiceNumber, errorMsg + "[匯入商品細項的文字檔發生錯誤/此商品已存在!!]", 3, 16, ref errorInfo, ProcessName, sourceFile, einvoiceDescription); } } else { errorMsg = "[正式][折讓證明單號碼:" + einvoiceNumber + "][字串尾要分號,共10個分號]"; EinvoiceRepository.AddEinvoiceToErrorBuffer(sKind0, einvoiceNumber, errorMsg, 4, 12, ref errorInfo, ProcessName, sourceFile, einvoiceDescription); } } else { errorMsg = "[正式][折讓證明單號碼:" + einvoiceNumber + "][讀取資料內容為空白]"; EinvoiceRepository.AddEinvoiceToErrorBuffer(sKind0, einvoiceNumber, errorMsg, 4, 12, ref errorInfo, ProcessName, sourceFile, einvoiceDescription); } } catch (Exception ex) { errorMsg = "[正式][未知錯誤]"; EinvoiceRepository.AddEinvoiceToErrorBuffer(sKind0, einvoiceNumber, errorMsg, 5, 15, ref errorInfo, ProcessName, sourceFile, einvoiceDescription); } } sqlAdapter.GoLogsAll(sPgSN, ProcessName, "FILE_TEMP", "", "", 2); ValidDetailsHasError(errorInfo); } }
public void Begin2(string path, string sKind0, ErrorInfoModel errorInfo, string identityKey) { if (!string.IsNullOrEmpty(sKind0)) { sKind0 = sKind0.ToUpper(); } string[] sArr; using (SQL1 sqlAdapter = new SQL1()) { sqlAdapter.ReturnArr(out sArr); } string sPaPartition = sArr[3]; using (SQL1 sqlAdapter = new SQL1()) { List <EinvoiceC0701Temp> tempData = new List <EinvoiceC0701Temp>(); var query = sqlAdapter.Kind1SelectTbl2("*", "FILE_TEMP", " EINVOICE_TP='C0701' and IDENT_KEY = '" + identityKey + "'", "", ""); if (query != null) { var rows = query.Table.Rows; for (int i = 0; i < rows.Count; i++) { tempData.Add(new EinvoiceC0701Temp() { EinvoiceContent = rows[i]["FILE_CONTENT"].ToString(), EinvoiceFIlePath = rows[i]["FILE_NM"].ToString(), }); } } else { return; } string sPgSN = DateTime.Now.ToString("yyyyMMddHHmmssfff"); sqlAdapter.GoLogsAll(sPgSN, ProcessName, "FILE_TEMP", "", "", 1); foreach (var data in tempData) { int index = tempData.IndexOf(data) + 1; string sourceFile = data.EinvoiceFIlePath; string einvoiceNumber = string.Empty; string errorMsg = string.Empty; try { string line = ""; List <Hashtable> einvoiceDataList = new List <Hashtable>(); line = data.EinvoiceContent; if (line.Trim() != "") { string[] CutS = { sPaPartition }; string[] charA = line.Split(CutS, StringSplitOptions.None); einvoiceNumber = charA[0].ToUpper(); //字串尾要分號//共9個分號 if (charA.Length == 9) { if (sqlAdapter.Kind1SelectTbl3("D0501SN", "CancelAllowanceNumber='" + charA[0].ToString() + "'", "D0501") == 0) { Console.WriteLine(string.Format("{0} 寫入正式資料庫 第{1}筆 發票號碼:{2}開始.", sKind0, index, einvoiceNumber)); Hashtable hashData = SetEinvoiceToHashtable(charA, sourceFile); string insertMsg = sqlAdapter.InsertDataNonKey("D0501", hashData); #region 寫入有錯誤之處理 if (!string.IsNullOrEmpty(insertMsg)) { errorMsg = "[正式][" + sKind0 + "]" + einvoiceNumber + "[TXT寫入正式資料庫發生錯誤,資料不寫入]" + insertMsg; sqlAdapter.GoLogsAll(sPgSN, ProcessName, sourceFile, errorMsg, index.ToString(), 51, false); EinvoiceRepository.AddEinvoiceToErrorBuffer(sKind0, einvoiceNumber, errorMsg, 2, 51, ref errorInfo, ProcessName); } else { Console.WriteLine(string.Format("{0} 寫入正式資料庫 第{1}筆 發票號碼:{2}結束.", sKind0, index, einvoiceNumber)); } #endregion 寫入有錯誤之處理 } else { errorMsg = "[正式][作廢折讓證明單號碼:" + einvoiceNumber + "][此發票號碼已存在,資料不寫入]"; sqlAdapter.GoLogsAll(sPgSN, ProcessName, sourceFile, errorMsg, index.ToString(), 11, false); EinvoiceRepository.AddEinvoiceToErrorBuffer(sKind0, einvoiceNumber, errorMsg, 3, 11, ref errorInfo, ProcessName); } } else { errorMsg = "[正式][作廢折讓證明單號碼:" + einvoiceNumber + "][字串尾要分號,共9個分號]"; sqlAdapter.GoLogsAll(sPgSN, ProcessName, sourceFile, "[正式]", index.ToString(), 12); EinvoiceRepository.AddEinvoiceToErrorBuffer(sKind0, einvoiceNumber, errorMsg, 4, 12, ref errorInfo, ProcessName); } } } catch (Exception ex) { errorMsg = "[正式][未知錯誤]"; sqlAdapter.GoLogsAll(sPgSN, ProcessName, sourceFile, errorMsg + ex.ToString(), "", 15, false); EinvoiceRepository.AddEinvoiceToErrorBuffer(sKind0, einvoiceNumber, errorMsg, 5, 15, ref errorInfo, ProcessName); } } sqlAdapter.GoLogsAll(sPgSN, ProcessName, "FILE_TEMP", "", "", 2); } }
/// <summary> /// 處理錯誤通知mail /// </summary> /// <param name="errorInfo"></param> private void SendErrorEmail(ErrorInfoModel errorInfo) { SQL1 sqlAdaper = new SQL1(); StringBuilder htmlContent = new StringBuilder(); string propertiesHtml = string.Empty; var groupData = errorInfo.ErrorBuffer.OrderBy(o => o.Key) .GroupBy(o => o.Key, o => o.Value).ToList(); //分出A0401H,C0401H foreach (var group in groupData) { var dataTotalCount = group.Sum(s => s.Details.Count); string einvoiceType = group.Key; htmlContent.AppendLine(@"<div style=""border:solid black 1px;padding:7px;"">"); htmlContent.AppendLine(@"<p style=""font-size:23px;"">"); htmlContent.AppendLine("發票處理程序:" + einvoiceType + " 資料筆數:" + dataTotalCount); htmlContent.AppendLine("<p>"); var errorsGroup = group.First().Details.GroupBy(g => g.ErrorGroupKey).Select(s => s); //分出錯誤群組 foreach (var error in errorsGroup) { var erKey = error.Key; htmlContent.AppendLine("<p>"); htmlContent.AppendLine("錯誤分類:" + erKey); htmlContent.AppendLine("<p>"); int dataIndex = 1; foreach (var er in error) { htmlContent.AppendLine(@"<div style=""border:solid #ccc 1px;padding:3px;"">"); htmlContent.AppendLine("<p>"); htmlContent.AppendLine("項目:" + dataIndex); htmlContent.AppendLine("<p>"); htmlContent.AppendLine("<p>"); htmlContent.AppendLine("錯誤發票:" + er.EinvoiceNumber); htmlContent.AppendLine("<p>"); htmlContent.AppendLine("<p>"); htmlContent.AppendLine("錯誤訊息:" + er.ErrorMessage); htmlContent.AppendLine("<p>"); htmlContent.AppendLine("<p>"); htmlContent.AppendLine("其他訊息:" + er.OtherMessage); htmlContent.AppendLine("<p>"); htmlContent.AppendLine("<p>"); htmlContent.AppendLine("處理程序:" + er.ProcessName); htmlContent.AppendLine("<p>"); htmlContent.AppendLine("</div>"); dataIndex++; } } htmlContent.AppendLine("</div>"); } var viewHtml = htmlContent.ToString(); XMLClass oXMLeParamts = new XMLClass(); string eToWho1 = oXMLeParamts.GetParaXml("eToWho"); string eFromWho1 = oXMLeParamts.GetParaXml("eFromWho"); sqlAdaper.AutoEMail(eToWho1, "", eFromWho1, "", htmlContent.ToString()); sqlAdaper.Dispose(); }
public ActionResult Index() { ErrorInfoModel model = new ErrorInfoModel(); model.BaseViewModelInfo.Title = GeneralTexts.UnexpectedError; return View(model); }
public ActionResult UnAuthorized() { ErrorInfoModel model = new ErrorInfoModel(); model.BaseViewModelInfo.Title = GeneralTexts.UnAuthorizedError; return View(model); }
public void Begin2(string path, string sKind0, ErrorInfoModel errorInfo, string identityKey) { Dictionary <string, List <string> > pdfNumList = new Dictionary <string, List <string> >(); if (!string.IsNullOrEmpty(sKind0)) { sKind0 = sKind0.ToUpper(); } string[] sArr; using (SQL1 sqlAdapter = new SQL1()) { sqlAdapter.ReturnArr(out sArr); } string sPaPartition = sArr[3]; using (var sqlAdapter = new SQL1()) { List <EinvoiceA0401HTemp> tempData = new List <EinvoiceA0401HTemp>(); var query = sqlAdapter.Kind1SelectTbl2("*", "FILE_TEMP", " EINVOICE_TP='A0401H' and IDENT_KEY = '" + identityKey + "'", "", ""); if (query != null) { var rows = query.Table.Rows; for (int i = 0; i < rows.Count; i++) { tempData.Add(new EinvoiceA0401HTemp() { EinvoiceContent = rows[i]["FILE_CONTENT"].ToString(), EinvoiceFIlePath = rows[i]["FILE_NM"].ToString(), }); } } else { return; } string sPgSN = DateTime.Now.ToString("yyyyMMddHHmmssfff"); sqlAdapter.GoLogsAll(sPgSN, ProcessName, "FILE_TEMP", "", "", 1); foreach (var data in tempData) { int index = tempData.IndexOf(data) + 1; string sourceFile = data.EinvoiceFIlePath; string einvoiceNumber = string.Empty; string errorMsg = string.Empty; try { string line = ""; List <Hashtable> einvoiceDataList = new List <Hashtable>(); line = data.EinvoiceContent; if (line.Trim() != "") { string[] CutS = { sPaPartition }; string[] charA = line.Split(CutS, StringSplitOptions.None); einvoiceNumber = charA[0].ToUpper(); //字串尾要分號//共48個分號 if (charA.Length == 48) { if (sqlAdapter.Kind1SelectTbl3("A0401SN", "MInvoiceNumber='" + charA[0].ToString() + "'", "A0401H") == 0) { Console.WriteLine(string.Format("{0} 寫入正式資料庫 第{1}筆 發票號碼:{2}開始.", sKind0, index, einvoiceNumber)); Dictionary <bool, string> validErrorBuffer = ValidInvoiceData(charA); if (validErrorBuffer.Count > 0 && validErrorBuffer.Keys.First() == false) { errorMsg = validErrorBuffer.Values.First() + "[正式]驗證失敗,資料不寫入"; sqlAdapter.GoLogsAll(sPgSN, ProcessName, sourceFile, errorMsg, index.ToString(), 11, false); EinvoiceRepository.AddEinvoiceToErrorBuffer(sKind0, einvoiceNumber, errorMsg, 1, 11, ref errorInfo, ProcessName); continue; } Hashtable hashData = SetEinvoiceToHashtable(charA, sourceFile); string insertMsg = sqlAdapter.InsertDataNonKey("A0401H", hashData); #region 寫入有錯誤之處理 if (!string.IsNullOrEmpty(insertMsg)) { errorMsg = "[正式][" + sKind0 + "]" + einvoiceNumber + "[TXT寫入正式資料庫發生錯誤,資料不寫入]" + insertMsg; sqlAdapter.GoLogsAll(sPgSN, ProcessName, sourceFile, errorMsg, index.ToString(), 51, false); EinvoiceRepository.AddEinvoiceToErrorBuffer(sKind0, einvoiceNumber, errorMsg, 2, 51, ref errorInfo, ProcessName); Console.WriteLine(errorMsg); } else { if (!pdfNumList.ContainsKey(sKind0)) { pdfNumList[sKind0] = new List <string>(); } pdfNumList[sKind0].Add(einvoiceNumber); Console.WriteLine(string.Format("{0} 寫入正式資料庫 第{1}筆 發票號碼:{2}完成.", sKind0, index, einvoiceNumber)); } #endregion 寫入有錯誤之處理 } else { errorMsg = "[正式][發票號碼:" + einvoiceNumber + "][此發票號碼已存在,資料不寫入]"; sqlAdapter.GoLogsAll(sPgSN, ProcessName, sourceFile, errorMsg, index.ToString(), 11, false); EinvoiceRepository.AddEinvoiceToErrorBuffer(sKind0, einvoiceNumber, errorMsg, 3, 11, ref errorInfo, ProcessName); } } else { errorMsg = "[正式][發票號碼:" + einvoiceNumber + "][字串尾要分號,共48個分號]"; sqlAdapter.GoLogsAll(sPgSN, ProcessName, sourceFile, "[正式]", index.ToString(), 12); EinvoiceRepository.AddEinvoiceToErrorBuffer(sKind0, einvoiceNumber, errorMsg, 4, 12, ref errorInfo, ProcessName); } } } catch (Exception ex) { errorMsg = "[正式][未知錯誤]"; sqlAdapter.GoLogsAll(sPgSN, ProcessName, sourceFile, errorMsg + ex.ToString(), "", 15, false); EinvoiceRepository.AddEinvoiceToErrorBuffer(sKind0, einvoiceNumber, errorMsg, 5, 15, ref errorInfo, ProcessName); } } sqlAdapter.GoLogsAll(sPgSN, ProcessName, "FILE_TEMP", "", "", 2); foreach (var inv in pdfNumList) { foreach (var item in inv.Value) { Hashtable hashTable = new Hashtable(); hashTable["PRINT_METHOD"] = inv.Key; hashTable["PRINT_EINV_NUM"] = item; //hashTable["MAKE_FILE_DATE"] = DateTime.UtcNow; hashTable["WRITE_DATE"] = DateTime.UtcNow; hashTable["IDEN_KEY"] = identityKey; string insertMsg = sqlAdapter.InsertDataNonKey("PRINT_TEMP", hashTable); } } } }