private void connection_test_button_Click(object sender, EventArgs e)
        {
            AlertGUI temp5 = new AlertGUI();

            temp5.setMessage("Attempting to connect to server....", "");
            temp5.Show();

            try
            {
                PDA_GUI.ServerConnection conn = new PDA_GUI.ServerConnection();
                conn.connect();

                temp5.Close();
                temp5.Dispose();

                conn.disconnect();
                AlertGUI temp3 = new AlertGUI();
                temp3.setMessage("Server Connected Successfully!", "");
                temp3.Show();
            }
            catch
            {
                AlertGUI temp2 = new AlertGUI();
                temp2.setMessage("Could not find server");


                //temp2.ShowDialog();
                temp2.Show();

                temp5.Close();
                temp5.Dispose();
            }
        }
        private void save_setup_button_Click(object sender, EventArgs e)
        {
            try
            {
                if (writeConfigFile(null, this.patient_name_textbox.Text, this.hostname_textbox.Text, this.username_textbox.Text, this.password_textbox.Text))
                {
                    AlertGUI temp = new AlertGUI();
                    temp.setMessage("File Written", "whatever");


                    //temp.ShowDialog();
                    temp.Show();

                    temp.Dispose();
                }
            }
            catch
            {
                try
                {
                    if (writeConfigFile(null, this.patient_name_textbox.Text, this.hostname_textbox.Text, this.username_textbox.Text, this.password_textbox.Text))
                    {
                        AlertGUI temp2 = new AlertGUI();
                        temp2.setMessage("File Written", "whatever");


                        //temp2.ShowDialog();
                        temp2.Show();

                        temp2.Dispose();
                    }
                }
                catch
                {
                    AlertGUI temp2 = new AlertGUI();
                    temp2.setMessage("File Not Written");


                    //temp2.ShowDialog();
                    temp2.Show();
                }
            }
        }
        public void exrtactConfigFile()
        {
            //Config file testing
            if (configFileExists())
            {
                StreamReader readConfigFile = new StreamReader(configFilePath);
                string       lastKnownTasks = killBrackets(readConfigFile.ReadLine());
                string       patientName    = killBrackets(readConfigFile.ReadLine());

                string hostname  = killBrackets(readConfigFile.ReadLine());
                string username  = killBrackets(readConfigFile.ReadLine());
                string password  = killBrackets(readConfigFile.ReadLine());
                string startTime = killBrackets(readConfigFile.ReadLine());
                string endTime   = killBrackets(readConfigFile.ReadLine());
                string date      = killBrackets(readConfigFile.ReadLine());



                readConfigFile.Close();

                mainMenuPointer.myConfig.lastKnownTasks = lastKnownTasks;
                mainMenuPointer.myConfig.patientName    = patientName;
                mainMenuPointer.myConfig.hostname       = hostname;
                mainMenuPointer.myConfig.username       = username;
                mainMenuPointer.myConfig.password       = password;
                mainMenuPointer.myConfig.startTime      = startTime;
                mainMenuPointer.myConfig.endTime        = endTime;
                mainMenuPointer.myConfig.date           = date;
            }

            //else create new config file
            else
            {
                AlertGUI temp = new AlertGUI();
                temp.setMessage("Config File doesnt exist");

                // temp.ShowDialog();
                temp.Show();

                createConfigFile();
            }
        }
        public void exrtactConfigFile()
        {
            //Config file testing
            if (configFileExists())
            {

                StreamReader readConfigFile = new StreamReader(configFilePath);
                string lastKnownTasks = killBrackets(readConfigFile.ReadLine());
                string patientName = killBrackets(readConfigFile.ReadLine());

                string hostname = killBrackets(readConfigFile.ReadLine());
                string username = killBrackets(readConfigFile.ReadLine());
                string password = killBrackets(readConfigFile.ReadLine());
                string startTime = killBrackets(readConfigFile.ReadLine());
                string endTime = killBrackets(readConfigFile.ReadLine());
                string date = killBrackets(readConfigFile.ReadLine());

                readConfigFile.Close();

                mainMenuPointer.myConfig.lastKnownTasks = lastKnownTasks;
                mainMenuPointer.myConfig.patientName = patientName;
                mainMenuPointer.myConfig.hostname = hostname;
                mainMenuPointer.myConfig.username = username;
                mainMenuPointer.myConfig.password = password;
                mainMenuPointer.myConfig.startTime = startTime;
                mainMenuPointer.myConfig.endTime = endTime;
                mainMenuPointer.myConfig.date = date;

            }

            //else create new config file
            else
            {

                AlertGUI temp = new AlertGUI();
                temp.setMessage("Config File doesnt exist");

               // temp.ShowDialog();
                temp.Show();

                createConfigFile();

            }
        }
        private void save_setup_button_Click(object sender, EventArgs e)
        {
            try
            {
                if (writeConfigFile(null, this.patient_name_textbox.Text, this.hostname_textbox.Text, this.username_textbox.Text, this.password_textbox.Text))
                {
                    AlertGUI temp = new AlertGUI();
                    temp.setMessage("File Written", "whatever");

                    //temp.ShowDialog();
                    temp.Show();

                    temp.Dispose();
                }
            }
            catch
            {

                try
                {
                    if (writeConfigFile(null, this.patient_name_textbox.Text, this.hostname_textbox.Text, this.username_textbox.Text, this.password_textbox.Text))
                    {
                        AlertGUI temp2 = new AlertGUI();
                        temp2.setMessage("File Written", "whatever");

                        //temp2.ShowDialog();
                        temp2.Show();

                        temp2.Dispose();
                    }
                }
                catch
                {

                    AlertGUI temp2 = new AlertGUI();
                    temp2.setMessage("File Not Written");

                    //temp2.ShowDialog();
                    temp2.Show();

                }
            }
        }
        private void connection_test_button_Click(object sender, EventArgs e)
        {
            AlertGUI temp5 = new AlertGUI();
            temp5.setMessage("Attempting to connect to server....", "");
            temp5.Show();

            try
            {
                PDA_GUI.ServerConnection conn = new PDA_GUI.ServerConnection();
                conn.connect();

                temp5.Close();
                temp5.Dispose();

                conn.disconnect();
                AlertGUI temp3 = new AlertGUI();
                temp3.setMessage("Server Connected Successfully!", "");
                temp3.Show();

            }
            catch
            {
                AlertGUI temp2 = new AlertGUI();
                temp2.setMessage("Could not find server");

                //temp2.ShowDialog();
                temp2.Show();

                temp5.Close();
                temp5.Dispose();

            }
        }
        //Create a config file
        public bool writeConfigFile(string[] tasks, string patient_name, string hostname, string username, string password)
        {
            string tasks_string = "";

            if (tasks == null)
            {
            }

            else
            {
                for (int i = 0; i < tasks.Length; ++i)
                {
                    if ((i = tasks.Length - 1) > 0)
                    {
                        tasks_string += tasks[i];
                    }

                    else
                    {

                        tasks_string += tasks[i] + ", ";
                    }

                }
            }

            if (!Directory.Exists(activityMonitorDirectory))
            {
                Directory.CreateDirectory(activityMonitorDirectory);
            }

            if (username.Contains('"'))
            {
                AlertGUI temp = new AlertGUI();
                temp.setMessage("Do not add \"");

                //temp.ShowDialog();
                temp.Show();

                return false;
            }
            if (hostname.Contains('"'))
            {
                AlertGUI temp = new AlertGUI();
                temp.setMessage("Do not add \"");

                //temp.ShowDialog();
                temp.Show();

                return false;
            }
            if (password.Contains('"'))
            {
                AlertGUI temp = new AlertGUI();
                temp.setMessage("Do not add \"");

                //temp.ShowDialog();
                temp.Show();

                return false;
            }
            if (patient_name.Contains('"'))
            {
                AlertGUI temp = new AlertGUI();
                temp.setMessage("Do not add \"");

                //temp.ShowDialog();
                temp.Show();

                return false;
            }

            //if config file exists, delete and create a new one
            if (configFileExists())
            {
                deleteConfigFile();
            }

            StreamWriter writeConfigFile = new StreamWriter(configFilePath);

            writeConfigFile.WriteLine("Last Known Tasks:\t {" + tasks_string + "}");
            writeConfigFile.WriteLine("Patient Name:\t {" + patient_name + "}");
            writeConfigFile.WriteLine("Hostname:\t {" + hostname + "}");
            writeConfigFile.WriteLine("Username:\t {" + username + "}");
            writeConfigFile.WriteLine("Password:\t {" + password + "}");
            writeConfigFile.WriteLine("Starttime:\t {00:00:00}");
            writeConfigFile.WriteLine("Endtime:\t {00:00:00}");
            writeConfigFile.WriteLine("Date:\t {00/00/00}");

            writeConfigFile.Close();
            return true;
        }
        //Create a config file
        public bool writeConfigFile(string[] tasks, string patient_name, string hostname, string username, string password)
        {
            string tasks_string = "";

            if (tasks == null)
            {
            }

            else
            {
                for (int i = 0; i < tasks.Length; ++i)
                {
                    if ((i = tasks.Length - 1) > 0)
                    {
                        tasks_string += tasks[i];
                    }

                    else
                    {
                        tasks_string += tasks[i] + ", ";
                    }
                }
            }


            if (!Directory.Exists(activityMonitorDirectory))
            {
                Directory.CreateDirectory(activityMonitorDirectory);
            }


            if (username.Contains('"'))
            {
                AlertGUI temp = new AlertGUI();
                temp.setMessage("Do not add \"");


                //temp.ShowDialog();
                temp.Show();

                return(false);
            }
            if (hostname.Contains('"'))
            {
                AlertGUI temp = new AlertGUI();
                temp.setMessage("Do not add \"");


                //temp.ShowDialog();
                temp.Show();

                return(false);
            }
            if (password.Contains('"'))
            {
                AlertGUI temp = new AlertGUI();
                temp.setMessage("Do not add \"");


                //temp.ShowDialog();
                temp.Show();

                return(false);
            }
            if (patient_name.Contains('"'))
            {
                AlertGUI temp = new AlertGUI();
                temp.setMessage("Do not add \"");


                //temp.ShowDialog();
                temp.Show();

                return(false);
            }

            //if config file exists, delete and create a new one
            if (configFileExists())
            {
                deleteConfigFile();
            }

            StreamWriter writeConfigFile = new StreamWriter(configFilePath);

            writeConfigFile.WriteLine("Last Known Tasks:\t {" + tasks_string + "}");
            writeConfigFile.WriteLine("Patient Name:\t {" + patient_name + "}");
            writeConfigFile.WriteLine("Hostname:\t {" + hostname + "}");
            writeConfigFile.WriteLine("Username:\t {" + username + "}");
            writeConfigFile.WriteLine("Password:\t {" + password + "}");
            writeConfigFile.WriteLine("Starttime:\t {00:00:00}");
            writeConfigFile.WriteLine("Endtime:\t {00:00:00}");
            writeConfigFile.WriteLine("Date:\t {00/00/00}");

            writeConfigFile.Close();
            return(true);
        }
