Esempio n. 1
0
        private void AmountInput_BeforeInput(object sender, BeforeInputEventArgs e)
        {
            AmountInputBox input              = sender as AmountInputBox;
            var            rowIndex           = int.Parse(input.Name.Substring(m_LastFocusControl.IndexOf("_") + 1));
            var            aInputCreditAmount = GetAmountInputBoxByName("aInputCredit_" + rowIndex).Value;
            var            aInputDebitsAmount = GetAmountInputBoxByName("aInputDebits_" + rowIndex).Value;

            if (input.Name.StartsWith("aInputCredit_") && aInputDebitsAmount > 0)
            {
                e.Disable = true;
            }
            else if (input.Name.StartsWith("aInputDebits_") && aInputCreditAmount > 0)
            {
                e.Disable = true;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 生效,把数据刷到界面上
        /// </summary>
        public void Refresh()
        {
            LogDebug(string.Format("Refresh[{0}]", m_DataSource.Count));
            ReleaseControls();
            if (grid.RowDefinitions.Count > 0)
            {
                grid.RowDefinitions.RemoveRange(0, grid.RowDefinitions.Count);
            }
            int index = 0;

            m_DataSource.ForEach(item =>
            {
                var row    = new RowDefinition();
                row.Height = new GridLength(60);
                grid.RowDefinitions.Add(row);

                Label lblIndex      = new Label();
                lblIndex.Name       = "lblIndex_" + index;
                lblIndex.Background = Consts.HIGHLIGHT_BRUSH;
                lblIndex.VerticalContentAlignment = VerticalAlignment.Center;
                lblIndex.BorderBrush     = Consts.BLACK_BRUSH;
                lblIndex.BorderThickness = new Thickness(1, 0, 1, 1);
                lblIndex.Content         = index + 1;
                lblIndex.GotFocus       += Row_GotFocus;
                lblIndex.Tag             = item.UniqueKey;

                grid.RegisterName("lblIndex_" + index, lblIndex);
                grid.Children.Add(lblIndex);
                m_Controls[index, 0] = "lblIndex_" + index;
                lblIndex.SetValue(Grid.RowProperty, index);
                lblIndex.SetValue(Grid.ColumnProperty, 0);

                AuxiliaryBox txtContent    = new AuxiliaryBox();
                txtContent.Name            = "txtContent_" + index;
                txtContent.BorderBrush     = Consts.BLACK_BRUSH;
                txtContent.BorderThickness = new Thickness(0, 0, 1, 1);
                txtContent.TextWrapping    = TextWrapping.Wrap;
                txtContent.Text            = item.Content;
                txtContent.GotFocus       += Row_GotFocus;
                txtContent.TabIndex        = this.TabIndex + index * 4 + 0;

                grid.RegisterName("txtContent_" + index, txtContent);
                grid.Children.Add(txtContent);
                m_Controls[index, 1] = "txtContent_" + index;
                Grid.SetRow(txtContent, index);
                Grid.SetColumn(txtContent, 1);

                AccountSubjectBox txtAccountSubject = new AccountSubjectBox();
                txtAccountSubject.Name            = "txtAccountSubject_" + index;
                txtAccountSubject.BorderBrush     = Consts.BLACK_BRUSH;
                txtAccountSubject.BorderThickness = new Thickness(0, 0, 1, 1);
                txtAccountSubject.Id                = item.AccountSubjectId;
                txtAccountSubject.IsReadOnly        = this.IsReadOnly;
                txtAccountSubject.GotFocus         += Row_GotFocus;
                txtAccountSubject.DataChangedEvent += (sender, e) => {
                    if (CurrentRowIndex < 0 || CurrentRowIndex >= m_DataSource.Count)
                    {
                        return;
                    }
                    e.Name = m_DataSource[CurrentRowIndex].UniqueKey;
                    AccountSubjectChangeEvent?.Invoke(sender, e);
                    var actSubjectObj = txtAccountSubject.Value;
                    if ((actSubjectObj.flag & (int)AccountFlag.FLAG_USDEF_MASK) != 0)
                    {
                        AdornerHelper.SetHasAdorner(txtAccountSubject, 1);
                    }
                    else
                    {
                        AdornerHelper.SetHasAdorner(txtAccountSubject, 0);
                    }
                };
                txtAccountSubject.KeyDown += (sender, e) => {
                    if (IsReadOnly)
                    {
                        return;
                    }
                    CellKeyDownEvent?.Invoke(sender, e);
                };
                txtAccountSubject.TabIndex = this.TabIndex + index * 4 + 1;
                grid.RegisterName("txtAccountSubject_" + index, txtAccountSubject);
                grid.Children.Add(txtAccountSubject);
                m_Controls[index, 2] = "txtAccountSubject_" + index;
                Grid.SetRow(txtAccountSubject, index);
                Grid.SetColumn(txtAccountSubject, 2);
                if ((item.AccountSubject.flag & (int)AccountFlag.FLAG_USDEF_MASK) != 0)
                {
                    AdornerHelper.SetHasAdorner(txtAccountSubject, 1);
                }

                AmountInputBox aInputDebits    = new AmountInputBox();
                aInputDebits.Name              = "aInputDebits_" + index;
                aInputDebits.BorderBrush       = Consts.BLACK_BRUSH;
                aInputDebits.BorderThickness   = new Thickness(0, 0, 1, 1);
                aInputDebits.Value             = item.DebitsAmount;
                aInputDebits.IsEnabled         = !this.IsReadOnly;
                aInputDebits.GotFocus         += Row_GotFocus;
                aInputDebits.LostFocus        += AInputDebits_LostFocus;
                aInputDebits.KeyDown          += AInputDebits_KeyDown;
                aInputDebits.TabIndex          = this.TabIndex + index * 4 + 2;
                aInputDebits.BeforeInputEvent += AmountInput_BeforeInput;
                grid.RegisterName("aInputDebits_" + index, aInputDebits);
                grid.Children.Add(aInputDebits);
                m_Controls[index, 3] = "aInputDebits_" + index;
                Grid.SetRow(aInputDebits, index);
                Grid.SetColumn(aInputDebits, 3);

                AmountInputBox aInputCredit    = new AmountInputBox();
                aInputCredit.Name              = "aInputCredit_" + index;
                aInputCredit.BorderBrush       = Consts.BLACK_BRUSH;
                aInputCredit.BorderThickness   = new Thickness(0, 0, 1, 1);
                aInputCredit.Value             = item.CreditAmount;
                aInputCredit.IsEnabled         = !this.IsReadOnly;
                aInputCredit.GotFocus         += Row_GotFocus;
                aInputCredit.LostFocus        += AInputCredit_LostFocus;
                aInputCredit.KeyDown          += AInputDebits_KeyDown;
                aInputCredit.TabIndex          = this.TabIndex + index * 4 + 3;
                aInputCredit.BeforeInputEvent += AmountInput_BeforeInput;
                grid.RegisterName("aInputCredit_" + index, aInputCredit);
                grid.Children.Add(aInputCredit);
                m_Controls[index, 4] = "aInputCredit_" + index;
                Grid.SetRow(aInputCredit, index);
                Grid.SetColumn(aInputCredit, 4);

                index++;
            });
            //if (index > 0)
            //    CurrentRowIndex = 0;
            CalcTotal();
            SetLastFocus();
        }