Пример #1
0
        void dotBig_MouseEnter(object sender, MouseEventArgs e)
        {
            if (IsHovering)
            {
                return;                //don't jump when two big dots overlap
            }
            int idxPath = -1;
            int idxDot  = -1;

            for (int i = 0; i < ListDotsBig.Count; i++)
            {
                if (visibleIndices != null && visibleIndices.Count > 0 && !visibleIndices.Contains(i))
                {
                    continue;
                }
                if (ListDotsBig[i].IndexOf((Ellipse)sender) == -1)
                {
                    continue;
                }
                idxPath = i;
                idxDot  = ListDotsBig[i].IndexOf((Ellipse)sender);
            }
            if (idxDot == -1)
            {
                return;
            }
            labelHover.Opacity = 1;
            string numFormat = "n0";

            if (YMultFactor == 1000)
            {
                numFormat = "c0";
            }
            string content = DateStart.AddMonths(idxDot).ToString("MMM") + ": " + ListData[idxPath][idxDot].ToString(numFormat);

            labelHover.Content = content;
            double        xCenter  = Canvas.GetLeft((Ellipse)sender) + 7;
            double        yCenter  = Canvas.GetTop((Ellipse)sender) + 7;
            Typeface      typeface = new Typeface(FontFamily, FontStyle, FontWeight, FontStretch);
            FormattedText ft       = new FormattedText(labelHover.Content.ToString(),
                                                       CultureInfo.CurrentCulture, FlowDirection.LeftToRight, typeface, FontSize, Foreground);
            double wText = ft.Width;

            Canvas.SetLeft(labelHover, xCenter - wText / 2d - 1);
            Canvas.SetTop(labelHover, yCenter - 23);
            Panel.SetZIndex(labelHover, 8);           //bring to front of other element
            IsHovering = true;
        }
Пример #2
0
        public void calculateExpiryDate()
        {
            if (string.IsNullOrEmpty(start_date.Text.Replace(" ", "").Replace("/", "").Trim()))
            {
                expiry_date.Text = "-";
                return;
            }

            if (start_date.Text.Trim().Length < 10)
            {
                expiry_date.Text = "-";
                return;
            }

            if (string.IsNullOrEmpty(age.Text.Trim()))
            {
                expiry_date.Text = "-";
                return;
            }

            if (Convert.ToInt32(age.Text.Trim()) <= 0)
            {
                expiry_date.Text = "-";
                return;
            }

            int months = Convert.ToInt32(age.Text.Trim());

            string[] tmpDate = start_date.Text.Split('/');

            if (!DateTime.TryParse(((Convert.ToInt32(tmpDate[2]) - 543)).ToString("0000") + "-" + Convert.ToInt32(tmpDate[1]).ToString("00") + "-" + Convert.ToInt32(tmpDate[0]).ToString("00"), out var DateStart))
            {
                string errTxt = "วัน เดือน ปี ไม่อยู่ในรูปแบบที่ถูกต้อง !\r\nค่าปัจจุบัน : " + start_date;
                GF.printError("***" + errTxt + "*** (DateTime.TryParse @ member_pt.calculateExpiryDate)");
                //GF.submitErrorLog();
                GF.Error(errTxt);
                return;
            }

            DateTime DateEnd = DateStart.AddMonths(months).AddDays(-1);

            expiry_date.Text = DateEnd.Day.ToString("00") + "/" + DateEnd.Month.ToString("00") + "/" + (DateEnd.Year + 543).ToString("0000");
        }
