/// <summary> /// Sets the Recruitment Model of the current index of the multi-recruitment array based off from the /// current selected cell value of dataGridComboBoxRecruitModel. /// </summary> /// <param name="currentModel">Index of the recruitment collection array</param> /// <param name="modelCbx">The DataGridViewComboBoxCell object that is being selected by the user</param> private void OnSelectingRecruitModel(int currentModel, DataGridViewComboBoxEditingControl modelCbx) { object kvpKey; var selectedRecruit = modelCbx.SelectedItem; if (selectedRecruit != null) { Type typeSelectedRecruit = selectedRecruit.GetType(); if (typeSelectedRecruit.IsGenericType) { Type baseTypeSelectedRecruit = typeSelectedRecruit.GetGenericTypeDefinition(); if (baseTypeSelectedRecruit == typeof(KeyValuePair <,>)) { Type[] argTypes = baseTypeSelectedRecruit.GetGenericArguments(); kvpKey = typeSelectedRecruit.GetProperty("Key").GetValue(selectedRecruit, null); this.recruitModelSelection[currentModel] = Convert.ToInt32(kvpKey); int selectedModelNum = Convert.ToInt32(kvpKey); if (this.collectionAgeproRecruitmentModels[currentModel] != null) { this.collectionAgeproRecruitmentModels[currentModel] = AgeproRecruitment.GetNewRecruitModel(selectedModelNum); } } } } }
//end OnSelectingRecruitingModel private Nmfs.Agepro.CoreLib.ValidationResult ValidateGeneralRecruitmentParameters() { List <string> errorMsgList = new List <string>(); //Select Recruitment Models if (this.dataGridComboBoxSelectRecruitModels.HasBlankOrNullCells() == true) { errorMsgList.Add("Select Recruitment Model Data Grid has invalid data."); } //Recruitment Scaling Factor if (string.IsNullOrWhiteSpace(this.textBoxRecruitngScalingFactor.Text)) { errorMsgList.Add("Missing Recruitment Scaling Factor value."); } //SSB Scaling Factor if (string.IsNullOrWhiteSpace(this.textBoxSSBScalingFactor.Text)) { errorMsgList.Add("Missing Recruitment SSB Scaling Factor value."); } //Recruitment Probability if (this.dataGridRecruitProb.HasBlankOrNullCells() == true) { errorMsgList.Add("Recruitment probability table has missing values."); } foreach (DataRow drow in this.recruitmentProb.Rows) { //List rows that have nulls/missing data if (drow.ItemArray.Any(x => string.IsNullOrWhiteSpace(x.ToString()))) { errorMsgList.Add("At row " + (this.recruitmentProb.Rows.IndexOf(drow) + 1) + ": Empty or missing value found."); } else { string[] recruitProbRow = Array.ConvertAll(drow.ItemArray, item => item.ToString()); if (AgeproRecruitment.CheckRecruitProbabilitySum(recruitProbRow) == false) { double rowSumRecruitProb = Array.ConvertAll <string, double>(recruitProbRow, double.Parse).Sum(); errorMsgList.Add("At row " + this.recruitmentProb.Rows.IndexOf(drow) + ": Recruitment probablity sum does not equal 1.0; probability sum is " + rowSumRecruitProb.ToString()); } } } var results = errorMsgList.EnumerateValidationResults(); return(results); }