Beispiel #1
0
        private void MakeList(object sender, EventArgs e)
        {
            // build the filters
            string[] rgsLocations     = null;
            string[] rgsColors        = null;
            bool     fGroupByVarietal = m_fVarietalGrouping.Checked;

            rgsLocations = BuildStringArrayFromCheckedListbox(m_lbxLocation);
            rgsColors    = BuildStringArrayFromCheckedListbox(m_lbxColor);

            WineList list = WineList.BuildFromCellar(m_cellar, rgsLocations, rgsColors, fGroupByVarietal);

            list.CreateFile(m_ebOutFile.Text, fGroupByVarietal, rgsColors == null || rgsColors.Length == 1);
        }
Beispiel #2
0
        public static WineList BuildFromCellar(Cellar cellar, string[] rgsLocations, string[] rgsColor, bool fGroupByVarietal)
        {
            WineList list = new WineList();
            Dictionary <string, int> bottlesSeen = new Dictionary <string, int>();
            StringBuilder            sbListName  = new StringBuilder();

            foreach (string sLocation in rgsLocations)
            {
                sbListName.Append($"_{sLocation}");
            }

            foreach (string sColor in rgsColor)
            {
                sbListName.Append($"_{sColor}");
            }

            if (fGroupByVarietal)
            {
                sbListName.Append("_Varietal");
            }

            list.ListName    = sbListName.ToString();
            list.BottleCount = 0;

            // collect the number of bottles seen
            foreach (Bottle bottle in cellar.Bottles)
            {
                if (bottle.Bin == "BINLESS")
                {
                    continue;
                }

                if (rgsLocations != null)
                {
                    bool fMatchLocation = false;

                    foreach (string sLocation in rgsLocations)
                    {
                        if (string.Compare(bottle.Location, sLocation, true) == 0)
                        {
                            fMatchLocation = true;
                            break;
                        }
                    }

                    if (!fMatchLocation)
                    {
                        continue;
                    }
                }

                list.BottleCount++;
                if (bottlesSeen.ContainsKey(bottle.Wine))
                {
                    bottlesSeen[bottle.Wine]++;
                }
                else
                {
                    bottlesSeen.Add(bottle.Wine, 1);
                }
            }

            foreach (Bottle bottle in cellar.Bottles)
            {
                if (bottle.Bin == "BINLESS")
                {
                    continue;
                }

                if (rgsLocations != null)
                {
                    bool fMatchLocation = false;

                    foreach (string sLocation in rgsLocations)
                    {
                        if (string.Compare(bottle.Location, sLocation, true) == 0)
                        {
                            fMatchLocation = true;
                            break;
                        }
                    }

                    if (!fMatchLocation)
                    {
                        continue;
                    }
                }

                if (rgsColor != null)
                {
                    bool fMatchColor = false;

                    foreach (string sColor in rgsColor)
                    {
                        if (string.Compare(bottle.Color, sColor, true) == 0)
                        {
                            fMatchColor = true;
                            break;
                        }
                    }

                    if (!fMatchColor)
                    {
                        continue;
                    }
                }

                if (bottlesSeen[bottle.Wine] == 0)
                {
                    continue; // we already added this bottle to the list
                }
                Bottle bottleNew = new Bottle(bottle)
                {
                    Count = bottlesSeen[bottle.Wine]
                };

                bottlesSeen[bottle.Wine] = 0;   // we've added it to the list, so don't add again...

                list.m_bottles.Add(bottleNew);
            }

            if (fGroupByVarietal)
            {
                list.m_bottles.Sort(Bottle.SortByVarietal);
            }
            else
            {
                list.m_bottles.Sort(Bottle.SortByColor);
            }

            return(list);
        }