private void PopulateList()
        {
            Dictionary<int, List<int>> rel = new Dictionary<int, List<int>>();

            DBInterface.GetAppliedSales();
            foreach( XmlNode node in DBInterface.Response )
            {
                int couponid = int.Parse( node.Get( "SaleID" ) );
                int itemid = int.Parse( node.Get( "ProductID" ) );

                if( !rel.ContainsKey( couponid ) )
                    rel[couponid] = new List<int>();

                rel[couponid].Add( itemid );
            }

            DBInterface.GetAllSales();
            foreach( XmlNode node in DBInterface.Response )
            {
                int id = int.Parse( node.Get( "SaleID" ) );

                //if the coupon doesn't relate to any items it won't have been added in the previous loop
                if( !rel.ContainsKey( id ) )
                    rel[id] = new List<int>();

                Sale sale = new Sale()
                {
                    ID = id,
                    Name = node.Get( "Name" ),
                    IsFlat = node.Get( "Flat" )[0] == '1',
                    Active = node.Get( "Active" )[0] == '1',
                    Amount = decimal.Parse( node.Get( "Discount" ) ),
                    _ItemIDList = rel[id]
                };
                data.Add( sale );
            }

            LoadItems();
        }
        private void CouponGrid_SelectionChanged( object sender, SelectionChangedEventArgs e )
        {
            try
            {
                Sale sale = (Sale)e.AddedItems[0];
                _sale = sale;

                foreach( var child in CheckBoxSP.Children )
                {
                    CheckBox cb = (CheckBox)child;

                    cb.Checked -= CheckBox_Toggle;
                    cb.Unchecked -= CheckBox_Toggle;

                    cb.IsChecked = sale.AppliesTo( (int)cb.DataContext );

                    cb.Checked += CheckBox_Toggle;
                    cb.Unchecked += CheckBox_Toggle;
                }
            }
            catch { }
        }