This discussion is archived
5 Replies Latest reply: Nov 19, 2012 8:58 AM by Segal RSS

Compliance Update Problem

962847 Newbie
Currently Being Moderated
Hi,

I have a custom class to modify the items on the Complies With, Allergens, Additives and Intolerances. When I run the custom class it fills Allergens, Additives and Intolerances but it leaves the Complies With blank. If I debug the code it shows that the Complies With has items at the end of the code but then they are not shown. What could be causing them not to be displayed?

Thank you!
  • 1. Re: Compliance Update Problem
    Ron M Pro
    Currently Being Moderated
    Hi.
    Please include you code so that we can review it. Also, when and from where are you calling this class?
  • 2. Re: Compliance Update Problem
    Matt J Journeyer
    Currently Being Moderated
    a couple of notes:
    1. attachments are not allowed on the external forum. however, you can include code in the body of the message by using the { code } tag (without the spaces) at the beginning and end of your code snippet.
    2. as this is an open forum, if you are uncomfortable providing your code here, please open an SR with support and reference this forum post. they will then send it to us for review.
    3. for anyone else viewing this thread, a request to review code will be handled on a case by case basis and should always start in the forum
  • 3. Re: Compliance Update Problem
    962847 Newbie
    Currently Being Moderated
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Xeno.Data;
    using Xeno.Data.Foodservice;
    using Xeno.Data.Common;
    using System.IO;
    
    namespace ProductSpecRollup
    {
        public class ComplianceRollup
        {
            public static bool PerformRollup(IFoodServiceProductDO productSpec)
            {
    
                List<ICompliesWith> compliesWith = new List<ICompliesWith>();
                List<ICompliesWith> negComplies = new List<ICompliesWith>();
                List<ICompliesWith> temp = new List<ICompliesWith>();
                List<IAllergenContainedDO> allergenCont = new List<IAllergenContainedDO>();
                List<IAllergenPossiblyContainedDO> allergenMayCont = new List<IAllergenPossiblyContainedDO>();
                List<IAdditiveContainedDO> additiveCont = new List<IAdditiveContainedDO>();
                List<IAdditivePossiblyContainedDO> additiveMayCont = new List<IAdditivePossiblyContainedDO>();
                List<IIntoleranceContainedDO> sensitCont = new List<IIntoleranceContainedDO>();
                List<IIntolerancePossiblyContainedDO> sensitMayCont = new List<IIntolerancePossiblyContainedDO>();
                ArrayList errormsgs = new ArrayList();
                bool firstTime = true;
                bool rollupSuccess = true;
    
                try
                {
    
                    foreach (IFoodServiceGlobalRegionalStandardDO linked in productSpec.AlternateGlobalStandards.Values)
                    {
                        IFoodServiceProductDO supplierFile = (IFoodServiceProductDO)linked.Alternate;
                        bool hasinfo = false; // variable to check if the spec has compliances
    
                        //go through all the classifications of the supplier files, they can only have the Supplier File Classification
                        foreach (IClassificationAttributes classattrib in supplierFile.ProductAttributes.Classifications.Values)
                        {
                            if (classattrib.Name.Equals("Supplier File"))
                            {
                                getCompliance(supplierFile, ref compliesWith, ref hasinfo, ref temp);
                                getAllergens(supplierFile, ref allergenCont, ref allergenMayCont, ref hasinfo);
                                getAdditives(supplierFile, ref additiveCont, ref additiveMayCont, ref hasinfo);
                                getSensitivities(supplierFile, ref sensitCont, ref sensitMayCont, ref hasinfo);
                                checkMayContAllergen(ref allergenCont, ref allergenMayCont);
                                checkMayContAdditive(ref additiveCont, ref additiveMayCont);
                                checkMayContSensit(ref sensitCont, ref sensitMayCont);
    
                                if (firstTime)
                                {
                                    negComplies = temp;
                                }
                                else
                                {
                                    foreach (ICompliesWith compare in temp)
                                    {
                                        bool has = false;
                                        if (negComplies.Contains(compare))
                                            has = true;
    
                                        if (!has)
                                            negComplies.Remove(compare);
                                    }
                                }
    
                                temp.Clear();
                            }
                        }
    
                        firstTime = false;
    
                        if (!hasinfo)
                            errormsgs.Add("Caution: Compliance information for " + supplierFile.SpecSummary.FreeTextName.Name + " has not been entered");
                    }
    
                    foreach (ICompliesWith item in negComplies)
                    {
                        if (!productSpec.CompliesWith.Contains(item))
                            productSpec.CompliesWith.Add(item);
                    }
    
                    //get all the compliance in the product spec
    
                    foreach (ICompliesWith item in compliesWith)
                    {
                        if (!productSpec.CompliesWith.Contains(item))
                            productSpec.CompliesWith.Add(item);
                    }
    
    
                    foreach (IAdditiveContainedDO item in additiveCont)
                    {
                        if (!productSpec.AdditivesContained.Contains(item))
                            productSpec.AdditivesContained.Add(item);
                    }
    
                    foreach (IAdditivePossiblyContainedDO item in additiveMayCont)
                    {
                        if (!productSpec.AdditivesPossiblyContained.Contains(item))
                            productSpec.AdditivesPossiblyContained.Add(item);
                    }
    
                    foreach (IAllergenContainedDO item in allergenCont)
                    {
                        if (!productSpec.AllergensContained.Contains(item))
                            productSpec.AllergensContained.Add(item);
                    }
    
                    foreach (IAllergenPossiblyContainedDO item in allergenMayCont)
                    {
                        if (!productSpec.AllergensPossiblyContained.Contains(item))
                            productSpec.AllergensPossiblyContained.Add(item);
                    }
    
                    foreach (IIntoleranceContainedDO item in sensitCont)
                    {
                        if (!productSpec.IntolerancesContained.Contains(item))
                            productSpec.IntolerancesContained.Add(item);
                    }
    
                    foreach (IIntolerancePossiblyContainedDO item in sensitMayCont)
                    {
                        if (!productSpec.IntolerancesPossiblyContained.Contains(item))
                            productSpec.IntolerancesPossiblyContained.Add(item);
                    }
    
                }
                catch (Exception ex)
                {
                    // TODO:  Log error/stack trace to Windows Event Log
                    rollupSuccess = false;
                }
                return rollupSuccess;
            }
    
            private static void getCompliance(IFoodServiceProductDO supplierSpec, ref List<ICompliesWith> compliesWith, ref bool hasinfo, ref List<ICompliesWith> temp)
            {
    
                //go through all the complies with of the supplier files
    
                foreach (IXDataObject item in supplierSpec.CompliesWith.Values)
                {
                    bool exists = false;
                    hasinfo = true;
                    ICompliesWith checkItem = (ICompliesWith)item.Clone();
    
                    //check if the item already exists on the list
    
                    if (compliesWith.Contains(checkItem))
                        exists = true;
    
                    //if the item does not exists it is added to the arraylist
                    if (!exists && !checkItem.IsNegative)
                        compliesWith.Add(checkItem);
                    else if (checkItem.IsNegative)
                        temp.Add(checkItem);
    
                }
            }
    
            private static void getAllergens(IFoodServiceProductDO supplierSpec,
                ref List<IAllergenContainedDO> allergenCont, ref List<IAllergenPossiblyContainedDO> allergenMayCont, ref bool hasinfo)
            {
                bool exists = false;
    
                foreach (IXDataObject item in supplierSpec.AllergensContained.Values)
                {
                    hasinfo = true;
                    for (int i = 0; i < allergenCont.Count; i++)
                    {
                        if (allergenCont.Allergen.Name.Equals(((IAllergenContainedDO)item).Allergen.Name)) exists = true;
    }
    if (!exists) allergenCont.Add((IAllergenContainedDO)item.Clone());
    exists = false;
    }
    //go through all the allergens contained
    exists = false;
    foreach (IXDataObject item in supplierSpec.AllergensPossiblyContained.Values)
    {
    hasinfo = true;
    for (int i = 0; i < allergenMayCont.Count; i++)
    {
    if (allergenMayCont[i].Allergen.Name.Equals(((IAllergenPossiblyContainedDO)item).Allergen.Name)) exists = true;
    }
    if (!exists) allergenMayCont.Add((IAllergenPossiblyContainedDO)item.Clone());
    exists = false;
    }
    }

    private static void getAdditives(IFoodServiceProductDO supplierSpec,
    ref List<IAdditiveContainedDO> additiveCont, ref List<IAdditivePossiblyContainedDO> additiveMayCont, ref bool hasinfo)
    {
    bool exists = false;
    //go through all the additives contained
    foreach (IXDataObject item in supplierSpec.AdditivesContained.Values)
    {
    hasinfo = true;
    for (int i = 0; i < additiveCont.Count; i++)
    {
    if (additiveCont[i].Additive.Name.Equals(((IAdditiveContainedDO)item).Additive.Name)) exists = true;
    }
    if (!exists) additiveCont.Add((IAdditiveContainedDO)item.Clone());
    exists = false;
    }

    //go through all the additives possibly contained
    exists = false;
    foreach (IXDataObject item in supplierSpec.AdditivesPossiblyContained.Values)
    {
    hasinfo = true;
    for (int i = 0; i < additiveMayCont.Count; i++)
    {
    if (additiveMayCont[i].Additive.Name.Equals(((IAdditivePossiblyContainedDO)item).Additive.Name)) exists = true;
    }
    if (!exists) additiveMayCont.Add((IAdditivePossiblyContainedDO)item.Clone());
    exists = false;
    }
    }

    private static void getSensitivities(IFoodServiceProductDO supplierSpec, ref List<IIntoleranceContainedDO> sensitCont, ref List<IIntolerancePossiblyContainedDO> sensitMayCont, ref bool hasinfo)
    {
    bool exists = false;
    //go through all the additives contained
    foreach (IXDataObject item in supplierSpec.IntolerancesContained.Values)
    {
    hasinfo = true;
    for (int i = 0; i < sensitCont.Count; i++)
    {
    if (sensitCont[i].Intolerance.Name.Equals(((IIntoleranceContainedDO)item).Intolerance.Name)) exists = true;
    }
    if (!exists) sensitCont.Add((IIntoleranceContainedDO)item.Clone());
    exists = false;
    }

    //go through all the additives possibly contained
    exists = false;
    foreach (IXDataObject item in supplierSpec.IntolerancesPossiblyContained.Values)
    {
    hasinfo = true;
    for (int i = 0; i < sensitMayCont.Count; i++)
    {
    if (sensitMayCont[i].Intolerance.Name.Equals(((IIntolerancePossiblyContainedDO)item).Intolerance.Name)) exists = true;
    }
    if (!exists) sensitMayCont.Add((IIntolerancePossiblyContainedDO)item.Clone());
    exists = false;
    }
    }

    //method to check if an allergen, additive or sensitivity on the may contain is on the known to contain

    private static void checkMayContAllergen(ref List<IAllergenContainedDO> cont, ref List<IAllergenPossiblyContainedDO> mayCont)
    {
    for (int i = 0; i < mayCont.Count; i++)
    {
    for (int j = 0; j < cont.Count; j++)
    {
    if (cont[j].Allergen.Name.Equals(mayCont[i].Allergen.Name))
    mayCont.RemoveAt(i);
    }
    }
    }

    private static void checkMayContAdditive(ref List<IAdditiveContainedDO> cont, ref List<IAdditivePossiblyContainedDO> mayCont)
    {
    for (int i = 0; i < mayCont.Count; i++)
    {
    for (int j = 0; j < cont.Count; j++)
    {
    if (cont[j].Additive.Name.Equals(mayCont[i].Additive.Name))
    mayCont.RemoveAt(i);
    }
    }
    }

    private static void checkMayContSensit(ref List<IIntoleranceContainedDO> cont, ref List<IIntolerancePossiblyContainedDO> mayCont)
    {
    for (int i = 0; i < mayCont.Count; i++)
    {
    for (int j = 0; j < cont.Count; j++)
    {
    if (cont[j].Intolerance.Name.Equals(mayCont[i].Intolerance.Name))
    mayCont.RemoveAt(i);
    }
    }
    }
    }
    }
    This is my code... I'm calling it from another class :
    public partial class _Default : XManagedSpecBaseForm //System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {
    String rollupType = Request.QueryString["rollupType"];



    if (SpecificationService.Current.PKID.Substring(0, 4).Equals("6501"))
    {
    IFoodServiceProductDO productSpec = (IFoodServiceProductDO)SpecificationService.Current;
    if (String.Compare(rollupType, "compliance", true) == 0)
    {
    if (ComplianceRollup.PerformRollup(productSpec))
    {
    lblResult.Text = "Success";
    lblResult.Text = productSpec.CompliesWith.Count.ToString();
    }
    else lblResult.Text = "Failure";
    }
    }
    } }
    This code is called from an .aspx (in which the product spec is reloaded at the end) which is called from an action button.
    
    Thank you!                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
  • 4. Re: Compliance Update Problem
    Ron M Pro
    Currently Being Moderated
    Sorry it has taken so long to reply.
    Can you describe what the purpose of the following line is:
                                temp.Clear();
    When you assign negComplies = temp
    if (firstTime)
    {
        negComplies = temp;
    }
    and then clear temp, doesn't negComplies get cleared too?
  • 5. Re: Compliance Update Problem
    Segal Explorer
    Currently Being Moderated
    Marked assumed answer because lack of response.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points