Example #9
0
        private void new_timer_Tick(object sender, EventArgs e)
        {
            if (mainMenuPointer.goodConnection == false)
            {
                AlertGUI temp2 = new AlertGUI();
                temp2.setMessage("Connection to server lost: Setting default task");

                temp2.Show();
                temp2.BringToFront();

                mainMenuPointer.goodConnection = true;
            }
            if (mainMenuPointer.wiimoteCon == false)
            {
                AlertGUI temp = new AlertGUI();
                temp.setMessage("Wiimote not connected");
                temp.Show();
                temp.BringToFront();
                mainMenuPointer.wiimoteCon = true;
            }

            mainMenuPointer.ProcessSteps();
            this.Refresh();
            this.steps_value.Text = mainMenuPointer.getSteps().ToString();
            this.Refresh();

            if (mainMenuPointer.isON)
            {
                this.Show();
            }

            dis_counter++;
            seconds++;

            stepsMin();//calculates and sets the steps per minuite field

            this.distance_value.Text = (mainMenuPointer.getSteps() * .003).ToString() + " mi";


            if (seconds == 60)
            {
                seconds = 0;
                sec     = "00";
                minutes++;
            }

            if (seconds < 10)
            {
                sec = "0" + seconds.ToString();
            }


            if (seconds >= 10)
            {
                sec = seconds.ToString();
            }

            if (minutes == 60)
            {
                minutes = 0;
                min     = "00";
                hours++;
            }

            if (minutes < 10)
            {
                min = "0" + minutes.ToString();
            }

            if (minutes >= 10)
            {
                min = minutes.ToString();
            }

            if (hours < 10)
            {
                hr = "0" + hours.ToString();
            }

            if (hours >= 10)
            {
                hr = hours.ToString();
            }


            this.time_walking_value.Text = hr + ":" + min + ":" + sec;
        }