protected void FixMotherfuckingCommas() { //string[] results = resultString.Split(','); List <MyUser> allUsers = new List <MyUser>(); MyUserModel mu = new MyUserModel(); allUsers = mu.GetAllMyUsers(); foreach (MyUser u in allUsers) { string newResults = ""; bool found = false; List <string> newres = new List <string>(); string newResString = ""; if (u.Results != null) { string oldResults = u.Results; int len = oldResults.Length; string[] oldresarray = oldResults.Split(','); if (len > 3) { for (int j = 0; j < oldresarray.Length; j++) { if (Convert.ToInt32(oldresarray[j]) > 4356) { //newres.Add(oldResults.Substring(j * 4, 4)); if (newResString.Length > 2) { newResString = newResString + "," + oldresarray[j]; } else { newResString = newResString + oldresarray[j]; } } } } MyUser newUse = new MyUser(); newUse.AccountType = u.AccountType; newUse.BillingCycle = u.BillingCycle; newUse.Companies = u.Companies; newUse.Email = u.Email; newUse.FirstName = u.FirstName; newUse.GUI = u.GUI; newUse.ID = u.ID; newUse.LastLogin = u.LastLogin; newUse.LastName = u.LastName; newUse.Newsletter = u.Newsletter; newUse.Results = newResString; newUse.StartDate = u.StartDate; newUse.Triggers = u.Triggers; newUse.UserName = u.UserName; mu.UpdateMyUser(u.ID, newUse); } } }
protected void DeleteFromUsers(string resultString) { string[] results = resultString.Split(','); List <MyUser> allUsers = new List <MyUser>(); MyUserModel mu = new MyUserModel(); allUsers = mu.GetAllMyUsers(); foreach (MyUser u in allUsers) { string newResults = ""; bool found = false; if (u.Results != null) { string oldResults = u.Results; string[] oldResultsArray = oldResults.Split(','); for (int i = 0; i < oldResultsArray.Length; i++) { found = false; for (int j = 0; j < results.Length; j++) { if (results[j] == oldResultsArray[i]) { found = true; } } if (!found) { if (newResults.Length > 2) { newResults = newResults + "," + oldResultsArray[i]; } else { newResults = newResults + oldResultsArray[i]; } } } MyUser newUse = new MyUser(); newUse.AccountType = u.AccountType; newUse.BillingCycle = u.BillingCycle; newUse.Companies = u.Companies; newUse.Email = u.Email; newUse.FirstName = u.FirstName; newUse.GUI = u.GUI; newUse.ID = u.ID; newUse.LastLogin = u.LastLogin; newUse.LastName = u.LastName; newUse.Newsletter = u.Newsletter; newUse.Results = newResults; newUse.StartDate = u.StartDate; newUse.Triggers = u.Triggers; newUse.UserName = u.UserName; mu.UpdateMyUser(u.ID, newUse); } } }
protected void FindAllResults() { CompanyModel cMod = new CompanyModel(); ResultModel rMod = new ResultModel(); MyUserModel muMod = new MyUserModel(); List <Company> myComps = cMod.GetAllCompanies(); List <MyUser> users = muMod.GetAllMyUsers(); string[] myTrigs = new string[7]; myTrigs[0] = "Hiring"; myTrigs[1] = "Merger"; myTrigs[2] = "Sales Growth"; myTrigs[3] = "Contract"; myTrigs[4] = "Training"; myTrigs[5] = "New Location"; myTrigs[6] = "New CFO"; string finalStatus = ""; int numRequests = 0; if ((myComps.Count < 1) || (myComps == null)) { litStatus.Text = "Problem with companies list."; finalStatus += "Problem with companies list."; } foreach (Company c in myComps) { litStatus.Text = "Checking for news about " + c.Name + "."; finalStatus += "Checking for news about " + c.Name + "."; string sear = c.Name; string[] res = MakeRequest(sear); numRequests++; string htmlBody = ""; if (res.Length < 1) { litStatus.Text = "Nothing found for " + c.Name + "."; finalStatus += "Nothing found for " + c.Name + "."; } else { List <int> skips = new List <int>(); string finalTrigger = ""; for (int j = 0; j < res.Length; j = j + 3) { string title = res[j]; string desc = res[j + 2]; string trig = TestRelevance(c.Name, title, desc); if ((trig == "False") || (trig == "") || (trig == null)) { skips.Add(j); skips.Add(j + 1); skips.Add(j + 2); } else { finalTrigger = trig; } } litStatus.Text = "Creating new result for " + c.Name + "."; finalStatus += "Creating new result for " + c.Name + "."; Result newRes = new Result(); string myComp = c.Name; newRes.Company = myComp; newRes.DateSearched = DateTime.Now; //FIX THIS newRes.Triggers = finalTrigger; //FIX THIS htmlBody += "<ul>"; for (int j = 0; j < res.Length; j = j + 3) { if (!skips.Contains(j)) { htmlBody += "<li>" + "<a href=\"" + res[j + 1] + "\">" + res[j] + "</a>" + "<p style=\"display:none;\">" + res[j + 2] + "</p>" + "</li>"; } if (j == (res.Length - 3)) { htmlBody += "</ul>"; } } //For if ((htmlBody == "<ul></ul>") || (HasDuplicates(newRes))) { //do nothing } else { newRes.BodyText = htmlBody; rMod.InsertResult(newRes); //Put result in user's shit foreach (MyUser m in users) { string uComps = m.Companies; if ((myComp != null) && (uComps != null) && (uComps.Contains(myComp)) && (m.Triggers.Contains(finalTrigger))) { string resultString = m.Results; string newResultString = ""; if ((resultString == null) || (resultString == "")) { newResultString = newRes.ID.ToString(); } else { newResultString = newRes.ID.ToString() + "," + resultString; } MyUser newUse = new MyUser(); newUse.AccountType = m.AccountType; newUse.BillingCycle = m.BillingCycle; newUse.Companies = m.Companies; newUse.Email = m.Email; newUse.FirstName = m.FirstName; newUse.GUI = m.GUI; newUse.ID = m.ID; newUse.LastLogin = m.LastLogin; newUse.LastName = m.LastName; newUse.Newsletter = m.Newsletter; newUse.Results = newResultString; newUse.StartDate = m.StartDate; newUse.Triggers = m.Triggers; newUse.UserName = m.UserName; muMod.UpdateMyUser(m.ID, newUse); } //if ucomps } //foreach } //end else } //if res.length } // foreach Company c in comps finalStatus += "This operation took " + numRequests.ToString() + " requests."; litFinalStatus.Text = finalStatus; } //FindAllResults()