Changeset 30 for trunk/Forms/UItemEdit.pas
- Timestamp:
- Nov 24, 2011, 8:35:25 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/UItemEdit.pas
r22 r30 7 7 uses 8 8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls, 9 StdCtrls, Spin, EditBtn, USqlDatabase, MaskEdit, USystem,9 StdCtrls, Spin, EditBtn, USqlDatabase, MaskEdit, ComCtrls, USystem, 10 10 SpecializedList, SpecializedDictionary; 11 11 … … 15 15 16 16 TItemEditForm = class(TForm) 17 ButtonAdd: TButton; 18 ButtonDelete: TButton; 19 ButtonEdit: TButton; 17 20 ButtonSave: TButton; 18 21 ButtonCancel: TButton; 22 ButtonView: TButton; 23 ListView1: TListView; 19 24 Panel1: TPanel; 25 Panel2: TPanel; 26 Panel3: TPanel; 27 PanelControls: TPanel; 28 Splitter1: TSplitter; 29 TabControl1: TTabControl; 30 procedure ButtonAddClick(Sender: TObject); 20 31 procedure ButtonCancelClick(Sender: TObject); 32 procedure ButtonDeleteClick(Sender: TObject); 33 procedure ButtonEditClick(Sender: TObject); 21 34 procedure ButtonSaveClick(Sender: TObject); 35 procedure ButtonViewClick(Sender: TObject); 22 36 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); 23 37 procedure FormCreate(Sender: TObject); 24 38 procedure FormDestroy(Sender: TObject); 25 39 procedure FormShow(Sender: TObject); 40 procedure ListView1Data(Sender: TObject; Item: TListItem); 41 procedure ListView1DblClick(Sender: TObject); 42 procedure ListView1KeyPress(Sender: TObject; var Key: char); 43 procedure ListView1Resize(Sender: TObject); 44 procedure ListView1SelectItem(Sender: TObject; Item: TListItem; 45 Selected: Boolean); 46 procedure TabControl1Change(Sender: TObject); 26 47 private 27 { private declarations } 48 SelectedItem: Integer; 49 SubListObject: TChronisObject; 50 TabObjectList: TListInteger; 51 TabDataTypeList: TListObject; 52 procedure LoadSubList; 28 53 public 29 54 Report: TReport; … … 37 62 38 63 uses 39 UMainForm, UDataTypes, UCore ;64 UMainForm, UDataTypes, UCore, UItemAdd, UItemView; 40 65 41 66 {$R *.lfm} … … 47 72 Close; 48 73 end; 74 75 procedure TItemEditForm.ButtonDeleteClick(Sender: TObject); 76 begin 77 if MessageDlg(SItemDeletion, SReallyWantToDelete, mtConfirmation, [mbYes, mbNo], 0) = mrYes then begin 78 79 end; 80 end; 81 82 procedure TItemEditForm.ButtonEditClick(Sender: TObject); 83 begin 84 if Assigned(ListView1.Selected) then 85 ItemEditForm.Show; 86 end; 87 88 procedure TItemEditForm.ButtonAddClick(Sender: TObject); 89 begin 90 if Assigned(ListView1.Selected) then 91 ItemAddForm.Show; 92 end; 93 94 procedure TItemEditForm.ListView1Data(Sender: TObject; Item: TListItem); 95 var 96 I: Integer; 97 begin 98 if Item.Index < Report.Count then 99 with TReportLine(Report[Item.Index]) do begin 100 Item.Caption := Items[0]; 101 for I := 1 to Items.Count - 1 do 102 if not TReportColumn(Report.Columns[I]).VirtualItem then 103 Item.SubItems.Add(Items[I]); 104 end; 105 end; 106 107 procedure TItemEditForm.ListView1DblClick(Sender: TObject); 108 begin 109 if Assigned(ListView1.Selected) then ButtonView.Click; 110 end; 111 112 procedure TItemEditForm.ListView1KeyPress(Sender: TObject; var Key: char); 113 begin 114 if Key = #13 then ButtonView.Click; 115 end; 116 49 117 50 118 procedure TItemEditForm.ButtonSaveClick(Sender: TObject); … … 76 144 end; 77 145 146 procedure TItemEditForm.ButtonViewClick(Sender: TObject); 147 begin 148 if Assigned(ListView1.Selected) then 149 ItemViewForm.Show; 150 end; 151 78 152 procedure TItemEditForm.FormClose(Sender: TObject; var CloseAction: TCloseAction 79 153 ); … … 84 158 procedure TItemEditForm.FormCreate(Sender: TObject); 85 159 begin 160 SubListObject := TChronisObject.Create; 161 SubListObject.Base := Core.System; 86 162 Report := TReport.Create; 87 163 Report.Base := Core.System; 164 TabObjectList := TListInteger.Create; 165 TabDataTypeList := TListObject.Create; 166 TabDataTypeList.OwnsObjects := False; 167 TabControl1.Tabs.Clear; 88 168 end; 89 169 90 170 procedure TItemEditForm.FormDestroy(Sender: TObject); 91 171 begin 172 SubListObject.Free; 92 173 Report.Free; 174 TabObjectList.Free; 175 TabDataTypeList.Free; 93 176 end; 94 177 … … 97 180 MainForm.PersistentForm.Load(Self); 98 181 BuildControls; 182 LoadSubList; 99 183 end; 100 184 … … 106 190 Column: Integer; 107 191 DataType: TDataType; 108 NewControl: T WinControl;109 New Label: TLabel;192 NewControl: TControl; 193 NewWinControl: TWinControl; 110 194 const 111 195 ColumnCount = 2; … … 116 200 IntToStr(MainForm.SelectedItem)); 117 201 118 for I := Panel1.ControlCount - 1 downto 0 do 119 Panel1.Controls[I].Free; 120 202 // Clear previous controls on panel 203 for I := PanelControls.ControlCount - 1 downto 0 do 204 PanelControls.Controls[I].Free; 205 206 TabControl1.Tabs.Clear; 207 TabObjectList.Clear; 208 TabDataTypeList.Clear; 121 209 if Report.Count = 1 then 122 210 for I := 0 to Report.Columns.Count - 1 do 123 211 if (TReportColumn(Report.Columns[I]).ColumnName <> 'Id') then begin 124 125 NewLabel := TLabel.Create(Panel1);126 NewLabel.Parent := Panel1;127 NewLabel.Top := LastTop;128 NewLabel.Left := Column * Width div ColumnCount + 10;129 NewLabel.Caption := TReportColumn(Report.Columns[I]).Caption + ':';130 131 212 DataType := TReportColumn(Report.Columns[I]).CustomType; 132 213 DataType.LoadDef(TReportColumn(Report.Columns[I]).CustomType.CustomType); 133 if not (DataType is TDataTypeRelationMany) then begin 134 NewControl := DataType.CreateControl(Panel1); 214 if DataType is TDataTypeRelationMany then begin 215 TabControl1.Tabs.Add(TReportColumn(Report.Columns[I]).Caption); 216 TabDataTypeList.Add(DataType); 217 TabObjectList.Add(MainForm.SelectedItem); 218 end else begin 219 NewControl := TLabel.Create(Panel1); 220 NewControl.Parent := PanelControls; 221 NewControl.Top := LastTop; 222 NewControl.Left := Column * Width div ColumnCount + 10; 223 TLabel(NewControl).Caption := TReportColumn(Report.Columns[I]).Caption + ':'; 224 225 NewWinControl := DataType.CreateControl(Panel1); 135 226 DataType.Load(TReportLine(Report[0]).Items[I]); 136 DataType.SetupControl(New Control);137 New Control.Parent := Panel1;138 New Control.Top := LastTop;139 New Control.Left := Column * Width div ColumnCount + (Width div ColumnCount) div 2;140 New Control.Width := (Width div ColumnCount) div 2 - 20;141 TReportColumn(Report.Columns[I]).Control := New Control;227 DataType.SetupControl(NewWinControl); 228 NewWinControl.Parent := Panel1; 229 NewWinControl.Top := LastTop; 230 NewWinControl.Left := Column * Width div ColumnCount + (Width div ColumnCount) div 2; 231 NewWinControl.Width := (Width div ColumnCount) div 2 - 20; 232 TReportColumn(Report.Columns[I]).Control := NewWinControl; 142 233 143 234 Column := (Column + 1) mod 2; 144 if Column = 0 then LastTop := LastTop + New Control.Height + 4;235 if Column = 0 then LastTop := LastTop + NewWinControl.Height + 4; 145 236 end; 146 end; 147 end; 237 end; 238 // Panel1; 239 // ListView1; 240 // TabControl1; 241 Panel2.Visible := TabControl1.Tabs.Count > 0; 242 end; 243 244 procedure TItemEditForm.LoadSubList; 245 begin 246 //SelectedObjectId := 0; 247 if (TabControl1.TabIndex >= 0) and (TabControl1.TabIndex < TabControl1.Tabs.Count) then 248 with ListView1 do 249 with TDataTypeRelationMany(TabDataTypeList[TabControl1.TabIndex]) do begin 250 Visible := True; 251 SubListObject.Load(ObjectId); 252 Report.Load(SubListObject, '`' + PropertyName + '`=' + IntToStr(TabObjectList[TabControl1.TabIndex])); 253 254 Report.FillListColumns(Columns); 255 Items.Count := Report.Count; 256 Refresh; 257 end; 258 ListView1Resize(Self); 259 end; 260 261 procedure TItemEditForm.ListView1Resize(Sender: TObject); 262 var 263 I: Integer; 264 begin 265 for I := 0 to ListView1.Columns.Count - 1 do 266 ListView1.Columns[I].Width := ListView1.Width div ListView1.Columns.Count; 267 end; 268 269 procedure TItemEditForm.ListView1SelectItem(Sender: TObject; Item: TListItem; 270 Selected: Boolean); 271 begin 272 if Assigned(ListView1.Selected) then 273 SelectedItem := TReportLine(Report[ListView1.Selected.Index]).Id 274 else SelectedItem := 0; 275 276 ButtonDelete.Enabled := Assigned(ListView1.Selected); 277 ButtonView.Enabled := Assigned(ListView1.Selected); 278 ButtonEdit.Enabled := Assigned(ListView1.Selected); 279 end; 280 281 procedure TItemEditForm.TabControl1Change(Sender: TObject); 282 begin 283 LoadSubList; 284 end; 285 148 286 149 287 end.
Note:
See TracChangeset
for help on using the changeset viewer.