public void EditQualityMetric(DataGridViewRow dr, QualityMetric qm)
        {
            if (qm.SegmentId != QualitivityRevisionController.SelectedSegmentId && qm.ParagraphId != QualitivityRevisionController.SelectedParagraphId)
            {
                FindSegmentInEditor();
            }


            var f = new Dialogs.QualityMetrics.QualityMetric
            {
                Metric = qm,
                IsEdit = true
            };

            f.ShowDialog();
            if (!f.Saved)
            {
                return;
            }
            qm.Updated = true;
            if (qm.RecordId != -1)
            {
                //if the QM entry was created originally in a different session, then
                //a independant entry is always created with a new ID.

                //Note: only when the QM is belonging to the same edit session can it be
                //updated without creating a new entry in the database.
                qm.Id = Guid.NewGuid().ToString();
            }
            qm.Modified = DateTime.Now;
            qm.UserName = Tracked.Settings.UserProfile.UserName;

            UpdateQualityMetricInDataViewList(dr, qm);
        }
        private void dataGridView_qm_DragDrop(object sender, DragEventArgs e)
        {
            var qm = new QualityMetric {
                Content = Tracked.ActiveDocument.Selection.Current.ToString()
            };

            QualitivityRevisionController.AddNewQualityMetric(qm);
        }
        private void toolStripButton_add_Click(object sender, EventArgs e)
        {
            var qm = new QualityMetric {
                Content = Tracked.ActiveDocument.Selection.Current.ToString()
            };


            AddNewQualityMetric(qm);
        }
        public void AddNewQualityMetric(QualityMetric qm)
        {
            var f = new Dialogs.QualityMetrics.QualityMetric();

            qm.ParagraphId = QualitivityRevisionController.SelectedParagraphId;
            qm.SegmentId   = QualitivityRevisionController.SelectedSegmentId;
            qm.Id          = Guid.NewGuid().ToString();

            qm.Created  = DateTime.Now;
            qm.Modified = DateTime.Now;
            qm.UserName = Tracked.Settings.UserProfile.UserName;
            f.Metric    = qm;
            f.IsEdit    = false;
            f.ShowDialog();
            if (!f.Saved)
            {
                return;
            }
            qm.Updated = true;
            //add the new qm to the list
            AddQualityMetricToDataViewList(qm);
        }
        private void button_insert_Click(object sender, EventArgs e)
        {
            if (comboBox_qm.SelectedItem.ToString().Trim() == string.Empty)
            {
                return;
            }
            var qm = new QualityMetric
            {
                ParagraphId  = QualitivityRevisionController.SelectedParagraphId,
                SegmentId    = QualitivityRevisionController.SelectedSegmentId,
                Id           = Guid.NewGuid().ToString(),
                Name         = comboBox_qm.SelectedItem.ToString(),
                SeverityName = comboBox_severity.SelectedItem.ToString(),
                Created      = DateTime.Now,
                Modified     = DateTime.Now,
                UserName     = Tracked.Settings.UserProfile.UserName,
                Updated      = true
            };

            #region  |  severityWeight  |
            foreach (var severity in Tracked.Settings.QualityMetricGroup.Severities)
            {
                if (string.Compare(qm.SeverityName, severity.Name, StringComparison.OrdinalIgnoreCase) != 0)
                {
                    continue;
                }
                qm.SeverityValue = severity.Value;
                break;
            }
            #endregion
            qm.Content = textBox_content.Text;
            qm.Comment = textBox_comment.Text;

            //add the qm to the container
            AddQualityMetricToDataViewList(qm);


            #region  |  clean up quick insert  |

            comboBox_qm.Items.Clear();
            comboBox_qm.Items.Add(string.Empty);
            comboBox_qm.SelectedIndex = 0;

            #region  |  comboBox_severity  |
            try
            {
                comboBox_severity.BeginUpdate();

                comboBox_severity.Items.Clear();
                comboBox_severity.Items.Add(string.Empty);
                foreach (var severity in Tracked.Settings.QualityMetricGroup.Severities)
                {
                    comboBox_severity.Items.Add(severity.Name);
                }
                comboBox_severity.SelectedIndex = 0;

                comboBox_severity.Enabled = false;
            }
            finally
            {
                comboBox_severity.EndUpdate();
            }
            #endregion

            textBox_content.Text = string.Empty;
            textBox_comment.Text = string.Empty;

            #endregion
        }
        private void UpdateQualityMetricInDataViewList(DataGridViewRow dr, QualityMetric qm)
        {
            var dataGridViewImageCell = dr.Cells["Column_status"] as DataGridViewImageCell;
            var img = imageList1.Images["empty"];

            switch (qm.Status)
            {
            case QualityMetric.ItemStatus.Open: img = imageList1.Images["Flag-Blue"]; break;

            case QualityMetric.ItemStatus.Resolved: img = imageList1.Images["Flag-Green"]; break;

            default: img = imageList1.Images["Flag-Violet"]; break;
            }
            if (dataGridViewImageCell != null)
            {
                dataGridViewImageCell.ImageLayout = DataGridViewImageCellLayout.Normal;
                dataGridViewImageCell.Value       = img;
                dataGridViewImageCell.ValueType   = typeof(Image);
                dataGridViewImageCell.ToolTipText = string.Empty;
                switch (qm.Status)
                {
                case QualityMetric.ItemStatus.Open: dataGridViewImageCell.ToolTipText = "Open"; break;

                case QualityMetric.ItemStatus.Resolved: dataGridViewImageCell.ToolTipText = "Resolved"; break;

                default: dataGridViewImageCell.ToolTipText = "Ignore"; break;
                }
            }

            dataGridViewImageCell = dr.Cells["Column_recorded"] as DataGridViewImageCell;
            img = qm.RecordId > -1 ? imageList1.Images["Flag-Yellow"] : imageList1.Images["empty"];

            if (dataGridViewImageCell != null)
            {
                dataGridViewImageCell.ImageLayout = DataGridViewImageCellLayout.Normal;
                dataGridViewImageCell.Value       = img;
                dataGridViewImageCell.ValueType   = typeof(Image);
                dataGridViewImageCell.ToolTipText = "";
            }


            var textBox = dr.Cells["Column_qm"] as DataGridViewTextBoxCell;

            if (textBox != null)
            {
                textBox.Value = qm.Name;
            }

            textBox = dr.Cells["Column_severity"] as DataGridViewTextBoxCell;
            if (textBox != null)
            {
                textBox.Value = qm.SeverityName;
            }

            textBox = dr.Cells["Column_content"] as DataGridViewTextBoxCell;
            if (textBox != null)
            {
                textBox.Value = qm.Content;
            }

            textBox = dr.Cells["Column_comment"] as DataGridViewTextBoxCell;
            if (textBox != null)
            {
                textBox.Value = qm.Comment;
            }


            dr.Tag = qm;

            dataGridView_qm_SelectionChanged(null, null);
        }
        private void AddQualityMetricToDataViewList(QualityMetric qm)
        {
            QualitivityRevisionController.QualityMetrics.Add(qm);

            var n = dataGridView_qm.Rows.Add();

            var dataGridViewImageCell = dataGridView_qm.Rows[n].Cells["Column_status"] as DataGridViewImageCell;
            var img = imageList1.Images["empty"];

            switch (qm.Status)
            {
            case QualityMetric.ItemStatus.Open: img = imageList1.Images["Flag-Blue"]; break;

            case QualityMetric.ItemStatus.Resolved: img = imageList1.Images["Flag-Green"]; break;

            default: img = imageList1.Images["Flag-Violet"]; break;
            }
            if (dataGridViewImageCell != null)
            {
                dataGridViewImageCell.ImageLayout = DataGridViewImageCellLayout.Normal;
                dataGridViewImageCell.Value       = img;
                dataGridViewImageCell.ValueType   = typeof(Image);
                dataGridViewImageCell.ToolTipText = string.Empty;
                switch (qm.Status)
                {
                case QualityMetric.ItemStatus.Open: dataGridViewImageCell.ToolTipText = "Open"; break;

                case QualityMetric.ItemStatus.Resolved: dataGridViewImageCell.ToolTipText = "Resolved"; break;

                default: dataGridViewImageCell.ToolTipText = "Ignore"; break;
                }
            }

            dataGridViewImageCell = dataGridView_qm.Rows[n].Cells["Column_recorded"] as DataGridViewImageCell;
            img = qm.RecordId > -1 ? imageList1.Images["Flag-Yellow"] : imageList1.Images["empty"];

            if (dataGridViewImageCell != null)
            {
                dataGridViewImageCell.ImageLayout = DataGridViewImageCellLayout.Normal;
                dataGridViewImageCell.Value       = img;
                dataGridViewImageCell.ValueType   = typeof(Image);
                dataGridViewImageCell.ToolTipText = "";
            }


            var segmentId = dataGridView_qm.Rows[n].Cells["Column_segment_id"] as DataGridViewTextBoxCell;

            if (segmentId != null)
            {
                segmentId.Value = qm.SegmentId;
            }

            var textBox = dataGridView_qm.Rows[n].Cells["Column_qm"] as DataGridViewTextBoxCell;

            if (textBox != null)
            {
                textBox.Value = qm.Name;
            }

            textBox = dataGridView_qm.Rows[n].Cells["Column_severity"] as DataGridViewTextBoxCell;
            if (textBox != null)
            {
                textBox.Value = qm.SeverityName;
            }

            textBox = dataGridView_qm.Rows[n].Cells["Column_content"] as DataGridViewTextBoxCell;
            if (textBox != null)
            {
                textBox.Value = qm.Content;
            }


            textBox = dataGridView_qm.Rows[n].Cells["Column_comment"] as DataGridViewTextBoxCell;
            if (textBox != null)
            {
                textBox.Value = qm.Comment;
            }



            dataGridView_qm.Rows[n].Tag = qm;

            dataGridView_qm.Sort(dataGridView_qm.Columns[2], ListSortDirection.Ascending);

            dataGridView_qm_SelectionChanged(null, null);
        }