|
//default from vs
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
//for txt file manipulation
using System.IO;
public partial class _PointWindow : System.Web.UI.Page
{
//setup blank point list txt file setup image linkups and file info
protected void Page_Load(object sender, EventArgs e)
{
String FILENAME = Server.MapPath("Points.txt");
if(!Page.IsPostBack)
{
StreamWriter sr = File.CreateText(FILENAME);
sr.Close();
PointList.Text = null;
}
FILENAME = Server.MapPath("ImageActive.txt");
StreamReader sr2 = File.OpenText(FILENAME);
String contents = sr2.ReadToEnd();
sr2.Close();
char [] trim;
trim = new char[2];
trim[0]=('~');
trim[1]=('/');
contents.TrimStart(trim);
//Create an image object from file
System.Drawing.Image CurrentImage = System.Drawing.Image.FromFile(Server.MapPath(contents));
//Determine width and height of image
int ImageWidth = CurrentImage.Width;
int ImageHeight = CurrentImage.Height;
Regions.Height = CurrentImage.Height;
Regions.Width = CurrentImage.Width;
Regions.ImageUrl = contents;
//load active list
FILENAME = Server.MapPath("ListActive.txt");
StreamReader sr3 = File.OpenText(FILENAME);
String contents2 = sr3.ReadToEnd();
sr3.Close();
if (contents2 != "")
{
char[] trim2;
trim2 = new char[2];
trim2[0] = ('~');
trim2[1] = ('/');
contents.TrimStart(trim2);
FILENAME = Server.MapPath(contents2);
StreamReader sr4 = File.OpenText(FILENAME);
String contents3 = sr4.ReadToEnd();
sr4.Close();
FILENAME = Server.MapPath("Points.txt");
StreamWriter sr5 = File.CreateText(FILENAME);
//sr5 = File.AppendAllText(FILENAME,"");
sr5.Write(contents3);
sr5.Close();
PointList.Text = contents3;
}
}
//read inpoints and save to generic file Points.txt
public void RegionMap_Clicked(object sender, ImageClickEventArgs Args)
{
String FILENAME = Server.MapPath("Points.txt");
StreamWriter sr = File.AppendText(FILENAME);
sr.Write(Args.X.ToString() + "," + Args.Y.ToString() + "," );
sr.Close();
StreamReader sr2 = File.OpenText(FILENAME);
String contents = sr2.ReadToEnd();
PointList.Text = contents;
sr2.Close();
//--Do line drawing here--\\
//draw all points in current list
string[] arInfo = new string[200];
// define which character is seperating fields
char[] splitter = { ',' };
arInfo = contents.Split(splitter);
int count = 0;
int[] x1 = new int[200];
int[] y1 = new int[200];
int[] x2 = new int[200];
int[] y2 = new int[200];
for (int x = 0; x > -1;)
{
if (count == 0)
{
if (arInfo[x] != "")
{
x1[count] = Int32.Parse(arInfo[x]);
x++;
}
else
{ break; }
if (arInfo[x] != "")
{
y1[count] = Int32.Parse(arInfo[x]);
x++;
}
else
{ break; }
}
else
{
if (arInfo[x] != "")
{
x1[count] = x2[count - 1];
//x++;
}
else
{ break; }
if (arInfo[x] != "")
{
y1[count] = y2[count - 1];
//x++;
}
else
{ break; }
}
if (arInfo[x] != "")
{
x2[count] = Int32.Parse(arInfo[x]);
x++;
}
else
{ break; }
if (arInfo[x] != "")
{
y2[count] = Int32.Parse(arInfo[x]);
x++;
}
else
{ break; }
count++;
}
string jScript;
jScript = "<script> var linecanvas_graphics = new Graphics('linecanvas');";
int index = 0;
if(count > 0)
{ for (;count != -1; count-- )
{
jScript += "linecanvas_graphics.drawLine(" + x1[index] + "," + y1[index] + "," + x2[index] + "," + y2[index] + "); ";
index++;
}
}
jScript += "linecanvas_graphics.paint(); </script>";
Page.RegisterClientScriptBlock("keyClientBlock", jScript);
}
//erase points.txt
protected void ClearPointList_Click(object sender, EventArgs e)
{
String FILENAME = Server.MapPath("Points.txt");
StreamWriter sr = File.CreateText(FILENAME);
sr.Close();
FILENAME = Server.MapPath("ListActive.txt");
StreamWriter sr1 = File.CreateText(FILENAME);
sr1.Close();
PointList.Text = null;
}
//save points.txt data in user defined file
protected void SavePointList_Click(object sender, EventArgs e)
{
if (PointListDisplay.Text != "")
{
//Point_Lists
String FILENAME = Server.MapPath("~/PointLists/" + PointListDisplay.Text + ".txt");
StreamWriter sr = File.CreateText(FILENAME);
sr.Write(PointList.Text);
sr.Close();
}
else
{
FileNameMessage.ForeColor = System.Drawing.Color.Red;
FileNameMessage.Text = ": Enter File Name Before Saving :";
}
}
protected void DrawPointList_Click(object sender, EventArgs e)
{
String FILENAME = Server.MapPath("Points.txt");
StreamReader sr2 = File.OpenText(FILENAME);
String contents = sr2.ReadToEnd();
sr2.Close();
//--Do line drawing here--\\
//draw all points in current list
string[] arInfo = new string[200];
// define which character is seperating fields
char[] splitter = { ',' };
arInfo = contents.Split(splitter);
int count = 0;
int[] x1 = new int[200];
int[] y1 = new int[200];
int[] x2 = new int[200];
int[] y2 = new int[200];
for (int x = 0; x > -1; )
{
if (count == 0)
{
if (arInfo[x] != "")
{
x1[count] = Int32.Parse(arInfo[x]);
x++;
}
else
{ break; }
if (arInfo[x] != "")
{
y1[count] = Int32.Parse(arInfo[x]);
x++;
}
else
{ break; }
}
else
{
if (arInfo[x] != "")
{
x1[count] = x2[count - 1];
//x++;
}
else
{ break; }
if (arInfo[x] != "")
{
y1[count] = y2[count - 1];
//x++;
}
else
{ break; }
}
if (arInfo[x] != "")
{
x2[count] = Int32.Parse(arInfo[x]);
x++;
}
else
{ break; }
if (arInfo[x] != "")
{
y2[count] = Int32.Parse(arInfo[x]);
x++;
}
else
{ break; }
count++;
}
string jScript;
jScript = "<script> var linecanvas_graphics = new Graphics('linecanvas');";
int index = 0;
if (count > 0)
{
for (; count != -1; count--)
{
jScript += "linecanvas_graphics.drawLine(" + x1[index] + "," + y1[index] + "," + x2[index] + "," + y2[index] + "); ";
index++;
}
}
jScript += "linecanvas_graphics.paint(); </script>";
Page.RegisterClientScriptBlock("keyClientBlock", jScript);
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.