Guest User

Untitled

a guest
Jul 12th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.49 KB | None | 0 0
  1. private void btnCon_Click(object sender, EventArgs e)
  2. {
  3. SqlConnection cnSMAT = new SqlConnection(cnstr);
  4. SqlCommand sqlInsertStatus;
  5.  
  6. //Ask if user is ready to update
  7. DialogResult dr = MessageBox.Show("Are you sure you wish to save this offer", "Warning!", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk);
  8. if (dr == DialogResult.Yes)
  9. {
  10. sqlInsertStatus = new SqlCommand("insert into applicant_status (ApplicantID, StatusID, DateIssued) values (@applicantID, 7, @dateIssued)", cnSMAT);
  11. sqlInsertStatus.Parameters.AddWithValue("applicantID", lbApplicants.SelectedValue);
  12. sqlInsertStatus.Parameters.AddWithValue("dateIssued", DateTime.Now);
  13.  
  14. cnSMAT.Open();
  15. sqlInsertStatus.ExecuteNonQuery();
  16. cnSMAT.Close();
  17.  
  18. lsbStatus.Text = "";
  19. rtbInterview.Text = "";
  20. rtbAptitudeTest.Text = "";
  21. lsbQualifications.Text = "";
  22.  
  23. dsSMAT.Tables["applicant"].Select("ApplicantID = " + lbApplicants.SelectedValue)[0].Delete();
  24.  
  25. MessageBox.Show("Offer Saved", "Accepted", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  26.  
  27. if (lbApplicants.Text == "")
  28. {
  29. btnCon.Enabled = false;
  30. btnReject.Enabled = false;
  31. btnUnCon.Enabled = false;
  32. btnWaiting.Enabled = false;
  33. }
  34.  
  35. dsSMAT.Tables["offer"].Rows.Clear();
  36.  
  37. daOffers = new SqlDataAdapter(@"select
  38. sub_query.ApplicantID,
  39. applicant.ApplicantForename,
  40. applicant.ApplicantSurname,
  41. applicant.ChosenCourseID
  42. from
  43. (select
  44. ApplicantID, StatusID, DateIssued,
  45. RANK() OVER (PARTITION BY ApplicantID ORDER BY DateIssued DESC, StatusID DESC) as 'Ranking'
  46. from
  47. applicant_status) as sub_query
  48. inner join
  49. applicant
  50. on
  51. sub_query.ApplicantID = applicant.ApplicantID
  52. where
  53. sub_query.StatusID = 7 and sub_query.Ranking = 1", cnstr);
  54. daOffers.FillSchema(dsSMAT, SchemaType.Source, "offer");
  55. daOffers.Fill(dsSMAT, "offer");
  56.  
  57. //dsSMAT.Tables["offer"].Columns.Add("FullName", typeof(string), "ApplicantForename + ' ' + ApplicantSurname");
  58. lbOffers.DataSource = dsSMAT.Tables["offer"];
  59. lbOffers.DisplayMember = "FullName";
  60. dsSMAT.Tables["offer"].DefaultView.RowFilter = "ChosenCourseID = -1";
  61.  
  62. SqlCommand sqlOfferCount = new SqlCommand(@"select
  63. COUNT(*) as 'Applicants'
  64. from
  65. (select
  66. ApplicantID, StatusID, DateIssued,
  67. RANK() OVER (PARTITION BY ApplicantID ORDER BY DateIssued DESC, StatusID DESC) as 'Ranking'
  68. from
  69. applicant_status) as sub_query
  70. inner join
  71. applicant
  72. on
  73. sub_query.ApplicantID = applicant.ApplicantID
  74. inner join
  75. course
  76. on
  77. applicant.ChosenCourseID = course.CourseID
  78. where
  79. (sub_query.StatusID = 7 or sub_query.StatusID = 8) and sub_query.Ranking = 1 and course.CourseID = @courseID", cnSMAT);
  80. sqlOfferCount.Parameters.AddWithValue("courseID", ((Course)cmbCourses.SelectedItem).CourseID);
  81.  
  82. cnSMAT.Open();
  83. offerCount = (int)sqlOfferCount.ExecuteScalar();
  84. cnSMAT.Close();
  85.  
  86. int maxPlaces = ((int)dsSMAT.Tables["applicant_offer"].Select("CourseID = " + ((Course)cmbCourses.SelectedItem).CourseID)[0]["CourseMaxPlaces"]) - offerCount;
  87. txtPlaces.Text = "" + maxPlaces;
  88.  
  89. dsSMAT.Tables["offer"].DefaultView.RowFilter = "ChosenCourseID = " + ((Course)cmbCourses.SelectedItem).CourseID;
  90.  
  91. }
  92. else
  93. if (dr == DialogResult.No)
  94. {
  95. }
  96. }
Add Comment
Please, Sign In to add comment