
///////////////////////////////////////////////////////////////////////////////  
//文件名称: WinBrandEditor.xaml
//文件描述: 品牌编辑
//创 建 者: xls
//创建日期: 2018/5/23 23:18:32
//版 本 号：1.0.0.0
////////////////////////////////////////////////////////////////////////////////

using System;
using System.Windows;
using System.Windows.Controls;
using Com.FirmLib.UI.Common;
using Com.FirmLib.UI.Manufacturer.Model;
using FWindSoft.Wpf;
using FWindSoft.Wpf.Controls;
using FWindSoft.Wpf.SystemTypeExtensions;

namespace Com.FirmLib.UI.Manufacturer
{
    /// <summary>
    /// WinBrandEditor.xaml 的交互逻辑
    /// </summary>
    public partial class WinBrandEditor : BaseWindow
    {
        private VmBrandEditor m_Vm;
        public WinBrandEditor():this(new VmBrandEditor())
        {
          
        }
        public WinBrandEditor(VmBrandEditor vm)
        {
            InitializeComponent();        
            this.m_Vm = vm;
            this.m_Vm.SetRefView(this);
            this.m_Vm.WatchValidateResult(() => !this.HasError());
            this.DataContext = this.m_Vm;
        }

        protected override void LoadData(LoadParameter parameter)
        {
            if (parameter == null)
                return;
            BrandShowItem brandShowItem = parameter.Parameter as BrandShowItem;
            if (brandShowItem == null)
                return;
            if (string.IsNullOrEmpty(brandShowItem.Id))
            {
                this.Title = "添加品牌";
                btnAddProduct.Visibility = Visibility.Visible;
                stackDelete.Visibility = Visibility.Collapsed;
            }
            else
            {
                this.Title = "编辑品牌";
                btnAddProduct.Visibility = Visibility.Collapsed;
                stackDelete.Visibility = Visibility.Visible;
            }
            TryCatchWrapper.Handled(() => this.m_Vm.Init(parameter));
        }
        #region 界面关联事件
        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                bg.UpdateSourceForEach();
                if (this.HasError())
                {
                    //MessageShow.Infomation("请修改错误输入项");
                    return;
                }            
            }
            catch (Exception ex)
            {
                //MessageShow.Show(ex);
            }
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            Close();
        }
        #endregion
        /// <summary>
        /// 新创建元素的Id
        /// </summary>
        public string BrandId { get { return this.m_Vm.BrandId; } }
        /// <summary>
        /// 使用删除命令
        /// </summary>
        public bool UseDelete { get { return this.m_Vm.UseDelete; } }
        /// <summary>
        /// 继续添加商品
        /// </summary>
        public bool AddProduct { get { return this.m_Vm.AddProduct; } }

        private void Border_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
        {
            var element = sender as Border;

            MaskOptions.SetIsShow(element, true);
        }
        private void Border_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            var element = sender as Border;

            MaskOptions.SetIsShow(element, true);
        }
    }
}
