private ConditionOperator GetConditionOperator(Schema.Domain.Attribute attr) { switch (attr.AttributeTypeName) { case AttributeTypeIds.PRIMARYKEY: return(ConditionOperator.Equal); case AttributeTypeIds.LOOKUP: return(ConditionOperator.Equal); case AttributeTypeIds.STATE: return(ConditionOperator.Equal); case AttributeTypeIds.BIT: return(ConditionOperator.Equal); case AttributeTypeIds.PICKLIST: return(ConditionOperator.Equal); case AttributeTypeIds.DATETIME: return(ConditionOperator.Equal); case AttributeTypeIds.NVARCHAR: return(ConditionOperator.Like); case AttributeTypeIds.VARCHAR: return(ConditionOperator.Like); case AttributeTypeIds.INT: return(ConditionOperator.Equal); default: return(ConditionOperator.Equal); } }
public static object UnWrapAttributeValue(this Entity entity, Schema.Domain.Attribute attr) { object value = null; if (entity.ContainsKey(attr.Name)) { var obj = entity[attr.Name]; if (obj is EntityReference) { value = (obj as EntityReference).ReferencedValue; } else if (obj is Money) { value = (obj as Money).Value; } else if (obj is OptionSetValue) { value = (obj as OptionSetValue).Value; } else if (obj is OwnerObject) { value = (obj as OwnerObject).OwnerId; } else if (obj is bool) { value = (bool.Parse(obj.ToString())) ? 1 : 0; } else { value = obj; } } return(value); }
private static bool ProcessLike(ConditionExpression cnd, Schema.Domain.Attribute attr, params object[] values) { bool result = false; if (values.NotEmpty() && values[0] != null) { switch (attr.AttributeTypeName) { case AttributeTypeIds.NVARCHAR: result = (values[0].ToString().Contains(cnd.Values[0].ToString())); break; case AttributeTypeIds.VARCHAR: result = (values[0].ToString().Contains(cnd.Values[0].ToString())); break; case AttributeTypeIds.TEXT: result = (values[0].ToString().Contains(cnd.Values[0].ToString())); break; case AttributeTypeIds.NTEXT: result = (values[0].ToString().Contains(cnd.Values[0].ToString())); break; default: break; } } return(result); }
private static bool ProcessLessEqual(ConditionExpression cnd, Schema.Domain.Attribute attr, params object[] values) { bool result = false; if (values.NotEmpty() && values[0] != null && values[0].ToString().IsNotEmpty()) { switch (attr.AttributeTypeName) { case AttributeTypeIds.INT: result = (int.Parse(values[0].ToString()) <= int.Parse(cnd.Values[0].ToString())); break; case AttributeTypeIds.DECIMAL: result = (decimal.Parse(values[0].ToString()) <= decimal.Parse(cnd.Values[0].ToString())); break; case AttributeTypeIds.FLOAT: result = (float.Parse(values[0].ToString()) <= float.Parse(cnd.Values[0].ToString())); break; case AttributeTypeIds.MONEY: result = (float.Parse(values[0].ToString()) <= float.Parse(cnd.Values[0].ToString())); break; } } return(result); }
private static bool ProcessGreaterEqual(ConditionExpression cnd, Schema.Domain.Attribute attr, params object[] values) { bool result = false; if (values.IsEmpty() || values[0] == null || values[0].ToString().IsEmpty()) { result = false; } else { switch (attr.AttributeTypeName) { case AttributeTypeIds.INT: result = (int.Parse(values[0].ToString()) >= int.Parse(cnd.Values[0].ToString())); break; case AttributeTypeIds.DECIMAL: result = (decimal.Parse(values[0].ToString()) >= decimal.Parse(cnd.Values[0].ToString())); break; case AttributeTypeIds.FLOAT: result = (float.Parse(values[0].ToString()) >= float.Parse(cnd.Values[0].ToString())); break; case AttributeTypeIds.MONEY: result = (float.Parse(values[0].ToString()) >= float.Parse(cnd.Values[0].ToString())); break; default: break; } } return(result); }
private string GetSearchName(Schema.Domain.Attribute attr, string entityAlias = "") { //|| attr.TypeIsState() || attr.TypeIsBit() || attr.TypeIsPickList() var name = attr.Name; if (attr != null && (attr.TypeIsPrimaryKey() || attr.TypeIsLookUp() || attr.TypeIsOwner())) { name += "Name"; } return(entityAlias.IsEmpty() ? name : entityAlias + "." + name); }
private void SetAttributeItems(Schema.Domain.Attribute attr) { if ((attr.TypeIsPickList() || attr.TypeIsStatus()))// && attr.OptionSet == null) { var os = _optionSetFinder.FindById(attr.OptionSetId.Value); attr.OptionSet = os; } else if ((attr.TypeIsBit() || attr.TypeIsState() ))// && attr.PickLists.IsEmpty()) { attr.PickLists = _stringMapFinder.Query(n => n.Where(w => w.AttributeId == attr.AttributeId).Sort(s => s.SortAscending(f => f.DisplayOrder))); } }
private static bool ProcessNotEndWith(ConditionExpression cnd, Schema.Domain.Attribute attr, params object[] values) { bool result = false; if (values.NotEmpty() && values[0] != null) { switch (attr.AttributeTypeName) { case AttributeTypeIds.NVARCHAR: result = !(cnd.Values[0].ToString().EndsWith(values[0].ToString(), StringComparison.InvariantCultureIgnoreCase)); break; default: break; } } return(result); }
//private void ToExcel(QueryView.Domain.QueryView queryView, FilterExpression filter, OrderExpression order, string fileName, bool includePrimaryKey = false, bool includeIndex = false, string title = "") //{ //} private void SetCellValue(ICell cell, object value, Schema.Domain.Attribute attr) { if (value != null) { if (attr != null && (attr.TypeIsMoney() || attr.TypeIsSmallMoney() || attr.TypeIsFloat() || attr.TypeIsDecimal() || attr.TypeIsInt() || attr.TypeIsSmallInt())) { cell.SetCellValue(double.Parse((string)value)); cell.SetCellType(CellType.Numeric); } else { cell.SetCellValue((string)value); } } else { cell.SetCellValue(string.Empty); } }
public static object WrapAttributeValue(this Entity entity, IEntityFinder entityFinder, Schema.Domain.Attribute attr, object value) { List <string> errors = new List <string>(); if (value == null || value.ToString().IsEmpty()) { return(null); } if (attr != null) { if (attr.TypeIsBit()) { if (value.ToString().IsInteger())// if value is 0/1 { value = value.ToString() == "1"; } else { var boolValue = true; if (bool.TryParse(value.ToString(), out boolValue)) { value = boolValue; } else//if (!(value is bool)) { errors.Add(string.Format("{0}'s value({1}) is not valid, it's type should be 'bool'", attr.Name, value.ToString())); } } } else if (attr.TypeIsLookUp()) { if (value is EntityReference) { var er = value as EntityReference; //是否存在该引用实体 if (!entityFinder.Exists(er.ReferencedEntityName)) { errors.Add(string.Format("referenced entity '{0}' is not found by attribute '{1}'", er.ReferencedEntityName, attr.Name)); } } else { if (value.ToString().IsGuid()) { var referencedEntity = entityFinder.FindById(attr.ReferencedEntityId.Value); value = new EntityReference(referencedEntity.Name, Guid.Parse(value.ToString())); } else { errors.Add(string.Format("{0}'s value({1}) is not valid, it's type should be 'SDK.EntityReference'", attr.Name, value.ToString())); } } } else if (attr.TypeIsPickList()) { //是否正确的格式 if (!(value is OptionSetValue)) { if (value.ToString().IsInteger()) { value = new OptionSetValue(int.Parse(value.ToString())); } else { errors.Add(string.Format("{0}'s value({1}) is not valid, it's type should be 'SDK.OptionSetValue'", attr.Name, value.ToString())); } } //是否存在该值 } else if (attr.TypeIsOwner()) { //是否正确的格式 if (!(value is OwnerObject)) { if (value.ToString().IsGuid()) { value = new OwnerObject(OwnerTypes.SystemUser, Guid.Parse(value.ToString())); } else { errors.Add(string.Format("{0}'s value({1}) is not valid, it's type should be 'SDK.OwnerObject'", attr.Name, value.ToString())); } } //是否存在该值 } else if (attr.TypeIsState()) { if (value.ToString().IsInteger())// if value is 0/1 { value = value.ToString() == "1"; } else { var boolValue = true; if (bool.TryParse(value.ToString(), out boolValue)) { value = boolValue; } else//if (!(value is bool)) { errors.Add(string.Format("{0}'s value({1}) is not valid, it's type should be 'bool'", attr.Name, value.ToString())); } } } else if (attr.TypeIsInt()) { //是否正确的格式 if (!value.ToString().IsInteger()) { errors.Add(string.Format("{0}'s value({1}) is not valid, it's type should be 'int'", attr.Name, value.ToString())); } } else if (attr.TypeIsFloat()) { //是否正确的格式 if (!value.ToString().IsNumeric()) { errors.Add(string.Format("{0}'s value({1}) is not valid, it's type should be 'float'", attr.Name, value.ToString())); } } else if (attr.TypeIsMoney()) { //是否正确的格式 if (!(value is Money)) { if (value.ToString().IsNumeric()) { value = new Money(decimal.Parse(value.ToString())); } else { errors.Add(string.Format("{0}'s value({1}) is not valid, it's type should be 'SDK.Money'", attr.Name, value.ToString())); } } } else if (attr.TypeIsDateTime()) { //是否正确的格式 if (!value.ToString().IsDateTime()) { errors.Add(string.Format("{0}'s value({1}) is not valid, it's type should be 'datetime'", attr.Name, value.ToString())); } } } if (errors.NotEmpty()) { throw new XmsException(string.Join("\n", errors)); } return(value); }
private ConditionExpression GetCondition(Schema.Domain.Attribute attr, object keyword, string entityAlias = "") { //数字类型 if (keyword.ToString().IsNumeric() && (attr.TypeIsInt() || attr.TypeIsFloat() || attr.TypeIsDecimal() || attr.TypeIsMoney() || attr.TypeIsSmallMoney() || attr.TypeIsSmallInt() )) { return(new ConditionExpression(GetSearchName(attr, entityAlias), GetConditionOperator(attr), keyword)); } //日期类型 else if ((attr.TypeIsDateTime() || attr.TypeIsSmallDateTime() )) { if (DateTime.TryParse(keyword.ToString(), out DateTime d)) { return(new ConditionExpression(GetSearchName(attr, entityAlias), GetConditionOperator(attr), keyword)); } } //guid类型 else if (attr.TypeIsPrimaryKey() || attr.TypeIsLookUp() || attr.TypeIsOwner() || attr.TypeIsCustomer()) { if (keyword.ToString().IsGuid()) { return(new ConditionExpression(attr.Name, GetConditionOperator(attr), keyword)); } return(new ConditionExpression(GetSearchName(attr, entityAlias), ConditionOperator.Like, keyword)); } //选项类型 else if ((attr.TypeIsState() || attr.TypeIsBit() || attr.TypeIsPickList() || attr.TypeIsStatus())) { if (keyword.ToString().IsInteger())//如果是数值 { return(new ConditionExpression(entityAlias.IsEmpty() ? attr.Name : entityAlias + "." + attr.Name, GetConditionOperator(attr), keyword)); } else { //按名称查找选项值 //... if (attr.TypeIsState() || attr.TypeIsBit()) { if (attr.PickLists.IsEmpty()) { attr.PickLists = _stringMapFinder.Query(n => n.Where(f => f.AttributeId == attr.AttributeId)); } var value = attr.PickLists.Find(n => n.Name.IsCaseInsensitiveEqual(keyword.ToString())); if (null != value) { keyword = value.Value; } } else if (attr.TypeIsPickList() || attr.TypeIsStatus()) { if (attr.OptionSet == null) { attr.OptionSet = new OptionSet();//_optionSetFinder.FindById(attr.OptionSetId.Value); } var value = attr.OptionSet.Items.Find(n => n.Name.IsCaseInsensitiveEqual(keyword.ToString())); if (null != value) { keyword = value.Value; } } } //if (keyword.ToString().IsInteger()) //{ // return new ConditionExpression(attr.Name, ConditionOperator.Equal, keyword); //} } //字符串类型 else if ((attr.TypeIsNvarchar() || attr.TypeIsVarchar() || attr.TypeIsChar())) { return(new ConditionExpression(GetSearchName(attr, entityAlias), GetConditionOperator(attr), keyword)); } return(null); }
public bool UpdateControlMap(EntityMap entityMap, IEnumerable <AttributeMap> attributeMaps, Guid sourceRecordId, Schema.Domain.Attribute refAttribute, IEnumerable <Schema.Domain.Attribute> sourceAttributeMeta, IEnumerable <Schema.Domain.Attribute> targetAttributeMeta, bool onDelete = false) { Sql s = Sql.Builder.Append("UPDATE [" + entityMap.SourceEnttiyName + "] SET "); foreach (var ca in attributeMaps) { //查找所有目标单据,钩稽字段的总和 s.Append(string.Format("[{0}]=(SELECT SUM([{1}]) AS SumValue FROM [{2}] WHERE [{3}] = '{4}')" , ca.RemainAttributeName, ca.TargetAttributeName, entityMap.TargetEnttiyName, refAttribute.Name, sourceRecordId)); s.Append(string.Format(",[{0}]=(CASE WHEN ([{1}]-(SELECT SUM([{2}]) AS SumValue FROM [{3}] WHERE [{4}] = '{5}'))<=0 THEN 1 ELSE 0 END)" , ca.ClosedAttributeName, ca.SourceAttributeName, ca.TargetAttributeName, entityMap.TargetEnttiyName, refAttribute.Name, sourceRecordId)); if (!onDelete && entityMap.MapType == MapType.ForceControl) { var data = _repository.ExecuteQuery(string.Format("SELECT 1 FROM [{0}] a LEFT JOIN (SELECT SUM([{1}]) AS SumValue,[{3}] FROM [{2}] WHERE [{3}] = '{4}' GROUP BY [{3}]) b ON a.{0}id=b.[{3}] WHERE a.{0}id='{4}' AND b.SumValue>a.[{5}]" , entityMap.SourceEnttiyName, ca.TargetAttributeName, entityMap.TargetEnttiyName, refAttribute.Name, sourceRecordId, ca.SourceAttributeName)); if (data.NotEmpty()) { var attr = sourceAttributeMeta.First(n => n.AttributeId.Equals(ca.SourceAttributeId)); var attr2 = targetAttributeMeta.First(n => n.AttributeId.Equals(ca.TargetAttributeId)); _repository.RollBackTransaction(); throw new XmsException(string.Format("'{0}' " + _loc["entitymap_greaterthan_error"] + " '{1}'", attr2.LocalizedName, attr.LocalizedName)); } } } s.Append(" WHERE " + entityMap.SourceEnttiyName + "id='" + sourceRecordId + "'"); _repository.Execute(s); return(true); }
private static bool ProcessEqual(ConditionExpression cnd, Schema.Domain.Attribute attr, params object[] values) { bool result = false; if (values.NotEmpty() && values[0] != null) { switch (attr.AttributeTypeName) { case AttributeTypeIds.INT: if (values[0].ToString().IsNotEmpty()) { result = (int.Parse(cnd.Values[0].ToString()) == int.Parse(values[0].ToString())); } break; case AttributeTypeIds.DECIMAL: if (values[0].ToString().IsNotEmpty()) { result = (decimal.Parse(cnd.Values[0].ToString()) == decimal.Parse(values[0].ToString())); } break; case AttributeTypeIds.FLOAT: if (values[0].ToString().IsNotEmpty()) { result = (float.Parse(cnd.Values[0].ToString()) == float.Parse(values[0].ToString())); } break; case AttributeTypeIds.MONEY: if (values[0].ToString().IsNotEmpty()) { result = (float.Parse(cnd.Values[0].ToString()) == float.Parse(values[0].ToString())); } break; case AttributeTypeIds.VARCHAR: result = (cnd.Values[0].ToString().IsCaseInsensitiveEqual(values[0].ToString())); break; case AttributeTypeIds.NVARCHAR: result = (cnd.Values[0].ToString().IsCaseInsensitiveEqual(values[0].ToString())); break; case AttributeTypeIds.TEXT: result = (cnd.Values[0].ToString().IsCaseInsensitiveEqual(values[0].ToString())); break; case AttributeTypeIds.PICKLIST: if (values[0].ToString().IsNotEmpty()) { result = (int.Parse(cnd.Values[0].ToString()) == int.Parse(values[0].ToString())); } break; case AttributeTypeIds.STATE: if (values[0].ToString().IsNotEmpty()) { result = (int.Parse(cnd.Values[0].ToString()) == int.Parse(values[0].ToString())); } break; case AttributeTypeIds.STATUS: if (values[0].ToString().IsNotEmpty()) { result = (int.Parse(cnd.Values[0].ToString()) == int.Parse(values[0].ToString())); } break; case AttributeTypeIds.BIT: if (values[0].ToString().IsNotEmpty()) { result = (int.Parse(cnd.Values[0].ToString()) == int.Parse(values[0].ToString())); } break; case AttributeTypeIds.LOOKUP: result = (cnd.Values[0].ToString().IsCaseInsensitiveEqual(values[0].ToString())); break; case AttributeTypeIds.OWNER: result = (cnd.Values[0].ToString().IsCaseInsensitiveEqual(values[0].ToString())); break; case AttributeTypeIds.PRIMARYKEY: result = (cnd.Values[0].ToString().IsCaseInsensitiveEqual(values[0].ToString())); break; case AttributeTypeIds.DATETIME: result = ProcessDatetimeCondition(cnd, values); break; default: break; } } return(result); }
public static bool IsTrue(this ConditionExpression cnd, Schema.Domain.Attribute attr, params object[] values) { bool result = false; switch (cnd.Operator) { case ConditionOperator.Equal: result = ProcessEqual(cnd, attr, values); break; case ConditionOperator.EqualUserId: result = ProcessEqual(cnd, attr, values); break; case ConditionOperator.NotEqual: result = ProcessNotEqual(cnd, attr, values); break; case ConditionOperator.NotEqualUserId: result = ProcessNotEqual(cnd, attr, values); break; case ConditionOperator.NotEqualBusinessId: result = ProcessNotEqual(cnd, attr, values); break; case ConditionOperator.BeginsWith: result = ProcessBeginsWith(cnd, attr, values); break; case ConditionOperator.DoesNotBeginWith: result = ProcessNotBeginWith(cnd, attr, values); break; case ConditionOperator.DoesNotContain: result = ProcessNotContain(cnd, attr, values); break; case ConditionOperator.DoesNotEndWith: result = ProcessNotEndWith(cnd, attr, values); break; case ConditionOperator.EndsWith: result = ProcessEndsWith(cnd, attr, values); break; case ConditionOperator.GreaterEqual: result = ProcessGreaterEqual(cnd, attr, values); break; case ConditionOperator.GreaterThan: result = ProcessGreaterThan(cnd, attr, values); break; case ConditionOperator.LessEqual: result = ProcessLessEqual(cnd, attr, values); break; case ConditionOperator.LessThan: result = ProcessLessThan(cnd, attr, values); break; case ConditionOperator.Last7Days: result = ProcessDatetimeCondition(cnd, values); break; case ConditionOperator.LastMonth: result = ProcessDatetimeCondition(cnd, values); break; case ConditionOperator.LastWeek: result = ProcessDatetimeCondition(cnd, values); break; case ConditionOperator.LastXDays: result = ProcessDatetimeCondition(cnd, values); break; case ConditionOperator.LastXHours: result = ProcessDatetimeCondition(cnd, values); break; case ConditionOperator.LastXMonths: result = ProcessDatetimeCondition(cnd, values); break; case ConditionOperator.LastXWeeks: result = ProcessDatetimeCondition(cnd, values); break; case ConditionOperator.LastXYears: result = ProcessDatetimeCondition(cnd, values); break; case ConditionOperator.LastYear: result = ProcessDatetimeCondition(cnd, values); break; case ConditionOperator.Next7Days: result = ProcessDatetimeCondition(cnd, values); break; case ConditionOperator.NextMonth: result = ProcessDatetimeCondition(cnd, values); break; case ConditionOperator.NextWeek: result = ProcessDatetimeCondition(cnd, values); break; case ConditionOperator.NextXDays: result = ProcessDatetimeCondition(cnd, values); break; case ConditionOperator.NextXHours: result = ProcessDatetimeCondition(cnd, values); break; case ConditionOperator.NextXMonths: result = ProcessDatetimeCondition(cnd, values); break; case ConditionOperator.NextXWeeks: result = ProcessDatetimeCondition(cnd, values); break; case ConditionOperator.NextXYears: result = ProcessDatetimeCondition(cnd, values); break; case ConditionOperator.NextYear: result = ProcessDatetimeCondition(cnd, values); break; case ConditionOperator.Today: result = ProcessDatetimeCondition(cnd, values); break; case ConditionOperator.NotBetween: result = ProcessDatetimeCondition(cnd, values); break; case ConditionOperator.Between: result = ProcessDatetimeCondition(cnd, values); break; case ConditionOperator.OlderThanXYears: result = ProcessDatetimeCondition(cnd, values); break; case ConditionOperator.OlderThanXMonths: result = ProcessDatetimeCondition(cnd, values); break; case ConditionOperator.OlderThanXDays: result = ProcessDatetimeCondition(cnd, values); break; case ConditionOperator.AfterXYears: result = ProcessDatetimeCondition(cnd, values); break; case ConditionOperator.AfterXMonths: result = ProcessDatetimeCondition(cnd, values); break; case ConditionOperator.AfterXDays: result = ProcessDatetimeCondition(cnd, values); break; case ConditionOperator.On: result = ProcessDatetimeCondition(cnd, values); break; case ConditionOperator.NotOn: result = ProcessDatetimeCondition(cnd, values); break; case ConditionOperator.OnOrAfter: result = ProcessDatetimeCondition(cnd, values); break; case ConditionOperator.OnOrBefore: result = ProcessDatetimeCondition(cnd, values); break; case ConditionOperator.ThisMonth: result = ProcessDatetimeCondition(cnd, values); break; case ConditionOperator.ThisWeek: result = ProcessDatetimeCondition(cnd, values); break; case ConditionOperator.ThisYear: result = ProcessDatetimeCondition(cnd, values); break; case ConditionOperator.Tomorrow: result = ProcessDatetimeCondition(cnd, values); break; case ConditionOperator.Yesterday: result = ProcessDatetimeCondition(cnd, values); break; case ConditionOperator.NotIn: result = ProcessNotIn(cnd, attr, values); break; case ConditionOperator.In: result = ProcessIn(cnd, attr, values); break; case ConditionOperator.Like: result = ProcessLike(cnd, attr, values); break; case ConditionOperator.Contains: result = ProcessContains(cnd, attr, values); break; case ConditionOperator.NotLike: result = ProcessNotLike(cnd, attr, values); break; case ConditionOperator.NotNull: result = (values.NotEmpty() && values[0] != null); break; case ConditionOperator.Null: result = (values.IsEmpty() || values[0] == null); break; case ConditionOperator.EqualBusinessId: result = ProcessEqual(cnd, attr, values); break; case ConditionOperator.EqualOrganizationId: result = ProcessEqual(cnd, attr, values); break; case ConditionOperator.NotEqualOrganizationId: result = ProcessNotEqual(cnd, attr, values); break; default: break; } return(result); }
public string GetFieldValueName(IQueryResolver queryTranslator, string field, Schema.Domain.Attribute attr = null) { return(_reportRepository.GetFieldValueName(queryTranslator, field, attr)); }
public bool UpdateSummaryValue(Schema.Domain.Entity entityMetadata, Entity data, Schema.Domain.Attribute summaryField, Schema.Domain.RelationShip relationShipMetadata, AttributeAggregateExpression aggExp) { var sql = string.Format("UPDATE {0} SET {1}=(SELECT {6}({2}) FROM {3} WITH(NOLOCK) WHERE {4}='{5}') WHERE {4} = '{5}'" , summaryField.EntityName, summaryField.Name, aggExp.Field, aggExp.EntityName , relationShipMetadata.ReferencedAttributeName, data[relationShipMetadata.ReferencingAttributeName].ToString() , aggExp.Aggregate); _repository.Execute(sql, null); return(true); }
public IActionResult CreateAttribute(CreateAttributeModel model) { if (ModelState.IsValid) { var entity = _entityFinder.FindById(model.EntityId); if (entity == null) { return(NotFound()); } var attr = _attributeFinder.Find(model.EntityId, model.Name); if (attr != null) { return(JError(T["attribute_name_exists"])); } var attrInfo = new Schema.Domain.Attribute(); //model.CopyTo(entity); attrInfo.EntityId = entity.EntityId; attrInfo.EntityName = entity.Name; attrInfo.Name = model.Name.Trim(); attrInfo.LocalizedName = model.LocalizedName; attrInfo.AttributeId = Guid.NewGuid(); attrInfo.IsNullable = model.IsNullable; attrInfo.IsRequired = model.IsRequired; attrInfo.LogEnabled = model.LogEnabled; attrInfo.IsCustomizable = true; attrInfo.IsCustomField = true; attrInfo.AuthorizationEnabled = model.AuthorizationEnabled; attrInfo.CreatedBy = CurrentUser.SystemUserId; attrInfo.Description = model.Description; attrInfo.ValueType = model.ValueType; switch (model.AttributeType) { case AttributeTypeIds.NVARCHAR: attrInfo.MaxLength = model.MaxLength.Value; attrInfo.DataFormat = model.TextFormat; attrInfo.DefaultValue = model.DefaultValue; if (model.ValueType == 2) { attrInfo.FormulaExpression = model.FormulaExpression; } break; case AttributeTypeIds.NTEXT: attrInfo.DataFormat = model.NTextFormat; break; case AttributeTypeIds.INT: attrInfo.MinValue = model.IntMinValue.Value <= int.MinValue ? int.MinValue + 2 : model.IntMinValue.Value; attrInfo.MaxValue = model.IntMaxValue.Value >= int.MaxValue ? int.MaxValue - 2 : model.IntMaxValue.Value; attrInfo.DefaultValue = model.DefaultValue; if (model.ValueType == 2) { attrInfo.FormulaExpression = model.FormulaExpression; } else if (model.ValueType == 3) { attrInfo.SummaryEntityId = model.SummaryEntityId; attrInfo.SummaryExpression = model.SummaryExpression; } break; case AttributeTypeIds.FLOAT: attrInfo.Precision = model.FloatPrecision.Value; attrInfo.MinValue = model.FloatMinValue.Value <= float.MinValue ? float.MinValue + 2 : model.FloatMinValue.Value; attrInfo.MaxValue = model.FloatMaxValue.Value >= float.MaxValue ? float.MaxValue - 2 : model.FloatMaxValue.Value; attrInfo.DefaultValue = model.DefaultValue; if (model.ValueType == 2) { attrInfo.FormulaExpression = model.FormulaExpression; } else if (model.ValueType == 3) { attrInfo.SummaryEntityId = model.SummaryEntityId; attrInfo.SummaryExpression = model.SummaryExpression; } break; case AttributeTypeIds.MONEY: attrInfo.Precision = model.MoneyPrecision.Value; attrInfo.MinValue = model.MoneyMinValue.Value <= float.MinValue ? float.MinValue + 2 : model.MoneyMinValue.Value; attrInfo.MaxValue = model.MoneyMaxValue.Value >= float.MaxValue ? float.MaxValue - 2 : model.MoneyMaxValue.Value; attrInfo.DefaultValue = model.DefaultValue; if (model.ValueType == 2) { attrInfo.FormulaExpression = model.FormulaExpression; } else if (model.ValueType == 3) { attrInfo.SummaryEntityId = model.SummaryEntityId; attrInfo.SummaryExpression = model.SummaryExpression; } break; case AttributeTypeIds.PICKLIST: attrInfo.DisplayStyle = model.OptionSetType; if (model.IsCommonOptionSet) { attrInfo.OptionSetId = model.CommonOptionSet.Value; } else { if (model.OptionSetName.IsEmpty()) { return(JError(T["attribute_options_empty"])); } //新建选项集 Schema.Domain.OptionSet os = new Schema.Domain.OptionSet(); os.OptionSetId = Guid.NewGuid(); os.Name = model.Name; os.IsPublic = false; List <Schema.Domain.OptionSetDetail> details = new List <Schema.Domain.OptionSetDetail>(); int i = 0; foreach (var item in model.OptionSetName) { if (item.IsEmpty()) { continue; } Schema.Domain.OptionSetDetail osd = new Schema.Domain.OptionSetDetail(); osd.OptionSetDetailId = Guid.NewGuid(); osd.OptionSetId = os.OptionSetId; osd.Name = item; osd.Value = model.OptionSetValue[i]; osd.IsSelected = model.IsSelectedOption[i]; osd.DisplayOrder = i; details.Add(osd); i++; } attrInfo.OptionSetId = os.OptionSetId; os.Items = details; attrInfo.OptionSet = os; } break; case AttributeTypeIds.BIT: if (model.BitOptionName.IsEmpty()) { return(JError(T["attribute_options_empty"])); } //新建选项集 List <Schema.Domain.StringMap> pickListItems = new List <Schema.Domain.StringMap>(); int j = 0; foreach (var item in model.BitOptionName) { Schema.Domain.StringMap s = new Schema.Domain.StringMap(); s.StringMapId = Guid.NewGuid(); s.Name = item; s.Value = j == 0 ? 1 : 0;//第一项为true选项 s.DisplayOrder = j; s.AttributeId = attrInfo.AttributeId; s.EntityName = attrInfo.EntityName; s.AttributeName = attrInfo.Name; j++; pickListItems.Add(s); } attrInfo.PickLists = pickListItems; break; case AttributeTypeIds.DATETIME: attrInfo.DataFormat = model.DateTimeFormat; break; case AttributeTypeIds.LOOKUP: attrInfo.ReferencedEntityId = model.LookupEntity.Value; attrInfo.DisplayStyle = model.LookupType; break; case AttributeTypeIds.PARTYLIST: attrInfo.DataFormat = model.PartyListFormat; break; } attrInfo.AttributeTypeName = model.AttributeType; _attributeCreater.Create(attrInfo); return(CreateSuccess(new { id = attrInfo.AttributeId })); } return(JModelError(T["created_error"])); }
public string GetFieldValueName(IQueryResolver queryTranslator, string field, Schema.Domain.Attribute attr = null) { if (attr == null) { var alias = queryTranslator.AttributeAliasList.Find(n => n.Alias.IsCaseInsensitiveEqual(field)); if (alias != null) { attr = queryTranslator.AttributeList.Find(n => n.Name.IsCaseInsensitiveEqual(alias.Name)); } } field = attr.GetNameField(field); return(field.ToLower()); }