public override ValidationResult Validate(object value, CultureInfo cultureInfo) { ExcelManager _manager = new ExcelManager(); List <ExcelB> listB = _manager.LoadCollectionExcelB(); ExcelA entry = (value as BindingGroup).Items[0] as ExcelA; if (string.IsNullOrEmpty(entry.Val1)) { return(new ValidationResult(false, "Value 1 must not be empty!")); } bool contains = false; foreach (var item in listB) { if (item.Val3Main.Equals(entry.Val3)) { contains = true; } } if (contains) { return(ValidationResult.ValidResult); } else { return(new ValidationResult(false, "Value 3 must exist in ExcelB!")); } }
private void InitValuesAndCollections() { // IMPOTANT: The order of these is essential as the last attributes are calling command on set() _manager = new ExcelManager(); AddExcelA = new ExcelA(); AddExcelB = new ExcelB(); MyCollectionA = new ObservableCollection <ExcelA>(); MyCollectionExcelAValue12 = new ObservableCollection <String>(); MyCollectionB = new ObservableCollection <ExcelB>(); MyCollectionC = new ObservableCollection <ExcelC>(); MonthComboboxSource = Constants.Months; SelectedMonth = Constants.getCurrentDateMonth(); }
public List <ExcelA> LoadCollectionExcelA(String month) { try { slDocExcelA = new SLDocument("ExcelA.xlsx"); } catch (System.IO.FileNotFoundException e) { slDocExcelA = new SLDocument(); slDocExcelA.SaveAs("ExcelA.xlsx"); slDocExcelA = new SLDocument("ExcelA.xlsx"); } catch (System.IO.IOException f) { throw f; } _InitWorkSheets(slDocExcelA); slDocExcelA.SelectWorksheet(month); List <ExcelA> tempList = new List <ExcelA>(); for (int i = 2; i < 80; i++) { ExcelA temp = new ExcelA(); temp.Val1 = slDocExcelA.GetCellValueAsString("B" + i.ToString()); temp.Val2 = slDocExcelA.GetCellValueAsString("C" + i.ToString()); temp.Val3 = slDocExcelA.GetCellValueAsString("D" + i.ToString()); temp.Val4 = slDocExcelA.GetCellValueAsString("E" + i.ToString()); if (string.IsNullOrEmpty(temp.Val1)) // Check for ID is not empty { break; } else { tempList.Add(temp); } } return(tempList); }
// CRUD-Commands private void AddEntryExcelA() { MyCollectionA.Add(AddExcelA); OnBItemChangedReloadGrid(MyActiveItemB); AddExcelA = new ExcelA(); }