123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302 |
-
- ///////////////////////////////////////////////////////////////////////////////
- //文件名称: VmSupplyAssetCreater.cs
- //文件描述: VmSupplyAssetCreater.cs
- //创 建 者: xls
- //创建日期: 2018/9/12 22:30:38
- //版 本 号:1.0.0.0
- ////////////////////////////////////////////////////////////////////////////////
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Windows;
- using Com.FirmLib.Bll;
- using Com.FirmLib.Entity;
- using Com.FirmLib.UI.BllCommon;
- using Com.FirmLib.UI.Common;
- using Com.FirmLib.UI.Common.Model;
- using FWindSoft.DataFramework;
- using FWindSoft.MVVM;
- using FWindSoft.Wpf;
- using FWindSoft.Wpf.Common;
- namespace Com.FirmLib.UI.Seller
- {
- public class VmSupplyAssetCreater : BaseViewModel
- {
- public VmSupplyAssetCreater()
- {
- Init();
- }
- private void Init()
- {
- AssetItems = new ObservableCollection<AssetShowItem>() { };
- this.AssetCount = 1;
- this.Price = 1000;
- this.MaintenancePeriod = 3;
- }
- public void Init(LoadParameter parameter)
- {
- SelectAssetContext context = parameter.Parameter as SelectAssetContext;
- if (context == null)
- return;
- Context = context;
- }
- SelectAssetContext Context { get; set; }
- #region 属性相关
- private int m_AssetCount;
- /// <summary>
- /// 资产数量
- /// </summary>
- public int AssetCount
- {
- get { return this.m_AssetCount; }
- set
- {
- this.m_AssetCount = value;
- RaisePropertyChanged(nameof(this.AssetCount));
- //更新资产
- UpdateAssetItems();
- }
- }
- private double m_Price;
- /// <summary>
- /// 采购价格
- /// </summary>
- public double Price
- {
- get { return this.m_Price; }
- set
- {
- this.m_Price = value;
- RaisePropertyChanged(nameof(this.Price));
- }
- }
- private double m_MaintenancePeriod;
- /// <summary>
- /// 保修期
- /// </summary>
- public double MaintenancePeriod
- {
- get { return this.m_MaintenancePeriod; }
- set
- {
- this.m_MaintenancePeriod = value;
- RaisePropertyChanged(nameof(this.MaintenancePeriod));
- }
- }
- private ProductTypeShowItem m_CurrentProductType;
- /// <summary>
- /// 当前选中类型
- /// </summary>
- public ProductTypeShowItem CurrentProductType
- {
- get { return this.m_CurrentProductType; }
- set
- {
- this.m_CurrentProductType = value;
- RaisePropertyChanged(nameof(this.CurrentProductType));
- }
- }
- private ObservableCollection<AssetShowItem> m_AssetItems;
- /// <summary>
- /// 创建资产
- /// </summary>
- public ObservableCollection<AssetShowItem> AssetItems
- {
- get { return this.m_AssetItems; }
- set
- {
- this.m_AssetItems = value;
- RaisePropertyChanged(nameof(this.AssetItems));
- }
- }
- #endregion
- #region 命令相关
- /// <summary>
- /// 选择型号
- /// </summary>
- /// <param name="parameter"></param>
- [Command]
- public void SelectProductType(object parameter)
- {
- try
- {
- WinSingleProductTypeSelector win = new WinSingleProductTypeSelector();
- win.Owner = this.GetWindow();
- LoadParameter.StartParameter(win, new LoadParameter(CurrentProductType?.Clone()));
- if (win.ShowDialog() == true)
- {
- ProductTypeShowItem item = win.GetRealResult<ProductTypeShowItem>();
- this.CurrentProductType = item;
- }
- }
- catch (Exception ex)
- {
- MessageTip.Show(ex.Message);
- }
- }
- public bool CanSelectProductType(object parameter)
- {
- return true;
- }
- /// <summary>
- /// 生成资产项目
- /// </summary>
- /// <param name="parameter"></param>
- [Command]
- public void CreateAssetItem(object parameter)
- {
- try
- {
- CreateAssetItems(parameter as Window);
- }
- catch (Exception ex)
- {
- MessageTip.Show(ex.ToString());
- }
- }
- public bool CanCreateAssetItem(object parameter)
- {
- return true;
- }
- #endregion
- #region 内部方法
- /// <summary>
- /// 控制资产数据设置
- /// </summary>
- private void UpdateAssetItems()
- {
- var currentCount = this.AssetItems.Count;
- //控件绑定的Value值,与控件显示不同步的情况;
- //不使用ValueChange事件,只能这样去处理
- var uiCount = Math.Min(Math.Max(1, this.AssetCount), 100);
- if (currentCount == uiCount)
- return;
- if (currentCount > uiCount)
- {
- for (int i = currentCount - 1; i >= uiCount; i--)
- {
- this.AssetItems.RemoveAt(i);
- }
- }
- else
- {
- for (int i = currentCount; i < uiCount; i++)
- {
- this.AssetItems.Add(new AssetShowItem() { LocalName = i.ToString(),ProductionDate=DateTime.Today.ToString("yyyyMMdd") });
- }
- }
- }
- /// <summary>
- /// 整理显示对象数据
- /// </summary>
- /// <returns></returns>
- private List<AssetShowItem> GetShowItems()
- {
- foreach (var asset in this.AssetItems)
- {
- asset.CacheParameters.Clear();
- asset.ProjectId = Context.ProjectId;
- if (this.CurrentProductType != null)
- {
- asset.Brand = this.CurrentProductType.BrandName;
- asset.Product = this.CurrentProductType.ProductName;
- asset.Type = this.CurrentProductType.ProductTypeName;
- asset.TypeId = this.CurrentProductType.ProductTypeId;
- asset.FamilyCode = this.CurrentProductType.FamilyCode;
- }
- asset.ProcurementPrice = this.Price;
- asset.Warranty = this.MaintenancePeriod;
- #region 增加修改参数
- asset.CacheParameters.Add(new WatchParameter(MBIBuiltInParameter.AssetID));
- asset.CacheParameters.Add(new WatchParameter(MBIBuiltInParameter.DPSpecificationID));
- asset.CacheParameters.Add(new WatchParameter(MBIBuiltInParameter.ProductDate));
- asset.CacheParameters.Add(new WatchParameter(MBIBuiltInParameter.EquipLocalName));
- asset.CacheParameters.Add(new WatchParameter(MBIBuiltInParameter.EquipLocalID));
- asset.CacheParameters.Add(new WatchParameter(MBIBuiltInParameter.SerialNum));
- asset.CacheParameters.Add(new WatchParameter(MBIBuiltInParameter.PurchasePrice));
- asset.CacheParameters.Add(new WatchParameter(MBIBuiltInParameter.Warranty));
- #endregion
- }
- return new List<AssetShowItem>(this.AssetItems);
- }
- /// <summary>
- /// 在项目中创建资产
- /// </summary>
- private void CreateAssetItems(Window window)
- {
- if (Context == null | string.IsNullOrEmpty(Context.ProjectId))
- {
- MessageTip.Show("项目id,不能为空");
- }
- var items = GetShowItems();
- var createItems = items.Select(c => ConcertTdItem(c)).ToList();
- BatchResult<List<string>> result=BllFactory<PlatformBll>.Instance.CreateAssetItems(new ProjectSetting(Context.ProjectId), createItems);
- if (result.Result == BatchResultType.Successed)
- {
- MessageTip.Show(this.GetWindow(), "创建资产成功");
- var ids = result.AttachInfo ?? new List<string>();
- for (int i = 0; i < ids.Count; i++)
- {
- if (items.Count > i)
- {
- items[i].Id = ids[i];
- }
- }
- if (Context != null)
- {
- Context.AddedItems.AddRange(items);
- }
-
- window.DialogResult = true;
- }
- else if(result.Result==BatchResultType.PartSuccessed)
- {
- MessageTip.Show(this.GetWindow(),"创建资产部分失败,不能直接将新资产关联到相关列表,请去选择列表选择");
- window.DialogResult = true;
- }
- else
- {
- MessageTip.Show(this.GetWindow(),"创建资产全部失败");
- window.DialogResult = false;
- }
- }
- #endregion
- #region 创建值转换信息
- /// <summary>
- /// 显示数据转换成操作数据
- /// </summary>
- /// <param name="item"></param>
- /// <returns></returns>
- private TdAssetItem ConcertTdItem(AssetShowItem item)
- {
- TdAssetItem tdItem = AssetManager.ConvertToAssetItem(item); ;
- //tdItem.FamilyCode = item.FamilyCode;
- return tdItem;
- }
- #endregion
- }
- }
|