/// <summary> /// 取込設定 明細から 実カラムへの変換 /// </summary> /// <param name="detail"></param> /// <returns></returns> private string ConvertImporterSettingDetailToColumnName(ImporterSettingDetail detail) => detail.Sequence == (int)Fields.CompanyCode ? "CompanyId" : detail.Sequence == (int)Fields.ParentCustomerCode ? "ParentCustomerId" : detail.Sequence == (int)Fields.CustomerCode ? "CustomerId" : detail.Sequence == (int)Fields.BilledAt ? "BilledAt" : detail.Sequence == (int)Fields.BillingAmount ? "BillingAmount" : detail.Sequence == (int)Fields.TaxAmount ? "TaxAmount" : detail.Sequence == (int)Fields.DueAt ? "DueAt" : detail.Sequence == (int)Fields.DepartmentCode ? "DepartmentId" : detail.Sequence == (int)Fields.DebitAccountTitleCode ? "DebitAccountTitleId" : detail.Sequence == (int)Fields.SalesAt ? "SalesAt" : detail.Sequence == (int)Fields.InvoiceCode ? "InvoiceCode" : detail.Sequence == (int)Fields.ClosingAt ? "ClosingAt" : detail.Sequence == (int)Fields.StaffCode ? "StaffId" : detail.Sequence == (int)Fields.Note1 ? "Note1" : detail.Sequence == (int)Fields.BillingCategoryCode ? "BillingCategoryId" : detail.Sequence == (int)Fields.Note2 ? "Note2" : detail.Sequence == (int)Fields.Note3 ? "Note3" : detail.Sequence == (int)Fields.Note4 ? "Note4" : detail.Sequence == (int)Fields.Note5 ? "Note5" : detail.Sequence == (int)Fields.Note6 ? "Note6" : detail.Sequence == (int)Fields.Note7 ? "Note7" : detail.Sequence == (int)Fields.Note8 ? "Note8" : detail.Sequence == (int)Fields.CurrencyCode ? "CurrencyId" : "";
public Task <ImporterSettingDetail> SaveAsync(ImporterSettingDetail detail, CancellationToken token = default(CancellationToken)) { var query = @" MERGE INTO ImporterSettingDetail AS target USING ( SELECT @ImporterSettingId [ImporterSettingId] , @Sequence [Sequence] ) AS source ON ( target.ImporterSettingId = source.[ImporterSettingId] AND target.[Sequence] = source.[Sequence] ) WHEN MATCHED THEN UPDATE SET ImportDivision = @ImportDivision , FieldIndex = COALESCE(@FieldIndex, 0) , FixedValue = @FixedValue , Caption = @Caption , IsUnique = @IsUnique , DoOverwrite = @DoOverwrite , AttributeDivision = @AttributeDivision , ItemPriority = @ItemPriority , UpdateKey = @UpdateKey , UpdateBy = @UpdateBy , UpdateAt = @UpdateAt WHEN NOT MATCHED THEN INSERT (ImporterSettingId, Sequence, ImportDivision, FieldIndex, Caption, IsUnique, AttributeDivision, DoOverwrite, FixedValue, ItemPriority, UpdateKey, CreateBy, CreateAt, UpdateBy, UpdateAt) VALUES (@ImporterSettingId, @Sequence, @ImportDivision, COALESCE(@FieldIndex, 0), @Caption, @IsUnique, @AttributeDivision, @DoOverwrite, @FixedValue, @ItemPriority, @UpdateKey, @CreateBy, @CreateAt, @UpdateBy,@UpdateAt) OUTPUT inserted.*;"; return(dbHelper.ExecuteAsync <ImporterSettingDetail>(query, detail, token)); }
private List <ImporterSettingDetail> PrepareSaveImporterSettingDetail() { var nowDateTime = DateTime.Now; return(grid.Rows.Select(row => { var detail = new ImporterSettingDetail(); detail.IsUnique = 0; detail.FixedValue = ""; detail.ImporterSettingId = ImporterSettingId; detail.UpdateBy = Login.UserId; detail.UpdateAt = nowDateTime; detail.Sequence = Convert.ToInt32(row.Cells[CellIndexSequence].Value); detail.CreateBy = Login.UserId; detail.CreateAt = nowDateTime; detail.ImportDivision = Convert.ToInt32(row.Cells[CellIndexImportDivision].Value); var field = (Fields)detail.Sequence; if (detail.ImportDivision == 1) { detail.FieldIndex = Convert.ToInt32(row.Cells[CellIndexFieldIndex].Value); } else if (detail.ImportDivision == 0 && (field == Fields.ReceiptAmount || field == Fields.ScheduledPaymentKey)) { detail.FieldIndex = Convert.ToInt32(row.Cells[CellIndexFieldIndex].Value); } else { detail.FieldIndex = Convert.ToInt32(row.Cells[CellIndexPriority].Value); } detail.Caption = row.Cells[CellIndexCaption].Value?.ToString() ?? ""; detail.ItemPriority = Convert.ToInt32(row.Cells[CellIndexAssendingOrder].Value); detail.AttributeDivision = Convert.ToInt32(row.Cells[CellIndexAttribute].Value); return detail; }).ToList()); }
protected Func <string, DateTime?> CreateFormatter(ImporterSettingDetail detail) { if (detail == null || !detail.AttributeDivision.HasValue) { return(null); } var attributeDivision = detail.AttributeDivision.Value; var provider = CultureInfo.CurrentCulture.DateTimeFormat.Clone() as DateTimeFormatInfo; var isJapaneseCalendar = (attributeDivision == 5 || attributeDivision == 6); if (isJapaneseCalendar) { provider.Calendar = new JapaneseCalendar(); } var format = ""; var pattern = ""; switch (attributeDivision) { case 1: /* yyyy/MM/dd */ case 3: /* yyyyMMdd */ format = "yyyy/M/d"; pattern = @"^\d{4}/\d{1,2}/\d{1,2}"; break; case 2: /* yy/MM/dd */ case 4: /* yyMMdd */ case 5: /* gg/MM/dd */ case 6: /* ggMMdd */ format = "yy/M/d"; pattern = @"^\d{2}/\d{1,2}/\d{1,2}"; break; } if (isJapaneseCalendar) { format = $"gg{format}"; } return(value => { value = value.Replace("-", "/"); if (attributeDivision == 3 || attributeDivision == 4 || attributeDivision == 6) { var offset = attributeDivision == 3 ? 2 : 0; if (value.Length == offset + "yyMMdd".Length) { value = value .Insert(offset + 4, "/") .Insert(offset + 2, "/"); } if (value.Length == offset + "yyMMddHHmmss".Length) { value = value .Insert(offset + 10, ":") .Insert(offset + 8, ":") .Insert(offset + 6, " ") .Insert(offset + 4, "/") .Insert(offset + 2, "/"); } if (value.Length >= offset + "yyMMddHHmmssf".Length) { value = value .Insert(offset + 12, ".") .Insert(offset + 10, ":") .Insert(offset + 8, ":") .Insert(offset + 6, " ") .Insert(offset + 4, "/") .Insert(offset + 2, "/"); } } pattern += @"(\s[0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}(\.[0-9]{1,3})?)?$"; if (!Regex.IsMatch(value, pattern)) { return null; } DateTime result; var times = new string[] { "", " H:m:s", " H:m:s.f", " H:m:s.ff", " H:m:s.fff" }; var formats = times.Select(x => format + x).ToArray(); if (isJapaneseCalendar) { value = DateTime.Today.ToString("gg", provider) + value; } if (DateTime.TryParseExact(value, formats, provider, DateTimeStyles.AssumeLocal, out result)) { return result; } return null; }); }
private bool IsAttributeEnabled(ImporterSettingDetail detail) => IsAttributeEnabled((Fields)detail.Sequence) && (IsImportRequired((Fields)detail.Sequence) || detail.ImportDivision == 1) ;
/// <summary> /// 優先順位 項目間 有効無効 項目内 も連動 /// </summary> /// <param name="detail"></param> /// <returns></returns> private bool IsItemPriorityEnabled(ImporterSettingDetail detail) => !IsImportRequired((Fields)detail.Sequence) && !IsImportIgnored((Fields)detail.Sequence) && detail.ImportDivision == 0 ;