///<summary>Inserts one QuickPasteNote into the database.  Returns the new priKey.</summary>
 public static long Insert(QuickPasteNote quickPasteNote)
 {
     if (DataConnection.DBtype == DatabaseType.Oracle)
     {
         quickPasteNote.QuickPasteNoteNum = DbHelper.GetNextOracleKey("quickpastenote", "QuickPasteNoteNum");
         int loopcount = 0;
         while (loopcount < 100)
         {
             try {
                 return(Insert(quickPasteNote, true));
             }
             catch (Oracle.ManagedDataAccess.Client.OracleException ex) {
                 if (ex.Number == 1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated"))
                 {
                     quickPasteNote.QuickPasteNoteNum++;
                     loopcount++;
                 }
                 else
                 {
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else
     {
         return(Insert(quickPasteNote, false));
     }
 }
Exemple #2
0
 ///<summary>Inserts one QuickPasteNote into the database.  Provides option to use the existing priKey.</summary>
 internal static long Insert(QuickPasteNote quickPasteNote,bool useExistingPK)
 {
     if(!useExistingPK && PrefC.RandomKeys) {
         quickPasteNote.QuickPasteNoteNum=ReplicationServers.GetKey("quickpastenote","QuickPasteNoteNum");
     }
     string command="INSERT INTO quickpastenote (";
     if(useExistingPK || PrefC.RandomKeys) {
         command+="QuickPasteNoteNum,";
     }
     command+="QuickPasteCatNum,ItemOrder,Note,Abbreviation) VALUES(";
     if(useExistingPK || PrefC.RandomKeys) {
         command+=POut.Long(quickPasteNote.QuickPasteNoteNum)+",";
     }
     command+=
              POut.Long  (quickPasteNote.QuickPasteCatNum)+","
         +    POut.Int   (quickPasteNote.ItemOrder)+","
         +"'"+POut.String(quickPasteNote.Note)+"',"
         +"'"+POut.String(quickPasteNote.Abbreviation)+"')";
     if(useExistingPK || PrefC.RandomKeys) {
         Db.NonQ(command);
     }
     else {
         quickPasteNote.QuickPasteNoteNum=Db.NonQ(command,true);
     }
     return quickPasteNote.QuickPasteNoteNum;
 }
Exemple #3
0
        ///<summary>Inserts one QuickPasteNote into the database.  Provides option to use the existing priKey.</summary>
        public static long Insert(QuickPasteNote quickPasteNote, bool useExistingPK)
        {
            if (!useExistingPK && PrefC.RandomKeys)
            {
                quickPasteNote.QuickPasteNoteNum = ReplicationServers.GetKey("quickpastenote", "QuickPasteNoteNum");
            }
            string command = "INSERT INTO quickpastenote (";

            if (useExistingPK || PrefC.RandomKeys)
            {
                command += "QuickPasteNoteNum,";
            }
            command += "QuickPasteCatNum,ItemOrder,Note,Abbreviation) VALUES(";
            if (useExistingPK || PrefC.RandomKeys)
            {
                command += POut.Long(quickPasteNote.QuickPasteNoteNum) + ",";
            }
            command +=
                POut.Long(quickPasteNote.QuickPasteCatNum) + ","
                + POut.Int(quickPasteNote.ItemOrder) + ","
                + "'" + POut.String(quickPasteNote.Note) + "',"
                + "'" + POut.String(quickPasteNote.Abbreviation) + "')";
            if (useExistingPK || PrefC.RandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                quickPasteNote.QuickPasteNoteNum = Db.NonQ(command, true);
            }
            return(quickPasteNote.QuickPasteNoteNum);
        }
Exemple #4
0
 ///<summary>Inserts one QuickPasteNote into the database.  Returns the new priKey.</summary>
 internal static long Insert(QuickPasteNote quickPasteNote)
 {
     if(DataConnection.DBtype==DatabaseType.Oracle) {
         quickPasteNote.QuickPasteNoteNum=DbHelper.GetNextOracleKey("quickpastenote","QuickPasteNoteNum");
         int loopcount=0;
         while(loopcount<100){
             try {
                 return Insert(quickPasteNote,true);
             }
             catch(Oracle.DataAccess.Client.OracleException ex){
                 if(ex.Number==1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated")){
                     quickPasteNote.QuickPasteNoteNum++;
                     loopcount++;
                 }
                 else{
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else {
         return Insert(quickPasteNote,false);
     }
 }
		///<summary></summary>
		public FormQuickPasteNoteEdit(QuickPasteNote quickNote){
			//
			// Required for Windows Form Designer support
			//
			QuickNote=quickNote;
			InitializeComponent();
			Lan.F(this);
		}
Exemple #6
0
        ///<summary>Updates one QuickPasteNote in the database.</summary>
        public static void Update(QuickPasteNote quickPasteNote)
        {
            string command = "UPDATE quickpastenote SET "
                             + "QuickPasteCatNum =  " + POut.Long(quickPasteNote.QuickPasteCatNum) + ", "
                             + "ItemOrder        =  " + POut.Int(quickPasteNote.ItemOrder) + ", "
                             + "Note             = '" + POut.String(quickPasteNote.Note) + "', "
                             + "Abbreviation     = '" + POut.String(quickPasteNote.Abbreviation) + "' "
                             + "WHERE QuickPasteNoteNum = " + POut.Long(quickPasteNote.QuickPasteNoteNum);

            Db.NonQ(command);
        }
        ///<summary>Updates one QuickPasteNote 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(QuickPasteNote quickPasteNote, QuickPasteNote oldQuickPasteNote)
        {
            string command = "";

            if (quickPasteNote.QuickPasteCatNum != oldQuickPasteNote.QuickPasteCatNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "QuickPasteCatNum = " + POut.Long(quickPasteNote.QuickPasteCatNum) + "";
            }
            if (quickPasteNote.ItemOrder != oldQuickPasteNote.ItemOrder)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ItemOrder = " + POut.Int(quickPasteNote.ItemOrder) + "";
            }
            if (quickPasteNote.Note != oldQuickPasteNote.Note)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "Note = " + DbHelper.ParamChar + "paramNote";
            }
            if (quickPasteNote.Abbreviation != oldQuickPasteNote.Abbreviation)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "Abbreviation = '" + POut.String(quickPasteNote.Abbreviation) + "'";
            }
            if (command == "")
            {
                return(false);
            }
            if (quickPasteNote.Note == null)
            {
                quickPasteNote.Note = "";
            }
            OdSqlParameter paramNote = new OdSqlParameter("paramNote", OdDbType.Text, POut.StringParam(quickPasteNote.Note));

            command = "UPDATE quickpastenote SET " + command
                      + " WHERE QuickPasteNoteNum = " + POut.Long(quickPasteNote.QuickPasteNoteNum);
            Db.NonQ(command, paramNote);
            return(true);
        }
		///<summary>Converts a DataTable to a list of objects.</summary>
		public static List<QuickPasteNote> TableToList(DataTable table){
			List<QuickPasteNote> retVal=new List<QuickPasteNote>();
			QuickPasteNote quickPasteNote;
			for(int i=0;i<table.Rows.Count;i++) {
				quickPasteNote=new QuickPasteNote();
				quickPasteNote.QuickPasteNoteNum= PIn.Long  (table.Rows[i]["QuickPasteNoteNum"].ToString());
				quickPasteNote.QuickPasteCatNum = PIn.Long  (table.Rows[i]["QuickPasteCatNum"].ToString());
				quickPasteNote.ItemOrder        = PIn.Int   (table.Rows[i]["ItemOrder"].ToString());
				quickPasteNote.Note             = PIn.String(table.Rows[i]["Note"].ToString());
				quickPasteNote.Abbreviation     = PIn.String(table.Rows[i]["Abbreviation"].ToString());
				retVal.Add(quickPasteNote);
			}
			return retVal;
		}
 ///<summary>Inserts one QuickPasteNote into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(QuickPasteNote quickPasteNote)
 {
     if (DataConnection.DBtype == DatabaseType.MySql)
     {
         return(InsertNoCache(quickPasteNote, false));
     }
     else
     {
         if (DataConnection.DBtype == DatabaseType.Oracle)
         {
             quickPasteNote.QuickPasteNoteNum = DbHelper.GetNextOracleKey("quickpastenote", "QuickPasteNoteNum");                  //Cacheless method
         }
         return(InsertNoCache(quickPasteNote, true));
     }
 }
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <QuickPasteNote> TableToList(DataTable table)
        {
            List <QuickPasteNote> retVal = new List <QuickPasteNote>();
            QuickPasteNote        quickPasteNote;

            foreach (DataRow row in table.Rows)
            {
                quickPasteNote = new QuickPasteNote();
                quickPasteNote.QuickPasteNoteNum = PIn.Long(row["QuickPasteNoteNum"].ToString());
                quickPasteNote.QuickPasteCatNum  = PIn.Long(row["QuickPasteCatNum"].ToString());
                quickPasteNote.ItemOrder         = PIn.Int(row["ItemOrder"].ToString());
                quickPasteNote.Note         = PIn.String(row["Note"].ToString());
                quickPasteNote.Abbreviation = PIn.String(row["Abbreviation"].ToString());
                retVal.Add(quickPasteNote);
            }
            return(retVal);
        }
Exemple #11
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <QuickPasteNote> TableToList(DataTable table)
        {
            List <QuickPasteNote> retVal = new List <QuickPasteNote>();
            QuickPasteNote        quickPasteNote;

            for (int i = 0; i < table.Rows.Count; i++)
            {
                quickPasteNote = new QuickPasteNote();
                quickPasteNote.QuickPasteNoteNum = PIn.Long(table.Rows[i]["QuickPasteNoteNum"].ToString());
                quickPasteNote.QuickPasteCatNum  = PIn.Long(table.Rows[i]["QuickPasteCatNum"].ToString());
                quickPasteNote.ItemOrder         = PIn.Int(table.Rows[i]["ItemOrder"].ToString());
                quickPasteNote.Note         = PIn.String(table.Rows[i]["Note"].ToString());
                quickPasteNote.Abbreviation = PIn.String(table.Rows[i]["Abbreviation"].ToString());
                retVal.Add(quickPasteNote);
            }
            return(retVal);
        }
        ///<summary>Updates one QuickPasteNote in the database.</summary>
        public static void Update(QuickPasteNote quickPasteNote)
        {
            string command = "UPDATE quickpastenote SET "
                             + "QuickPasteCatNum =  " + POut.Long(quickPasteNote.QuickPasteCatNum) + ", "
                             + "ItemOrder        =  " + POut.Int(quickPasteNote.ItemOrder) + ", "
                             + "Note             =  " + DbHelper.ParamChar + "paramNote, "
                             + "Abbreviation     = '" + POut.String(quickPasteNote.Abbreviation) + "' "
                             + "WHERE QuickPasteNoteNum = " + POut.Long(quickPasteNote.QuickPasteNoteNum);

            if (quickPasteNote.Note == null)
            {
                quickPasteNote.Note = "";
            }
            OdSqlParameter paramNote = new OdSqlParameter("paramNote", OdDbType.Text, POut.StringParam(quickPasteNote.Note));

            Db.NonQ(command, paramNote);
        }
Exemple #13
0
        ///<summary>Updates one QuickPasteNote 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(QuickPasteNote quickPasteNote, QuickPasteNote oldQuickPasteNote)
        {
            string command = "";

            if (quickPasteNote.QuickPasteCatNum != oldQuickPasteNote.QuickPasteCatNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "QuickPasteCatNum = " + POut.Long(quickPasteNote.QuickPasteCatNum) + "";
            }
            if (quickPasteNote.ItemOrder != oldQuickPasteNote.ItemOrder)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ItemOrder = " + POut.Int(quickPasteNote.ItemOrder) + "";
            }
            if (quickPasteNote.Note != oldQuickPasteNote.Note)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "Note = '" + POut.String(quickPasteNote.Note) + "'";
            }
            if (quickPasteNote.Abbreviation != oldQuickPasteNote.Abbreviation)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "Abbreviation = '" + POut.String(quickPasteNote.Abbreviation) + "'";
            }
            if (command == "")
            {
                return;
            }
            command = "UPDATE quickpastenote SET " + command
                      + " WHERE QuickPasteNoteNum = " + POut.Long(quickPasteNote.QuickPasteNoteNum);
            Db.NonQ(command);
        }
 ///<summary>Returns true if Update(QuickPasteNote,QuickPasteNote) 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(QuickPasteNote quickPasteNote, QuickPasteNote oldQuickPasteNote)
 {
     if (quickPasteNote.QuickPasteCatNum != oldQuickPasteNote.QuickPasteCatNum)
     {
         return(true);
     }
     if (quickPasteNote.ItemOrder != oldQuickPasteNote.ItemOrder)
     {
         return(true);
     }
     if (quickPasteNote.Note != oldQuickPasteNote.Note)
     {
         return(true);
     }
     if (quickPasteNote.Abbreviation != oldQuickPasteNote.Abbreviation)
     {
         return(true);
     }
     return(false);
 }
        ///<summary>Inserts one QuickPasteNote into the database.  Provides option to use the existing priKey.  Doesn't use the cache.</summary>
        public static long InsertNoCache(QuickPasteNote quickPasteNote, bool useExistingPK)
        {
            bool   isRandomKeys = Prefs.GetBoolNoCache(PrefName.RandomPrimaryKeys);
            string command      = "INSERT INTO quickpastenote (";

            if (!useExistingPK && isRandomKeys)
            {
                quickPasteNote.QuickPasteNoteNum = ReplicationServers.GetKeyNoCache("quickpastenote", "QuickPasteNoteNum");
            }
            if (isRandomKeys || useExistingPK)
            {
                command += "QuickPasteNoteNum,";
            }
            command += "QuickPasteCatNum,ItemOrder,Note,Abbreviation) VALUES(";
            if (isRandomKeys || useExistingPK)
            {
                command += POut.Long(quickPasteNote.QuickPasteNoteNum) + ",";
            }
            command +=
                POut.Long(quickPasteNote.QuickPasteCatNum) + ","
                + POut.Int(quickPasteNote.ItemOrder) + ","
                + DbHelper.ParamChar + "paramNote,"
                + "'" + POut.String(quickPasteNote.Abbreviation) + "')";
            if (quickPasteNote.Note == null)
            {
                quickPasteNote.Note = "";
            }
            OdSqlParameter paramNote = new OdSqlParameter("paramNote", OdDbType.Text, POut.StringParam(quickPasteNote.Note));

            if (useExistingPK || isRandomKeys)
            {
                Db.NonQ(command, paramNote);
            }
            else
            {
                quickPasteNote.QuickPasteNoteNum = Db.NonQ(command, true, "QuickPasteNoteNum", "quickPasteNote", paramNote);
            }
            return(quickPasteNote.QuickPasteNoteNum);
        }
		private void butAddNote_Click(object sender,System.EventArgs e) {
			if(listCat.SelectedIndex==-1){
				MessageBox.Show(Lan.g(this,"Please select a category first."));
				return;
			}
			QuickPasteNote quickNote=new QuickPasteNote();
			quickNote.QuickPasteCatNum=QuickPasteCats.List[listCat.SelectedIndex].QuickPasteCatNum;
			if(listNote.SelectedIndex==-1){
				quickNote.ItemOrder=notesForCat.Length;//one more than list will hold.
			}
			else{
				quickNote.ItemOrder=listNote.SelectedIndex;
			}
			FormQuickPasteNoteEdit FormQ=new FormQuickPasteNoteEdit(quickNote);
			FormQ.IsNew=true;
			FormQ.ShowDialog();
			if(FormQ.DialogResult==DialogResult.OK){
				if(listNote.SelectedIndex!=-1){
					//move other items down in list to make room for new one.
					for(int i=quickNote.ItemOrder;i<notesForCat.Length;i++){
						notesForCat[i].ItemOrder++;
						QuickPasteNotes.Update(notesForCat[i]);
					}
				}
				localChanged=true;
			}
			QuickPasteNotes.RefreshCache();
			FillNotes();
		}
Exemple #17
0
		///<summary></summary>
		public static void Refresh(){
			string command=
				"SELECT * from quickpastenote "
				+"ORDER BY ItemOrder";
 			DataTable table=General.GetTable(command);
			List=new QuickPasteNote[table.Rows.Count];
			for(int i=0;i<List.Length;i++){
				List[i]=new QuickPasteNote();
				List[i].QuickPasteNoteNum= PIn.PInt   (table.Rows[i][0].ToString());
				List[i].QuickPasteCatNum = PIn.PInt   (table.Rows[i][1].ToString());
				List[i].ItemOrder        = PIn.PInt   (table.Rows[i][2].ToString());	
				List[i].Note             = PIn.PString(table.Rows[i][3].ToString());
				List[i].Abbreviation     = PIn.PString(table.Rows[i][4].ToString());
			}
		}
Exemple #18
0
		///<summary>Only used from FormQuickPaste to get all notes for the selected cat.</summary>
		public static QuickPasteNote[] GetForCat(int cat){
			ArrayList ALnotes=new ArrayList();
			for(int i=0;i<List.Length;i++){
				if(List[i].QuickPasteCatNum==cat){
					ALnotes.Add(List[i]);
				}
			}
			QuickPasteNote[] retArray=new QuickPasteNote[ALnotes.Count];
			for(int i=0;i<ALnotes.Count;i++){
				retArray[i]=(QuickPasteNote)ALnotes[i];
			}
			return retArray;
		}
Exemple #19
0
 ///<summary>Inserts one QuickPasteNote into the database.  Returns the new priKey.</summary>
 public static long Insert(QuickPasteNote quickPasteNote)
 {
     return(Insert(quickPasteNote, false));
 }
Exemple #20
0
 ///<summary>Updates one QuickPasteNote in the database.</summary>
 internal static void Update(QuickPasteNote quickPasteNote)
 {
     string command="UPDATE quickpastenote SET "
         +"QuickPasteCatNum =  "+POut.Long  (quickPasteNote.QuickPasteCatNum)+", "
         +"ItemOrder        =  "+POut.Int   (quickPasteNote.ItemOrder)+", "
         +"Note             = '"+POut.String(quickPasteNote.Note)+"', "
         +"Abbreviation     = '"+POut.String(quickPasteNote.Abbreviation)+"' "
         +"WHERE QuickPasteNoteNum = "+POut.Long(quickPasteNote.QuickPasteNoteNum);
     Db.NonQ(command);
 }
Exemple #21
0
 ///<summary>Updates one QuickPasteNote 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>
 internal static void Update(QuickPasteNote quickPasteNote,QuickPasteNote oldQuickPasteNote)
 {
     string command="";
     if(quickPasteNote.QuickPasteCatNum != oldQuickPasteNote.QuickPasteCatNum) {
         if(command!=""){ command+=",";}
         command+="QuickPasteCatNum = "+POut.Long(quickPasteNote.QuickPasteCatNum)+"";
     }
     if(quickPasteNote.ItemOrder != oldQuickPasteNote.ItemOrder) {
         if(command!=""){ command+=",";}
         command+="ItemOrder = "+POut.Int(quickPasteNote.ItemOrder)+"";
     }
     if(quickPasteNote.Note != oldQuickPasteNote.Note) {
         if(command!=""){ command+=",";}
         command+="Note = '"+POut.String(quickPasteNote.Note)+"'";
     }
     if(quickPasteNote.Abbreviation != oldQuickPasteNote.Abbreviation) {
         if(command!=""){ command+=",";}
         command+="Abbreviation = '"+POut.String(quickPasteNote.Abbreviation)+"'";
     }
     if(command==""){
         return;
     }
     command="UPDATE quickpastenote SET "+command
         +" WHERE QuickPasteNoteNum = "+POut.Long(quickPasteNote.QuickPasteNoteNum);
     Db.NonQ(command);
 }