Feature: MS Excel (xlsx) Import/Export
Microsoft Excel files can be used to import/export devices. Several import bugs were also fixed in the process.
This commit is contained in:
@@ -19,13 +19,15 @@ namespace Disco.Services.Devices.Importing.Fields
|
||||
public override string FriendlyValue { get { return parsedValue; } }
|
||||
public override string FriendlyPreviousValue { get { return previousValue; } }
|
||||
|
||||
public override bool Parse(DiscoDataContext Database, IDeviceImportCache Cache, DeviceImportContext Context, int RecordIndex, string DeviceSerialNumber, Device ExistingDevice, Dictionary<DeviceImportFieldTypes, string> Values, string Value)
|
||||
public override bool Parse(DiscoDataContext Database, IDeviceImportCache Cache, IDeviceImportContext Context, string DeviceSerialNumber, Device ExistingDevice, List<IDeviceImportRecord> PreviousRecords, IDeviceImportDataReader DataReader, int ColumnIndex)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(Value))
|
||||
var value = DataReader.GetString(ColumnIndex);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
parsedValue = null;
|
||||
else
|
||||
{
|
||||
parsedValue = Value.Trim();
|
||||
parsedValue = value.Trim();
|
||||
if (parsedValue.Length > 250)
|
||||
return Error("Cannot be more than 250 characters");
|
||||
}
|
||||
@@ -43,10 +45,10 @@ namespace Disco.Services.Devices.Importing.Fields
|
||||
|
||||
public override bool Apply(DiscoDataContext Database, Device Device)
|
||||
{
|
||||
if (this.FieldAction == EntityState.Added ||
|
||||
this.FieldAction == EntityState.Modified)
|
||||
if (FieldAction == EntityState.Added ||
|
||||
FieldAction == EntityState.Modified)
|
||||
{
|
||||
Device.Location = this.parsedValue;
|
||||
Device.Location = parsedValue;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@@ -55,14 +57,14 @@ namespace Disco.Services.Devices.Importing.Fields
|
||||
}
|
||||
}
|
||||
|
||||
public override int? GuessHeader(DiscoDataContext Database, DeviceImportContext Context)
|
||||
public override int? GuessColumn(DiscoDataContext Database, IDeviceImportContext Context, IDeviceImportDataReader DataReader)
|
||||
{
|
||||
// column name
|
||||
var possibleColumns = Context.Header
|
||||
.Select((h, i) => Tuple.Create(h, i))
|
||||
.Where(h => h.Item1.Item2 == DeviceImportFieldTypes.IgnoreColumn && h.Item1.Item1.IndexOf("location", System.StringComparison.OrdinalIgnoreCase) >= 0);
|
||||
var possibleColumns = Context.Columns
|
||||
.Where(h => h.Type == DeviceImportFieldTypes.IgnoreColumn &&
|
||||
h.Name.IndexOf("location", StringComparison.OrdinalIgnoreCase) >= 0);
|
||||
|
||||
return possibleColumns.Select(h => (int?)h.Item2).FirstOrDefault();
|
||||
return possibleColumns.Select(h => (int?)h.Index).FirstOrDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user