public void AddByKey(AdaptiveValue pValue, int pFieldIndex, int pRowIndex) { if (!this.ContainsKey(pRowIndex)) { this.Add(pRowIndex, new AdaptiveRow()); } if (!this[pRowIndex].ContainsKey(pFieldIndex)) { this[pRowIndex].Add(pFieldIndex, new AdaptiveValue("")); } this[pRowIndex][pFieldIndex] = pValue; }
public static Values3D ParseSelectionWithCurrentSettings(Range pSelection, UploadForm pFrm, int mFirstDataRow, int mFirstDataCol) { var mMessages = new MessageObject(); pFrm.Log("Freistar å prosessere utvalet med gjeldande innstillingar", true); var mTimer = new Stopwatch(); mTimer.Start(); var mSelection = pSelection.Cells.Value; // Create data object to hold values var mData = new Values3D(); // For each row for (int mR = mFirstDataRow; mR <= pSelection.Rows.Count; mR++) { // For each column for (int mC = mFirstDataCol; mC <= pSelection.Columns.Count; mC++) { // Get the value (as a double) var mAdaptiveValue = new AdaptiveValue(Table.GetNullOrDoubleString(mSelection[mR, mC])); // Get manual settings for statistical variable var mManualStatVarProps = pFrm.ParseStatVarProperties(mR, mC, pFrm.StatVarProperties.DataOrientation); // Get/set the corresponding statvar if (mManualStatVarProps.StatVar1 != null) { mAdaptiveValue.variable1 = mManualStatVarProps.StatVar1.var1; if (String.IsNullOrWhiteSpace(mManualStatVarProps.StatVar1.var1)) { mMessages.AddMessage(MessagesNotices.StatVarParseUsingDefaultNotice); } } if (mManualStatVarProps.StatVar2 != null) { mAdaptiveValue.variable2 = mManualStatVarProps.StatVar2.var2; } if (mManualStatVarProps.StatVar3 != null) { mAdaptiveValue.variable3 = mManualStatVarProps.StatVar3.var3; } if (mManualStatVarProps.StatVar4 != null) { mAdaptiveValue.variable4 = mManualStatVarProps.StatVar4.var4; } if (mManualStatVarProps.StatVar5 != null) { mAdaptiveValue.variable5 = mManualStatVarProps.StatVar5.var5; } mAdaptiveValue.fk_variable = mManualStatVarProps.fk_variable; // Get/set the measurement unit mAdaptiveValue.enhet = mManualStatVarProps.MeasurementUnit; if (mAdaptiveValue.enhet == null) { mMessages.AddMessage(MessagesErrors.MUnitNotSet); } // Add date, if available if (pFrm.StatDatumProperties != null) { // Add logic to parse the date value into its individual parts here var mStatDatum = new StatDateParser((string)pFrm.StatDatumProperties.GetValue(mR, mC), (string)pFrm.cbStatDatumFormat.SelectedValue); if (mStatDatum.Success == true) { mAdaptiveValue.ar = mStatDatum.Year; mAdaptiveValue.mnd = mStatDatum.Month; //mAdaptiveValue.Day = mStatDatum.Day; mAdaptiveValue.kvartal = mStatDatum.Quarter; } else { mMessages.AddMessage(MessagesErrors.AutoDateParseError); } } else { // Get the values from the datagridview with statistical variables if (mManualStatVarProps.Year != null) { mAdaptiveValue.ar = mManualStatVarProps.Year; mMessages.AddMessage(MessagesErrors.ManualDateNotSet); } if (mManualStatVarProps.Quarter != null) { mAdaptiveValue.kvartal = mManualStatVarProps.Quarter; mMessages.AddMessage(MessagesNotices.ManualQuarterNotSet); } if (mManualStatVarProps.Month != null) { mAdaptiveValue.mnd = mManualStatVarProps.Month; mMessages.AddMessage(MessagesNotices.ManualMonthNotSet); } if (mManualStatVarProps.Day != null) { mAdaptiveValue.Day = mManualStatVarProps.Day; mMessages.AddMessage(MessagesNotices.ManualDayNotSet); } } if (pFrm.StatAreaIDsProperties != null || pFrm.StatAreaNameProperties != null || pFrm.StatAreaGroupProperties != null) { // Add statareaID if available if (pFrm.StatAreaIDsProperties != null) { mAdaptiveValue.krets_id = (string)pFrm.StatAreaIDsProperties.GetValue(mR, mC); } // Statareaname is only relevant if id is present if (pFrm.StatAreaNameProperties != null) { mAdaptiveValue.krets_navn = (string)pFrm.StatAreaNameProperties.GetValue(mR, mC); } // Statarea group is only relevant if id is present if (pFrm.StatAreaGroupProperties != null) { mAdaptiveValue.region = (string)pFrm.StatAreaGroupProperties.GetValue(mR, mC); } } // If no auto-properties, pick values from manual form fields else { mAdaptiveValue.krets_id = pFrm.tbStatUnitID.Text; mAdaptiveValue.krets_navn = pFrm.tbStatUnitName.Text; mAdaptiveValue.region = pFrm.tbStatUnitGroup.Text; } mData.AddByKey(mAdaptiveValue, mR, mC); } } mTimer.Stop(); pFrm.Log(mMessages.GetMessages()); pFrm.Log(String.Format("Ferdig på {0} ms", mTimer.ElapsedMilliseconds)); return mData; }