Esempio n. 1
0
		/// <summary>
		/// 解析指定的字典名称、位运算值创建并输出其位运算后的,支持通过位运算的复选但不需要明细项(如其它备注信息)的情况。
		/// </summary>
		/// <param name="data">要解析的目标数据字典对象</param>
		/// <param name="bitwiseValue">位运算后的值</param>
		/// <returns>字典数据对象</returns>
		public void ResolveMultieSelectDictionaryDataWithBitwise(DictionaryData data, out long bitwiseValue)
		{
			if (data == null)
			{
				throw new ArgumentNullException("data");
			}

			bitwiseValue = data.BitwiseValue;
		}
Esempio n. 2
0
		/// <summary>
		/// 解析指定的字典名称、数据项集合、值字段名称、备注字段、选中字段名称创建并返回字典数据对象,支持非位运算的复选且备注信息(如果需要的话)在不选中的状态下仍然能够持久化的情况。
		/// </summary>
		/// <param name="data">要解析的目标数据字典对象</param>
		/// <param name="modelType">字典数据明细项对应的实体模型的类型</param>
		/// <param name="valueFieldName">值字段名称</param>
		/// <param name="descriptionFieldName">备注字段名称</param>
		/// <param name="selectedFieldName">选中字段名称</param>
		/// <returns>字典数据对象</returns>
		public List<object> ResolveMultieSelectDictionaryData(DictionaryData data, Type modelType, string valueFieldName, string descriptionFieldName, string selectedFieldName)
		{
			if (data == null)
			{
				throw new ArgumentNullException("data");
			}
			if (modelType == null)
			{
				throw new ArgumentNullException("modelType");
			}
			this.EnsureStrArgNotNullOrWhiteSpace("valueFieldName", valueFieldName);
			this.EnsureStrArgNotNullOrWhiteSpace("selectedFieldName", selectedFieldName);

			DictionaryDataItem dictionaryDataItem;

			List<object> list = new List<object>();
			for (int i = 0; i < data.All.Count; i++)
			{
				dictionaryDataItem = data.All[i];
				if (dictionaryDataItem.Selected || (dictionaryDataItem.DictionaryItem.RequireDescription && !String.IsNullOrWhiteSpace(dictionaryDataItem.Description)))// 某数据项处于选中状态或数据项的 Description 不为空,就将其持久化
				{
					object modelInstance = Activator.CreateInstance(modelType);
					if (dictionaryDataItem.ExtendProperties.Count > 0)
					{
						foreach (KeyValuePair<string, object> kvp in dictionaryDataItem.ExtendProperties)
						{
							MemberInfo member = this.GetPropertyOrFieldMember(kvp.Key, modelType);
							if (member != null)
							{
								this.SetPropertyOrFieldMemberValue(member, modelInstance, kvp.Value);
							}
						}
					}
					if (dictionaryDataItem.DictionaryItem.RequireDescription)
					{
						if (String.IsNullOrWhiteSpace(descriptionFieldName))
						{
							throw new ArgumentException("因为字典\"{0}\"中值为\"{1}\"的字典项需要备注信息,所以备注字段的名称不能为空。", "descriptionFieldName");
						}
						this.SetPropertyOrFieldMemberValue(descriptionFieldName, modelType, modelInstance, dictionaryDataItem.Description);
					}
					this.SetPropertyOrFieldMemberValue(valueFieldName, modelType, modelInstance, 
						data.Dictionary.ConvertInt64ToItemValueDataType( dictionaryDataItem.DictionaryItem.Value)
						);
					this.SetPropertyOrFieldMemberValue(selectedFieldName, modelType, modelInstance, dictionaryDataItem.Selected);

					list.Add(modelInstance);
				}
			}
			return list;
		}
Esempio n. 3
0
		/// <summary>
		/// 解析指定的数据字典对象并输出其选定的值,支持字典单选的情况。
		/// </summary>
		/// <param name="data">要解析的目标数据字典对象</param>
		/// <param name="selectedValue">选定值</param>
		/// <returns>字典数据对象</returns>
		public void ResolveSingleSelectDictionaryData(DictionaryData data, out long selectedValue)
		{
			if (data == null)
			{
				throw new ArgumentNullException("data");
			}

			selectedValue = -1;

			for (int i = 0; i < data.All.Count; i++)
			{
				if (data.All[i].Selected)
				{
					selectedValue = data.All[i].DictionaryItem.Value;
					break;
				}
			}
		}
