Beispiel #1
0
 public void TestFrFRUpperCaseCharacter()
 {
     char ch = 'G';
     char expectedChar = 'g';
     TextInfo textInfo = new CultureInfo("fr-FR").TextInfo;
     char actualChar = textInfo.ToLower(ch);
     Assert.Equal(expectedChar, actualChar);
 }
Beispiel #2
0
        public void TestEnUSLowercaseCharacter()
        {
            char ch = 'a';
            char expectedChar = ch;
            TextInfo textInfo = new CultureInfo("en-US").TextInfo;

            char actualChar = textInfo.ToLower(ch);
            Assert.Equal(expectedChar, actualChar);
        }
Beispiel #3
0
        /// <summary>
        /// Prompts the user for a standard input (AKA console) input to whether they wish to enter a middle name or not
        /// </summary>
        private void checkMiddle()
        {
            TextInfo ti = new CultureInfo("en-US", false).TextInfo;

            Console.WriteLine("Do you have a middle name? [Y/N]");
            if (String.Compare(ti.ToLower(readString()), "y") == 0)
                hasMiddle = true;
            else
                hasMiddle = false;
        }
Beispiel #4
0
        public void TestNonAlphabeticCharacter()
        {
            for (int i = 0; i <= 9; i++)
            {
                char ch = Convert.ToChar(i);
                char expectedChar = ch;
                TextInfo textInfo = new CultureInfo("en-US").TextInfo;

                char actualChar = textInfo.ToLower(ch);
                Assert.Equal(expectedChar, actualChar);
            }
        }
        public static String toProper(String columnString) {

            // Creates a TextInfo object from which the method will apply the casing rules
            var myTI = new CultureInfo("en-US", false).TextInfo;

            // Constructs the proper cased string
            var retval = myTI.ToTitleCase(myTI.ToLower(columnString));

            // Returns the String to the caller
            return retval;

        } // End of Method declaration
