示例#1
0
 ///<summary>Inserts one TaskAncestor into the database.  Returns the new priKey.</summary>
 internal static long Insert(TaskAncestor taskAncestor)
 {
     if(DataConnection.DBtype==DatabaseType.Oracle) {
         taskAncestor.TaskAncestorNum=DbHelper.GetNextOracleKey("taskancestor","TaskAncestorNum");
         int loopcount=0;
         while(loopcount<100){
             try {
                 return Insert(taskAncestor,true);
             }
             catch(Oracle.DataAccess.Client.OracleException ex){
                 if(ex.Number==1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated")){
                     taskAncestor.TaskAncestorNum++;
                     loopcount++;
                 }
                 else{
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else {
         return Insert(taskAncestor,false);
     }
 }
        ///<summary>Updates one TaskAncestor in the database.</summary>
        public static void Update(TaskAncestor taskAncestor)
        {
            string command = "UPDATE taskancestor SET "
                             + "TaskNum        =  " + POut.Long(taskAncestor.TaskNum) + ", "
                             + "TaskListNum    =  " + POut.Long(taskAncestor.TaskListNum) + " "
                             + "WHERE TaskAncestorNum = " + POut.Long(taskAncestor.TaskAncestorNum);

            Db.NonQ(command);
        }
 ///<summary>Returns true if Update(TaskAncestor,TaskAncestor) 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(TaskAncestor taskAncestor, TaskAncestor oldTaskAncestor)
 {
     if (taskAncestor.TaskNum != oldTaskAncestor.TaskNum)
     {
         return(true);
     }
     if (taskAncestor.TaskListNum != oldTaskAncestor.TaskListNum)
     {
         return(true);
     }
     return(false);
 }
		///<summary>Converts a DataTable to a list of objects.</summary>
		public static List<TaskAncestor> TableToList(DataTable table){
			List<TaskAncestor> retVal=new List<TaskAncestor>();
			TaskAncestor taskAncestor;
			for(int i=0;i<table.Rows.Count;i++) {
				taskAncestor=new TaskAncestor();
				taskAncestor.TaskAncestorNum= PIn.Long  (table.Rows[i]["TaskAncestorNum"].ToString());
				taskAncestor.TaskNum        = PIn.Long  (table.Rows[i]["TaskNum"].ToString());
				taskAncestor.TaskListNum    = PIn.Long  (table.Rows[i]["TaskListNum"].ToString());
				retVal.Add(taskAncestor);
			}
			return retVal;
		}
示例#5
0
 ///<summary>Inserts many TaskAncestors into the database.  Provides option to use the existing priKey.</summary>
 public static void InsertMany(List <TaskAncestor> listTaskAncestors)
 {
     if (DataConnection.DBtype == DatabaseType.Oracle || PrefC.RandomKeys)
     {
         foreach (TaskAncestor taskAncestor in listTaskAncestors)
         {
             Insert(taskAncestor);
         }
     }
     else
     {
         StringBuilder sbCommands = null;
         int           index      = 0;
         while (index < listTaskAncestors.Count)
         {
             TaskAncestor  taskAncestor = listTaskAncestors[index];
             StringBuilder sbRow        = new StringBuilder("(");
             bool          hasComma     = false;
             if (sbCommands == null)
             {
                 sbCommands = new StringBuilder();
                 sbCommands.Append("INSERT INTO taskancestor (");
                 sbCommands.Append("TaskNum,TaskListNum) VALUES ");
             }
             else
             {
                 hasComma = true;
             }
             sbRow.Append(POut.Long(taskAncestor.TaskNum)); sbRow.Append(",");
             sbRow.Append(POut.Long(taskAncestor.TaskListNum)); sbRow.Append(")");
             if (sbCommands.Length + sbRow.Length + 1 > TableBase.MaxAllowedPacketCount)
             {
                 Db.NonQ(sbCommands.ToString());
                 sbCommands = null;
             }
             else
             {
                 if (hasComma)
                 {
                     sbCommands.Append(",");
                 }
                 sbCommands.Append(sbRow.ToString());
                 if (index == listTaskAncestors.Count - 1)
                 {
                     Db.NonQ(sbCommands.ToString());
                 }
                 index++;
             }
         }
     }
 }
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <TaskAncestor> TableToList(DataTable table)
        {
            List <TaskAncestor> retVal = new List <TaskAncestor>();
            TaskAncestor        taskAncestor;

            foreach (DataRow row in table.Rows)
            {
                taskAncestor = new TaskAncestor();
                taskAncestor.TaskAncestorNum = PIn.Long(row["TaskAncestorNum"].ToString());
                taskAncestor.TaskNum         = PIn.Long(row["TaskNum"].ToString());
                taskAncestor.TaskListNum     = PIn.Long(row["TaskListNum"].ToString());
                retVal.Add(taskAncestor);
            }
            return(retVal);
        }
示例#7
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        internal static List <TaskAncestor> TableToList(DataTable table)
        {
            List <TaskAncestor> retVal = new List <TaskAncestor>();
            TaskAncestor        taskAncestor;

            for (int i = 0; i < table.Rows.Count; i++)
            {
                taskAncestor = new TaskAncestor();
                taskAncestor.TaskAncestorNum = PIn.Long(table.Rows[i]["TaskAncestorNum"].ToString());
                taskAncestor.TaskNum         = PIn.Long(table.Rows[i]["TaskNum"].ToString());
                taskAncestor.TaskListNum     = PIn.Long(table.Rows[i]["TaskListNum"].ToString());
                retVal.Add(taskAncestor);
            }
            return(retVal);
        }
示例#8
0
 ///<summary>Inserts one TaskAncestor into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(TaskAncestor taskAncestor)
 {
     if (DataConnection.DBtype == DatabaseType.MySql)
     {
         return(InsertNoCache(taskAncestor, false));
     }
     else
     {
         if (DataConnection.DBtype == DatabaseType.Oracle)
         {
             taskAncestor.TaskAncestorNum = DbHelper.GetNextOracleKey("taskancestor", "TaskAncestorNum");                  //Cacheless method
         }
         return(InsertNoCache(taskAncestor, true));
     }
 }
		///<summary>Inserts one TaskAncestor into the database.  Provides option to use the existing priKey.</summary>
		public static long Insert(TaskAncestor taskAncestor,bool useExistingPK){
			if(!useExistingPK && PrefC.RandomKeys) {
				taskAncestor.TaskAncestorNum=ReplicationServers.GetKey("taskancestor","TaskAncestorNum");
			}
			string command="INSERT INTO taskancestor (";
			if(useExistingPK || PrefC.RandomKeys) {
				command+="TaskAncestorNum,";
			}
			command+="TaskNum,TaskListNum) VALUES(";
			if(useExistingPK || PrefC.RandomKeys) {
				command+=POut.Long(taskAncestor.TaskAncestorNum)+",";
			}
			command+=
				     POut.Long  (taskAncestor.TaskNum)+","
				+    POut.Long  (taskAncestor.TaskListNum)+")";
			if(useExistingPK || PrefC.RandomKeys) {
				Db.NonQ(command);
			}
			else {
				taskAncestor.TaskAncestorNum=Db.NonQ(command,true);
			}
			return taskAncestor.TaskAncestorNum;
		}
示例#10
0
 ///<summary>Inserts one TaskAncestor into the database.  Returns the new priKey.</summary>
 public static long Insert(TaskAncestor taskAncestor)
 {
     return(Insert(taskAncestor, false));
 }
示例#11
0
 ///<summary>Inserts many TaskAncestors into the database.  Provides option to use the existing priKey.</summary>
 public static void InsertMany(List <TaskAncestor> listTaskAncestors, bool useExistingPK)
 {
     if (!useExistingPK && PrefC.RandomKeys)
     {
         foreach (TaskAncestor taskAncestor in listTaskAncestors)
         {
             Insert(taskAncestor);
         }
     }
     else
     {
         StringBuilder sbCommands = null;
         int           index      = 0;
         int           countRows  = 0;
         while (index < listTaskAncestors.Count)
         {
             TaskAncestor  taskAncestor = listTaskAncestors[index];
             StringBuilder sbRow        = new StringBuilder("(");
             bool          hasComma     = false;
             if (sbCommands == null)
             {
                 sbCommands = new StringBuilder();
                 sbCommands.Append("INSERT INTO taskancestor (");
                 if (useExistingPK)
                 {
                     sbCommands.Append("TaskAncestorNum,");
                 }
                 sbCommands.Append("TaskNum,TaskListNum) VALUES ");
                 countRows = 0;
             }
             else
             {
                 hasComma = true;
             }
             if (useExistingPK)
             {
                 sbRow.Append(POut.Long(taskAncestor.TaskAncestorNum)); sbRow.Append(",");
             }
             sbRow.Append(POut.Long(taskAncestor.TaskNum)); sbRow.Append(",");
             sbRow.Append(POut.Long(taskAncestor.TaskListNum)); 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 == listTaskAncestors.Count - 1)
                 {
                     Db.NonQ(sbCommands.ToString());
                 }
                 index++;
             }
         }
     }
 }
		///<summary>Updates one TaskAncestor 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(TaskAncestor taskAncestor,TaskAncestor oldTaskAncestor){
			string command="";
			if(taskAncestor.TaskNum != oldTaskAncestor.TaskNum) {
				if(command!=""){ command+=",";}
				command+="TaskNum = "+POut.Long(taskAncestor.TaskNum)+"";
			}
			if(taskAncestor.TaskListNum != oldTaskAncestor.TaskListNum) {
				if(command!=""){ command+=",";}
				command+="TaskListNum = "+POut.Long(taskAncestor.TaskListNum)+"";
			}
			if(command==""){
				return;
			}
			command="UPDATE taskancestor SET "+command
				+" WHERE TaskAncestorNum = "+POut.Long(taskAncestor.TaskAncestorNum);
			Db.NonQ(command);
		}
		///<summary>Updates one TaskAncestor in the database.</summary>
		public static void Update(TaskAncestor taskAncestor){
			string command="UPDATE taskancestor SET "
				+"TaskNum        =  "+POut.Long  (taskAncestor.TaskNum)+", "
				+"TaskListNum    =  "+POut.Long  (taskAncestor.TaskListNum)+" "
				+"WHERE TaskAncestorNum = "+POut.Long(taskAncestor.TaskAncestorNum);
			Db.NonQ(command);
		}