public static bool?Show(ref FilterSizeModel fzModel)
        {
            if (fzModel == null)
            {
                fzModel = new FilterSizeModel();
            }

            var window = new FilterSizeWindow(fzModel);

            window.ShowDialog();
            return(window.FilterResult);
        }
 private IEnumerable <object> FilterSizeRow(IEnumerable <object> rows, FilterSizeModel fzModel, Func <object, long> szFunc)
 {
     if (fzModel.Condition == TwoConditionRule.MinOnly)
     {
         rows = rows.Where(p => szFunc(p) >= (fzModel.MinSize ?? 0));
     }
     else if (fzModel.Condition == TwoConditionRule.MaxOnly)
     {
         rows = rows.Where(p => szFunc(p) <= (fzModel.MaxSize ?? 0));
     }
     else if (fzModel.Condition == TwoConditionRule.MinOrMax)
     {
         rows = rows.Where(p => szFunc(p) <= (fzModel.MaxSize ?? 0) || szFunc(p) >= (fzModel.MinSize));
     }
     else if (fzModel.Condition == TwoConditionRule.MinAndMax)
     {
         rows = rows.Where(p => szFunc(p) <= (fzModel.MaxSize ?? 0) && szFunc(p) >= (fzModel.MinSize));
     }
     return(rows);
 }
Esempio n. 3
0
        public FilterSizeWindow(FilterSizeModel fzModel)
        {
            InitializeComponent();
            InitializeEvents();

            if (fzModel == null)
            {
                throw new ArgumentNullException(nameof(fzModel));
            }

            this.FilterSizeModel = fzModel;
            if (fzModel.MaxSize != null)
            {
                txbfewer.Text = (fzModel.MaxSize / 1024).ToString();
            }
            if (fzModel.MinSize != null)
            {
                txbLarger.Text = (fzModel.MinSize / 1024).ToString();
            }

            switch (fzModel.Condition)
            {
            case TwoConditionRule.MinAndMax:
            case TwoConditionRule.MinOrMax:
                chbfewer.IsChecked  = true;
                chbLarger.IsChecked = true;
                break;

            case TwoConditionRule.MinOnly:
                chbLarger.IsChecked = true;
                break;

            case TwoConditionRule.MaxOnly:
                chbfewer.IsChecked = true;
                break;
            }

            if (fzModel.MaxUnitSize != null)
            {
                foreach (var item in cmbfewer.Items)
                {
                    var comboItem = item as ComboBoxItem;
                    if (comboItem != null)
                    {
                        if (comboItem.Content.ToString() == fzModel.MaxUnitSize)
                        {
                            cmbfewer.SelectedItem = comboItem;
                            txbfewer.Text         = GetSizeStringBy(fzModel.MaxUnitSize, fzModel.MaxSize ?? 0);
                            break;
                        }
                    }
                }
            }
            if (fzModel.MinUnitSize != null)
            {
                foreach (var item in cmbLarger.Items)
                {
                    var comboItem = item as ComboBoxItem;
                    if (comboItem != null)
                    {
                        if (comboItem.Content.ToString() == fzModel.MinUnitSize)
                        {
                            cmbLarger.SelectedItem = comboItem;
                            txbLarger.Text         = GetSizeStringBy(fzModel.MinUnitSize, fzModel.MinSize ?? 0);
                            break;
                        }
                    }
                }
            }

            rtbOr.IsChecked = fzModel.Condition == TwoConditionRule.MinOrMax;
        }