void MatchEmerald(string[] userKeywords)
        {

            Journal Emerald= new Journal();
            string[] splitter = { ".", " ", ":", ",", ";", "'", "\"", "(", ")" };
            Journal[] journals = DataManager.GetEmeraldData();
            float mostmatch = 0;
            foreach (Journal j in journals)
            {

                float match = Comparator.GetStatsEmerald(j.Keywords.Split(splitter, StringSplitOptions.RemoveEmptyEntries), userKeywords);

                if (match > mostmatch)
                {

                    mostmatch = match;
                    Emerald = j;

                }

            }

            if (String.IsNullOrEmpty(Emerald.Name))
            {

                Journal2Name.Text = "No match found";
            }
            else
            {
                Journal2Link = Emerald.Link;
                Journal2SubLink = Emerald.Submit;
                Journal2Name.Text = "Emerald:<br>" + Emerald.Name;
            }

        }
        void MatchSpringer(string[] userKeywords)
        {

             Journal Springer = new Journal();
            string[] splitter = { ".", " ", ":", ",", ";", "'", "\"", "(", ")" };
            Journal[] journals = DataManager.GetSpringerData();
            float mostmatch = 0;
            foreach (Journal j in journals)
            { 
            
            float match=Comparator.GetStatsSpringer(j.Keywords.Split(splitter,StringSplitOptions.RemoveEmptyEntries),userKeywords);

                if (match > mostmatch)
                {

                    mostmatch = match;
                    Springer = j;

                 }
            
            }

            if (String.IsNullOrEmpty(Springer.Name))
            {

                Journal1Name.Text = "No match found";
            }
            else
            {
                Journal1Link = Springer.Link;
                Journal1SubLink = Springer.Submit;
                Journal1Name.Text = "Springer:<br>" + Springer.Name;
            }
        
        }
        public static Journal[] FromSpringer()
        {

            List<Journal> JournalsFromSpringer = new List<Journal>();

            string source = "https://www.springer.com/gp/adis/products-services";
            var html = new HtmlDocument();

            try
            {
                html.LoadHtml(new WebClient().DownloadString(source)); // load a string web address
                // create a root node
                var root = html.DocumentNode;

                var Links = root.Descendants().Where(n => n.GetAttributeValue("class", "").Equals("flapContent--paragraph"));


                foreach (var Link in Links)
                {


                    Journal JournalObj = new Journal();

                    HtmlAttribute newAttribute = Link.FirstChild.Attributes["href"];
                    JournalObj.Link = newAttribute.Value;
                    JournalObj.Name = Link.InnerText;
                    JournalObj.Website = "Springer";
                    //JournalObj.Keywords = KeywordExtractor.springerKeywords(JournalObj.Link);
                    //JournalObj.Submit = KeywordExtractor.springerLink(JournalObj.Link);
                    if (String.IsNullOrEmpty(JournalObj.Submit))
                    {
                        JournalObj.Submit = "https://www.editorialmanager.com/";
                    
                    }
                    JournalsFromSpringer.Add(JournalObj);


                }
            }
            catch (Exception ex)
            { 
            
            
            }
            return JournalsFromSpringer.ToArray();
        }
        void MatchEmerald(string[] userKeywords)
        {

            Journal Emerald= new Journal();
            string[] splitter = { ".", " ", ":", ",", ";", "'", "\"", "(", ")" };
            Journal[] journals = DataManager.GetEmeraldData();
            float mostmatch = 0;
            string names = "";
            foreach (Journal j in journals)
            {

                float match = Comparator.GetStatsEmerald(j.Keywords.Split(splitter, StringSplitOptions.RemoveEmptyEntries), userKeywords);

                if (match >= Strictness)
                {

                    DropDownList2.Items.Add(new ListItem(j.Name, j.Link + "^" + j.Submit));
                    DropDownList2.SelectedIndex = DropDownList2.Items.Count - 1;
                   
                   
                     Emerald = j;
                    names += j.Name + "<br>"; // remove this line
                    // add journal name as text here (html plain text or asp label)
                    // add new button here
                    // add button in div (see html for journal EMERALD names div)
                    // add onClick event by button.onClick+=newOnclickhandler;
                    // add response.redirect(j.link); code to that event , it will redirect to that link
                    // SEE EXISTING onClick EVENTS FOR LINKS CORRECTION

                }

            }

            if (String.IsNullOrEmpty(names))
                Journal2Details.Text = "No match found";


        }
        protected void Button2_Click(object sender, EventArgs e)
        {


            try
            {
                Journal[] journal = new Journal[1];

                if (!(tempJournal.Link == ""))
                {
                    journal[0] = tempJournal;
                    DataManager.SetJournalData(journal);
                    LogLabel.Text = "Data Entered Successfully";
                }
                else
                {
                    throw new NullReferenceException();
                
                }

            }
            catch (Exception er)
            {

                LogLabel.Text = "Data Not Entered";
            
            }
        }
        protected void JournalList_SelectedIndexChanged(object sender, EventArgs e)
        {
            LogLabel.Text = "Links";
            string JournalLink = JournalList.SelectedValue;
            Journal j = new Journal();

            foreach (Journal journal in journals)
            {

                if (journal.Link == JournalLink)
                {


                    j = journal;
                    break;

                }


            }
            tempJournal = j;
            HyperLink1.NavigateUrl = j.Link;

            Name.Text = j.Name;

            Website.Text = j.Website;
            KeywordsText.Text = j.Keywords;

        }
        protected void Button1_Click(object sender, EventArgs e)
        {

            try
            {
                LogLabel.Text = "Links";
                if (JournalDrop.SelectedValue == "abc" || JournalLinksBy.SelectedValue == "abc" || HeadingValue.SelectedValue == "abc" || KeywordDropdown.SelectedValue == "abc" || SubmitValue.SelectedValue == "abc"
                    || String.IsNullOrEmpty(UrlText.Text) || String.IsNullOrEmpty(KeywordsText.Text) || String.IsNullOrEmpty(SubmitText.Text) || String.IsNullOrEmpty(JournalTextbox.Text)
                    )
                {
                    LogLabel.Text = "   Data Missing, please make sure values are set correctly.";
                }
                else
                {
                    if (JournalDrop.SelectedValue == "JournalHome")
                    {

                        Journal journal = new Journal();

                        journal.Name = Crawler.Name(UrlText.Text, HeadingValue.SelectedValue, HeadingText.Text);
                        journal.Link = UrlText.Text;
                        journal.Keywords = Crawler.Keywords(journal.Link, KeywordDropdown.SelectedValue, KeywordsText.Text);
                        journal.Website = "Other";
                        journal.Submit = Crawler.SubmitLink(journal.Link, SubmitValue.SelectedValue, SubmitText.Text);


                        HyperLink1.NavigateUrl = journal.Link;

                        Name.Text = journal.Name;

                        Website.Text = journal.Website;
                        KeywordsText.Text = journal.Keywords;
                        tempJournal = journal;

                    }
                    if (JournalDrop.SelectedValue == "JournalLinks")
                    {

                        string[] links = Crawler.JournalLinks(UrlText.Text, JournalLinksBy.SelectedValue.ToString(), JournalTextbox.Text);

                        foreach (string link in links)
                        {


                            LogLabel.Text += "<br/>" + link;

                        }


                    }
                }
            }
            catch (Exception ec)
            {



            }
        }
            public static void SetJournalData(Journal[] journalDataList)
            {
                DataSet SQLdset;
                SqlCeDataAdapter SQLAdp;

                SqlCeConnection SQLCon;
                string tableName = "Journal_Data";

                SQLCon = new SqlCeConnection();

                string ConString = @"Data Source=|DataDirectory|KeywordsDB.sdf;";

                SQLCon.ConnectionString = ConString;



                try
                {
                    if (SQLCon != null)
                    {
                        SQLCon.Open();


                        string sql;


                        SqlCeCommand comm = new SqlCeCommand();

                        comm.CommandType = CommandType.Text;
                        comm.Connection = SQLCon;


                        int count = journalDataList.Length;


                        for (int i = 0; i < count; i++)
                        {



                            sql = "INSERT INTO Journal_Data(JournalName, JournalLink, Keywords, Website, SubmitLink) VALUES('" + journalDataList[i].Name + "','" + journalDataList[i].Link + "','" + journalDataList[i].Keywords.ToLower() + "','" + journalDataList[i].Website + "','" + journalDataList[i].Submit + "');";



                            comm.CommandText = sql;

                            try
                            {



                                comm.ExecuteNonQuery();

                            }
                            catch (Exception ex)
                            {
                                System.Diagnostics.Debug.WriteLine(ex.Message);
                            }
                            finally
                            {


                            }
                        }
                        SQLCon.Close();

                    }
                }
                catch (Exception ec)
                { }




            }
            public static Journal[] GetSpringerData()
            {

                 DataSet SQLdset;
                 SqlCeDataAdapter SQLAdp;
     
                SqlCeConnection SQLCon;

                Journal[] journalData = new Journal[1]; // sample declaration to prevent compile time error

                try
                {
                    SQLCon = new SqlCeConnection();

                    string tableName = "Journal_Data";
                    string ConString = @"Data Source=|DataDirectory|KeywordsDB.sdf;";

                    SQLCon.ConnectionString = ConString;

                    SQLdset = new DataSet();
                    SQLAdp = new SqlCeDataAdapter();

                    SQLCon.Open();

                    string Comm = "SELECT DISTINCT JournalName FROM Journal_Data WHERE Website='Springer'";

                    SqlCeCommand command = new SqlCeCommand(Comm);
                    command.Connection = SQLCon;
                    SQLAdp.SelectCommand = command;

                    SQLAdp.Fill(SQLdset, tableName);


                    SQLCon.Close();


                    if (SQLdset != null)
                    {
                        ;
                        int j = SQLdset.Tables[tableName].Rows.Count;


                        journalData = new Journal[j];
                        ;

                        for (int i = 0; i < j; i++)
                        {
                            DataSet SQLdset2 = new DataSet();
                            SQLCon.Open();

                            Comm = "SELECT * FROM Journal_Data Where JournalName='" + SQLdset.Tables[tableName].Rows[i]["JournalName"].ToString() + "';"; ;

                            SqlCeDataAdapter SQLAdp2 = new SqlCeDataAdapter(); ;
                            SqlCeCommand command2 = new SqlCeCommand(Comm);
                            command2.Connection = SQLCon;
                            SQLAdp2.SelectCommand = command2;


                            SQLAdp2.Fill(SQLdset2, tableName);

                            SQLCon.Close();

                            journalData[i] = new Journal();

                            journalData[i].Name = SQLdset2.Tables[tableName].Rows[0]["JournalName"].ToString();
                            journalData[i].Link = SQLdset2.Tables[tableName].Rows[0]["JournalLink"].ToString();
                            journalData[i].Website = SQLdset2.Tables[tableName].Rows[0]["Website"].ToString();
                            journalData[i].Keywords = SQLdset2.Tables[tableName].Rows[0]["Keywords"].ToString();
                            journalData[i].Submit = SQLdset2.Tables[tableName].Rows[0]["SubmitLink"].ToString();


                        }
                    }
                }
                catch (Exception ec)
                { }
                return journalData;

            }
        void MatchACMandOther(string[] userKeywords)
        {

            string names = "";


            Journal ACM = new Journal();
            string[] splitter = { ".", " ", ":", ",", ";", "'", "\"", "(", ")" };
            Journal[] journals = DataManager.GetACMData();
            float mostmatch = 0;
            foreach (Journal j in journals)
            {

                float match = Comparator.GetStatsACM(j.Keywords.Split(splitter, StringSplitOptions.RemoveEmptyEntries), userKeywords);

                if (match >= 50)
                {
              
                    //mostmatch = match;
                    ACM = j;
                    names += "<br> " + ACM.Name;

                }

            }

            if (names == "")
            {

                Journal3Name.Text = "No match found";
            }
            else
            {
                Journal3Link = ACM.Link;
                Journal3SubLink = ACM.Submit;
                Journal3Name.Text = ACM.Website + ":<br>" + names;
            }

        }
       public static Journal springerKeywords(string uri)
        {
            Journal journalObj = new Journal();

            journalObj.Link = uri;

            string Keywords = null;

           string springer="http://www.springer.com/";

            var html = new HtmlDocument();

           char[] splitter={','};

          
           
           if (uri.Contains(springer))
           {
               uri = uri + "?detailsPage=aboutThis";

               try
               {
                   html.LoadHtml(new WebClient().DownloadString(uri)); // load a string web address


                   // create a root node
                   var root = html.DocumentNode;

                   // Submit Online
                   /////////////////////////// GET Submit Link ////////////////////////
                   var spans = root.Descendants("span");
                   HtmlNode linkNode = null;

                   foreach (var item in spans)
                   {

                       if (item.InnerText == "Submit Online")
                       {
                           linkNode = item;
                           break;

                       }


                   }



                   string SubmitLink = linkNode.ParentNode.Attributes["href"].Value;
                   journalObj.Submit = SubmitLink;

                   ////////////////////////////// end submit link ///////////////////////
                   //////////////////////////////////////////////////////////////////////

                   
                   
                   
                   
                   
                   string Name = root.SelectSingleNode("//h1[@class='headline']").InnerText;
                   journalObj.Name = Name;

                   var node = root.SelectSingleNode("//div[@class='colLeftContentContainer']");

                   var Tags = node.Descendants("a");

                   //  var TagArray = Tags.ToArray();

               

                   // this should run only once
                   foreach (var tag in Tags)
                   {

                       if (tag.FirstChild != null)
                       {
                           HtmlNode spanNode = tag.FirstChild;

                           if (!String.IsNullOrEmpty(spanNode.InnerText))
                           {

                               if (String.IsNullOrEmpty(Keywords))
                                   Keywords = spanNode.InnerText;
                               else
                               Keywords += ", " + spanNode.InnerText;
                           }
                       }
                   }
               }
               catch (Exception ec)
               {

                   string t = ec.Source;

               }
              


           }
           else
           {


               uri = uri + "about";

               try
               {
                   html.LoadHtml(new WebClient().DownloadString(uri)); // load a string web address

                   
                   // create a root node
                   var root = html.DocumentNode;


                   /////////////////////////// GET Submit Link ////////////////////////
                   var spans = root.Descendants("span");
                   HtmlNode linkNode = null;

                   foreach (var item in spans)
                   {

                       if (item.InnerText == "Submit a manuscript")
                       {
                           linkNode = item;
                           break;

                       }


                   }



                   string SubmitLink = linkNode.ParentNode.Attributes["href"].Value;

                   journalObj.Submit = SubmitLink;
                   
                   ////////////////////////////// end submit link ///////////////////////
                   //////////////////////////////////////////////////////////////////////



                   string Website = "Springer";
                   journalObj.Website = Website;
                   

                   ///////////////////////////// Get Aims and scope paragraph ie keywords data ///////////////////

                   var Tags = root.Descendants("div").Where(n => n.GetAttributeValue("class", "").Equals("wrap-inner content"));


                
                   
                   //  var TagArray = Tags.ToArray();

                   string Name = root.SelectSingleNode("//h1").InnerText;
                   Name = Name.Replace("About ", "");

                   journalObj.Name = Name;
                  
                   
                   
                   // this should run only once
                   foreach (var tag in Tags)
                   {


                       HtmlNode spanNode = tag.ChildNodes[9];
                       Keywords = spanNode.InnerText;
                       break;

                   }
               }
               catch (Exception ec)
               {

                   string ecp = ec.Source;

               }
               
           
           
           }
           /////////////////////////////////////////////// end keywords ///////////////////////////////////////
           Keywords = (Keywords);
           journalObj.Keywords = Keywords;
           journalObj.Website = "Springer";

           return journalObj;


        }