Example #1
0
        ///<summary>Inserts one DictCustom into the database.  Provides option to use the existing priKey.</summary>
        public static long Insert(DictCustom dictCustom, bool useExistingPK)
        {
            if (!useExistingPK && PrefC.RandomKeys)
            {
                dictCustom.DictCustomNum = ReplicationServers.GetKey("dictcustom", "DictCustomNum");
            }
            string command = "INSERT INTO dictcustom (";

            if (useExistingPK || PrefC.RandomKeys)
            {
                command += "DictCustomNum,";
            }
            command += "WordText) VALUES(";
            if (useExistingPK || PrefC.RandomKeys)
            {
                command += POut.Long(dictCustom.DictCustomNum) + ",";
            }
            command +=
                "'" + POut.String(dictCustom.WordText) + "')";
            if (useExistingPK || PrefC.RandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                dictCustom.DictCustomNum = Db.NonQ(command, true);
            }
            return(dictCustom.DictCustomNum);
        }
Example #2
0
        private void butAdd_Click(object sender, EventArgs e)
        {
            if (textCustom.Text == "")
            {
                MsgBox.Show(this, "Please enter a custom word first.");
                return;
            }
            string newWord = Regex.Replace(textCustom.Text, "[\\s]|[\\p{P}\\p{S}-['-]]", ""); //don't allow words with spaces or punctuation except ' and - in them

            for (int i = 0; i < DictCustoms.Listt.Count; i++)                                 //Make sure it's not already in the custom list
            {
                if (DictCustoms.Listt[i].WordText == newWord)
                {
                    MsgBox.Show(this, "The word " + newWord + " is already in the custom word list.");
                    textCustom.Clear();
                    return;
                }
            }
            DictCustom word = new DictCustom();

            word.WordText = newWord;
            DictCustoms.Insert(word);
            DataValid.SetInvalid(InvalidType.DictCustoms);
            textCustom.Clear();
            FillGrid();
        }
Example #3
0
        ///<summary>Inserts one DictCustom into the database.  Provides option to use the existing priKey.  Doesn't use the cache.</summary>
        public static long InsertNoCache(DictCustom dictCustom, bool useExistingPK)
        {
            bool   isRandomKeys = Prefs.GetBoolNoCache(PrefName.RandomPrimaryKeys);
            string command      = "INSERT INTO dictcustom (";

            if (!useExistingPK && isRandomKeys)
            {
                dictCustom.DictCustomNum = ReplicationServers.GetKeyNoCache("dictcustom", "DictCustomNum");
            }
            if (isRandomKeys || useExistingPK)
            {
                command += "DictCustomNum,";
            }
            command += "WordText) VALUES(";
            if (isRandomKeys || useExistingPK)
            {
                command += POut.Long(dictCustom.DictCustomNum) + ",";
            }
            command +=
                "'" + POut.String(dictCustom.WordText) + "')";
            if (useExistingPK || isRandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                dictCustom.DictCustomNum = Db.NonQ(command, true, "DictCustomNum", "dictCustom");
            }
            return(dictCustom.DictCustomNum);
        }
