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 CompareButton_Click(object sender, EventArgs e)
        {
            //load the refrence image
            RefrenceImageBox.ImageLocation = refrenceImageFileName;
            RefrenceImage = new Bitmap(refrenceImageFileName);
            Bitmap ComparisonImage = new Bitmap("DeviceImage" + ImageNumber + ".jpg");

            if (LevelCheckBox.Checked)
            {
                LevelProgressBar.Value = 0; //resetting the progress bar
                CalculateLevel getlevel = new CalculateLevel(ComparisonImage);
                LevelTextBox.Text = getlevel.level;
                LevelProgressBar.Increment(100);                 //incrementing the progress bar
                ResultingImageBox.Image = getlevel.resultBitmap; //setting the resultant bitmap to imagebox.
                //writing protein levels to file
                StreamWriter w = new StreamWriter("ProteinLevelFile.txt", true);
                w.WriteLine("DeviceImage" + ImageNumber + "=" + getlevel.level);
                w.Close();
            }

            if (GreenCheckbox.Checked & !SquaresCheckbox.Checked)
            {
                ComparisonProgressBar.Value = 0;     //resetting progress bar
                //delete previous entry
                StreamReader reader    = new StreamReader("PercentageList.txt");
                string       totalfile = reader.ReadToEnd();
                reader.Close();
                Regex regs = new Regex("Device" + ImageNumber + "=");
                if (regs.IsMatch(totalfile))
                {
                    string newtotalfile = regs.Replace(totalfile, "");

                    StreamWriter tempwriter = new StreamWriter("PercentageList.txt");
                    tempwriter.WriteLine(newtotalfile);
                    tempwriter.Close();
                }


                GetGreenPercentage getgreen = new GetGreenPercentage();
                double             PercentageOfBlackOriginal = getgreen.GetPercentage(ComparisonImage);
                if (((PercentageOfBlackOriginal >= 4) & (PercentageOfBlackOriginal <= 8)) | (PercentageOfBlackOriginal >= 11) & (PercentageOfBlackOriginal <= 16)) //setting the checkboxes to correct state. Percentages between 2-8% for positive result
                {
                    CheckBoxFalse.Checked = false;
                    CheckBoxTrue.Checked  = true;
                }

                else
                {
                    CheckBoxFalse.Checked = true;
                    CheckBoxTrue.Checked  = false;
                }

                StreamWriter writer = new StreamWriter("PercentageList.txt", true);
                writer.WriteLine("Device" + ImageNumber + "=" + PercentageOfBlackOriginal);
                PercentageTextBox.Text = "" + PercentageOfBlackOriginal + "%";
                writer.Close();
                ResultingImageBox.Image = getgreen.ResultantImage;
                ComparisonProgressBar.Increment(100); //indicating the comparison is done.
            }

            if (!GreenCheckbox.Checked & SquaresCheckbox.Checked)
            {
                ComparisonProgressBar.Value = 0; //resetting progress bar
                //delete previous entry
                StreamReader reader    = new StreamReader("PercentageList.txt");
                string       totalfile = reader.ReadToEnd();
                reader.Close();
                Regex regs = new Regex("Device" + ImageNumber + "=");
                if (regs.IsMatch(totalfile))
                {
                    string newtotalfile = regs.Replace(totalfile, "");

                    StreamWriter tempwriter = new StreamWriter("PercentageList.txt");
                    tempwriter.WriteLine(newtotalfile);
                    tempwriter.Close();
                }

                ComparisonProgressBar.Value = 0;
                CompareImages compareImages = new CompareImages(RefrenceImage, ComparisonImage, 1000);
                ResultingImageBox.Image = compareImages.SquareImage;
                if (compareImages.TotalPercentageDifference < 20) //setting the checkboxes to correct state
                {
                    CheckBoxFalse.Checked = false;
                    CheckBoxTrue.Checked  = true;
                }

                else
                {
                    CheckBoxFalse.Checked = true;
                    CheckBoxTrue.Checked  = false;
                }

                StreamWriter writer = new StreamWriter("PercentageList.txt", true);
                writer.WriteLine("Device" + ImageNumber + "=" + compareImages.TotalPercentageDifference);
                PercentageTextBox.Text = "" + compareImages.TotalPercentageDifference + "%";
                writer.Close();
                ComparisonProgressBar.Increment(100); //indicating the comparison is done.
            }
        }