Beispiel #6
0
        public void TestTrTRUppercaseCharacter()
        {
            char ch = '\u0130';
            char expectedChar = 'i';
            TextInfo textInfo = new CultureInfo("tr-TR").TextInfo;

            char actualChar = textInfo.ToLower(ch);
            Assert.Equal(expectedChar, actualChar);

            ch = 'I';
            expectedChar = '\u0131';
            actualChar = textInfo.ToLower(ch);
            Assert.Equal(expectedChar, actualChar);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            string usernameCookie = "";

            if (Request.Cookies["user"] != null)
            { //If cookie exist, get username
                
                HttpCookie getUserCookie = Request.Cookies["user"];

                usernameCookie = getUserCookie.Values["username"];
                string userType = getUserCookie.Values["usertype"];

                switch (userType)
                {
                    case "s":
                        userProfileHomeID.Attributes["href"] = String.Format("UserProfile.aspx");
                        break;

                    case "r":
                        userProfileHomeID.Attributes["href"] = String.Format("ReviewerProfile.aspx");
                        break;

                    case "a":
                        userProfileHomeID.Attributes["href"] = String.Format("Admin_Dashboard_Main.aspx");
                        break;
                }
            }
            else
            {
                Response.Redirect("A_Login.aspx");
            }


            string firstName = "";
            string lastName = "";
            string finalFirstName = "";
            string finalLastName = "";
            string finalFullName = "";
            string emailAddress = "";
            string finalEmailAddress = "";
            string collegeDepartment = "";
            string finalCollegeDepartment = "";
            string username = usernameCookie;
            string picFileName = "";

            //username = Request.QueryString["u.username"];



            string connectionString;
            connectionString = ConfigurationManager.ConnectionStrings["ConnectionStringLocalDB"].ConnectionString;
            using (SqlConnection connection = new SqlConnection(connectionString)) {
                using (SqlCommand command = connection.CreateCommand()) { 
                    command.CommandText=
                        "SELECT "+
                        "First_Name, "+
                        "Last_Name, "+
                        "College_Dept, "+
                        "Email, " +
                        "Comment_Box " +
                        "FROM "+
                        "dbo.USERS "+
                        "WHERE username = @usernameDB";
                    command.Parameters.AddWithValue("@usernameDB", username);
                    try
                    {
                        connection.Open();
                        SqlDataReader reader = command.ExecuteReader();
                        if (reader.HasRows) {
                            while (reader.Read()) {
                                firstName = reader.GetString(0);
                                lastName = reader.GetString(1);
                                collegeDepartment = reader.GetString(2);
                                emailAddress = reader.GetString(3);
                                picFileName = reader.GetString(4);

                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }

                    finally
                    {
                        connection.Close();
                    }
                }
            }

            //Define object to make string proper case
            TextInfo titleCase = new CultureInfo("en-US", false).TextInfo;

            finalFirstName = titleCase.ToTitleCase(firstName.ToLower());
            finalLastName = titleCase.ToTitleCase(lastName);
            finalFullName = finalFirstName + " " + finalLastName;
            finalEmailAddress = titleCase.ToLower(emailAddress);
            reviewerUserID.Text = finalFirstName + " " + finalLastName;
            profileNameID.Text = finalFullName;
            departmentID.Text = collegeDepartment;
            useremailID.Text = finalEmailAddress;
            
            profPic.InnerHtml = "<img class='userProfileImageBorder' src='UploadImage/" + picFileName + "'></img>"; ;

            SqlDataSource1.SelectCommand="select username, Project_ID , Project_Name , Course_ID from FILES "+ 
                                            "WHERE "+ 
                                            "Comm_Name in "+
                                            "(select First_Name+' '+Last_Name from USERS WHERE username='******') OR "+
                                            "Chair_Name in "+
                                            "(select First_Name+' '+Last_Name from USERS WHERE username='******')";
        }
Beispiel #8
0
        /// <summary>
        /// Utilises CultureInfo to detect which part of the name the user is attempting to input, as well as resolving any issues with case.
        /// </summary>
        /// <param name="control">Switch info: 1 = First Name, 2 = Middle Name (if applicable), 3 = Surname</param>
        /// <returns>-1 on failure</returns>
        private int getName(int control)
        {
            if (control < 0 || control > 3)
                return -1;

            TextInfo ti = new CultureInfo("en-US", false).TextInfo;

            switch (control)
            {
                case 1:
                    {
                        Console.WriteLine("Please enter your first name: ");
                        first = ti.ToTitleCase(ti.ToLower(readString()));
                        return 0;
                    } // 1
                case 2:
                    {
                        Console.WriteLine("Please enter your middle name/s: ");
                        middle = ti.ToTitleCase(ti.ToLower(readString()));
                        return 0;
                    } // 2
                case 3:
                    {
                        Console.WriteLine("Please enter your surname: ");
                        surname = ti.ToTitleCase(ti.ToLower(readString()));
                        return 0;
                    } // 3
                default:
                    return -1;
            } // switch
        }
        //Made Changes Here

        protected void Page_Load(object sender, EventArgs e) {
                string cookieUsername = "";
                string userPasswordFromCookie = "";
                
                if (Request.Cookies["user"] != null) { //If cookie exist, get username
                    HttpCookie getUserCookie = Request.Cookies["user"];
                    cookieUsername = getUserCookie.Values["username"];
                    userPasswordFromCookie = getUserCookie.Values["userpassword"];

                    string userType = getUserCookie.Values["usertype"];

                    switch (userType)
                    {
                        case "s":
                            userProfileHomeID.Attributes["href"] = String.Format("UserProfile.aspx");
                            break;

                        case "r":
                            userProfileHomeID.Attributes["href"] = String.Format("ReviewerProfile.aspx");
                            break;

                        case "a":
                            userProfileHomeID.Attributes["href"] = String.Format("Admin_Dashboard_Main.aspx");
                            break;

                    }
                }
                else {
                    Response.Redirect("A_Login.aspx");
                }


                //Arrive from search page
                if (!String.IsNullOrEmpty(Request.QueryString["usernameFromSearch"]))
                {
                    cookieUsername = Request.QueryString["usernameFromSearch"];    
                }
                


                string connectionString = 
                ConfigurationManager.ConnectionStrings["ConnectionStringLocalDB"].ConnectionString;

                string UserUsernameDB = "";
                string UserFirst_NameDB = "";
                string UserLast_NameDB = "";
                string UserEmailDB = "";
                string UserSecurity_QuestionDB = "";
                string UserSecurity_AnswerDB = "";
                string UserAcct_ReasonDB = "";
                string UserSemester_CompletionDB = "";
                DateTime UserAccount_DateDB = DateTime.Now;
                int UserProgress_BarDB = 0;
                string UserComment_BoxDB = "";
                string UserComment_StatusDB = "";
                string UserReviewer_CommentsDB = "";
                string UserCollege_DeptDB = "";

                string LoginUsername = "";
                string LoginUserpassword = "";
                string LoginUser_Type = "";
                int Login_Count;
                DateTime Last_Login = DateTime.Now;
                string Approve_Status = "";

                string Filesusername = "";
                string FilesProject_ID = "";
                string FilesProject_Name = "";
                string FilesCourse_ID = "";
                string FilesKeyword1 = "";
                string FilesKeyword2 = "";
                string FilesKeyword3 = "";
                string FilesAbstract = "";
                string FilesLive_Link = "";
                string FilesVideo_Link = "";
                string FilesChair_Name = "";
                string FilesChair_Email = "";
                string FilesComm_Name = "";
                string FilesComm_Email = "";
                string FilesGadvisor_Name = "";
                string FilesGadvisor_Email = "";
                DateTime FilesUpload_Date = DateTime.Now;
                string FilesReject_Reason = "";
                int FilesNum_Views = 0;
                int FilesNum_Dloads = 0;
                string FilesPic_File = "";
                string FilesProj_Pdf_File = "";
                string FilesProj_Zip_File = "";
                string FilesPres_Date = "";
                int FilesDislike_Count = 0;
                int FilesLike_Count = 0;
                string FilesApproval_Status1 = "";
                string FilesApproval_Status2 = "";
                string FilesApproval_Status3 = "";
                string FilesReviewer_Comment1 = "";
                string FilesReviewer_Comment2 = "";
                string FilesReviewer_Comment3 = "";
                string finalCommitteeMemberName = "";
                string finalCommitteeChairName = "";
                string finalAdvisorName = "";
                using (SqlConnection connection = new SqlConnection(connectionString)) {
                    using (SqlCommand command = connection.CreateCommand()) {
                        command.CommandText =
                            "SELECT " +
                                "u.username, " +
                                "u.First_Name, " +
                                "u.Last_Name, " +
                                "u.Email, " +
                                "u.Security_Question, " +
                                "u.Security_Answer, " +
                                "u.Acct_Reason, " +
                                "u.Semester_Completion, " +
                                "u.Account_Date, " +
                                "u.Progress_Bar, " +
                                "u.Comment_Box, " +
                                "u.Comment_Status, " +
                                "u.Reviewer_Comments, " +
                                "u.College_Dept, " + 

                                "l.username, " +
                                "l.userpassword, " +
                                "l.User_Type, " +
                                "l.Login_Count, " +
                                "l.Last_Login, " +
                                "l.Approve_Status, " +

                                "f.username, " +
                                "f.Project_ID, " +
                                "f.Project_Name, " +
                                "f.Course_ID, " +
                                "f.Keyword1, " +
                                "f.Keyword2, " +
                                "f.Keyword3, " +
                                "f.Abstract, " +
                                "f.Live_Link, " +
                                "f.Video_Link, " +
                                "f.Chair_Name, " +
                                "f.Chair_Email, " +
                                "f.Comm_Name, " +
                                "f.Comm_Email, " +
                                "f.Gadvisor_Name, " +
                                "f.Gadvisor_Email, " +
                                "f.Upload_Date, " +
                                "f.Reject_Reason, " +
                                "f.Num_Views, " +
                                "f.Num_Dloads, " +
                                "f.Pic_File, " +
                                "f.Proj_Pdf_File, " +
                                "f.Proj_Zip_File, " +
                                "f.Pres_Date, " +
                                "f.Dislike_Count, " +
                                "f.Like_Count, " +
                                "f.Approval_Status1, " +
                                "f.Approval_Status2, " +
                                "f.Approval_Status3, " +
                                "f.Reviewer_Comment1, " +
                                "f.Reviewer_Comment2, " +
                                "f.Reviewer_Comment3 " +
                            "FROM " +
                            "dbo.USERS u JOIN dbo.LOGIN l " +
                                "ON u.username=l.username " +
                            "JOIN dbo.FILES f " +
                                "ON l.username=f.username " +
                            "WHERE u.username = @usernameDB";

                        command.Parameters.AddWithValue("@usernameDB", cookieUsername);
                        try {
                            connection.Open();
                            SqlDataReader reader = command.ExecuteReader();

                            if (reader.HasRows) {
                                while (reader.Read()) {
                                    UserUsernameDB = reader.GetString(0);
                                    UserFirst_NameDB = reader.GetString(1);
                                    UserLast_NameDB = reader.GetString(2);
                                    UserEmailDB = reader.GetString(3);
                                    UserSecurity_QuestionDB = reader.GetString(4);
                                    UserSecurity_AnswerDB = reader.GetString(5);
                                    UserAcct_ReasonDB = reader.GetString(6);
                                    UserSemester_CompletionDB = reader.GetString(7);
                                    UserAccount_DateDB = reader.GetDateTime(8);
                                    UserProgress_BarDB = reader.GetInt32(9);
                                    UserComment_BoxDB = reader.GetString(10);
                                    UserComment_StatusDB = reader.GetString(11);
                                    UserReviewer_CommentsDB = reader.GetString(12);
                                    UserCollege_DeptDB = reader.GetString(13);

                                    LoginUsername = reader.GetString(14);
                                    LoginUserpassword = reader.GetString(15);
                                    LoginUser_Type = reader.GetString(16);
                                    Login_Count = reader.GetInt32(17);
                                    Last_Login = reader.GetDateTime(18);
                                    Approve_Status = reader.GetString(19);

                                    Filesusername = reader.GetString(20);
                                    FilesProject_ID = reader.GetString(21);
                                    FilesProject_Name = reader.GetString(22);
                                    FilesCourse_ID = reader.GetString(23);
                                    FilesKeyword1 = reader.GetString(24);
                                    FilesKeyword2 = reader.GetString(25);
                                    FilesKeyword3 = reader.GetString(26);
                                    FilesAbstract = reader.GetString(27);
                                    FilesLive_Link = reader.GetString(28);
                                    FilesVideo_Link = reader.GetString(29);
                                    FilesChair_Name = reader.GetString(30);
                                    FilesChair_Email = reader.GetString(31);
                                    FilesComm_Name = reader.GetString(32);
                                    FilesComm_Email = reader.GetString(33);
                                    FilesGadvisor_Name = reader.GetString(34);
                                    FilesGadvisor_Email = reader.GetString(35);
                                    FilesUpload_Date = reader.GetDateTime(36);
                                    FilesReject_Reason = reader.GetString(37);
                                    FilesNum_Views = reader.GetInt32(38);
                                    FilesNum_Dloads = reader.GetInt32(39);
                                    FilesPic_File = reader.GetString(40);
                                    FilesProj_Pdf_File = reader.GetString(41);
                                    FilesProj_Zip_File = reader.GetString(42);
                                    FilesPres_Date = reader.GetString(43);
                                    FilesDislike_Count = reader.GetInt32(44);
                                    FilesLike_Count = reader.GetInt32(45);
                                    FilesApproval_Status1 = reader.GetString(46);
                                    FilesApproval_Status2 = reader.GetString(47);
                                    FilesApproval_Status3 = reader.GetString(48);
                                    FilesReviewer_Comment1 = reader.GetString(49);
                                    FilesReviewer_Comment2 = reader.GetString(50);
                                    FilesReviewer_Comment3 = reader.GetString(51);
                                }
                            }
                        }
                        catch (Exception ex) {
                            Console.WriteLine(ex.Message);
                        }
                    } //End SqlCommand
                } //End SqlConnection

                //Define object to make string proper case
                TextInfo titleCase = new CultureInfo("en-US", false).TextInfo;

                rejectID.Text = FilesReviewer_Comment1 + "  " + FilesReviewer_Comment2 + "  " + FilesReviewer_Comment3;
                commentSectionID.Text = UserComment_BoxDB;
                finalAdvisorName = titleCase.ToTitleCase(FilesGadvisor_Name);
                finalCommitteeChairName = titleCase.ToTitleCase(FilesChair_Name);
                finalCommitteeMemberName = titleCase.ToTitleCase(FilesComm_Name); 
                string firstNameProperCase = titleCase.ToTitleCase(UserFirst_NameDB.ToLower());
                string lastNameProperCase = titleCase.ToTitleCase(UserLast_NameDB);
                presentationDateID.Text = FilesPres_Date;
                headerUserNameID.Text = firstNameProperCase + " " + lastNameProperCase;
                FullNameLabel.Text = titleCase.ToTitleCase(UserFirst_NameDB.ToLower()) + " " + titleCase.ToTitleCase(UserLast_NameDB.ToLower());
                
                LastLoginLabel.Text = Last_Login.ToString("G");
                CourseNumberLabel.Text = FilesCourse_ID;
                DepartmentLabel.Text = UserCollege_DeptDB;
                SemesterCompletedLabel.Text = UserSemester_CompletionDB;
                EmailLabel.Text = titleCase.ToLower(UserEmailDB);
                
                AccountCreatedDateLabel.Text = UserAccount_DateDB.ToString("G");
                AccountReasonLabel.Text = titleCase.ToTitleCase(UserAcct_ReasonDB);

                string statusString = "";
                if (Approve_Status == "y") {
                    statusString = "Approved";
                }
                else {
                    statusString = "Not Approved";
                }

                AccountApprovedLabel.Text = statusString;
                
                firstNameId.Text = titleCase.ToTitleCase(UserFirst_NameDB);
                lastNameId.Text = titleCase.ToTitleCase(UserLast_NameDB);
                userNameId.Text = UserUsernameDB;
                passwordId.Attributes.Add("value", userPasswordFromCookie);

                emailId.Text = UserEmailDB;
                securityQuestionID.Text = UserSecurity_QuestionDB;
                securityAnswerID.Text = UserSecurity_AnswerDB;

                keyword1Id.Text = titleCase.ToTitleCase(FilesKeyword1);
                keyword2Id.Text = titleCase.ToTitleCase(FilesKeyword2);
                keyword3Id.Text = titleCase.ToTitleCase(FilesKeyword3);

                liveLinkId.Text = titleCase.ToLower(FilesLive_Link);
                videoLinkId.Text = titleCase.ToLower(FilesVideo_Link);
                
                researchNameLabel.Text = FilesProject_Name;
                abstractID.Text = titleCase.ToLower(FilesAbstract);
                
                if (FilesLive_Link == "") {
                    projectLiveLinkID.NavigateUrl = "";
                    string liveLinkMsg = "No LIVE URL was provided.";
                    projectLiveLinkID.Text = liveLinkMsg;
                    projectLiveLinkID.Enabled = false;

                }
                else {
                    projectLiveLinkID.NavigateUrl = FilesLive_Link;
                }
                

                if (FilesVideo_Link == "")
                {
                    projectVideoLinkID.NavigateUrl = "";
                    string videoLinkMsg = "No VIDEO URL was provided.";
                    projectVideoLinkID.Text = videoLinkMsg;
                    projectVideoLinkID.Enabled = false;

                }
                else
                {
                    projectVideoLinkID.NavigateUrl = FilesVideo_Link;
                }

                pdfDownload.NavigateUrl = "UploadPDF\\" + FilesProj_Pdf_File;
                zipDownload.NavigateUrl = "UploadZIP\\" + FilesProj_Zip_File;

                committeeChairNameID.Text = "Dr. "+finalCommitteeChairName;
                committeeChairEmailID.Text = FilesChair_Email;
                committeeMemberNameID.Text = "Dr. " + finalCommitteeMemberName;
                committeeMemberEmailID.Text = FilesComm_Email;
                graduateAdvisorNameID.Text = finalAdvisorName;
                graduateAdvisorEmailID.Text = FilesGadvisor_Email;


                userPic.InnerHtml = "<img class='userProfileImageBorder' src='UploadImage/" + FilesPic_File + "'></img>";
                
                if (UserProgress_BarDB >= 0) {
                    progressBarPanel.Visible = true;
                    submissionDeclinedPanel.Visible = false;    
                }
                else {
                    progressBarPanel.Visible = false;
                    submissionDeclinedPanel.Visible = true;    
                }

                int progressBarStart = UserProgress_BarDB;

                switch (progressBarStart) {
                    case 0:
                        progressBarInt.Style.Add("width", "10%");
                        break;
                    case 1:
                        progressBarInt.Style.Add("width", "33%");
                        break;
                    case 2:
                        progressBarInt.Style.Add("width", "66%");
                        break;
                    case 3:
                        progressBarInt.Style.Add("width", "100%");
                        break;
                }


                numberOfViewsID.Text = FilesNum_Views.ToString();
                numberOfDownloadID.Text = FilesNum_Dloads.ToString();
                likeCountID.Text = FilesLike_Count.ToString();
                dislikeCountID.Text = FilesDislike_Count.ToString();
                //commentSectionID.Text 


                invitationChairEmail = FilesChair_Email;
                inivitationCommEmail = FilesComm_Email;
                invitationAdvisorEmail = FilesGadvisor_Email;
                invitationFirstName = firstNameProperCase;
                invitationLastName = lastNameProperCase;
                invitationProjectName = FilesProject_Name;
                //Changes made here
        }
Beispiel #10
0
        private static void play()
        {
            Console.WriteLine("Would you prefer what is behind door number 1, 2, or 3?");
            int min = 1;
            int max = 4;

            // Load the random numbers
            ArrayList availableNumbers = new ArrayList();
            for (int i = min; i < max; i++)
                availableNumbers.Add(i);

            // Assign the first number to the car's door number
            int carValue = RandomNumber(min, max);
            availableNumbers.Remove(carValue);
            int boatValue = carValue;
            int catValue;
            string message;

            // Randomly search for a value for the boat's door number
            while (!availableNumbers.Contains(boatValue))
                boatValue = RandomNumber(min, max);
            availableNumbers.Remove(boatValue);

            // Assign the cat value the remaining number
            catValue = (int)availableNumbers[0];

            // DEBUG
            //Console.WriteLine(String.Format("CarValue: {0} BoatValue: {1} CatValue: {2}",carValue,boatValue,catValue));

            // Read the user input
            int userValue = readNumber(min, max);

            // The 'CatValue' variable now only holds debug purposes, due to sufficient validation on the integer input
            if (userValue == carValue)
                message = "You won a new car!";
            else if (userValue == boatValue)
                message = "You won a new boat!";
            else
                message = "You won a new cat!";

            Console.WriteLine(message);

            Console.WriteLine("Do you want to play again? [Y/N]");
            TextInfo ti = new CultureInfo("en-US", false).TextInfo;
            if (String.Compare(ti.ToLower(readString()), "y") == 0)
            {
                // Repeat
                Console.WriteLine("");
                play();
            }
            else
                // Cleanly exit
                Environment.Exit(-1);
        }
        public string_advanced_examples()
        {
            //escape sequences
            string tab = "This is a\t tab.";
            string charLiterals = "This is a\' break.";
            string newLine = "This is a\n new line.";
            string backslash = "This is a \\ backslash because otherwise it wouldn't work properly and it would throw an error.";
            string backspace = "this is a backspace \b";
            string carriageReturn = "This is a \r carriage return";

            /*-----------------------------------------------------
            * All escape sequences
            * ---------------------------------------------------*/
            //\' - single quote, needed for character literals
            //\" - double quote, needed for string literals
            //\\ - backslash
            //\0 - Unicode character 0 (ASCII)
            //\a - Alert (character 7)
            //\b - Backspace (character 8)
            //\f - Form feed (character 12)
            //\n - New line (character 10)
            //\r - Carriage return (character 13)
            //\t - Horizontal tab (character 9)
            //\v - Vertical quote (character 11)
            //\uxxxx - Unicode escape sequence for character with hex value xxxx
            //\xn[n][n][n] - Unicode escape sequence for character with hex value nnnn (variable length version of \uxxxx)
            //\Uxxxxxxxx - Unicode escape sequence for character with hex value xxxxxxxx (for generating surrogates)

            //verbatims
            //In a verbatim string literal, the characters between the delimiters are interpreted verbatim, the only exception being a quote-escape-sequence. In particular, simple escape sequences and hexadecimal and Unicode escape sequences are not processed in verbatim string literals. A verbatim string literal may span multiple lines.
            string verbatim = @"And she said, 'Johnny knows the world is cruel but he loves 'it' anyways'.";
            Console.WriteLine(verbatim);
            //verbatims appear "as-is", meaning it is cleaner and easier to program. You don't need to use escape sequences all over the place.

            //case manipulation
            Console.WriteLine("\nBegin String case manipulation\n");
            string monkey = "monKEYs aRE WILD animals.";
            Console.WriteLine("\"{0}\" string lower case: {1}", monkey, monkey.ToLower());// this should take the string and put everything in lower case.
            Console.WriteLine("\"{0}\" string upper case: {1}", monkey, monkey.ToUpper());// this should take the string and put everything in upper case.

            TextInfo ti = new CultureInfo("en-US", false).TextInfo;
            Console.WriteLine("\"{0}\" textinfo upper case: {1}", monkey, ti.ToUpper(monkey));// this should take the string and put everything in upper case.
            Console.WriteLine("\"{0}\" textinfo lower case: {1}", monkey, ti.ToLower(monkey));// this should take the string and put everything in lower case.
            Console.WriteLine("\"{0}\" textinfo titled case: {1}", monkey, ti.ToTitleCase(monkey));// this should take the string and put everything in titled case.

            string bubby = "   asdf a sdfsd  sd  f d  f f     ";
            bubby = bubby.Trim();// removes all white spaces and non-alphabetic characters.
            Console.WriteLine("The new and improved bubby is: " + bubby);

            //i have no idea what these do.
            bubby = bubby.PadLeft(17, 'a');
            Console.WriteLine(bubby);
            bubby = bubby.PadRight(5, 'u');
            Console.WriteLine(bubby);

            string attack = "Yummy people are awkward to socalize with.";
            Console.WriteLine("Length of attack var is " + attack.Length);//this returns the number of characters of the string. Cannot be invoked like Java.

            bool check = true;

            while (check == true)
            {

                if (attack.Contains(':') || attack.Contains('@') || attack.Contains('.') || attack.Contains('='))
                {
                    Console.WriteLine("A SQL injection attempt has been detected. Cleaning input now.");
                    attack = attack.Replace('.', ' ');
                    attack = attack.Replace('@', ' ');
                    attack = attack.Replace(':', ' ');
                    attack = attack.Replace('=', ' ');

                    check = true;//this type of logic could be used to check for invalid input that might be used in a SQL injection attack.
                }
                else
                {
                    Console.WriteLine("SQL injection check completed. As you were.");
                    check = false;
                }

            }

            //concationating strings
            string hank = "Hank Hill";
            string peggy = "Peggy Hill";
            string married = "are married.";
            Console.WriteLine(hank + " and " + peggy + " " + married);
            //similar way to do this:
            Console.WriteLine("{0} and {1} {2}", hank, peggy, married);// don't have to type as many pluses and "" things.

            //concatination is slow. Use the String Builder class for larger strings.
            StringBuilder sbuild = new StringBuilder();
            sbuild.Append(hank);
            sbuild.Append(" and ");
            sbuild.Append(peggy);
            sbuild.Append(" ");
            sbuild.Append(married);

            Console.WriteLine(sbuild);
            //although there is no output difference this method is more efficient.
        }
Beispiel #12
0
        // regex match evaluator for changing case
        private string MatchEvalChangeCase( Match match )
        {
            TextInfo ti = new CultureInfo( "en" ).TextInfo;

              if     ( itmChangeCaseUppercase.Checked ) return ti.ToUpper( match.Groups[1].Value );
              else if( itmChangeCaseLowercase.Checked ) return ti.ToLower( match.Groups[1].Value );
              else if( itmChangeCaseTitlecase.Checked ) return ti.ToTitleCase( match.Groups[1].Value.ToLower() );
              else                                      return match.Groups[1].Value;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Cookies["user"] != null)
            { //If cookie exist, get username
                HttpCookie getUserCookie = Request.Cookies["user"];

                string userType = getUserCookie.Values["usertype"];

                switch (userType)
                {
                    case "s":
                        userProfileHomeID.Attributes["href"] = String.Format("UserProfile.aspx");
                        break;

                    case "r":
                        userProfileHomeID.Attributes["href"] = String.Format("ReviewerProfile.aspx");
                        break;

                    case "a":
                        userProfileHomeID.Attributes["href"] = String.Format("Admin_Dashboard_Main.aspx");
                        break;
                }
            }
            else
            {
                Response.Redirect("A_Login.aspx");
            }



            string cookieUsername = "";
            string userNameToSet = "a";
            string userNameToSet2 = "a";
            string finalUsername = "";
            string finalFirstName = "";
            string finalLastName = "";
            string finalFullName = "";
            string finalEmail = "";
            string finalPicFile = "";
            string finalLiveLink = "";
            string finalVideoLink = "";
            string finalZipFile = "";
            string finalPdfFile = "";
            string courseIDNumber = "";
            string collegeDept = "";
            string firstName = "";
            string lastName = "";
            string emailAddress = "";
            string imageFile = "";
            string researchName = "";
            string abstractContent = "";
            string liveLink = "";
            string videoLink = "";
            string pdfFile = "";
            string zipFile = "";
            string userImage = "";
            string committeeChairName = "";
            string committeeMemberName = "";
            string advisorName = "";
            string committeeChairEmail = "";
            string committeeMemberEmail = "";
            string advisorEmail = "";
            string semesterCompleted = "";
            string presentationDate = "";
            string finalCommitteeMemberName = "";
            string finalCommitteeChairName = "";
            string finalAdvisorName = "";
            
            
            if (!String.IsNullOrEmpty(Request.QueryString["username"]))
            {
                userNameToSet = Request.QueryString["username"];
                finalUsername = userNameToSet;
            }

            if (!String.IsNullOrEmpty(Request.QueryString["u.username"]))
            {
                userNameToSet2 = Request.QueryString["u.username"];
                finalUsername = userNameToSet2;
            }

            
            //try
            //{
            //    if (userNameToSet.Length > 1)
            //    {
            //        finalUsername = userNameToSet;
            //    }
            //    if (userNameToSet2.Length > 1)
            //    {
            //        finalUsername = userNameToSet2;
            //    }
            //}
            ////Fit the other condition here
            //catch (Exception ex)
            //{
            //    Console.WriteLine(ex.Message);
            //}


            //if (Request.Cookies["user"] != null)
            //{ //If cookie exist, get username
            //    HttpCookie getUserCookie = Request.Cookies["user"];
            //    cookieUsername = getUserCookie.Values["username"];
            //}
            //else
            //{
            //    Response.Redirect("A_Login.aspx");
            //}
            string connectionString;
            connectionString = ConfigurationManager.ConnectionStrings["ConnectionStringLocalDB"].ConnectionString;
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                using (SqlCommand command = connection.CreateCommand())
                {
                    command.CommandText =
                        "SELECT " +
                        "First_Name, " +
                        "Last_Name, " +
                        "Email, " +
                        "Semester_Completion, " +
                        "College_Dept " +
                        "FROM " +
                        "dbo.USERS " +
                        "WHERE username = @usernameDB";
                    command.Parameters.AddWithValue("@usernameDB", finalUsername);
                    try
                    {
                        connection.Open();
                        SqlDataReader reader = command.ExecuteReader();
                        if (reader.HasRows)
                        {
                            while (reader.Read())
                            {
                                firstName = reader.GetString(0);
                                lastName = reader.GetString(1);
                                emailAddress = reader.GetString(2);
                                semesterCompleted = reader.GetString(3);
                                collegeDept = reader.GetString(4);

                            }
                        }
                    }

                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }

                    finally
                    {
                        connection.Close();
                    }
                }
            }

            connectionString =
                ConfigurationManager.ConnectionStrings["ConnectionStringLocalDB"].ConnectionString;
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                using (SqlCommand command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT " +
                        "Course_ID, " +
                        "Pic_File, " +
                        "Project_Name, " +
                        " Abstract, " +
                        "Live_Link, " +
                        "Video_Link, " +
                        "Proj_Zip_File, " +
                        "Proj_Pdf_File, " +
                        "Chair_Name, " +
                        "Chair_Email, " +
                        "Comm_Name, " +
                        "Comm_Email, " +
                        "Gadvisor_Name, " +
                        "Gadvisor_Email, " +
                        "Pres_Date " +
                        "FROM " +
                        "dbo.FILES " +
                        "WHERE username = @usernameDB";
                    command.Parameters.AddWithValue("@usernameDB", finalUsername);
                    try
                    {
                        connection.Open();
                        SqlDataReader reader = command.ExecuteReader();
                        if (reader.HasRows)
                        {
                            while (reader.Read())
                            {
                                courseIDNumber = reader.GetString(0);
                                imageFile = reader.GetString(1);
                                researchName = reader.GetString(2);
                                abstractContent = reader.GetString(3);
                                liveLink = reader.GetString(4);
                                videoLink = reader.GetString(5);
                                zipFile = reader.GetString(6);
                                pdfFile = reader.GetString(7);
                                committeeChairName = reader.GetString(8);
                                committeeChairEmail = reader.GetString(9);
                                committeeMemberName = reader.GetString(10);
                                committeeMemberEmail = reader.GetString(11);
                                advisorName = reader.GetString(12);
                                advisorEmail = reader.GetString(13);
                                presentationDate = reader.GetString(14);

                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    finally
                    {
                        connection.Close();
                    }
                }
            }

            //Define object to make string proper case
            TextInfo titleCase = new CultureInfo("en-US", false).TextInfo;

            finalAdvisorName = titleCase.ToTitleCase(advisorName);
            finalCommitteeChairName = titleCase.ToTitleCase(committeeChairName);
            finalCommitteeMemberName = titleCase.ToTitleCase(committeeMemberName); 
            finalFirstName = titleCase.ToTitleCase(firstName.ToLower());
            finalLastName = titleCase.ToTitleCase(lastName);
            finalFullName = finalFirstName + " " + finalLastName;
            finalEmail = titleCase.ToLower(emailAddress);
            finalPicFile = imageFile;
            finalLiveLink = liveLink;
            finalVideoLink = videoLink;
            finalZipFile = zipFile;
            finalPdfFile = pdfFile;

            pdfLink.NavigateUrl = "UploadPDF\\" + finalPdfFile;
            zipLink.NavigateUrl = "UploadZIP\\" + finalZipFile; 

            userHeaderNameID.Text = finalFullName;
            profileNameID.Text = finalFullName;
            courseNumberID.Text = courseIDNumber;
            departmentID.Text = collegeDept;
            semesterCompletedID.Text = semesterCompleted;
            userEmailID.Text = finalEmail;
            researchNameLabel.Text = researchName;
            abstractID.Text = abstractContent;
            projectLiveLinkID.NavigateUrl = finalLiveLink;
            projectLiveLinkID.Text = finalLiveLink;
            projectVideoLinkID.NavigateUrl = finalVideoLink;
            projectVideoLinkID.Text = finalVideoLink;
            committeeChairNameID.Text = "Dr. "+finalCommitteeChairName;
            committeeChairEmailID.Text = committeeChairEmail;
            committeeMemberNameID.Text ="Dr. "+finalCommitteeMemberName;
            committeeMemberEmailID.Text = committeeMemberEmail;
            graduateAdvisorNameID.Text = finalAdvisorName;
            graduateAdvisorEmailID.Text = advisorEmail;
            presentationDateID.Text = presentationDate;

            userPic.InnerHtml = "<img class='userProfileImageBorder' src='UploadImage/" + finalPicFile + "'></img>";
        }
 public static string ToTitleCase(this string s)
 {
     var textInfo = new CultureInfo("en-US", false).TextInfo;
     return textInfo.ToTitleCase(textInfo.ToLower(s));
 }
        public static string FormatMarketFactSourceDates(string strDate)
        {
            TextInfo myTI = new CultureInfo("en-US", false).TextInfo;
            string strFormatted = strDate;

            //REGULAR EXPRESSION MATCHES

            //Matches 3.24.02 => YYYY-MM-DD
            string re_mm_dd_yy = "^(?<Month>\\d{1,2})([./-])(?<Day>\\d{1,2})([./-])(?<Year>(?:\\d{1,2}))$";
            Regex objDatePattern1 = new Regex(re_mm_dd_yy, RegexOptions.None);
            if (objDatePattern1.IsMatch(strDate))
            {
                MatchCollection MatchArray = objDatePattern1.Matches(strDate);
                Match FirstMatch = MatchArray[0];
                string _year = FirstMatch.Groups["Year"].Value;
                string _month = FirstMatch.Groups["Month"].Value;
                string _day = FirstMatch.Groups["Day"].Value;

                Regex objIntPattern = new Regex("^\\d{1}$");
                if(objIntPattern.IsMatch(_month))
                {
                    _month = "0" + _month;
                };

                strFormatted = getYearFull(_year) + "-" + _month + "-" + _day;
            }

            //Matches SPRING 02 => Spring 2002
            string re_Season_yy = "^(?<Season>SPRING|SUMMER|FALL|WINTER)([\\s])(?<Year>\\d{1,2})$";
            Regex objDatePattern2 = new Regex(re_Season_yy, RegexOptions.None);
            if (objDatePattern2.IsMatch(strDate))
            {
                MatchCollection MatchArray = objDatePattern2.Matches(strDate);
                Match FirstMatch = MatchArray[0];
                string _season = myTI.ToLower(FirstMatch.Groups["Season"].Value);
                string _year = FirstMatch.Groups["Year"].Value;

                strFormatted = myTI.ToTitleCase(_season) + " " + getYearFull(_year);
            }

            //Matches 4.02 => April 2002
            string re_m_yy = "^(?<Month>\\d{1,2})([.])(?<Year>\\d{1,2})$";
            Regex objDatePattern3 = new Regex(re_m_yy, RegexOptions.None);
            if (objDatePattern3.IsMatch(strDate))
            {
                MatchCollection MatchArray = objDatePattern3.Matches(strDate);
                Match FirstMatch = MatchArray[0];
                string _month = FirstMatch.Groups["Month"].Value;
                string _year = FirstMatch.Groups["Year"].Value;

                strFormatted = getMonthFull(_month.TrimStart('0')) + " " + getYearFull(_year);
            }

            //Matches 1/2.02 => January/February 2002
            string re_M_M_yyyy = "^(?<Month>\\d{1,2})([/])(?<Month2>\\d{1,2})([.])(?<Year>\\d{1,2})$";
            Regex objDatePattern4 = new Regex(re_M_M_yyyy, RegexOptions.None);
            if (objDatePattern4.IsMatch(strDate))
            {
                MatchCollection MatchArray = objDatePattern4.Matches(strDate);
                Match FirstMatch = MatchArray[0];
                string _month = FirstMatch.Groups["Month"].Value;
                string _month2 = FirstMatch.Groups["Month2"].Value;
                string _year = FirstMatch.Groups["Year"].Value;

                strFormatted = getMonthFull(_month.TrimStart('0')) + "/" + getMonthFull(_month2.TrimStart('0')) + " " + getYearFull(_year);
            }

            //Matches 2001 => 2001
            string re_yyyy = "^(?<Year>\\d{4})$";
            Regex objDatePattern5 = new Regex(re_yyyy, RegexOptions.None);
            if (objDatePattern5.IsMatch(strDate))
            {
                MatchCollection MatchArray = objDatePattern5.Matches(strDate);
                Match FirstMatch = MatchArray[0];
                string _year = FirstMatch.Groups["Year"].Value;

                strFormatted = _year;
            }

            //Matches 6.28-7.4.02 => 28 June-4 July 2002
            string re_m_d_m_d_y = "^(?<Month>\\d{1,2})([.])(?<Day>\\d{1,2})([-])(?<Month2>\\d{1,2})([.])(?<Day2>\\d{1,2})([.])(?<Year>\\d{1,2})$";
            Regex objDatePattern6 = new Regex(re_m_d_m_d_y, RegexOptions.None);
            if (objDatePattern6.IsMatch(strDate))
            {
                MatchCollection MatchArray = objDatePattern6.Matches(strDate);
                Match FirstMatch = MatchArray[0];
                string _month = FirstMatch.Groups["Month"].Value;
                string _month2 = FirstMatch.Groups["Month2"].Value;
                string _day = FirstMatch.Groups["Day"].Value;
                string _day2 = FirstMatch.Groups["Day2"].Value;
                string _year = FirstMatch.Groups["Year"].Value;

                strFormatted = _day.TrimStart('0') + " " + getMonthFull(_month.TrimStart('0')) + "-" + _day2 + " " + getMonthFull(_day2.TrimStart('0')) + " " + getYearFull(_year);
            }


            //Matches 12.01/1.02 => December 2001/January 2002
            string re_mm_yy_mm_yy = "^(?<Month>\\d{1,2})([.])(?<Year>\\d{1,2})([/])(?<Month2>\\d{1,2})([.])(?<Year2>\\d{1,2})$";
            Regex objDatePattern7 = new Regex(re_mm_yy_mm_yy, RegexOptions.None);
            if (objDatePattern7.IsMatch(strDate))
            {
                MatchCollection MatchArray = objDatePattern7.Matches(strDate);
                Match FirstMatch = MatchArray[0];
                string _month = FirstMatch.Groups["Month"].Value;
                string _month2 = FirstMatch.Groups["Month2"].Value;
                string _year = FirstMatch.Groups["Year"].Value;
                string _year2 = FirstMatch.Groups["Year2"].Value;

                strFormatted = getMonthFull(_month.TrimStart('0')) + " " + getYearFull(_year) + "/" + getMonthFull(_month2.TrimStart('0')) + " " + getYearFull(_year);
            }

            //Matches WINTER/SPRING 2002 => Winter/Spring 2002
            string re_season_season_year = "^(?<Season1>SPRING|SUMMER|FALL|WINTER)([/])(?<Season2>SPRING|SUMMER|FALL|WINTER)([\\s])(?<Year>\\d{4})$";
            Regex objDatePattern8 = new Regex(re_season_season_year, RegexOptions.None);
            if (objDatePattern8.IsMatch(strDate))
            {
                MatchCollection MatchArray = objDatePattern8.Matches(strDate);
                Match FirstMatch = MatchArray[0];
                string _season = myTI.ToLower(FirstMatch.Groups["Season1"].Value);
                string _season2 = myTI.ToLower(FirstMatch.Groups["Season2"].Value);
                string _year = FirstMatch.Groups["Year"].Value;

                strFormatted = myTI.ToTitleCase(_season) + "/" + myTI.ToTitleCase(_season2) + " " + _year;
            }

            //Matches WINTER 01-02 => Winter 2001-2002
            string re_season_year_year = "^(?<Season>SPRING|SUMMER|FALL|WINTER)([\\s])(?<Year>\\d{1,2})([-])(?<Year2>\\d{1,2})$";
            Regex objDatePattern9 = new Regex(re_season_year_year, RegexOptions.None);
            if (objDatePattern9.IsMatch(strDate))
            {
                MatchCollection MatchArray = objDatePattern9.Matches(strDate);
                Match FirstMatch = MatchArray[0];
                string _season = myTI.ToLower(FirstMatch.Groups["Season"].Value);
                string _year = FirstMatch.Groups["Year"].Value;
                string _year2 = FirstMatch.Groups["Year2"].Value;

                strFormatted = myTI.ToTitleCase(_season) + " " + getYearFull(_year) + "-" + getYearFull(_year2);
            }
            
            return strFormatted;
        }