private DataTable FindProductNotInReceivedFile(Config config, DataTable dataTable) { using (var sdService = new SuppDistService(config.TargetConnectionString)) { DataTable sc_products = sdService.GetAllSupplierProducts(config.FileName); var rowsOnlyInDt1 = sc_products.AsEnumerable().Where(r2 => !dataTable.AsEnumerable() .Any(r => r[1].ToString().Trim().ToLower() == r2["supplier_code"].ToString().Trim().ToLower() && r[1].ToString().Trim().ToLower() == r2["supplier_code"].ToString().Trim().ToLower())); DataTable result = new DataTable(); if (rowsOnlyInDt1.Count() > 0) { result = rowsOnlyInDt1.CopyToDataTable();//The third table } return(result); } }
private ImportDataException ValidateUniqueDistributorCode(MappingTable mappingTable, DataRow row) { if (mappingTable.TableName.ToUpperInvariant() != "INGREDIENT") { return(null); } int?distributorNameOrdinal = mappingTable.ColumnOrdinalOf("distributor_id"); int?distributorCodeOrdinal = mappingTable.ColumnOrdinalOf("distributor_code"); if (distributorNameOrdinal == null || distributorCodeOrdinal == null) { return(null); } string importDistName = row[Convert.ToInt32(distributorNameOrdinal)].ToString().Trim(); string importDistCode = row[Convert.ToInt32(distributorCodeOrdinal)].ToString().Trim(); if (string.IsNullOrEmpty(importDistName) || string.IsNullOrEmpty(importDistCode)) { return(null); } using (var sdService = new SuppDistService(_config.TargetConnectionString)) { if (sdService.DistributorCodeUsedForProduct(importDistName, importDistCode)) { string columnName = mappingTable.ColumnNameOf("distributor_code"); string mappingName = mappingTable.MappingNameOf("distributor_code"); return(new ImportDataException { ExceptionType = ExceptionType.DuplicateDistributorCode, TemplateColumnName = columnName, IsValid = false, TemplateMappingColumn = mappingName }); } } return(null); }