Ejemplo n.º 1
0
        private void btnEditTerm_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(txtName.Text) && DialogResult.Cancel == MessageBox.Show(
                    $"The current term ({txtName.Text}) has not been added to the list!\r\n" +
                    "Click Cancel if you want a chance to add the term first.\r\n" +
                    "Press Ok to overwrite the current term with selected one from the term list.",
                    $"Unsaved changes to {txtName.Text}",
                    MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2))
            {
                return;
            }

            var row = dgvTerms.SelectedRows.Cast <DataGridViewRow>().FirstOrDefault();

            if (row == null)
            {
                return;
            }

            rdoCharacter.Checked = ImageUtil.AreEqual((Bitmap)row.Cells[0].Value, Resources.character);
            rdoTopic.Checked     = ImageUtil.AreEqual((Bitmap)row.Cells[0].Value, Resources.setting);
            txtName.Text         = row.Cells[1].Value?.ToString() ?? "";
            txtAliases.Text      = row.Cells[2].Value?.ToString() ?? "";
            txtDescription.Text  = row.Cells[3].Value?.ToString() ?? "";
            txtLink.Text         = row.Cells[4].Value?.ToString() ?? "";
            rdoGoodreads.Checked = row.Cells[5].Value?.ToString() == "Goodreads";
            rdoWikipedia.Checked = row.Cells[5].Value?.ToString() == "Wikipedia";
            chkMatch.Checked     = (bool?)row.Cells[6].Value ?? false;
            chkCase.Checked      = (bool?)row.Cells[7].Value ?? false;
            //chkDelete.Checked = (bool)row.Cells[8].Value;
            chkRegex.Checked = (bool?)row.Cells[9].Value ?? false;
            dgvTerms.Rows.Remove(row);
        }
Ejemplo n.º 2
0
        private IEnumerable <Term> GetTermsFromGrid()
        {
            var termId = 1;

            foreach (DataGridViewRow row in dgvTerms.Rows)
            {
                yield return(new Term
                {
                    Id = termId++,
                    Type = ImageUtil.AreEqual((Bitmap)row.Cells[0].Value, Resources.character)
                        ? "character"
                        : "topic",
                    TermName = row.Cells[1].Value?.ToString() ?? "",
                    Aliases = !string.IsNullOrEmpty(row.Cells[2].Value?.ToString())
                        ? row.Cells[2].Value.ToString().Split(',').Distinct().ToList()
                        : new List <string>(),
                    Desc = row.Cells[3].Value?.ToString() ?? "",
                    DescUrl = row.Cells[4].Value?.ToString() ?? "",
                    DescSrc = row.Cells[5].Value?.ToString() ?? "",
                    Match = (bool?)row.Cells[6].Value ?? false,
                    MatchCase = (bool?)row.Cells[7].Value ?? false,
                    RegexAliases = (bool?)row.Cells[9].Value ?? false
                });
            }
        }