public Product CallAddProductPopup(string productScanCode, string notificationMsg, WarehouseContext dbcontext)
        {
            var window = new NotifyWindow();

            window.Width  = 400;
            window.Height = 600;
            window.Title  = "录入产品信息";

            Product newp = null;

            window.MyContent = CallAddProductControl(productScanCode, dbcontext, (p) =>
            {
                window.Close();
                newp = p;
            });

            if (!string.IsNullOrEmpty(notificationMsg))
            {
                window.ShowNotificationMessage(notificationMsg);
            }

            // block until dialog close
            window.ShowDialog();
            return(newp);
        }
        public Goods CallRegisterGoodsPopup(Product product, WarehouseContext dbcontext)
        {
            Goods newGoods = null;
            var   window   = new NotifyWindow();

            window.Width  = 400;
            window.Height = 600;
            window.Title  = "添加货物";

            var formControl = FormControlHelper.CreateFormControl();
            var goods       = new Goods();

            goods.Product   = product;
            goods.Name      = product.Name;
            goods.State     = GoodsState.Inbound;
            goods.GoodsCode = DateTime.Now.ToString("yyyyMMddHHmmss") + "001";

            formControl.CreateControlCallback = (cx, ctl) =>
            {
                if (cx.ControlType == ControlType.Editable)
                {
                    switch (cx.PropertyInfo.Name)
                    {
                    case "Product":
                        var tb = new TextBox();
                        tb.Text      = product.Name;
                        tb.Style     = Application.Current.Resources["editctl_TextBox"] as Style;
                        tb.IsEnabled = false;
                        CustomValidation.SetValidationOptOut(tb);
                        return(tb);

                    case "GoodsCode":
                        ctl.IsEnabled = false;
                        return(ctl);
                    }
                }
                return(ctl);
            };

            formControl.RenderForm(goods, false);
            formControl.ConfirmButton.Content = "添加";
            formControl.SubmitCallback        = d =>
            {
                try
                {
                    newGoods             = d as Goods;
                    newGoods.InboundDate = DateTime.Now;
                    dbcontext.Goods.Add(newGoods);
                    window.Close();
                }
                catch (Exception ex)
                {
                    window.ShowNotificationMessage("添加货物失败,请重试。");
                }
            };
            window.MyContent = formControl;
            window.ShowDialog();
            return(newGoods);
        }