Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void btnCon_Click(object sender, EventArgs e)
- {
- SqlConnection cnSMAT = new SqlConnection(cnstr);
- SqlCommand sqlInsertStatus;
- //Ask if user is ready to update
- DialogResult dr = MessageBox.Show("Are you sure you wish to save this offer", "Warning!", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk);
- if (dr == DialogResult.Yes)
- {
- sqlInsertStatus = new SqlCommand("insert into applicant_status (ApplicantID, StatusID, DateIssued) values (@applicantID, 7, @dateIssued)", cnSMAT);
- sqlInsertStatus.Parameters.AddWithValue("applicantID", lbApplicants.SelectedValue);
- sqlInsertStatus.Parameters.AddWithValue("dateIssued", DateTime.Now);
- cnSMAT.Open();
- sqlInsertStatus.ExecuteNonQuery();
- cnSMAT.Close();
- lsbStatus.Text = "";
- rtbInterview.Text = "";
- rtbAptitudeTest.Text = "";
- lsbQualifications.Text = "";
- dsSMAT.Tables["applicant"].Select("ApplicantID = " + lbApplicants.SelectedValue)[0].Delete();
- MessageBox.Show("Offer Saved", "Accepted", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
- if (lbApplicants.Text == "")
- {
- btnCon.Enabled = false;
- btnReject.Enabled = false;
- btnUnCon.Enabled = false;
- btnWaiting.Enabled = false;
- }
- dsSMAT.Tables["offer"].Rows.Clear();
- daOffers = new SqlDataAdapter(@"select
- sub_query.ApplicantID,
- applicant.ApplicantForename,
- applicant.ApplicantSurname,
- applicant.ChosenCourseID
- from
- (select
- ApplicantID, StatusID, DateIssued,
- RANK() OVER (PARTITION BY ApplicantID ORDER BY DateIssued DESC, StatusID DESC) as 'Ranking'
- from
- applicant_status) as sub_query
- inner join
- applicant
- on
- sub_query.ApplicantID = applicant.ApplicantID
- where
- sub_query.StatusID = 7 and sub_query.Ranking = 1", cnstr);
- daOffers.FillSchema(dsSMAT, SchemaType.Source, "offer");
- daOffers.Fill(dsSMAT, "offer");
- //dsSMAT.Tables["offer"].Columns.Add("FullName", typeof(string), "ApplicantForename + ' ' + ApplicantSurname");
- lbOffers.DataSource = dsSMAT.Tables["offer"];
- lbOffers.DisplayMember = "FullName";
- dsSMAT.Tables["offer"].DefaultView.RowFilter = "ChosenCourseID = -1";
- SqlCommand sqlOfferCount = new SqlCommand(@"select
- COUNT(*) as 'Applicants'
- from
- (select
- ApplicantID, StatusID, DateIssued,
- RANK() OVER (PARTITION BY ApplicantID ORDER BY DateIssued DESC, StatusID DESC) as 'Ranking'
- from
- applicant_status) as sub_query
- inner join
- applicant
- on
- sub_query.ApplicantID = applicant.ApplicantID
- inner join
- course
- on
- applicant.ChosenCourseID = course.CourseID
- where
- (sub_query.StatusID = 7 or sub_query.StatusID = 8) and sub_query.Ranking = 1 and course.CourseID = @courseID", cnSMAT);
- sqlOfferCount.Parameters.AddWithValue("courseID", ((Course)cmbCourses.SelectedItem).CourseID);
- cnSMAT.Open();
- offerCount = (int)sqlOfferCount.ExecuteScalar();
- cnSMAT.Close();
- int maxPlaces = ((int)dsSMAT.Tables["applicant_offer"].Select("CourseID = " + ((Course)cmbCourses.SelectedItem).CourseID)[0]["CourseMaxPlaces"]) - offerCount;
- txtPlaces.Text = "" + maxPlaces;
- dsSMAT.Tables["offer"].DefaultView.RowFilter = "ChosenCourseID = " + ((Course)cmbCourses.SelectedItem).CourseID;
- }
- else
- if (dr == DialogResult.No)
- {
- }
- }
Add Comment
Please, Sign In to add comment