Esempio n. 1
0
        /// <summary>
        ///
        ///     This method inserts a new template into the Template table in the db.
        ///     This function also takes the selected sections from the checklist box and
        ///     generates PersonalSection objects that link the template and section.
        ///     This is important because the codeList box in the feedbackForm uses the chosen
        ///     template id and populates the code list based on the codes that are related to the
        ///     section IDs found in PersonalSection where that section ID is linked with the TemplateID

        /// </summary>
        /// <param name="input"> new template's tempType </param>
        /// <param name="selectedSections"> The checkedlistbox where user can check the sections to relate to the new template </param>
        public static void CreateTemplateWithSelectedSections(string input, CheckedListBox selectedSections)
        {
            //when template is submitted, needs to make a new section ID, then needs to make new PersonalSection
            //objects for each checked section in the sectionsListBox
            bool stringOk = false; //stringOk will check the string isn't just spaces or blank

            //ideally there would be a check to make sure this name asn't already been entered into the database
            //if SELECT * FROM Section WHERE name = tagBox.Text != null then throw error (because a row exists with this name)
            if (input.Replace(" ", "") != "")
            {
                stringOk = true;
            }

            if (stringOk == true)
            {
                //has to create the section object first so we have a section ID to work with
                string queryString = SqlQueries.InsertNewTemplate(input);
                Connection.GetDbConn().CreateCommand(queryString);
                //template object has now been created
                //we will get the id of this new template first instead of getting it in each iteration of the loop
                DataSet ds         = Connection.GetDbConn().GetDataSet(SqlQueries.GetTemplateIdFromName(input));
                DataRow dRow       = ds.Tables[0].Rows[0];
                var     templateId = dRow.ItemArray.GetValue(0);
                foreach (string section in selectedSections.CheckedItems)
                {
                    //for each template selected, we have to add a template id and section id to PersonalSection
                    //so we will get the template id from the template name
                    DataSet ds1       = Connection.GetDbConn().GetDataSet(SqlQueries.GetSectionIdFromName(section));
                    DataRow dRow1     = ds1.Tables[0].Rows[0];
                    var     sectionId = dRow1.ItemArray.GetValue(0);
                    //now we have the template id and section id
                    Connection.GetDbConn().CreateCommand(SqlQueries.InsertNewPersonalSection(templateId, sectionId));
                    //now a PersonalSection object has been created
                }
            }
            else if (stringOk == false)
            {
                //need an error box here to advise user of issue
            }
        }
        /// <summary>
        ///
        ///     Constructor. Displays success message if applicant added.
        ///     Gets applicants from database and lists them.
        ///
        /// </summary>
        /// <param name="applicantAdded"> If a new applicant has been added: True, and False </param>
        public ConfirmApplicantForm(bool applicantAdded)
        {
            InitializeComponent();

            if (applicantAdded)
            {
                Label_Success.Visible = true;
            }

            DataSet applicantDB = Connection.GetDbConn().
                                  GetDataSet(SqlQueries.SelectApplicant());

            DataGrid_ApplicantList.DataSource = applicantDB.Tables[0];

            for (int i = 0; i < DataGrid_ApplicantList.Columns.Count; i++)
            {
                DataGrid_ApplicantList.Columns[i].Width = 181;
            }

            Label_RecruiterName.Text  = Recruiter.GetInstance().Name + " " + Recruiter.GetInstance().Surname;
            Label_ApplicantTotal.Text = Applicant.applicants.Count.ToString();
        }
Esempio n. 3
0
        /// <summary>
        /// Retrieve the codes from the database and add them into a List <Code>
        /// </summary>
        public static void FillCodeList()
        {
            // Retrieves the codes from the database
            DataSet ds = Connection.GetDbConn().GetDataSet(SqlQueries.SelectCodes());
            DataRow dRow;

            // Iterates through the table extracted from the database
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                dRow = ds.Tables[0].Rows[i];

                // Creates a new instance passing the data-fields from the database
                Code _instance = new Code(
                    Int32.Parse(dRow.ItemArray.GetValue(0).ToString()), // Code ID
                    dRow.ItemArray.GetValue(1).ToString(),              // CodeName
                    Int32.Parse(dRow.ItemArray.GetValue(2).ToString()), // SectionNo
                    dRow.ItemArray.GetValue(3).ToString()               // CodeParagraph
                    );
                // the instance is added into the list
                Code.codeList.Add(_instance);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Generates templateS according to the number of applicants into the list.
        /// </summary>
        /// <param name="applicant">Gets the object of the applicant being reviewed</param>
        /// <param name="templateType">Gets the type of the template chosen</param>
        public static void GenerateTemplateForApplicant(Applicant applicant, string templateType)
        {
            // Retrieves the template Id from the database given its type
            DataSet templateDB = Connection.GetDbConn().
                                 GetDataSet(SqlQueries.GetTemplateIdFromName(templateType));

            DataRow templateDBValue;

            for (int i = 0; i < templateDB.Tables[0].Rows.Count; i++)
            {
                templateDBValue = templateDB.Tables[0].Rows[i];

                // Creates the instance
                Template _instance = new Template(
                    Int32.Parse(templateDBValue.ItemArray.GetValue(0).ToString()), // Template ID
                    templateType,                                                  // Template's tempType
                    applicant                                                      // Applicant belonging to
                    );
                // Add the applicant inside the list
                Template.templatesForApplicants.Add(_instance);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Create instances with the information in database and add it into the sectionList
        /// </summary>
        public static void FillSectionList()
        {
            // Retrieves all the sections from the database
            DataSet ds = Connection.GetDbConn().GetDataSet(SqlQueries.GetSectionNameId());
            DataRow dRow;

            // Iterates through the section table
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                dRow = ds.Tables[0].Rows[i];

                // Instance created getting the values from the database
                _instance = new Section(
                    Int32.Parse(dRow.ItemArray.GetValue(0).ToString()), // section ID
                    dRow.ItemArray.GetValue(1).ToString()               // section's name
                    );
                // _instance issaved into the list
                Section.sectionList.Add(_instance);
            }

            // The instance is destroyed as it doesn't need anymore
            _instance = null;
        }
Esempio n. 6
0
        /// <summary>
        /// inserts a new section and iterates over every checked item in a checklist of template names. creates a PersonalSection
        /// object for each
        /// </summary>
        /// <param name="input"> This is a string from the section textbox. User input.</param>
        /// <param name="templateCheckBox"> A ChecklistBox object containing template names.</param>
        public static void InsertSectionWithSelectedTemplates(string input, CheckedListBox templateCheckBox)
        {
            //has to create the section object first so we have a section ID to work with
            string queryString = SqlQueries.CreateNewTag(input);

            Connection.GetDbConn().CreateCommand(queryString); //section object has now been created
            //we will get the id of this new section first instead of getting it in each iteration of the loop
            DataSet ds        = Connection.GetDbConn().GetDataSet(SqlQueries.GetSectionIdFromName(input));
            DataRow dRow      = ds.Tables[0].Rows[0];
            var     sectionId = dRow.ItemArray.GetValue(0);

            foreach (string template in templateCheckBox.CheckedItems)
            {
                //for each template selected, we have to add a template id and section id to PersonalSection
                //so we will get the template id from the template name
                DataSet ds1        = Connection.GetDbConn().GetDataSet(SqlQueries.GetTemplateIdFromName(template));
                DataRow dRow1      = ds1.Tables[0].Rows[0];
                var     templateId = dRow1.ItemArray.GetValue(0);
                //now we have the template id and section id
                string createPersonalSection = $"insert into PersonalSection (template_ID, section_ID) VALUES ('{templateId}', '{sectionId}')";
                Connection.GetDbConn().CreateCommand(createPersonalSection);
                //now a PersonalSection object has been created
            }
        }