Esempio n. 1
0
        private void btnDownload_Click(object sender, EventArgs e)
        {
            btnFix.Enabled    = false;
            btnUpload.Enabled = false;

            cut            = null;
            fissureCount   = 0;
            fissurePeriSum = 0;

            fisPeri_1_old  = -1;
            fisPeri_2_old  = -1;
            fisPeri_3_old  = -1;
            fisPeri_4_old  = -1;
            fisPeri_5_old  = -1;
            fisPeri_6_old  = -1;
            fisPeri_7_old  = -1;
            fisPeri_8_old  = -1;
            fisPeri_9_old  = -1;
            fisPeri_10_old = -1;

            fisPeri_1_new  = -1;
            fisPeri_2_new  = -1;
            fisPeri_3_new  = -1;
            fisPeri_4_new  = -1;
            fisPeri_5_new  = -1;
            fisPeri_6_new  = -1;
            fisPeri_7_new  = -1;
            fisPeri_8_new  = -1;
            fisPeri_9_new  = -1;
            fisPeri_10_new = -1;

            MySQL mysql = new MySQL();

            cut = mysql.GetCut(textBox1.Text, textBox2.Text, textBox3.Text, textBox4.Text);

            if (cut == null)
            {
                MessageBox.Show("No cut for this data found!");
                return;
            }

            List <Result> results = mysql.GetResults(cut.Id.ToString());

            if (results == null || results.Count == 0)
            {
                MessageBox.Show("No results for this cut found!");
                return;
            }

            string fisPeri_1_string = results.FirstOrDefault(res => res.ResultType == "fissure" && res.Identifier == "1" && res.Key == "perimeter")?.Value;

            if (string.IsNullOrEmpty(fisPeri_1_string) == false)
            {
                Double.TryParse(fisPeri_1_string, out fisPeri_1_old);
                fissureCount++;
            }

            string fisPeri_2_string = results.FirstOrDefault(res => res.ResultType == "fissure" && res.Identifier == "2" && res.Key == "perimeter")?.Value;

            if (string.IsNullOrEmpty(fisPeri_2_string) == false)
            {
                Double.TryParse(fisPeri_2_string, out fisPeri_2_old);
                fissureCount++;
            }

            string fisPeri_3_string = results.FirstOrDefault(res => res.ResultType == "fissure" && res.Identifier == "3" && res.Key == "perimeter")?.Value;

            if (string.IsNullOrEmpty(fisPeri_3_string) == false)
            {
                Double.TryParse(fisPeri_3_string, out fisPeri_3_old);
                fissureCount++;
            }

            string fisPeri_4_string = results.FirstOrDefault(res => res.ResultType == "fissure" && res.Identifier == "4" && res.Key == "perimeter")?.Value;

            if (string.IsNullOrEmpty(fisPeri_4_string) == false)
            {
                Double.TryParse(fisPeri_4_string, out fisPeri_4_old);
                fissureCount++;
            }

            string fisPeri_5_string = results.FirstOrDefault(res => res.ResultType == "fissure" && res.Identifier == "5" && res.Key == "perimeter")?.Value;

            if (string.IsNullOrEmpty(fisPeri_5_string) == false)
            {
                Double.TryParse(fisPeri_5_string, out fisPeri_5_old);
                fissureCount++;
            }

            string fisPeri_6_string = results.FirstOrDefault(res => res.ResultType == "fissure" && res.Identifier == "6" && res.Key == "perimeter")?.Value;

            if (string.IsNullOrEmpty(fisPeri_6_string) == false)
            {
                Double.TryParse(fisPeri_6_string, out fisPeri_6_old);
                fissureCount++;
            }

            string fisPeri_7_string = results.FirstOrDefault(res => res.ResultType == "fissure" && res.Identifier == "7" && res.Key == "perimeter")?.Value;

            if (string.IsNullOrEmpty(fisPeri_7_string) == false)
            {
                Double.TryParse(fisPeri_7_string, out fisPeri_7_old);
                fissureCount++;
            }

            string fisPeri_8_string = results.FirstOrDefault(res => res.ResultType == "fissure" && res.Identifier == "8" && res.Key == "perimeter")?.Value;

            if (string.IsNullOrEmpty(fisPeri_8_string) == false)
            {
                Double.TryParse(fisPeri_8_string, out fisPeri_8_old);
                fissureCount++;
            }

            string fisPeri_9_string = results.FirstOrDefault(res => res.ResultType == "fissure" && res.Identifier == "9" && res.Key == "perimeter")?.Value;

            if (string.IsNullOrEmpty(fisPeri_9_string) == false)
            {
                Double.TryParse(fisPeri_9_string, out fisPeri_9_old);
                fissureCount++;
            }

            string fisPeri_10_string = results.FirstOrDefault(res => res.ResultType == "fissure" && res.Identifier == "10" && res.Key == "perimeter")?.Value;

            if (string.IsNullOrEmpty(fisPeri_10_string) == false)
            {
                Double.TryParse(fisPeri_10_string, out fisPeri_10_old);
                fissureCount++;
            }

            AddOldRow("1", fisPeri_1_old);
            AddOldRow("2", fisPeri_2_old);
            AddOldRow("3", fisPeri_3_old);
            AddOldRow("4", fisPeri_4_old);
            AddOldRow("5", fisPeri_5_old);
            AddOldRow("6", fisPeri_6_old);
            AddOldRow("7", fisPeri_7_old);
            AddOldRow("8", fisPeri_8_old);
            AddOldRow("9", fisPeri_9_old);
            AddOldRow("10", fisPeri_10_old);

            btnFix.Enabled = true;
        }
