UcWeighterItem.xaml.cs 7.13 KB
Newer Older
1
using FLY.OBJComponents.Client;
2 3 4
using FLY.Weight.Client;
using FLY.Weight.IService;
using MultiLayout.UiModule;
5 6 7 8 9 10 11 12 13 14 15 16 17 18
using System;
using System.Collections.Generic;
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;
19
using Unity;
20

21
namespace FLY.Weight.UI.Client.UiModule
22 23 24 25 26 27
{
    /// <summary>
    /// UcWeighterItem.xaml 的交互逻辑
    /// </summary>
    public partial class UcWeighterItem : UserControl
    {
28 29
        IUnityContainer container;
        IWeightSystemService weightSystemService;
30 31 32 33 34 35 36
        List<SetPLCUpdatePlan> setPlan_items = new List<SetPLCUpdatePlan>();
        int Index = 0;

        public UcWeighterItem()
        {
            InitializeComponent();
        }
37 38 39 40 41 42

        [InjectionMethod]
        public void Init(
            IUnityContainer container,
            int id, 
            IWeightSystemService weightSystemService)
43
        {
44 45
            this.container = container;
            this.weightSystemService = weightSystemService;
46 47 48 49 50 51 52 53

            //查找参数
            if (WeighterItemParams.Current.Indexs.ContainsKey(id))
            {
                Index = WeighterItemParams.Current.Indexs[id];
            }
            else 
            {
54
                for (int i = 0; i < this.weightSystemService.Items.Count(); i++) 
55 56 57 58 59 60 61 62 63 64 65
                {
                    if (!WeighterItemParams.Current.Indexs.ContainsValue(i)) 
                    {
                        WeighterItemParams.Current.Indexs.Add(id, i);
                        Index = i;
                        break;
                    }
                }
            }

            int idx = Index;
66 67
            if (idx >= this.weightSystemService.Items.Count())
                idx = this.weightSystemService.Items.Count() - 1;
68 69 70
            else if (idx < 0)
                idx = 0;

71
            this.DataContext = this.weightSystemService.Items[idx];
72

73
            for (int i = 0; i < this.weightSystemService.Items.Count(); i++)
74 75
            {
                SetPLCUpdatePlan plan = new SetPLCUpdatePlan(
76 77
                    this.weightSystemService.PLCos,
                    this.weightSystemService.Items[i],
78 79 80 81
                    item_update_propertynames);
                setPlan_items.Add(plan);
            }

82 83
            if (weightSystemService is WeightSystemServiceClient)
                (weightSystemService as WeightSystemServiceClient).ResetItemsEvent += MWeighterCsService_ResetItemsEvent;
84 85 86 87 88
        }

        private void MWeighterCsService_ResetItemsEvent()
        {
            //把多出来的删除
89
            int remove_cnt = setPlan_items.Count() - weightSystemService.Items.Count();
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
            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(
106 107
                    weightSystemService.PLCos,
                    weightSystemService.Items[start_idx + i],
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
                    item_update_propertynames);
                    setPlan_items.Add(plan);
                }
            }
        }
        string[] item_update_propertynames = new string[] {
           // "CumulativeProduction",
            "FlowSetting",//√
            "CurrentFlow",//√
            "ScrewPDisp",//√
            "ScrewPSet",//√
            "ScrewPDisp",//√
            "MixBucketWeight",//√
            "BinWeight",//√
            "MixIsOn",//√
            "BucketValveIsOpen",//√
            "ScrewMotorFreq",//√
            "ScrewMotorIsOn",//√
            "ScrewIsAutoMode",//√
            "ScrewManualFreq"//√
        };

        private async void button_frequency_Click(object sender, RoutedEventArgs e)
        {
132
            WdFrequency w = new WdFrequency();
133 134 135 136 137 138 139 140 141 142 143 144 145 146
            var weight = ((Button)sender).Tag as FLY.Weight.Common.WeighterC;
            w.FrequencySet = weight.ScrewManualFreq;
            w.Owner = FLY.ControlLibrary.COMMON.GetWindow(this);
            if (w.ShowDialog() == true)
            {
                //TODO
                weight.ScrewManualFreq = (float)w.FrequencySet;
                weight.ScrewManualFreqIsSet = true;
                //不用写下降沿!!!!!
            }
        }

        private void button_ratio_Click(object sender, RoutedEventArgs e)
        {
147
            WdRatioSet w = new WdRatioSet();
148
            w.Owner = FLY.ControlLibrary.COMMON.GetWindow(this);
149
            w.Init(weightSystemService);
150 151 152 153 154
            w.ShowDialog();
        }

        private void button_ingredient_Click(object sender, RoutedEventArgs e)
        {
155
            WdIngredient w = new WdIngredient();
156
            FLY.Weight.Common.WeighterC weight = ((Button)sender).Tag as FLY.Weight.Common.WeighterC;
157
            w.Init(container, weight, weightSystemService);
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175

            w.Owner = FLY.ControlLibrary.COMMON.GetWindow(this);
            w.ShowDialog();
        }
    }

    /// <summary>
    /// 全部扫描图的参数
    /// </summary>
    public class WeighterItemParams 
    {
        public Dictionary<int, int> Indexs = new Dictionary<int, int>();
        public WeighterItemParams()
        {
        }
        public static WeighterItemParams Current { get; } = new WeighterItemParams();
    }

176
    public class UiModule2_UcWeighterItem : MultiLayout.UiModule.IUiModule2
177 178 179 180 181
    {
        /// <summary>
        /// 控件标题
        /// 它的值取决于culture
        /// </summary>
182 183 184 185 186
        public string Title => "称重层控制";

        public ComponentType Type => ComponentType.Graph;

        public bool IsUnique => true;
187 188 189 190 191 192 193

        /// <summary>
        /// 控件
        /// 创建时,需要给它唯一ID,让加载自己的数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
194
        public FrameworkElement GetComponent(int id, IUnityContainer container)
195 196
        {
            UcWeighterItem graph = new UcWeighterItem();
197
            container.BuildUp(graph);
198 199 200 201 202 203 204 205 206
            return graph;
        }

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

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