using System; using System.Collections.Generic; //using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.Text; using System.IO; using Subgurim.Controles; using System.Text.RegularExpressions; public partial class MasterEdit : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (Request.Browser.Browser == "IE") { txtURL.Visible = false; } if (!IsPostBack) { Page.RegisterStartupScript("myscript", ""); } } string timePointFile, busStopFile, routeFile,rerouteFile; string[] timePointFileArray, busStopFileArray, routeFileArray, rerouteFileArray; string[] info; public void reload_page() { timePointFile = "" + hdnTimePoint.Value; busStopFile = "" + hdnBusStop.Value; routeFile=""+ hdnRoute.Value; rerouteFile = "" + hdnReroute.Value; //remove all from list box lstBusStop.Items.Clear(); lstTimePoint.Items.Clear(); lstRoute.Items.Clear(); lstReroute.Items.Clear(); //add back string script = "DrawMap();resetMarker();"; if (timePointFile != "") { timePointFile = timePointFile.Replace("\r\n", "!"); timePointFileArray = timePointFile.Split('!'); for (int i = 0; i < timePointFileArray.Length - 1; i++) { ListItem addList = new ListItem(); info = timePointFileArray[i].Split(','); addList.Text = info[0]; addList.Value = info[1] + "~" + info[2] + "~" + info[3]; lstTimePoint.Items.Add(addList); script += "setLatLong(" + info[2] + " , " + info[3] + ");dragMarker('timePoint', 1);"; } } if (busStopFile != "") { busStopFile = busStopFile.Replace("\r\n", "!"); busStopFileArray = busStopFile.Split('!'); for (int i = 0; i < busStopFileArray.Length - 1; i++) { ListItem addList = new ListItem(); info = busStopFileArray[i].Split(','); addList.Text = info[0]; addList.Value = info[1] + "~" + info[2] + "~" + info[3]; lstBusStop.Items.Add(addList); script += "setLatLong(" + info[2] + " , " + info[3] + ");dragMarker('busStop', 2); "; } } if (routeFile != "") { routeFileArray=routeFile.Split('!'); for (int i=0;i " + info[1]; addList.Value = info[0] + "," + info[1]; lstReroute.Items.Add(addList); } } Page.RegisterStartupScript("myscript", ""); } protected void btnUpload_Click(object sender, EventArgs e) { // string pathFileName=""; // if (Request.Browser.Browser == "IE") // { // pathFileName = System.IO.Path.GetFileName(UploadedFile.PostedFile.FileName); // } // else { // pathFileName = txtFileName.Value; // } // string[] splitFileName = pathFileName.Split('\\'); // Regex objNotWholePattern = new Regex(".cvs$"); //bool a = objNotWholePattern.IsMatch(pathFileName); //check file here } protected void btnCreateTimePoint_Click(object sender, EventArgs e) { if (hdnTimePoint.Value != "") { try { string pathName = createUniqueFileName("Time Point"); StreamWriter newFile = new StreamWriter(pathName, true); newFile.WriteLine("Time Point list"); newFile.WriteLine(); newFile.WriteLine("Name,Address,Latitude,Longitude"); newFile.WriteLine(hdnTimePoint.Value); newFile.Close(); Response.Write(""); } catch { Response.Write(""); } } else { Response.Write(""); } reload_page(); } protected void btnCreateBusStop_Click(object sender, EventArgs e) { if (hdnBusStop.Value != "") { try { string pathName = createUniqueFileName("Bus Stop"); StreamWriter newFile = new StreamWriter(pathName, true); newFile.WriteLine("Bus Stop list"); newFile.WriteLine(); newFile.WriteLine("Name,Address,Latitude,Longitude"); newFile.WriteLine(hdnBusStop.Value); newFile.Close(); Response.Write(""); } catch { Response.Write(""); } } else { Response.Write(""); } reload_page(); } protected void btnCreateRoute_Click(object sender, EventArgs e) { if (hdnRoute.Value != "") { try { string pathName = createUniqueFileName("Route"); StreamWriter newFile = new StreamWriter(pathName, true); newFile.WriteLine("Route list"); newFile.WriteLine(); string[] splitList = hdnRoute.Value.Split('!'); string[] information; string DirectionInfo=""; string direction = "", timeSheet = ""; int count = splitList.Length; for (int i = 0; i < count-1; i++) { information = splitList[i].Split('~'); direction = information[1] + "\r\n"; timeSheet = information[2]; string[] temp = timeSheet.Replace("\r\n", "!").Split('!'); string[] temp2 = temp[0].Split(','); if (temp2.Length == 11) { newFile.WriteLine("Location,Arrival Time,Wait Time,Repeat Time,First Repeat,Last Repeat,Peak,Wait Time,Repeat Time,First Repeat,Last Repeat"); } else { newFile.WriteLine("Location,Arrival Time,Wait Time,Repeat Time,First Repeat,Last Repeat"); } newFile.WriteLine(timeSheet); DirectionInfo = DirectionInfo + direction; } newFile.WriteLine(DirectionInfo); newFile.Close(); Response.Write(""); } catch { Response.Write(""); } } else { Response.Write(""); } reload_page(); } protected void btnCreateReRoute_Click(object sender, EventArgs e) { if (hdnReroute.Value != "") { try { string pathName = createUniqueFileName("ReRoute"); StreamWriter newFile = new StreamWriter(pathName, true); newFile.WriteLine("reRoute list"); newFile.WriteLine(); newFile.WriteLine("From,To,"); string[] info = hdnReroute.Value.Split('~'); for (int i = 0; i < info.Length; i++) { newFile.WriteLine(info[i]); } newFile.Close(); Response.Write(""); } catch { Response.Write(""); } } else { Response.Write(""); } reload_page(); } string filename, username; public string createUniqueFileName(string text) { // create a writer and open the file DateTime time = DateTime.Now; string timeConvert = time + ""; timeConvert = timeConvert.Replace("/", ""); timeConvert = timeConvert.Replace(":", ""); timeConvert = timeConvert.Replace(" ", ""); timeConvert = timeConvert.Replace("AM", ""); timeConvert = timeConvert.Replace("PM", ""); filename = timeConvert + "-" + text + ".csv"; //create unique file name username = System.Environment.UserName; string path = username + "\\Downloads\\" + filename; string path1 = @Path.Combine(@"C:\Users\", path); return path1; } protected void btnCreateCSV_Click(object sender, EventArgs e) { reload_page(); if (ddlCreateCSV.SelectedItem.Text == "Time Point") { } if (ddlCreateCSV.SelectedItem.Text == "Bus Stop") { } if (ddlCreateCSV.SelectedItem.Text == "Route") { } if (ddlCreateCSV.SelectedItem.Text == "reRoute") { } if (ddlCreateCSV.SelectedItem.Text == "All") { } } }