Example #1
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();
                }
            }
        }
        private void Reanalyze()
        {
            cutList.Clear();
            cutList = mysql.GetCut(firstId, lastId);

            bool   filter         = false;
            int    filterAge      = 0;
            string filterGenoType = "";
            string filterLayer    = "";

            if (string.IsNullOrEmpty(textBox3.Text) == false)
            {
                if (int.TryParse(textBox3.Text, out filterAge))
                {
                    filter = true;
                }
            }

            int customOffset        = 0;
            int customBlurredFactor = 0;
            int customIntersectionPointRestrictedRadius = 0;

            if (string.IsNullOrEmpty(textBox5.Text) == false)
            {
                int.TryParse(textBox5.Text, out customOffset);
            }

            if (string.IsNullOrEmpty(textBox6.Text) == false)
            {
                int.TryParse(textBox6.Text, out customBlurredFactor);
            }

            if (string.IsNullOrEmpty(textBox7.Text) == false)
            {
                int.TryParse(textBox7.Text, out customIntersectionPointRestrictedRadius);
            }

            if (string.IsNullOrEmpty(textBox4.Text) == false)
            {
                if (textBox4.Text.Trim().ToUpper() == "WT")
                {
                    filterGenoType = "WT";
                    filter         = true;
                }
                if (textBox4.Text.Trim().ToUpper() == "KO")
                {
                    filterGenoType = "KO";
                    filter         = true;
                }
            }

            if (string.IsNullOrEmpty(textBox8.Text) == false)
            {
                filterLayer = textBox8.Text.Trim().ToLower();
                filter      = true;
            }

            foreach (Cut cut in cutList)
            {
                try
                {
                    if (filter)
                    {
                        if (filterAge > 0 && cut.Age != filterAge)
                        {
                            continue;
                        }

                        if (string.IsNullOrEmpty(filterGenoType) == false && cut.Genotype != filterGenoType)
                        {
                            continue;
                        }

                        if (string.IsNullOrEmpty(filterLayer) == false && cut.Layer.ToLower().Contains(filterLayer) == false)
                        {
                            continue;
                        }
                    }

                    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 fileName =
                        $"P{cut.Age}_{cut.Animal}_{cut.Genotype}_{cut.Method}_{cut.ZoomFactor}x{cut.CutIdentifier}.jpg";
                    string filePath = Path.Combine(Path.GetTempPath(), fileName);
                    mysql.GetImage(cut.Id.ToString(), "marked image", filePath);

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

                    mysql.GetImage(cut.Id.ToString(), "original image", filePathOriginal);
                    mysql.GetImage(cut.Id.ToString(), "marked image", filePathMarked);

                    filePath = filePathOriginal;

                    List <Point> coordinates = mysql.GetCoordinates(cut.Id.ToString());

                    pleaseWait.Close();
                    Hide();

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

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

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

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

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

                    formWorker._waitTime    = _waitTime;
                    formWorker._filePath    = filePath;
                    formWorker._coordinates = coordinates;
                    formWorker._note        = cut.Note;
                    formWorker._layer       = cut.Layer;
                    formWorker._originalPictureOVERWRITE = new Bitmap(filePathOriginal);
                    formWorker._markedPictureOVERWRITE   = new Bitmap(filePathMarked);
                    formWorker.ShowDialog();
                }
                catch (Exception ex)
                {
                    //just for debug
                }
            }
        }