Page_Main.xaml.cs 8.95 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
using FLY.OBJComponents.Client;
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;

namespace FLY.Weight.UI.Client.UIModule
{
    /// <summary>
    /// Page_Main.xaml 的交互逻辑
    /// </summary>
    public partial class Page_Main : Page
    {
        FLY.Weight.Client.WeightSystemClient mWeighterCsService;
        SysParam sysparam;
        SetPLCUpdatePlan setPlan_accessory;
        List<SetPLCUpdatePlan> setPlan_items = new List<SetPLCUpdatePlan>();
        public Page_Main()
        {
            InitializeComponent();

        }

        public void Init(int id)
        {
            sysparam = SysParam.Current;
            mWeighterCsService = TDGage.Current.mWeighterCsService;
            root_grid.DataContext = mWeighterCsService;

            setPlan_accessory = new SetPLCUpdatePlan(
                mWeighterCsService.PLCos,
                mWeighterCsService.Accessory,
                new string[] {
45 46 47
                        "TotalFlowSetting",
                        "TotalFlow",
                        "TotalProduction",
48

49 50 51 52
                        "ALast",
                        "ACurrent",
                        "ACurrentLen",
                        "AClear",
潘栩锋's avatar
潘栩锋 committed
53

54 55 56 57
                        "BLast",
                        "BCurrent",
                        "BCurrentLen",
                        "BClear",
潘栩锋's avatar
潘栩锋 committed
58

59 60 61 62 63 64 65 66
                        "TotalFilmWidth",
                        "IsRimNoRecycle",
                        "RimWidth",
                        "ActFilmWidth",
                        "SetThickness",
                        "TargetVelocity",
                        "CurrentVelocity"
                });
潘栩锋's avatar
潘栩锋 committed
67 68 69 70 71 72

            for (int i = 0; i < mWeighterCsService.Items.Count(); i++)
            {
                SetPLCUpdatePlan plan = new SetPLCUpdatePlan(
                    mWeighterCsService.PLCos,
                    mWeighterCsService.Items[i],
73
                    item_update_propertynames);
潘栩锋's avatar
潘栩锋 committed
74 75
                setPlan_items.Add(plan);
            }
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

            mWeighterCsService.ResetItemsEvent += MWeighterCsService_ResetItemsEvent;
        }

        private void MWeighterCsService_ResetItemsEvent()
        {
            //把多出来的删除
            int remove_cnt = setPlan_items.Count() - mWeighterCsService.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(
                    mWeighterCsService.PLCos,
                    mWeighterCsService.Items[start_idx+i],
                    item_update_propertynames);
                    setPlan_items.Add(plan);
                }
            }
潘栩锋's avatar
潘栩锋 committed
106
        }
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
        string[] item_update_propertynames = new string[] {
            "CurrentFlow",
            "CumulativeProduction",
            "FlowSetting",
            "CurrentFlow",
            "ScrewPDisp",
            "ScrewPSet",
            "ScrewPDisp",
            "MixBucketWeight",
            "BinWeight",
            "MixIsOn",
            "BucketValveIsOpen",
            "ScrewMotorFreq",
            "ScrewMotorIsOn",
            "ScrewIsAutoMode",
            "ScrewManualFreq"
        };
潘栩锋's avatar
潘栩锋 committed
124

125
        private async void button_frequency_Click(object sender, RoutedEventArgs e)
