public DemographyView(AdminLevelDemography d, AdminLevel a, bool canViewEdit) : base() { canEdit = canViewEdit; adminLevel = a; this.model = d; InitializeComponent(); }
private void Demo_Load(object sender, EventArgs e) { if (!DesignMode) { adminLevelBoundToGlobalTree = adminLevel; adminLevel = Util.DeepClone<AdminLevel>(adminLevel); Localizer.TranslateControl(this); demo = new DemoRepository(); if (model == null) { model = new AdminLevelDemography(); model.AdminLevelId = adminLevel.Id; } else originalDate = model.DateDemographyData; lblType.Text = Translations.Demography; StatusChanged(model.UpdatedBy); if (!canEdit) { btnTopSave.Visible = false; btnBottomSave.Visible = false; } if(!Roles.IsUserInRole(ApplicationData.Instance.CurrentUser.UserName, "RoleDataEnterer") && !Roles.IsUserInRole(ApplicationData.Instance.CurrentUser.UserName, "RoleAdmin")) { lnkEditAdminLevelUnit.Visible = false; btnTopSave.Visible = false; btnBottomSave.Visible = false; } bsDemo.DataSource = model; BindAdminLevel(); } }
public ImportResult ImportData(string filePath, int userId, bool importDemography, bool doAggregate, int rows, AdminLevel filterLevel, DateTime dateReported) { try { System.Globalization.CultureInfo cultureEn = new System.Globalization.CultureInfo("en-US"); filterBy = filterLevel; GetParams(); DataSet ds = LoadDataFromFile(filePath); if (ds.Tables.Count == 0) return new ImportResult(TranslationLookup.GetValue("NoDataFound")); string errorMessage = ""; Dictionary<string, int> parentIds = demo.GetParentIds(filterBy, dropdownBy); List<AdminLevel> levels = new List<AdminLevel>(); foreach (DataRow row in ds.Tables[0].Rows) { int parentId = 1; if (parentIds.Count > 0) if (parentIds.ContainsKey(row["* " + dropdownBy.DisplayName].ToString().Trim().ToLower())) parentId = parentIds[row["* " + dropdownBy.DisplayName].ToString().Trim().ToLower()]; var adminLevel = new AdminLevel { AdminLevelTypeId = locationType.Id, LevelNumber = locationType.LevelNumber, Name = row["* " + locationType.DisplayName].ToString(), UrbanOrRural = row[TranslationLookup.GetValue("UrbanOrRural")].ToString(), ParentId = parentId, CurrentDemography = null }; double d1 = 0; if (double.TryParse(row[TranslationLookup.GetValue("LatWho")].ToString(), NumberStyles.Any, cultureEn, out d1)) adminLevel.LatWho = d1; if (double.TryParse(row[TranslationLookup.GetValue("LngWho")].ToString(), NumberStyles.Any, cultureEn, out d1)) adminLevel.LngWho = d1; if (importDemography) { var demography = new AdminLevelDemography(); demography.Notes = row[TranslationLookup.GetValue("Notes")].ToString(); demography.DateDemographyData = dateReported; // need to do the required validation, do all and then show errors int i = 0; if (int.TryParse(row["* " + TranslationLookup.GetValue("YearCensus")].ToString(), out i)) demography.YearCensus = i; double d = 0; int integer = 0; if (double.TryParse(row["* " + TranslationLookup.GetValue("GrowthRate")].ToString(), NumberStyles.Any, cultureEn, out d)) demography.GrowthRate = d; if (double.TryParse(row[TranslationLookup.GetValue("PercentRural")].ToString(), NumberStyles.Any, cultureEn, out d)) demography.PercentRural = d; if (TryParseAsIntThenDouble(row["* " + TranslationLookup.GetValue("TotalPopulation")].ToString(), NumberStyles.Any, cultureEn, out integer)) demography.TotalPopulation = integer; if (TryParseAsIntThenDouble(row[TranslationLookup.GetValue("Pop0Month")].ToString(), NumberStyles.Any, cultureEn, out integer)) demography.Pop0Month = integer; if (TryParseAsIntThenDouble(row[TranslationLookup.GetValue("PopPsac")].ToString(), NumberStyles.Any, cultureEn, out integer)) demography.PopPsac = integer; if (TryParseAsIntThenDouble(row["* " + TranslationLookup.GetValue("PopSac")].ToString(), NumberStyles.Any, cultureEn, out integer)) demography.PopSac = integer; if (TryParseAsIntThenDouble(row[TranslationLookup.GetValue("Pop5yo")].ToString(), NumberStyles.Any, cultureEn, out integer)) demography.Pop5yo = integer; if (TryParseAsIntThenDouble(row[TranslationLookup.GetValue("PopAdult")].ToString(), NumberStyles.Any, cultureEn, out integer)) demography.PopAdult = integer; if (TryParseAsIntThenDouble(row[TranslationLookup.GetValue("PopFemale")].ToString(), NumberStyles.Any, cultureEn, out integer)) demography.PopFemale = integer; if (TryParseAsIntThenDouble(row[TranslationLookup.GetValue("PopMale")].ToString(), NumberStyles.Any, cultureEn, out integer)) demography.PopMale = integer; adminLevel.CurrentDemography = demography; } var demographyErrors = (adminLevel.CurrentDemography != null && !adminLevel.CurrentDemography.IsValid()) ? adminLevel.CurrentDemography.GetAllErrors(true) : ""; var adminErrors = !adminLevel.IsValid() ? adminLevel.GetAllErrors(true) : ""; if (!string.IsNullOrEmpty(demographyErrors) && !string.IsNullOrEmpty(adminErrors)) errorMessage += string.Format(TranslationLookup.GetValue("ImportErrors"), adminLevel.Name) + adminErrors + "," + demographyErrors + Environment.NewLine; else if (!string.IsNullOrEmpty(demographyErrors) || !string.IsNullOrEmpty(adminErrors)) errorMessage += string.Format(TranslationLookup.GetValue("ImportErrors"), adminLevel.Name) + adminErrors + demographyErrors + Environment.NewLine; levels.Add(adminLevel); } // Validation rules and errors if (levels.Count != rows) errorMessage = string.Format(TranslationLookup.GetValue("ImportRecordsDontMatch"), rows, levels.Count) + Environment.NewLine + errorMessage; if (!string.IsNullOrEmpty(errorMessage)) return new ImportResult(TranslationLookup.GetValue("ImportErrorHeader") + Environment.NewLine + errorMessage); demo.BulkImportAdminLevelsForLevel(levels, locationType.Id, userId); if (doAggregate) demo.AggregateUp(locationType, dateReported, userId, null, countryDemoId); int rec = levels.Count; return new ImportResult { WasSuccess = true, Count = rec, Message = string.Format(TranslationLookup.GetValue("ImportSuccess"), rec) }; } catch (Exception ex) { return new ImportResult(TranslationLookup.GetValue("UnexpectedException") + ex.Message); } }
public ImportResult ImportData(string filePath, int userId, DateTime dateReported, bool doAggregate) { try { System.Globalization.CultureInfo cultureEn = new System.Globalization.CultureInfo("en-US"); DataSet ds = LoadDataFromFile(filePath); if (ds.Tables.Count == 0) return new ImportResult(TranslationLookup.GetValue("NoDataFound")); string errorMessage = ""; List<AdminLevelDemography> demos = new List<AdminLevelDemography>(); foreach (DataRow row in ds.Tables[0].Rows) { var demography = new AdminLevelDemography(); if (ds.Tables[0].Columns.Contains("* " + TranslationLookup.GetValue("ID") + "#")) demography.Id = Convert.ToInt32(row["* " + TranslationLookup.GetValue("ID") + "#"]); demography.AdminLevelId = Convert.ToInt32(row["* " + TranslationLookup.GetValue("Location") + "#"]); demography.Notes = row[TranslationLookup.GetValue("Notes")].ToString(); demography.DateDemographyData = dateReported; // need to do the required validation, do all and then show errors int i = 0; if (int.TryParse(row["* " + TranslationLookup.GetValue("YearCensus")].ToString(), out i)) demography.YearCensus = i; double d = 0; int integer = 0; if (double.TryParse(row["* " + TranslationLookup.GetValue("GrowthRate")].ToString(), NumberStyles.Any, cultureEn, out d)) demography.GrowthRate = d; if (double.TryParse(row[TranslationLookup.GetValue("PercentRural")].ToString(), NumberStyles.Any, cultureEn, out d)) demography.PercentRural = d; if (TryParseAsIntThenDouble(row["* " + TranslationLookup.GetValue("TotalPopulation")].ToString(), NumberStyles.Any, cultureEn, out integer)) demography.TotalPopulation = integer; if (TryParseAsIntThenDouble(row[TranslationLookup.GetValue("Pop0Month")].ToString(), NumberStyles.Any, cultureEn, out integer)) demography.Pop0Month = integer; if (TryParseAsIntThenDouble(row[TranslationLookup.GetValue("PopPsac")].ToString(), NumberStyles.Any, cultureEn, out integer)) demography.PopPsac = integer; if (TryParseAsIntThenDouble(row["* " + TranslationLookup.GetValue("PopSac")].ToString(), NumberStyles.Any, cultureEn, out integer)) demography.PopSac = integer; if (TryParseAsIntThenDouble(row[TranslationLookup.GetValue("Pop5yo")].ToString(), NumberStyles.Any, cultureEn, out integer)) demography.Pop5yo = integer; if (TryParseAsIntThenDouble(row[TranslationLookup.GetValue("PopAdult")].ToString(), NumberStyles.Any, cultureEn, out integer)) demography.PopAdult = integer; if (TryParseAsIntThenDouble(row[TranslationLookup.GetValue("PopFemale")].ToString(), NumberStyles.Any, cultureEn, out integer)) demography.PopFemale = integer; if (TryParseAsIntThenDouble(row[TranslationLookup.GetValue("PopMale")].ToString(), NumberStyles.Any, cultureEn, out integer)) demography.PopMale = integer; var demographyErrors = !demography.IsValid() ? demography.GetAllErrors(true) : ""; if (!string.IsNullOrEmpty(demographyErrors)) errorMessage += string.Format(TranslationLookup.GetValue("ImportErrors"), row["* " + locationType.DisplayName]) + demographyErrors + Environment.NewLine; demos.Add(demography); } if (!string.IsNullOrEmpty(errorMessage)) return new ImportResult(TranslationLookup.GetValue("ImportErrorHeader") + Environment.NewLine + errorMessage); demo.Save(demos, userId); if (doAggregate) demo.AggregateUp(locationType, dateReported, userId, null, countryDemoId); int rec = demos.Count; return new ImportResult { WasSuccess = true, Count = rec, Message = string.Format(TranslationLookup.GetValue("ImportSuccess"), rec) }; } catch (Exception ex) { return new ImportResult(TranslationLookup.GetValue("UnexpectedException") + ex.Message); } }
public virtual KeyValuePair<string, string> GetCalculatedValue(string formTranslationKey, string field, Dictionary<string, string> relatedValues, AdminLevelDemography demo, DateTime start, DateTime end, ref string errors) { return new KeyValuePair<string, string>(); }