コード例 #1
0
        private static Company BuildCompanywithType1(Product p, Type1 t1)
        {
            Company comp = new Company();

            comp.CompanyName   = p.CompanyName;
            comp.CompanyFlavor = new List <Flavor>();
            comp.Type1List     = new List <Type1>()
            {
                t1
            };
            comp.IsFAC = p.FAC;
            return(comp);
        }
コード例 #2
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);
        }
コード例 #3
0
        private static Type1 BuildType1withFlavor(Product p)
        {
            Type1 t1 = new Type1();

            t1.Type1Name = p.Type1;
            if (p.Flavor != string.Empty)
            {
                Flavor f = BuildFlavor(p);
                t1.Type1Flavor = new List <Flavor>()
                {
                    f
                };
            }
            else
            {
                t1.Type1Flavor = new List <Flavor>();
            }
            t1.Type2List = new List <Type2>();
            return(t1);
        }
コード例 #4
0
        private static string OrderFlavorType(List <Flavor> flavors, List <Type1> typeflavor)
        {
            List <string> flavor  = new List <string>();
            string        printer = string.Empty;

            if (flavors.Count > 0)
            {
                foreach (Flavor f in flavors)
                {
                    flavor.Add(f.flavor);
                }
            }

            if (typeflavor.Count > 0)
            {
                foreach (Type1 t in typeflavor)
                {
                    flavor.Add(t.Type1Name);
                }
            }

            flavor.Sort();

            for (int i = 0; i < flavor.Count; i++)
            {
                if (flavors.Exists(o => o.flavor == flavor[i]))
                {
                    if (i == 0)
                    {
                        printer += flavor[i];
                    }
                    else
                    {
                        printer += ", " + flavor[i];
                    }
                }
                else
                {
                    Type1 type1 = typeflavor.Find(o => o.Type1Name == flavor[i]);
                    if (i == 0)
                    {
                        printer += type1.Type1Name;
                        if (type1.Type2List.Count > 0)
                        {
                            if ((type1.Type2List.Count + type1.Type1Flavor.Count) > 1)
                            {
                                printer += " (";
                            }
                            else
                            {
                                printer += " ";
                            }
                            printer += OrderType1Type2(type1.Type1Flavor, type1.Type2List);
                            if ((type1.Type2List.Count + type1.Type1Flavor.Count) > 1)
                            {
                                printer += ")";
                            }
                            else if ((type1.Type2List.Count + type1.Type1Flavor.Count) == 1)
                            {
                                printer += "";
                            }
                            else
                            {
                                printer += " ";
                            }
                        }
                        else
                        {
                            printer += PrintTypes(type1.Type1Name, type1.Type1Flavor);
                        }
                    }
                    else
                    {
                        printer += ", " + type1.Type1Name;
                        if (type1.Type2List.Count > 0)
                        {
                            if ((type1.Type2List.Count + type1.Type1Flavor.Count) > 1)
                            {
                                printer += " (";
                            }
                            else
                            {
                                printer += " ";
                            }
                            printer += OrderType1Type2(type1.Type1Flavor, type1.Type2List);
                            if ((type1.Type2List.Count + type1.Type1Flavor.Count) > 1)
                            {
                                printer += ")";
                            }
                            else if ((type1.Type2List.Count + type1.Type1Flavor.Count) == 1)
                            {
                                printer += "";
                            }
                            else
                            {
                                printer += " ";
                            }
                        }
                        else
                        {
                            printer += PrintTypes(type1.Type1Name, type1.Type1Flavor);
                        }
                    }
                }
            }


            return(printer);
        }
コード例 #5
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);
        }