Esempio n. 4
0
		/// <summary>
		/// 解析指定的字典名称、数据项集合、值字段名称、备注字段、选中字段名称创建并返回字典数据对象,支持非位运算的复选且备注信息(如果需要的话)在不选中的状态下仍然能够持久化的情况。
		/// </summary>
		/// <param name="cityId">字典关联的城市Id,系统根据此参数值为特定城市返回适用于该城市的字典。</param>
		/// <param name="dictionaryName">字典名称</param>
		/// <param name="dataItems">数据项集合</param>
		/// <param name="valueFieldName">值字段名称</param>
		/// <param name="descriptionFieldName">备注字段名称</param>
		/// <param name="selectedFieldName">选中字段名称</param>
		/// <returns>字典数据对象</returns>
		public DictionaryData CreateMultieSelectDictionaryData(int cityId, string dictionaryName, List<object> dataItems, string valueFieldName, string descriptionFieldName, string selectedFieldName)
		{
			Dictionary dictionary = this.EnsureDictionary(dictionaryName, cityId);

			if (dataItems != null)
			{
				this.EnsureStrArgNotNullOrWhiteSpace("valueFieldName", valueFieldName);
			}
			DictionaryData data = new DictionaryData(dictionary);

			DictionaryDataItem dictionaryDataItem;

			if (dataItems != null && dataItems.Count > 0)
			{
				Type modelType = dataItems[0].GetType();
				for (int i = 0; i < dataItems.Count; i++)
				{
					Int64 value = Convert.ToInt64(this.GetPropertyOrFieldMemberValue(valueFieldName, modelType, dataItems[i]));
					dictionaryDataItem = data.All.GetItemByValue(value);
					if (dictionaryDataItem != null)
					{
						// 备注信息的绑定
						if (dictionaryDataItem.DictionaryItem.RequireDescription)
						{
							if (String.IsNullOrWhiteSpace(descriptionFieldName))
							{
								throw new ArgumentException("因为字典\"{0}\"中值为\"{1}\"的字典项需要备注信息,所以备注字段的名称不能为空。", "descriptionFieldName");
							}
						}
						this.InitDictionaryDataItem(dictionaryDataItem, modelType, dataItems[i], valueFieldName, descriptionFieldName, selectedFieldName);

						// 未指定选中字段的情况下,dataitems 中的所有项都视为选中状态
						if (String.IsNullOrWhiteSpace(selectedFieldName))
						{
							dictionaryDataItem.Selected = true;
						}
					}
				}
			}
			return data;
		}
Esempio n. 5
0
		/// <summary>
		/// 解析指定的字典名称、位运算值、数据项集合、值字段名称、备注字段名称创建并返回字典数据对象,支持字典通过位运算的复选且需要明细项(如其它备注信息)的情况。
		/// </summary>
		/// <param name="cityId">字典关联的城市Id,系统根据此参数值为特定城市返回适用于该城市的字典。</param>
		/// <param name="dictionaryName">字典名称</param>
		/// <param name="bitwiseValue">位运算值</param>
		/// <param name="dataItems">数据项集合</param>
		/// <param name="valueFieldName">值字段名称</param>
		/// <param name="descriptionFieldName">备注字段名称</param>
		/// <returns>字典数据对象</returns>
		public DictionaryData CreateMultieSelectDictionaryDataWithBitwise(int cityId, string dictionaryName, long bitwiseValue, List<object> dataItems, string valueFieldName, string descriptionFieldName)
		{
			Dictionary dictionary = this.EnsureDictionary(dictionaryName, cityId);

			if (!dictionary.RaiseBitwise)
			{
				throw new ApplicationException(String.Format("名称为\"{0}\"的字典不支持位运算", dictionaryName));
			}

			if (dataItems != null && String.IsNullOrWhiteSpace(valueFieldName))
			{
				throw new ArgumentException("valueFieldName");
			}

			DictionaryData data = new DictionaryData(dictionary);

			DictionaryDataItem dictionaryDataItem;

			// 绑定值
			if (bitwiseValue > 0)
			{
				for (int i = 0; i < data.All.Count; i++)
				{
					dictionaryDataItem = data.All[i];
					if (dictionaryDataItem.Children.Count > 0)//如果存在子级字典项,则本级字典项不参与位运算
					{
					}
					else
					{
						if ((dictionaryDataItem.DictionaryItem.Value & bitwiseValue) == dictionaryDataItem.DictionaryItem.Value)
						{
							dictionaryDataItem.Selected = true;
						}
					}
				}
			}

			// 绑定备注信息
			if (dataItems != null && dataItems.Count > 0)
			{
				Type modelType = dataItems[0].GetType();
				for (int i = 0; i < dataItems.Count; i++)
				{
					Int64 value = Convert.ToInt64(this.GetPropertyOrFieldMemberValue(valueFieldName, modelType, dataItems[i]));
					dictionaryDataItem = data.All.GetItemByValue(value);
					if (dictionaryDataItem != null)
					{
						// 备注信息的绑定
						if (dictionaryDataItem.DictionaryItem.RequireDescription)
						{
							if (String.IsNullOrWhiteSpace(descriptionFieldName))
							{
								throw new ArgumentException("因为字典\"{0}\"中值为\"{1}\"的字典项需要备注信息,所以备注字段的名称不能为空。", "descriptionFieldName");
							}
						}
						this.InitDictionaryDataItem(dictionaryDataItem, modelType, dataItems[i], valueFieldName, descriptionFieldName, null);
					}
				}
			}
			return data;
		}
Esempio n. 6
0
		/// <summary>
		/// 解析指定的字典名称、选定值创建并返回字典数据对象,支持字典单选的情况。
		/// </summary>
		/// <param name="cityId">字典关联的城市Id,系统根据此参数值为特定城市返回适用于该城市的字典。</param>
		/// <param name="dictionaryName">字典名称</param>
		/// <param name="selectedValue">选定值</param>
		/// <returns>字典数据对象</returns>
		public DictionaryData CreateSingleSelectDictionaryData(int cityId, string dictionaryName, long selectedValue)
		{
			Dictionary dictionary = this.EnsureDictionary(dictionaryName, cityId);

			DictionaryData data = new DictionaryData(dictionary);

			DictionaryDataItem dictionaryDataItem;

			for (int i = 0; i < data.All.Count; i++)
			{
				dictionaryDataItem = data.All[i];
				if (dictionaryDataItem.DictionaryItem.Value == selectedValue)
				{
					dictionaryDataItem.Selected = true;
					break;
				}
			}

			return data;
		}
Esempio n. 7
0
		internal void SetRelation(DictionaryData owner, DictionaryDataItem parent, DictionaryDataItemCollection children)
		{
			this.owner = owner;
			this.parent = parent;
			this.children = children;
		}