コード例 #1
0
 int MapIndexOf(ProgressMap map, double i)
 {
     for (int j = 0; j < map.Cells.Count; j++)
     {
         if (!map.Cells[j].footer && !map.Cells[j].header)
         {
             if (map.Cells[j].start <= i && i <= map.Cells[j].start + map.Cells[j].length)
             {
                 return(j);
             }
         }
     }
     return(-1);
 }
コード例 #2
0
        /*protected override void Paint(Graphics g,
         *  Rectangle clipBounds,
         *  Rectangle cellBounds,
         *  int rowIndex,
         *  DataGridViewElementStates cellState,
         *  object value, object formattedValue,
         *  string errorText,
         *  DataGridViewCellStyle cellStyle,
         *  DataGridViewAdvancedBorderStyle advancedBorderStyle,
         *  DataGridViewPaintParts paintParts)
         * {
         *  if (value == null)
         *  {
         *      if (ProgressBarColors != null && ProgressBarColors.Count == 1)
         *      {
         *          g.FillRectangle(new SolidBrush(ProgressBarColors[0]), cellBounds);
         *          return;
         *      }
         *      value = 0;
         *  }
         *  List<int> Vals = new List<int>();
         *  try
         *  {
         *      Vals = (List<int>)value;
         *  }
         *  catch
         *  {
         *      Vals.Add(0);
         *      Vals.Add((int)value);
         *  }
         *
         *
         *  Brush foreColorBrush = new SolidBrush(cellStyle.ForeColor);
         *
         *  // Draws the cell grid
         *  base.Paint(g, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, (paintParts & ~DataGridViewPaintParts.ContentForeground));
         *
         *  float posX = cellBounds.X;
         *  float posY = cellBounds.Y;
         *
         *
         *  cellStyle.Padding = new Padding(2);
         *  var x = cellBounds.X + cellStyle.Padding.Left;
         *  var y = cellBounds.Y + cellStyle.Padding.Top;
         *  var w = cellBounds.Width - cellStyle.Padding.Right - cellStyle.Padding.Left;
         *  var h = cellBounds.Height - cellStyle.Padding.Top - cellStyle.Padding.Bottom;
         *  var brush = new SolidBrush(ProgressBarColor);
         *
         *
         *  var percent = 0.0;
         *  if (Vals.Count > 1) percent = Vals[1] / 10.0;
         *
         *  if (Vals.Count == 2 && Vals[0] == 0)
         *  {
         *      if (Vals[1] > 750)
         *          brush = new SolidBrush(Color.FromArgb(0x1E, 0xBA, 0x12));
         *      else if (Vals[1] > 350)
         *          brush = new SolidBrush(Color.LightBlue);
         *      else brush = new SolidBrush(Color.LightSalmon);
         *  }
         *  for (int i = 0; i < Vals.Count; i += 2)
         *  {
         *      if (Vals[i] < 0)
         *      {
         *          Vals[i + 1] += Vals[i];
         *          Vals[i] = -1;
         *      }
         *      if (Vals[i] + Vals[i + 1] > 1000)
         *          Vals[i + 1] = 1000 - Vals[i];
         *      var brush_ = brush;
         *      var h_ = h;
         *      var y_ = y;
         *      if (!(Vals.Count == 2 && Vals[0] == 0) && ProgressBarColors != null && ProgressBarColors.Count > i / 2)
         *      {
         *          brush_ = new SolidBrush(ProgressBarColors[i / 2]);
         *          if (ProgressBarColors[i / 2] == headerColor)
         *          {
         *              y_ = cellBounds.Y;
         *              h_ = 3;
         *          }
         *          if (ProgressBarColors[i / 2] == footerColor)
         *          {
         *              y_ = cellBounds.Y + cellBounds.Height - 7;
         *              h_ = 7;
         *          }
         *      }
         *      // Draw the progress
         *      g.FillRectangle(brush_,
         *          x + (int)(w * Vals[i] / 1000.0),
         *          y_,
         *          (Int32)(w * Vals[i + 1] / 1000.0),
         *          h_);
         *  }
         *
         #region
         *  if (Vals.Count == 2 && Vals[0] == 0)
         *  {
         *      float textWidth = TextRenderer.MeasureText(percent + "%", cellStyle.Font).Width;
         *      float textHeight = TextRenderer.MeasureText(percent + "%", cellStyle.Font).Height;
         *
         *
         *      posX = cellBounds.X + (cellBounds.Width / 2) - textWidth / 2;
         *      posY = cellBounds.Y + (cellBounds.Height / 2) - textHeight / 2;
         *      g.DrawString(percent + "%", cellStyle.Font, foreColorBrush, posX, posY);
         *  }
         *  else
         *  {
         *      if (major != 0)
         *      {
         *          if (minor != 0)
         *          {
         *              var brush_ = new SolidBrush(minorColor);
         *              for (int i = 1; i < minor * major; i++)
         *              {
         *                  g.FillRectangle(brush_,
         *                      x + (float)(w * i / (minor * major * 1.0)),
         *                      cellBounds.Y - cellBounds.Height / 7,
         *                      1f,
         *                      2 * (cellBounds.Height / 7));
         *              }
         *          }
         *          {
         *              var brush_ = new SolidBrush(majorColor);
         *              for (int i = 1; i < major; i++)
         *              {
         *                  g.FillRectangle(brush_,
         *                      x + (float)(w * i / (1.0 * major)),
         *                      cellBounds.Y,
         *                      1,
         *                      cellBounds.Height);
         *              }
         *          }
         *      }
         *  }
         #endregion
         * }*/

        protected override void Paint(Graphics g,
                                      Rectangle clipBounds,
                                      Rectangle cellBounds,
                                      int rowIndex,
                                      DataGridViewElementStates cellState,
                                      object value, object formattedValue,
                                      string errorText,
                                      DataGridViewCellStyle cellStyle,
                                      DataGridViewAdvancedBorderStyle advancedBorderStyle,
                                      DataGridViewPaintParts paintParts)
        {
            // Draws the cell grid
            base.Paint(g, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, (paintParts & ~DataGridViewPaintParts.ContentForeground));

            ProgressMap map = null;

            if (value is ProgressMap)
            {
                map = (ProgressMap)value;
            }
            else if (value is double || value is int)
            {
                map = new ProgressMap()
                {
                    max   = 100,
                    Cells = new List <ProgressCell> {
                        new ProgressCell {
                            start = 0, length = Convert.ToDouble(value)
                        }
                    },
                    SimpleProgress = true,
                }
            }
            ;
            if (map == null)
            {
                return;
            }

            float posX = cellBounds.X;
            float posY = cellBounds.Y;

            cellStyle.Padding = new Padding(2);
            var x = cellBounds.X;
            var y = cellBounds.Y;
            var w = cellBounds.Width;
            var h = cellBounds.Height;

            if (!map.SimpleProgress)
            {
                x += cellStyle.Padding.Left;
                y += cellStyle.Padding.Top;
                w -= cellStyle.Padding.Left + cellStyle.Padding.Right;
                h -= cellStyle.Padding.Bottom + cellStyle.Padding.Top;
            }

            foreach (var cell in map.Cells)
            {
                var brush = new SolidBrush(ProgressBarColor);
                try
                {
                    if (map.Cells.Count == 1 &&
                        map.Cells[0].start == 0 &&
                        map.SimpleProgress &&
                        map.Cells[0].color == null)
                    {
                        brush.Dispose();
                        if (map.Cells[0].length / map.max > 0.750)
                        {
                            brush = new SolidBrush(Color.FromArgb(0x1E, 0xBA, 0x12));
                        }
                        else if (map.Cells[0].length / map.max > 0.350)
                        {
                            brush = new SolidBrush(Color.LightBlue);
                        }
                        else
                        {
                            brush = new SolidBrush(Color.LightSalmon);
                        }
                    }
                    if (cell.start < 0)
                    {
                        cell.length += cell.start;
                        cell.start   = -1;
                    }
                    if (cell.start + cell.length > map.max)
                    {
                        cell.length = map.max - cell.start;
                    }
                    var h_ = h;
                    var y_ = y;
                    if (cell.header)
                    {
                        brush.Dispose();
                        brush = new SolidBrush(headerColor);
                        y_    = cellBounds.Y;
                        h_    = 3;
                    }
                    if (cell.footer)
                    {
                        brush.Dispose();
                        brush = new SolidBrush(footerColor);
                        y_    = cellBounds.Y + cellBounds.Height - 7;
                        h_    = 7;
                    }
                    if (map.color != null)
                    {
                        brush.Dispose();
                        brush = new SolidBrush(map.color.Value);
                    }
                    if (cell.color != null)
                    {
                        brush.Dispose();
                        brush = new SolidBrush(cell.color.Value);
                    }
                    var s = cell.start;
                    var d = cell.length;
                    if (map.RightToLeft)
                    {
                        s = map.max - (s + d);
                    }
                    // Draw the progress
                    g.FillRectangle(brush,
                                    x + (int)(w * s / map.max),
                                    y_,
                                    (int)(w * d / map.max),
                                    h_);
                }
                finally
                {
                    brush.Dispose();
                }
            }

            #region
            if (map.SimpleProgress || map.text != null)
            {
                var percent = "0%";
                if (map.text != null)
                {
                    percent = map.text;
                }
                else if (map.Cells.Count > 0)
                {
                    percent = (100 * map.Cells[0].length / map.max).ToString("0.#") + "%";
                }
                float textWidth  = TextRenderer.MeasureText(percent, cellStyle.Font).Width;
                float textHeight = TextRenderer.MeasureText(percent, cellStyle.Font).Height;


                posX = cellBounds.X + (cellBounds.Width / 2) - textWidth / 2;
                posY = cellBounds.Y + (cellBounds.Height / 2) - textHeight / 2;
                using (var foreColorBrush = new SolidBrush(cellStyle.ForeColor))
                    g.DrawString(percent, cellStyle.Font, foreColorBrush, posX, posY);
            }

            if (major != 0 && map.SimpleProgress == false)
            {
                if (minor != 0)
                {
                    using (var brush_ = new SolidBrush(minorColor))
                        for (int i = 1; i < minor * major; i++)
                        {
                            g.FillRectangle(brush_,
                                            x + (float)(w * i / (minor * major * 1.0)),
                                            cellBounds.Y - cellBounds.Height / 7,
                                            1f,
                                            2 * (cellBounds.Height / 7));
                        }
                }
                {
                    using (var brush_ = new SolidBrush(majorColor))
                        for (int i = 1; i < major; i++)
                        {
                            g.FillRectangle(brush_,
                                            x + (float)(w * i / (1.0 * major)),
                                            cellBounds.Y,
                                            1,
                                            cellBounds.Height);
                        }
                }
            }
            #endregion
        }
