private void OnImportFromExcel() { var dictionaryRes = StaticContainer.Container.Resolve <IExcelImporter>().ImportFromExcel(worksheet => { if (string.IsNullOrWhiteSpace(worksheet.GetCellValue(1, 3).Item)) { return; } try { var dictionary = new Dictionary <ushort, string>(); int counter = 2; while (worksheet.GetCellValue(counter, 1).Item != null && !string.IsNullOrWhiteSpace(worksheet.GetCellValue(counter, 1).Item.ToString())) { dictionary[ushort.Parse(worksheet.GetCellValue(counter, 2).Item.ToString())] = worksheet.GetCellValue(counter, 3).Item.ToString(); counter++; } KeyValuesDictionary.Clear(); foreach (KeyValuePair <ushort, string> kvp in dictionary) { KeyValuesDictionary.Add(new BindableKeyValuePair <ushort, string>(kvp.Key, kvp.Value)); } } catch { MessageBox.Show(StaticContainer.Container.Resolve <ILocalizerService>().GetLocalizedString( ApplicationGlobalNames.StatusMessages .FORMAT_ERROR), "Excel"); } }); }
private void AddNewKeyPair() { if (KeyValuesDictionary.Count == 0) { KeyValuesDictionary.Add(new BindableKeyValuePair <ushort, string>()); return; } ushort maxKey = KeyValuesDictionary.Select(pair => pair.Key).Max(); BindableKeyValuePair <ushort, string> keyPair = new BindableKeyValuePair <ushort, string> { Key = (ushort)(maxKey + 1), Value = string.Empty }; KeyValuesDictionary.Add(keyPair); }