using FLY.OBJComponents.Client;
using FLY.Weight.Client;
using FLY.Weight.Common;
using FLY.Weight.IService;
using MultiLayout;
using MultiLayout.UiModule;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Unity;
namespace FLY.Weight.UI.Client.UiModule
{
///
/// Page_Main.xaml 的交互逻辑
///
public partial class MainGraphV4 : UserControl
{
IWeightSystemService weightSystemService;
List setPlan_items = new List();
public MainGraphV4()
{
InitializeComponent();
}
[InjectionMethod]
public void Init(
IUnityContainer container,
IWeightSystemService weightSystemService)
{
this.container_grid.DataContext = container;
ucTotalFlow.Init(weightSystemService);
ucThickness.Init(weightSystemService);
this.weightSystemService = weightSystemService;
root_grid.DataContext = this.weightSystemService;
for (int i = 0; i < this.weightSystemService.Items.Count(); i++)
{
string objname = $"{nameof(IWeightSystemService.Items)}[{i}]";
SetPLCUpdatePlan plan = new SetPLCUpdatePlan(
this.weightSystemService.PLCos,
objname,
UcWeighterItemV0.item_update_propertynames);
setPlan_items.Add(plan);
}
if (weightSystemService is WeightSystemServiceClient) {
(weightSystemService as WeightSystemServiceClient).ResetItemsEvent += MWeighterCsService_ResetItemsEvent;
}
}
private void MWeighterCsService_ResetItemsEvent()
{
//把多出来的删除
int remove_cnt = setPlan_items.Count() - weightSystemService.Items.Count();
if (remove_cnt > 0)
{
for (int i = 0; i < remove_cnt; i++)
{
SetPLCUpdatePlan plan = setPlan_items[setPlan_items.Count() - 1 - i];
plan.Dispose();
}
setPlan_items.RemoveRange(setPlan_items.Count() - remove_cnt, remove_cnt);
}
else
{
int start_idx = setPlan_items.Count();
int add_cnt = -remove_cnt;
for (int i = 0; i < add_cnt; i++)
{
string objname = $"{nameof(IWeightSystemService.Items)}[{start_idx + i}]";
SetPLCUpdatePlan plan = new SetPLCUpdatePlan(
weightSystemService.PLCos,
objname,
UcWeighterItemV0.item_update_propertynames);
setPlan_items.Add(plan);
}
}
}
}
}