protected void SubmitProgram_Click(object sender, EventArgs e)
    {
        MessageUserControl.TryRun(() =>
        {
            // Variables
            string programName, credentialType, programLink, programLength;
            string errorList = "";
            int categoryID, temp;
            Uri tempUrl;
            bool workOutdoors, shiftWork, travel, activated, checkURL;

            //Validate non-string variables
            //Po
            bool result = int.TryParse(ProgramLength.Text.Trim(), out temp);
            if (!result)
            {
                errorList += "- Please enter a numeric value into the program length field (whole number only).\\n";
            }
            if (temp != 0)
            {
                if ((int.Parse(ProgramLength.Text)) < 0 || (int.Parse(ProgramLength.Text)) > 100)
                {
                    errorList += "- Program length must be a whole number between 1 - 99.\\n";
                }
            }

            //Validate URL
            result = Uri.TryCreate(ProgramLink.Text, UriKind.Absolute, out tempUrl) && tempUrl.Scheme == Uri.UriSchemeHttp;
            if (!result)
            {
                errorList += "- Please enter a properly formatted URL (ex. http://www.example.com).\\n";
            }

            PathwaysController controller = new PathwaysController();

            //Validate field lengths
            if (ProgramName.Text.Trim().Length > 100)
            {
                errorList += "- Program Name cannot exceed 100 characters. \\n";
            }

            if (ProgramLink.Text.Trim().Length > 150)
            {
                errorList += "- Program Link cannot exceed 150 characters. \\n";
            }

            //check to see if program name exists
            //Po
            result = controller.CheckProgramName(ProgramName.Text.Trim());
            //verify the name does not exist
            if (result == false)
            {
                errorList += "- The Program Name selected currently exists in the system, and cannot be repeated.\\n";
            }



            // Get values from page
            //Po
            programName    = ProgramName.Text.Trim();
            credentialType = CredentialType.SelectedValue;
            programLink    = ProgramLink.Text.Trim();
            programLength  = ProgramLength.Text.Trim() + " " + ProgramLengthDDL.SelectedValue;
            workOutdoors   = WorkOutdoors.Checked;
            shiftWork      = ShiftWork.Checked;
            travel         = Travel.Checked;
            activated      = Activated.Checked;
            categoryID     = int.Parse(CategoryList.SelectedValue);



            if (credentialType == "Degree")
            {
                //verify the URL does not exist
                checkURL = controller.CheckDegUrl(programLink);
                if (checkURL == false)
                {
                    errorList += "- The url selected currently exists in the system, and cannot be repeated.\\n";
                }

                // Make a list for entering degree pathway information
                List <int> diplomaIDs = new List <int>();
                Degree degreeProgram  = new Degree();

                // Populate a new degree
                degreeProgram.DegreeName   = programName;
                degreeProgram.DegreeLink   = programLink;
                degreeProgram.DegreeLength = programLength;
                degreeProgram.Activated    = activated;
                degreeProgram.WorkOutdoors = workOutdoors;
                degreeProgram.WorkTravel   = travel;
                degreeProgram.ShiftWork    = shiftWork;
                degreeProgram.CategoryID   = categoryID;

                int numOfRows = Program_GridView.Rows.Count;

                if (numOfRows != 0)
                {
                    //gather data from the degree pathway gridview for processing
                    foreach (GridViewRow row in Program_GridView.Rows)
                    {
                        // Find controls in the Gridview
                        int diplomaID = int.Parse((row.FindControl("ProgramList") as DropDownList).SelectedValue);
                        diplomaIDs.Add(diplomaID);
                    }
                }

                int index = 0;
                diplomaIDs.Sort();
                bool flagDip = true;
                while (index < diplomaIDs.Count - 1 && flagDip == true)
                {
                    if (diplomaIDs[index] == diplomaIDs[index + 1])
                    {
                        errorList += "- Diploma pathways cannot appear more than once.\\n";
                        flagDip    = false;
                    }
                    else
                    {
                        index++;
                    }
                }

                if (errorList != "")
                {
                    throw new Exception(errorList);
                }

                //Insert the entry
                controller.InsertDegreeProgram(degreeProgram, diplomaIDs);
                ClearFields();
                Response.Write("<script type=\"text/javascript\">alert('Entry has been inserted.');</script>");
                //Hide panels
                ShowCoursesView.Checked = false;
                ShowDipPathView.Checked = false;
                ShowDegPathView.Checked = false;
                entrance_req.Visible    = false;
                degree_link.Visible     = false;
                degree_pathways.Visible = false;
            }

            if (credentialType == "Diploma")
            {
                //verify the URL does not exist
                checkURL = controller.CheckDipCertUrl(programLink);
                if (checkURL == false)
                {
                    errorList += "- The url selected currently exists in the system, and cannot be repeated.\\n";
                }
                //validate field length
                if (EntReqDetail.Text.Length > 150)
                {
                    errorList += "- Entrance Requirement Details cannot exceed 150 characters. \\n";
                }

                //check coompetitive advantage
                //Po
                result = int.TryParse(CompetitiveAdv.Text.Trim(), out temp);
                if (!result)
                {
                    errorList += "- Please enter a numeric value into the competitive advantage field (whole number only).\\n";
                }
                if (temp != 0)
                {
                    if ((int.Parse(CompetitiveAdv.Text)) < 0 || (int.Parse(CompetitiveAdv.Text)) > 100)
                    {
                        errorList += "- Competitive advantage must be a whole number between 1 - 99.\\n";
                    }
                }
                // get other required data
                byte competitiveAdvantage = byte.Parse(CompetitiveAdv.Text);
                string entReqDetail       = EntReqDetail.Text;

                DiplomaCertificate diploma = new DiplomaCertificate();

                // Populate a new diploma
                diploma.ProgramName               = programName;
                diploma.ProgramLink               = programLink;
                diploma.ProgramLength             = programLength;
                diploma.Activated                 = activated;
                diploma.WorkOutdoors              = workOutdoors;
                diploma.WorkTravel                = travel;
                diploma.ShiftWork                 = shiftWork;
                diploma.CategoryID                = categoryID;
                diploma.CredentialType            = true;
                diploma.CompetitveAdvantage       = competitiveAdvantage;
                diploma.EntranceRequirementDetail = entReqDetail;

                // Make a list for entering entrance requirement information
                List <EntranceRequirementList> entranceReqList = new List <EntranceRequirementList>();


                if (ShowCoursesView.Checked)
                {
                    // Gather data from course gridview for processing items
                    foreach (GridViewRow row in Course_Gridview.Rows)
                    {
                        // Find controls in the Gridview
                        //Po
                        int courseID = int.Parse((row.FindControl("CourseList") as DropDownList).SelectedValue);
                        byte mark;
                        result = byte.TryParse(((row.FindControl("EnterMark") as TextBox).Text.Trim()), out mark);
                        if (!result)
                        {
                            errorList += "- Marks entered must be numeric values (whole numbers greater than 0). \\n";
                        }
                        if (mark > 100 || mark < 0)
                        {
                            errorList += "- Marks entered must whole numbers between 1 - 99. \\n";
                        }

                        entranceReqList.Add(new EntranceRequirementList()
                        {
                            CourseID = courseID,
                            Mark     = mark
                        });
                    }
                }
                List <int> courseIds = new List <int>();
                foreach (EntranceRequirementList item in entranceReqList)
                {
                    courseIds.Add(item.CourseID);
                }

                courseIds.Sort();
                int index = 0;
                bool flag = true;
                while (index < entranceReqList.Count - 1 && flag == true)
                {
                    if (courseIds[index] == courseIds[index + 1])
                    {
                        errorList += "- Courses in entrance requirements cannot appear more than once.\\n";
                        flag       = false;
                    }
                    else
                    {
                        index++;
                    }
                }

                int numOfRows        = DegreeList_GridView.Rows.Count;
                List <int> degreeIDs = new List <int>();
                if (numOfRows != 0)
                {
                    //gather data from the degree pathway gridview for processing
                    foreach (GridViewRow row in DegreeList_GridView.Rows)
                    {
                        // Find controls in the Gridview
                        int degreeID = int.Parse((row.FindControl("DegreeList") as DropDownList).SelectedValue);
                        if (degreeID != 0)
                        {
                            degreeIDs.Add(degreeID);
                        }
                    }
                }

                degreeIDs.Sort();
                bool flagDeg = true;
                while (index < degreeIDs.Count - 1 && flagDeg == true)
                {
                    if (degreeIDs[index] == degreeIDs[index + 1])
                    {
                        errorList += "- Degree pathways cannot appear more than once.\\n";
                        flagDeg    = false;
                    }
                    else
                    {
                        index++;
                    }
                }

                if (errorList != "")
                {
                    throw new Exception(errorList);
                }

                //Insert the entry
                controller.InsertDiplomaProgram(diploma, entranceReqList, degreeIDs);
                ClearFields();
                Response.Write("<script type=\"text/javascript\">alert('Entry has been inserted.');</script>");
                //Hide panels
                ShowCoursesView.Checked = false;
                ShowDipPathView.Checked = false;
                ShowDegPathView.Checked = false;
                entrance_req.Visible    = false;
                degree_link.Visible     = false;
                degree_pathways.Visible = false;
            }

            if (credentialType == "Certificate")
            {
                //verify the URL does not exist
                checkURL = controller.CheckDipCertUrl(programLink);
                if (checkURL == false)
                {
                    errorList += "- The url selected currently exists in the system, and cannot be repeated.\\n";
                }
                //validate field length
                if (EntReqDetail.Text.Length > 150)
                {
                    errorList += "- Entrance Requirement Details cannot exceed 150 characters. \\n";
                }
                byte competitiveAdvantage;
                //Po
                result = byte.TryParse(CompetitiveAdv.Text.Trim(), out competitiveAdvantage);
                if (!result)
                {
                    errorList += "- Please enter a numeric value into the competitive advantage field (whole numbers greater than zero only).\\n";
                }

                if (competitiveAdvantage < 0 || competitiveAdvantage > 100)
                {
                    errorList += "- Please enter a numeric value between 1 - 99. \\n";
                }
                //check coompetitive advantage
                //po
                result = int.TryParse(CompetitiveAdv.Text.Trim(), out temp);
                if (!result)
                {
                    errorList += "- Please enter a numeric value into the competitive advantage field (whole number only).\\n";
                }
                if (temp != 0)
                {
                    if ((int.Parse(CompetitiveAdv.Text)) < 0 || (int.Parse(CompetitiveAdv.Text)) > 100)
                    {
                        errorList += "- Competitive advantage must be a whole number between 1 - 99.\\n";
                    }
                }
                string entReqDetail = EntReqDetail.Text;


                DiplomaCertificate certificate = new DiplomaCertificate();
                // Populate a new certificate
                certificate.ProgramName               = programName;
                certificate.ProgramLink               = programLink;
                certificate.ProgramLength             = programLength;
                certificate.Activated                 = activated;
                certificate.WorkOutdoors              = workOutdoors;
                certificate.WorkTravel                = travel;
                certificate.ShiftWork                 = shiftWork;
                certificate.CategoryID                = categoryID;
                certificate.CredentialType            = false;
                certificate.CompetitveAdvantage       = competitiveAdvantage;
                certificate.EntranceRequirementDetail = entReqDetail;

                // Make a list for entering entrance requirement information
                List <EntranceRequirementList> entranceReqList = new List <EntranceRequirementList>();
                if (ShowCoursesView.Checked)
                {
                    // Gather data from course gridview for processing items
                    foreach (GridViewRow row in Course_Gridview.Rows)
                    {
                        // Find controls in the Gridview
                        int courseID = int.Parse((row.FindControl("CourseList") as DropDownList).SelectedValue);
                        byte mark;
                        result = byte.TryParse(((row.FindControl("EnterMark") as TextBox).Text.Trim()), out mark);
                        if (!result)
                        {
                            errorList += "- Marks entered must be numeric values (whole numbers greater than 0). \\n";
                        }
                        if (mark > 100 || mark < 0)
                        {
                            errorList += "- Marks entered must whole numbers between 1 - 99. \\n";
                        }

                        entranceReqList.Add(new EntranceRequirementList()
                        {
                            CourseID = courseID,
                            Mark     = mark
                        });
                    }
                    List <int> courseIds = new List <int>();
                    foreach (EntranceRequirementList item in entranceReqList)
                    {
                        courseIds.Add(item.CourseID);
                    }

                    courseIds.Sort();
                    int index = 0;
                    bool flag = true;
                    while (index < entranceReqList.Count - 1 && flag == true)
                    {
                        if (courseIds[index] == courseIds[index + 1])
                        {
                            errorList += "- Courses in entrance requirements cannot appear more than once.\\n";
                            flag       = false;
                        }
                        else
                        {
                            index++;
                        }
                    }
                }

                if (errorList != "")
                {
                    throw new Exception(errorList);
                }

                //Insert the entry
                controller.InsertCertificateProgram(certificate, entranceReqList);
                ClearFields();
                Response.Write("<script type=\"text/javascript\">alert('Entry has been inserted.');</script>");
                //Hide panels
                ShowCoursesView.Checked = false;
                ShowDipPathView.Checked = false;
                ShowDegPathView.Checked = false;
                entrance_req.Visible    = false;
                degree_link.Visible     = false;
                degree_pathways.Visible = false;
            }
        });
    }
