// 开始监控一个门 public void BeginMonitor(DoorItem door) { lock (_syncRoot) { // 检查以前这个门是否已经有监控消息 var message = _messages.Find((m) => { if (m.Door == door) { return(true); } return(false); }); if (message != null) { App.CurrentApp.Speak("补做遗留提交"); WpfClientInfo.WriteInfoLog($"对门 {message.Door.Name} 补做一次 submit (1)"); _func_submit?.Invoke(message.Door, false); message.StartTime = DateTime.Now; // 重新开始 message.HeartbeatTicks = RfidManager.LockHeartbeat; } else { message = new MonitorMessage { Door = door, StartTime = DateTime.Now, HeartbeatTicks = RfidManager.LockHeartbeat }; _messages.Add(message); } } }
private void Border_ContextMenuOpening(object sender, ContextMenuEventArgs e) { var border = (Border)sender; DoorItem door = border.DataContext as DoorItem; ContextMenuOpen111?.Invoke(sender, new DoorContextMenuArgs { OriginArgs = e, Door = door }); }
private void All_Click(object sender, MouseButtonEventArgs e) { TextBlock button = (TextBlock)sender; DoorItem door = button.DataContext as DoorItem; OpenDoor?.Invoke(sender, new OpenDoorEventArgs { ButtonName = "count", Door = button.DataContext as DoorItem }); e.Handled = true; }
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { DoorItem door = (values[0] as DoorItem); string state = values[1] as string; /* * if (state == "open") * return new SolidColorBrush(OpenColor); * * return new SolidColorBrush(CloseColor); */ /* * if (state == "open") * return new SolidColorBrush(door.OpenBrush); * * return new SolidColorBrush(door.CloseBrush); */ Brush brush = null; if (state == "open") { brush = door.OpenBrush; } else { brush = door.CloseBrush; } /* * if (brush is ImageBrush) * { * var imageBrush = brush as ImageBrush; * return new ImageBrush(imageBrush.ImageSource.Clone()); * } */ return(brush); /* * BrushConverter convertor = new BrushConverter(); * * Brush brush = null; * if (state == "open") * brush = (Brush)convertor.ConvertFromString(door.OpenColor); * else * brush = (Brush)convertor.ConvertFromString(door.CloseColor); * brush.Freeze(); * return brush; */ }
private void TextBlock_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { TextBlock textblock = (TextBlock)sender; DoorItem door = textblock.DataContext as DoorItem; OpenDoor?.Invoke(sender, new OpenDoorEventArgs { ButtonName = textblock.Name, Door = textblock.DataContext as DoorItem }); e.Handled = true; /* * Button button = textblock.TemplatedParent as Button; * DoorItem door = button.DataContext as DoorItem; */ }
// 把不再需要监控的消息移走 public void RemoveMessages(DoorItem door) { lock (_syncRoot) { List <MonitorMessage> delete_messages = new List <MonitorMessage>(); foreach (var message in _messages) { if (message.Door == door) { delete_messages.Add(message); } } foreach (var message in delete_messages) { _messages.Remove(message); } } }
// 根据一个 door 元素定义,创建一个 Button 控件 Button CreateDoorControl(XmlElement door, DoorItem door_item) { string door_name = door.GetAttribute("name"); Button button = new Button { // Name = $"button_{column}_{row}", }; var template = this.Resources["ButtonTemplate"]; // button.Children.Add(block); button.SetValue(Button.TemplateProperty, template); // button.SetValue(Grid.RowProperty, row); button.SetValue(Grid.ColumnProperty, 0); button.Click += Button_Click; button.DataContext = door_item; // this.canvas.Children.Add(button); return(button); }
// 将指定门的暂存的信息保存为 Action。但并不立即提交 public async static Task SaveDoorActions(DoorItem door, bool clearOperator) { var result = await ShelfData.SaveActions((entity) => { var results = DoorItem.FindDoors(ShelfData.Doors, entity.ReaderName, entity.Antenna); // TODO: 如果遇到 results.Count > 1 是否抛出异常? if (results.Count > 1) { WpfClientInfo.WriteErrorLog($"读卡器名 '{entity.ReaderName}' 天线编号 {entity.Antenna} 匹配上 {results.Count} 个门"); throw new Exception($"读卡器名 '{entity.ReaderName}' 天线编号 {entity.Antenna} 匹配上 {results.Count} 个门。请检查 shelf.xml 并修正配置此错误,确保只匹配一个门"); } if (results.IndexOf(door) != -1) { return(door.Operator); // return GetOperator(entity); } return(null); }); if (result.Value == -1) { SetGlobalError("save_actions", $"SaveDoorActions() 出错: {result.ErrorInfo}"); PageShelf.TrySetMessage(null, $"SaveDoorActions() 出错: {result.ErrorInfo}。这是一个严重错误,请管理员及时介入处理"); } else { SetGlobalError("save_actions", null); } // 2019/12/21 if (clearOperator == true && door.State == "close") { door.Operator = null; // 清掉门上的操作者名字 } }
public void InitializeButtons(XmlDocument cfg_dom, List <DoorItem> door_items) { // 2019/12/22 this.canvas.Children.Clear(); // testing // door_items = new List<DoorItem>(); XmlElement root = cfg_dom.DocumentElement; CheckAttributes(root, two_attrs); double canvas_width = GetDouble(root, "width", 0); double canvas_height = GetDouble(root, "height", 0); var doors = cfg_dom.DocumentElement.SelectNodes("//door"); bool undefined = false; int index = 0; foreach (XmlElement door in doors) { CheckAttributes(door, all_attrs); GroupPosition gp = GetPosition(door); if (gp.Left == -1 || gp.Top == -1 || gp.Width == -1 || gp.Height == -1) { undefined = true; } DoorItem door_item = null; if (index < door_items.Count) { door_item = door_items[index++]; } var button = CreateDoorControl(door, door_item); button.Tag = gp; if (door_item != null) { door_item.BorderBrush = gp.BorderBrush; // if (gp.OpenBrush is SolidColorBrush) door_item.OpenBrush = gp.OpenBrush; // (gp.OpenBrush as SolidColorBrush).Color; // if (gp.CloseBrush is SolidColorBrush) door_item.CloseBrush = gp.CloseBrush; // (gp.CloseBrush as SolidColorBrush).Color; door_item.BorderThickness = gp.BorderThickness; door_item.CornerRadius = gp.CornerRadius; door_item.Foreground = gp.Foreground; door_item.ErrorForeground = gp.ErrorForeground; } this.canvas.Children.Add(button); } // 对 -1 进行调整 if (undefined) { double x = 0; double y = 0; foreach (Button button in this.canvas.Children) { GroupPosition gp = button.Tag as GroupPosition; if (gp.Left == -1) { gp.Left = 0; gp.Top = y; gp.Width = 20; gp.Height = 10; y += 10; } } canvas_width = 20; canvas_height = y; } // 变换为比率 foreach (Button button in this.canvas.Children) { GroupPosition gp = button.Tag as GroupPosition; gp.Left /= canvas_width; gp.Top /= canvas_height; gp.Width /= canvas_width; gp.Height /= canvas_height; gp.Padding = Divide(gp.Padding, canvas_width, canvas_height); gp.Margin = Divide(gp.Margin, canvas_width, canvas_height); gp.BorderThickness = Divide(gp.BorderThickness, canvas_width, canvas_height); gp.CornerRadius = Divide(gp.CornerRadius, canvas_width, canvas_height); } // 记忆 _canvas_width = canvas_width; _canvas_height = canvas_height; InitialSize(); SetBackgroundImage(); }
static double _delay = 0.02; // 下一个门启动动画的延迟时间(秒) public void AnimateDoors() { double start = 0; App.Invoke(new Action(() => { // 遍历 Grid 对象 foreach (Button button in this.canvas.Children) { if (button == null) { continue; } { if (button == null) { continue; } var door = button.DataContext as DoorItem; if (door.State == "open") { continue; } var borders = GetChildOfType <Border>(button); var border = borders[borders.Count - 1]; // https://docs.microsoft.com/en-us/dotnet/framework/wpf/graphics-multimedia/how-to-animate-color-by-using-key-frames ColorAnimationUsingKeyFrames colorAnimation = new ColorAnimationUsingKeyFrames(); colorAnimation.Duration = TimeSpan.FromSeconds(start + _length); Color oldColor = Colors.Black; if (door.CloseBrush is SolidColorBrush) { oldColor = DoorItem.FromColor((door.CloseBrush as SolidColorBrush).Color, 255); // door.CloseBrush; } Color brightColor = Colors.White; if (door.OpenBrush is SolidColorBrush) { brightColor = DoorItem.FromColor((door.OpenBrush as SolidColorBrush).Color, 255); // door.CloseBrush; } colorAnimation.KeyFrames.Add( new LinearColorKeyFrame( brightColor, // Colors.DarkOrange, // Target value (KeyValue) KeyTime.FromTimeSpan(TimeSpan.FromSeconds(start + _top))) // KeyTime ); colorAnimation.KeyFrames.Add( new LinearColorKeyFrame( oldColor, // Target value (KeyValue) KeyTime.FromTimeSpan(TimeSpan.FromSeconds(start + _length))) // KeyTime ); //Binding save = BindingOperations.GetBinding(border, Border.BackgroundProperty); // 2020/7/12 // SolidColorBrush temp = border.Background as SolidColorBrush; //if (border.Background != null) // border.Background = border.Background.CloneCurrentValue(); // new SolidColorBrush(temp != null ? temp.Color : Colors.Black); border.Background = new SolidColorBrush(oldColor); colorAnimation.FillBehavior = FillBehavior.Stop; colorAnimation.Completed += (s, e) => { border.Background = null; // border.Background.BeginAnimation(SolidColorBrush.ColorProperty, null); // border.Background = new SolidColorBrush(Colors.Red); // BindingOperations.SetBinding(border, Border.BackgroundProperty, save); }; border.Background.BeginAnimation(SolidColorBrush.ColorProperty, colorAnimation); start += _delay; } } })); }