Exemplo n.º 1
0
        private void OnLostFocus(object sender, RoutedEventArgs e)
        {
            if (base.IsReadOnly)
            {
                return;
            }
            base.Background = Consts.WHITE_BRUSH;
            var txt = GetValue(TextProperty).ToString();
            var obj = AccountSubjectList.FindByNo(txt.Trim());

            Value = obj;
            if (Id != oldId)
            {
                DataChangedEvent?.Invoke(this,
                                         new DataChangedArgs {
                    OldValue = oldId,
                    NewValue = Id
                });
            }
            if (DisplayHookEvent != null)
            {
                var args = new DisplayHookArgs();
                args.Value = obj;
                DisplayHookEvent.Invoke(this, args);
                SetValue(TextProperty, args.Text);
            }
            else
            {
                SetValue(TextProperty, obj.FullName);
            }
        }
Exemplo n.º 2
0
 void Display()
 {
     mChildrenList.ForEach(n => xPanel.UnregisterName(n));
     xPanel.Children.Clear();
     mChildrenList.Clear();
     foreach (var item in mDataSource)
     {
         UserDefineInput input = new UserDefineInput();
         input.IsEnabled         = this.IsEnabled;
         input.Width             = item.Width == 0 ? 220 : (90 + item.Width);
         input.TagLabel          = item.TagLabel;
         input.Label             = item.Label;
         input.DataType          = item.DataType;
         input.DataValue         = item.DataValue;
         input.Margin            = new Thickness(0, 5, 0, 0);
         input.Name              = this.Name + "_" + item.Name;
         input.DataChangedEvent += new DataChangedEventHandler((sender, e) => {
             DataChangedEvent?.Invoke(sender, e);
             if (e.Cancel)
             {
                 mCanceled = true;
             }
         });
         xPanel.RegisterName(input.Name, input);
         mChildrenList.Add(input.Name);
         xPanel.Children.Add(input);
     }
 }
        public override int SaveChanges()
        {
            if (!TrackChanges)
            {
                return(base.SaveChanges());
            }
            string userId     = (_contextAccessor.HttpContext.User.Identity as ClaimsIdentity).Claims.First(claim => claim.Type == ClaimTypes.PrimarySid).Value;
            var    changeList = ChangeTracker.Entries()
                                .Where(p => p.State == EntityState.Added || p.State == EntityState.Deleted || p.State == EntityState.Modified)
                                .SelectMany(entity => GetAuditRecordsForChange(entity, userId)).ToList();

            foreach (var log in changeList)
            {
                AuditLogs.Add(log);
            }
            var ret = base.SaveChanges();

            foreach (var log in changeList)
            {
                _dataChanged?.Invoke(this, Mapper.Map <AuditLog, DataChangedEventArgs>(log));
            }
            return(ret);
        }
Exemplo n.º 4
0
 private void OnLostFocus(object sender, RoutedEventArgs e)
 {
     if (base.IsReadOnly)
     {
         return;
     }
     FillAccountSubject();
     base.Background = Consts.WHITE_BRUSH;
     if (Id != oldId)
     {
         DataChangedEvent?.Invoke(this,
                                  new DataChangedArgs {
             OldValue = oldId,
             NewValue = Id
         });
     }
 }
            /// <summary>
            /// Called when a data changed event is received.
            /// </summary>
            public void OnEvent(
                int hClientSubscription,
                int bRefresh,
                int bLastRefresh,
                int dwCount,
                ONEVENTSTRUCT[] pEvents)
            {
                LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.AlarmsConditions, true);
                try
                {
                    lock (this)
                    {
                        // do nothing if no connections.
                        if (DataChangedEventHandler == null)
                        {
                            return;
                        }

                        // un marshal item values.
                        TsCAeEventNotification[] notifications = Interop.GetEventNotifications(pEvents);

                        foreach (var notification in notifications)
                        {
                            notification.ClientHandle = clientHandle_;
                        }

                        if (!LicenseHandler.IsExpired)
                        {
                            // invoke the callback.
                            DataChangedEventHandler?.Invoke(notifications, bRefresh != 0, bLastRefresh != 0);
                        }
                    }
                }
                catch (Exception e)
                {
                    Utils.Trace(e, "Exception '{0}' in event handler.", e.Message);

                    string stack = e.StackTrace;
                }
            }
Exemplo n.º 6
0
        /// <summary>
        /// 显示
        /// </summary>
        void Display()
        {
            if (IsEnabled && TagLabel.StartsWith("comb|"))
            {
                DisplayCombBox();
                return;
            }
            xCombBox.Visibility = Visibility.Hidden;
            if (mValue == null)
            {
                xString.Text = "";
            }
            else
            {
                xString.Text = Convert.ToString(mValue);
            }

            if (!IsEnabled)
            {
                xString.BorderThickness = new Thickness(0, 0, 0, 1);
                return;
            }

            if (DataType == typeof(long) || DataType == typeof(decimal) || DataType == typeof(byte) ||
                DataType == typeof(sbyte) || DataType == typeof(short) || DataType == typeof(int) ||
                DataType == typeof(ushort) || DataType == typeof(uint) || DataType == typeof(ulong) ||
                DataType == typeof(float) || DataType == typeof(double))
            {
                xString.HorizontalContentAlignment = HorizontalAlignment.Right;
            }
            xString.PreviewMouseDown += XString_PreviewMouseDown;
            xString.GotFocus         += new RoutedEventHandler((sender, e) =>
            {
                xString.SelectAll();
                xString.PreviewMouseDown -= XString_PreviewMouseDown;
                e.Handled = true;
            });
            xString.KeyDown += new KeyEventHandler((sender, e) => {
                if (e.Key == Key.Enter)
                {
                    Commons.Keyboard.Press(Key.Tab);
                }
            });
            xString.LostFocus += new RoutedEventHandler((sender, e) => {
                xString.PreviewMouseDown += XString_PreviewMouseDown;
                object defaultValue       = DataType.IsValueType ? Activator.CreateInstance(DataType) : null;
                bool err = false;
                try
                {
                    object oldValue = mValue;
                    mValue          = Convert.ChangeType(xString.Text, DataType);
                    if (mValue == defaultValue)
                    {
                        throw new Exception();
                    }
                    if (oldValue == mValue)
                    {
                        return;
                    }
                    DataChangedArgs args = new DataChangedArgs
                    {
                        Name     = this.Name,
                        OldValue = oldValue,
                        NewValue = mValue,
                        Cancel   = false,
                        DataType = DataType
                    };
                    DataChangedEvent?.Invoke(this, args);
                    if (args.Cancel)
                    {
                        Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background,
                                               new Action(() =>
                        {
                            if (oldValue == null)
                            {
                                xString.Text = "";
                            }
                            else
                            {
                                xString.Text = Convert.ToString(oldValue);
                            }
                            if (err)
                            {
                                xString.SelectAll();
                            }
                        }));
                        e.Handled = true;
                    }
                }
                catch
                {
                    mValue    = defaultValue;
                    e.Handled = true;
                    err       = true;
                }
                finally
                {
                    Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background,
                                           new Action(() =>
                    {
                        if (mValue == null)
                        {
                            xString.Text = "";
                        }
                        else
                        {
                            xString.Text = Convert.ToString(mValue);
                        }
                        if (err)
                        {
                            xString.SelectAll();
                        }
                    }));
                }
            });
        }