Esempio n. 2
0
    protected void SubmitProgram_Click(object sender, EventArgs e)
    {
        MessageUserControl.TryRun(() =>
        {
            // BUILD OBJECTS AND UPDATE BASED ON PROGRAM TYPE

            //Declare variables for error handling
            Uri tempUrl;
            int temp;
            string errorList = "";

            if (InitialCredential.SelectedValue == "Certificate")
            {
                //Validate non-string variables
                //Po
                bool result = int.TryParse(ProgramLength.Text.Trim(), out temp);
                if (!result)
                {
                    errorList += "- Please enter a numeric value into the program length field (whole number only). \\n";
                }
                if (temp != 0)
                {
                    //Po
                    if ((int.Parse(ProgramLength.Text.Trim())) < 0 || (int.Parse(ProgramLength.Text.Trim())) > 100)
                    {
                        errorList += "- Program length must be a whole number between 1 - 99. \\n";
                    }
                }
                //Validate URL
                //Po
                result = Uri.TryCreate(ProgramLink.Text.Trim(), UriKind.Absolute, out tempUrl) && tempUrl.Scheme == Uri.UriSchemeHttp;
                if (!result)
                {
                    errorList += "- Please enter a properly formatted URL (ex. http://www.example.com). \\n";
                }
                PathwaysController controller = new PathwaysController();



                //verify the URL does not exist
                if (ProgramLinkCompare.Value != ProgramLink.Text.Trim())
                {
                    //Po
                    bool checkURL = controller.CheckDipCertUrl(ProgramLink.Text.Trim());
                    if (checkURL == false)
                    {
                        errorList += "- The url selected currently exists in the system, and cannot be repeated.\\n";
                    }
                }

                //verify the name does not exist
                //Po
                if (ProgramNameCompare.Value != ProgramName.Text.Trim())
                {
                    //Po
                    bool checkName = controller.CheckProgramName(ProgramName.Text.Trim());
                    if (checkName == false)
                    {
                        errorList += "- The Program Name selected currently exists in the system, and cannot be repeated.\\n";
                    }
                }

                //Validate field lengths
                if (ProgramName.Text.Trim().Length > 100)
                {
                    errorList += "- Program Name cannot exceed 100 characters. \\n";
                }

                if (ProgramLink.Text.Trim().Length > 150)
                {
                    errorList += "- Program Link cannot exceed 150 characters. \\n";
                }
                //validate field length
                if (EntReqDetail.Text.Trim().Length > 150)
                {
                    errorList += "- Entrance Requirement Details cannot exceed 150 characters. \\n";
                }

                byte competitiveAdvantage;
                result = byte.TryParse(CompetitiveAdv.Text.Trim(), out competitiveAdvantage);
                if (!result)
                {
                    errorList += "- Please enter a numeric value into the competitive advantage field (whole numbers greater than zero only). \\n";
                }

                if (competitiveAdvantage < 0 || competitiveAdvantage > 100)
                {
                    errorList += "- Please enter a numeric value between 1 - 99. \\n";
                }

                //populate certificate
                DiplomaCertificate certificate = new DiplomaCertificate()
                {
                    ProgramID                 = int.Parse(ProgramID.Text),
                    ProgramName               = ProgramName.Text.Trim(),
                    ProgramLength             = ProgramLength.Text.Trim() + " " + ProgramLengthDDL.SelectedValue,
                    EntranceRequirementDetail = EntReqDetail.Text,
                    CompetitveAdvantage       = competitiveAdvantage,
                    ProgramLink               = ProgramLink.Text.Trim(),
                    Activated                 = Activated.Checked,
                    WorkOutdoors              = WorkOutdoors.Checked,
                    ShiftWork                 = ShiftWork.Checked,
                    WorkTravel                = Travel.Checked,
                    CredentialType            = false,
                    CategoryID                = int.Parse(CategoryList.SelectedValue)
                };
                if (errorList != "")
                {
                    throw new Exception(errorList);
                }
                //process update
                // PathwaysController controller = new PathwaysController();
                controller.CertDiploma_Update(certificate);
                Clear_Click();
                Response.Write("<script type=\"text/javascript\">alert('The selected Certificate program has been updated.');</script>");
            }
            else if (InitialCredential.SelectedValue == "Diploma")
            {
                //Validate non-string variables
                bool result = int.TryParse(ProgramLength.Text.Trim(), out temp);
                if (!result)
                {
                    errorList += "- Please enter a numeric value into the program length field (whole number only). \\n";
                }
                if (temp != 0)
                {
                    if ((int.Parse(ProgramLength.Text)) < 0 || (int.Parse(ProgramLength.Text)) > 100)
                    {
                        errorList += "- Program length must be a whole number between 1 - 99. \\n";
                    }
                }
                //Validate URL
                result = Uri.TryCreate(ProgramLink.Text.Trim(), UriKind.Absolute, out tempUrl) && tempUrl.Scheme == Uri.UriSchemeHttp;
                if (!result)
                {
                    errorList += "- Please enter a properly formatted URL (ex. http://www.example.com). \\n";
                }
                PathwaysController controller = new PathwaysController();

                //verify the URL does not exist
                if (ProgramLinkCompare.Value != ProgramLink.Text.Trim())
                {
                    bool checkURL = controller.CheckDipCertUrl(ProgramLink.Text.Trim());
                    if (checkURL == false)
                    {
                        errorList += "- The url selected currently exists in the system, and cannot be repeated.\\n";
                    }
                }

                //verify the name does not exist
                if (ProgramNameCompare.Value != ProgramName.Text.Trim())
                {
                    bool checkName = controller.CheckProgramName(ProgramName.Text.Trim());
                    if (checkName == false)
                    {
                        errorList += "- The Program Name selected currently exists in the system, and cannot be repeated.\\n";
                    }
                }

                //Validate field lengths
                if (ProgramName.Text.Trim().Length > 100)
                {
                    errorList += "- Program Name cannot exceed 100 characters. \\n";
                }

                if (ProgramLink.Text.Trim().Length > 150)
                {
                    errorList += "- Program Link cannot exceed 150 characters. \\n";
                }
                //validate field length
                if (EntReqDetail.Text.Trim().Length > 150)
                {
                    errorList += "- Entrance Requirement Details cannot exceed 150 characters. \\n";
                }

                byte competitiveAdvantage;
                result = byte.TryParse(CompetitiveAdv.Text.Trim(), out competitiveAdvantage);
                if (!result)
                {
                    errorList += "- Please enter a numeric value into the competitive advantage field (whole numbers greater than zero only). \\n";
                }

                if (competitiveAdvantage < 0 || competitiveAdvantage > 100)
                {
                    errorList += "- Please enter a numeric value between 1 - 99. \\n";
                }

                //populate diploma
                DiplomaCertificate diploma = new DiplomaCertificate()
                {
                    ProgramID                 = int.Parse(ProgramID.Text),
                    ProgramName               = ProgramName.Text.Trim(),
                    ProgramLength             = ProgramLength.Text.Trim() + " " + ProgramLengthDDL.SelectedValue,
                    EntranceRequirementDetail = EntReqDetail.Text.Trim(),
                    CompetitveAdvantage       = competitiveAdvantage,
                    ProgramLink               = ProgramLink.Text.Trim(),
                    Activated                 = Activated.Checked,
                    WorkOutdoors              = WorkOutdoors.Checked,
                    ShiftWork                 = ShiftWork.Checked,
                    WorkTravel                = Travel.Checked,
                    CredentialType            = true,
                    CategoryID                = int.Parse(CategoryList.SelectedValue)
                };
                if (errorList != "")
                {
                    throw new Exception(errorList);
                }
                //process update
                //PathwaysController controller = new PathwaysController();
                controller.CertDiploma_Update(diploma);
                Clear_Click();
                Response.Write("<script type=\"text/javascript\">alert('The selected Diploma program has been updated.');</script>");
            }
            else if (InitialCredential.SelectedValue == "Degree")
            {
                //Validate non-string variables
                bool result = int.TryParse(ProgramLength.Text.Trim(), out temp);
                if (!result)
                {
                    errorList += "- Please enter a numeric value into the program length field (whole number only). \\n";
                }
                if (temp != 0)
                {
                    if ((int.Parse(ProgramLength.Text.Trim())) < 0 || (int.Parse(ProgramLength.Text)) > 100)
                    {
                        errorList += "- Program length must be a whole number between 1 - 99. \\n";
                    }
                }
                //Validate URL
                result = Uri.TryCreate(ProgramLink.Text.Trim(), UriKind.Absolute, out tempUrl) && tempUrl.Scheme == Uri.UriSchemeHttp;
                if (!result)
                {
                    errorList += "- Please enter a properly formatted URL (ex. http://www.example.com). \\n";
                }

                PathwaysController controller = new PathwaysController();
                if (ProgramLinkCompare.Value != ProgramLink.Text.Trim())
                {
                    //verify the URL does not exist
                    bool checkURL = controller.CheckDegUrl(ProgramLink.Text.Trim());
                    if (checkURL == false)
                    {
                        errorList += "- The url selected currently exists in the system, and cannot be repeated.\\n";
                    }
                }

                //verify the name does not exist
                if (ProgramNameCompare.Value != ProgramName.Text.Trim())
                {
                    bool checkName = controller.CheckProgramName(ProgramName.Text.Trim());
                    if (checkName == false)
                    {
                        errorList += "- The Program Name selected currently exists in the system, and cannot be repeated.\\n";
                    }
                }

                //Validate field lengths
                if (ProgramName.Text.Trim().Length > 100)
                {
                    errorList += "- Program Name cannot exceed 100 characters. \\n";
                }

                if (ProgramLink.Text.Trim().Length > 150)
                {
                    errorList += "- Program Link cannot exceed 150 characters. \\n";
                }

                //populate degree
                Degree degree = new Degree()
                {
                    DegreeID     = int.Parse(ProgramID.Text),
                    DegreeName   = ProgramName.Text.Trim(),
                    DegreeLength = ProgramLength.Text.Trim() + " " + ProgramLengthDDL.SelectedValue,
                    DegreeLink   = ProgramLink.Text.Trim(),
                    Activated    = Activated.Checked,
                    WorkOutdoors = WorkOutdoors.Checked,
                    ShiftWork    = ShiftWork.Checked,
                    WorkTravel   = Travel.Checked,
                    CategoryID   = int.Parse(CategoryList.SelectedValue)
                };

                if (errorList != "")
                {
                    throw new Exception(errorList);
                }
                //process update
                //PathwaysController controller = new PathwaysController();
                controller.Degree_Update(degree);
                Clear_Click();
                Response.Write("<script type=\"text/javascript\">alert('The selected Degree program has been updated.');</script>");
            }
            else
            {
            }
        });
    }