Exemplo n.º 1
0
        static void Main(string[] args)
        {
            MinVal min1 = new MinVal(1, 5, 6, 7, 8, 9, -2);

            Console.WriteLine(min1.Min());
            MinVal min2 = new MinVal();

            Console.WriteLine(min2.Min());

            Console.ReadKey();
        }
Exemplo n.º 2
0
        public string CheckField(UniversalEditorField field, object value)
        {
            string errText = "Поле \"" + field.HeaderText + "\" должно быть ";

            if (MinVal != decimal.MinValue)
            {
                errText += "больше " + MinVal.ToUniString();
            }
            if (MinVal != decimal.MinValue && MaxVal != decimal.MaxValue)
            {
                errText += " и ";
            }
            if (MaxVal != decimal.MaxValue)
            {
                errText += "меньше " + MaxVal.ToUniString();
            }
            var obj = value.ToTypedObject(field.DataType);

            if (obj == null)
            {
                if (field.DataType == typeof(decimal))
                {
                    obj = (value ?? "").ToString().Replace(",", ".").ToTypedObject(field.DataType) ??
                          (value ?? "").ToString().Replace(".", ",").ToTypedObject(field.DataType);
                }
            }
            if (obj == null)
            {
                return(errText);
            }
            if (obj is decimal)
            {
                if ((decimal)obj <= MinVal || (decimal)obj >= MaxVal)
                {
                    return(errText);
                }
            }
            if (obj is int)
            {
                if ((int)obj <= MinVal || (int)obj >= MaxVal)
                {
                    return(errText);
                }
            }
            return("");
        }
 /// <summary>
 /// Sets the minimum.
 /// </summary>
 /// <param name="value">The value.</param>
 /// <returns></returns>
 public double SetMin(string value)
 {
     MinVal.Text = value;
     MinVal.UpdateLayout();
     return(MinVal.ActualWidth);
 }
        private void DrawDataSet(Graphics g, Rectangle rc, double[] data, Color color)
        {
            double min = MinVal.GetValueOrDefault();
            double max = MaxVal.GetValueOrDefault();

            int dataSetLen = data.Length;

            Point last = new Point(rc.Left,
                                   (max == min) ? rc.Bottom - rc.Height / 2 :
                                   rc.Bottom - (int)((data[0] - min) * rc.Height / (max - min)));

            for (double i = 0; i < data.Length; i++)
            {
                try
                {
                    Point pt = Point.Empty;

                    double val = Math.Min(max, Math.Max(min, data[(int)i]));

                    int y =
                        (max == min) ? rc.Bottom - rc.Height / 2 :
                        rc.Bottom - (int)((val - min) * rc.Height / (max - min));

                    int w = (int)Math.Round((float)rc.Width / (float)dataSetLen);
                    if (w < 1)
                    {
                        w = 1;
                    }

                    int x = 0;
                    if (LogarithmicXAxis)
                    {
                        double logXDomain = Math.Abs(Math.Log((double)1 / data.Length));
                        x = rc.Left + (int)((logXDomain + Math.Log(i / data.Length)) * rc.Width / logXDomain);
                    }
                    else
                    {
                        x = rc.Left + (int)(i * rc.Width / data.Length);
                    }

                    pt = new Point(x, y);

                    if (IsHistogram)
                    {
                        if (color == Color.Transparent)
                        {
                            DrawCustomHistoBar(g, rc, w, pt);
                        }
                        else
                        {
                            using (Brush b = new SolidBrush(color))
                            {
                                Rectangle rcBar = new Rectangle(pt.X - w, pt.Y, w, rc.Bottom - pt.Y);
                                g.FillRectangle(b, rcBar);
                            }
                        }
                    }
                    else
                    {
                        using (Pen pen = new Pen(color, 1.51f))
                        {
                            g.DrawLine(pen, last, pt);
                        }

                        last = pt;
                    }
                }
                catch (Exception ex)
                {
                    string s = ex.Message;
                }
            }
        }