Example #1
0
        private void btnCodesAdd_Click(object sender, EventArgs e)
        {
            try
            {
                //Open new pop up for adding the data
                AddRegExpStatistics popUp = new AddRegExpStatistics("", false, "");
                if (popUp.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    var regExp      = popUp.regExp;
                    var replace     = popUp.replace;
                    var replaceText = popUp.replaceText;

                    //Insert to database
                    string       cmdText = "INSERT INTO [RegExpStatistics] ([Regexp],[IsReplace], [ReplacementText]) VALUES (?,?,?);";
                    OleDbCommand cmd     = new OleDbCommand(cmdText, _views.MainForm.adapterDocuments.Connection);
                    cmd.Parameters.Add("RegExpStatistics", OleDbType.Char).Value = regExp;
                    cmd.Parameters.Add("IsReplace", OleDbType.Boolean).Value     = replace;
                    cmd.Parameters.Add("ReplacementText", OleDbType.Char).Value  = replaceText;
                    cmd.ExecuteNonQuery();

                    string query2 = "Select @@Identity";
                    cmd.CommandText = query2;
                    var tag = (int)cmd.ExecuteScalar();


                    //Add to listbox
                    ListViewItem listItem = new ListViewItem(new[] { regExp, replace.ToString(), replaceText });
                    listItem.Tag = tag.ToString();
                    lvRegExp.Items.Add(listItem);
                }
            }
            catch { }
        }
Example #2
0
        private void btnCodesEdit_Click(object sender, EventArgs e)
        {
            try
            {
                if (lvRegExp.SelectedItems.Count > 0)
                {
                    ListViewItem selectedItem    = lvRegExp.SelectedItems[0];
                    var          id              = selectedItem.Tag.ToString();
                    var          regExpFromList  = selectedItem.SubItems[0].Text;
                    var          replaceT        = selectedItem.SubItems[1].Text;
                    var          replaceFromList = true;
                    if (replaceT == "False")
                    {
                        replaceFromList = false;
                    }
                    var replaceTextFromList = selectedItem.SubItems[2].Text;

                    //Open new pop up for adding the data
                    AddRegExpStatistics popUp = new AddRegExpStatistics(regExpFromList, replaceFromList, replaceTextFromList);
                    if (popUp.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        var regExp      = popUp.regExp;
                        var replace     = popUp.replace;
                        var replaceText = popUp.replaceText;
                        //Add to listbox

                        lvRegExp.SelectedItems[0].SubItems[0].Text = regExp;
                        lvRegExp.SelectedItems[0].SubItems[1].Text = replace.ToString();
                        lvRegExp.SelectedItems[0].SubItems[2].Text = replaceText;

                        //Update database
                        string       cmdText = "UPDATE [RegExpStatistics] SET [Regexp] = ?,[IsReplace] = ?, [ReplacementText] = ? WHERE ID = " + id + ";";
                        OleDbCommand cmd     = new OleDbCommand(cmdText, _views.MainForm.adapterDocuments.Connection);
                        cmd.Parameters.Add("Regexp", OleDbType.Char).Value          = regExp;
                        cmd.Parameters.Add("IsReplace", OleDbType.Boolean).Value    = replace;
                        cmd.Parameters.Add("ReplacementText", OleDbType.Char).Value = replaceText;
                        cmd.ExecuteNonQuery();
                    }
                }
            }
            catch { }
        }