Skip to content

Commit

Permalink
simple notificaiton about processing
Browse files Browse the repository at this point in the history
  • Loading branch information
anion0278 committed Dec 20, 2022
1 parent e9ffe82 commit 57b25c4
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 48 deletions.
106 changes: 59 additions & 47 deletions Mapp.UI/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ internal class MainWindowViewModel : ViewModelWithErrorValidationBase, IMainWind
private string _defaultEmail;
private string _trackingCode;
private bool _openTargetFolderAfterConversion;
private bool _isReadyForProcessing = true;

public RelayCommand SelectAmazonInvoicesCommand { get; }
public RelayCommand ExportConvertedAmazonInvoicesCommand { get; }
Expand Down Expand Up @@ -156,6 +157,12 @@ public bool OpenTargetFolderAfterConversion
}
}

public bool IsReadyForProcessing
{
get => _isReadyForProcessing;
private set => Set(ref _isReadyForProcessing, value);
} // I knwo that it does not make any sense, but Im just too tired

public string WindowTitle { get; set; }


Expand Down Expand Up @@ -243,62 +250,67 @@ public MainWindowViewModel(IConfigProvider configProvider,

private async void ConvertWarehouseData()
{
StockDataXmlSourceDefinition[] sources =
IsReadyForProcessing = false;
try
{
new()
StockDataXmlSourceDefinition[] sources =
{
Url= "https://www.rappa.cz/export/vo.xml",
ItemNodeName = "SHOPITEM",
SkuNodeParsingOptions = new []
new()
{
new ValueParsingOption("EAN", null),
Url = "https://www.rappa.cz/export/vo.xml",
ItemNodeName = "SHOPITEM",
SkuNodeParsingOptions = new[]
{
new ValueParsingOption("EAN", null),
},
StockQuantityNodeParsingOptions = new[]
{
new ValueParsingOption("STOCK", null),
},
},
StockQuantityNodeParsingOptions = new []
new()
{
new ValueParsingOption("STOCK", null),
},
},
new()
Url = "https://en.bushman.eu/content/feeds/uQ5TueFNQh_expando_4.xml",
ItemNodeName = "item",
SkuNodeParsingOptions = new[]
{
new ValueParsingOption("g:gtin", null),
new ValueParsingOption("g:sku_with_ean", @"\d{13}"),
},
StockQuantityNodeParsingOptions = new[]
{
new ValueParsingOption("g:quantity", null),
},
}
};

var stockQuantityUpdater = new StockQuantityUpdater();
var stockData = await stockQuantityUpdater.ConvertWarehouseData(sources);
var columnNamesLine =
"sku\tprice\tminimum-seller-allowed-price\tmaximum-seller-allowed-price\tquantity\thandling-time\tfulfillment-channel";
var lines = new List<string>(stockData.Count() + 1) { columnNamesLine };
string lineTemplate = "{0}\t\t\t\t{1}\t\t";
foreach (var stockInfo in stockData)
{
Url= "https://en.bushman.eu/content/feeds/uQ5TueFNQh_expando_4.xml",
ItemNodeName = "item",
SkuNodeParsingOptions = new []
{
new ValueParsingOption("g:gtin", null),
new ValueParsingOption("g:sku_with_ean", @"\d{13}"),
},
StockQuantityNodeParsingOptions = new []
{
new ValueParsingOption("g:quantity", null),
},
lines.Add(lineTemplate.FormatWith(stockInfo.Sku, stockInfo.Quantity));
}
};

var stockQuantityUpdater = new StockQuantityUpdater();
var stockData = await stockQuantityUpdater.ConvertWarehouseData(sources);
var columnNamesLine =
"sku\tprice\tminimum-seller-allowed-price\tmaximum-seller-allowed-price\tquantity\thandling-time\tfulfillment-channel";
var lines = new List<string>(stockData.Count() + 1) { columnNamesLine };
string lineTemplate = "{0}\t\t\t\t{1}\t\t";
foreach (var stockInfo in stockData)
{
lines.Add(lineTemplate.FormatWith(stockInfo.Sku, stockInfo.Quantity));
}

var saveFileDialog = new SaveFileDialog
{
Title = "Zvol umisteni vystupniho souboru",
FileName = "stockQuantity_" + DateTime.Today.ToString("dd-MM-yyyy") + ".txt",
Filter = "Text files|*.txt"
};
bool? result = saveFileDialog.ShowDialog();
if (result != true) return;

await File.WriteAllLinesAsync(saveFileDialog.FileName, lines);
if (_configProvider.OpenTargetFolderAfterConversion)
{
_fileOperationService.OpenFileFolder(saveFileDialog.FileName);
var saveFileDialog = new SaveFileDialog
{
Title = "Zvol umisteni vystupniho souboru",
FileName = "stockQuantity_" + DateTime.Today.ToString("dd-MM-yyyy") + ".txt",
Filter = "Text files|*.txt"
};
bool? result = saveFileDialog.ShowDialog();
if (result != true) return;

await File.WriteAllLinesAsync(saveFileDialog.FileName, lines);
if (_configProvider.OpenTargetFolderAfterConversion)
{
_fileOperationService.OpenFileFolder(saveFileDialog.FileName);
}
}
finally{ IsReadyForProcessing = true; }
}


Expand Down
13 changes: 12 additions & 1 deletion Mapp.UI/Views/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,18 @@
<RowDefinition />
</Grid.RowDefinitions>
<StackPanel Grid.Row="1">
<Button Content="Natahnout pocty a konvertovat" Width="200" Height="35" Command="{Binding ConvertWarehouseDataCommand}" />
<Button Width="200" IsEnabled="{Binding IsReadyForProcessing}" Height="35" Command="{Binding ConvertWarehouseDataCommand}" >
<Button.Style>
<Style TargetType="Button">
<Setter Property="Content" Value="Natahnout pocty a konvertovat"></Setter>
<Style.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Content" Value="...zpracovuje se..." />
</Trigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
</StackPanel>
</Grid>
</TabItem>
Expand Down

0 comments on commit 57b25c4

Please sign in to comment.