潘栩锋's avatar
潘栩锋 committed
126 127
        {
            Window_Frequency w = new Window_Frequency();
128
            var weight = ((Button)sender).Tag as FLY.Weight.Common.WeighterC;
潘栩锋's avatar
潘栩锋 committed
129
            w.FrequencySet = weight.ScrewManualFreq;
130
            w.Owner = FLY.ControlLibrary.COMMON.GetWindow(this);
潘栩锋's avatar
潘栩锋 committed
131 132 133 134
            if (w.ShowDialog()==true)
            {
                //TODO
                weight.ScrewManualFreq = (float)w.FrequencySet;
135 136
                weight.ScrewManualFreqIsSet = true;
                //不用写下降沿!!!!!
潘栩锋's avatar
潘栩锋 committed
137 138 139 140 141 142
            }
        }

        private void button_ratio_Click(object sender, RoutedEventArgs e)
        {
            Window_RatioSet w = new Window_RatioSet();
143
            w.Owner = FLY.ControlLibrary.COMMON.GetWindow(this);
潘栩锋's avatar
潘栩锋 committed
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
            w.Init(mWeighterCsService);
            w.ShowDialog();
        }

        private void button_info_Click(object sender, RoutedEventArgs e)
        {
            //NavigationService ns = this.NavigationService;// Application.Current.Properties["NavigationService"] as NavigationService;
            NavigationService ns = Application.Current.Properties["NavigationService"] as NavigationService;
            if (ns != null)
            {
                Page_Menu p = new Page_Menu();
                ns.Navigate(p);
            }
        }

        private void button_clear_Click(object sender, RoutedEventArgs e)
        {
            foreach (FLY.Weight.Common.WeighterC weight in mWeighterCsService.Items)
            {
                weight.ClearProduction = true;
            }
            FLY.ControlLibrary.Window_Tip.Show("", "清空成功", TimeSpan.FromSeconds(2));
        }

        private void button_ingredient_Click(object sender, RoutedEventArgs e)
        {
            Window_Ingredient w = new Window_Ingredient();
            FLY.Weight.Common.WeighterC weight = ((Button)sender).Tag as FLY.Weight.Common.WeighterC;
            w.Init(weight);


175
            w.Owner = FLY.ControlLibrary.COMMON.GetWindow(this);
潘栩锋's avatar
潘栩锋 committed
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
            w.ShowDialog();
        }

        private void button_thickness_Click(object sender, RoutedEventArgs e)
        {
            Window_Thickness w = new Window_Thickness();
            if (mWeighterCsService.Items.Count() < 1)
                return;

            w.SetThickness = (int)mWeighterCsService.Accessory.SetThickness;
            w.FilmWidth = (int)mWeighterCsService.Accessory.TotalFilmWidth;
            w.RimWidth = (int)mWeighterCsService.Accessory.RimWidth;
            w.IsRimNoRecycle = mWeighterCsService.Accessory.IsRimNoRecycle;

            
191 192 193

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

潘栩锋's avatar
潘栩锋 committed
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
            if (w.ShowDialog() == true)
            {
                mWeighterCsService.Accessory.SetThickness = w.SetThickness;
                mWeighterCsService.Accessory.TotalFilmWidth = w.FilmWidth;
                mWeighterCsService.Accessory.RimWidth = w.RimWidth;
                mWeighterCsService.Accessory.IsRimNoRecycle = w.IsRimNoRecycle;

                FLY.ControlLibrary.Window_Tip.Show("","厚度参数设置成功", TimeSpan.FromSeconds(2));
            }
        }

        private void button_aclear_Click(object sender, RoutedEventArgs e)
        {
            if (mWeighterCsService.ItemsCnt > 0)
            {
                mWeighterCsService.Accessory.AClear = true;
                FLY.ControlLibrary.Window_Tip.Show("", "清空成功", TimeSpan.FromSeconds(2));
            }
        }

        private void button_bclear_Click(object sender, RoutedEventArgs e)
        {
            if (mWeighterCsService.ItemsCnt > 0)
            {
                mWeighterCsService.Accessory.BClear = true;
                FLY.ControlLibrary.Window_Tip.Show("", "清空成功", TimeSpan.FromSeconds(2));
            }
        }
    }




    public class UIModule_Main : FLY.UI.Module.IUIModule
    {
        /// <summary>
        /// 控件标题
        /// 它的值取决于culture
        /// </summary>
        public string Title
        {
            get
            {
                return "称重主界面";
            }
        }

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

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


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