Esempio n. 2
0
        public void GetImage(string id, string type, string localFilePath)
        {
            MySQL innerMySql = null;

            try
            {
                if (File.Exists(localFilePath))
                {
                    File.Delete(localFilePath);
                }

                string query = $"SELECT cImage FROM vImage WHERE cType = '{type}' AND kCut = {id}";

                innerMySql           = new MySQL();
                innerMySql._waitTime = _waitTime;
                innerMySql.ConnectToMySQL();

                MySqlCommand cmd = new MySqlCommand(query, innerMySql.Connection);
                cmd.CommandType = CommandType.Text;

                using (MySqlDataReader mySqlDataReader = cmd.ExecuteReader())
                {
                    while (mySqlDataReader.Read())
                    {
                        try
                        {
                            int size      = (int)mySqlDataReader.GetBytes(0, 0, null, 0, 0);
                            var result    = new byte[size];
                            int bytesRead = 0;
                            int curPos    = 0;
                            while (curPos < size)
                            {
                                bytesRead += (int)mySqlDataReader.GetBytes(0, curPos, result, curPos, size - curPos);
                                curPos    += bytesRead;
                            }

                            File.WriteAllBytes(localFilePath, result);
                        }
                        catch (Exception ex)
                        {
                            MessageBoxAutocloseWithButtons.Show(_waitTime, true, "Ok", "Cancel",
                                                                ex.Message);
                        }
                    }

                    mySqlDataReader.Close();
                }

                try
                {
                    innerMySql.DisconnectFromMySQL();
                }
                catch (Exception ex)
                {
                    MessageBoxAutocloseWithButtons.Show(_waitTime, true, "Ok", "Cancel",
                                                        ex.Message);
                }
            }
            catch (Exception ex)
            {
                MessageBoxAutocloseWithButtons.Show(_waitTime, true, "Ok", "Cancel",
                                                    ex.Message);
                try
                {
                    innerMySql.DisconnectFromMySQL();
                }
                catch (Exception exInner)
                {
                    MessageBoxAutocloseWithButtons.Show(_waitTime, true, "Ok", "Cancel",
                                                        exInner.Message);
                }
            }
            finally
            {
                if (innerMySql != null)
                {
                    try
                    {
                        innerMySql.DisconnectFromMySQL();
                    }
                    catch (Exception ex)
                    {
                        MessageBoxAutocloseWithButtons.Show(_waitTime, true, "Ok", "Cancel",
                                                            ex.Message);
                    }
                }
            }
        }
