Esempio n. 1
0
        private void AutoProcess_Click(object sender, EventArgs e)
        {
            //check internet connection//
            WebClient web = new WebClient();

            try
            {
                web.OpenRead("http://www.google.com");
                InternetCon = true;
            }
            catch
            {
                InternetCon = false;
            }

            //Checking for internet connection done//

            //count how many devices there are
            double j = 0;

            try
            {
                while (true)
                {
                    Bitmap temp = new Bitmap("DeviceImage" + (int)j + ".jpg");
                    j++;
                }
            }

            catch
            {
            }

            //end of counting devices

            if (InternetCon)
            {
                int i = 0;
                try
                {
                    StreamReader reader   = new StreamReader("flaglist.txt");
                    string       flaglist = reader.ReadToEnd();
                    reader.Close();

                    while (true)
                    {
                        //Check for flagged images

                        Bitmap image = new Bitmap("DeviceImage" + i + ".jpg");
                        Regex  regs  = new Regex("Device" + i + "true");

                        if (!regs.IsMatch(flaglist))
                        {
                            GetGreenPercentage getgreenpercent           = new GetGreenPercentage();
                            double             PercentageOfBlackOriginal = getgreenpercent.GetPercentage(image);
                            Communications     comms = new Communications();
                            if (((PercentageOfBlackOriginal >= 4) & (PercentageOfBlackOriginal <= 8)) | (PercentageOfBlackOriginal >= 11) & (PercentageOfBlackOriginal <= 16))     //setting the checkboxes to correct state. Percentages between 2-8% for positive result
                            {
                                comms.SendEmail(EmailList[i], "Test Result: Device:" + i, "The result of your test is: Positive");
                            }

                            else
                            {
                                comms.SendEmail(EmailList[i], "Test Result: Device:" + i, "The result of your test is: Negative");
                            }
                        }
                        i++;
                        int percentage = (int)((1 / j) * 100);
                        AutoProcessProgressBar.Increment(percentage);
                        AutoProcessProgressBar.Update();
                    }
                }

                catch
                {
                    AutoProcessProgressBar.Value = 0;
                }
            }

            else
            {
                MessageTextBox.Text = "Please check the Internet connection and try again";
            }
        }
Esempio n. 2
0
        private void SendButtton_Click(object sender, EventArgs e)
        {
            //check internet connection//
            WebClient web      = new WebClient();
            Stream    myStream = null;

            try
            {
                myStream    = web.OpenRead("http://www.google.com");
                InternetCon = true;
            }
            catch
            {
                InternetCon = false;
            }

            myStream.Close();

            //Checking for internet connection done//



            if ((InternetCon == true) & (!flag))
            {
                Communications comms = new Communications();

                if ((EmailCheckBox.Checked == false) & (SMSCheckBox.Checked == false))
                {
                    MessageTextBox.Text = "No Message Sent, please tick Email or SMS checkbox";
                    StreamWriter writer = new StreamWriter("Responselist.txt", true);
                    writer.WriteLine("Device" + ImageNumber + "No ");
                    writer.Close();
                }

                if ((EmailCheckBox.Checked == true) & (SMSCheckBox.Checked == false))
                {
                    //overwrite previous entry for that device
                    StreamReader reader      = new StreamReader("Responselist.txt");
                    string       tempstring0 = reader.ReadToEnd();
                    reader.Close();

                    Regex        regs        = new Regex("Device" + ImageNumber + "No ");
                    string       tempstring1 = regs.Replace(tempstring0, ""); //deletes the "no" responses
                    StreamWriter writer      = new StreamWriter("Responselist.txt", true);
                    writer.WriteLine(tempstring1);

                    //write new entry
                    comms.SendEmail(EmailList[ImageNumber], "ImageAnalysis", MessageTextBox.Text);
                    MessageTextBox.Text = "Email Message Sent";
                    writer.WriteLine("Device" + ImageNumber + "Email ");
                    writer.Close();
                }

                if ((EmailCheckBox.Checked == false) & (SMSCheckBox.Checked == true))
                {
                    //overwrite previous entry for that device
                    StreamReader reader      = new StreamReader("Responselist.txt");
                    string       tempstring0 = reader.ReadToEnd();
                    reader.Close();

                    Regex        regs0       = new Regex("Device" + ImageNumber + "No ");
                    string       tempstring1 = regs0.Replace(tempstring0, ""); //delete all the "no" responses
                    StreamWriter writer      = new StreamWriter("Responselist.txt", true);
                    writer.WriteLine(tempstring1);

                    //write new entry
                    comms.SendSMS(PhoneNumberList[ImageNumber], MessageTextBox.Text);
                    MessageTextBox.Text = "SMS Message Sent";
                    writer.WriteLine("Device" + ImageNumber + "SMS ");
                    writer.Close();
                }

                if ((EmailCheckBox.Checked == true) & (SMSCheckBox.Checked == true))
                {
                    //overwrite previous entry for that device
                    StreamReader reader      = new StreamReader("Responselist.txt");
                    string       tempstring0 = reader.ReadToEnd();
                    reader.Close();

                    Regex  regs0       = new Regex("Device" + ImageNumber + "No ");
                    string tempstring1 = regs0.Replace(tempstring0, ""); //delete all the "no" responses
                    Regex  regs1       = new Regex("Device" + ImageNumber + "Email ");
                    string tempstring2 = regs0.Replace(tempstring1, ""); //delete all the "Email" Responses
                    Regex  regs2       = new Regex("Device" + ImageNumber + "SMS ");
                    string tempstring3 = regs0.Replace(tempstring2, ""); //delete all the "SMS" Responses

                    StreamWriter writer = new StreamWriter("Responselist.txt", true);
                    writer.WriteLine(tempstring3);
                    //write new entry
                    comms.SendEmail(EmailList[ImageNumber], "ImageAnalysis", MessageTextBox.Text);
                    comms.SendSMS(PhoneNumberList[ImageNumber], MessageTextBox.Text);
                    MessageTextBox.Text = "Email and SMS Message Sent";
                    writer.WriteLine("Device" + ImageNumber + "SMS and Email ");
                    writer.Close();
                }



                //check if the user has responded to the patient

                StreamReader reader1          = new StreamReader("Responselist.txt");
                string       tempResponselist = reader1.ReadToEnd();
                reader1.Close();

                Regex regs00 = new Regex("Device" + ImageNumber + "Email ");
                Regex reg1   = new Regex("Device" + ImageNumber + "SMS ");
                Regex regs3  = new Regex("Device" + ImageNumber + "SMS and Email ");


                response = "No"; //default response.

                if (regs00.IsMatch(tempResponselist))
                {
                    response = "Yes - Email";
                }

                if (reg1.IsMatch(tempResponselist))
                {
                    response = "Yes - SMS";
                }

                if (regs3.IsMatch(tempResponselist) | (regs00.IsMatch(tempResponselist)) & (reg1.IsMatch(tempResponselist)))
                {
                    response = "Yes - SMS & Email";
                }

                InformationTextBox.Text = "Name: " + NameList[0] + "\r\nEmail: " + EmailList[0] + "\r\nPhone Number: " + PhoneNumberList[0] +
                                          " \r\nResponded to: " + response + "\r\nFlag: " + flag;
            }

            else
            {
                MessageTextBox.Text = "No Message Sent - No Internet Connection";
                //checking for Flags

                if (flag == true)
                {
                    MessageTextBox.Text = "No Message Sent - Image Flagged";
                }
                // End of Check for flags
            }

            InternetTextBox.Text = InternetCon.ToString(); //display internet connection
        }