private void ApplySkuLinkFilters(bool queryDatabase) { //Cannot use LinkedFrom and LinkedTo //Using Sku and Sku1 (repectively) instead var waitkey = FrmWaitScreen.ShowMessage("Applying Filter"); dgvSkuLinks.DataSource = null; dgvSkuLinks.Invalidate(); _filteredSkuLinks = null; lblLeftTaxonomy.Text = @"No Filter Applied"; lblRightTaxonomy.Text = @"No Filter Applied"; if ((LeftTaxonomyFilters == null || LeftTaxonomyFilters.Count == 0) && (RightTaxonomyFilters == null || RightTaxonomyFilters.Count == 0)) { FrmWaitScreen.HideMessage(waitkey); return; } var skuLinks = AryaTools.Instance.InstanceData.Dc.SkuLinks.Where(sl => sl.Active); if (LeftTaxonomyFilters != null && LeftTaxonomyFilters.Count > 0) { lblLeftTaxonomy.Text = LeftTaxonomyFilters.Count == 1 ? string.Format("Taxonomy is [{0}]", LeftTaxonomyFilters[0]) : string.Format( "Taxonomy is one of the {0} selected nodes", LeftTaxonomyFilters.Count); List <Guid> taxIds = LeftTaxonomyFilters.Select(tf => tf.ID).ToList(); if (LeftIncludeChildren) { LeftTaxonomyFilters.ForEach(tax => taxIds.AddRange(tax.AllChildren.Select(t => t.ID))); lblLeftTaxonomy.Text += @" and its child nodes"; } skuLinks = from sl in skuLinks //let tax = sl.LinkedFrom.Taxonomy.ID let tax = sl.Sku.SkuInfos.Where(si => si.Active).Select(si => si.TaxonomyID).FirstOrDefault() where taxIds.Contains(tax) select sl; } if (RightTaxonomyFilters != null && RightTaxonomyFilters.Count > 0) { lblRightTaxonomy.Text = RightTaxonomyFilters.Count == 1 ? string.Format("Taxonomy is [{0}]", RightTaxonomyFilters[0]) : string.Format( "Taxonomy is one of the {0} selected nodes", RightTaxonomyFilters.Count); List <Guid> taxIds = RightTaxonomyFilters.Select(tf => tf.ID).ToList(); if (RightIncludeChildren) { RightTaxonomyFilters.ForEach(tax => taxIds.AddRange(tax.AllChildren.Select(t => t.ID))); lblRightTaxonomy.Text += @" and its child nodes"; } skuLinks = from sl in skuLinks //let tax = sl.LinkedTo.Taxonomy.ID let tax = sl.Sku1.SkuInfos.Where(si => si.Active).Select(si => si.TaxonomyID).FirstOrDefault() where taxIds.Contains(tax) select sl; } if (!string.IsNullOrEmpty(txtFilterSkuLinkType.Text)) { skuLinks = from sl in skuLinks where sl.LinkType.Equals(txtFilterSkuLinkType.Text) select sl; } if (queryDatabase) { _filteredSkuLinks = (from sl in skuLinks select new FilteredSkuLink { LeftSku = sl.Sku, LeftTaxonomy = sl.Sku.Taxonomy, RightSku = sl.Sku1, RightTaxonomy = sl.Sku1.Taxonomy }).ToList(); dgvSkuLinks.DataSource = _filteredSkuLinks; dgvSkuLinks.Invalidate(); } FrmWaitScreen.HideMessage(waitkey); }
private void ValidateMatchedLinks() { var globalAttributesInSkuGapFile = new[] { "AS400Description", "Detail Description", "Brand Name", "Manufacturer's Part Number" }; if (_filteredSkuLinks == null) { _currentStatus = "Nothing to validate\nPlease Apply your Filter first."; return; } _currentStatus = "Validating Links"; var accuracies = new List <string>(_filteredSkuLinks.Count); for (int i = 0; i < _filteredSkuLinks.Count; i++) { var link = _filteredSkuLinks[i]; string accuracy, reasonCode, reasonDetail, brandReasonDetail; DoMatch(link, out accuracy, out reasonCode, out reasonDetail, out brandReasonDetail); UpdateLinkStatus(link, accuracy, reasonCode, reasonDetail, brandReasonDetail); accuracies.Add(accuracy); _currentStatus = string.Format("Validating Links ({0} of {1})", i + 1, _filteredSkuLinks.Count); } using (TextWriter skuGapsFile = new StreamWriter(skuGapsFileName, false)) { string line = globalAttributesInSkuGapFile.Aggregate( "Item Id", (result, current) => string.Format("{0}\t{1}\t", result, current)); skuGapsFile.WriteLine(line); //fetch the skuGaps from only SkuNode. foreach (var g in _skuGaps.Where(p => p.Key.Taxonomy.ToString().Contains(">SKUs>"))) { var gap = g; line = globalAttributesInSkuGapFile.Aggregate( gap.Key.ItemID, (result, current) => { var values = gap.Key.GetValuesForAttribute(current, true); var firstValue = values.Count > 0 ? values.First().Value : string.Empty; return(string.Format("{0}\t{1}\t", result, firstValue)); }); line = gap.Value.Aggregate(line, (result, current) => string.Format("{0}\t{1}\t", result, current)); skuGapsFile.WriteLine(line); } } AryaTools.Instance.SaveChangesIfNecessary(true, false); List <Guid> taxIds = LeftTaxonomyFilters.Select(tf => tf.ID).ToList(); if (LeftIncludeChildren) { LeftTaxonomyFilters.ForEach(tax => taxIds.AddRange(tax.AllChildren.Select(t => t.ID))); } var allSkus = AryaTools.Instance.InstanceData.Dc.TaxonomyInfos.Where(ti => taxIds.Contains(ti.ID)).SelectMany(left => left.SkuInfos.Where(si => si.Active).Select(si => si.Sku)).Distinct().ToList(); //var allSkus = // LeftTaxonomyFilters.SelectMany(left => left.SkuInfos.Where(si => si.Active).Select(si => si.Sku)).Distinct().ToList(); _currentStatus = "Updating Accuracy,ReasonCode & Detail for Skus with NoImage or ImageID:NOIMAGE-11,TotalSkus = " + allSkus.Count; foreach (var sku in from sku in allSkus let values = sku.GetValuesForAttribute("Image") let imageValue = values.Count == 0 ? null : values.Distinct().First().Value where string.IsNullOrEmpty(imageValue) || imageValue == "NOIMAGE-11" || imageValue == "N/A" select sku) { sku.UpsertValue(txtResultPrefix.Text + "Accurate?", "No"); //sku.UpsertValue(txtResultPrefix.Text + "Reason Code", "Does not fit Image Guidelines"); sku.UpsertValue(txtResultPrefix.Text + "Reason Detail", string.Empty); sku.UpsertValue(txtResultPrefix.Text + "Reason Code", "No Image"); sku.UpsertValue(txtResultPrefix.Text + "Status", "Completed"); } _currentStatus = "Finished Updating."; AryaTools.Instance.SaveChangesIfNecessary(false, false); //Summary var summary = accuracies.GroupBy(v => v).Select(grp => new { Accuracy = grp.Key, Count = grp.Count() }); _currentStatus = summary.Aggregate( "Summary:", (current, detail) => current + "|" + detail.Accuracy + ": " + detail.Count); }