Script to create Dynamic MAP Graphics in WASP3D using SQLEXPRESS

Published 3 months ago, has comments

WASP3D scene Editor Script:

#region NameSpaceRegion
    using System;
    using System.Data.SqlClient;
    using System.Windows.Forms;
    using System.Data;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Xml;
    using System.Xml.Linq;
    using BeeSys.Wasp3D.Hosting;
    using System.Collections.Generic;
    using BeeSys.Wasp3D.WrapperHelper;
    using GFXWrpSceneGraph; 
#endregion

namespace BeeSys.Wasp3D.Scene
{
    public partial class SceneHandler : SceneGraph
    {            

 		public void createMap() {
 			// BJP   0.9,0.4,0,1
			//CONGRESS   0,1,0,1
			//OTHERS   0.4,0.4,0.4,1

			
			XDocument xdPolyData = XDocument.Parse("<shape></shape>");
			
			foreach (DataRow theRow in  this.getDataSetTable().Rows) {
				//Console.WriteLine(theRow["number"] + "\t" + theRow["last_party"]);
				
				XElement xePoly = XElement.Parse("<polygon />");
				
				string clr = "0.9,0.4,0,1";
				
				if (theRow["last_party"].ToString() == "BJP") clr = "0.7,0.4,0,1";
				else if (theRow["last_party"].ToString() == "INC") clr = "0,1,0,1";
				else if (theRow["last_party"].ToString() == "SP") clr = "1,0.1,0,1";
				else if (theRow["last_party"].ToString() == "BSP") clr = "1,1,0,1";
				else clr = "0.4,0.4,0.4,1";
				
				xePoly.SetAttributeValue("name", theRow["number"].ToString());
				xePoly.SetAttributeValue("visibility",1);
				xePoly.SetAttributeValue("color",clr);
				xdPolyData.Root.Add(xePoly);

				System.Threading.Thread.Sleep(50);
				
			} // end foreach
			
			this.LocalVariable.mapData = xdPolyData.ToString();
			
 		
 		}

        // this method is called when scene is cue    
        private void OnSceneCue(ref bool bRender)
        {
        	
        	
        	this.createMap();	
        }
        
 
		
	public DataTable getDataSetTable(){
 		
 			SqlConnection thisConnection = new SqlConnection(@"Server=MY_SERVER_ADDRESS_OR_IP;Database=MYDBNAME;Uid=MYUSERNAME;Pwd=MYPASSWORD");
			
			DataSet thisDataSet = new DataSet();
		
			try {
 				thisConnection.Open();
 				SqlDataAdapter thisAdapter = new SqlDataAdapter("SELECT number, last_party FROM MAP_DATA WHERE state='UP'", thisConnection);

				thisAdapter.Fill(thisDataSet, "seats");
				
				return thisDataSet.Tables["seats"];
 				
 			} catch(Exception e){
			    Console.WriteLine(e.ToString());
			    //MessageBox.Show(e.ToString());
			}
 			
			return thisDataSet.Tables["seats"];
		
			
 		}
       
    }
}