Esempio n. 1
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (typeOfCheck.SelectedItem == null)
     {
         MessageBox.Show("Please choose the type of resources to check");
         return;
     }
     this.Enabled = false;
     db _db = new db("GLOBALEDGE_MVCConnectionString");
     var manageURL = "";
     switch (typeOfCheck.SelectedItem.ToString())
     {
         case "Resources":
             _db.ExecuteSqlReader("SELECT uniqueid, url FROM v2_resources WHERE URL IS NOT NULL");
             manageURL = "https://globaledge.msu.edu/Management/Resources/Edit/";
             break;
         case "International Internships":
             _db.ExecuteSqlReader("SELECT internshipid as uniqueid, url FROM Internships");
             manageURL = "https://globaledge.msu.edu/Management/InternationalInternships/InternshipEdit/";
             break;
         default:
             this.Enabled = true;
             return;
     }
     Dictionary<int, string> urls = new Dictionary<int, string>();
     while (_db.Reader.Read())
     {
         urls.Add((int)_db.Reader["uniqueid"], (string)_db.Reader["url"]);
     }
     var counter = urls.Count;
     var width = (100.0 / counter);
     var current = 1;
     System.Threading.Tasks.Parallel.ForEach(urls, i =>
     //foreach(var i in urls)
     {
         progressBar1.Value = Convert.ToInt16(width * current);
         current++;
         try
         {
             HttpWebRequest request = (HttpWebRequest)WebRequest.Create(i.Value);
             request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.3 (KHTML, like Gecko) Chrome/19.0.1061.1 Safari/536.3";
             request.Method = "GET";
             request.Proxy = null;
             request.UseDefaultCredentials = true;
             CookieContainer cc = new CookieContainer();
             request.CookieContainer = cc;
             using (HttpWebResponse resp = (HttpWebResponse)request.GetResponse())
             {
             }
         }
         catch (WebException ex)
         {
             dataGridView1.Rows.Add(new string[] { i.Value, ex.Message, manageURL + i.Key + "?tag=0&section=0" });
         }
     });
     this.Enabled = true;
     progressBar1.Value = 100;
 }
Esempio n. 2
0
        public static void Parse2091(TextBox t, string tableData, int fieldid, int tagid)
        {
            db db = new db(System.Configuration.ConfigurationSettings.AppSettings["db"]);
            db.ParameterAdd("@FieldID", fieldid);
            db.ParameterAdd("@TagID", tagid);
            db.ParameterAdd("@IsEstimate", false);

            var parsedData = Regex.Matches(tableData.Trim(), @"(\w*): (\d{1,3}(\,\d{3})*\.?\d*)\s*deaths\/1,000 live births\s*(\((\d{4})\s*(est.?)?\))?\s*");
            int year = 0;
            double total = 0d;
            string notes = "";
            int c = 0;
            db.SetSqlStoredProcedure();
            for (var i = 0; i < parsedData.Count; i++)
            {
                if (parsedData[i].Groups[1].Value == "total")
                {
                    Double.TryParse(parsedData[i].Groups[2].Value, out total);
                }
                else if (parsedData[i].Groups[1].Value == "note")
                {
                    notes = parsedData[i].Groups[2].Value;
                }
                if (parsedData[i].Groups[5].Value != "")
                {
                    int.TryParse(parsedData[i].Groups[5].Value, out year);
                    if (parsedData[i].Groups[6].Value != "")
                    {
                        db.ParameterEdit("@IsEstimate", true);
                    }
                }

            }
            if (year == 0)
            {
                return;
            }
            db.ParameterAdd("@Value", total);
            db.ParameterAdd("@Year", year);
            db.ParameterAdd("@Note", notes);
            try
            {
                var ex = db.ExecuteSql("CIA_Insert_Data");
                if (ex != null)
                {
                    t.Text += ex.Message + "--->" + Environment.NewLine;
                }
            }
            catch (Exception convEx)
            {
                t.Text += convEx.Message + "-->" + fieldid + Environment.NewLine;
            }
            db.CloseConnection();
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            // Creates two database connections
            db db = new db("DB");
            db dbUpdate = new db("DB");

            // Gets the default Parameters so I can just update instead.
            dbUpdate.ParameterAdd("@Latitude", "");
            dbUpdate.ParameterAdd("@Longitude", "");
            dbUpdate.ParameterAdd("@ZipCode", "");

            // Queries the DB
            var sqlStr = "SELECT ZipCode FROM ZipCodes WHERE ZipCode > 48101";
            var ex = db.ExecuteSqlReader(sqlStr);
            while (db.Reader.Read())
            {
                Console.WriteLine("Updating " + db.Reader[0]);
                // Makes the call to bing. Only could get US to work for now as a zip code was giving me heck.
                HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://dev.virtualearth.net/REST/v1/Locations/US/-/" + db.Reader[0] + "/?key=" + System.Configuration.ConfigurationManager.AppSettings["BingKey"]);
                var resp = req.GetResponse();
                var stream = resp.GetResponseStream();
                var strReader = new StreamReader(stream);
                var str = (strReader.ReadToEnd());
                var data = JsonConvert.DeserializeObject<BingMaps>(str);

                // Update the datbase
                sqlStr = "UPDATE ZipCodes SET Latitude=@Latitude, Longitude=@Longitude WHERE ZipCode=@ZipCode";
                dbUpdate.ParameterEdit("@Latitude", data.resourceSets[0].resources[0].point.coordinates[0]);
                dbUpdate.ParameterEdit("@Longitude", data.resourceSets[0].resources[0].point.coordinates[1]);
                dbUpdate.ParameterEdit("@ZipCode", db.Reader[0]);
                ex = dbUpdate.ExecuteSql(sqlStr);
                if (ex != null)
                {
                    Console.WriteLine("Zip Code: " + db.Reader[0] + " had an error in updating. Error -->" + ex.Message);
                }
                Thread.Sleep(1000);
            }
            dbUpdate.CloseConnection();
            db.CloseConnection();
        }