Example #4
0
 ///<summary>Inserts one DictCustom into the database.  Returns the new priKey.</summary>
 public static long Insert(DictCustom dictCustom)
 {
     if (DataConnection.DBtype == DatabaseType.Oracle)
     {
         dictCustom.DictCustomNum = DbHelper.GetNextOracleKey("dictcustom", "DictCustomNum");
         int loopcount = 0;
         while (loopcount < 100)
         {
             try {
                 return(Insert(dictCustom, true));
             }
             catch (Oracle.DataAccess.Client.OracleException ex) {
                 if (ex.Number == 1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated"))
                 {
                     dictCustom.DictCustomNum++;
                     loopcount++;
                 }
                 else
                 {
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else
     {
         return(Insert(dictCustom, false));
     }
 }
Example #5
0
        ///<summary>Updates one DictCustom in the database.</summary>
        public static void Update(DictCustom dictCustom)
        {
            string command = "UPDATE dictcustom SET "
                             + "WordText     = '" + POut.String(dictCustom.WordText) + "' "
                             + "WHERE DictCustomNum = " + POut.Long(dictCustom.DictCustomNum);

            Db.NonQ(command);
        }
Example #6
0
 ///<summary>Returns true if Update(DictCustom,DictCustom) would make changes to the database.
 ///Does not make any changes to the database and can be called before remoting role is checked.</summary>
 public static bool UpdateComparison(DictCustom dictCustom, DictCustom oldDictCustom)
 {
     if (dictCustom.WordText != oldDictCustom.WordText)
     {
         return(true);
     }
     return(false);
 }
Example #7
0
		///<summary>Converts a DataTable to a list of objects.</summary>
		public static List<DictCustom> TableToList(DataTable table){
			List<DictCustom> retVal=new List<DictCustom>();
			DictCustom dictCustom;
			for(int i=0;i<table.Rows.Count;i++) {
				dictCustom=new DictCustom();
				dictCustom.DictCustomNum= PIn.Long  (table.Rows[i]["DictCustomNum"].ToString());
				dictCustom.WordText     = PIn.String(table.Rows[i]["WordText"].ToString());
				retVal.Add(dictCustom);
			}
			return retVal;
		}
Example #8
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <DictCustom> TableToList(DataTable table)
        {
            List <DictCustom> retVal = new List <DictCustom>();
            DictCustom        dictCustom;

            for (int i = 0; i < table.Rows.Count; i++)
            {
                dictCustom = new DictCustom();
                dictCustom.DictCustomNum = PIn.Long(table.Rows[i]["DictCustomNum"].ToString());
                dictCustom.WordText      = PIn.String(table.Rows[i]["WordText"].ToString());
                retVal.Add(dictCustom);
            }
            return(retVal);
        }
Example #9
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <DictCustom> TableToList(DataTable table)
        {
            List <DictCustom> retVal = new List <DictCustom>();
            DictCustom        dictCustom;

            foreach (DataRow row in table.Rows)
            {
                dictCustom = new DictCustom();
                dictCustom.DictCustomNum = PIn.Long(row["DictCustomNum"].ToString());
                dictCustom.WordText      = PIn.String(row["WordText"].ToString());
                retVal.Add(dictCustom);
            }
            return(retVal);
        }
Example #10
0
 ///<summary>Inserts one DictCustom into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(DictCustom dictCustom)
 {
     if (DataConnection.DBtype == DatabaseType.MySql)
     {
         return(InsertNoCache(dictCustom, false));
     }
     else
     {
         if (DataConnection.DBtype == DatabaseType.Oracle)
         {
             dictCustom.DictCustomNum = DbHelper.GetNextOracleKey("dictcustom", "DictCustomNum");                  //Cacheless method
         }
         return(InsertNoCache(dictCustom, true));
     }
 }
Example #11
0
        ///<summary>Updates one DictCustom in the database.  Uses an old object to compare to, and only alters changed fields.  This prevents collisions and concurrency problems in heavily used tables.</summary>
        public static void Update(DictCustom dictCustom, DictCustom oldDictCustom)
        {
            string command = "";

            if (dictCustom.WordText != oldDictCustom.WordText)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "WordText = '" + POut.String(dictCustom.WordText) + "'";
            }
            if (command == "")
            {
                return;
            }
            command = "UPDATE dictcustom SET " + command
                      + " WHERE DictCustomNum = " + POut.Long(dictCustom.DictCustomNum);
            Db.NonQ(command);
        }
Example #12
0
		///<summary>Inserts one DictCustom into the database.  Provides option to use the existing priKey.</summary>
		public static long Insert(DictCustom dictCustom,bool useExistingPK){
			if(!useExistingPK && PrefC.RandomKeys) {
				dictCustom.DictCustomNum=ReplicationServers.GetKey("dictcustom","DictCustomNum");
			}
			string command="INSERT INTO dictcustom (";
			if(useExistingPK || PrefC.RandomKeys) {
				command+="DictCustomNum,";
			}
			command+="WordText) VALUES(";
			if(useExistingPK || PrefC.RandomKeys) {
				command+=POut.Long(dictCustom.DictCustomNum)+",";
			}
			command+=
				 "'"+POut.String(dictCustom.WordText)+"')";
			if(useExistingPK || PrefC.RandomKeys) {
				Db.NonQ(command);
			}
			else {
				dictCustom.DictCustomNum=Db.NonQ(command,true);
			}
			return dictCustom.DictCustomNum;
		}
Example #13
0
        private void gridMain_CellDoubleClick(object sender, ODGridClickEventArgs e)
        {
            InputBox   editWord = new InputBox("Edit word");
            DictCustom origWord = DictCustoms.Listt[e.Row];

            editWord.textResult.Text = origWord.WordText;
            if (editWord.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            if (editWord.textResult.Text == origWord.WordText)
            {
                return;
            }
            if (editWord.textResult.Text == "")
            {
                DictCustoms.Delete(origWord.DictCustomNum);
                DataValid.SetInvalid(InvalidType.DictCustoms);
                FillGrid();
                return;
            }
            string newWord = Regex.Replace(editWord.textResult.Text, "[\\s]|[\\p{P}\\p{S}-['-]]", ""); //don't allow words with spaces or punctuation except ' and - in them

            for (int i = 0; i < DictCustoms.Listt.Count; i++)                                          //Make sure it's not already in the custom list
            {
                if (DictCustoms.Listt[i].WordText == newWord)
                {
                    MsgBox.Show(this, "The word " + newWord + " is already in the custom word list.");
                    editWord.textResult.Text = origWord.WordText;
                    return;
                }
            }
            origWord.WordText = newWord;
            DictCustoms.Update(origWord);
            DataValid.SetInvalid(InvalidType.DictCustoms);
            FillGrid();
        }
Example #14
0
		///<summary>Inserts one DictCustom into the database.  Returns the new priKey.</summary>
		public static long Insert(DictCustom dictCustom){
			if(DataConnection.DBtype==DatabaseType.Oracle) {
				dictCustom.DictCustomNum=DbHelper.GetNextOracleKey("dictcustom","DictCustomNum");
				int loopcount=0;
				while(loopcount<100){
					try {
						return Insert(dictCustom,true);
					}
					catch(Oracle.DataAccess.Client.OracleException ex){
						if(ex.Number==1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated")){
							dictCustom.DictCustomNum++;
							loopcount++;
						}
						else{
							throw ex;
						}
					}
				}
				throw new ApplicationException("Insert failed.  Could not generate primary key.");
			}
			else {
				return Insert(dictCustom,false);
			}
		}
Example #15
0
		///<summary>Updates one DictCustom in the database.  Uses an old object to compare to, and only alters changed fields.  This prevents collisions and concurrency problems in heavily used tables.  Returns true if an update occurred.</summary>
		public static bool Update(DictCustom dictCustom,DictCustom oldDictCustom){
			string command="";
			if(dictCustom.WordText != oldDictCustom.WordText) {
				if(command!=""){ command+=",";}
				command+="WordText = '"+POut.String(dictCustom.WordText)+"'";
			}
			if(command==""){
				return false;
			}
			command="UPDATE dictcustom SET "+command
				+" WHERE DictCustomNum = "+POut.Long(dictCustom.DictCustomNum);
			Db.NonQ(command);
			return true;
		}
Example #16
0
 ///<summary>Inserts one DictCustom into the database.  Returns the new priKey.</summary>
 public static long Insert(DictCustom dictCustom)
 {
     return(Insert(dictCustom, false));
 }
Example #17
0
        private void menuItem_Click(object sender, System.EventArgs e)
        {
            if (ReadOnly && contextMenu.MenuItems.IndexOf((MenuItem)sender) != 13)
            {
                MsgBox.Show(this, "This feature is currently disabled due to this text box being read only.");
                return;
            }
            switch (contextMenu.MenuItems.IndexOf((MenuItem)sender))
            {
            case 0:
            case 1:
            case 2:
            case 3:
            case 4:
                if (!this.spellCheckIsEnabled || !PrefC.GetBool(PrefName.SpellCheckIsEnabled))                         //if spell check disabled, break.  Should never happen since the suggested words won't show if spell check disabled
                {
                    break;
                }
                int originalCaret = this.SelectionStart;
                this.Text = this.Text.Remove(ReplWord.StartIndex, ReplWord.Value.Length);
                this.Text = this.Text.Insert(ReplWord.StartIndex, contextMenu.MenuItems[contextMenu.MenuItems.IndexOf((MenuItem)sender)].Text);
                if (this.Text.Length <= originalCaret)
                {
                    this.SelectionStart = this.Text.Length;
                }
                else
                {
                    this.SelectionStart = originalCaret;
                }
                timer1.Start();
                break;

            //case 5 is separator
            case 6:                                                                            //Add to dict
                if (!this.spellCheckIsEnabled || !PrefC.GetBool(PrefName.SpellCheckIsEnabled)) //if spell check disabled, break.  Should never happen since Add to Dict won't show if spell check disabled
                {
                    break;
                }
                string newWord = ReplWord.Value;
                //guaranteed to not already exist in custom dictionary, or it wouldn't be underlined.
                DictCustom word = new DictCustom();
                word.WordText = newWord;
                DictCustoms.Insert(word);
                DataValid.SetInvalid(InvalidType.DictCustoms);
                ListIncorrect.Remove(ReplWord.Value);
                ListCorrect.Add(ReplWord.Value);
                timer1.Start();
                break;

            case 7:                    //Disable spell check
                if (!MsgBox.Show(this, MsgBoxButtons.OKCancel, "This will disable spell checking.  To re-enable, go to Setup | Spell Check and check the \"Spell Check Enabled\" box."))
                {
                    break;
                }
                Prefs.UpdateBool(PrefName.SpellCheckIsEnabled, false);
                DataValid.SetInvalid(InvalidType.Prefs);
                ClearWavyLines();
                break;

            //case 8 is separator
            case 9:
                InsertDate();
                break;

            case 10:                    //Insert Quick Note
                ShowFullDialog();
                break;

            //case 11 is separator
            case 12:                    //cut
                Clipboard.SetDataObject(SelectedText);
                int caretPos = SelectionStart;
                Text            = Text.Remove(SelectionStart, SelectionLength);
                SelectionStart  = caretPos;
                SelectionLength = 0;
                break;

            case 13:                    //copy
                Clipboard.SetDataObject(SelectedText);
                break;

            case 14:                    //paste
                if (!Clipboard.ContainsText())
                {
                    MsgBox.Show(this, "There is no text on the clipboard.");
                    break;
                }
                int         caret = SelectionStart;
                IDataObject iData = Clipboard.GetDataObject();
                if (SelectionLength > 0)
                {
                    Text            = Text.Remove(SelectionStart, SelectionLength);
                    SelectionLength = 0;
                }
                string strPaste = (string)iData.GetData(DataFormats.Text);
                Text = Text.Insert(caret, strPaste);
                //MaxLength is not enforced by the RichTextBox.  It allows us to set the Text value to a longer length, so we have to handle it manually.
                if (Text.Length > MaxLength)
                {
                    Text = Text.Substring(0, MaxLength);
                }
                SelectionStart = caret + strPaste.Length;
                break;
            }
        }
Example #18
0
		///<summary>Updates one DictCustom in the database.</summary>
		public static void Update(DictCustom dictCustom){
			string command="UPDATE dictcustom SET "
				+"WordText     = '"+POut.String(dictCustom.WordText)+"' "
				+"WHERE DictCustomNum = "+POut.Long(dictCustom.DictCustomNum);
			Db.NonQ(command);
		}