public void Update(string Description,int OwnerID,int PreviousSectionID) { Functions F = new Functions(); bool KeepUser = true; int[] UO = F.GetUnassignedObjects(); //Check to see if this is NoBody User if(mvarOwnerID == UO[0]) { OCL.Section PrevSect = F.GetSection(PreviousSectionID); foreach(OCL.User U in PrevSect.CurrentUsers) { if(U.ID == mvarOwnerID) { if(U.NextOwnedSections.Count == 1) { KeepUser = false; //The Nobody User only has this one //section attached to this branch it //is ok to remove him after reassign } } } } string sSQL = "UPDATE tblSection SET Name = '" + Description + "' , OwnerID = " + OwnerID + " WHERE ID = " + mvarID; int results = F.ExecuteSqlCommand(sSQL); int OldOwner = mvarOwnerID; if(OwnerID != mvarOwnerID) { try { sSQL = "SELECT * FROM tblUserSectionRel WHERE UserId = " + OwnerID + " AND " + "SectionId = " + PreviousSectionID; // "SectionId = " + mvarID; DataSet DS = F.ReturnDataSet(sSQL); DataTable DT = DS.Tables[0]; if(DT.Rows.Count == 0) { F.AddUser(OwnerID,PreviousSectionID); } if(!KeepUser) F.RemoveUser(OldOwner,PreviousSectionID); mvarOwnerID = OwnerID; } catch(Exception Err) { throw new ApplicationException(Err.Message,Err.InnerException); } } }