protected void Page_Load(object sender, EventArgs e) { if (!_authority.HasPermission(Permission.CanValidateActivistEmail, Organization.PPSEid, -1, Authorization.Flag.AnyGeographyExactOrganization)) { Master.CurrentPageProhibited = true; } if (IsPostBack && TextBox1.Text.Trim() != "") { int noOfMemberActivist = 0; int noOfNonMemberActivist = 0; int noMemberships = 0; BasicPerson[] persons = PirateDb.GetDatabase().GetPeopleFromEmail(TextBox1.Text.Trim()); foreach (BasicPerson bp in persons) { Person p = Person.FromIdentity(bp.Identity); Memberships msList = p.GetMemberships(); if (msList.Count > 0) { ++noMemberships; if ((p.IsActivist)) { ++noOfMemberActivist; } } else { if ((p.IsActivist)) { ++noOfNonMemberActivist; } ; } } string format = litResultTemplate.Text; litResult.Text = string.Format(format, noMemberships.ToString(), noOfMemberActivist.ToString(), noOfNonMemberActivist.ToString()); } this.Form.DefaultButton = Button1.UniqueID; }
protected void Button1_Click(object sender, EventArgs e) { int col_firstNames = 0; int col_lastName = 1; int col_dateOfBirth = 2; int col_email = 3; int col_municipality = 4; int col_address = 5; int col_postalCode = 6; int col_city = 7; int col_phone = 8; int col_dateJoined = 9; int col_active = 10; int currentRow = -1; int currentImported = 0; DateTime T0 = DateTime.Now; Dictionary <string, BasicCity> postcodes = PirateDb.GetDatabase().GetCitiesPerPostalCode(loadCntry.Identity); Dictionary <string, BasicCity> cityPerName = new Dictionary <string, BasicCity>(); Dictionary <int, BasicCity> cityPerId = new Dictionary <int, BasicCity>(); foreach (BasicCity bc in postcodes.Values) { cityPerName[bc.Name.ToLower().Replace(" ", "")] = bc; cityPerId[bc.Identity] = bc; } People allpeople = People.GetAll(); Dictionary <string, Person> peoplePerKey = new Dictionary <string, Person>(); foreach (Person p in allpeople) { peoplePerKey[p.Email.ToLower().Replace(" ", "") + p.Birthdate.ToString("yyMMdd")] = p; } Memberships memberships = Memberships.ForOrganization(currentOrg); Dictionary <int, Membership> membershipsDict = new Dictionary <int, Membership>(); foreach (Membership ms in memberships) { membershipsDict[ms.PersonId] = ms; } string[] rows = TextBoxImport.Text.Replace("\r\n", "\n").Split('\n'); using (TransactionScope txScope = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 30, 0))) { foreach (string row in rows) { ++currentRow; string[] cols = (row + "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t").Split('\t'); Geography mainGeo = null; string name = cols[col_firstNames] + " " + cols[col_lastName]; if (!Formatting.ValidateEmailFormat(cols[col_email])) { AddError(currentRow, "Bad email format:" + cols[col_email]); continue; } BasicCity foundCity = null; Dictionary <int, Geography> geos = new Dictionary <int, Geography>(); string pcode = cols[col_postalCode].Trim(); if (pcode != "") { while (pcode.Length < loadCntry.PostalCodeLength) { pcode = "0" + pcode; } if (!postcodes.ContainsKey(pcode)) { AddError(currentRow, "Invalid postal code:" + pcode); } else { foundCity = postcodes[pcode]; mainGeo = Geography.FromIdentity(foundCity.GeographyId); geos[foundCity.GeographyId] = mainGeo; } } else if (cols[col_city].Trim() != "") { if (!cityPerName.ContainsKey(cols[col_city].ToLower().Replace(" ", ""))) { AddError(currentRow, "Invalid postal code:" + pcode); } else { foundCity = cityPerName[cols[col_city].ToLower().Replace(" ", "")]; mainGeo = Geography.FromIdentity(foundCity.GeographyId); geos[foundCity.GeographyId] = mainGeo; } } foreach (Geography g in geotree) { string[] names = g.Name.ToLower().Replace(" ", "").Split('/'); foreach (string partName in names) { if (partName == cols[col_municipality].ToLower().Replace(" ", "")) { mainGeo = g; geos[g.Identity] = g; } } } if (geos.Count == 0 || geos.Count > 1) { AddError(currentRow, "Warning only: can not find a specific local geography"); } DateTime dob = NormalizeDate(cols[col_dateOfBirth]); DateTime doj = NormalizeDate(cols[col_dateJoined]); string key = cols[col_email].ToLower().Replace(" ", "") + dob.ToString("yyMMdd"); Person currentPerson = null; if (!peoplePerKey.ContainsKey(key)) { if (mainGeo == null) { mainGeo = loadCntry.Geography; } currentPerson = Person.Create(name, cols[col_email], "ABCABCABCABC", cols[col_phone], cols[col_address], pcode, cols[col_city], loadCntry.Code, dob, PersonGender.Unknown); currentPerson.Geography = mainGeo; PWLog.Write(PWLogItem.Person, currentPerson.Identity, PWLogAction.PersonCreated, "Created Person from Import", "Import for " + currentOrg.Name); } else { currentPerson = peoplePerKey[key]; AddError(currentRow, "Warning only: Person with email already existed "); if (currentPerson.Birthdate < new DateTime(1901, 1, 1)) { currentPerson.Birthdate = dob; } if (currentPerson.Phone.Length < cols[col_phone].Length) { currentPerson.Phone = cols[col_phone]; } if (currentPerson.Street.Length < cols[col_address].Length) { currentPerson.Street = cols[col_address]; } if (currentPerson.PostalCode.CompareTo(pcode) < 0) { currentPerson.PostalCode = pcode; } if (currentPerson.CityName.Length < cols[col_city].Length) { currentPerson.CityName = cols[col_city]; } if (mainGeo != null && mainGeo.Identity != currentPerson.GeographyId) { currentPerson.Geography = mainGeo; } } // add membership if (!membershipsDict.ContainsKey(currentPerson.Identity)) { Membership newMs = Membership.Import(currentPerson, currentOrg, doj, nowValue.AddYears(100)); newMs.SetPaymentStatus(MembershipPaymentStatus.PaymentRecieved, nowValue); } // add activist if (cols[col_active] == "1") { currentPerson.CreateActivist(true, true); PWLog.Write(currentPerson, PWLogItem.Person, currentPerson.Identity, PWLogAction.ActivistJoin, "New activist joined.", "Import for " + currentOrg.Name); } ++currentImported; } txScope.Complete(); } StringBuilder sb = new StringBuilder(); sb.AppendLine("ProcessTime= " + Math.Round(DateTime.Now.Subtract(T0).TotalSeconds)); sb.AppendLine("Rows read= " + currentRow); sb.AppendLine("Rows imported= " + currentImported); sb.AppendLine("Errors and warnings"); foreach (int row in errRows.Keys) { sb.AppendLine("Line: " + row); sb.AppendLine(rows[row]); foreach (string err in errRows[row]) { sb.AppendLine(" " + err); } sb.AppendLine(""); } TextBoxResult.Text = sb.ToString(); }
SeriesCollection GetAgeGenderData(OrganizationMetadata metadata) { int orgId = metadata.OrganizationId; bool recurseTree = metadata.Recursive; Series seriesMale = new Series(); Series seriesFemale = new Series(); seriesMale.Name = "Male"; seriesFemale.Name = "Female"; Memberships memberships = null; if (recurseTree) { memberships = Memberships.ForOrganizations(Organization.FromIdentity(orgId).GetTree()); } else { memberships = Memberships.ForOrganization(Organization.FromIdentity(orgId)); } BasicPerson[] allPeople = PirateDb.GetDatabase().GetAllPeople(); Dictionary <int, int> geoLookup = new Dictionary <int, int>(); Dictionary <int, PersonGender> genderLookup = new Dictionary <int, PersonGender>(); Dictionary <int, int> birthYearLookup = new Dictionary <int, int>(); Dictionary <int, bool> personLookup = new Dictionary <int, bool>(); foreach (BasicPerson person in allPeople) { geoLookup[person.Identity] = person.GeographyId; genderLookup[person.Identity] = person.IsMale ? PersonGender.Male : PersonGender.Female; birthYearLookup[person.Identity] = person.Birthdate.Year; } int[] male = new int[200]; int[] female = new int[200]; foreach (Membership membership in memberships) { int birthYear = 0; PersonGender gender = PersonGender.Unknown; if (personLookup.ContainsKey(membership.PersonId)) { continue; // If a person was already counted, do not count again } if (genderLookup.ContainsKey(membership.PersonId) && (membership.OrganizationId == orgId || (recurseTree && membership.Organization.Inherits(orgId)))) { birthYear = birthYearLookup[membership.PersonId]; gender = genderLookup[membership.PersonId]; int index = birthYear - 1900; if (index < 30 || index >= 100) { index = 90; // Put invalid years on 1990, where it won't show up in the noise } if (gender == PersonGender.Male) { male[index]++; } else { female[index]++; } personLookup[membership.PersonId] = true; } } Element newElement = new Element(); for (int yearIndex = 30; yearIndex < 100; yearIndex++) { newElement = new Element(); newElement.Name = (1900 + yearIndex).ToString(); newElement.YValue = male[yearIndex]; seriesMale.Elements.Add(newElement); newElement = new Element(); newElement.Name = (1900 + yearIndex).ToString(); newElement.YValue = female[yearIndex]; seriesFemale.Elements.Add(newElement); } seriesMale.DefaultElement.Color = Color.Blue; seriesFemale.DefaultElement.Color = Color.Red; SeriesCollection collection = new SeriesCollection(); collection.Add(seriesFemale); collection.Add(seriesMale); return(collection); }
SeriesCollection GetBlogInfluenceData(DateTime pieDate) { Dictionary <PoliticalAffiliation, Color> colorLookup = new Dictionary <PoliticalAffiliation, Color>(); Dictionary <PoliticalAffiliation, int> score = new Dictionary <PoliticalAffiliation, int>(); colorLookup[PoliticalAffiliation.Brown] = Color.DarkGoldenrod; colorLookup[PoliticalAffiliation.Conservative] = Color.Khaki; colorLookup[PoliticalAffiliation.IndependentBlue] = Color.LightBlue; colorLookup[PoliticalAffiliation.IndependentGreen] = Color.LightGreen; colorLookup[PoliticalAffiliation.IndependentRed] = Color.Salmon; colorLookup[PoliticalAffiliation.LoyalBlue] = Color.DarkBlue; colorLookup[PoliticalAffiliation.LoyalGreen] = Color.DarkGreen; colorLookup[PoliticalAffiliation.LoyalRed] = Color.DarkRed; colorLookup[PoliticalAffiliation.NotPolitical] = Color.LightGray; colorLookup[PoliticalAffiliation.Pirate] = Color.FromArgb(0x66, 0, 0x87); colorLookup[PoliticalAffiliation.Unknown] = Color.DarkGray; BasicMedium[] politicalBlogs = PirateDb.GetDatabase().GetBlogTopList(pieDate); int position = 0; foreach (BasicMedium blog in politicalBlogs) { position++; int thisScore = 51 - position; if (blog.PoliticalAffiliation == PoliticalAffiliation.Unknown) { Person.FromIdentity(1).SendNotice("Unknown political affiliation: " + blog.Name + " (" + blog.Identity.ToString() + ")", "Unknown political affiliation for blog: " + blog.Name + "\r\n", 1); } if (score.ContainsKey(blog.PoliticalAffiliation)) { score[blog.PoliticalAffiliation] += thisScore; } else { score[blog.PoliticalAffiliation] = thisScore; } } SeriesCollection collection = new SeriesCollection(); foreach (PoliticalAffiliation key in score.Keys) { Series series = new Series(); series.Name = key.ToString(); series.DefaultElement.Color = colorLookup[key]; Element newElement = new Element(); newElement.YValue = score[key]; series.Elements.Add(newElement); collection.Add(series); } return(collection); }
private void BuildTable() { tab.Rows.Clear(); OutboundMails mails = OutboundMails.FromArray(PirateDb.GetDatabase().GetOutboundMailQueue(500)); TableRow row = new TableRow(); tab.Rows.Add(row); TableCell c = new TableCell(); row.Cells.Add(c); c.Text = "Template"; c = new TableCell(); row.Cells.Add(c); c.Text = "Title"; c = new TableCell(); row.Cells.Add(c); c.Text = "Release time"; c = new TableCell(); row.Cells.Add(c); c.Text = "Time until release"; c = new TableCell(); row.Cells.Add(c); c.Text = "Counts"; c = new TableCell(); row.Cells.Add(c); c.Text = "Started"; foreach (OutboundMail mail in mails) { TypedMailTemplate tmpl = null; if (mail.MailType != 0) { tmpl = TypedMailTemplate.FromName(mail.Title); tmpl.Initialize("SE", mail.OrganizationId, mail, ""); tmpl.InsertAllPlaceHoldersToTemplate(); } row = new TableRow(); tab.Rows.Add(row); if (mail.MailType != 0) { c = new TableCell(); row.Cells.Add(c); c.Text = mail.Title; c = new TableCell(); row.Cells.Add(c); c.Text = tmpl.Template.TemplateTitleText; } else { c = new TableCell(); row.Cells.Add(c); c.Text = "none"; c = new TableCell(); row.Cells.Add(c); c.Text = mail.Title; } c = new TableCell(); row.Cells.Add(c); c.Text = mail.ReleaseDateTime.ToString(); if ((new DateTime(1970, 1, 1)) == mail.StartProcessDateTime && mail.ReleaseDateTime < DateTime.Now) { c.ForeColor = System.Drawing.Color.Red; c.Font.Bold = true; } c = new TableCell(); row.Cells.Add(c); c.Text = Math.Round((DateTime.Now.Subtract(mail.ReleaseDateTime).TotalMinutes)).ToString(); c = new TableCell(); row.Cells.Add(c); c.Text = mail.RecipientCount.ToString(); c.Text += " / " + mail.RecipientsSuccess.ToString(); c.Text += " / " + mail.RecipientsFail.ToString(); c = new TableCell(); row.Cells.Add(c); c.Text = mail.StartProcessDateTime.ToString(); } }
protected void Page_Load(object sender, EventArgs e) { string fileName = DateTime.Now.ToString("yyyyMMdd_HHmm") + ".txt"; DateTime specificDate = DateTime.MinValue; DateTime yearLimit = DateTime.Today.AddYears(-1); if (Request["Date"] != null) { DateTime.TryParse(Request["Date"].ToString(), out specificDate); if (specificDate != DateTime.MinValue) { fileName = "[" + specificDate.ToString("yyyyMMdd_HHmm") + "]" + fileName; specificDate = specificDate.AddDays(1); yearLimit = specificDate.AddYears(-1); specificDate = specificDate.AddSeconds(-1); } } if (Request.Browser.Browser == "IE") { fileName = Server.UrlPathEncode(fileName); if (fileName != null) { fileName = fileName.Replace(@"+", @"%20"); } } int org = Organization.UPSEid; Organization organization = Organization.FromIdentity(org); fileName = organization.NameShort + fileName; Response.ContentType = "text/plain"; Response.ContentEncoding = Encoding.GetEncoding(1252); //Response.ContentType = "application/octet-stream"; Response.AddHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\";"); if (_authority.HasRoleAtOrganization(organization, new RoleType[] { RoleType.OrganizationChairman, RoleType.OrganizationSecretary }, Authorization.Flag.AnyGeographyExactOrganization) || _authority.HasRoleType(RoleType.SystemAdmin)) { People ThePeople = People.GetAll().RemoveUnlisted(); Memberships MembershipsList = null; if (Request["Date"] != null) { MembershipsList = Memberships.FromArray(PirateDb.GetDatabase().GetMemberships()); // gets ALL memberships } else { MembershipsList = Memberships.ForOrganizations(Organization.FromIdentity(org).GetTree()); } Dictionary <int, string> GeoDistriktForGeo = new Dictionary <int, string>(); Dictionary <int, string> OrgDistriktForOrg = new Dictionary <int, string>(); Dictionary <int, Memberships> ActiveMemberships = new Dictionary <int, Memberships>(); foreach (Membership ms in MembershipsList) { if (ms.OrganizationId == org || ms.Organization.Inherits(org)) { if (specificDate != DateTime.MinValue) { if ((ms.Active || ms.DateTerminated > specificDate) && // Rick replaced "DateTerminated.HasValue" with "Active=1" ms.Expires > specificDate && ms.MemberSince <= specificDate) { if (!ActiveMemberships.ContainsKey(ms.PersonId)) { ActiveMemberships.Add(ms.PersonId, new Memberships()); } ActiveMemberships[ms.PersonId].Add(ms); } } else if (ms.Active) { if (!ActiveMemberships.ContainsKey(ms.PersonId)) { ActiveMemberships.Add(ms.PersonId, new Memberships()); } ActiveMemberships[ms.PersonId].Add(ms); } } } List <int> idlist = new List <int>(); Dictionary <int, List <BasicPWEvent> > personLogs = new Dictionary <int, List <BasicPWEvent> >(); foreach (int pId in ActiveMemberships.Keys) { idlist.Add(pId); if (idlist.Count > 500) { FetchBatchOfLogs(ref specificDate, ref yearLimit, idlist, personLogs); idlist = new List <int>(); } } if (idlist.Count > 0) { FetchBatchOfLogs(ref specificDate, ref yearLimit, idlist, personLogs); } StringBuilder sb = new StringBuilder(); sb.Append("Identity"); sb.Append("\tName"); sb.Append("\tEmail"); sb.Append("\tStreet"); sb.Append("\tPostalCode"); sb.Append("\tCity"); sb.Append("\tCountry.Name"); sb.Append("\tPhone"); sb.Append("\tBirthdate"); sb.Append("\tGender"); sb.Append("\tGeography.Name"); sb.Append("\tGeography.District"); sb.Append("\tOrganization.Name"); sb.Append("\tOrganization.District"); sb.Append("\tMembership.start"); sb.Append("\tMembership.until"); sb.Append("\tRenewed"); sb.Append("\tType"); sb.Append("\tby"); sb.Append("\tfrom"); sb.Append("\r\n"); foreach (Person p in ThePeople) { if (ActiveMemberships.ContainsKey(p.PersonId)) { Memberships pMemberships = ActiveMemberships[p.PersonId]; foreach (Membership m in pMemberships) { if (!GeoDistriktForGeo.ContainsKey(p.GeographyId)) { Geography currentGeoDistr = null; GeoDistriktForGeo[p.GeographyId] = "N/A"; if (p.GeographyId != 0) { try { Geography previous = p.Geography; if (p.Geography.ParentGeographyId != 0) { currentGeoDistr = p.Geography.Parent; } while (currentGeoDistr != null && currentGeoDistr.Identity != 0 && currentGeoDistr.Identity != Geography.SwedenId && currentGeoDistr.Identity != Geography.RootIdentity) { previous = currentGeoDistr; if (currentGeoDistr.ParentGeographyId == 0) { currentGeoDistr = null; } else { currentGeoDistr = currentGeoDistr.Parent; } } if (previous != null) { GeoDistriktForGeo[p.GeographyId] = previous.Name; } } catch (Exception ex) { GeoDistriktForGeo[p.GeographyId] = "n/a"; } } } if (!OrgDistriktForOrg.ContainsKey(m.OrganizationId)) { Organization currentOrgDistr = null; OrgDistriktForOrg[m.OrganizationId] = "N/A"; Organization previous = m.Organization; currentOrgDistr = m.Organization.Parent;; while (currentOrgDistr != null && currentOrgDistr.Identity != 0 && currentOrgDistr.Identity != org && currentOrgDistr.Identity != Organization.RootIdentity) { previous = currentOrgDistr; if (currentOrgDistr.ParentOrganizationId == 0) { currentOrgDistr = null; } else { currentOrgDistr = currentOrgDistr.Parent; } } if (previous != null) { OrgDistriktForOrg[m.OrganizationId] = previous.NameShort; } } sb.Append(p.Identity); sb.Append("\t" + p.Name.Replace("\t", "")); sb.Append("\t" + p.Email.Replace("\t", "")); sb.Append("\t" + p.Street.Replace("\t", "")); sb.Append("\t" + p.PostalCode.Replace("\t", "")); sb.Append("\t" + p.CityName.Replace("\t", "")); sb.Append("\t" + p.Country.Name.Replace("\t", "")); sb.Append("\t" + p.Phone.Replace("\t", "")); sb.Append("\t" + p.Birthdate); sb.Append("\t" + p.Gender); sb.Append("\t" + p.Geography.Name); sb.Append("\t" + GeoDistriktForGeo[p.GeographyId]); sb.Append("\t" + m.Organization.Name); sb.Append("\t" + OrgDistriktForOrg[m.OrganizationId]); sb.Append("\t" + m.MemberSince); if (!m.Active) { sb.Append("\t" + m.DateTerminated); } else { sb.Append("\t" + m.Expires); } if (personLogs.ContainsKey(p.Identity)) { bool found = false; foreach (BasicPWEvent log in personLogs[p.Identity]) { if (log.OrganizationId == m.OrganizationId) { sb.Append("\t" + log.DateTime); sb.Append("\t" + log.EventType); sb.Append("\t" + log.ActingPersonId); sb.Append("\t" + log.ParameterText); found = true; break; } } if (!found) { sb.Append("\t\t\t\t"); } } else { sb.Append("\t\t\t\t"); } sb.Append("\r\n"); } } } Response.Write(sb.ToString()); } }
SeriesCollection GetAgeGenderData() { string orgIdString = Request.QueryString["OrgId"]; string recurseTreeString = Request.QueryString["RecurseTree"]; int orgId = Organization.PPSEid; bool recurseTree = false; if (orgIdString != null) { orgId = Int32.Parse(orgIdString); } if (recurseTreeString == "1") { recurseTree = true; } Chart.ChartArea.YAxis.Label.Text = "Medlems\xE5ldrar och k\xF6n - " + Organization.FromIdentity(orgId).Name; Series seriesMale = new Series(); Series seriesFemale = new Series(); seriesMale.Name = "M\xE4n"; seriesFemale.Name = "Kvinnor"; Memberships memberships = null; if (recurseTree) { memberships = Memberships.ForOrganizations(Organization.FromIdentity(orgId).GetTree()); } else { memberships = Memberships.ForOrganization(Organization.FromIdentity(orgId)); } BasicPerson[] allPeople = PirateDb.GetDatabase().GetAllPeople(); Dictionary <int, int> geoLookup = new Dictionary <int, int>(); Dictionary <int, PersonGender> genderLookup = new Dictionary <int, PersonGender>(); Dictionary <int, int> birthYearLookup = new Dictionary <int, int>(); Dictionary <int, int> personLookup = new Dictionary <int, int>(); foreach (BasicPerson person in allPeople) { geoLookup[person.Identity] = person.GeographyId; genderLookup[person.Identity] = person.IsMale ? PersonGender.Male : PersonGender.Female; birthYearLookup[person.Identity] = person.Birthdate.Year; } int[] male = new int[200]; int[] female = new int[200]; foreach (Membership membership in memberships) { int birthYear = 0; PersonGender gender = PersonGender.Unknown; if (genderLookup.ContainsKey(membership.PersonId) && !personLookup.ContainsKey(membership.PersonId) && (membership.OrganizationId == orgId || (recurseTree && membership.Organization.Inherits(orgId)))) { personLookup[membership.PersonId] = 1; birthYear = birthYearLookup[membership.PersonId]; gender = genderLookup[membership.PersonId]; if (birthYear > 1900 && birthYear < (1900 + 200)) { if (gender == PersonGender.Male) { male[birthYear - 1900]++; } else { female[birthYear - 1900]++; } } } } Element newElement = new Element(); for (int yearIndex = 30; yearIndex <= 100; yearIndex++) { newElement = new Element(); newElement.Name = (1900 + yearIndex).ToString(); newElement.YValue = male[yearIndex]; seriesMale.Elements.Add(newElement); newElement = new Element(); newElement.Name = (1900 + yearIndex).ToString(); newElement.YValue = female[yearIndex]; seriesFemale.Elements.Add(newElement); } seriesMale.DefaultElement.Color = Color.Blue; seriesFemale.DefaultElement.Color = Color.Red; SeriesCollection collection = new SeriesCollection(); collection.Add(seriesFemale); collection.Add(seriesMale); return(collection); }