private void PrepareFields() { _fields.Clear(); var i = 0; foreach (var attr in Query.Attributes) { _fields.Add( new SqlQueryField { Index = i, SelectAttribute = attr, AttrDef = attr.Def, AttributeId = attr.Def != null ? attr.Def.Id : Guid.Empty, AttributeName = attr.Def != null ? attr.Def.Name : SystemIdentConverter.Convert(attr.Ident), IsIdent = attr.IsSystemIdent, Ident = attr.IsSystemIdent ? attr.Ident : SystemIdent.Id, IsExp = attr.IsMultiExpression, DocDef = attr.Attributes[0].Source != null ? attr.Attributes[0].Source.GetDocDef() : null, DocDefId = attr.Attributes[0].Source != null ? attr.Attributes[0].Source.GetDocDef().Id : Guid.Empty, DataType = attr.IsSystemIdent ? SystemIdentConverter.ToBaseType(attr.Ident) : attr.Def != null ? CissaDataTypeHelper.ConvertToBase(attr.Def.Type.Id) : BaseDataType.Unknown }); i++; } }
private static string GetAttributeTableName(CissaDataType dataType) { var tableName = CissaDataTypeHelper.GetTableName(dataType); if (String.IsNullOrEmpty(tableName)) { throw new ApplicationException("Атрибут не является сохраняемым!"); } return(tableName); }
public override BaseDataType GetDataType() { if (Grouping == SqlQuerySummaryFunction.Count) { return(BaseDataType.Int); } return(AttrDef != null ? CissaDataTypeHelper.ConvertToBase(AttrDef.Type.Id) : SystemIdentConverter.ToBaseType(Ident)); }
protected void SimpleSave(Guid docId, AttrDef attrDef, object value, Guid userId, DateTime date) { var tableName = CissaDataTypeHelper.GetTableName(attrDef.Type.Id); DataContext.BeginTransaction(); try { var emptyText = value != null && attrDef.Type.Id == (short)CissaDataType.Text && String.IsNullOrEmpty(value.ToString()); if (value != null && !emptyText) { using (var command = CreateCommand(String.Format(SaveAttrSql, tableName))) { AddParamWithValue(command, "@DocId", docId); AddParamWithValue(command, "@DefId", attrDef.Id); AddParamWithValue(command, "@Created", date); if (attrDef.Type.Id == (short)CissaDataType.Text) { AddParamWithValue(command, "@Value", value, SqlDbType.NVarChar); } else { AddParamWithValue(command, "@Value", value); } AddParamWithValue(command, "@UserId", userId); command.ExecuteNonQuery(); } } else { using (var command = CreateCommand(String.Format(ExpiryAttrSql, tableName))) { AddParamWithValue(command, "@DocId", docId); AddParamWithValue(command, "@DefId", attrDef.Id); AddParamWithValue(command, "@Expired", date); command.ExecuteNonQuery(); } } DataContext.Commit(); } catch { DataContext.Rollback(); throw; } }
private void SaveBlob(Guid docId, Guid attrDefId, byte[] value, string fileName, Guid userId, DateTime date) { var tableName = CissaDataTypeHelper.GetTableName(CissaDataType.Blob); DataContext.BeginTransaction(); try { if (value != null) { using (var command = CreateCommand(String.Format(SaveBlobAttrSql, tableName))) { AddParamWithValue(command, "@DocId", docId); AddParamWithValue(command, "@DefId", attrDefId); AddParamWithValue(command, "@Created", date); AddParamWithValue(command, "@Value", value); AddParamWithValue(command, "@UserId", userId); AddParamWithValue(command, "@FileName", fileName); command.ExecuteNonQuery(); } } else { using (var command = CreateCommand(String.Format(ExpiryAttrSql, tableName))) { AddParamWithValue(command, "@DocId", docId); AddParamWithValue(command, "@DefId", attrDefId); AddParamWithValue(command, "@Expired", date); command.ExecuteNonQuery(); } } DataContext.Commit(); } catch { DataContext.Rollback(); throw; } }
public string GetAttrDefTableName() { if (Def != null) { /*switch ((CissaDataType)Def.Type.Id) * { * case CissaDataType.Int: * return "Int_Attributes"; * case CissaDataType.Text: * return "Text_Attributes"; * case CissaDataType.Float: * return "Float_Attributes"; * case CissaDataType.Enum: * return "Enum_Attributes"; * case CissaDataType.Bool: * return "Boolean_Attributes"; * case CissaDataType.Currency: * return "Currency_Attributes"; * case CissaDataType.DateTime: * return "Date_Time_Attributes"; * case CissaDataType.Doc: * return "Document_Attributes"; * case CissaDataType.DocList: * return "DocumentList_Attributes"; * case CissaDataType.Organization: * return "Org_Attributes"; * case CissaDataType.DocumentState: * return "Doc_State_Attributes"; * }*/ var tableName = CissaDataTypeHelper.GetTableName((CissaDataType)Def.Type.Id); if (!String.IsNullOrEmpty(tableName)) { return(tableName); } } throw new ApplicationException("Не поддерживаемый тип атрибута в SQL запросе!"); }
public override BaseDataType GetDataType() { return(CissaDataTypeHelper.ConvertToBase(AttrDef.Type.Id)); }