Пример #1
0
        private static Type1 BuildType1withType2(Product p)
        {
            Type2 t2 = BuildType2(p);

            Type1 t1 = new Type1();

            t1.Type1Flavor = new List <Flavor>();
            t1.Type1Name   = p.Type1;
            t1.Type2List   = new List <Type2>()
            {
                t2
            };
            return(t1);
        }
Пример #2
0
        private static string OrderType1Type2(List <Flavor> Type1Flavor, List <Type2> Type2Flavors)
        {
            List <string> flavor  = new List <string>();
            string        printer = string.Empty;

            foreach (Flavor f in Type1Flavor)
            {
                flavor.Add(f.flavor);
            }
            foreach (Type2 t2 in Type2Flavors)
            {
                flavor.Add(t2.Type2Name);
            }

            flavor.Sort();

            for (int i = 0; i < flavor.Count; i++)
            {
                if (Type1Flavor.Exists(o => o.flavor == flavor[i]))
                {
                    if (i == 0)
                    {
                        printer += flavor[i];
                    }
                    else
                    {
                        printer += ", " + flavor[i];
                    }
                }
                else
                {
                    Type2 t2 = Type2Flavors.Find(o => o.Type2Name == flavor[i]);
                    if (i == 0)
                    {
                        printer += t2.Type2Name;
                        printer += PrintTypes(t2.Type2Name, t2.Type2Flavor);
                    }
                    else
                    {
                        printer += ", " + t2.Type2Name;
                        printer += PrintTypes(t2.Type2Name, t2.Type2Flavor);
                    }
                }
            }

            return(printer);
        }
Пример #3
0
        private static Type2 BuildType2(Product p)
        {
            Type2 t2 = new Type2();

            if (p.Flavor != string.Empty)
            {
                Flavor f = BuildFlavor(p);
                t2.Type2Flavor = new List <Flavor>()
                {
                    f
                };
            }
            else
            {
                t2.Type2Flavor = new List <Flavor>();
            }
            t2.Type2Name = p.Type2;
            return(t2);
        }
Пример #4
0
        private static List <Category> LoadProducts(List <Product> unorderedProducts)
        {
            List <Category> Products = new List <Category>();

            foreach (Product p in unorderedProducts)
            {
                if (!Products.Exists(o => o.CategoryName == p.Category))
                {
                    if (p.Type2 != string.Empty)
                    {
                        Type1    t1   = BuildType1withType2(p);
                        Company  comp = BuildCompanywithType1(p, t1);
                        Category cat  = BuildCategory(p, comp);
                        Products.Add(cat);
                    }
                    else if (p.Type1 != string.Empty)
                    {
                        Type1    t1   = BuildType1withFlavor(p);
                        Company  comp = BuildCompanywithType1(p, t1);
                        Category cat  = BuildCategory(p, comp);
                        Products.Add(cat);
                    }
                    else if (p.CompanyName != string.Empty)
                    {
                        Company  comp = BuildCompanywithFlavor(p);
                        Category cat  = BuildCategory(p, comp);
                        Products.Add(cat);
                    }
                }
                else
                {
                    Category cat = Products.Find(o => o.CategoryName == p.Category);

                    if (!cat.CompanyList.Exists(o => o.CompanyName == p.CompanyName))
                    {
                        if (p.Type2 != string.Empty)
                        {
                            Type1   t1   = BuildType1withType2(p);
                            Company comp = BuildCompanywithType1(p, t1);
                            cat.CompanyList.Add(comp);
                        }
                        else if (p.Type1 != string.Empty)
                        {
                            Type1   t1   = BuildType1withFlavor(p);
                            Company comp = BuildCompanywithType1(p, t1);
                            cat.CompanyList.Add(comp);
                        }
                        else
                        {
                            Company comp = BuildCompanywithFlavor(p);
                            cat.CompanyList.Add(comp);
                        }
                    }
                    else
                    {
                        Company comp = cat.CompanyList.Find(o => o.CompanyName == p.CompanyName);

                        if (p.Type1 != string.Empty)
                        {
                            if (!comp.Type1List.Exists(o => o.Type1Name == p.Type1))
                            {
                                if (p.Type2 != string.Empty)
                                {
                                    Type1 t1 = BuildType1withType2(p);
                                    comp.Type1List.Add(t1);
                                }
                                else
                                {
                                    Type1 t1 = BuildType1withFlavor(p);
                                    comp.Type1List.Add(t1);
                                }
                            }
                            else
                            {
                                Type1 type1 = comp.Type1List.Find(o => o.Type1Name == p.Type1);

                                if (p.Type2 != string.Empty)
                                {
                                    if (!type1.Type2List.Exists(o => o.Type2Name == p.Type2))
                                    {
                                        if (p.Type2 != string.Empty)
                                        {
                                            Type2 t2 = BuildType2(p);
                                            type1.Type2List.Add(t2);
                                        }
                                    }
                                    else
                                    {
                                        Type2 type2 = type1.Type2List.Find(o => o.Type2Name == p.Type2);

                                        Flavor f = BuildFlavor(p);
                                        type2.Type2Flavor.Add(f);
                                    }
                                }
                                else
                                {
                                    Flavor f = BuildFlavor(p);
                                    type1.Type1Flavor.Add(f);
                                }
                            }
                        }
                        else
                        {
                            Flavor f = BuildFlavor(p);
                            comp.CompanyFlavor.Add(f);
                        }
                    }
                }
            }
            return(Products);
        }