Esempio n. 3
0
        private void btnUpload_Click(object sender, EventArgs e)
        {
            MySQL mysql = new MySQL();

            Result result_fisPer_1 = new Result
            {
                CutId      = cut.Id,
                ResultType = "fissure",
                Identifier = "1",
                Key        = "perimeter",
                Unit       = "µm",
                Value      = fisPeri_1_new.ToString(FormWorker.FLOAT_ACCURACY)
            };

            mysql.CreateResultOnlyValid(result_fisPer_1);

            Result result_fisPer_2 = new Result
            {
                CutId      = cut.Id,
                ResultType = "fissure",
                Identifier = "2",
                Key        = "perimeter",
                Unit       = "µm",
                Value      = fisPeri_2_new.ToString(FormWorker.FLOAT_ACCURACY)
            };

            mysql.CreateResultOnlyValid(result_fisPer_2);

            Result result_fisPer_3 = new Result
            {
                CutId      = cut.Id,
                ResultType = "fissure",
                Identifier = "3",
                Key        = "perimeter",
                Unit       = "µm",
                Value      = fisPeri_3_new.ToString(FormWorker.FLOAT_ACCURACY)
            };

            mysql.CreateResultOnlyValid(result_fisPer_3);

            Result result_fisPer_4 = new Result
            {
                CutId      = cut.Id,
                ResultType = "fissure",
                Identifier = "4",
                Key        = "perimeter",
                Unit       = "µm",
                Value      = fisPeri_4_new.ToString(FormWorker.FLOAT_ACCURACY)
            };

            mysql.CreateResultOnlyValid(result_fisPer_4);

            Result result_fisPer_5 = new Result
            {
                CutId      = cut.Id,
                ResultType = "fissure",
                Identifier = "5",
                Key        = "perimeter",
                Unit       = "µm",
                Value      = fisPeri_5_new.ToString(FormWorker.FLOAT_ACCURACY)
            };

            mysql.CreateResultOnlyValid(result_fisPer_5);

            Result result_fisPer_6 = new Result
            {
                CutId      = cut.Id,
                ResultType = "fissure",
                Identifier = "6",
                Key        = "perimeter",
                Unit       = "µm",
                Value      = fisPeri_6_new.ToString(FormWorker.FLOAT_ACCURACY)
            };

            mysql.CreateResultOnlyValid(result_fisPer_6);

            Result result_fisPer_7 = new Result
            {
                CutId      = cut.Id,
                ResultType = "fissure",
                Identifier = "7",
                Key        = "perimeter",
                Unit       = "µm",
                Value      = fisPeri_7_new.ToString(FormWorker.FLOAT_ACCURACY)
            };

            mysql.CreateResultOnlyValid(result_fisPer_7);

            Result result_fisPer_8 = new Result
            {
                CutId      = cut.Id,
                ResultType = "fissure",
                Identifier = "8",
                Key        = "perimeter",
                Unit       = "µm",
                Value      = fisPeri_8_new.ToString(FormWorker.FLOAT_ACCURACY)
            };

            mysql.CreateResultOnlyValid(result_fisPer_8);

            Result result_fisPer_9 = new Result
            {
                CutId      = cut.Id,
                ResultType = "fissure",
                Identifier = "9",
                Key        = "perimeter",
                Unit       = "µm",
                Value      = fisPeri_9_new.ToString(FormWorker.FLOAT_ACCURACY)
            };

            mysql.CreateResultOnlyValid(result_fisPer_9);

            Result result_fisPer_10 = new Result
            {
                CutId      = cut.Id,
                ResultType = "fissure",
                Identifier = "10",
                Key        = "perimeter",
                Unit       = "µm",
                Value      = fisPeri_10_new.ToString(FormWorker.FLOAT_ACCURACY)
            };

            mysql.CreateResultOnlyValid(result_fisPer_10);

            if (fisPeri_1_new > 0)
            {
                fissurePeriSum += fisPeri_1_new;
            }

            if (fisPeri_2_new > 0)
            {
                fissurePeriSum += fisPeri_2_new;
            }

            if (fisPeri_3_new > 0)
            {
                fissurePeriSum += fisPeri_3_new;
            }

            if (fisPeri_4_new > 0)
            {
                fissurePeriSum += fisPeri_4_new;
            }

            if (fisPeri_5_new > 0)
            {
                fissurePeriSum += fisPeri_5_new;
            }

            if (fisPeri_6_new > 0)
            {
                fissurePeriSum += fisPeri_6_new;
            }

            if (fisPeri_7_new > 0)
            {
                fissurePeriSum += fisPeri_7_new;
            }

            if (fisPeri_8_new > 0)
            {
                fissurePeriSum += fisPeri_8_new;
            }

            if (fisPeri_9_new > 0)
            {
                fissurePeriSum += fisPeri_9_new;
            }

            if (fisPeri_10_new > 0)
            {
                fissurePeriSum += fisPeri_10_new;
            }

            Result result_fisPer_avg = new Result
            {
                CutId      = cut.Id,
                ResultType = "fissure",
                Identifier = "Ø",
                Key        = "perimeter",
                Unit       = "µm",
                Value      = (fissurePeriSum / fissureCount).ToString(FormWorker.FLOAT_ACCURACY)
            };

            mysql.CreateResultOnlyValid(result_fisPer_avg);

            Result result_fisPer_sum = new Result
            {
                CutId      = cut.Id,
                ResultType = "fissure",
                Identifier = "Σ",
                Key        = "perimeter",
                Unit       = "µm",
                Value      = fissurePeriSum.ToString(FormWorker.FLOAT_ACCURACY)
            };

            mysql.CreateResultOnlyValid(result_fisPer_sum);



            if (MessageBoxAutocloseWithButtons.Show(0, true, "No", "Yes",
                                                    $"Show result online?") == DialogResult.Cancel)
            //if (MessageBox.Show("Show result online?", "Result", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                Process.Start($"{Config.HomepageBaseUrl}/php/details.php?age={cut.Age}&genotype={cut.Genotype}&animal={cut.Animal}&cutidentifier={cut.CutIdentifier}");
            }


            Close();
        }
