public bool RemoveMasterFully(string id) { if (Universal.instance.firstMst != null && isNumber(id)) // Checking whether we have student or not { if (Universal.instance.firstMst != Universal.instance.lastMst) //Checking if we have more than one student { if (Convert.ToUInt64(id) == Universal.instance.firstMst.info.id) //Means that we wanna delete the first Student { RowNode <Master> newfirstRowNode = new RowNode <Master>(); newfirstRowNode.info = Universal.instance.firstMst.next.info; newfirstRowNode.next = Universal.instance.firstMst.next.next; newfirstRowNode.nextRow = Universal.instance.firstMst.nextRow; Universal.instance.firstMst = newfirstRowNode; return(true); } else if (Convert.ToUInt64(id) == Universal.instance.lastMst.info.id)//Means that we wanna delete the last Student { RowNode <Master> newlasttRowNode = new RowNode <Master>(); if (Universal.instance.lastMst.next != null) // Checking if we have convertable node to RowNode { newlasttRowNode.info = Universal.instance.lastMst.next.info; newlasttRowNode.next = Universal.instance.lastMst.next.next; Universal.instance.lastMst = newlasttRowNode; return(true); } else // Here we don't have convertable node to RowNode { RowNode <Master> lastMst = Universal.instance.lastMst; while (lastMst.nextRow != null) { lastMst = lastMst.nextRow; } Universal.instance.lastMst = lastMst; return(true); } } else // Here we want to delete the students in which there are at the Middle Nodes { RowNode <Master> prev = new RowNode <Master>(); prev = SearchPrevMaster(id); if (prev != null) //if the student exists { if (prev.nextRow != null) //Prev is RowNode { if (prev.nextRow.info.id == Convert.ToUInt64(id)) //Deleting node is nextRowNode { if (prev.nextRow.next != null) //if the deleting RowNode has nextNode { prev.nextRow.info = prev.nextRow.next.info; prev.nextRow.next = prev.nextRow.next.next; } else //deleting RowNode doesn't have nextNode { prev.nextRow = prev.nextRow.nextRow; } } else // Deleting node is nextNode { prev.next = prev.next.next; } } else //Prev is not RowNode = Usual Node { prev.next = prev.next.next; } } else // Student doesn't exist { return(false); } return(false); } } else // We have just one student { Universal.instance.firstMst = null; Universal.instance.lastMst = null; return(true); } } else { //Showing Errore that the insterted id is wrong return(false); } //End of Method }
public static RowNode <Manager> SearchPrevManager(string id) { /** * Returning the previous Student of that id **/ if (isNumber(id)) { if (Universal.instance.firstMng.info.id > Convert.ToUInt64(id) || Universal.instance.firstMng.info.id + 9 < Convert.ToUInt64(id)) { //Showing Error return(null); } else { ulong subId = Convert.ToUInt64(id.Substring(0, 10)); RowNode <Manager> pstd = Universal.instance.firstMng; if (pstd != null) { RowNode <Manager> mng = pstd; while (subId > pstd.info.id / 10) { if (Convert.ToUInt64(id) == mng.nextRow.info.id) { return(mng); } pstd = pstd.nextRow; } if (subId < pstd.info.id / 10) { //Showing Error return(null); } else { //Horizontal navigation while (mng.next != null) { if (Convert.ToUInt64(id) == mng.next.info.id) { return(mng); } mng = mng.next as RowNode <Manager>; } //Showing Error return(null); } } else { //Showing Error return(null); } } } else { return(null); } }