コード例 #3
0
        internal void UpdateProgresssBar(DateTime?date = null)
        {
            if (date == null)
            {
                date = Utils.PersianParse(dataGridView1[2, 0].Value.ToString());
            }
            dataGridView2.Rows.Clear();
            var color = Color.Lime;
            var map   = new ProgressMap {
                RightToLeft = true
            };

            foreach (var p in db.ActiveProjects)
            {
                if (!p.IsHozoor)
                {
                    foreach (var t in p.Times)
                    {
                        if (t.Start.Date == date)
                        {
                            if (t.Duration.sec < 0)
                            {
                                t.Duration.sec = 0;
                            }
                            map.Cells.Add(new ProgressCell
                            {
                                start  = 1 + (t.Start - t.Start.Date).TotalSeconds * 1000 / day_seconds,
                                length = t.Duration.sec * 1000 / day_seconds,
                                color  = color
                            });
                        }
                    }
                }
            }
            {
                var p = db.GetByType(hozoor: true);
                foreach (var t in p.Times)
                {
                    if (t.Start.Date == date)
                    {
                        if (t.Duration.sec < 0)
                        {
                            t.Duration.sec = 0;
                        }
                        map.Cells.Add(new ProgressCell
                        {
                            start  = 1 + (t.Start - t.Start.Date).TotalSeconds * 1000 / day_seconds,
                            length = t.Duration.sec * 1000 / day_seconds,
                            header = true
                        });
                    }
                }
            }
            map.Cells.Add(new ProgressCell
            {
                start  = (DateTime.Now - DateTime.Now.Date).TotalSeconds * 1000 / day_seconds,
                length = 2,
                color  = Color.Red
            });
            dataGridView2.Rows.Add(map);
        }