C#
===
using
System;using
System.Collections;using
System.Data.SqlClient;using
System.Data;namespace
CustomUserDic{
/// <summary>/// Extends and customises UserDictionary functionality./// This is a simple example class, to demonstrate the principle, your own implementation/// should handle your connections, db setup and exceptions as per the rest of your/// application./// </summary>public class DBUserDictionary : Keyoti.RapidSpell.UserDictionary{
ArrayList wordList;int wordLimit;String dictionaryId;public DBUserDictionary(String dictionaryId, int maxNumWords){
wordList =
new ArrayList(50);wordLimit = maxNumWords;
this.dictionaryId = dictionaryId;//Commented out to simplify and test;//The purpose of this is to read all user words stored in the DB into the list//SqlConnection conn = new SqlConnection("Persist Security Info=False;Integrated Security=SSPI;database=pb_mcsis;server=localhost;Connect Timeout=30");//SqlCommand command = new SqlCommand("select * From DictionaryUser", conn);//conn.Open();//SqlDataReader dr = command.ExecuteReader(CommandBehavior.SingleResult);//while(dr.Read())// wordList.Add(dr[0]);//conn.Close();wordList.Add(
"ProgressBook");wordList.Add(
"Paul");wordList.Add(
"Dale");wordList.Add(
"WordsBySA");}
public DBUserDictionary(String dictionaryId) : this(dictionaryId, 100000) { }
public override int ReadAll(ArrayList a){
//used by RapidSpell to read the words from the DB.a.Clear();
a.AddRange(wordList);
return a.Count;}
public override bool IsValid(){
//return true if the word list exists and is valid.//this should return false, if for example there was an sql exception at some point.//return wordList != null;//Defaulted to True for test.return true;}
public override bool ReloadDictionary(){
//doing anything necessary herereturn true;}
public override bool AddWord(String word){
wordList.Add(word);
OnListChanged(
new ListChangedEventArgs(ListChangedEventArgs.ListChangeOperation.WordAdd, word)); //The purpose of this is to store the word (in "word") in the database.// SqlConnection conn = new SqlConnection("server=(local)\\NetSDK;database=....;Trusted_Connection=yes");// SqlCommand command = new SqlCommand("INSERT INTO .............", conn);// conn.Open();// command.ExecuteNonQuery();// conn.Close();return true;}
public override bool RemoveWord(string word){
wordList.Remove(word);
OnListChanged(
new ListChangedEventArgs(ListChangedEventArgs.ListChangeOperation.WordRemove, word)); return base.RemoveWord(word);}
}
}
VB.NET
=======
Imports System
Imports System.Collections
Imports System.Data.SqlClient
Imports System.Data
Namespace Custom
UserDic
_
'/
'/ Extends and customises UserDictionary functionality.
'/ This is a simple example class, to demonstrate the principle, your own implementation
'/ should handle your connections, db setup and exceptions as per the rest of your
'/ application.
'/ Public Class DB
UserDictionary
Inherits Keyoti.RapidSpell.
UserDictionary
Private wordList As ArrayList
Private wordLimit As Integer
Private dictionaryId As [String]
Public Sub New(dictionaryId As [String], maxNumWords As Integer)
wordList = New ArrayList(50)
wordLimit = maxNumWords
Me.dictionaryId = dictionaryId
'Commented out to simplify and test;
'The purpose of this is to read all
user words stored in the DB into the list
Dim conn As New SqlConnection("Persist Security Info=False;Integrated Security=SSPI;
database=pb_mcsis;server=localhost;Connect Timeout=30")
Dim command As New SqlCommand("select * From Dictionary
User", conn)
conn.Open()
Dim dr As SqlDataReader = command.ExecuteReader(CommandBehavior.SingleResult)
While dr.Read()
wordList.Add(dr(0))
End While
conn.Close()
End Sub 'New
Public Overrides Function ReloadDictionary() As Boolean'doing anything necessary here
Return True
Public Sub New(dictionaryId As [String])
MyClass.New(dictionaryId, 100000)
End Sub 'New
Public Overrides Function ReadAll(a As ArrayList) As Integer
'used by RapidSpell to read the words from the DB.
a.Clear()
a.AddRange(wordList)
Return a.Count
End Function 'ReadAll
Public Overrides Function IsValid() As Boolean
'return true if the word list exists and is valid.
'this should return false, if for example there was an sql exception at some point.
'return wordList != null;
'Defaulted to True for test.
Return True
End Function 'IsValid
Public Overrides Function AddWord(w As [String]) As Boolean
wordList.Add(w)
'The purpose of this is to store the word (in "w") in the
database.
Dim conn As New SqlConnection("server=(local)\NetSDK;
database=....;Trusted_Connection=yes")
Dim command As New SqlCommand("INSERT INTO .............", conn)
conn.Open()
command.ExecuteNonQuery()
conn.Close()
Return True
End Function 'AddWord