查询条件的封装(二)
TConditionItem
1 { TConditionItem }
2
3 procedure TConditionItem.Assign(Source: TPersistent);
4 begin
5 if Source is TConditionItem then
6 begin
7 if Assigned(Collection) then Collection.BeginUpdate;
8 try
9 //RestoreDefaults;
10 ConditionName := TConditionItem(Source).ConditionName;
11 ConditionLabel := TConditionItem(Source).ConditionLabel;
12 ConditionEditType := TConditionItem(Source).ConditionEditType;
13 ConditionValueType := TConditionItem(Source).ConditionValueType;
14 finally
15 if Assigned(Collection) then Collection.EndUpdate;
16 end;
17 end
18 else
19 inherited Assign(Source);
20 end;
21
22 constructor TConditionItem.Create(Collection: TCollection);
23 begin
24 try
25 inherited Create(Collection);
26 FConditionName := Self.ClassName+IntToStr(Collection.Count);
27 FConditionLabel := '查询条件'+IntToStr(Collection.Count);
28 FConditionValueType := cidtString;
29 FConditionEditType := cetButtonEdit;
30 if Collection is TConditionItems then
31 begin
32 if TConditionItems(Collection).FConditionUI <> nil then
33 TConditionItems(Collection).FConditionUI.BuildConditionGridByItems;
34 end;
35 finally
36
37 end;
38 end;
39
40 procedure TConditionItem.SetConditionEditType(
41 const Value: TConditionEditType);
42 begin
43 FConditionEditType := Value;
44 end;
45
46 procedure TConditionItem.SetConditionLabel(const Value: string);
47 begin
48 FConditionLabel := Value;
49 end;
50
51 procedure TConditionItem.SetConditionName(const Value: string);
52 begin
53 FConditionName := Value;
54 end;
55
56 procedure TConditionItem.SetConditionValue(const Value: Variant);
57 begin
58 FConditionValue := Value;
59 end;
60
61 procedure TConditionItem.SetConditionValueType(
62 const Value: TConditionItemDataType);
63 begin
64 FConditionValueType := Value;
65 end;
66
67 procedure TConditionItem.SetIndex(Value: Integer);
68 begin
69 inherited SetIndex(Value);
70 // 这里不需要处理,SetIndex会触发Changed,从而触发容器的Update。Update已经有控制表格的处理逻辑。
71 // if Collection is TConditionItems then
72 // begin
73 // if TConditionItems(Collection).FConditionUI <> nil then
74 // TConditionItems(Collection).FConditionUI.BuildConditionGridByItems;
75 // end;
76 end;
TConditionItems
1 { TConditionItems }
2
3 function TConditionItems.Add: TConditionItem;
4 begin
5 Result := TConditionItem(inherited Add);
6 end;
7
8 constructor TConditionItems.Create(AConditionUI: TConditionUI;
9 ItemClass: TItemClass);
10 begin
11 inherited Create(ItemClass);
12 FConditionUI := AConditionUI;
13 end;
14
15 function TConditionItems.FindItemIndex(index: Integer): TConditionItem;
16 var
17 i : Integer;
18 begin
19 Result := nil;
20 for i := 0 to Count - 1 do
21 begin
22 if Items[i].Index = index then
23 begin
24 Result := Items[i];
25 Break;
26 end;
27 end;
28 end;
29
30 function TConditionItems.FindItemName(
31 AConditionName: string): TConditionItem;
32 var
33 i : Integer;
34 begin
35 Result := nil;
36 for i := 0 to Count - 1 do
37 begin
38 if Items[i].ConditionName = AConditionName then
39 begin
40 Result := Items[i];
41 Break;
42 end;
43 end;
44 end;
45
46 function TConditionItems.GetItems(Index: Integer): TConditionItem;
47 begin
48 Result := TConditionItem(inherited Items[Index]);
49 end;
50
51 function TConditionItems.GetOwner: TPersistent;
52 begin
53 Result := FConditionUI;
54 end;
55
56 procedure TConditionItems.SetItems(Index: Integer;
57 const Value: TConditionItem);
58 begin
59 Items[Index].Assign(Value);
60 end;
61
62 procedure TConditionItems.Update(Item: TCollectionItem);
63 begin
64 if (FConditionUI.ConditionGrid = nil) or (csLoading in FConditionUI.ConditionGrid.ComponentState) then Exit;
65 if Item = nil then
66 begin
67
68 end
69 else
70 begin
71
72 end;
73 FConditionUI.BuildConditionGridByItems;
74 end;
TConditionUI
1 { TConditionUI }
2
3 procedure TConditionUI.BuildConditionGridByItems;
4 const AColumnCaption: array[0..2] of string = ('查询条件', '条件值', '隐藏列');
5 var
6 i : integer;
7 Column : TcxGridColumn;
8 begin
9 if FConditionGrid <> nil then
10 begin
11 with FConditionGrid do
12 begin
13 BeginUpdate;
14 // 清空表格记录
15 OptionsSelection.CellMultiSelect := true;
16 DataController.ClearSelection;
17 DataController.SelectAll;
18 DataController.DeleteSelection;
19 OptionsSelection.CellMultiSelect := False;
20
21 // 清空表格列
22 for i := FConditionGrid.ColumnCount - 1 downto 0 do
23 begin
24 FConditionGrid.Columns[i].Free;
25 end;
26
27 //
补充:软件开发 , Delphi ,