Пример #3
0
        private void FillGraph()
        {
            double wCol = rectMain.Width / 11d;

            //vertical lines----------------------------------------------------------------------
            for (double i = 1; i < 11; i++)
            {
                Line line = new Line();
                line.X1              = rectMain.Left() + (i * wCol);
                line.Y1              = rectMain.Top();
                line.X2              = rectMain.Left() + (i * wCol);
                line.Y2              = rectMain.Bottom();
                line.Stroke          = Brushes.LightGray;
                line.StrokeThickness = 1;
                canvasMain.Children.Add(line);
                //year marker
                if (DateStart.AddMonths((int)i).Month == 1)
                {
                    line                 = new Line();
                    line.X1              = rectMain.Left() + (i * wCol) - wCol / 2d;
                    line.Y1              = rectMain.Top();
                    line.X2              = rectMain.Left() + (i * wCol) - wCol / 2d;
                    line.Y2              = rectMain.Bottom();
                    line.Stroke          = Brushes.Black;
                    line.StrokeThickness = 1.5;
                    Canvas.SetZIndex(line, 5);                   //same as grid outline, causing horizontal lines to go under
                    canvasMain.Children.Add(line);
                }
            }
            //x axis numbers-----------------------------------------------------------------------
            for (double i = 0; i < 12; i++)
            {
                Label  label   = new Label();
                string content = DateStart.AddMonths((int)i).ToString("%M");
                label.Content  = content;
                label.MaxWidth = 100;
                Canvas.SetTop(label, rectMain.Bottom() - 4);
                Typeface      typeface = new Typeface(FontFamily, FontStyle, FontWeight, FontStretch);
                FormattedText ft       = new FormattedText(content, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, typeface, FontSize, Foreground);
                double        wText    = ft.Width;
                //Debug.WriteLine(content+": "+wText.ToString("F0"));
                Canvas.SetLeft(label, rectMain.Left() + (i * wCol) - wText / 2d - 5);
                canvasMain.Children.Add(label);
            }
            //calculate max y and increments---------------------------------------------------------
            double maxValD = 0;

            for (int p = 0; p < ListData.Count; p++)
            {
                for (int i = 0; i < ListData[p].Count; i++)
                {
                    if ((ListData[p][i] / YMultFactor) > maxValD)
                    {
                        maxValD = (double)ListData[p][i] / YMultFactor;
                    }
                }
            }
            //add 5% for white space
            maxValD = 1.05 * maxValD;
            //round up to nearest int. This is important if the max is just over 1k.
            int maxVal = (int)maxValD + 1;

            //calculate amount for each tick.  No more than 10 ticks
            //replace the code below later with a more elegant algorithm to handle unlimited scaling
            YIncrement = 1;
            if (maxVal > 10)
            {
                YIncrement = 2;
            }
            if (maxVal > 20)
            {
                YIncrement = 5;
            }
            if (maxVal > 50)
            {
                YIncrement = 10;
            }
            if (maxVal > 100)
            {
                YIncrement = 20;
            }
            if (maxVal > 200)
            {
                YIncrement = 50;
            }
            //etc
            //int yCount=(int)(maxVal/10000);
            //double hRow=rectMain.Height/(yCount-1);
            double hRow      = rectMain.Height / (double)maxVal * (double)YIncrement; //in pixels
            int    tickCount = (int)(rectMain.Height / hRow);                         //trunc to int. Does not include the tick at zero.

            //horizontal lines----------------------------------------------------------------------
            for (double i = 0; i < tickCount; i++)
            {
                //the first tick is not at zero
                Line line = new Line();
                line.X1              = rectMain.Left();
                line.Y1              = rectMain.Bottom() - ((i + 1) * hRow);
                line.X2              = rectMain.Right();
                line.Y2              = rectMain.Bottom() - ((i + 1) * hRow);
                line.Stroke          = Brushes.LightGray;
                line.StrokeThickness = 1;
                canvasMain.Children.Add(line);
            }
            //y axis numbers-----------------------------------------------------------------------
            for (double i = 0; i < tickCount; i++)
            {
                Label  label   = new Label();
                string content = ((i + 1) * YIncrement).ToString();
                if (YMultFactor == 1000)
                {
                    content = content + "k";
                }
                label.Content  = content;
                label.MaxWidth = 200;
                Canvas.SetTop(label, rectMain.Bottom() - ((i + 1) * hRow) - 14);
                Canvas.SetLeft(label, -3);
                label.Width = rectMain.Left() + 5;
                label.HorizontalContentAlignment = HorizontalAlignment.Right;
                canvasMain.Children.Add(label);
            }
            //Initialize-----------------------------------------------------------------------------
            ListPaths   = new List <Path>();
            ListDots    = new List <List <Ellipse> >();
            ListDotsBig = new List <List <Ellipse> >();
            //Paths and dots-------------------------------------------------------------------------
            for (int p = 0; p < ListData.Count; p++)
            {
                PathFigure     pathFig            = new PathFigure();
                List <Ellipse> listDotsOneType    = new List <Ellipse>();
                List <Ellipse> listDotsBigOneType = new List <Ellipse>();
                for (int i = 0; i < ListData[p].Count; i++)
                {
                    Point pt = new Point(rectMain.Left() + (i * wCol), rectMain.Bottom() - (double)((double)ListData[p][i] / YMultFactor * hRow / (double)YIncrement));
                    if (i == 0)
                    {
                        pt.X += 1;
                    }
                    if (i == ListData[p].Count - 1)
                    {
                        pt.X -= 1;
                    }
                    if (i == 0)
                    {
                        pathFig.StartPoint = pt;
                    }
                    else
                    {
                        LineSegment lineSeg = new LineSegment();
                        lineSeg.Point = pt;
                        pathFig.Segments.Add(lineSeg);
                    }
                    //dots
                    Ellipse ellipse = new Ellipse();
                    ellipse.Height = 4;
                    ellipse.Width  = 4;
                    Canvas.SetLeft(ellipse, pt.X - 2);
                    Canvas.SetTop(ellipse, pt.Y - 2);
                    ellipse.Fill = new SolidColorBrush(ListColors[p]);
                    Panel.SetZIndex(ellipse, 6);
                    canvasMain.Children.Add(ellipse);
                    listDotsOneType.Add(ellipse);
                    //dotsBig
                    ellipse        = new Ellipse();
                    ellipse.Height = 14;
                    ellipse.Width  = 14;
                    Canvas.SetLeft(ellipse, pt.X - 7);
                    Canvas.SetTop(ellipse, pt.Y - 7);
                    ellipse.Opacity = 0;
                    ellipse.Fill    = Brushes.Red;
                    Panel.SetZIndex(ellipse, 7);                   //in front of everything
                    ellipse.MouseEnter += new MouseEventHandler(dotBig_MouseEnter);
                    ellipse.MouseLeave += new MouseEventHandler(dotBig_MouseLeave);
                    canvasMain.Children.Add(ellipse);
                    listDotsBigOneType.Add(ellipse);
                }
                PathGeometry pathGeo = new PathGeometry();
                pathGeo.Figures.Add(pathFig);
                Path path = new Path();
                path.Data            = pathGeo;
                path.Stroke          = new SolidColorBrush(ListColors[p]);
                path.StrokeThickness = 1.5;
                Panel.SetZIndex(path, 6);               //in front of grid
                canvasMain.Children.Add(path);
                ListPaths.Add(path);
                ListDots.Add(listDotsOneType);
                ListDotsBig.Add(listDotsBigOneType);
            }
        }
Пример #4
0
 public override DateTime GetDateEnd()
 {
     DateEnd = DateStart.AddMonths(period);
     return(DateEnd);
 }
Пример #5
0
 private void CalculateDateBounds()
 {
     DateStart = DateTime.Now;
     DateEnd   = DateStart.AddMonths(Constants.DefaultModuleLengthMonth);
 }