public object GetValue(OleDbConnection conn, Dictionary <string, object> fieldValuesOfCurrentRow, List <ColumnDataCache> caches) { if (this == null) { return(null); } object value = ""; switch (this.ValueCategroy) { case JValueCategroy.List: #region List不管是DateTime、Numeric、String处理方式都一样 object[] values = this.Values.ToArray(); int listCount = this.Values.Count(); int randNum = rd.Next(0, listCount); value = values[randNum]; break; #endregion case JValueCategroy.Range: #region Range switch (this.ValueType) { case JFieldType.DateTime: #region Range DateTime minDate = DateTime.Parse(this.MinValue.ToJString()); DateTime maxDate = DateTime.Parse(this.MaxValue.ToJString()); int minutesDiff = (int)(maxDate - minDate).TotalMinutes; int randMinutes = rd.Next(0, minutesDiff); value = minDate.AddMinutes(randMinutes); break; #endregion case JFieldType.Numeric: #region Range decimal maxSeed = decimal.Parse(this.MaxValue.ToJString()); decimal minSeed = decimal.Parse(this.MinValue.ToJString()); if (maxSeed <= 1) { maxSeed = maxSeed * 10000; minSeed = minSeed * 10000; value = (decimal)rd.Next((int)minSeed, (int)maxSeed) / 10000; } else { value = rd.Next((int)minSeed, (int)maxSeed); } break; #endregion case JFieldType.String: value = String.Format(string.IsNullOrEmpty(this.Format) ? "{0}" : this.Format, rd.Next((Int32)this.MinValue, (Int32)this.MaxValue)); break; } break; #endregion case JValueCategroy.Sequence: #region Sequence switch (this.ValueType) { case JFieldType.DateTime: #region Sequence throw new FieldValueTypeNotSupportValueCategroyException(this.FieldName, this.ValueType, this.ValueCategroy); #endregion case JFieldType.Numeric: #region Sequence value = this.MinValue; this.MinValue = int.Parse(this.MinValue.ToJString("0")) + int.Parse(this.Step.ToJString("0")); break; #endregion case JFieldType.String: value = String.Format(string.IsNullOrEmpty(this.Format) ? "{0}" : this.Format, this.MinValue); this.MinValue = int.Parse(this.MinValue.ToJString("0")) + int.Parse(this.Step.ToJString("0")); break; } break; #endregion case JValueCategroy.FromTable: #region FromTable string refTableName = this.ReferenceTableName; string refColumnName = this.ReferenceColumnName; List <string> parameters = new List <string>(); string filterFormat = this.RefFilter.ToParameters(parameters); List <object> parameterValues = new List <object>(); foreach (var item in parameters) { parameterValues.Add(fieldValuesOfCurrentRow[item]); } string refFilter = string.Format(filterFormat, parameterValues.ToArray()); var tableCache = caches.Where(row => row.Table.Equals(refTableName) && row.Column.Equals(refColumnName)).FirstOrDefault(); List <object> cacheData = tableCache == null ? new List <object>() : tableCache.Datas; object tempValue = !JTable.HaveParameter(this.RefFilter) ? cacheData[rd.Next(0, cacheData.Count - 1)] : CommonDAL.GetValue(conn, refTableName, refColumnName, refFilter); SourceFieldData tempData = new SourceFieldData() { fieldName = refColumnName, TableName = refTableName, Value = tempValue }; value = tempData.Value; break; #endregion case JValueCategroy.OtherField: #region OtherField 数据准备 if (!fieldValuesOfCurrentRow.ContainsKey(this.OtherFiledName)) { throw new FieldValueTypeNotSupportValueCategroyException(this.FieldName, this.ValueType, this.ValueCategroy); } value = fieldValuesOfCurrentRow[this.OtherFiledName]; #endregion break; } return(value); }
public object GetValue(OleDbConnection conn, Dictionary<string, object> fieldValuesOfCurrentRow, List<ColumnDataCache> caches) { if (this == null) { return null; } object value = ""; switch (this.ValueCategroy) { case JValueCategroy.List: #region List不管是DateTime、Numeric、String处理方式都一样 object[] values = this.Values.ToArray(); int listCount = this.Values.Count(); int randNum = rd.Next(0, listCount); value = values[randNum]; break; #endregion case JValueCategroy.Range: #region Range switch (this.ValueType) { case JFieldType.DateTime: #region Range DateTime minDate = DateTime.Parse(this.MinValue.ToJString()); DateTime maxDate = DateTime.Parse(this.MaxValue.ToJString()); int minutesDiff = (int)(maxDate - minDate).TotalMinutes; int randMinutes = rd.Next(0, minutesDiff); value = minDate.AddMinutes(randMinutes); break; #endregion case JFieldType.Numeric: #region Range decimal maxSeed = decimal.Parse(this.MaxValue.ToJString()); decimal minSeed = decimal.Parse(this.MinValue.ToJString()); if (maxSeed <= 1) { maxSeed = maxSeed * 10000; minSeed = minSeed * 10000; value = (decimal)rd.Next((int)minSeed, (int)maxSeed) / 10000; } else { value = rd.Next((int)minSeed, (int)maxSeed); } break; #endregion case JFieldType.String: value = String.Format(string.IsNullOrEmpty(this.Format) ? "{0}" : this.Format, rd.Next((Int32)this.MinValue, (Int32)this.MaxValue)); break; } break; #endregion case JValueCategroy.Sequence: #region Sequence switch (this.ValueType) { case JFieldType.DateTime: #region Sequence throw new FieldValueTypeNotSupportValueCategroyException(this.FieldName, this.ValueType, this.ValueCategroy); #endregion case JFieldType.Numeric: #region Sequence value = this.MinValue; this.MinValue = int.Parse(this.MinValue.ToJString("0")) + int.Parse(this.Step.ToJString("0")); break; #endregion case JFieldType.String: value = String.Format(string.IsNullOrEmpty(this.Format) ? "{0}" : this.Format, this.MinValue); this.MinValue = int.Parse(this.MinValue.ToJString("0")) + int.Parse(this.Step.ToJString("0")); break; } break; #endregion case JValueCategroy.FromTable: #region FromTable string refTableName = this.ReferenceTableName; string refColumnName = this.ReferenceColumnName; List<string> parameters = new List<string>(); string filterFormat = this.RefFilter.ToParameters(parameters); List<object> parameterValues = new List<object>(); foreach (var item in parameters) { parameterValues.Add(fieldValuesOfCurrentRow[item]); } string refFilter = string.Format(filterFormat, parameterValues.ToArray()); var tableCache = caches.Where(row => row.Table.Equals(refTableName) && row.Column.Equals(refColumnName)).FirstOrDefault(); List<object> cacheData = tableCache == null ? new List<object>() : tableCache.Datas; object tempValue = !JTable.HaveParameter(this.RefFilter) ? cacheData[rd.Next(0, cacheData.Count - 1)] : CommonDAL.GetValue(conn, refTableName, refColumnName, refFilter); SourceFieldData tempData = new SourceFieldData() { fieldName = refColumnName, TableName = refTableName, Value = tempValue }; value = tempData.Value; break; #endregion case JValueCategroy.OtherField: #region OtherField 数据准备 if (!fieldValuesOfCurrentRow.ContainsKey(this.OtherFiledName)) { throw new FieldValueTypeNotSupportValueCategroyException(this.FieldName, this.ValueType, this.ValueCategroy); } value = fieldValuesOfCurrentRow[this.OtherFiledName]; #endregion break; } return value; }