private static void OnProductSelectedChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
        {
            UProductFinalDiscountSelection control = obj as UProductFinalDiscountSelection;
            MPackageFinalDiscount          d       = (MPackageFinalDiscount)e.NewValue;

            updateGui(control, d);
        }
        private void lkupItem_SelectedObjectChanged(object sender, EventArgs e)
        {
            UProductFinalDiscountSelection control = this;

            if (control.OnChanged != null)
            {
                control.OnChanged(control, null);
            }

            if (lkupItem != null)
            {
                lblUnit.Content = "";

                if (lkupItem.Lookup == LookupSearchType2.ServiceLookup)
                {
                    MService sv = (MService)lkupItem.SelectedObject;
                    if (sv != null)
                    {
                        lblUnit.Content = sv.ServiceUOMName;
                    }
                }
                else if (lkupItem.Lookup == LookupSearchType2.InventoryItemLookup)
                {
                    MInventoryItem sv = (MInventoryItem)lkupItem.SelectedObject;
                    if (sv != null)
                    {
                        lblUnit.Content = sv.ItemUOMName;
                    }
                }

                updateObject();
            }
        }
        private void txtQuantity_TextChanged(object sender, TextChangedEventArgs e)
        {
            UProductFinalDiscountSelection control = this;

            if (control.OnChanged != null)
            {
                control.OnChanged(control, null);
            }

            updateObject();
        }
        private static void updateGui(UProductFinalDiscountSelection control, MPackageFinalDiscount v)
        {
            if (v == null)
            {
                return;
            }

            MPackageFinalDiscount o = new MPackageFinalDiscount(v.GetDbObject().Clone());

            control.cbxEnable.IsChecked = o.EnabledFlag.Equals("Y");
            int selectionType = CUtil.StringToInt(o.SelectionType);

            control.cboSelectionType.SelectedIndex = selectionType - 1;

            MMasterRef mr = CUtil.MasterIDToObject(CMasterReference.Instance.ProductSpecificSelectionTypes, o.SelectionType);

            if (mr != null)
            {
                //control.cboSelectionType.SelectedItem = mr;

                if (mr.MasterID.Equals("1"))
                {
                    control.lkupItem.Lookup         = LookupSearchType2.ServiceLookup;
                    control.lkupItem.SelectedObject = o.ServiceObj;
                }
                else if (mr.MasterID.Equals("2"))
                {
                    control.lkupItem.Lookup         = LookupSearchType2.InventoryItemLookup;
                    control.lkupItem.SelectedObject = o.ItemObj;
                }
                else
                {
                    control.lkupItem.Lookup         = LookupSearchType2.ServiceLookup;
                    control.lkupItem.SelectedObject = o.ServiceObj;
                }
            }

            control.txtQuantity.Text = o.Quantity;

            v.ExtFlag = "I";
            if (v.PackageFinalDiscountID.Equals(""))
            {
                v.ExtFlag = "A";
            }
        }
        private void cbxEnable_Unchecked(object sender, RoutedEventArgs e)
        {
            UProductFinalDiscountSelection control = this;

            if (control.OnChanged != null)
            {
                control.OnChanged(control, null);
            }

            MPackageFinalDiscount v = (MPackageFinalDiscount)ProductSelected;

            if (v == null)
            {
                return;
            }

            v.EnabledFlag = "N";
        }
        private void cboSelectionType_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            UProductFinalDiscountSelection control = this;

            if (control.OnChanged != null)
            {
                control.OnChanged(control, null);
            }

            ComboBox cbo = sender as ComboBox;

            if (lkupItem != null)
            {
                lkupItem.Lookup         = LookupSearchType2.ServiceLookup;
                lkupItem.SelectedObject = null;
            }

            MMasterRef mr = (MMasterRef)cbo.SelectedItem;

            if (mr == null)
            {
                return;
            }

            if (mr.MasterID.Equals("1"))
            {
                lkupItem.Lookup = LookupSearchType2.ServiceLookup;
            }
            else if (mr.MasterID.Equals("2"))
            {
                lkupItem.Lookup = LookupSearchType2.InventoryItemLookup;
            }

            lkupItem.SelectedObject = null;
            updateObject();
        }