仓库映射图
假設我們的生產管理系統中,需要用圖形化的方式表示出來各個倉位的金額比重。下面介紹一種思路幫助大家開始
1. 我們的數據結構大致是這樣的。其實很多倉庫都是可以劃分為一個平面圖形的。我這里是隨機地產生了100個倉位
2.我最后做出來的效果如下
代碼大致如下
準備數據的代碼
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;
轉載于:https://www.cnblogs.com/chenxizhang/archive/2008/08/16/1269127.html
總結
- 上一篇: Windows Mobile访问SQL
- 下一篇: DB2: 为DB2数据库创建新用户帐户并