Advertisement
Guest User

task3

a guest
Jul 23rd, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 36.87 KB | None | 0 0
  1. using System.Data;
  2. using Oracle.DataAccess.Client;
  3.  
  4.  
  5. namespace FYPMSWebsite.App_Code
  6. {
  7. /// <summary>
  8. /// Student name:
  9. /// Student number:
  10. ///
  11. /// NOTE: This is an individual task. By submitting this file you certify that this
  12. /// code is the result of YOUR INDIVIDUAL EFFORT and that it has not been developed
  13. /// in collaoration with or copied from any other person. If this is not the case,
  14. /// then you must identify by name all the persons with whom you collaborated or
  15. /// from whom you copied code below.
  16. ///
  17. /// Collaborators:
  18. /// </summary>
  19.  
  20. public class FYPMSDB
  21. {
  22. //******************************** IMPORTANT NOTE **********************************
  23. // For the web pages to display a query result correctly, the attribute names in *
  24. // the query result table must be EXACTLY the same as that in the database tables. *
  25. // Report problems with the website code to 3311rep@cse.ust.hk. *
  26. //**********************************************************************************
  27.  
  28. OracleDBAccess myOracleDBAccess = new OracleDBAccess();
  29. private string sql;
  30.  
  31. public DataTable GetProjectsWithoutReaders()
  32. {
  33. //*********************************************************************************
  34. // TODO 01: Used in Coordinator/AssignReader.aspx.cs *
  35. // Construct the SQL SELECT statement to retrieve the group id, group code, *
  36. // assigned fypid and project title, category and type for the project groups *
  37. // that DO NOT have an assigned reader. Order the result by group code ascending. *
  38. //*********************************************************************************
  39. sql = "select groupid, groupcode ,fypAssigned, title , fypCategory , fypType from ProjectGroup P, FYProject F where F.fypId = P.fypAssigned and reader is null order by groupcode asc";
  40. return myOracleDBAccess.GetData(sql);
  41. }
  42.  
  43. public decimal NumberProjectsAssignedToReader(string username)
  44. {
  45. //******************************************************************************
  46. // TODO 02: Used in Coordinator/AssignReader.aspx.cs *
  47. // Construct the SQL SELECT statement to retrieve the number of project groups *
  48. // to which a faculty, identified by his/her username, is assigned as reader. *
  49. //******************************************************************************
  50. sql = "select count(*) from ProjectGroup P where P.reader ='"+username+"'";
  51. return myOracleDBAccess.GetAggregateValue(sql);
  52. }
  53.  
  54. public bool AssignReaderToProject(string groupId, string username)
  55. {
  56. //**********************************************************************
  57. // TODO 03: Used in AssignReader.aspx.cs *
  58. // Construct the SQL UPDATE statement to assign a reader, identified *
  59. // by his/her username, to a project group, identified by its groupId. *
  60. //**********************************************************************
  61. sql = "update ProjectGroup set reader ="+username+"' where groupid ="+groupId ;
  62. return SetData(sql);
  63. }
  64.  
  65. public DataTable GetAssignedReaders()
  66. {
  67. //************************************************************************
  68. // TODO 04: Used in Coordinator/DisplayProjectReaders.aspx.cs *
  69. // Construct the SQL SELECT statement to retrieve the reader name, group *
  70. // code and project title for the project groups with assigned readers. *
  71. // Order the result by group code ascending. *
  72. //************************************************************************
  73. sql = "select facultyName , groupCode , title from FYProject P ,ProjectGroup G ,Faculty F where P.fypId = G.fypAssigned and G.reader is not null and G.reader = F.username order by groupCode";
  74. return myOracleDBAccess.GetData(sql);
  75. }
  76.  
  77. public DataTable GetFacultyCode(string username)
  78. {
  79. //*************************************************************
  80. // TODO 05: Used in Faculty/AssignGrades.aspx.cs *
  81. // Construct the SQL SELECT statement to retrieve the faculty *
  82. // code of a faculty identified by his/her username. *
  83. //*************************************************************
  84. sql = "select facultyCode from Faculty where username ='"+username+"'";
  85. return myOracleDBAccess.GetData(sql);
  86. }
  87.  
  88. public DataTable GetFacultyGroups(string facultyCode)
  89. {
  90. //****************************************************************************************
  91. // TODO 06: Used in Faculty/AssignGrades.aspx.cs *
  92. // Construct the SQL SELECT statement to retrieve the group id, group code and fyp id of *
  93. // the project group to which the group is assigned for the groups supervised by the *
  94. // faculty identified by his/her faculty code. Order the result by group id ascending. *
  95. //****************************************************************************************
  96. sql = "select distinct groupId , groupCode , fypAssigned from ProjectGroup P , Faculty F ,Supervises S where P.fypAssigned = S.fypId and F.username = S.username and F.facultyCode ='" + facultyCode+"' order by groupId asc";
  97. return myOracleDBAccess.GetData(sql);
  98. }
  99.  
  100. public DataTable GetStudentRequirements(string groupId, string fypId)
  101. {
  102. //****************************************************************************************
  103. // TODO 07: Used in Faculty/AssignGrades.aspx.cs *
  104. // Construct the SQL SELECT statement to retrieve students' username, name and all the *
  105. // requirement grades given by any of the faculty that are the supervisors of a project *
  106. // identified by its fyp id, for all the students in a group identified by its group id. *
  107. //****************************************************************************************
  108. sql = "select distinct S.username , S.studentName ,proposalGrade, progressGrade , finalGrade, presentationGrade from Students S ,Requirement R ,ProjectGroup P where S.groupId ="+groupId+"and P.groupId = S.groupId and P.fypAssigned = "+fypId+ "and S.username = R.studentUsername ";
  109. return myOracleDBAccess.GetData(sql);
  110. }
  111.  
  112. public bool UpdateGrades(string fypId, string studentUsername, string proposalGrade,
  113. string progressGrade, string finalGrade, string presentationGrade)
  114. {
  115. //***************************************************************************************
  116. // TODO 08: Used in Faculty/AssignGrades.aspx.cs *
  117. // Construct the SQL UPDATE statement to update ALL grade values in a requirement *
  118. // record, identified by a faculty username and a student username. NOTE: While a grade *
  119. // can be updated by ANY of the supervisors of a project, only the username of the *
  120. // faculty who assigned a group to a project appears in the Requirement table record. * *
  121. //***************************************************************************************
  122. sql = "update Requirement R set proposalGrade ="+proposalGrade+" , progressGrade = "+progressGrade+", finalGrade ="+finalGrade+",presentationGrade ="+presentationGrade+" where R.studentUsername ='"+studentUsername +"' and R.facultyUsername =(select username from SuperVises where fypid ="+fypId+")";
  123. return SetData(sql);
  124. }
  125.  
  126. public DataTable GetProjectFacultyCodes(string fypId)
  127. {
  128. //******************************************************************
  129. // TODO 09: Used in Faculty/AssignGroupToProject.aspx.cs *
  130. // Construct the SQL SELECT statement to retrieve the faculty *
  131. // codes of the supervisors of a project identified by its FYP id. *
  132. // Order the result by faculty code ascending. *
  133. //******************************************************************
  134. sql = "select facultyCode from SuperVises S, Faculty F where S.fypId ="+fypId+" and S.username = F.username order by facultyCode asc";
  135. return myOracleDBAccess.GetData(sql);
  136. }
  137.  
  138. public decimal GetFacultyCodeSequenceNumber(string groupCodePrefix)
  139. {
  140. //************************************************************
  141. // TODO 10: Used in Faculty/AssignGroupToProject.aspx.cs *
  142. // Construct the SQL SELECT statement to retrieve the number *
  143. // of times a given group code prefix has been used. *
  144. // A group code prefix is the group code minus its trailing *
  145. // integer (e.g., for group code "FL1" the prefix is "FL"). *
  146. //************************************************************
  147. sql = "select count(*) from ProjectGroup where substr(groupCode ,0, length('"+groupCodePrefix+"')) = '"+groupCodePrefix+"'";
  148. return myOracleDBAccess.GetAggregateValue(sql);
  149. }
  150.  
  151. public DataTable GetGroupsAvailableToAssign(string fypId)
  152. {
  153. //********************************************************************************
  154. // TODO 11: Used in Faculty/AssignGroupToProject.aspx.cs *
  155. // Construct the SQL SELECT statement to retrieve the group id and priority, as *
  156. // well as the name and username of the students in the group, for those groups *
  157. // that are available for assignment and that have have indicated an interest in *
  158. // a project identified by its fyp id where the project is available. Order the *
  159. // result first by group id ascending and then by student name ascending. *
  160. //********************************************************************************
  161. sql = "select S.groupId , fypPriority , studentName, username from InterestedIn I, FyProject F ,Students S where I.fypId ="+fypId+" and F.fypid = I.fypid and F.isAvailable ='Y' and I.groupId = S.groupId order by groupId asc ,studentName asc";
  162. return myOracleDBAccess.GetData(sql);
  163. }
  164.  
  165. public DataTable GetGroupsCurrentlyAssigned(string fypId)
  166. {
  167. //**********************************************************************************
  168. // TODO 12: Used in Faculty/AssignGroupToProject.aspx.cs *
  169. // Construct the SQL SELECT statement to retrieve the group id and group code, as *
  170. // well as the name of the students in the group, for those groups that have been *
  171. // assigned to a project identified by its fyp id. Order the result first by group *
  172. // id ascending and then by student name ascending. *
  173. //**********************************************************************************
  174. sql = "select S.groupid ,groupCode ,studentName from ProjectGroup P , Students S where P.fypAssigned ="+fypId+ " and S.groupId = P.groupId order by groupId asc, studentName asc";
  175. return myOracleDBAccess.GetData(sql);
  176. }
  177.  
  178. public DataTable GetFacultyProjects(string username)
  179. {
  180. //************************************************************
  181. // TODO 13: Used in Faculty/AssignGroupToProject.aspx.cs *
  182. // Construct the SQL SELECT statement to retrieve the id and *
  183. // title of the projects supervised by a faculty identified *
  184. // by his/her username. Order the result by title ascending. *
  185. //************************************************************
  186. sql = "select S.fypId , title from Supervises S , FYProject P where S.username ='"+username+"' and P.fypId = S.fypId";
  187. return myOracleDBAccess.GetData(sql);
  188. }
  189.  
  190. public DataTable GetProjectAvailability(string fypId)
  191. {
  192. //********************************************************
  193. // TODO 14: Used in Faculty/AssignGroupToProject.aspx.cs *
  194. // Construct the SQL SELECT statement to retrieve the *
  195. // availability of a project identified by its fyp id. *
  196. //********************************************************
  197. sql = "select isAvailable from FYproject where fypId = "+fypId;
  198. return myOracleDBAccess.GetData(sql);
  199. }
  200.  
  201. public bool AssignGroupToProject(string groupCode, string fypId, string groupId)
  202. {
  203. //*****************************************************************************
  204. // TODO 15: Used in Faculty/AssignGroupToProject.aspx.cs *
  205. // Construct the SQL UPDATE statement to assign a project group to a project. *
  206. //*****************************************************************************
  207. sql = "update ProjectGroup set fypAssigned ="+fypId+"where groupCode ='"+groupCode+"' and groupId = "+groupId;
  208. return SetData(sql);
  209. }
  210.  
  211. public decimal GetNumberOfGroupsSupervised(string username)
  212. {
  213. //***********************************************************************************
  214. // TODO 16: Used in Faculty/AssignGroupToProject.aspx.cs *
  215. // Construct the SQL SELECT statement to retrieve the total number of groups that a *
  216. // faculty, identified by his/her username, has assigned to all of his/her projects.*
  217. //***********************************************************************************
  218. sql = "select count(*) from Supervises S , ProjectGroup P where P.fypAssigned = S.fypId and S.username ='"+username+"'";
  219. return myOracleDBAccess.GetAggregateValue(sql);
  220. }
  221.  
  222. public bool CreateFYProject(string fypId, string title, string fypDescription, string fypCategory,
  223. string fypType, string requirement, string minStudents, string maxStudents, string isAvailable,
  224. string supervisor, string cosupervisor)
  225. {
  226. // First, create an Oracle transaction.
  227. OracleTransaction trans = myOracleDBAccess.BeginTransaction();
  228. if (trans == null) { return false; }
  229.  
  230. // Second, create the project record.
  231. //*******************************************************************
  232. // TODO 17: Used in Faculty/CreateProject.aspx.cs *
  233. // Construct the SQL INSERT statement to insert a FYProject record. *
  234. //*******************************************************************
  235. sql = "insert into FYProject values ("+fypId+",'"+title+"', '"+fypDescription+"','"+fypCategory+"','"+fypType+"','"+ requirement+ "',"+minStudents+","+maxStudents+",'"+isAvailable+"')";
  236. if (!myOracleDBAccess.SetData(sql, trans)) { myOracleDBAccess.DisposeTransaction(trans); return false; }
  237.  
  238. // Third, create the Supervises record for the supervisor.
  239. //***************
  240. // Uses TODO 18 *
  241. //***************
  242. if (!CreateSupervises(supervisor, fypId, trans)) { myOracleDBAccess.DisposeTransaction(trans); return false; }
  243. {
  244. // Create the Supervises record for the cosupervisor, if any.
  245. if (cosupervisor != "")
  246. {
  247. if (!CreateSupervises(cosupervisor, fypId, trans)) { myOracleDBAccess.DisposeTransaction(trans); return false; }
  248. }
  249. }
  250. myOracleDBAccess.CommitTransaction(trans);
  251. return true;
  252. }
  253.  
  254. public bool CreateSupervises(string username, string fypId, OracleTransaction trans)
  255. {
  256. if (trans == null)
  257. {
  258. trans = myOracleDBAccess.BeginTransaction();
  259. if (trans == null) { return false; }
  260. }
  261. //********************************************************************
  262. // TODO 18: Used in App_Code/FYPMSDB.CreateFYProject *
  263. // Construct the SQL INSERT statement to insert a Supervises record. *
  264. //********************************************************************
  265. sql = "insert into Supervises values('"+username+"',"+fypId+")";
  266. return myOracleDBAccess.SetData(sql, trans);
  267. }
  268.  
  269. public DataTable GetSupervisorProjectDigest(string username)
  270. {
  271. //*******************************************************************************
  272. // TODO 19: Used in Faculty/DisplayProjects.aspx.cs *
  273. // Construct the SQL SELECT statement to retrieve the fyp id, title, category, *
  274. // type, mimimum students and maximum students of the projects supervised by a *
  275. // faculty identified by his/her username. Order the result by title ascending. *
  276. //*******************************************************************************
  277. sql = "select F.fypId ,title , fypCategory ,fypType, minStudents ,maxStudents from FYProject F ,Supervises S where S.username ='"+username+"' and S.fypId = F.fypId order by title asc ";
  278. return myOracleDBAccess.GetData(sql);
  279. }
  280.  
  281. public DataTable GetInterestedInProject(string fypId)
  282. {
  283. //**********************************************************************
  284. // TODO 20: Used in Faculty/EditProject.aspx.cs *
  285. // Construct the SQL SELECT statement to retrieve all the attributes *
  286. // from the InterestedIn table for a project identified by its fyp id. *
  287. //**********************************************************************
  288. sql = "select * from InterestedIn I where I.fypId ="+fypId+"";
  289. return myOracleDBAccess.GetData(sql);
  290. }
  291.  
  292. public DataTable GetCosupervisorInfoForEdit(string fypId, string username)
  293. {
  294. //**************************************************************************************
  295. // TODO 21: Used in Faculty/EditProject.aspx.cs *
  296. // Construct the SQL SELECT statement to retrieve the username of the cosupervisor, if *
  297. // any, of a project, identified by its fyp id, given the username of one supervisor. *
  298. //**************************************************************************************
  299. sql = "select username from Supervises S1 where fypId =(select S2.fypid from Supervises S2 where S2.username <> S1.username and S1.fypId = S2.fypid and S2.username ='"+username+"')";
  300. return myOracleDBAccess.GetData(sql);
  301. }
  302.  
  303. public bool UpdateFYProject(string fypId, string title, string fypDescription, string fypCategory,
  304. string fypType, string requirement, string minStudents, string maxStudents, string isAvailable,
  305. string oldCosupervisor, string newCosupervisor)
  306. {
  307. // First, create an Oracle transaction.
  308. OracleTransaction trans = myOracleDBAccess.BeginTransaction();
  309. if (trans == null) { return false; }
  310.  
  311. // Second, update the FYP project values.
  312. //***********************************************************************************
  313. // TODO 22: Used in Faculty/EditProject.aspx.cs *
  314. // Construct the SQL UPDATE statement to update all the values of a FYProject table *
  315. // record with the corresponding parameter value for the given project fyp id. *
  316. //***********************************************************************************
  317. sql = "update FYProject set title ='"+title+ "',fypDescription ='"+ fypDescription+ "',fypCategory='"+ fypCategory+ "',fypType ='"+ fypType+ "',requirement ='"+requirement+ "',minStudents ="+ minStudents+",maxStudents ="+maxStudents+ ",isAvailable= '"+ isAvailable+"' where fypId ="+fypId+"";
  318. if (!myOracleDBAccess.SetData(sql, trans)) { myOracleDBAccess.DisposeTransaction(trans); return false; }
  319.  
  320. // Finally, update the cosupervisor, if necessary.
  321. if (oldCosupervisor != newCosupervisor)
  322. {
  323. if (oldCosupervisor != "")
  324. {
  325. // Delete the old cosupervsior for the project from the Supervises table.
  326. //***************
  327. // Uses TODO 23 *
  328. //***************
  329. if (!DeleteSupervises(oldCosupervisor, fypId, trans)) { myOracleDBAccess.DisposeTransaction(trans); return false; }
  330. }
  331. if (newCosupervisor != "")
  332. {
  333. // Insert a new cosupervisor for the project into the Supervises table.
  334. //***************
  335. // Uses TODO 18 *
  336. //***************
  337. if (!CreateSupervises(newCosupervisor, fypId, trans)) { myOracleDBAccess.DisposeTransaction(trans); return false; }
  338. }
  339. }
  340. myOracleDBAccess.CommitTransaction(trans);
  341. return true;
  342. }
  343.  
  344. public bool DeleteSupervises(string username, string fypId, OracleTransaction trans)
  345. {
  346. //**************************************************************
  347. // TODO 23: Used in App_Code/FYPMSDB.UpdateFYProject *
  348. // Construct the SQL DELETE statement to delete the Supervises *
  349. // record identified by an fyp id and a username. *
  350. //**************************************************************
  351. sql = "delete from Supervises where username ='"+username+"' and fypId ="+fypId+"";
  352. return myOracleDBAccess.SetData(sql, trans);
  353. }
  354.  
  355. public bool CreateInterestedIn(string fypId, string groupId, string fypPriority)
  356. {
  357. //*************************************************************************
  358. // TODO 24: Used in Student/AvailableProjects.aspx.cs *
  359. // Construct the SQL INSERT statement to add a record to the InterestedIn *
  360. // table with the specified fyp id, group id and priority values. *
  361. //*************************************************************************
  362. sql = "insert into InterestedIn values ("+fypId+","+groupId+","+groupId+")";
  363. return SetData(sql);
  364. }
  365.  
  366. public DataTable GetProjectAssignedToGroup(string groupId)
  367. {
  368. //***************************************************************
  369. // TODO 25: Used in Student/AvailableProjects.aspx.cs *
  370. // Construct the SQL SELECT statement to retrieve the title of *
  371. // the project assigned to the group identified by its groupId. *
  372. // Order the result by title ascending. *
  373. //***************************************************************
  374. sql = "select title from FYProject F , ProjectGroup P where F.fypId = P.fypId and P.groupId ="+groupId;
  375. return myOracleDBAccess.GetData(sql);
  376. }
  377.  
  378. public bool AddStudentToGroup(string groupId, string username)
  379. {
  380. //***********************************************************************
  381. // TODO 26: Used in Student/ManageProjectGroup.aspx.cs *
  382. // Construct the SQL UPDATE statement to assign a groupId to a student. *
  383. //***********************************************************************
  384. sql = "update Students set groupId ='"+groupId +" where username ='"+username+"'";
  385. return SetData(sql);
  386. }
  387.  
  388. public DataTable GetStudentRecord(string username)
  389. {
  390. //****************************************************************
  391. // TODO 27: Used in Student/ManageProjectGroup.aspx.cs *
  392. // Construct the SQL SELECT statement to retrieve all of the *
  393. // attribute values of a student identified by his/her username. *
  394. //****************************************************************
  395. sql = "select * from Students where username = '"+username+"'";
  396. return myOracleDBAccess.GetData(sql);
  397. }
  398.  
  399. public bool RemoveGroupMember(string username)
  400. {
  401. //*********************************************************
  402. // TODO 28: Used in Student/ManageProjectGroup.aspx.cs *
  403. // Construct the SQL UPDATE statement to remove a student *
  404. // identified by his/her username from a project group. *
  405. //*********************************************************
  406. sql = "update Students set groupId = null where username ='"+username+"'";
  407. return SetData(sql);
  408. }
  409.  
  410. public bool DeleteProjectGroup(string groupId)
  411. {
  412. //******************************************************
  413. // TODO 29: Used in Student/ManageProjectGroup.aspx.cs *
  414. // Construct the SQL DELETE statement to delete a *
  415. // project group identified by its groupId. *
  416. //******************************************************
  417. sql = "delete from ProjectGroup where groupId ="+groupId;
  418. return SetData(sql);
  419. }
  420.  
  421. public bool CreateProjectGroup(string groupId)
  422. {
  423. //*********************************************************************************
  424. // TODO 30: Used in Student/ManageProjectGroup.aspx.cs *
  425. // Construct the SQL INSERT statement to add a project group with the specified *
  426. // groupId to the ProjectGroup table. All other attributes values should be null. *
  427. //*********************************************************************************
  428. sql = "insert into ProjectGroup values ("+groupId+",null,null,null)";
  429. return SetData(sql);
  430. }
  431.  
  432. public DataTable GetAssignedProjectInformatione(string username)
  433. {
  434. //*****************************************************************************
  435. // TODO 31: Used in Student/ViewGrades.aspx.cs *
  436. // Construct the SQL SELECT statement to retrieve the fyp id and title of the *
  437. // project to which a student, identified by his/her username, is assigned. *
  438. //*****************************************************************************
  439. sql = "select F.fypId , title where FYProject F ,Students S, ProjectGroup P where S.groupId = P.groupId and F.fypId = P.fypAssigned and S.username ='"+username+"'";
  440. return myOracleDBAccess.GetData(sql);
  441. }
  442.  
  443. public DataTable GetStudentGrades(string username)
  444. {
  445. //****************************************************************************
  446. // TODO 32: Used in Student/ViewGrades.aspx.cs *
  447. // Construct the SQL SELECT statement to retrieve the faculty name, as well *
  448. // as the proposal, progress, final and presentation grades, given by the *
  449. // supervisor and the reader for the student identified by his/her username. *
  450. //****************************************************************************
  451. sql = "select facultyName , proposalGrade ,proposalGrade, progressGrade ,finalGrade ,presentationGrade from Faculty F, Students S, Requirement R where F.username = R.facultyUsername and S.username = R.studentUsername ";
  452. return myOracleDBAccess.GetData(sql);
  453. }
  454.  
  455. /***********************************************/
  456. /***** Methods used in App_Code/Helpers.cs *****/
  457. /***********************************************/
  458.  
  459. public bool CreateRequirement(string facultyUsername, string studentUsername, string proposalGrade,
  460. string progressGrade, string finalGrade, string presentationGrade)
  461. {
  462. //******************************************************************
  463. // TODO 33: Used in CreateRequirementRecord in App_Code/Helpers.cs *
  464. // Construct the SQL INSERT statement to insert a value for each *
  465. // attribute of the Requirement table whose values are specified *
  466. // by the corresponding parameter of this method. *
  467. //******************************************************************
  468. sql = "insert into Requirement values('"+facultyUsername+"','"+studentUsername+"',"+proposalGrade+","+progressGrade+","+finalGrade+","+presentationGrade+")";
  469. return SetData(sql);
  470. }
  471.  
  472. public DataTable GetAssignedFypId(string groupId)
  473. {
  474. //***************************************************************************
  475. // TODO 34: Used in IsGroupAssigned in App_Code/Helpers.cs *
  476. // Construct the SQL SELECT statement to retrieve the fyp id of the project *
  477. // to which a project group, identified by its group id, has been assigned. *
  478. //***************************************************************************
  479. sql = "select fypAssigned from ProjectGroup where groupid ="+groupId;
  480. return myOracleDBAccess.GetData(sql);
  481. }
  482.  
  483. public DataTable GetFaculty()
  484. {
  485. //*****************************************************
  486. // TODO 35: Used in GetFaculty in App_Code/Helpers.cs *
  487. // Construct the SQL SELECT statement to retrieve *
  488. // the username and name of all faculty. *
  489. //*****************************************************
  490. sql = "select username ,facultyName from Faculty";
  491. return myOracleDBAccess.GetData(sql);
  492. }
  493.  
  494. public DataTable GetGroupAvailableProjectDigests(string groupId)
  495. {
  496. //**************************************************************************************
  497. // TODO 36: Used in GetGroupAvailableProjectDigests in App_Code/Helpers.cs *
  498. // Construct the SQL SELECT statement to retrieve the fyp id, title, category, type, *
  499. // minimum students and maximum students of the projects for which a group, identified *
  500. // by its group id, can indicate an interest. Only those projects that are available, *
  501. // meet the group's size requirements and for which a group has not alredy indicated *
  502. // an interest should be retrieved. Groups that have been assigned to a project cannot *
  503. // indicate an interest in any project. Order the result by title ascending. * *
  504. //**************************************************************************************
  505. sql = "with temp as(select groupId ,count(*) as numStu from Students where groupId ="+groupId+" group by groupId) select distinct F.fypId,F.title,F.category,F.fypType, F.minStudents,F.maxStudents from temp T , FYProject F, ProjectGroup P where T.numStu between F.minStudents and F.maxStudents and P.groupId =temp.groupId and P.fypAssigned = null and F.fypId not in (select fypId from InterestedIn I where I.groupId =P.groupId and I.fypId = F.fypid)";
  506. return myOracleDBAccess.GetData(sql);
  507. }
  508.  
  509. public DataTable GetProjectGroupMembers(string groupId)
  510. {
  511. //****************************************************************************
  512. // TODO 37: Used in GetProjectGroupMembers in App_Code/Helpers.cs *
  513. // Construct the SQL SELECT statement to retrieve the value of all the *
  514. // attributes of the students in a project group identified by its group id. *
  515. //****************************************************************************
  516. sql = "select * from Students where groupId ="+groupId;
  517. return myOracleDBAccess.GetData(sql);
  518. }
  519.  
  520. public DataTable GetStudentGroupId(string username)
  521. {
  522. //************************************************************
  523. // TODO 38: Used in GetStudentGroupId in App_Code/Helpers.cs *
  524. // Construct the SQL SELECT statement to retrieve the *
  525. // group id for the student identified by his/her username. *
  526. //************************************************************
  527. sql = "select groupId from Students where username ='"+username+"'";
  528. return myOracleDBAccess.GetData(sql);
  529. }
  530.  
  531. public DataTable GetSupervisors(string fypId)
  532. {
  533. //**************************************************************************
  534. // TODO 39: Used in GetProjectSupervisors in App_Code/Helpers.cs *
  535. // Construct the SQL SELECT statement to retrieve the username and faculty *
  536. // name of all the supervisors of a project identified by its fyp id. *
  537. //**************************************************************************
  538. sql = "select F.username , facultyName from Faculty F, Supervises S where S.username =F.username and S.fypId ="+fypId;
  539. return myOracleDBAccess.GetData(sql);
  540. }
  541.  
  542. public DataTable GetProjectsGroupInterestedIn(string groupId)
  543. {
  544. //*********************************************************************************
  545. // TODO 40: Used in GetProjectsGroupInterestedIn in App_Code/Helpers.cs *
  546. // Construct the SQL SELECT statement to retrieve the fyp id, title, category, *
  547. // type and priority of the projects for which a group, identified by its group *
  548. // id, HAS ALREADY indicated an interest. Order the result by priority ascending. *
  549. //*********************************************************************************
  550. sql = "select I.fypId , title , fypCategory , fypType, fypPriority from InterestedIn I , FYProject F where I.groupId ="+groupId+ " and F.fypId = I.fypId order by fypPriority asc";
  551. return myOracleDBAccess.GetData(sql);
  552. }
  553.  
  554. /*---------------------------------END OF TODOS---------------------------------*/
  555.  
  556. #region *** DO NOT CHANGE THE METHODS BELOW THIS LINE. THEY ARE NOT TODOS!!! ***!
  557.  
  558. public DataTable GetProjectCategories()
  559. {
  560. sql = "select * from ProjectCategory";
  561. return myOracleDBAccess.GetData(sql);
  562. }
  563.  
  564. public DataTable GetProjectDetails(string fypId)
  565. {
  566. sql = "select * from FYProject where fypId=" + fypId;
  567. return myOracleDBAccess.GetData(sql);
  568. }
  569.  
  570. public DataTable GetProjectDigests()
  571. {
  572. sql = "select fypId, title, fypCategory, fypType, minStudents, maxStudents, isAvailable" +
  573. " from FYProject order by title";
  574. return myOracleDBAccess.GetData(sql);
  575. }
  576.  
  577. public bool RemoveGroupFromProject(string groupId)
  578. {
  579. sql = "update ProjectGroup set fypAssigned=null where groupId=" + groupId;
  580. return SetData(sql);
  581. }
  582.  
  583. public bool RemoveReader(string groupId)
  584. {
  585. sql = "update ProjectGroup set reader=null where groupId=" + groupId;
  586. return SetData(sql);
  587. }
  588.  
  589.  
  590. public bool SetData(string sql)
  591. {
  592. OracleTransaction trans = myOracleDBAccess.BeginTransaction();
  593. if (trans == null) { return false; }
  594. if (myOracleDBAccess.SetData(sql, trans))
  595. { myOracleDBAccess.CommitTransaction(trans); return true; } // The insert/update/delete succeeded.
  596. else
  597. { myOracleDBAccess.DisposeTransaction(trans); return false; } // The insert/update/delete failed.
  598. }
  599. #endregion
  600. }
  601. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement