public void AddParameter(string name, ParameterDirection direction, TkDataType type, int size, object value) { if (fParamCreated) { TkDebug.ThrowToolkitException(string.Format(ObjectUtil.SysCulture, "存储过程{0}已经执行过了,不能再添加参数了", ProcName), this); return; } StoredProcParameter param = Add(name, direction, type); if (size > 0) { param.Size = size; } if (value != null) { param.Value = value; } fParams.Add(param); if (DbUtil.IsInputParameter(direction)) { fInputParams.Add(name, param); } if (direction != ParameterDirection.Input) { fOutputParams.Add(name, param); } }
public void FillDataParameter(IDbDataParameter parameter) { Parameter = parameter; parameter.ParameterName = Name; parameter.Direction = Direction; if (Size > 0) { parameter.Size = Size; } if (DbUtil.IsInputParameter(Direction)) { parameter.Value = Value; fNeedFillValue = false; } }
protected sealed override void PrepareParameters() { PropertyInfo[] properties = GetType().GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); var parameters = from memberInfo in properties from attribute in memberInfo.GetCustomAttributes(false) where attribute is ParameterAttribute select new { Property = memberInfo, Attribute = (ParameterAttribute)attribute }; foreach (var item in parameters) { ParameterAttribute attribute = item.Attribute; string name; if (string.IsNullOrEmpty(attribute.Name)) { name = item.Property.Name; switch (attribute.LetterCase) { case CaseCategory.Uppercase: name = name.ToUpper(ObjectUtil.SysCulture); break; case CaseCategory.Lowercase: name = name.ToLower(ObjectUtil.SysCulture); break; } } else { name = attribute.Name; } TkDataType dataType = attribute.UseDefaultType ? MetaDataUtil.ConvertTypeToDataType(item.Property.PropertyType) : attribute.DataType; StoredProcParameter param = Add(name, attribute.Direction, dataType); if (attribute.Size > 0) { param.Size = attribute.Size; } else { if (dataType == TkDataType.String) { param.Size = 255; } } ParameterInfo info = new ParameterInfo { Attribute = attribute, Parameter = param, Property = item.Property }; if (DbUtil.IsInputParameter(attribute.Direction)) { fInputProperties.Add(info); } if (DbUtil.IsOutputParameter(attribute.Direction)) { fOutputProperties.Add(info); } IDbDataParameter parameter = CreateDataParameter(param); info.SetInputValue(this); Command.Parameters.Add(parameter); } }