private void ChangeToFlowerProfileBtn_Click(object sender, EventArgs e)
        {
            Database_Manager DBMngrInstance = new Database_Manager();

            new flowerProfile(DBMngrInstance.FetchEnglish(copyOfFlowerId), DBMngrInstance.FetchLatin(copyOfFlowerId), DBMngrInstance.FetchBotan(copyOfFlowerId), DBMngrInstance.FetchNote(copyOfFlowerId), DBMngrInstance.FetchFilePath(copyOfFlowerId), copyOfFlowerId, userAcctType).Show();
            this.Hide();
        }
        // member functions



        /* Function which prompts the checking of the database manager for a currently-existing
         * Flower object with the same attributes. */
        public static bool verifyFlower(Flower customFlower)
        {
            bool             added  = false;
            Database_Manager DBMngr = new Database_Manager();

            // test user-given Flower object with dummy Flower object instantiated here until database is implemented
            //Flower dummyFlower = new Flower("Rosus Maximus", "Rose", "Stabby Flowers");
            //dummyFlower.setFlowerID(customFlower.getFlowerID() + 1);

            // if at least one of the three required attributes for a flower, the Latin name, English name, and botanical family is missing
            if ((customFlower.getLatinName() == "") || (customFlower.getEnglishName() == "") || (customFlower.getBotanicalFam() == ""))
            {
                added = false;
            }
            // else, the flower can be added to the database
            else
            {
                bool exists = DBMngr.checkFlower(customFlower.getLatinName());
                if (exists == false)
                {
                    string newpath = "";
                    if (customFlower.getImgPath() != "" && customFlower.getImgPath() != null)
                    {
                        newpath = ChangeFilePath(customFlower.getImgPath());
                    }
                    DBMngr.InsertFlower(customFlower.getEnglishName(), customFlower.getLatinName(), customFlower.getBotanicalFam(), customFlower.getNote(), newpath);
                    added = true;
                }
                else
                {
                    added = false;
                }
            }
            return(added);
        }
