• 仓库映射图


    假设我们的生产管理系统中,需要用图形化的方式表示出来各个仓位的金额比重。下面介绍一种思路帮助大家开始

    1. 我们的数据结构大致是这样的。其实很多仓库都是可以划分为一个平面图形的。我这里是随机地产生了100个仓位

    image

    2.我最后做出来的效果如下

    image

    代码大致如下

    准备数据的代码

    public DataTable GetData() {
        DataTable tb = new DataTable();
        tb.Columns.Add("仓位");
        tb.Columns.Add("库存");
        tb.Columns.Add("顶边距");
        tb.Columns.Add("左边距");

        Random rnd = new Random();

        string[] ColumnName = new string[10] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J" };
        for (int x = 0; x < 10; x++)
        {
            for (int y = 0; y < 10; y++)
            {
                DataRow row = tb.NewRow();
                row["仓位"] = ColumnName[x] + y.ToString();
                row["库存"] = rnd.Next(100, 200);
                row["顶边距"] = (x - 0) * 20;
                row["左边距"] = (y - 0) * 80;

                tb.Rows.Add(row);
            }
        }

        return tb;
    }

    画图的代码

    Bitmap bitmap = new Bitmap(800, 200);
    Graphics graphics = Graphics.FromImage(bitmap);
    graphics.FillRectangle(new SolidBrush(Color.White), 0, 0, 800, 200);

    DataTable tb = GetData();
    foreach (DataRow row in tb.Rows) {
         float x = float.Parse(row["左边距"].ToString());
         float y = float.Parse(row["顶边距"].ToString());
         float width = 80;
         float height = 20;
         int value = int.Parse(row["库存"].ToString());

         Brush brush=null;
         if (value < 150)
             brush=new SolidBrush(Color.Green);
         else if (value < 180)
             brush = new SolidBrush(Color.HotPink);
         else
             brush = new SolidBrush(Color.Red);

         graphics.FillRectangle(brush, x, y, width, height);

    }

    this.pictureBox1.Image = bitmap;

  • 相关阅读:
    字符串转换成整数
    回文字符串判断
    字符串包含
    翻转单词顺序VS左旋转字符串
    穷举子集合
    求S=a+aa+aaa+aaaa+aa...a的值
    数组元素去重
    找最长等差数列的长度
    Git pull and push
    Google 开发console查找元素或方法
  • 原文地址:https://www.cnblogs.com/chenxizhang/p/1269127.html
Copyright © 2020-2023  润新知