Esempio n. 1
0
        ///<summary>Inserts one AutoNote into the database.  Provides option to use the existing priKey.</summary>
        public static long Insert(AutoNote autoNote, bool useExistingPK)
        {
            if (!useExistingPK && PrefC.RandomKeys)
            {
                autoNote.AutoNoteNum = ReplicationServers.GetKey("autonote", "AutoNoteNum");
            }
            string command = "INSERT INTO autonote (";

            if (useExistingPK || PrefC.RandomKeys)
            {
                command += "AutoNoteNum,";
            }
            command += "AutoNoteName,MainText) VALUES(";
            if (useExistingPK || PrefC.RandomKeys)
            {
                command += POut.Long(autoNote.AutoNoteNum) + ",";
            }
            command +=
                "'" + POut.String(autoNote.AutoNoteName) + "',"
                + "'" + POut.String(autoNote.MainText) + "')";
            if (useExistingPK || PrefC.RandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                autoNote.AutoNoteNum = Db.NonQ(command, true);
            }
            return(autoNote.AutoNoteNum);
        }
Esempio n. 2
0
 ///<summary>Inserts one AutoNote into the database.  Returns the new priKey.</summary>
 internal static long Insert(AutoNote autoNote)
 {
     if(DataConnection.DBtype==DatabaseType.Oracle) {
         autoNote.AutoNoteNum=DbHelper.GetNextOracleKey("autonote","AutoNoteNum");
         int loopcount=0;
         while(loopcount<100){
             try {
                 return Insert(autoNote,true);
             }
             catch(Oracle.DataAccess.Client.OracleException ex){
                 if(ex.Number==1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated")){
                     autoNote.AutoNoteNum++;
                     loopcount++;
                 }
                 else{
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else {
         return Insert(autoNote,false);
     }
 }
Esempio n. 3
0
        ///<summary>Sets the AutoNoteResponseText with the selected AutoNote in the format "Auto Note Response Text : {AutoNoteName}".</summary>
        private void butOK_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textResponseText.Text))
            {
                MsgBox.Show(this, "Please enter a response text.");
                return;
            }
            if (gridMain.GetSelectedIndex() == -1)
            {
                MsgBox.Show(this, "Please select an AutoNote.");
                return;
            }
            AutoNote autoNoteSelected = gridMain.SelectedTag <AutoNote>();

            if (autoNoteSelected == null)
            {
                MsgBox.Show(this, "Invalid AutoNote selected. Please select a new one.");
                gridMain.SetSelected(false);
                return;                //This shouldn't happen.
            }
            //The AutoNoteResponseText should be in format "Auto Note Response Text : {AutoNoteName}"
            //This format is needed so the text processing logic can parse through it correctly.
            //If this format changes, we need to change the logic in FormAutoNoteCompose.PromptForAutoNotes()
            //If this format changes, you will also need to modify FormAutoNoteCompose.GetAutoNoteName() and FormAutoNoteCompose.GetAutoNoteResponseText
            AutoNoteResponseText = textResponseText.Text + " : {" + autoNoteSelected.AutoNoteName + "}";
            DialogResult         = DialogResult.OK;
        }
Esempio n. 4
0
        ///<summary>Updates one AutoNote 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(AutoNote autoNote, AutoNote oldAutoNote)
        {
            string command = "";

            if (autoNote.AutoNoteName != oldAutoNote.AutoNoteName)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "AutoNoteName = '" + POut.String(autoNote.AutoNoteName) + "'";
            }
            if (autoNote.MainText != oldAutoNote.MainText)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "MainText = '" + POut.String(autoNote.MainText) + "'";
            }
            if (command == "")
            {
                return;
            }
            command = "UPDATE autonote SET " + command
                      + " WHERE AutoNoteNum = " + POut.Long(autoNote.AutoNoteNum);
            Db.NonQ(command);
        }