Esempio n. 4
0
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            var senderGrid = (DataGridView)sender;

            if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn &&
                e.RowIndex >= 0)
            {
                //if(MessageBoxAutocloseWithButtons.Show(5, true, "Yes", "No", $"Include X Y coordinates?") == DialogResult.OK)
                if (MessageBox.Show("Include X Y coordinates?", "Include coordinates", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    FormPleaseWait pleaseWait = new FormPleaseWait("download data");
                    pleaseWait.Owner         = this;
                    pleaseWait.StartPosition = FormStartPosition.CenterParent;
                    pleaseWait.Show(this);
                    int x = this.DesktopBounds.Left + (this.Width - pleaseWait.Width) / 2;
                    int y = this.DesktopBounds.Top + (this.Height - pleaseWait.Height) / 2;
                    pleaseWait.SetDesktopLocation(x, y);

                    string id = senderGrid.Rows[e.RowIndex].Cells[0].Value.ToString();

                    MySQL mySql = new MySQL();

                    string fileName = $"P{senderGrid.Rows[e.RowIndex].Cells[1].Value}_{senderGrid.Rows[e.RowIndex].Cells[3].Value}_{senderGrid.Rows[e.RowIndex].Cells[2].Value}_{senderGrid.Rows[e.RowIndex].Cells[5].Value}_{senderGrid.Rows[e.RowIndex].Cells[8].Value}x{senderGrid.Rows[e.RowIndex].Cells[4].Value}.jpg";
                    string filePath = Path.Combine(Path.GetTempPath(), fileName);
                    mySql.GetImage(id, "marked image", filePath);

                    string filePathOriginal = Path.Combine(Path.GetTempPath(), "original-" + fileName);
                    string filePathMarked   = Path.Combine(Path.GetTempPath(), "marked-" + fileName);

                    mySql.GetImage(id, "original image", filePathOriginal);
                    mySql.GetImage(id, "marked image", filePathMarked);

                    filePath = filePathOriginal;

                    List <Point> coordinates = mySql.GetCoordinates(id);

                    pleaseWait.Close();
                    Hide();

                    int    blurredFactor       = FormWorker.fallbackBlurredFactor;
                    string blurredFactorString = blurredFactor.ToString();
                    if (MessageBoxCustom.InputBox("Setting: Min Dist", "minimal distance between 2 datapoints:", ref blurredFactorString) == DialogResult.OK)
                    {
                        int.TryParse(blurredFactorString, out blurredFactor);
                    }

                    int    offset       = FormWorker.fallbackOffset;
                    string offsetString = offset.ToString();
                    if (MessageBoxCustom.InputBox("Setting: Offset", "offset:", ref offsetString) == DialogResult.OK)
                    {
                        int.TryParse(offsetString, out offset);
                    }

                    int    restArea       = FormWorker.fallbackIntersectionPointRestrictedRadius;
                    string restAreaString = restArea.ToString();
                    if (MessageBoxCustom.InputBox("Setting: Restricted Area", "intersection point restriced area:", ref restAreaString) == DialogResult.OK)
                    {
                        int.TryParse(restAreaString, out restArea);
                    }

                    FormWorker formWorker = new FormWorker(WorkerMethod.ReanalyzeSingleDatapointsAndMeasurement, this);


                    bool smthingChanged = false;
                    if (offset > 0)
                    {
                        formWorker.DEFAULT_OFFSET   = offset;
                        formWorker._offsetOuterLine = offset;
                        smthingChanged = true;
                    }

                    if (blurredFactor > 0)
                    {
                        formWorker.DEFAULT_BLURRED_FACTOR = blurredFactor;
                        formWorker._blurredFactor         = blurredFactor;
                        smthingChanged = true;
                    }

                    if (restArea > 0)
                    {
                        formWorker.DEFAULT_INTERSECTION_POINT_RESTRICTED_RADIUS = restArea;
                        formWorker._intersectionPointRestrictedRadius           = restArea;
                        smthingChanged = true;
                    }

                    if (smthingChanged)
                    {
                        formWorker.FillOptionsWithDefaultValues();
                    }

                    formWorker._waitTime    = waitTime;
                    formWorker._filePath    = filePath;
                    formWorker._coordinates = coordinates;
                    formWorker._note        = senderGrid.Rows[e.RowIndex].Cells[10].Value.ToString();
                    formWorker._layer       = senderGrid.Rows[e.RowIndex].Cells[9].Value.ToString();

                    if (File.Exists(filePathOriginal))
                    {
                        formWorker._originalPictureOVERWRITE = new Bitmap(filePathOriginal);
                    }
                    else
                    {
                        formWorker._originalPictureOVERWRITE = new Bitmap(1024, 768);
                    }

                    if (File.Exists(filePathMarked))
                    {
                        formWorker._markedPictureOVERWRITE = new Bitmap(filePathMarked);
                    }
                    else
                    {
                        formWorker._markedPictureOVERWRITE = new Bitmap(1024, 768);
                    }

                    formWorker.ShowDialog();
                }
                else
                {
                    FormPleaseWait pleaseWait = new FormPleaseWait("download data");
                    pleaseWait.Owner         = this;
                    pleaseWait.StartPosition = FormStartPosition.CenterParent;
                    pleaseWait.Show(this);
                    int x = this.DesktopBounds.Left + (this.Width - pleaseWait.Width) / 2;
                    int y = this.DesktopBounds.Top + (this.Height - pleaseWait.Height) / 2;
                    pleaseWait.SetDesktopLocation(x, y);

                    string id = senderGrid.Rows[e.RowIndex].Cells[0].Value.ToString();

                    MySQL mySql = new MySQL();

                    string fileName =
                        $"P{senderGrid.Rows[e.RowIndex].Cells[1].Value}_{senderGrid.Rows[e.RowIndex].Cells[3].Value}_{senderGrid.Rows[e.RowIndex].Cells[2].Value}_{senderGrid.Rows[e.RowIndex].Cells[5].Value}_{senderGrid.Rows[e.RowIndex].Cells[8].Value}x{senderGrid.Rows[e.RowIndex].Cells[4].Value}.jpg";
                    string filePath = Path.Combine(Path.GetTempPath(), fileName);
                    mySql.GetImage(id, "original image", filePath);

                    string filePathOriginal = Path.Combine(Path.GetTempPath(), "original-" + fileName);
                    string filePathMarked   = Path.Combine(Path.GetTempPath(), "marked-" + fileName);

                    mySql.GetImage(id, "original image", filePathOriginal);
                    mySql.GetImage(id, "marked image", filePathMarked);

                    pleaseWait.Close();
                    Hide();

                    int    offset       = FormWorker.fallbackOffset;
                    string offsetString = offset.ToString();
                    if (MessageBoxCustom.InputBox("Setting: Offset", "offset:", ref offsetString) == DialogResult.OK)
                    {
                        int.TryParse(offsetString, out offset);
                    }

                    int    blurredFactor       = FormWorker.fallbackBlurredFactor;
                    string blurredFactorString = blurredFactor.ToString();
                    if (MessageBoxCustom.InputBox("Setting: Min Dist", "minimal distance between 2 datapoints:", ref blurredFactorString) == DialogResult.OK)
                    {
                        int.TryParse(blurredFactorString, out blurredFactor);
                    }

                    int    restArea       = FormWorker.fallbackIntersectionPointRestrictedRadius;
                    string restAreaString = restArea.ToString();
                    if (MessageBoxCustom.InputBox("Setting: Restricted Area", "intersection point restriced area:", ref restAreaString) == DialogResult.OK)
                    {
                        int.TryParse(restAreaString, out restArea);
                    }

                    FormWorker formWorker = new FormWorker(WorkerMethod.ReanalyzeSingleDatapointsAndMeasurement, this);


                    bool smthingChanged = false;
                    if (offset > 0)
                    {
                        formWorker.DEFAULT_OFFSET   = offset;
                        formWorker._offsetOuterLine = offset;
                        smthingChanged = true;
                    }

                    if (blurredFactor > 0)
                    {
                        formWorker.DEFAULT_BLURRED_FACTOR = blurredFactor;
                        formWorker._blurredFactor         = blurredFactor;
                        smthingChanged = true;
                    }

                    if (restArea > 0)
                    {
                        formWorker.DEFAULT_INTERSECTION_POINT_RESTRICTED_RADIUS = restArea;
                        formWorker._intersectionPointRestrictedRadius           = restArea;
                        smthingChanged = true;
                    }

                    if (smthingChanged)
                    {
                        formWorker.FillOptionsWithDefaultValues();
                    }

                    formWorker._waitTime = waitTime;
                    formWorker._filePath = filePath;
                    formWorker._layer    = senderGrid.Rows[e.RowIndex].Cells[9].Value.ToString();

                    if (File.Exists(filePathOriginal))
                    {
                        formWorker._originalPictureOVERWRITE = new Bitmap(filePathOriginal);
                    }
                    else
                    {
                        formWorker._originalPictureOVERWRITE = new Bitmap(1024, 768);
                    }

                    if (File.Exists(filePathMarked))
                    {
                        formWorker._markedPictureOVERWRITE = new Bitmap(filePathMarked);
                    }
                    else
                    {
                        formWorker._markedPictureOVERWRITE = new Bitmap(1024, 768);
                    }

                    formWorker.ShowDialog();
                }
            }
        }