MainGraph.xaml.cs 4.28 KB
Newer Older
潘栩锋's avatar
潘栩锋 committed
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
using FLY.OBJComponents.Client;
using FLY.Weight2.Client;
using FLY.Weight2.Common;
using FLY.Weight2.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.Weight2.UI.Client.UiModule
{
    /// <summary>
    /// Page_Main.xaml 的交互逻辑
    /// </summary>
    public partial class MainGraph : UserControl
    {

        IWeightSystemService weightSystemService;

 
        List<SetPLCUpdatePlan> setPlan_items = new List<SetPLCUpdatePlan>();
        public MainGraph()
        {
            InitializeComponent();
        }

        [InjectionMethod]
        public void Init(
            IUnityContainer container,
            IWeightSystemService weightSystemService)
        {
            ucTotalFlow.Init(weightSystemService);
            ucThickness.Init(weightSystemService);

            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],
                    UcWeighterItem.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++)
                {
                    SetPLCUpdatePlan plan = new SetPLCUpdatePlan(
                    weightSystemService.PLCos,
                    weightSystemService.Items[start_idx+i],
                    UcWeighterItem.item_update_propertynames);
                    setPlan_items.Add(plan);
                }
            }
        }
    }




    public class UiModule2_MainGraph : IUiModule2
    {
        /// <summary>
        /// 控件标题
        /// 它的值取决于culture
        /// </summary>
        public string Title => "称重单组分主界面";

        public ComponentType Type => ComponentType.Graph;

        public bool IsUnique => true;

        /// <summary>
        /// 控件
        /// 创建时,需要给它唯一ID,让加载自己的数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public FrameworkElement GetComponent(int id, IUnityContainer container)
        {
            MainGraph graph = new MainGraph();
            container.BuildUp(graph);
            return graph;
        }

        /// <summary>
        /// 控件缩略图,用于编辑界面时,大致看看
        /// 创建时,需要给它唯一ID,让加载自己的数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public FrameworkElement GetThumbnail()
        {
            return new System.Windows.Controls.Grid();
        }


        /// <summary>
        /// 给出全部控件ID, 控件自行删除没有的参数
        /// </summary>
        /// <param name="IDs"></param>
        public void MatchParam(int[] IDs)
        {
        }
    }
}