Beispiel #1
0
 ///<summary>Inserts one QuickPasteCat into the database.  Returns the new priKey.</summary>
 public static long Insert(QuickPasteCat quickPasteCat)
 {
     if (DataConnection.DBtype == DatabaseType.Oracle)
     {
         quickPasteCat.QuickPasteCatNum = DbHelper.GetNextOracleKey("quickpastecat", "QuickPasteCatNum");
         int loopcount = 0;
         while (loopcount < 100)
         {
             try {
                 return(Insert(quickPasteCat, true));
             }
             catch (Oracle.ManagedDataAccess.Client.OracleException ex) {
                 if (ex.Number == 1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated"))
                 {
                     quickPasteCat.QuickPasteCatNum++;
                     loopcount++;
                 }
                 else
                 {
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else
     {
         return(Insert(quickPasteCat, false));
     }
 }
Beispiel #2
0
 ///<summary>Inserts one QuickPasteCat into the database.  Returns the new priKey.</summary>
 internal static long Insert(QuickPasteCat quickPasteCat)
 {
     if(DataConnection.DBtype==DatabaseType.Oracle) {
         quickPasteCat.QuickPasteCatNum=DbHelper.GetNextOracleKey("quickpastecat","QuickPasteCatNum");
         int loopcount=0;
         while(loopcount<100){
             try {
                 return Insert(quickPasteCat,true);
             }
             catch(Oracle.DataAccess.Client.OracleException ex){
                 if(ex.Number==1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated")){
                     quickPasteCat.QuickPasteCatNum++;
                     loopcount++;
                 }
                 else{
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else {
         return Insert(quickPasteCat,false);
     }
 }
        ///<summary>Inserts one QuickPasteCat into the database.  Provides option to use the existing priKey.</summary>
        public static long Insert(QuickPasteCat quickPasteCat, bool useExistingPK)
        {
            if (!useExistingPK && PrefC.RandomKeys)
            {
                quickPasteCat.QuickPasteCatNum = ReplicationServers.GetKey("quickpastecat", "QuickPasteCatNum");
            }
            string command = "INSERT INTO quickpastecat (";

            if (useExistingPK || PrefC.RandomKeys)
            {
                command += "QuickPasteCatNum,";
            }
            command += "Description,ItemOrder,DefaultForTypes) VALUES(";
            if (useExistingPK || PrefC.RandomKeys)
            {
                command += POut.Long(quickPasteCat.QuickPasteCatNum) + ",";
            }
            command +=
                "'" + POut.String(quickPasteCat.Description) + "',"
                + POut.Int(quickPasteCat.ItemOrder) + ","
                + "'" + POut.String(quickPasteCat.DefaultForTypes) + "')";
            if (useExistingPK || PrefC.RandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                quickPasteCat.QuickPasteCatNum = Db.NonQ(command, true);
            }
            return(quickPasteCat.QuickPasteCatNum);
        }
Beispiel #4
0
        ///<summary></summary>
        public static void Delete(QuickPasteCat cat)
        {
            string command = "DELETE from quickpastecat WHERE QuickPasteCatNum = '"
                             + POut.PInt(cat.QuickPasteCatNum) + "'";

            General.NonQ(command);
        }
Beispiel #5
0
 ///<summary>Inserts one QuickPasteCat into the database.  Provides option to use the existing priKey.</summary>
 internal static long Insert(QuickPasteCat quickPasteCat,bool useExistingPK)
 {
     if(!useExistingPK && PrefC.RandomKeys) {
         quickPasteCat.QuickPasteCatNum=ReplicationServers.GetKey("quickpastecat","QuickPasteCatNum");
     }
     string command="INSERT INTO quickpastecat (";
     if(useExistingPK || PrefC.RandomKeys) {
         command+="QuickPasteCatNum,";
     }
     command+="Description,ItemOrder,DefaultForTypes) VALUES(";
     if(useExistingPK || PrefC.RandomKeys) {
         command+=POut.Long(quickPasteCat.QuickPasteCatNum)+",";
     }
     command+=
          "'"+POut.String(quickPasteCat.Description)+"',"
         +    POut.Int   (quickPasteCat.ItemOrder)+","
         +"'"+POut.String(quickPasteCat.DefaultForTypes)+"')";
     if(useExistingPK || PrefC.RandomKeys) {
         Db.NonQ(command);
     }
     else {
         quickPasteCat.QuickPasteCatNum=Db.NonQ(command,true);
     }
     return quickPasteCat.QuickPasteCatNum;
 }
Beispiel #6
0
        private void butAddCat_Click(object sender, System.EventArgs e)
        {
            QuickPasteCat     quickCat = new QuickPasteCat();
            FormQuickPasteCat FormQ    = new FormQuickPasteCat(quickCat);

            FormQ.ShowDialog();
            if (FormQ.DialogResult != DialogResult.OK)
            {
                return;
            }
            quickCat = FormQ.QuickCat;
            QuickPasteCats.Insert(quickCat);
            _hasChanges = true;
            //We are doing this so tha when the sync is called in FormQuickPaste_FormClosing(...) we do not re-insert.
            //For now the sync will still detect a change due to the item orders.
            _listCatsOld.Add(quickCat.Copy());
            if (listCat.SelectedIndex != -1)
            {
                _listCats.Insert(listCat.SelectedIndex, quickCat); //insert at selectedindex AND selects new category when we refill grid below.
            }
            else                                                   //Will only happen if they do not have any categories.
            {
                _listCats.Add(quickCat);                           //add to bottom of list, will be selected when we fill grid below.
            }
            FillCats();
            FillMain();
        }
Beispiel #7
0
        ///<summary></summary>
        public static void Insert(QuickPasteCat cat)
        {
            if (PrefB.RandomKeys)
            {
                cat.QuickPasteCatNum = MiscData.GetKey("quickpastecat", "QuickPasteCatNum");
            }
            string command = "INSERT INTO quickpastecat (";

            if (PrefB.RandomKeys)
            {
                command += "QuickPasteCatNum,";
            }
            command += "Description,ItemOrder,DefaultForTypes) VALUES(";
            if (PrefB.RandomKeys)
            {
                command += "'" + POut.PInt(cat.QuickPasteCatNum) + "', ";
            }
            command +=
                "'" + POut.PString(cat.Description) + "', "
                + "'" + POut.PInt(cat.ItemOrder) + "', "
                + "'" + POut.PString(cat.DefaultForTypes) + "')";
            //MessageBox.Show(string command);
            if (PrefB.RandomKeys)
            {
                General.NonQ(command);
            }
            else
            {
                cat.QuickPasteCatNum = General.NonQ(command, true);
            }
        }
Beispiel #8
0
 ///<summary>The QuickPasteCat passed into this constructor is directly manipulated.</summary>
 public FormQuickPasteCat(QuickPasteCat quickCat)
 {
     QuickCat = quickCat.Copy();
     //
     // Required for Windows Form Designer support
     //
     InitializeComponent();
     Lan.F(this);
 }
Beispiel #9
0
        ///<summary></summary>
        public static void Update(QuickPasteCat cat)
        {
            string command = "UPDATE quickpastecat SET "
                             + "Description='" + POut.PString(cat.Description) + "'"
                             + ",ItemOrder = '" + POut.PInt(cat.ItemOrder) + "'"
                             + ",DefaultForTypes = '" + POut.PString(cat.DefaultForTypes) + "'"
                             + " WHERE QuickPasteCatNum = '" + POut.PInt(cat.QuickPasteCatNum) + "'";

            General.NonQ(command);
        }
Beispiel #10
0
        ///<summary>Updates one QuickPasteCat in the database.</summary>
        public static void Update(QuickPasteCat quickPasteCat)
        {
            string command = "UPDATE quickpastecat SET "
                             + "Description     = '" + POut.String(quickPasteCat.Description) + "', "
                             + "ItemOrder       =  " + POut.Int(quickPasteCat.ItemOrder) + ", "
                             + "DefaultForTypes = '" + POut.String(quickPasteCat.DefaultForTypes) + "' "
                             + "WHERE QuickPasteCatNum = " + POut.Long(quickPasteCat.QuickPasteCatNum);

            Db.NonQ(command);
        }
Beispiel #11
0
		///<summary>Converts a DataTable to a list of objects.</summary>
		public static List<QuickPasteCat> TableToList(DataTable table){
			List<QuickPasteCat> retVal=new List<QuickPasteCat>();
			QuickPasteCat quickPasteCat;
			for(int i=0;i<table.Rows.Count;i++) {
				quickPasteCat=new QuickPasteCat();
				quickPasteCat.QuickPasteCatNum= PIn.Long  (table.Rows[i]["QuickPasteCatNum"].ToString());
				quickPasteCat.Description     = PIn.String(table.Rows[i]["Description"].ToString());
				quickPasteCat.ItemOrder       = PIn.Int   (table.Rows[i]["ItemOrder"].ToString());
				quickPasteCat.DefaultForTypes = PIn.String(table.Rows[i]["DefaultForTypes"].ToString());
				retVal.Add(quickPasteCat);
			}
			return retVal;
		}
Beispiel #12
0
 ///<summary>Inserts one QuickPasteCat into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(QuickPasteCat quickPasteCat)
 {
     if (DataConnection.DBtype == DatabaseType.MySql)
     {
         return(InsertNoCache(quickPasteCat, false));
     }
     else
     {
         if (DataConnection.DBtype == DatabaseType.Oracle)
         {
             quickPasteCat.QuickPasteCatNum = DbHelper.GetNextOracleKey("quickpastecat", "QuickPasteCatNum");                  //Cacheless method
         }
         return(InsertNoCache(quickPasteCat, true));
     }
 }
Beispiel #13
0
 ///<summary>Returns true if Update(QuickPasteCat,QuickPasteCat) 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(QuickPasteCat quickPasteCat, QuickPasteCat oldQuickPasteCat)
 {
     if (quickPasteCat.Description != oldQuickPasteCat.Description)
     {
         return(true);
     }
     if (quickPasteCat.ItemOrder != oldQuickPasteCat.ItemOrder)
     {
         return(true);
     }
     if (quickPasteCat.DefaultForTypes != oldQuickPasteCat.DefaultForTypes)
     {
         return(true);
     }
     return(false);
 }
Beispiel #14
0
        ///<summary>Updates one QuickPasteCat in the database.</summary>
        public static void Update(QuickPasteCat quickPasteCat)
        {
            string command = "UPDATE quickpastecat SET "
                             + "Description     = '" + POut.String(quickPasteCat.Description) + "', "
                             + "ItemOrder       =  " + POut.Int(quickPasteCat.ItemOrder) + ", "
                             + "DefaultForTypes =  " + DbHelper.ParamChar + "paramDefaultForTypes "
                             + "WHERE QuickPasteCatNum = " + POut.Long(quickPasteCat.QuickPasteCatNum);

            if (quickPasteCat.DefaultForTypes == null)
            {
                quickPasteCat.DefaultForTypes = "";
            }
            OdSqlParameter paramDefaultForTypes = new OdSqlParameter("paramDefaultForTypes", OdDbType.Text, POut.StringParam(quickPasteCat.DefaultForTypes));

            Db.NonQ(command, paramDefaultForTypes);
        }
Beispiel #15
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <QuickPasteCat> TableToList(DataTable table)
        {
            List <QuickPasteCat> retVal = new List <QuickPasteCat>();
            QuickPasteCat        quickPasteCat;

            for (int i = 0; i < table.Rows.Count; i++)
            {
                quickPasteCat = new QuickPasteCat();
                quickPasteCat.QuickPasteCatNum = PIn.Long(table.Rows[i]["QuickPasteCatNum"].ToString());
                quickPasteCat.Description      = PIn.String(table.Rows[i]["Description"].ToString());
                quickPasteCat.ItemOrder        = PIn.Int(table.Rows[i]["ItemOrder"].ToString());
                quickPasteCat.DefaultForTypes  = PIn.String(table.Rows[i]["DefaultForTypes"].ToString());
                retVal.Add(quickPasteCat);
            }
            return(retVal);
        }
Beispiel #16
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <QuickPasteCat> TableToList(DataTable table)
        {
            List <QuickPasteCat> retVal = new List <QuickPasteCat>();
            QuickPasteCat        quickPasteCat;

            foreach (DataRow row in table.Rows)
            {
                quickPasteCat = new QuickPasteCat();
                quickPasteCat.QuickPasteCatNum = PIn.Long(row["QuickPasteCatNum"].ToString());
                quickPasteCat.Description      = PIn.String(row["Description"].ToString());
                quickPasteCat.ItemOrder        = PIn.Int(row["ItemOrder"].ToString());
                quickPasteCat.DefaultForTypes  = PIn.String(row["DefaultForTypes"].ToString());
                retVal.Add(quickPasteCat);
            }
            return(retVal);
        }
Beispiel #17
0
        ///<summary></summary>
        public static void Refresh()
        {
            string command =
                "SELECT * from quickpastecat "
                + "ORDER BY ItemOrder";
            DataTable table = General.GetTable(command);

            List = new QuickPasteCat[table.Rows.Count];
            for (int i = 0; i < List.Length; i++)
            {
                List[i] = new QuickPasteCat();
                List[i].QuickPasteCatNum = PIn.PInt(table.Rows[i][0].ToString());
                List[i].Description      = PIn.PString(table.Rows[i][1].ToString());
                List[i].ItemOrder        = PIn.PInt(table.Rows[i][2].ToString());
                List[i].DefaultForTypes  = PIn.PString(table.Rows[i][3].ToString());
            }
        }
Beispiel #18
0
        private void butDeleteCat_Click(object sender, System.EventArgs e)
        {
            if (listCat.SelectedIndex == -1)
            {
                MessageBox.Show(Lan.g(this, "Please select a category first."));
                return;
            }
            if (MessageBox.Show(Lan.g(this, "Are you sure you want to delete the entire category and all notes in it?"), "", MessageBoxButtons.OKCancel) != DialogResult.OK)
            {
                return;
            }
            QuickPasteCat category = _listCats[listCat.SelectedIndex];

            _listCats.Remove(category);
            _listNotes.RemoveAll(x => x.QuickPasteCatNum == category.QuickPasteCatNum);
            FillCats();
            FillMain();
        }
Beispiel #19
0
        ///<summary>Updates one QuickPasteCat 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(QuickPasteCat quickPasteCat, QuickPasteCat oldQuickPasteCat)
        {
            string command = "";

            if (quickPasteCat.Description != oldQuickPasteCat.Description)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "Description = '" + POut.String(quickPasteCat.Description) + "'";
            }
            if (quickPasteCat.ItemOrder != oldQuickPasteCat.ItemOrder)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ItemOrder = " + POut.Int(quickPasteCat.ItemOrder) + "";
            }
            if (quickPasteCat.DefaultForTypes != oldQuickPasteCat.DefaultForTypes)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "DefaultForTypes = " + DbHelper.ParamChar + "paramDefaultForTypes";
            }
            if (command == "")
            {
                return(false);
            }
            if (quickPasteCat.DefaultForTypes == null)
            {
                quickPasteCat.DefaultForTypes = "";
            }
            OdSqlParameter paramDefaultForTypes = new OdSqlParameter("paramDefaultForTypes", OdDbType.Text, POut.StringParam(quickPasteCat.DefaultForTypes));

            command = "UPDATE quickpastecat SET " + command
                      + " WHERE QuickPasteCatNum = " + POut.Long(quickPasteCat.QuickPasteCatNum);
            Db.NonQ(command, paramDefaultForTypes);
            return(true);
        }
Beispiel #20
0
        ///<summary>Inserts one QuickPasteCat into the database.  Provides option to use the existing priKey.  Doesn't use the cache.</summary>
        public static long InsertNoCache(QuickPasteCat quickPasteCat, bool useExistingPK)
        {
            bool   isRandomKeys = Prefs.GetBoolNoCache(PrefName.RandomPrimaryKeys);
            string command      = "INSERT INTO quickpastecat (";

            if (!useExistingPK && isRandomKeys)
            {
                quickPasteCat.QuickPasteCatNum = ReplicationServers.GetKeyNoCache("quickpastecat", "QuickPasteCatNum");
            }
            if (isRandomKeys || useExistingPK)
            {
                command += "QuickPasteCatNum,";
            }
            command += "Description,ItemOrder,DefaultForTypes) VALUES(";
            if (isRandomKeys || useExistingPK)
            {
                command += POut.Long(quickPasteCat.QuickPasteCatNum) + ",";
            }
            command +=
                "'" + POut.String(quickPasteCat.Description) + "',"
                + POut.Int(quickPasteCat.ItemOrder) + ","
                + DbHelper.ParamChar + "paramDefaultForTypes)";
            if (quickPasteCat.DefaultForTypes == null)
            {
                quickPasteCat.DefaultForTypes = "";
            }
            OdSqlParameter paramDefaultForTypes = new OdSqlParameter("paramDefaultForTypes", OdDbType.Text, POut.StringParam(quickPasteCat.DefaultForTypes));

            if (useExistingPK || isRandomKeys)
            {
                Db.NonQ(command, paramDefaultForTypes);
            }
            else
            {
                quickPasteCat.QuickPasteCatNum = Db.NonQ(command, true, "QuickPasteCatNum", "quickPasteCat", paramDefaultForTypes);
            }
            return(quickPasteCat.QuickPasteCatNum);
        }
Beispiel #21
0
        private void butAddCat_Click(object sender, System.EventArgs e)
        {
            QuickPasteCat quickCat = new QuickPasteCat();

            if (listCat.SelectedIndex == -1)
            {
                quickCat.ItemOrder = listCat.Items.Count;              //one more than list will hold.
            }
            else
            {
                quickCat.ItemOrder = listCat.SelectedIndex;
            }
            QuickPasteCats.Insert(quickCat);
            FormQuickPasteCat FormQ = new FormQuickPasteCat(quickCat);

            FormQ.ShowDialog();
            if (FormQ.DialogResult == DialogResult.OK)
            {
                if (listCat.SelectedIndex != -1)
                {
                    //move other items down in list to make room for new one.
                    for (int i = listCat.SelectedIndex; i < QuickPasteCats.List.Length; i++)
                    {
                        QuickPasteCats.List[i].ItemOrder++;
                        QuickPasteCats.Update(QuickPasteCats.List[i]);
                    }
                }
                localChanged = true;
            }
            else
            {
                QuickPasteCats.Delete(quickCat);
            }
            QuickPasteCats.Refresh();
            FillCats();
            FillNotes();
        }
Beispiel #22
0
        ///<summary>Updates one QuickPasteCat 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(QuickPasteCat quickPasteCat, QuickPasteCat oldQuickPasteCat)
        {
            string command = "";

            if (quickPasteCat.Description != oldQuickPasteCat.Description)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "Description = '" + POut.String(quickPasteCat.Description) + "'";
            }
            if (quickPasteCat.ItemOrder != oldQuickPasteCat.ItemOrder)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ItemOrder = " + POut.Int(quickPasteCat.ItemOrder) + "";
            }
            if (quickPasteCat.DefaultForTypes != oldQuickPasteCat.DefaultForTypes)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "DefaultForTypes = '" + POut.String(quickPasteCat.DefaultForTypes) + "'";
            }
            if (command == "")
            {
                return;
            }
            command = "UPDATE quickpastecat SET " + command
                      + " WHERE QuickPasteCatNum = " + POut.Long(quickPasteCat.QuickPasteCatNum);
            Db.NonQ(command);
        }
Beispiel #23
0
 ///<summary>Inserts one QuickPasteCat into the database.  Returns the new priKey.</summary>
 public static long Insert(QuickPasteCat quickPasteCat)
 {
     return(Insert(quickPasteCat, false));
 }
Beispiel #24
0
		///<summary>Updates one QuickPasteCat 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(QuickPasteCat quickPasteCat,QuickPasteCat oldQuickPasteCat){
			string command="";
			if(quickPasteCat.Description != oldQuickPasteCat.Description) {
				if(command!=""){ command+=",";}
				command+="Description = '"+POut.String(quickPasteCat.Description)+"'";
			}
			if(quickPasteCat.ItemOrder != oldQuickPasteCat.ItemOrder) {
				if(command!=""){ command+=",";}
				command+="ItemOrder = "+POut.Int(quickPasteCat.ItemOrder)+"";
			}
			if(quickPasteCat.DefaultForTypes != oldQuickPasteCat.DefaultForTypes) {
				if(command!=""){ command+=",";}
				command+="DefaultForTypes = '"+POut.String(quickPasteCat.DefaultForTypes)+"'";
			}
			if(command==""){
				return false;
			}
			command="UPDATE quickpastecat SET "+command
				+" WHERE QuickPasteCatNum = "+POut.Long(quickPasteCat.QuickPasteCatNum);
			Db.NonQ(command);
			return true;
		}
Beispiel #25
0
		///<summary>Updates one QuickPasteCat in the database.</summary>
		public static void Update(QuickPasteCat quickPasteCat){
			string command="UPDATE quickpastecat SET "
				+"Description     = '"+POut.String(quickPasteCat.Description)+"', "
				+"ItemOrder       =  "+POut.Int   (quickPasteCat.ItemOrder)+", "
				+"DefaultForTypes = '"+POut.String(quickPasteCat.DefaultForTypes)+"' "
				+"WHERE QuickPasteCatNum = "+POut.Long(quickPasteCat.QuickPasteCatNum);
			Db.NonQ(command);
		}