Exemplo n.º 3
0
        private void FetchNotes(int[] id)
        {
            Database_Manager db = new Database_Manager();

            try
            {
                //for (int i = 0; i < 3; i++)
                //{
                //    notes[i] = db.FetchNote(id[0]);
                //}
                if (id[0] != 0)
                {
                    notes[0] = db.FetchNote(id[0]);
                    if (id[1] != 0)
                    {
                        notes[1] = db.FetchNote(id[1]);
                        if (id[2] != 0)
                        {
                            notes[2] = db.FetchNote(id[2]);
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        // member functions


        // This version of verifyFlower() will verify that the flower entry
        // passed as an argument does not exist within the database, rather than
        // comparing with the contents of a pseudo-database, or a dummy Flower instantiation,
        // like what was done for Iteration I.
        public string verifyFlower(string userEnteredEnglish, string userEnteredLatin, string userEnteredBotan, string userEnteredNote, string userEnteredImgPath)
        {
            string           msgToDisplay;
            Database_Manager DBMngr = new Database_Manager();

            // need to be able to get the flower entry from the database
            // which matches the id of 'customFlower'


            // if a change is made to the english name AND that change does not result in it being blank
            if ((userEnteredEnglish != DBMngr.FetchEnglish(flowerId)) && (userEnteredEnglish != ""))
            {
                DBMngr.changeEnglishName(userEnteredEnglish, flowerId);
                msgToDisplay = "Changes successfully saved!";
            }
            else
            {
                msgToDisplay = "Changes unable to be saved: One of the three minimum attributes is missing.";
            }
            // same structure for latin name and botanical family
            if ((userEnteredLatin != DBMngr.FetchLatin(flowerId)) && (userEnteredLatin != ""))
            {
                DBMngr.changeLatinName(userEnteredLatin, flowerId);
                msgToDisplay = "Changes successfully saved!";
            }
            else
            {
                msgToDisplay = "Changes unable to be saved: One of the three minimum attributes is missing.";
            }
            if ((userEnteredBotan != DBMngr.FetchBotan(flowerId)) && (userEnteredBotan != ""))
            {
                DBMngr.changeBotanicalFam(userEnteredBotan, flowerId);
                msgToDisplay = "Changes successfully saved!";
            }
            else
            {
                msgToDisplay = "Changes unable to be saved: One of the three minimum attributes is missing.";
            }


            if (userEnteredNote != DBMngr.FetchNote(flowerId) && userEnteredNote != "")
            {
                DBMngr.changeNote(userEnteredNote, flowerId);
                msgToDisplay = "Changes successfully saved!";
            }

            if (userEnteredImgPath != DBMngr.FetchFilePath(flowerId) && userEnteredImgPath != "")
            {
                userEnteredImgPath = ChangeFilePath(userEnteredImgPath);
                DBMngr.changeImgPath(userEnteredImgPath, flowerId);
                msgToDisplay = "Changes successfully saved!";
            }


            return(msgToDisplay);
        }
Exemplo n.º 5
0
        //Fetch english names from the Database
        //Stores results into linked list that is passed by reference
        //type of name is passes as a string and is then passes to the database manager
        private void Fetch_names(string type, ref LinkedList <Candidate> list)
        {
            Database_Manager db = new Database_Manager();

            try
            {
                db.FetchAllNames(ref list, type);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 6
0
        //Query the database using the ID of the entry in question.
        //Will return the botanical name of the entry
        //This exists in order to compare English names and Latin names in order to help decide
        //which one the user might be looking for.
        private string Fetch_botanical(int id)
        {
            string           temp;
            Database_Manager db = new Database_Manager();

            try
            {
                temp = db.FetchBotan(id);
            }
            catch (Exception)
            {
                throw;
            }
            return(temp);
        }
Exemplo n.º 7
0
        private void Fetch_notes(string entry, ref LinkedList <Candidate> list)
        {
            Database_Manager db = new Database_Manager();

            try
            {
                //Query database for all notes containing key words
                //Put all results into list for later comparisons and testing.
                db.FetchAllNotes(entry, ref list);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                throw;
            }
        }
Exemplo n.º 8
0
        private void FetchImages(int[] id)
        {
            //FOR TESTING ONLY//
            images1 = new string[3];

            //images1[0] = images1[1] = images1[2] = "flower.jpg";
            //FOR TESTING ONLY//

            try
            {
                //TODO
                //first the number of images for each flower must be gotten from the database
                //then the arrays for the images of each flower must be initialized.
            }
            catch (Exception)
            {
                throw;
            }
            try
            {
                Database_Manager db = new Database_Manager();
                //TODO
                //Next all 3 arrays must be populated with filepaths from the database.
                //for (int i = 0; i < 3; i++)
                //{
                //    images1[i] = db.FetchFilePath(id[i]);
                //}
                if (id[0] != 0)
                {
                    images1[0] = db.FetchFilePath(id[0]);
                    if (id[1] != 0)
                    {
                        images1[1] = db.FetchFilePath(id[1]);
                        if (id[2] != 0)
                        {
                            images1[2] = db.FetchFilePath(id[2]);
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        public LoginController(ref int userAcctType, string user, string pass)
        {
            fail = false;

            Database_Manager dbMngr = new Database_Manager();

            if (dbMngr.checkUsername(user))
            {
                //checks the db password against the salted version of the provided password
                string dbPass   = dbMngr.FetchPassword(user);
                string saltPass = (pass + ".cs.is.fun.team.dirk.");
                string hashPass = Convert.ToString(saltPass.GetHashCode());
                if (dbPass != (hashPass))
                {
                    MessageBox.Show("Your password was not correct. Please enter the right credentials.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    fail = true;
                }
                else
                {
                    //Check user's account type
                    string type = dbMngr.Fetchaccttype(user);
                    Console.WriteLine(type);
                    if (type == "Administrator")
                    {
                        userAcctType = 3;
                    }
                    else if (type == "Researcher")
                    {
                        userAcctType = 2;
                    }
                    else if (type == "Student")
                    {
                        userAcctType = 1;
                    }

                    //Proceed to Main Menu
                    //new MainMenu(userAcctType).Show();
                }
            }
            else
            {
                MessageBox.Show("Your username was not correct. Please enter the right credentials.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                fail = true;
            }
        }
Exemplo n.º 10
0
        // remove the flower from the database
        public static bool removeFlower(int id)
        {
            // database connection variables and info

            Database_Manager db = new Database_Manager();

            // try to open the database and delete
            try
            {
                // connect to DBMngr and execute the delete flower function
                db.DeleteFlower(id);
                return(true);
            }
            // if error is thrown, return false
            catch (Exception ex)
            {
                return(false);
            }
        }
Exemplo n.º 11
0
        public void Main(string first, string last, string username, string password, string accType)
        {
            Database_Manager db     = new Database_Manager();
            bool             exists = false;

            exists = db.checkUsername(username);
            if (exists)
            {
                if (password != null && password != "")
                {
                    // salt and hash the password
                    password = Salt(password);
                    int hashPass = Hash(password);
                    password = Convert.ToString(hashPass);
                    db.ChangePassword(username, password);
                }
                if (last != null && last != "")
                {
                    db.ChangeLastname(username, last);
                }
                if (first != null && first != "")
                {
                    db.ChangeFirstname(username, first);
                }
                if (accType != null && accType != "" && accType != "(No change)")
                {
                    db.ChangeAccType(username, accType);
                }
                if (verify(username, password, first, last, accType))
                {
                    MessageBox.Show("User account successfully changed.");
                }
                else
                {
                    MessageBox.Show("ERROR: User info was not changed");
                }
            }
            else
            {
                MessageBox.Show("ERROR: User account does not exist");
            }
        }
Exemplo n.º 12
0
        private void FetchNames(int[] id, ref bool res1, ref bool res2, ref bool res3)
        {
            ////////////////////////////////////////////////////////
            string query = "SELECT English, Latin, Botanical FROM Flower WHERE id = " + id[0];

            try
            {
                Database_Manager db = new Database_Manager();
                if (id[0] != 0)
                {
                    res1 = true;
                    flowers[0].setEnglishName(db.FetchEnglish(id[0]));
                    flowers[0].setLatinName(db.FetchLatin(id[0]));
                    flowers[0].setBotanicalFam(db.FetchBotan(id[0]));
                    if (id[1] != 0)
                    {
                        res2 = true;
                        flowers[1].setEnglishName(db.FetchEnglish(id[1]));
                        flowers[1].setLatinName(db.FetchLatin(id[1]));
                        flowers[1].setBotanicalFam(db.FetchBotan(id[1]));
                        if (id[2] != 0)
                        {
                            res3 = true;
                            flowers[2].setEnglishName(db.FetchEnglish(id[2]));
                            flowers[2].setLatinName(db.FetchLatin(id[2]));
                            flowers[2].setBotanicalFam(db.FetchBotan(id[2]));
                        }
                    }
                }

                //TODO
                //When database is implemented this method will pull name, botanical, and latin for each result
                //from the database and put it in each flower object
            }
            catch (SqlException e)
            {
                MessageBox.Show(e.Message);
                throw;
            }
        }
Exemplo n.º 13
0
        public bool verify(string username, string password, string first, string last, string acct)
        {
            Database_Manager db = new Database_Manager();

            if (password != "" && password != null)
            {
                string salted = Salt(password);
                int    temp   = Hash(salted);
                salted = temp.ToString();
                if (db.FetchPassword(username) != password)
                {
                    return(false);
                }
            }
            if (first != "" && first != null)
            {
                if (db.Fetchfirst(username) != first)
                {
                    return(false);
                }
            }
            if (last != "" && last != null)
            {
                if (db.FetchLast(username) != last)
                {
                    return(false);
                }
            }
            if (acct != "(No change)")
            {
                if (db.Fetchaccttype(username) != acct)
                {
                    return(false);
                }
            }
            return(true);
        }
        public ImageSearchController(string filename, string wordSearch, string freqColor)
        {
            Database_Manager dbManager = new Database_Manager();
            Bitmap           orig      = new Bitmap(filename);
            Bitmap           img       = new Bitmap(orig, 256, 256);

            array       = new Color[img.Width, img.Height]; //Image Pixel Array
            redPixels   = new int[img.Width, img.Height];   //RGB Arrays
            greenPixels = new int[img.Width, img.Height];   //RGB Arrays
            bluePixels  = new int[img.Width, img.Height];   //RGB Arrays

            //loading 2D array with pixels of given search image
            for (int i = 0; i < img.Width; i++)
            {
                for (int j = 0; j < img.Height; j++)
                {
                    Color  pixel = img.GetPixel(i, j);
                    string pix   = "" + pixel; //outputs: Color [A=255, R=80, G=72, B=61]
                    pixel = array[i, j];
                    //loading RGB arrays with RGB values of the pixels
                    Regex           arg   = new Regex(@"=(.+?),");
                    Regex           b     = new Regex(@"B=(.+?)]");
                    MatchCollection mcARG = arg.Matches(pix);
                    MatchCollection mcB   = b.Matches(pix);
                    string          red   = Regex.Replace(mcARG[1].ToString(), "[^0-9.]", "");
                    string          green = Regex.Replace(mcARG[2].ToString(), "[^0-9.]", "");
                    string          blue  = Regex.Replace(mcB[0].ToString(), "[^0-9.]", "");
                    redPixels[i, j]   = Int32.Parse(red);
                    greenPixels[i, j] = Int32.Parse(green);
                    bluePixels[i, j]  = Int32.Parse(blue);

                    //Pixel Range RGB subdivisions

                    //0-63
                    if (redPixels[i, j] >= 0 && redPixels[i, j] <= 63)
                    {
                        zeroToSixyThreeRed++;
                    }
                    if (bluePixels[i, j] >= 0 && bluePixels[i, j] <= 63)
                    {
                        zeroToSixyThreeBlue++;
                    }
                    if (greenPixels[i, j] >= 0 && greenPixels[i, j] <= 63)
                    {
                        zeroToSixyThreeGreen++;
                    }

                    //64-127
                    if (redPixels[i, j] >= 64 && redPixels[i, j] <= 127)
                    {
                        sixtyFourToOneTwentySevenRed++;
                    }
                    if (bluePixels[i, j] >= 64 && bluePixels[i, j] <= 127)
                    {
                        sixtyFourToOneTwentySevenBlue++;
                    }
                    if (greenPixels[i, j] >= 64 && greenPixels[i, j] <= 127)
                    {
                        sixtyFourToOneTwentySevenGreen++;
                    }

                    //128-191
                    if (redPixels[i, j] >= 128 && redPixels[i, j] <= 191)
                    {
                        oneTwentyEightToOneNinetyOneRed++;
                    }
                    if (bluePixels[i, j] >= 128 && bluePixels[i, j] <= 191)
                    {
                        oneTwentyEightToOneNinetyOneBlue++;
                    }
                    if (greenPixels[i, j] >= 128 && greenPixels[i, j] <= 191)
                    {
                        oneTwentyEightToOneNinetyOneGreen++;
                    }

                    //192-255
                    if (redPixels[i, j] >= 192 && redPixels[i, j] <= 255)
                    {
                        oneNinetyTwoToTwoFiftyFiveRed++;
                    }
                    if (bluePixels[i, j] >= 192 && bluePixels[i, j] <= 255)
                    {
                        oneNinetyTwoToTwoFiftyFiveBlue++;
                    }
                    if (greenPixels[i, j] >= 192 && greenPixels[i, j] <= 255)
                    {
                        oneNinetyTwoToTwoFiftyFiveGreen++;
                    }
                }
            }

            //Count of Pixel values: for each R, G, and B: [0-63], [64-127], [128-191], [192-255]
            imageValueBins       = new int[3, 4];
            imageValueBins[0, 0] = zeroToSixyThreeRed;
            imageValueBins[1, 0] = zeroToSixyThreeGreen;
            imageValueBins[2, 0] = zeroToSixyThreeBlue;
            imageValueBins[0, 1] = sixtyFourToOneTwentySevenRed;
            imageValueBins[1, 1] = sixtyFourToOneTwentySevenGreen;
            imageValueBins[2, 1] = sixtyFourToOneTwentySevenBlue;
            imageValueBins[0, 2] = oneTwentyEightToOneNinetyOneRed;
            imageValueBins[1, 2] = oneTwentyEightToOneNinetyOneGreen;
            imageValueBins[2, 2] = oneTwentyEightToOneNinetyOneBlue;
            imageValueBins[0, 3] = oneNinetyTwoToTwoFiftyFiveRed;
            imageValueBins[1, 3] = oneNinetyTwoToTwoFiftyFiveGreen;
            imageValueBins[2, 3] = oneNinetyTwoToTwoFiftyFiveBlue;

            //Database Manager

            /*
             * NOTE: FOR TESTING PURPOSES, REPLACE THE FILEPATHS WITH LOCAL PATHS FROM YOUR SYSTEM
             */
            /*
             * OLD:
             *  int length = 5; //need # of database filepaths
             *  for (int i = 0; i < length; i++) {
             *      imageFilePaths[i] = dbManager.FetchFilePath(i);
             *  }
             * "C:\\Users\\dipak\\Desktop\\Nexus\\Photos\\Pictures\\D1.jpg", "C:\\Users\\dipak\\Desktop\\Nexus\\Photos\\Pictures\\D1.jpg", "C:\\Users\\dipak\\Desktop\\Nexus\\Photos\\Pictures\\D1.jpg", "C:\\Users\\dipak\\Desktop\\Nexus\\Photos\\Pictures\\D1.jpg", "C:\\Users\\dipak\\Desktop\\Nexus\\Photos\\Pictures\\D1.jpg"
             */
            string[] imageFilePaths = { "..\\Pictures\\bulk.jpg",   "..\\Pictures\\button.jpg", "..\\Pictures\\cherry.jpg", "..\\Pictures\\cool.jpg",
                                        "..\\Pictures\\dahlia.jpg", "..\\Pictures\\daisy.jpg",  "..\\Pictures\\flower.jpg", "..\\Pictures\\hibuscus.jpg",
                                        "..\\Pictures\\orange.jpg", "..\\Pictures\\salmon.jpg", "..\\Pictures\\sun.jpg",    "..\\Pictures\\sunflower.jpg",
                                        "..\\Pictures\\yellow.jpg" };
            chiSquareDistances = new double[imageFilePaths.Length];
            order = new int[13];

            for (int d = 0; d < imageFilePaths.Length; d++)
            {
                order[d] = d;
                chiSquareDistances[d] = 0.0;
                Color[,] dbArray;
                int[,] dbRedPixels;
                int[,] dbGreenPixels;
                int[,] dbBluePixels;
                int[,] dbImageValueBins;
                //Value Bin Instance Variables
                int dbZeroToSixyThreeRed                = 0;
                int dbZeroToSixyThreeGreen              = 0;
                int dbZeroToSixyThreeBlue               = 0;
                int dbSixtyFourToOneTwentySevenRed      = 0;
                int dbSixtyFourToOneTwentySevenGreen    = 0;
                int dbSixtyFourToOneTwentySevenBlue     = 0;
                int dbOneTwentyEightToOneNinetyOneRed   = 0;
                int dbOneTwentyEightToOneNinetyOneGreen = 0;
                int dbOneTwentyEightToOneNinetyOneBlue  = 0;
                int dbOneNinetyTwoToTwoFiftyFiveRed     = 0;
                int dbOneNinetyTwoToTwoFiftyFiveGreen   = 0;
                int dbOneNinetyTwoToTwoFiftyFiveBlue    = 0;

                Bitmap dbOrig = new Bitmap(imageFilePaths[d]);        //iterating through array of database image filepaths
                Bitmap dbImg  = new Bitmap(dbOrig, 256, 256);
                dbArray       = new Color[dbImg.Width, dbImg.Height]; //Image Pixel Array
                dbRedPixels   = new int[dbImg.Width, dbImg.Height];   //RGB Arrays
                dbGreenPixels = new int[dbImg.Width, dbImg.Height];   //RGB Arrays
                dbBluePixels  = new int[dbImg.Width, dbImg.Height];   //RGB Arrays
                //loading 2D array with pixels of the database image
                for (int i = 0; i < dbImg.Width; i++)
                {
                    for (int j = 0; j < dbImg.Height; j++)
                    {
                        Color  dbPixel = dbImg.GetPixel(i, j);
                        string dbPix   = "" + dbPixel;
                        dbPixel = dbArray[i, j];
                        //loading RGB arrays with RGB values of the pixels
                        Regex           arg   = new Regex(@"=(.+?),");
                        Regex           b     = new Regex(@"B=(.+?)]");
                        MatchCollection mcARG = arg.Matches(dbPix);
                        MatchCollection mcB   = b.Matches(dbPix);
                        string          red   = Regex.Replace(mcARG[1].ToString(), "[^0-9.]", "");
                        string          green = Regex.Replace(mcARG[2].ToString(), "[^0-9.]", "");
                        string          blue  = Regex.Replace(mcB[0].ToString(), "[^0-9.]", "");
                        dbRedPixels[i, j]   = Int32.Parse(red);
                        dbGreenPixels[i, j] = Int32.Parse(green);
                        dbBluePixels[i, j]  = Int32.Parse(blue);

                        //Pixel Range RGB subdivisions

                        //0-63
                        if (dbRedPixels[i, j] >= 0 && dbRedPixels[i, j] <= 63)
                        {
                            dbZeroToSixyThreeRed++;
                        }
                        if (dbBluePixels[i, j] >= 0 && dbBluePixels[i, j] <= 63)
                        {
                            dbZeroToSixyThreeBlue++;
                        }
                        if (dbGreenPixels[i, j] >= 0 && dbGreenPixels[i, j] <= 63)
                        {
                            dbZeroToSixyThreeGreen++;
                        }

                        //64-127
                        if (dbRedPixels[i, j] >= 64 && dbRedPixels[i, j] <= 127)
                        {
                            dbSixtyFourToOneTwentySevenRed++;
                        }
                        if (dbBluePixels[i, j] >= 64 && dbBluePixels[i, j] <= 127)
                        {
                            dbSixtyFourToOneTwentySevenBlue++;
                        }
                        if (dbGreenPixels[i, j] >= 64 && dbGreenPixels[i, j] <= 127)
                        {
                            dbSixtyFourToOneTwentySevenGreen++;
                        }

                        //128-191
                        if (dbRedPixels[i, j] >= 128 && dbRedPixels[i, j] <= 191)
                        {
                            dbOneTwentyEightToOneNinetyOneRed++;
                        }
                        if (dbBluePixels[i, j] >= 128 && dbBluePixels[i, j] <= 191)
                        {
                            dbOneTwentyEightToOneNinetyOneBlue++;
                        }
                        if (dbGreenPixels[i, j] >= 128 && dbGreenPixels[i, j] <= 191)
                        {
                            dbOneTwentyEightToOneNinetyOneGreen++;
                        }

                        //192-255
                        if (dbRedPixels[i, j] >= 192 && dbRedPixels[i, j] <= 255)
                        {
                            dbOneNinetyTwoToTwoFiftyFiveRed++;
                        }
                        if (dbBluePixels[i, j] >= 192 && dbBluePixels[i, j] <= 255)
                        {
                            dbOneNinetyTwoToTwoFiftyFiveBlue++;
                        }
                        if (dbGreenPixels[i, j] >= 192 && dbGreenPixels[i, j] <= 255)
                        {
                            dbOneNinetyTwoToTwoFiftyFiveGreen++;
                        }
                    }
                }

                //Count of Pixel values: for each R, G, and B: [0-63], [64-127], [128-191], [192-255]
                dbImageValueBins       = new int[3, 4];
                dbImageValueBins[0, 0] = dbZeroToSixyThreeRed;
                dbImageValueBins[1, 0] = dbZeroToSixyThreeGreen;
                dbImageValueBins[2, 0] = dbZeroToSixyThreeBlue;
                dbImageValueBins[0, 1] = dbSixtyFourToOneTwentySevenRed;
                dbImageValueBins[1, 1] = dbSixtyFourToOneTwentySevenGreen;
                dbImageValueBins[2, 1] = dbSixtyFourToOneTwentySevenBlue;
                dbImageValueBins[0, 2] = dbOneTwentyEightToOneNinetyOneRed;
                dbImageValueBins[1, 2] = dbOneTwentyEightToOneNinetyOneGreen;
                dbImageValueBins[2, 2] = dbOneTwentyEightToOneNinetyOneBlue;
                dbImageValueBins[0, 3] = dbOneNinetyTwoToTwoFiftyFiveRed;
                dbImageValueBins[1, 3] = dbOneNinetyTwoToTwoFiftyFiveGreen;
                dbImageValueBins[2, 3] = dbOneNinetyTwoToTwoFiftyFiveBlue;

                //Chi-Squared Distance Comparisons
                double chiRed;
                double chiGreen;
                double chiBlue;
                double chiThreshold;

                double redSum   = 0;
                double greenSum = 0;
                double blueSum  = 0;
                for (int color = 0; color < 3; color++)
                {
                    for (int range = 0; range < 4; range++)
                    {
                        if (color == 0)
                        {
                            redSum += ((Math.Pow((imageValueBins[color, range] - dbImageValueBins[color, range]), 2)) / (imageValueBins[color, range] + dbImageValueBins[color, range]));
                        }
                        if (color == 1)
                        {
                            greenSum += ((Math.Pow((imageValueBins[color, range] - dbImageValueBins[color, range]), 2)) / (imageValueBins[color, range] + dbImageValueBins[color, range]));
                        }
                        if (color == 2)
                        {
                            blueSum += ((Math.Pow((imageValueBins[color, range] - dbImageValueBins[color, range]), 2)) / (imageValueBins[color, range] + dbImageValueBins[color, range]));
                        }
                    }
                }

                if (redSum == double.NaN)
                {
                    redSum = 0;
                }
                if (greenSum == double.NaN)
                {
                    greenSum = 0;
                }
                if (blueSum == double.NaN)
                {
                    blueSum = 0;
                }

                chiRed       = (0.25) * (Math.Sqrt(redSum));
                chiGreen     = (0.25) * (Math.Sqrt(greenSum));
                chiBlue      = (0.25) * (Math.Sqrt(blueSum));
                chiThreshold = (1.0 / 3.0) * (chiRed + chiGreen + chiBlue);
                Console.WriteLine(chiThreshold);
                if (chiThreshold == double.NaN)
                {
                    chiThreshold = 0;
                }
                chiSquareDistances[d] = chiThreshold / 100.0;
            }

            //Sorting Chi-Square Distance Values to Determine Smallest (Most Accurate) Results
            sortedDistances = chiSquareDistances;


            for (int write = 0; write < sortedDistances.Length; write++)
            {
                for (int sort = 0; sort < sortedDistances.Length - 1; sort++)
                {
                    if (sortedDistances[sort] > sortedDistances[sort + 1])
                    {
                        double temp = sortedDistances[sort + 1];
                        sortedDistances[sort + 1] = sortedDistances[sort];
                        sortedDistances[sort]     = temp;

                        int tempOrder = order[sort + 1];
                        order[sort + 1] = order[sort];
                        order[sort]     = tempOrder;
                    }
                }
            }

            topThree[0] = Array.FindIndex(chiSquareDistances, m => m == sortedDistances[0]);
            topThree[1] = Array.FindIndex(chiSquareDistances, m => m == sortedDistances[1]);
            topThree[2] = Array.FindIndex(chiSquareDistances, m => m == sortedDistances[2]);

            if (topThree[0] >= 1)
            {
                topThree[0] = topThree[1];
                topThree[1] = topThree[2];
                topThree[2] = Array.FindIndex(chiSquareDistances, m => m == sortedDistances[3]);
            }
            else if (topThree[1] >= 1)
            {
                topThree[1] = topThree[2];
                topThree[2] = Array.FindIndex(chiSquareDistances, m => m == sortedDistances[3]);
            }

            else if (topThree[2] >= 1)
            {
                topThree[2] = Array.FindIndex(chiSquareDistances, m => m == sortedDistances[3]);
            }
            Console.WriteLine("Algorithm Completed");
        }
Exemplo n.º 15
0
        // main driver for addUser logic
        public void main(string first, string last, string username, string password, string accType, string file)
        {
            Database_Manager dbm = new Database_Manager();
            string           msg = "";
            int    addedCount    = 0;
            int    failedCount   = 0;
            bool   valid;
            bool   added  = false;
            bool   exists = true;
            string line;

            // entries from a batch file
            if (file != "")
            {
                // while not at the end of the csv file, read the line and save the data in the corresponding variables
                using (StreamReader sr = File.OpenText(file))
                {
                    while ((line = sr.ReadLine()) != null)
                    {
                        string[] values = new string[5] {
                            "", "", "", "", ""
                        };                                                     // sets initial values to 0
                        string[] tempValues = line.Split(',');                 // creates a temp array, so if something is missing, it doesnt mess up assigning values below
                        for (int i = 0; i < tempValues.Length; i++)
                        {
                            values[i] = tempValues[i];
                        }
                        // set values
                        first    = values[0];
                        last     = values[1];
                        username = values[2];
                        password = values[3];
                        accType  = values[4];
                        // verify that required info is provided
                        failedItems = new string[5];
                        valid       = verifyInfo(first, last, username, password, accType);
                        // if it is
                        if (valid == true)
                        {
                            // check database to see if username exists
                            exists = dbm.checkUsername(username);
                            if (exists == false)
                            {
                                // salt and hash pasword
                                password = Salt(password);
                                int hashPass = Hash(password);
                                password = Convert.ToString(hashPass);
                                // add to database
                                added = dbm.addUser(first, last, username, password, accType);
                                // if the user was added, keep track of the addition
                                if (added == true)
                                {
                                    // user was added, update added info
                                    addedCount = updateAddedCount(addedCount);
                                    addedUserList.Add(first + " " + last + ": " + username);
                                }
                                else
                                {
                                    // user was not added, update failed info
                                    failedCount = updateFailedCount(failedCount);
                                    failedUserList.Add(first + " " + last + ": " + username);
                                }
                            }
                            else
                            {
                                // username already exists in DB
                                failedCount = updateFailedCount(failedCount);
                                failedUserList.Add(first + " " + last + ": " + username);
                            }
                        }
                        else
                        {
                            // if user was not added, keep track of failed additions
                            failedCount = updateFailedCount(failedCount);
                            failedUserList.Add(first + " " + last + ": " + username);
                        }
                    }
                    // create a message of how many added and failed users from batch file
                }
                msg = createBatchMsg(addedCount, failedCount);
                // empty the lists so the next batch file the admin uses doesnt have this files info in it
                addedUserList.Clear();
                failedUserList.Clear();
            }

            // used for text box entries
            else
            {
                // verify that required info is provided
                failedItems = new string[5];
                valid       = verifyInfo(first, last, username, password, accType);
                // if it is
                if (valid == true)
                {
                    // check database to see if username exists
                    exists = dbm.checkUsername(username);
                    if (exists == false)
                    {
                        // salt and hash pasword
                        password = Salt(password);
                        int hashPass = Hash(password);
                        password = Convert.ToString(hashPass);
                        // add to database
                        added = dbm.addUser(first, last, username, password, accType);
                        if (added == true)
                        {
                            // provide confirmation
                            msg = confirmMsg(username);
                        }
                        else
                        {
                            // this message is when the catch is called in the database
                            msg = "Error while adding user, can not use username: " + username;
                        }
                    }
                    else
                    {
                        msg = userExistsMsg(username);
                    }
                }
                else
                {
                    // provide feedback why it didn't get added
                    msg = failMsg(username);
                }
            }
            // display success/fail message
            ShowMsg(msg);
        }