public override ISource CreateObject(params object[] args) { MultipleDbInsertSource source = new MultipleDbInsertSource(this) { UseMetaData = UseMetaData }; if (Resolvers != null) { int i = 0; foreach (var item in Resolvers) { TableResolver resolver = item.CreateObject(source); if (i++ == 0) { source.SetMainResolver(resolver); } else { source.AddDetailTableResolver(resolver, IsDetailEmptyRow); } } } return(source); }
private static TableResolver CreateTableResolver(IConfigCreator <TableResolver> resolverConfig, IDbDataSource source) { TableResolver resolver = resolverConfig.CreateObject(source); return(resolver); }
public void SetHandled(TableResolver resolver, bool value) { TkDebug.Assert(fResolvers.ContainsKey(resolver), string.Format( ObjectUtil.SysCulture, "在Resolver集合中,没有找到({0})的Resolver。" + "请确认是否使用AddResolvers增加对应的Resolver", resolver), resolver); fResolvers[resolver] = value; }
private static string CreateWhereSql(TableResolver resolver, IDbCommand command, List <FieldInfoEventArgs> list, bool isOrigin) { StringBuilder whereSql = new StringBuilder(BUFFER_SIZE); int i = 0; TkDbContext context = resolver.Context; foreach (FieldInfoEventArgs item in list) { if ((item.Position & SqlPosition.Where) == SqlPosition.Where) { string fieldName = item.FieldInfo.FieldName; JoinStringItem(whereSql, i++, string.Format(ObjectUtil.SysCulture, "{0} = {1}", context.EscapeName(fieldName), context.GetSqlParamName(fieldName, isOrigin)), " AND "); command.Parameters.Add(CreateDataParameter(context, item.FieldInfo, isOrigin)); } } string sql = whereSql.ToString(); TkDebug.Assert(!string.IsNullOrEmpty(sql), string.Format(ObjectUtil.SysCulture, "表{0}在设置提交SQL的Where部分时,没有找到对应的字段,请确认主键是否设置,或者SetFieldInfo事件是否正确", resolver.TableName), resolver); return("WHERE " + sql); }
public DbDetailStatListSource(IBaseDbConfig config, IConfigCreator <TableResolver> mainResolver, ChildTableInfoConfig childInfoConfig) : base(childInfoConfig.Stat) { TkDebug.AssertArgumentNull(config, "config", null); TkDebug.AssertArgumentNull(mainResolver, "mainResolver", null); TkDebug.AssertArgumentNull(childInfoConfig, "childInfoConfig", null); SetConfig(config); fChildInfo = new ChildTableInfo(this, childInfoConfig); // 子列表不该占有主配置的数据权限 //if (config.DataRight != null) //{ // SupportData = config.SupportData; // DataRight = config.DataRight.CreateObject(fChildInfo.Resolver); //} // 子列表不该占有功能权限 FunctionType = FunctionRightType.None; OrderBy = fChildInfo.Relation.OrderBy; FilterSql = fChildInfo.Relation.FilterSql; MainResolver = fChildInfo.Resolver; fMasterResolver = mainResolver.CreateObject(this); if (childInfoConfig.Operators != null) { Operators = childInfoConfig.Operators.CreateObject(); } }
internal static string GetLayer(TableResolver resolver, DbTreeDefinition tree, string parentId) { TkDbContext context = resolver.Context; IFieldInfo layerField = resolver.GetFieldInfo(tree.LayerField); IParamBuilder fixBuilder = resolver.CreateFixCondition(); string execRootId = tree.ExecuteRootId; if (execRootId == parentId) { string subStringSql = context.ContextConfig.GetFunction("SubString", layerField.FieldName, 1, 3); string sql = string.Format(ObjectUtil.SysCulture, "SELECT MAX({0}) FROM {1}", subStringSql, resolver.TableName); string value = (fixBuilder == null ? DbUtil.ExecuteScalar(sql, context) : DbUtil.ExecuteScalar(sql, context, fixBuilder)).ToString(); if (string.IsNullOrEmpty(value)) { return("000"); } else { return(AddLayer(value)); } } else { try { string sql = string.Format(ObjectUtil.SysCulture, "SELECT {0} FROM {1}", layerField.FieldName, resolver.TableName); IParamBuilder builder = ParamBuilder.CreateParamBuilder(fixBuilder, SqlParamBuilder.CreateEqualSql(context, resolver.GetFieldInfo(tree.IdField), parentId)); string topLayer = DbUtil.ExecuteScalar(sql, context, builder).ToString(); string subStringSql = context.ContextConfig.GetFunction("SubString", layerField.FieldName, topLayer.Length + 1, 3); builder = CreateLayerParamBuilder(context, layerField, topLayer); builder = SqlParamBuilder.CreateParamBuilder(fixBuilder, builder); sql = string.Format(ObjectUtil.SysCulture, "SELECT MAX({0}) FROM {1}", subStringSql, resolver.TableName); string value = DbUtil.ExecuteScalar(sql, context, builder).ToString().Trim(); if (string.IsNullOrEmpty(value)) { DataRow parentRow = resolver.SelectRowWithParam(tree.IdField, parentId); parentRow[tree.LeafField] = 0; resolver.SetCommands(AdapterCommand.Update); return(topLayer + "000"); } else { return(topLayer + AddLayer(value.Substring(value.Length - 3))); } } catch { return(string.Empty); } } }
public static void UpdateTableResolvers(TkDbContext context, Action <Transaction> applyData, bool sort, TableResolver resolver, IEnumerable <TableResolver> resolvers) { TkDebug.AssertArgumentNull(resolver, "resolver", null); TkDebug.AssertArgumentNull(resolvers, "resolvers", null); UpdateTableResolvers(context, applyData, sort, EnumUtil.Convert(resolver, resolvers)); }
public SwitchFieldSource(TableResolver resolver, SwitchConfig @switch) { TkDebug.AssertArgumentNull(resolver, "resolver", null); TkDebug.AssertArgumentNull(@switch, "switch", null); Resolver = resolver; Switch = @switch; }
protected override void FillUpdateTables(TableResolver resolver, IInputData input, ChildTableInfo childInfo) { if (FillDetailData || childInfo == null) { base.FillUpdateTables(resolver, input, childInfo); } }
private IParamBuilder GetDetailParamBuilder(TableResolver detailResolver, DataRow row, string filterSql) { ParamBuilderContainer container = new ParamBuilderContainer(); container.Add(GetManyToManyParamBuilder(detailResolver, row[fMasterFields[0]])); container.Add(filterSql); return(container); }
protected override void OnReadMetaData(TableResolver resolver, IPageStyle style, ITableSchemeEx scheme) { fListFields = (from field in scheme.Fields let tk5field = field.Convert <Tk5FieldInfoEx>() where IsListField(tk5field, style) orderby field.Control.GetOrder(style) select MetaDataTableResolver.GetSortField(field)).ToList(); }
public ChildTableInfo(TableResolver resolver, TableRelation relation) { TkDebug.AssertArgumentNull(resolver, "resolver", null); TkDebug.AssertArgumentNull(relation, "relation", null); Relation = relation; Resolver = resolver; fCreateResolver = false; }
public void SetMainResolver(TableResolver resolver) { TkDebug.AssertArgumentNull(resolver, "resolver", this); TkDebug.Assert(MainResolver == null, string.Format(ObjectUtil.SysCulture, "MainResolver已经设置,当前MainResolver的表名是{0}", MainResolver == null ? string.Empty : MainResolver.TableName), this); MainResolver = resolver; }
private void MainResolver_UpdatedRow(object sender, UpdatingEventArgs e) { TableResolver resolver = sender.Convert <TableResolver>(); Tuple <IRecordDataPicker, List <RecordLogData> > recordLogInfo; if (fRecordLogs.TryGetValue(resolver.TableName, out recordLogInfo)) { RecordLogUtil.LogRecord(resolver, recordLogInfo.Item1, e, recordLogInfo.Item2); } }
protected override void OnSetMainResolver(TableResolver resolver) { base.OnSetMainResolver(resolver); if (resolver != null) { resolver.UpdateMode = UpdateMode; resolver.UpdatingRow += ResolverUpdatingRow; } }
private static void DecodeResolver(IInputData input, TableResolver resolver) { MetaDataTableResolver metaResolver = resolver as MetaDataTableResolver; if (metaResolver != null) { metaResolver.FillCodeTable(input.Style); metaResolver.Decode(input.Style); } }
public ChangeStatusSource(TableResolver resolver, string nickName, string status) { TkDebug.AssertArgumentNull(resolver, "resolver", null); TkDebug.AssertArgumentNullOrEmpty(nickName, "nickName", null); TkDebug.AssertArgumentNull(status, "status", null); Resolver = resolver; NickName = nickName; Status = status; }
protected override void FillUpdateTables(TableResolver resolver, IInputData input, ChildTableInfo childInfo) { if (childInfo == null) { DataSet postDataSet = input.PostObject.Convert <DataSet>(); resolver.Query(postDataSet); } else { childInfo.FillDetailTables(MainResolver); } }
/// <summary> /// Initializes a new instance of the ResolverConfig class. /// </summary> public ResolverConfig(TableResolver resolver, PageStyle style, UpdateKind kind, UpdateMode mode, bool disposeResolver) { TkDebug.AssertArgumentNull(resolver, "resolver", this); Resolver = resolver; resolver.UpdateMode = mode; Kind = kind; Mode = mode; Style = style; fDisposeResolver = disposeResolver; }
public bool IsHandled(TableResolver resolver) { try { bool value = fResolvers[resolver]; return(value); } catch { return(false); } }
protected virtual void FillUpdateTables(TableResolver resolver, IInputData input, ChildTableInfo childInfo) { if (childInfo == null) { fMainRow = resolver.Query(input.QueryString); } else { childInfo.FillDetailTables(MainResolver); } }
public ITree CreateObject(params object[] args) { TableResolver resolver = Resolver.CreateObject(args); Tk5TreeTableResolver treeResolver = resolver.Convert <Tk5TreeTableResolver>(); ITree tree = treeResolver.CreateTree(); NormalDbTree dbTree = tree as NormalDbTree; if (dbTree != null && DataRight != null) { dbTree.DataRight = DataRight.CreateObject(resolver); } return(tree); }
internal static void SortTree(TableResolver resolver, DbTreeDefinition tree, string id, TreeNodeMoveDirection direct) { TkDebug.AssertArgumentNull(resolver, "resolver", null); TkDebug.AssertArgumentNull(tree, "tree", null); TkDebug.AssertArgumentNullOrEmpty(id, "id", null); IParamBuilder fixBuilder = resolver.CreateFixCondition(); IParamBuilder builder = ParamBuilder.CreateParamBuilder(fixBuilder, SqlParamBuilder.CreateEqualSql(resolver.Context, resolver.GetFieldInfo(tree.IdField), id)); IFieldInfo layerField = resolver.GetFieldInfo(tree.LayerField); string sql = string.Format(ObjectUtil.SysCulture, "SELECT {0} FROM {1}", layerField.FieldName, resolver.TableName); string layer = DbUtil.ExecuteScalar(sql, resolver.Context, builder).ToString(); string parentLayer = layer.Substring(0, layer.Length - 3); resolver.SetCommands(AdapterCommand.Update); builder = SqlParamBuilder.CreateSingleSql(resolver.Context, layerField, "LIKE", parentLayer + "___"); resolver.Select(builder, "ORDER BY " + layerField.FieldName); if (resolver.HostTable == null || resolver.HostTable.Rows.Count == 0) { return; } int rowNum = GetRowNum(resolver.HostTable, tree.IdField, id); if (rowNum == -1) { return; } //根据移动方向,执行不同操作 switch (direct) { case TreeNodeMoveDirection.Up: if (rowNum == 0) //已经最前,不能向上移动 { return; } SwapLayer(resolver, tree, rowNum, rowNum - 1); break; case TreeNodeMoveDirection.Down: if (rowNum == resolver.HostTable.Rows.Count - 1) //已经最后,不能向下移动 { return; } SwapLayer(resolver, tree, rowNum, rowNum + 1); break; } }
public static void GetInsertCommand(TableResolver resolver) { List <FieldInfoEventArgs> list = resolver.GetFieldInfo(UpdateKind.Insert); if (resolver.DataAdapter.InsertCommand == null) { resolver.DataAdapter.InsertCommand = resolver.Context.CreateCommand(); } else { resolver.DataAdapter.InsertCommand.Parameters.Clear(); } resolver.DataAdapter.InsertCommand.CommandText = CreateInsertSql(resolver, list); list = null; }
internal static void MoveTree(TableResolver resolver, DbTreeDefinition tree, string sourceId, string destId) { TkDebug.AssertArgumentNull(resolver, "resolver", null); TkDebug.AssertArgumentNull(tree, "tree", null); TkDebug.AssertArgumentNullOrEmpty(sourceId, "sourceId", null); TkDebug.AssertArgumentNullOrEmpty(destId, "destId", null); IFieldInfo layerField = resolver.GetFieldInfo(tree.LayerField); string sql = string.Format(ObjectUtil.SysCulture, "SELECT {0} FROM {1}", layerField.FieldName, resolver.TableName); IParamBuilder builder = ParamBuilder.CreateParamBuilder(resolver.CreateFixCondition(), SqlParamBuilder.CreateEqualSql(resolver.Context, resolver.GetFieldInfo(tree.IdField), destId)); string destLayer = DbUtil.ExecuteScalar(sql, resolver.Context, builder).ToString(); DataRow srcRow = resolver.SelectRowWithParam(tree.IdField, sourceId); if (destId == srcRow[tree.ParentIdField].ToString()) { //throw new InvalidMoveException(); } string oldLayer = srcRow[tree.LayerField].ToString(); if (destLayer.StartsWith(oldLayer, StringComparison.Ordinal)) { //throw new InvalidMoveException(); } resolver.SetCommands(AdapterCommand.Update); string newLayer = GetLayer(resolver, tree, destId); srcRow[tree.LayerField] = newLayer; DataTable table = resolver.HostTable; int currentCount = table.Rows.Count; builder = CreateLayerParamBuilder(resolver.Context, layerField, oldLayer); resolver.Select(builder); for (int i = currentCount; i < table.Rows.Count; ++i) { DataRow row = table.Rows[i]; row[tree.LayerField] = row[tree.LayerField].ToString().Replace( oldLayer, newLayer); } SetParentLeaf(resolver, tree, srcRow[tree.ParentIdField].ToString()); srcRow[tree.ParentIdField] = destId; }
public void SetSimpleFieldValue(TableResolver masterResolver, TableResolver detailResolver) { TkDebug.AssertArgumentNull(masterResolver, "masterResolver", this); TkDebug.AssertArgumentNull(detailResolver, "detailResolver", this); fMasterResolver = masterResolver; fDetailResolver = detailResolver; if ((fType & RelationType.MasterValue) == RelationType.MasterValue) { fDetailResolver.UpdatingRow += SetSimpleDetailFieldValue; } else if ((fType & RelationType.DetailValue) == RelationType.DetailValue) { fMasterResolver.UpdatingRow += SetSimpleMasterFieldValue; } }
protected override void FillUpdateTables(TableResolver resolver, IInputData input) { if (SupportData) { var fieldInfo = resolver.GetFieldInfo(ParentKey); ListDataRightEventArgs e = new ListDataRightEventArgs(Context, BaseGlobalVariable.Current.UserInfo, resolver); var builder = DataRight.GetListSql(e); builder = ParamBuilder.CreateParamBuilder( SqlParamBuilder.CreateEqualSql(Context, fieldInfo, fParentKey), builder); resolver.Select(builder); } else { resolver.SelectWithParam(ParentKey, fParentKey); } }
private static void SwapLayer(TableResolver resolver, DbTreeDefinition fields, int rowNum1, int rowNum2) { string layerField = fields.LayerField; string leafField = fields.LeafField; DataRow row1 = resolver.HostTable.Rows[rowNum1]; DataRow row2 = resolver.HostTable.Rows[rowNum2]; string tempLayer = row1[layerField].ToString(); row1[layerField] = row2[layerField]; row2[layerField] = tempLayer; ChangeChildLayer(resolver, fields, row1[fields.IdField].ToString(), row1[layerField].ToString(), row1[leafField].Value <int>()); ChangeChildLayer(resolver, fields, row2[fields.IdField].ToString(), row2[layerField].ToString(), row2[leafField].Value <int>()); }
public static void LogRecord(TableResolver resolver, IRecordDataPicker dataPicker, UpdatingEventArgs e, List <RecordLogData> logList) { try { var result = dataPicker.PickData(resolver, e); if (result != null) { RecordLogData log = new RecordLogData(resolver.TableName, e.InvokeMethod, e.Status, result); logList.Add(log); } } catch { } }
public void Switch(TableResolver resolver, DataRow row) { TkDebug.AssertArgumentNull(resolver, "resolver", null); TkDebug.AssertArgumentNull(row, "row", null); object value = row[NickName]; row.BeginEdit(); try { if (value == DBNull.Value) { switch (NullValueProcess) { case SwitchNullProcessMethod.OpenValue: row[NickName] = OpenValue; break; case SwitchNullProcessMethod.ThrowException: throw new WebPostException(ErrorMessage); } } else if (value.ToString() == OpenValue) { row[NickName] = CloseValue; } else { row[NickName] = OpenValue; } if (UpdateTrackField) { resolver.UpdateTrackField(UpdateKind.Update, row); } } finally { row.EndEdit(); } resolver.SetCommands(AdapterCommand.Update); resolver.UpdateDatabase(); }