zoukankan      html  css  js  c++  java
  • 查询条件的封装(二)

    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 // 创建表格列
    28 for i := 0 to 2 do
    29 begin
    30 Column := FConditionGrid.CreateColumn;
    31 Column.Caption := AColumnCaption[i];
    32 if i = 0 then
    33 Column.Options.Focusing := False
    34 else
    35 if i = 2 then
    36 Column.Visible := False;
    37 end;
    38 // 创建表格行
    39 for i := 0 to FConditionItems.Count -1 do
    40 begin
    41 DataController.AppendRecord;
    42 DataController.Values[i, 0] := TConditionItem(FConditionItems.FindItemIndex(i)).ConditionLabel; //TConditionItem(FConditionItems.FindItemID(i)).ConditionLabel; //FConditionItems.Items[i].ConditionLabel;
    43 DataController.Values[i, 2] := 0;
    44 DataController.Values[i, 1] := '2012-01-01';
    45 end;
    46
    47 EndUpdate;
    48 end;
    49 end;
    50 end;
    51
    52 constructor TConditionUI.Create(AOwner: TComponent);
    53 begin
    54 inherited Create(AOwner);
    55 FSelectedStyle := TcxStyle.Create(Self);
    56 FSelectedStyle.Name := 'cxSelectedStyle';
    57 FSelectedStyle.Font.Name := 'MS Sans Serif';
    58 FSelectedStyle.Font.Size := 8;
    59 FSelectedStyle.Color := $00FED2B3;
    60 FSelectedStyle.AssignedValues := [svColor, svTextColor];
    61
    62 FNormalStyle := TcxStyle.Create(Self);
    63 FNormalStyle.Name := 'cxNormalStyle';
    64 FNormalStyle.Font.Name := '宋体';
    65 FNormalStyle.Font.Size := 9;
    66 FNormalStyle.Color := $00FED2B3;
    67 FNormalStyle.AssignedValues := [svColor, svFont, svTextColor];
    68
    69 FConditionItems := CreateConditionItems;
    70 end;
    71
    72 function TConditionUI.CreateConditionItems: TConditionItems;
    73 begin
    74 Result := TConditionItems.Create(Self, TConditionItem);
    75 end;
    76
    77 procedure TConditionUI.CustomDrawIndicatorCell(Sender: TcxGridTableView;
    78 ACanvas: TcxCanvas; AViewInfo: TcxCustomGridIndicatorItemViewInfo;
    79 var ADone: Boolean);
    80 var
    81 vstr: string;
    82 vCol: integer;
    83 vIndicatorViewInfo: TcxGridIndicatorRowItemViewInfo;
    84 vTextRect: TRect;
    85 vStyle: TcxStyle;
    86 begin
    87 // 行号设置
    88 if not (AViewInfo is TcxGridIndicatorRowItemViewInfo) then
    89 Exit;
    90
    91 vTextRect := AViewInfo.ContentBounds;
    92 vIndicatorViewInfo := AViewInfo as TcxGridIndicatorRowItemViewInfo;
    93 InflateRect(vTextRect, -2, -1);
    94 //vCol := 0;
    95
    96 //判断有没有子集
    97 if Sender.FindItemByName('gd_ClassViews_SonCount') <> nil then
    98 begin
    99 vCol := Sender.FindItemByName('gd_ClassViews_SonCount').Index;
    100
    101 if vIndicatorViewInfo.GridRecord.Values[vCol] > 0 then
    102 vstr := IntToStr(vIndicatorViewInfo.GridRecord.Index + 1) + '..'
    103 else
    104 vstr := IntToStr(vIndicatorViewInfo.GridRecord.Index + 1);
    105 end
    106 else
    107 vstr := IntToStr(vIndicatorViewInfo.GridRecord.Index + 1);
    108
    109 if vIndicatorViewInfo.GridRecord.Selected then
    110 vStyle := FSelectedStyle
    111 else
    112 vStyle := FNormalStyle;
    113 Sender.LookAndFeelPainter.DrawHeader(ACanvas, AViewInfo.ContentBounds,
    114 vTextRect, [], cxBordersAll, cxbsNormal, taCenter, vaCenter,
    115 False, False, vstr,
    116 vStyle.Font, vStyle.TextColor, vStyle.Color);
    117
    118 ADone := True;
    119 end;
    120
    121 destructor TConditionUI.Destroy;
    122 begin
    123 FConditionItems.Free;
    124 FConditionItems := nil;
    125
    126 inherited;
    127 end;
    128
    129 function TConditionUI.GetConditionValue(AConditionName: string): Variant;
    130 var
    131 AConditionItem : TConditionItem;
    132 begin
    133 Result := EmptyParam;
    134 AConditionItem := FConditionItems.FindItemName(AConditionName);
    135 if AConditionItem <> nil then
    136 begin
    137 Result := AConditionItem.ConditionValue;
    138 end;
    139 end;
    140
    141 procedure TConditionUI.SetConditionGrid(const Value: TcxGridTableView);
    142 begin
    143 FConditionGrid := Value;
    144 if FConditionGrid <> nil then
    145 begin
    146 // 行号
    147 FConditionGrid.OptionsView.Indicator := True;
    148 FConditionGrid.OptionsView.IndicatorWidth := 24;
    149 FConditionGrid.OnCustomDrawIndicatorCell := CustomDrawIndicatorCell;
    150 FConditionGrid.OptionsView.GroupByBox := False;
    151 end;
    152 end;
    153
    154 procedure TConditionUI.SetConditionItems(const Value: TConditionItems);
    155 begin
    156 FConditionItems.Assign(Value);
    157 end;
    158
    159 procedure TConditionUI.SetNormalStyle(const Value: TcxStyle);
    160 begin
    161 FNormalStyle.Assign(Value);
    162 end;
    163
    164 procedure TConditionUI.SetSelectedStyle(const Value: TcxStyle);
    165 begin
    166 FSelectedStyle.Assign(Value);
    167 end;

    以上代码后续应该有变更。因为现在只是一个雏形,也是记录自己学习和完成的一个过程。


  • 相关阅读:
    react 和 vue 的优缺点总结
    解决js小数求和出现多位小数问题
    同步循环发请求用promise
    hook中ref使用
    只能输入数字和保留三位的小树
    react添加右键点击事件
    redux
    深拷贝和浅拷贝区别及概念
    pointer-events的css属性。使用该属性可以决定是否能穿透绝对定位元素去触发下面元素的某些行为
    React 使用link在url添加参数(url中不可见)
  • 原文地址:https://www.cnblogs.com/codingnote/p/2432390.html
Copyright © 2011-2022 走看看