Пример #1
0
 ///<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));
     }
 }
Пример #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;
 }
Пример #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);
        }
Пример #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);
		}
Пример #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);
        }
Пример #7
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.  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;
		}
Пример #9
0
 ///<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));
     }
 }
Пример #10
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;

            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);
        }
Пример #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);
        }
Пример #12
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             =  " + 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);
        }
Пример #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);
        }
Пример #14
0
 ///<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);
 }
Пример #15
0
        ///<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);
        }
Пример #16
0
		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();
		}
Пример #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());
			}
		}
Пример #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;
		}
Пример #19
0
 ///<summary>Inserts one QuickPasteNote into the database.  Returns the new priKey.</summary>
 public static long Insert(QuickPasteNote quickPasteNote)
 {
     return(Insert(quickPasteNote, false));
 }
Пример #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);
 }
Пример #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);
 }