Esempio n. 5
0
 ///<summary>Inserts one AutoNote into the database.  Returns the new priKey.</summary>
 public static long Insert(AutoNote autoNote)
 {
     if (DataConnection.DBtype == DatabaseType.Oracle)
     {
         autoNote.AutoNoteNum = DbHelper.GetNextOracleKey("autonote", "AutoNoteNum");
         int loopcount = 0;
         while (loopcount < 100)
         {
             try {
                 return(Insert(autoNote, true));
             }
             catch (Oracle.ManagedDataAccess.Client.OracleException ex) {
                 if (ex.Number == 1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated"))
                 {
                     autoNote.AutoNoteNum++;
                     loopcount++;
                 }
                 else
                 {
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else
     {
         return(Insert(autoNote, false));
     }
 }
Esempio n. 6
0
        private void listBoxAutoNotes_SelectedIndexChanged(object sender, EventArgs e)
        {
            for (int x = 0; x <= this.Controls.Count - 1; x++)
            {
                if (this.Controls[x].Name.ToString() != "listBoxAutoNotes" &&
                    this.Controls[x].Name.ToString() != "butOK" &&
                    this.Controls[x].Name.ToString() != "listBoxControls")
                {
                    this.Controls.RemoveAt(x);
                    x--;
                }
            }

            if (listBoxAutoNotes.SelectedIndex == -1)
            {
                return;
            }
            listBoxControls.Items.Clear();
            AutoNoteCur = AutoNotes.Listt[listBoxAutoNotes.SelectedIndex];
            string[] lines = AutoNoteCur.ControlsToInc.Split(new char[] { ',' });
            for (int i = 0; i < lines.Length; i++)
            {
                if (lines[i].ToString() != "")
                {
                    listBoxControls.Items.Add(lines[i].ToString());
                }
            }
            DrawControls();
        }
Esempio n. 7
0
        ///<summary></summary>
        public static void Insert(AutoNote autonote)
        {
            string command = "INSERT INTO autonote (AutoNoteName, ControlsToInc)"
                             + "VALUES ("
                             + "'" + POut.PString(autonote.AutoNoteName) + "',"
                             + "'" + POut.PString(autonote.ControlsToInc) + "')";

            General.NonQ(command);
        }
Esempio n. 8
0
        ///<summary></summary>
        public static void Update(AutoNote autonote)
        {
            string command = "UPDATE autonote SET "
                             + "AutoNoteName = '" + POut.PString(autonote.AutoNoteName) + "', "
                             + "ControlsToInc = '" + POut.PString(autonote.ControlsToInc) + "' "
                             + "WHERE AutoNoteNum = '" + POut.PInt(autonote.AutoNoteNum) + "'";

            General.NonQ(command);
        }
Esempio n. 9
0
        ///<summary>Updates one AutoNote in the database.</summary>
        public static void Update(AutoNote autoNote)
        {
            string command = "UPDATE autonote SET "
                             + "AutoNoteName= '" + POut.String(autoNote.AutoNoteName) + "', "
                             + "MainText    = '" + POut.String(autoNote.MainText) + "' "
                             + "WHERE AutoNoteNum = " + POut.Long(autoNote.AutoNoteNum);

            Db.NonQ(command);
        }
Esempio n. 10
0
		///<summary>Converts a DataTable to a list of objects.</summary>
		public static List<AutoNote> TableToList(DataTable table){
			List<AutoNote> retVal=new List<AutoNote>();
			AutoNote autoNote;
			for(int i=0;i<table.Rows.Count;i++) {
				autoNote=new AutoNote();
				autoNote.AutoNoteNum = PIn.Long  (table.Rows[i]["AutoNoteNum"].ToString());
				autoNote.AutoNoteName= PIn.String(table.Rows[i]["AutoNoteName"].ToString());
				autoNote.MainText    = PIn.String(table.Rows[i]["MainText"].ToString());
				retVal.Add(autoNote);
			}
			return retVal;
		}
Esempio n. 11
0
 ///<summary>Inserts one AutoNote into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(AutoNote autoNote)
 {
     if (DataConnection.DBtype == DatabaseType.MySql)
     {
         return(InsertNoCache(autoNote, false));
     }
     else
     {
         if (DataConnection.DBtype == DatabaseType.Oracle)
         {
             autoNote.AutoNoteNum = DbHelper.GetNextOracleKey("autonote", "AutoNoteNum");                  //Cacheless method
         }
         return(InsertNoCache(autoNote, true));
     }
 }
Esempio n. 12
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <AutoNote> TableToList(DataTable table)
        {
            List <AutoNote> retVal = new List <AutoNote>();
            AutoNote        autoNote;

            for (int i = 0; i < table.Rows.Count; i++)
            {
                autoNote              = new AutoNote();
                autoNote.AutoNoteNum  = PIn.Long(table.Rows[i]["AutoNoteNum"].ToString());
                autoNote.AutoNoteName = PIn.String(table.Rows[i]["AutoNoteName"].ToString());
                autoNote.MainText     = PIn.String(table.Rows[i]["MainText"].ToString());
                retVal.Add(autoNote);
            }
            return(retVal);
        }
Esempio n. 13
0
        /// <summary></summary>
        public static List <AutoNote> AutoNoteEdit(string AutoNoteName)
        {
            string command = "SELECT AutoNoteName, AutoNoteNum, ControlsToInc FROM autonote "
                             + "WHERE AutoNoteName = " + "'" + AutoNoteName + "'";
            DataTable       table = General.GetTable(command);
            List <AutoNote> Listt = new List <AutoNote>();
            //List = new AutoNote[table.Rows.Count];
            AutoNote note = new AutoNote();

            note.AutoNoteNum   = PIn.PInt(table.Rows[0]["AutoNoteNum"].ToString());
            note.AutoNoteName  = PIn.PString(table.Rows[0]["AutoNoteName"].ToString());
            note.ControlsToInc = PIn.PString(table.Rows[0]["ControlsToInc"].ToString());
            Listt.Add(note);
            return(Listt);
        }
Esempio n. 14
0
        ///<summary>Updates one AutoNote in the database.</summary>
        public static void Update(AutoNote autoNote)
        {
            string command = "UPDATE autonote SET "
                             + "AutoNoteName= '" + POut.String(autoNote.AutoNoteName) + "', "
                             + "MainText    =  " + DbHelper.ParamChar + "paramMainText, "
                             + "Category    =  " + POut.Long(autoNote.Category) + " "
                             + "WHERE AutoNoteNum = " + POut.Long(autoNote.AutoNoteNum);

            if (autoNote.MainText == null)
            {
                autoNote.MainText = "";
            }
            OdSqlParameter paramMainText = new OdSqlParameter("paramMainText", OdDbType.Text, POut.StringParam(autoNote.MainText));

            Db.NonQ(command, paramMainText);
        }
Esempio n. 15
0
 ///<summary>Returns true if Update(AutoNote,AutoNote) 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(AutoNote autoNote, AutoNote oldAutoNote)
 {
     if (autoNote.AutoNoteName != oldAutoNote.AutoNoteName)
     {
         return(true);
     }
     if (autoNote.MainText != oldAutoNote.MainText)
     {
         return(true);
     }
     if (autoNote.Category != oldAutoNote.Category)
     {
         return(true);
     }
     return(false);
 }
Esempio n. 16
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <AutoNote> TableToList(DataTable table)
        {
            List <AutoNote> retVal = new List <AutoNote>();
            AutoNote        autoNote;

            foreach (DataRow row in table.Rows)
            {
                autoNote              = new AutoNote();
                autoNote.AutoNoteNum  = PIn.Long(row["AutoNoteNum"].ToString());
                autoNote.AutoNoteName = PIn.String(row["AutoNoteName"].ToString());
                autoNote.MainText     = PIn.String(row["MainText"].ToString());
                autoNote.Category     = PIn.Long(row["Category"].ToString());
                retVal.Add(autoNote);
            }
            return(retVal);
        }
Esempio n. 17
0
        public static void Refresh()
        {
            string    command = "SELECT * FROM autonote ORDER BY AutoNoteNum";
            DataTable table   = General.GetTable(command);

            Listt = new List <AutoNote>();
            AutoNote note;

            for (int i = 0; i < table.Rows.Count; i++)
            {
                note               = new AutoNote();
                note.AutoNoteNum   = PIn.PInt(table.Rows[i][0].ToString());
                note.AutoNoteName  = PIn.PString(table.Rows[i][1].ToString());
                note.ControlsToInc = PIn.PString(table.Rows[i][2].ToString());
                Listt.Add(note);
            }
        }
Esempio n. 18
0
        ///<summary>Updates one AutoNote 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(AutoNote autoNote, AutoNote oldAutoNote)
        {
            string command = "";

            if (autoNote.AutoNoteName != oldAutoNote.AutoNoteName)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "AutoNoteName = '" + POut.String(autoNote.AutoNoteName) + "'";
            }
            if (autoNote.MainText != oldAutoNote.MainText)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "MainText = " + DbHelper.ParamChar + "paramMainText";
            }
            if (autoNote.Category != oldAutoNote.Category)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "Category = " + POut.Long(autoNote.Category) + "";
            }
            if (command == "")
            {
                return(false);
            }
            if (autoNote.MainText == null)
            {
                autoNote.MainText = "";
            }
            OdSqlParameter paramMainText = new OdSqlParameter("paramMainText", OdDbType.Text, POut.StringParam(autoNote.MainText));

            command = "UPDATE autonote SET " + command
                      + " WHERE AutoNoteNum = " + POut.Long(autoNote.AutoNoteNum);
            Db.NonQ(command, paramMainText);
            return(true);
        }
Esempio n. 19
0
        ///<summary>Inserts one AutoNote into the database.  Provides option to use the existing priKey.  Doesn't use the cache.</summary>
        public static long InsertNoCache(AutoNote autoNote, bool useExistingPK)
        {
            bool   isRandomKeys = Prefs.GetBoolNoCache(PrefName.RandomPrimaryKeys);
            string command      = "INSERT INTO autonote (";

            if (!useExistingPK && isRandomKeys)
            {
                autoNote.AutoNoteNum = ReplicationServers.GetKeyNoCache("autonote", "AutoNoteNum");
            }
            if (isRandomKeys || useExistingPK)
            {
                command += "AutoNoteNum,";
            }
            command += "AutoNoteName,MainText,Category) VALUES(";
            if (isRandomKeys || useExistingPK)
            {
                command += POut.Long(autoNote.AutoNoteNum) + ",";
            }
            command +=
                "'" + POut.String(autoNote.AutoNoteName) + "',"
                + DbHelper.ParamChar + "paramMainText,"
                + POut.Long(autoNote.Category) + ")";
            if (autoNote.MainText == null)
            {
                autoNote.MainText = "";
            }
            OdSqlParameter paramMainText = new OdSqlParameter("paramMainText", OdDbType.Text, POut.StringParam(autoNote.MainText));

            if (useExistingPK || isRandomKeys)
            {
                Db.NonQ(command, paramMainText);
            }
            else
            {
                autoNote.AutoNoteNum = Db.NonQ(command, true, "AutoNoteNum", "autoNote", paramMainText);
            }
            return(autoNote.AutoNoteNum);
        }
Esempio n. 20
0
		///<summary>Inserts one AutoNote into the database.  Provides option to use the existing priKey.</summary>
		public static long Insert(AutoNote autoNote,bool useExistingPK){
			if(!useExistingPK && PrefC.RandomKeys) {
				autoNote.AutoNoteNum=ReplicationServers.GetKey("autonote","AutoNoteNum");
			}
			string command="INSERT INTO autonote (";
			if(useExistingPK || PrefC.RandomKeys) {
				command+="AutoNoteNum,";
			}
			command+="AutoNoteName,MainText) VALUES(";
			if(useExistingPK || PrefC.RandomKeys) {
				command+=POut.Long(autoNote.AutoNoteNum)+",";
			}
			command+=
				 "'"+POut.String(autoNote.AutoNoteName)+"',"
				+"'"+POut.String(autoNote.MainText)+"')";
			if(useExistingPK || PrefC.RandomKeys) {
				Db.NonQ(command);
			}
			else {
				autoNote.AutoNoteNum=Db.NonQ(command,true);
			}
			return autoNote.AutoNoteNum;
		}
Esempio n. 21
0
        private void treeNotes_MouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            if (e.Node == null || !(e.Node.Tag is AutoNote))
            {
                return;
            }
            AutoNote noteCur = ((AutoNote)e.Node.Tag).Copy();

            if (IsSelectionMode)
            {
                AutoNoteCur  = noteCur;
                DialogResult = DialogResult.OK;
                return;
            }
            FormAutoNoteEdit FormA = new FormAutoNoteEdit();

            FormA.IsNew       = false;
            FormA.AutoNoteCur = noteCur;
            FormA.ShowDialog();
            if (FormA.DialogResult == DialogResult.OK)
            {
                AutoNoteL.FillListTree(treeNotes, _userOdCurPref);
            }
        }
Esempio n. 22
0
 ///<summary>Inserts many AutoNotes into the database.  Provides option to use the existing priKey.</summary>
 public static void InsertMany(List <AutoNote> listAutoNotes, bool useExistingPK)
 {
     if (!useExistingPK && PrefC.RandomKeys)
     {
         foreach (AutoNote autoNote in listAutoNotes)
         {
             Insert(autoNote);
         }
     }
     else
     {
         StringBuilder sbCommands = null;
         int           index      = 0;
         int           countRows  = 0;
         while (index < listAutoNotes.Count)
         {
             AutoNote      autoNote = listAutoNotes[index];
             StringBuilder sbRow    = new StringBuilder("(");
             bool          hasComma = false;
             if (sbCommands == null)
             {
                 sbCommands = new StringBuilder();
                 sbCommands.Append("INSERT INTO autonote (");
                 if (useExistingPK)
                 {
                     sbCommands.Append("AutoNoteNum,");
                 }
                 sbCommands.Append("AutoNoteName,MainText,Category) VALUES ");
                 countRows = 0;
             }
             else
             {
                 hasComma = true;
             }
             if (useExistingPK)
             {
                 sbRow.Append(POut.Long(autoNote.AutoNoteNum)); sbRow.Append(",");
             }
             sbRow.Append("'" + POut.String(autoNote.AutoNoteName) + "'"); sbRow.Append(",");
             sbRow.Append("'" + POut.String(autoNote.MainText) + "'"); sbRow.Append(",");
             sbRow.Append(POut.Long(autoNote.Category)); sbRow.Append(")");
             if (sbCommands.Length + sbRow.Length + 1 > TableBase.MaxAllowedPacketCount && countRows > 0)
             {
                 Db.NonQ(sbCommands.ToString());
                 sbCommands = null;
             }
             else
             {
                 if (hasComma)
                 {
                     sbCommands.Append(",");
                 }
                 sbCommands.Append(sbRow.ToString());
                 countRows++;
                 if (index == listAutoNotes.Count - 1)
                 {
                     Db.NonQ(sbCommands.ToString());
                 }
                 index++;
             }
         }
     }
 }
Esempio n. 23
0
		///<summary>Updates one AutoNote in the database.</summary>
		public static void Update(AutoNote autoNote){
			string command="UPDATE autonote SET "
				+"AutoNoteName= '"+POut.String(autoNote.AutoNoteName)+"', "
				+"MainText    = '"+POut.String(autoNote.MainText)+"' "
				+"WHERE AutoNoteNum = "+POut.Long(autoNote.AutoNoteNum);
			Db.NonQ(command);
		}
Esempio n. 24
0
 ///<summary>Inserts one AutoNote into the database.  Returns the new priKey.</summary>
 public static long Insert(AutoNote autoNote)
 {
     return(Insert(autoNote, false));
 }
Esempio n. 25
0
		///<summary>Updates one AutoNote 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(AutoNote autoNote,AutoNote oldAutoNote){
			string command="";
			if(autoNote.AutoNoteName != oldAutoNote.AutoNoteName) {
				if(command!=""){ command+=",";}
				command+="AutoNoteName = '"+POut.String(autoNote.AutoNoteName)+"'";
			}
			if(autoNote.MainText != oldAutoNote.MainText) {
				if(command!=""){ command+=",";}
				command+="MainText = '"+POut.String(autoNote.MainText)+"'";
			}
			if(command==""){
				return;
			}
			command="UPDATE autonote SET "+command
				+" WHERE AutoNoteNum = "+POut.Long(autoNote.AutoNoteNum);
			Db.NonQ(command);
		}