
///////////////////////////////////////////////////////////////////////////////  
//文件名称: WinSellerProjectContract.xaml
//文件描述: 供销商项目合同
//创 建 者: xls
//创建日期: 2018/5/24 21:31:49
//版 本 号：1.0.0.0
////////////////////////////////////////////////////////////////////////////////

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using FWindSoft.Wpf;
using FWindSoft.Wpf.Controls;
using FWindSoft.Wpf.SystemTypeExtensions;

namespace Com.FirmLib.UI.Seller
{
    /// <summary>
    /// WinSellerProjectContract.xaml 的交互逻辑
    /// </summary>
    public partial class WinSellerProjectContract : NChildWindow
    {
        private VmSellerProjectContract m_Vm;
        public WinSellerProjectContract():this(new VmSellerProjectContract())
        {
          
        }
        public WinSellerProjectContract(VmSellerProjectContract vm)
        {
            InitializeComponent();
            this.m_Vm = vm;
            this.EveryTimeLoad = true;
            this.m_Vm.SetRefView(this);
            this.DataContext = this.m_Vm;
            this.m_Vm.WatchValidateResult(() => !this.HasError());
           
        }
        protected override void LoadData(LoadParameter parameter)
        {
            //初始化列表数据
            TryCatchWrapper.Handled(() => this.m_Vm.Init(parameter));
        }
        #region 界面关联事件
        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                try
                {
                    this.m_Vm.BeginInEdit();
                    var textBoxes = this.GetSpecifyTypeChildren<TextBox>();
                    foreach (var textBox in textBoxes)
                    {
                        var binding = textBox.GetBindingExpression(TextBox.TextProperty);
                        if (binding != null)
                        {
                            binding.UpdateSource();
                        }
                    }
                }
                finally
                {

                    this.m_Vm.EndInEdit();
                }
                //bg.UpdateSourceForEach();
                if (this.HasError())
                {
                    return;
                }          
            }
            catch (Exception ex)
            {
                //MessageShow.Show(ex);
            }
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            Close();
        }
        #endregion
      
    }
}
