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

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

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

                rel[couponid].Add( itemid );
            }

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

                //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>();

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

            LoadItems();
        }
        private void CouponGrid_SelectionChanged( object sender, SelectionChangedEventArgs e )
        {
            try
            {
                Coupon coupon = (Coupon)e.AddedItems[0];
                _coupon = coupon;

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

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

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

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