コード例 #1
0
        public void UpdateView()
        {
            fWorkTime = fModel.GetWorkTime(fAquarium);

            if (!fWorkTime.WasStarted() || fWorkTime.IsInactive())
            {
                SetTankState(TankState.Inactive);
            }
            else
            {
                SetTankState(TankState.Normal);
            }

            fValues = fModel.CollectData(fAquarium);

            Refresh();
        }
コード例 #2
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            Graphics gfx = e.Graphics;

            ButtonBorderStyle style = (fSelected) ? ButtonBorderStyle.Inset : ButtonBorderStyle.Outset;

            ControlPaint.DrawBorder(e.Graphics, ClientRectangle, Color.Silver, style);

            if (fAquarium == null)
            {
                return;
            }

            var layoutRect = ClientRectangle;

            layoutRect.Inflate(-4, -4);

            Font font = new Font(Font, FontStyle.Bold);

            fStrFormat.Alignment = StringAlignment.Near;
            DrawText(gfx, fAquarium.Name, font, ForeColor, layoutRect);

            double normalWaterVolume = fAquarium.CalcWaterVolume();
            double waterVolume       = fModel.GetWaterVolume(fAquarium.Id);
            string volumes           = ALCore.GetDecimalStr(waterVolume) + " / " + ALCore.GetDecimalStr(normalWaterVolume) + " / " + ALCore.GetDecimalStr(fAquarium.TankVolume);

            fStrFormat.Alignment = StringAlignment.Far;
            Color wvColor = (DoubleHelper.Equals(normalWaterVolume, waterVolume, 0.5)) ? Color.Green : Color.Orange;

            DrawText(gfx, volumes, font, wvColor, layoutRect);

            string works = fWorkTime.GetWorkDays();
            int    x     = layoutRect.Left;
            int    y     = layoutRect.Top + (int)(Font.Height * 1.6f);

            DrawText(gfx, works, Font, ForeColor, x, y);

            Color  wsColor      = ForeColor;
            string waterStatus  = "";
            string waterChanges = "";

            if (!fWorkTime.IsInactive())
            {
                if (!fWorkTime.WasStarted())
                {
                    waterChanges = "---";
                }
                else
                {
                    double avgChangeDays;
                    double lastChangeDays;
                    fModel.GetWaterChangeIntervals(fAquarium.Id, fWorkTime, out avgChangeDays, out lastChangeDays);

                    string avgChange  = "avg=" + ALCore.GetDecimalStr(avgChangeDays, 1) + "d";
                    string lastChange = ", last=" + ALCore.GetDecimalStr(lastChangeDays, 1) + "d";

                    if (lastChangeDays <= avgChangeDays)
                    {
                        waterStatus = " [normal]";
                        wsColor     = Color.Green;
                    }
                    else if (lastChangeDays >= avgChangeDays * 2)
                    {
                        waterStatus = " [alarm]";
                        wsColor     = Color.Red;
                    }
                    else if (avgChangeDays + 1 < lastChangeDays)
                    {
                        waterStatus = " [exceeded]";
                        wsColor     = Color.Orange;
                    }

                    waterChanges = avgChange + lastChange + waterStatus;
                }
            }
            else
            {
                waterChanges = "---";
            }

            y = y + (int)(Font.Height * 1.6f);
            DrawText(gfx, Localizer.LS(LSID.WaterChanges) + ": " + waterChanges, Font, wsColor, x, y);

            int inhabCount = fModel.QueryInhabitantsCount(fAquarium.Id);

            y = y + (int)(Font.Height * 1.6f);
            DrawText(gfx, Localizer.LS(LSID.Inhabitants) + ": " + inhabCount.ToString(), Font, ForeColor, x, y);

            int xoffset = layoutRect.Width / 4;
            int col     = 0;

            for (int i = 0; i < 13; i++)
            {
                if (i % 4 == 0)
                {
                    y   = y + (int)(Font.Height * 1.6f);
                    col = 0;
                }

                DrawMeasure(gfx, i, font, x + (xoffset * col), y);
                col += 1;
            }
        }