Exemplo n.º 1
0
        private void CreateSortButton(Control ctr, string name, IFactor factor = null,
                                      SortingModes sortMode = SortingModes.PositionAll)
        {
            Button btn = new Button
            {
                Text    = @"S",
                Size    = new Size(15, 20),
                Enabled = Stock.AllStocksInListAnalyzed
            };

            SortButtons.Add(btn);
            ctr.Parent.Controls.Add(btn);
            btn.BringToFront();
            btn.Location = new Point(ctr.Location.X + ctr.Width + (factor == null ? 12 : factor is Metric ? 30 : 40),
                                     ctr.Location.Y - 2);
            btn.Click += (o, args) =>
            {
                sortMode = factor is Coefficient ? SortingModes.Coefficeint :
                           factor is Metric ? SortingModes.Metric : sortMode;
                SortList(sortMode, m_selectedList.StList.ToList(), factor);
            };
            var text = "Sort";

            Label tb = null;

            btn.MouseEnter += (o, args) =>
            {
                var sender = o as Control ?? throw new ArgumentNullException();
                if (tb == null)
                {
                    tb = new Label
                    {
                        Margin      = new Padding(4),
                        Name        = $"textBoxHelp_{name}",
                        BorderStyle = BorderStyle.Fixed3D,
                        Text        = text,
                        AutoSize    = true
                    };
                    int x = sender.Location.X;
                    int y = sender.Location.Y;
                    tb.Font     = new Font(tb.Font.FontFamily, tb.Font.Size + 1);
                    tb.Location = new Point(x - sender.Width / 2, y - sender.Height + 1);
                    btn.Parent.Controls.Add(tb);
                    tb.BringToFront();
                }
                else
                {
                    tb.Visible = true;
                    tb.BringToFront();
                }
            };
            btn.MouseLeave += (o, args) => { tb.Visible = false; };
        }
Exemplo n.º 2
0
        /// <summary>
        /// Сортирует список по указанной метрике
        /// </summary>
        /// <param name="regime">0-MainPE, 1-Main, 2-MainAll</param>
        /// <param name="lst">Список акций</param>
        /// <param name="factor">Коэффициент или метрика</param>
        private void SortList(SortingModes regime, List <Stock> lst, IFactor factor)
        {
            if (!Stock.AllStocksInListAnalyzed)
            {
                ButtonAnalyzeMultiplicators_Click(null, null);
            }
            comboBoxStocks.Items.Clear();
            lst.Sort((s1, s2) =>
            {
                switch (regime)
                {
                case SortingModes.PositionAll:
                    return(s1.AveragePositionAll > s2.AveragePositionAll ? 1 :
                           Math.Abs(s1.AveragePositionAll - s2.AveragePositionAll) < Const.Tolerance ? 0 : -1);

                case SortingModes.PositionMetric:
                    return(s1.AveragePositionMetric > s2.AveragePositionMetric ? 1 :
                           Math.Abs(s1.AveragePositionMetric - s2.AveragePositionMetric) < Const.Tolerance ? 0 : -1);

                case SortingModes.PositionCoef:
                    return(s1.AveragePositionNormalizedCoefs > s2.AveragePositionNormalizedCoefs ? 1 :
                           Math.Abs(s1.AveragePositionNormalizedCoefs - s2.AveragePositionNormalizedCoefs) <
                           Const.Tolerance ? 0 : -1);

                case SortingModes.Coefficeint:
                    var coef = factor as Coefficient;
                    if (coef == null)
                    {
                        throw new ArgumentNullException(nameof(factor));
                    }
                    var v1 = s1.NormalizedCoefficientsValues[coef];
                    var v2 = s2.NormalizedCoefficientsValues[coef];
                    if (v1.HasValue && v2.HasValue)
                    {
                        return(v1 < v2 ? 1 : Math.Abs(v1.Value - v2.Value) < Const.Tolerance ? 0 : -1);
                    }
                    if (v1.HasValue && !v2.HasValue)
                    {
                        return(-1);
                    }
                    if (!v1.HasValue && v2.HasValue)
                    {
                        return(1);
                    }
                    return(0);

                case SortingModes.Metric:
                    var metric = factor as Metric;
                    if (metric == null)
                    {
                        throw new ArgumentNullException(nameof(factor));
                    }
                    var m1 = s1.MetricsValues[metric];
                    var m2 = s2.MetricsValues[metric];
                    return(m1 < m2 ? 1 : Math.Abs(m1 - m2) < Const.Tolerance ? 0 : -1);
                }

                throw new NotSupportedException("In sort list");
            });
            foreach (var st in lst)
            {
                comboBoxStocks.Items.Add(st.FullName);
            }
        }
Exemplo n.º 3
0
 public SortingField(string fieldName, SortingModes sotinMode = SortingModes.Ascending)
 {
     FieldName   = fieldName;
     SortingMode = sotinMode;
 }