/// <summary>
        /// 链接到PO
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnPO_Click(object sender, RoutedEventArgs e)
        {
            GiftCardFabricationVM item = (sender as HyperlinkButton).DataContext as GiftCardFabricationVM;

            if (!string.IsNullOrEmpty(item.POSysNo))
            {
                Window.Navigate(string.Format(ConstValue.PO_PurchaseOrderMaintain, item.POSysNo), null, true);
            }
        }
        /// <summary>
        /// 编辑
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void hlEdit_Click(object sender, RoutedEventArgs e)
        {
            UCGiftCardFabricationMaintain ucMaintain = new UCGiftCardFabricationMaintain();
            GiftCardFabricationVM         item       = (sender as HyperlinkButton).DataContext as GiftCardFabricationVM;

            ucMaintain.VM = item;

            //this.Window.ShowDialog("编辑礼品卡制作单", ucMaintain);
            ucMaintain.Dialog = Window.ShowDialog(ResGiftCardInfo.Title_EditGiftCard, ucMaintain, (obj, args) =>
            {
                filter   = model.ConvertVM <GiftCardFabricationVM, ECCentral.QueryFilter.IM.GiftCardFabricationFilter>();
                filterVM = Newegg.Oversea.Silverlight.Utilities.UtilityHelper.DeepClone <ECCentral.QueryFilter.IM.GiftCardFabricationFilter>(filter);
                DataGrid.QueryCriteria = this.filter;
                DataGrid.Bind();
            });
        }
        public override void OnPageLoad(object sender, EventArgs e)
        {
            facade            = new GiftCardFacade(this);
            filter            = new ECCentral.QueryFilter.IM.GiftCardFabricationFilter();
            model             = new GiftCardFabricationVM();
            model.CompanyCode = Newegg.Oversea.Silverlight.ControlPanel.Core.CPApplication.Current.CompanyCode;
            model.ChannelID   = "1";

            CodeNamePairHelper.GetList("IM", "GiftCardFabricationStatus", CodeNamePairAppendItemType.All, (obj, args) =>
            {
                if (args.FaultsHandle())
                {
                    return;
                }
                comStatus.ItemsSource = args.Result;
            });
            SeachBuilder.DataContext = model;
            btnNew.DataContext       = model;
            base.OnPageLoad(sender, e);
        }
        void UCGiftCardFabricationMaintain_Loaded(object sender, RoutedEventArgs e)
        {
            Loaded -= new RoutedEventHandler(UCGiftCardFabricationMaintain_Loaded);
            facade  = new GiftCardFacade(CPApplication.Current.CurrentPage);
            BtnStack.DataContext = new GiftCardFabricationVM();

            if (VM != null)
            {
                ECCentral.Portal.Basic.Utilities.CodeNamePairHelper.GetList("IM", "GiftCardFabricationStatus", (obj, args) =>
                {
                    if (args.FaultsHandle())
                    {
                        return;
                    }
                    comStatus.ItemsSource = args.Result;
                    VM.ChannelID          = "1";
                    if (args.Result != null)
                    {
                        VM.Status = args.Result.SingleOrDefault(a => a.Name == VM.Status).Code;
                    }


                    if (string.IsNullOrEmpty(VM.POSysNo))
                    {
                        hlPOSysNo.Visibility = System.Windows.Visibility.Collapsed;
                    }


                    //if (VM.POStatus != ECCentral.BizEntity.PO.PurchaseOrderStatus.Abandoned)
                    if (VM.Status != "-1" && VM.Status != "-2")
                    {
                        if (VM.POStatus == PurchaseOrderStatus.WaitingInStock || VM.Status == "1")
                        {
                            btnExport.Visibility = Visibility.Visible;
                        }
                        else if (VM.Status == "0" && VM.POStatus == null)
                        {
                            btnSave.Visibility     = Visibility.Visible;
                            btnCreatePO.Visibility = Visibility.Visible;
                            btnVoid.Visibility     = Visibility.Visible;
                        }
                        ;
                    }

                    // if (VM.POStatus == PurchaseOrderStatus.InStocked)//测试用
                    //    btnExport.IsEnabled = true;

                    BaseInfo.DataContext = VM;
                });
            }
            else
            {
                ECCentral.Portal.Basic.Utilities.CodeNamePairHelper.GetList("IM", "GiftCardFabricationStatus", (obj, args) =>
                {
                    if (args.FaultsHandle())
                    {
                        return;
                    }
                    comStatus.ItemsSource = args.Result;
                });
                hlPOSysNo.Visibility = System.Windows.Visibility.Collapsed;

                VM                   = new GiftCardFabricationVM();
                VM.ChannelID         = "1";
                VM.Status            = "0";
                VM.SysNo             = 0;
                BaseInfo.DataContext = VM;
                tbTotal.Text         = string.Format(total, 0, 0, 0);

                btnSave.Visibility = Visibility.Visible;
                //btnCreatePO.IsEnabled = false;
                //btnVoid.IsEnabled = false;
                //btnExport.IsEnabled = false;
            }

            facade.GetGiftCardFabricationItem(VM.SysNo.Value, (obj, args) =>
            {
                if (args.FaultsHandle())
                {
                    return;
                }

                rsp = args.Result;

                gridVM = new List <GiftCardFabricationItemVM>();
                if (rsp.GiftCardFabricationList != null)
                {
                    foreach (GiftCardFabrication gift in rsp.GiftCardFabricationList)
                    {
                        GiftCardFabricationItemVM item = new GiftCardFabricationItemVM();
                        item.SysNo        = gift.SysNo.Value;
                        item.Quantity     = gift.Quantity;
                        item.ProductName  = gift.Product.ProductBasicInfo.ShortDescription.Content;
                        item.CurrentPrice = gift.Product.ProductPriceInfo.CurrentPrice;
                        item.ProductID    = gift.Product.ProductID;
                        item.ProductSysNo = gift.Product.SysNo;
                        item.PMUserSysNo  = gift.PMUserSysNo;
                        gridVM.Add(item);
                    }
                    DataGrid.ItemsSource = gridVM;
                    if (gridVM[0].SysNo.Value == 0)
                    {
                        DataGrid.Columns[0].Visibility = System.Windows.Visibility.Collapsed;
                    }
                    if (rsp.GiftCardFabricationList != null)
                    {
                        tbTotal.Text = string.Format(total, rsp.GiftCardFabricationList.Count, rsp.TotalPrice, rsp.TotalCount);
                    }
                    else
                    {
                        tbTotal.Text = string.Format(total, 0, 0, 0);
                    }
                }
                else
                {
                    CPApplication.Current.CurrentPage.Context.Window.Alert(ResGiftCardInfo.Information_CheckTheCardGiftProduct, MessageType.Information);
                }
            });
        }