
///////////////////////////////////////////////////////////////////////////////
//文件名称: VmProjectAssetList.cs
//文件描述: 项目资产清单.cs
//创 建 者: xls
//创建日期: 2018/5/23 23:33:28
//版 本 号：1.0.0.0
////////////////////////////////////////////////////////////////////////////////

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CEFSharpWpf;
using Com.FirmLib.Bll;
using Com.FirmLib.Entity;
using Com.FirmLib.UI.BllCommon;
using Com.FirmLib.UI.Manufacturer.Model;
using FWindSoft.DataFramework;
using FWindSoft.MVVM;
using FWindSoft.Wpf;

namespace Com.FirmLib.UI.Manufacturer
{
    public class VmProjectAssetList : BaseViewModel
    {
        public VmProjectAssetList()
        {
            Init();
        }

        private void Init()
        {
          
        }
        public void Init(LoadParameter parameter)
        {
            ProjectAssetShowItem currentParameter = parameter.Parameter as ProjectAssetShowItem;
            LoadAssetItems(currentParameter.ManufactureId, currentParameter.ProjectId);
        }
        #region 属性相关



        private ObservableCollection<AssetShowItem> m_AssetItems;
        /// <summary>
        /// 资源清单
        /// </summary>
        public ObservableCollection<AssetShowItem> AssetItems
        {
            get { return this.m_AssetItems; }
            set
            {
                this.m_AssetItems = value;
                RaisePropertyChanged(() => this.AssetItems);
            }
        }

        #endregion

        #region 命令相关
        /// <summary>
        /// 浏览资产信息
        /// </summary>
        /// <param name="parameter"></param>
        [Command]
        public void ScanAssetInfo(object parameter)
        {

            try
            {
                AssetShowItem item = parameter as AssetShowItem;
                if (item == null)
                    return;
                AssetItem parItem = new AssetItem();
                parItem.Id = item.Id;
                parItem.ProjectId = item.ProjectId;
                parItem.FamilyCode = item.Family;
                string url = BllFactory<AssetBll>.Instance.GetAssetUrl(parItem);
                //WinBrowser.Instance.Show("http://www.baidu.com", "资产信息");
                WinBrowser.Instance.Show(url, "资产信息");
            }
            catch (Exception ex)
            {
                MessageTipEx.Show(ex);
            }
        }
        public bool CanScanAssetInfo(object parameter)
        {
            return true;
        }
        #endregion

        /// <summary>
        /// 加载资产信息
        /// </summary>
        /// <param name="venderId"></param>
        /// <param name="projectId"></param>
        private void LoadAssetItems(string venderId,string projectId)
        {
            var dataItems = BllFactory<ManufacturerBll>.Instance.GetProjectAssetItems(venderId,projectId);
            AssetItems = new ObservableCollection<AssetShowItem>();
            foreach (var dataItem in dataItems)
            {
                AssetShowItem item = new AssetShowItem();
                item.Id = dataItem.Id;
                item.ProjectId = projectId;
                item.Family = dataItem.Family;
                item.Brand = dataItem.Asset.Brand;
                item.Product = dataItem.Asset.Product;
                item.LeaveFactoryCode = dataItem.Asset.SerialNum;

                item.LocalCode = dataItem.Asset.EquipLocalId;
                item.LocalName = dataItem.Asset.EquipLocalName;
                item.ManufactureDate = dataItem.Asset.ProductDate;
                try
                {
                    DateTime dateTime = DateTimeManager.ConvertDateTime(item.ManufactureDate);
                    if (dateTime != null)
                    {
                        item.ManufactureDate = dateTime.ToString("yyyy年MM月dd日");
                    }
                }
                  
                catch (Exception ex)
                {
                }

                AssetItems.Add(item);
            }
        }
    }
}
