private byte[] _CreateErrorExcelByte(AirBagFilePutCondition condition) { var workBook = new XLWorkbook(); var workSheet = workBook.Worksheets.Add("ErrorFeedBacks"); var colIndex = new AirBagDetailInputFileMap().MemberMaps.ToDictionary(x => x.Data.Member.Name, x => x.Data.Index + 1); var errorList = condition.AirBagDetails.Where(x => !string.IsNullOrEmpty(x.ErrorMessages)).ToList(); workSheet.Range("A1:F1").Style.Fill.BackgroundColor = XLColor.PastelOrange; workSheet.Style.Font.FontName = "游ゴシック"; workSheet.Cell(1, 1).Value = "Make of Vehicle"; workSheet.Cell(1, 2).Value = "Model of Vehicle"; workSheet.Cell(1, 3).Value = "Manifest VIN"; workSheet.Cell(1, 4).Value = "Border Checked"; workSheet.Cell(1, 5).Value = "Alpha"; workSheet.Cell(1, 6).Value = "Non-Alpha"; var rowIndex = 2; foreach (var row in condition.AirBagDetails) { if (string.IsNullOrEmpty(row.ErrorMessages)) { continue; } workSheet.Cell(rowIndex, colIndex[nameof(row.CarMakerNameEng)]).Value = row.CarMakerNameEng; workSheet.Cell(rowIndex, colIndex[nameof(row.CarModelName)]).Value = row.CarModelName; workSheet.Cell(rowIndex, colIndex[nameof(row.ChassisNo)]).Value = row.ChassisNo; //workSheet.Cell(rowIndex, colIndex[nameof(row.InspectionDateText)]).Value = row.InspectionDate?.ToString("dd/M/yyyy"); workSheet.Cell(rowIndex, colIndex[nameof(row.InspectionDateText)]).Style.NumberFormat.SetFormat("dd/MM/yyyy"); workSheet.Cell(rowIndex, colIndex[nameof(row.InspectionDateText)]).Value = row.InspectionDateText; workSheet.Cell(rowIndex, colIndex[nameof(row.RecallStatusName)]).Value = row.RecallStatusName; workSheet.Cell(rowIndex, colIndex[nameof(row.NonAlphaRecallStatusName)]).Value = row.NonAlphaRecallStatusName; workSheet.Cell(rowIndex, colIndex[nameof(row.ErrorMessages)]).Value = row.ErrorMessages; rowIndex++; } workSheet.Columns("A:F").AdjustToContents(); var bytes = new byte[0]; using (var ms = new MemoryStream()) { workBook.SaveAs(ms); bytes = ms.ToArray(); } return(bytes); }
private void _InputCheck(AirBagDetailInputFile row, List <string> status) { var colIndex = new AirBagDetailInputFileMap().MemberMaps.ToDictionary(x => x.Data.Member.Name, x => x.Data.Index + 1); var errorMessages = new List <string>(); //エラー処理をカプセル化 void addError(string columnName, string msg) => errorMessages.Add(string.Format(Resources.Format_ColIndex, colIndex[columnName], msg)); //必須チェック void requiredCheck(string value, string columnName) { if (string.IsNullOrEmpty(value)) { addError(columnName, Resources.E_Required); } } //文字数チェック void lengthCheck(string value, string columnName, int maxLength) { if (!string.IsNullOrEmpty(value) && value.Length > maxLength) { addError(columnName, string.Format(Resources.E_StringLength, maxLength)); } } //DateTime刑チェック void dateCheck(DateTime?value, string columnName) { //DateTime dt; //bool success = DateTime.TryParseExact(value.ToString(), "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt); if (value == null) { addError(columnName, Resources.E_DateFormat); } } //Result形式チェック void recallCheck(string value, string columnName) { if (!status.Contains(value)) { addError(columnName, Resources.E_StatusName); } } void nonAlpharecallCheck(string value, string columnName) { if (!status.Contains(value)) { addError(columnName, Resources.E_NonAlphaStatusName); } } void halfWidthString(string value, string columnName) { Encoding sjisEnc = Encoding.GetEncoding("Shift_JIS"); int num = sjisEnc.GetByteCount(value); if (num == value.Length * 2) { addError(columnName, Resources.E_HalfString); } } //必須チェック requiredCheck(row.CarMakerNameEng, nameof(row.CarMakerNameEng)); requiredCheck(row.CarModelName, nameof(row.CarModelName)); requiredCheck(row.ChassisNo, nameof(row.ChassisNo)); requiredCheck(row.InspectionDateText, nameof(row.InspectionDateText)); requiredCheck(row.RecallStatusName, nameof(row.RecallStatusName)); requiredCheck(row.NonAlphaRecallStatusName, nameof(row.NonAlphaRecallStatusName)); //文字数チェック lengthCheck(row.CarMakerNameEng, nameof(row.CarMakerNameEng), 100); lengthCheck(row.CarModelName, nameof(row.CarModelName), 100); lengthCheck(row.ChassisNo, nameof(row.ChassisNo), 100); lengthCheck(row.InspectionDateText, nameof(row.InspectionDateText), 100); lengthCheck(row.RecallStatusName, nameof(row.RecallStatusName), 100); lengthCheck(row.NonAlphaRecallStatusName, nameof(row.NonAlphaRecallStatusName), 100); //半角チェック halfWidthString(row.ChassisNo, nameof(row.ChassisNo)); //DateTime刑チェック //dateCheck(row.InspectionDate, nameof(row.InspectionDateText)); dateCheck(row.InspectionDate, nameof(row.InspectionDateText)); //Result形式チェック recallCheck(row.RecallStatusName, nameof(row.RecallStatusName)); nonAlpharecallCheck(row.NonAlphaRecallStatusName, nameof(row.NonAlphaRecallStatusName)); if (errorMessages.Any()) { row.ErrorMessages += string.Join(",", errorMessages); } } /*_InputCheck*/