Esempio n. 4
0
        public static string ParseTableData(string tableData, int fieldid, int tagid)
        {
            var sb = new StringBuilder();
            var db = new db(System.Configuration.ConfigurationSettings.AppSettings["db"]);
            db.ParameterAdd("@FieldID", fieldid);
            db.ParameterAdd("@TagID", tagid);
            db.ParameterAdd("@Value", "");
            db.ParameterAdd("@Year", "");
            db.ParameterAdd("@IsEstimate", "");
            var parsedData = Regex.Split(tableData.Trim(), @"[\r\n]+").ToList();
            int c = 0;
            var note = parsedData.FirstOrDefault(a => a.Trim().StartsWith("note:"));
            var noteRemove = note;
            if (note == null)
            {
                note = "";
            }
            else
            {
                note = note.Replace("note:", "").Trim();
            }
            db.ParameterAdd("@Note", note);
            db.SetSqlStoredProcedure();
            var noteDateMatch = Regex.Matches(note, @".*\(\b(\d{0,2}\s*\w*\s\d{2,4}|\d{4}|FY\d{0,4}\/?\d{0,4})\s*(est.?)?\b.*$", RegexOptions.Singleline);
            string noteDate = "";
            if (noteDateMatch.Count > 0)
            {
                noteDate = parseDate(noteDateMatch[0].Groups[1].Value);
            }
            parsedData.Remove(noteRemove);
            foreach (var i in parsedData)
            {
                var regExString = @"^\$?(-?\d{1,3}(\,\d{3})*\.?\d*)%?\s*(\w*)?.*\(\b(\w*\s\d{1,2},\s?\d{2,4}|\d{0,2}\s*\w*\s\d{2,4}|\d{4}|FY\d{0,4}\/?\d{0,4})\s*(est.?)?\b.*$";
                var matches = Regex.Match(i.Trim(), regExString);
                if (matches.Groups.Count < 2 && noteDate == "")
                {
                    sb.AppendLine("DID NOT MATCH-->" + i.Trim());
                    continue;
                }
                else if(matches.Groups.Count < 2 && noteDate != "")
                {
                    matches = Regex.Match(i.Trim() + " " + note, regExString);
                    if (matches.Groups.Count < 2 && noteDate != "")
                    {
                        sb.AppendLine("2nd Chance DID NOT MATCH-->" + i.Trim());
                        continue;
                    }
                }
                try
                {
                    var value = Convert.ToDecimal(matches.Groups[1].Value);
                    switch (matches.Groups[3].Value.Trim())
                    {
                        case "thousand":
                            value *= 1000m;
                            break;
                        case "million":
                            value *= 1000000m;
                            break;
                        case "billion":
                            value *= 1000000000m;
                            break;
                        case "trillion":
                            value *= 1000000000000m;
                            break;
                    }
                    db.ParameterEdit("@Value", value);
                    var date = parseDate(matches.Groups[4].Value) ?? noteDate;
                    if (date == "")
                    {
                        continue;
                    }
                    db.ParameterEdit("@Year", date);
                    db.ParameterEdit("@IsEstimate", string.IsNullOrEmpty(matches.Groups[5].Value) ? false : true);
                    var ex = db.ExecuteSql("CIA_Insert_Data");
                    if (ex != null)
                    {
                        sb.AppendLine(ex.Message + "--->");
                    }
                }
                catch (Exception convEx)
                {
                    sb.AppendLine(convEx.Message + "-->" + tagid + "--->" + fieldid);

                }
            }
            db.CloseConnection();
            return sb.ToString();
        }
Esempio n. 5
0
        public static void Parse2121(TextBox t, string tableData, int fieldid, int tagid)
        {
            db db = new db(System.Configuration.ConfigurationSettings.AppSettings["db"]);
            db.ParameterAdd("@FieldID", fieldid);
            db.ParameterAdd("@TagID", tagid);
            db.ParameterAdd("@IsEstimate", false);

            var parsedData = Regex.Match(tableData.Trim(), @"(total:)? (\d{1,3}(\,\d{3})*)\s*km.*\b(\d{4})\b\)$*", RegexOptions.Singleline);
            int year = 0;
            double total = 0d;
            string notes = "";
            int c = 0;
            db.SetSqlStoredProcedure();
            if (parsedData.Groups.Count < 1)
            {
                return;
            }
            db.ParameterAdd("@Value", Convert.ToDouble(parsedData.Groups[2].Value));
            db.ParameterAdd("@Year", parsedData.Groups[4].Value);
            db.ParameterAdd("@Note", "");
            try
            {
                var ex = db.ExecuteSql("CIA_Insert_Data");
                if (ex != null)
                {
                    t.Text += ex.Message + "--->" + Environment.NewLine;
                }
            }
            catch (Exception convEx)
            {
                t.Text += convEx.Message + "-->" + fieldid + Environment.NewLine;
            }
            db.CloseConnection();
        }