//Create a new event private void newEventButton_Click(object sender, RoutedEventArgs e) { //error check number int error = 0; //Get the details from a popup, add the event to the linked list, write the string to the file Popup container = new Popup(); container.Height = 300; container.Width = 400; container.VerticalOffset = 100; WindowsPhoneControl5 temp = new WindowsPhoneControl5(); container.Child = temp; container.IsOpen = true; temp.OKbtn.Click += (s, args) => { //Create a new node and add it to the LinkedList String title = temp.titleTxt.Text; //error code 1 if(title == null) { error = error * 10; error = error + 1; } else { if(title.Length < 1) { error = error * 10; error = error + 1; } } String date = temp.dateTxt.Text; String startTimeString = temp.startTimeTxt.Text; String endTimeString = temp.endTimeTxt.Text; DateTime eventDate = new DateTime(); try { eventDate = DateTime.ParseExact(date, "MM/dd/yyyy", null); //error code 2 } catch (Exception ex) { error = error * 10; error = error + 2; } DateTime startTime = new DateTime(); try { startTime = DateTime.ParseExact(startTimeString, "HH:mm", null); //error code 3 } catch (Exception ex) { error = error * 10; error = error + 3; } DateTime endTime = new DateTime(); try { endTime = DateTime.ParseExact(endTimeString, "HH:mm", null); //error code 4 } catch (Exception ex) { error = error * 10; error = error + 4; } DateTime startTimeDate = new DateTime(eventDate.Year, eventDate.Month, eventDate.Day, startTime.Hour, startTime.Minute, 0); DateTime endTimeDate = new DateTime(eventDate.Year, eventDate.Month, eventDate.Day, endTime.Hour, endTime.Minute, 0); String extra = temp.extraTxt.Text; //error code 5 String detail = temp.extraTxt.Text; //error code 6 System.Console.Write("extra: " + extra); System.Console.Write("detail: " + detail); if(error != 0) { Popup fixError = new Popup(); AboutControl page = new AboutControl(); fixError.Height = 300; fixError.Width = 400; fixError.VerticalOffset = 100; fixError.Child = page; fixError.IsOpen = true; string errorMessage = ""; int code; while (error > 0) { code = error % 10; error = error / 10; switch (code) { case 1: errorMessage = String.Concat("Please enter a title\n", errorMessage); break; case 2: errorMessage = String.Concat("Invalid date\n", errorMessage); break; case 3: errorMessage = String.Concat("Invalid start time\n", errorMessage); break; case 4: errorMessage = String.Concat("Invalid end time\n", errorMessage); break; case 5: errorMessage = String.Concat("Invalid info\n", errorMessage); break; case 6: errorMessage = String.Concat("Invalid description\n", errorMessage); break; default: errorMessage = String.Concat("Unkown error\n", errorMessage); break; } } page.infoBox.Text = errorMessage; page.closeButton.Click += (s1, args1) => { fixError.IsOpen = false; }; container.IsOpen = false; return; } //Add the event to the EList linked list if (remList == null) { remList = new EList(); } remList.addEvent((startTimeDate.ToString()), endTimeDate.ToString(), title, 0, extra, detail); //Write backupString to a file for persistent storage string backupString = remList.returnAll(); StreamWriter writer = new StreamWriter(new IsolatedStorageFileStream(eFile, FileMode.Truncate, eventFile)); writer.Write(backupString); writer.Close(); //add button on main screen for event, display title and start time HyperlinkButton eventButton = new HyperlinkButton(); eventButton.Name = title; eventButton.Height = 72; eventButton.Width = 427; eventButton.Margin = new Thickness(5); eventButton.Content = title + " " + startTimeDate.ToString(); eventButton.Background = new SolidColorBrush(Colors.Red); eventButton.Foreground = new SolidColorBrush(Colors.Black); listPanel.Children.Add(eventButton); //Add action handler to display information about event when clicked eventButton.Click+= new RoutedEventHandler(eventButtonGeneralClick); eventButton.Hold += new EventHandler<System.Windows.Input.GestureEventArgs>(eventButtonGeneralHold); //create a reminder for the event Reminder rem = new Reminder(title); rem.BeginTime = new DateTime(eventDate.Year, eventDate.Month, eventDate.Day, startTime.Hour, startTime.Minute, 0); rem.Content = detail; ScheduledActionService.Add(rem); container.IsOpen = false; }; temp.cancelBtn.Click += (s, args) => { container.IsOpen = false; }; }
// Constructor public MainPage() { InitializeComponent(); //connect to the server and create a user string address = "sslab01.cs.purdue.edu"; const int BACKUP_PORT = 7272; SocketClient client = new SocketClient(); client.Connect(address, BACKUP_PORT); client.Send("CreateNewUser|larry|pass|"); client.Close(); Application.Current.Host.Settings.EnableFrameRateCounter = false; if (!listFile.FileExists(sFile))//Create a file for storing list names if it doesn't exist { IsolatedStorageFileStream dataFile = listFile.CreateFile(sFile); dataFile.Close(); } if (!eventFile.FileExists(eFile))//Create a file for storing event details if it doesn't exist { IsolatedStorageFileStream temp = eventFile.CreateFile(eFile); temp.Close(); } //Read listNames from the file StreamReader reader = new StreamReader(new IsolatedStorageFileStream(sFile, FileMode.Open, listFile)); string rawData = reader.ReadToEnd(); reader.Close(); string[] sep = new string[] { "\r\n" };//Seperate by new line string[] arrData = rawData.Split(sep, StringSplitOptions.RemoveEmptyEntries); foreach (var d in arrData) { loadListButton(d);//Add the lists to the main screen } //Read the events in here, add buttons to the display reader = new StreamReader(new IsolatedStorageFileStream(eFile, FileMode.Open, eventFile)); string data = reader.ReadToEnd(); reader.Close(); remList = new EList(); remList.Recreate(data); loadEvents(); }