This explains how we can draw the Business maps for locating particular object the using .net drawing classes. These Classes are available under the namespace “System. Drawing". We had done business maps for mainly two types of databases.
Here is the sample code:-
///To draw the bitmap image
public Bitmap Draw() { int i, j; float x, y;
try { DataSet dst = new DataSet(); DataSet dstitems = new DataSet(); Functions fun = new Functions();
Pen blackPen = new Pen(Color.Black, 1); Pen ThinblackPen = new Pen(Color.Black, 1); Pen ThickblackPen = new Pen(Color.Black, 2); Pen redPen = new Pen(Color.Red, 2);
Brush blackBrush = new SolidBrush(Color.Black); Brush redBrush = new SolidBrush(Color.Red); Brush brownBrush = new SolidBrush(Color.Brown); Brush greenBrush = new SolidBrush(Color.Green);
Font axesFont = new Font("arial", 10); Pen pen = new Pen(Color.Blue, 1);
//Assign the dataset with the co-ordinates from database if (HttpContext.Current.Session["constraints"] != null) dst = (DataSet)HttpContext.Current.Session["constraints"];
//Assign the dataset with the co-ordinates from database if (HttpContext.Current.Session["items"] != null) dstitems = (DataSet)HttpContext.Current.Session["items"];
// first establish working area graphics.FillRectangle(new SolidBrush(Color.LightYellow), 0, 0, Width, Height); int ChartInset =1; int ChartWidth = Width - (1 * ChartInset); int ChartHeight = Height - (1 * ChartInset);
//int ChartWidth = Width ; //int ChartHeight = Height ;
// graphics.DrawRectangle(new Pen(Color.Black, 1), ChartInset, ChartInset, ChartWidth, ChartHeight);
graphics.DrawRectangle(new Pen(Color.Black, 1), 0, 0, ChartWidth, ChartHeight);
//must draw all text items before doing the rotate below graphics.DrawString(Title, new Font("arial", 8), blackBrush, 10, 10);
//draw X axis labels for (i = 0; i <= Xdivs; i++) { x = ChartInset + (i * ChartWidth) / Xdivs; y = ChartHeight + ChartInset; //if (x > 230) //{ // x = 230; //}
//if (y > 230) //{ // y = 230; //} //graphics.DrawLine(blackPen, x, y + 2, x, y - 2);
graphics.DrawLine(blackPen, x+1, y+1 , x-1, y-1);
}
//draw Y axis labels for (i = 0; i <= Ydivs; i++) { x = ChartInset; y = ChartHeight + ChartInset - (i * ChartHeight / Ydivs); //if (x > 230) //{ // x = 230; //}
//if (y > 230) //{ // y = 230; //} // graphics.DrawLine(blackPen, x + 2, y, x - 2, y);
graphics.DrawLine(blackPen, x+1, y+1, x-1, y-1); }
//rotate the chart graphics.RotateTransform(180); graphics.TranslateTransform(0, -Height); graphics.TranslateTransform(-ChartInset, ChartInset); graphics.ScaleTransform(-1, 1);
//draw the map using dataset for constructs for (j = 0; j < dst.Tables[0].Rows.Count; j++) { //take pen with required width and color pen = get_pen(dst.Tables["Table"].Rows[j]["Color"].ToString(), Convert.ToInt32(dst.Tables["Table"].Rows[j]["Width"]));
//assign the co-ordinates i = 0; x1 = Convert.ToInt32(dst.Tables["Table"].Rows[j][i]); y1 = Convert.ToInt32(dst.Tables["Table"].Rows[j][i + 1]); x2 = Convert.ToInt32(dst.Tables["Table"].Rows[j][i + 2]); y2 = Convert.ToInt32(dst.Tables["Table"].Rows[j][i + 3]);
//draw required shape draw_Shape(dst.Tables[0].Rows[j]["Shape"].ToString(), pen, ChartWidth, ChartHeight); }
//draw the Items using dataset for (j = 0; j < dstitems.Tables[0].Rows.Count; j++) { //assign the co-ordinates i = 0; x1 = Convert.ToInt32(dstitems.Tables["Table"].Rows[j][i]); y1 = Convert.ToInt32(dstitems.Tables["Table"].Rows[j][i + 1]); x2 = Convert.ToInt32(dstitems.Tables["Table"].Rows[j]["Height"]); y2 = Convert.ToInt32(dstitems.Tables["Table"].Rows[j]["Width"]); string ss = dstitems.Tables[0].Rows[j]["Item_ID"].ToString(); string ss1 = Convert.ToString(HttpContext.Current.Session["Item_ID"]); //Search object is drawn with specified color if (dstitems.Tables[0].Rows[j]["Item_ID"].ToString() == Convert.ToString(HttpContext.Current.Session["Item_ID"])) { pen = new Pen(Color.Red, 2); } else { pen = new Pen(Color.Black, 1); }
//draw required shape draw_Shape(dstitems.Tables[0].Rows[j]["Shape"].ToString(), pen, ChartWidth, ChartHeight); }
return bitmap; //after drawing save image //save_Image(); } catch (ArgumentNullException argnullexp) { throw argnullexp; } catch (ArgumentException argexp) { throw argexp; } catch (HttpException httpexp) { throw httpexp; } catch (ArithmeticException arthexp) { throw arthexp; } catch (Exception exp) { throw exp; } }
AttachmentsObject finder using Maps (556-23447-AutoFitReset.zip)
|
| Author: venkat | Member Level: Bronze | Revenue Score:   |
Hi,
Please upload the database tables and stored procs or object_finder.mdf and object_finder.ldf or email me vmamilla@msn.com
Thanks, Venkat.
|