MainGraphV3_2.xaml.cs 3.03 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
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
{
    /// <summary>
    /// Page_Main.xaml 的交互逻辑
    /// </summary>
29
    public partial class MainGraphV3_2 : UserControl
30 31 32 33
    {
        IWeightSystemService weightSystemService;

        List<SetPLCUpdatePlan> setPlan_items = new List<SetPLCUpdatePlan>();
34
        public MainGraphV3_2()
35 36 37 38 39 40 41 42 43 44
        {
            InitializeComponent();

        }

        [InjectionMethod]
        public void Init(
            IUnityContainer container,
            IWeightSystemService weightSystemService)
        {
45
            this.container_grid.DataContext = container;
46 47 48
            ucTotalFlow.Init(weightSystemService);
            ucThickness.Init(weightSystemService);

49 50 51 52 53 54 55 56
            this.weightSystemService = weightSystemService;
            root_grid.DataContext = this.weightSystemService;

            for (int i = 0; i < this.weightSystemService.Items.Count(); i++)
            {
                SetPLCUpdatePlan plan = new SetPLCUpdatePlan(
                    this.weightSystemService.PLCos,
                    this.weightSystemService.Items[i],
57
                    UcWeighterItem.item_update_propertynames);
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
                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++)
                {
                    SetPLCUpdatePlan plan = new SetPLCUpdatePlan(
                    weightSystemService.PLCos,
                    weightSystemService.Items[start_idx+i],
88
                    UcWeighterItem.item_update_propertynames);
89 90 91 92 93 94 95 96 97 98 99
                    setPlan_items.Add(plan);
                }
            }
        }

    }




}