using FLY.OBJComponents.Client; using FLY.Weight2.Client; using FLY.Weight2.IService; using MultiLayout.UiModule; 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; using Unity; namespace FLY.Weight2.UI.Client.UiModule { /// <summary> /// UcWeighterItem.xaml 的交互逻辑 /// </summary> public partial class UcWeighterItem : UserControl { public IWeightSystemService WeightSystemService { get { return (IWeightSystemService)GetValue(WeightSystemServiceProperty); } set { SetValue(WeightSystemServiceProperty, value); } } // Using a DependencyProperty as the backing store for WeightSystemService. This enables animation, styling, binding, etc... public static readonly DependencyProperty WeightSystemServiceProperty = DependencyProperty.Register("WeightSystemService", typeof(IWeightSystemService), typeof(UcWeighterItem), new PropertyMetadata(null)); List<SetPLCUpdatePlan> setPlan_items = new List<SetPLCUpdatePlan>(); int Index = 0; public UcWeighterItem() { InitializeComponent(); } [InjectionMethod] public void Init( int id, IWeightSystemService weightSystemService) { this.WeightSystemService = weightSystemService; //查找参数 if (WeighterItemParams.Current.Indexs.ContainsKey(id)) { Index = WeighterItemParams.Current.Indexs[id]; } else { for (int i = 0; i < this.WeightSystemService.Items.Count(); i++) { if (!WeighterItemParams.Current.Indexs.ContainsValue(i)) { WeighterItemParams.Current.Indexs.Add(id, i); Index = i; break; } } } int idx = Index; if (idx >= this.WeightSystemService.Items.Count()) idx = this.WeightSystemService.Items.Count() - 1; else if (idx < 0) idx = 0; this.DataContext = this.WeightSystemService.Items[idx]; SetPLCUpdatePlan plan = new SetPLCUpdatePlan( this.WeightSystemService.PLCos, this.WeightSystemService.Items[idx], item_update_propertynames); setPlan_items.Add(plan); } public static string[] item_update_propertynames = new string[] { nameof(Common.WeighterC.CurrentFlow), nameof(Common.WeighterC.ScrewPDisp), nameof(Common.WeighterC.CurrentFlowAuto), nameof(Common.WeighterC.ScrewPDispAuto), nameof(Common.WeighterC.BinWeight), nameof(Common.WeighterC.ScrewMotorFreq), nameof(Common.WeighterC.ScrewManualFreq), nameof(Common.WeighterC.ScrewManualFreqIsSet), nameof(Common.WeighterC.ScrewIsAutoMode), nameof(Common.WeighterC.ScrewMotorIsOn), nameof(Common.WeighterC.ScrewMotorOnSet) }; private async void button_frequency_Click(object sender, RoutedEventArgs e) { WdFrequency w = new WdFrequency(); var weight = ((Button)sender).Tag as FLY.Weight2.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) { WdRatioSet w = new WdRatioSet(); w.Owner = FLY.ControlLibrary.COMMON.GetWindow(this); w.Init(WeightSystemService); 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(); } public class UiModule2_UcWeighterItem : MultiLayout.UiModule.IUiModule2 { /// <summary> /// 控件标题 /// 它的值取决于culture /// </summary> public string Title => "单组称重.层控制"; public ComponentType Type => ComponentType.Graph; public bool IsUnique => false; /// <summary> /// 控件 /// 创建时,需要给它唯一ID,让加载自己的数据 /// </summary> /// <param name="id"></param> /// <returns></returns> public FrameworkElement GetComponent(int id, IUnityContainer container) { UcWeighterItem graph = new UcWeighterItem(); 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) { } } }