From 47781a3c5308d3a65387b707f595276d794fc649 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Mon, 25 Jul 2016 20:41:30 +0000 Subject: [PATCH] tvplanit: Add sqlite3 as another example for TVpFlexDatastore. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5031 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../datastores/flex/sqlite3/project1.lpi | 88 ++ .../datastores/flex/sqlite3/project1.lpr | 20 + .../datastores/flex/sqlite3/unit1.lfm | 989 ++++++++++++++++++ .../datastores/flex/sqlite3/unit1.pas | 328 ++++++ 4 files changed, 1425 insertions(+) create mode 100644 components/tvplanit/examples/datastores/flex/sqlite3/project1.lpi create mode 100644 components/tvplanit/examples/datastores/flex/sqlite3/project1.lpr create mode 100644 components/tvplanit/examples/datastores/flex/sqlite3/unit1.lfm create mode 100644 components/tvplanit/examples/datastores/flex/sqlite3/unit1.pas diff --git a/components/tvplanit/examples/datastores/flex/sqlite3/project1.lpi b/components/tvplanit/examples/datastores/flex/sqlite3/project1.lpi new file mode 100644 index 000000000..90a062a9b --- /dev/null +++ b/components/tvplanit/examples/datastores/flex/sqlite3/project1.lpi @@ -0,0 +1,88 @@ + + + + + + + + + + <ResourceType Value="res"/> + <UseXPManifest Value="True"/> + </General> + <VersionInfo> + <StringTable ProductVersion=""/> + </VersionInfo> + <BuildModes Count="1"> + <Item1 Name="Default" Default="True"/> + </BuildModes> + <PublishOptions> + <Version Value="2"/> + </PublishOptions> + <RunParams> + <local> + <FormatVersion Value="1"/> + </local> + </RunParams> + <RequiredPackages Count="4"> + <Item1> + <PackageName Value="SQLDBLaz"/> + </Item1> + <Item2> + <PackageName Value="FCL"/> + </Item2> + <Item3> + <PackageName Value="laz_visualplanit"/> + </Item3> + <Item4> + <PackageName Value="LCL"/> + </Item4> + </RequiredPackages> + <Units Count="2"> + <Unit0> + <Filename Value="project1.lpr"/> + <IsPartOfProject Value="True"/> + </Unit0> + <Unit1> + <Filename Value="unit1.pas"/> + <IsPartOfProject Value="True"/> + <ComponentName Value="Form1"/> + <HasResources Value="True"/> + <ResourceBaseClass Value="Form"/> + <UnitName Value="Unit1"/> + </Unit1> + </Units> + </ProjectOptions> + <CompilerOptions> + <Version Value="11"/> + <PathDelim Value="\"/> + <Target> + <Filename Value="project1"/> + </Target> + <SearchPaths> + <IncludeFiles Value="$(ProjOutDir);dbase"/> + <OtherUnitFiles Value="dbase"/> + <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/> + </SearchPaths> + <Linking> + <Options> + <Win32> + <GraphicApplication Value="True"/> + </Win32> + </Options> + </Linking> + </CompilerOptions> + <Debugging> + <Exceptions Count="3"> + <Item1> + <Name Value="EAbort"/> + </Item1> + <Item2> + <Name Value="ECodetoolError"/> + </Item2> + <Item3> + <Name Value="EFOpenError"/> + </Item3> + </Exceptions> + </Debugging> +</CONFIG> diff --git a/components/tvplanit/examples/datastores/flex/sqlite3/project1.lpr b/components/tvplanit/examples/datastores/flex/sqlite3/project1.lpr new file mode 100644 index 000000000..cbaf9b146 --- /dev/null +++ b/components/tvplanit/examples/datastores/flex/sqlite3/project1.lpr @@ -0,0 +1,20 @@ +program project1; + +{$mode objfpc}{$H+} + +uses + {$IFDEF UNIX}{$IFDEF UseCThreads} + cthreads, + {$ENDIF}{$ENDIF} + Interfaces, // this includes the LCL widgetset + Forms, Unit1, laz_visualplanit; + +{$R *.res} + +begin + RequireDerivedFormResource := True; + Application.Initialize; + Application.CreateForm(TForm1, Form1); + Application.Run; +end. + diff --git a/components/tvplanit/examples/datastores/flex/sqlite3/unit1.lfm b/components/tvplanit/examples/datastores/flex/sqlite3/unit1.lfm new file mode 100644 index 000000000..a83f56d9a --- /dev/null +++ b/components/tvplanit/examples/datastores/flex/sqlite3/unit1.lfm @@ -0,0 +1,989 @@ +object Form1: TForm1 + Left = 344 + Height = 686 + Top = 169 + Width = 980 + Caption = 'Form1' + ClientHeight = 686 + ClientWidth = 980 + OnCreate = FormCreate + OnDestroy = FormDestroy + LCLVersion = '1.7' + object Panel1: TPanel + Left = 0 + Height = 34 + Top = 0 + Width = 980 + Align = alTop + BevelOuter = bvNone + ClientHeight = 34 + ClientWidth = 980 + TabOrder = 0 + object VpResourceCombo1: TVpResourceCombo + Left = 8 + Height = 23 + Top = 5 + Width = 208 + DataStore = VpFlexDataStore1 + Style = csDropDownList + end + object BtnNewRes: TButton + Left = 222 + Height = 25 + Top = 4 + Width = 99 + Caption = 'New resource' + OnClick = BtnNewResClick + TabOrder = 1 + end + object BtnEditRes: TButton + Left = 328 + Height = 25 + Top = 4 + Width = 96 + Caption = 'Edit resource' + OnClick = BtnEditResClick + TabOrder = 2 + end + end + object PageControl1: TPageControl + Left = 0 + Height = 652 + Top = 34 + Width = 980 + ActivePage = TabSheet1 + Align = alClient + TabIndex = 0 + TabOrder = 1 + object TabSheet1: TTabSheet + Caption = 'Events and tasks' + ClientHeight = 624 + ClientWidth = 972 + object VpDayView1: TVpDayView + Left = 0 + Height = 624 + Top = 0 + Width = 301 + DataStore = VpFlexDataStore1 + ControlLink = VpControlLink1 + Color = clWindow + Align = alLeft + ReadOnly = False + TabStop = True + TabOrder = 0 + AllDayEventAttributes.BackgroundColor = clBtnShadow + AllDayEventAttributes.EventBorderColor = cl3DDkShadow + AllDayEventAttributes.EventBackgroundColor = clBtnFace + ShowEventTimes = False + DrawingStyle = dsFlat + TimeSlotColors.Active = clWhite + TimeSlotColors.Inactive = 8454143 + TimeSlotColors.Holiday = 16744703 + TimeSlotColors.Weekday = clWhite + TimeSlotColors.Weekend = 16777088 + TimeSlotColors.ActiveRange.RangeBegin = h_00 + TimeSlotColors.ActiveRange.RangeEnd = h_00 + HeadAttributes.Font.Height = -13 + HeadAttributes.Color = clBtnFace + RowHeadAttributes.HourFont.Height = -24 + RowHeadAttributes.MinuteFont.Height = -12 + RowHeadAttributes.Color = clBtnFace + ShowResourceName = True + LineColor = clGray + GutterWidth = 7 + DateLabelFormat = 'dddd, mmmm dd, yyyy' + Granularity = gr30Min + DefaultTopHour = h_07 + TimeFormat = tf12Hour + end + object Panel2: TPanel + Left = 306 + Height = 624 + Top = 0 + Width = 386 + Align = alLeft + BevelOuter = bvNone + Caption = 'Panel2' + ClientHeight = 624 + ClientWidth = 386 + TabOrder = 1 + object VpWeekView1: TVpWeekView + Left = 0 + Height = 378 + Top = 0 + Width = 386 + DataStore = VpFlexDataStore1 + ControlLink = VpControlLink1 + Color = clWindow + AllDayEventAttributes.BackgroundColor = clWindow + AllDayEventAttributes.EventBorderColor = clGray + AllDayEventAttributes.EventBackgroundColor = clBtnFace + DateLabelFormat = 'dddd, mmmm dd, yyyy' + DayHeadAttributes.Color = clBtnFace + DayHeadAttributes.DateFormat = 'dddd mmmm, dd' + DayHeadAttributes.Font.Height = -13 + DayHeadAttributes.Font.Name = 'Tahoma' + DayHeadAttributes.Bordered = True + DrawingStyle = dsFlat + HeadAttributes.Color = clBtnFace + LineColor = clGray + TimeFormat = tf12Hour + ShowEventTime = True + WeekStartsOn = dtMonday + Align = alClient + TabStop = True + TabOrder = 0 + end + object VpMonthView1: TVpMonthView + Left = 0 + Height = 241 + Top = 383 + Width = 386 + DataStore = VpFlexDataStore1 + ControlLink = VpControlLink1 + Color = clWindow + Align = alBottom + TabStop = True + TabOrder = 1 + KBNavigation = True + DateLabelFormat = 'mmmm yyyy' + DayHeadAttributes.Color = clBtnFace + DayHeadAttributes.Font.Height = -13 + DayHeadAttributes.Font.Name = 'Tahoma' + DayNameStyle = dsShort + DrawingStyle = dsFlat + EventDayStyle = [] + HeadAttributes.Color = clBtnFace + LineColor = clGray + TimeFormat = tf12Hour + TodayAttributes.Color = clSilver + TodayAttributes.BorderPen.Color = clRed + TodayAttributes.BorderPen.Width = 3 + OffDayColor = clSilver + SelectedDayColor = clRed + ShowEvents = True + ShowEventTime = False + WeekStartsOn = dtMonday + end + object Splitter2: TSplitter + Cursor = crVSplit + Left = 0 + Height = 5 + Top = 378 + Width = 386 + Align = alBottom + ResizeAnchor = akBottom + end + end + object VpTaskList1: TVpTaskList + Left = 697 + Height = 624 + Top = 0 + Width = 275 + DataStore = VpFlexDataStore1 + ControlLink = VpControlLink1 + Color = clWindow + Align = alClient + TabStop = True + TabOrder = 2 + ReadOnly = False + DisplayOptions.CheckBGColor = clWindow + DisplayOptions.CheckColor = cl3DDkShadow + DisplayOptions.CheckStyle = csCheck + DisplayOptions.DueDateFormat = 'dd.MM.yyyy' + DisplayOptions.ShowCompletedTasks = True + DisplayOptions.ShowAll = False + DisplayOptions.ShowDueDate = True + DisplayOptions.OverdueColor = clRed + DisplayOptions.NormalColor = clBlack + DisplayOptions.CompletedColor = clGray + LineColor = clGray + MaxVisibleTasks = 250 + TaskHeadAttributes.Color = clSilver + DrawingStyle = dsFlat + ShowResourceName = True + end + object Splitter1: TSplitter + Left = 692 + Height = 624 + Top = 0 + Width = 5 + end + object Splitter3: TSplitter + Left = 301 + Height = 624 + Top = 0 + Width = 5 + end + end + object TabSheet2: TTabSheet + Caption = 'Contacts' + ClientHeight = 624 + ClientWidth = 972 + object VpContactButtonBar1: TVpContactButtonBar + Left = 0 + Height = 624 + Top = 0 + Width = 40 + DrawingStyle = dsFlat + RadioStyle = False + Align = alLeft + end + object VpContactGrid1: TVpContactGrid + Left = 40 + Height = 624 + Top = 0 + Width = 932 + DataStore = VpFlexDataStore1 + ControlLink = VpControlLink1 + Color = clWindow + Align = alClient + TabStop = True + TabOrder = 1 + AllowInPlaceEditing = True + BarWidth = 3 + BarColor = clSilver + ColumnWidth = 200 + ContactHeadAttributes.Color = clSilver + ContactHeadAttributes.Bordered = True + DrawingStyle = dsFlat + end + end + end + object VpControlLink1: TVpControlLink + DataStore = VpFlexDataStore1 + Printer.BottomMargin = 0 + Printer.DayStart = h_08 + Printer.DayEnd = h_05 + Printer.Granularity = gr30Min + Printer.LeftMargin = 0 + Printer.MarginUnits = imAbsolutePixel + Printer.PrintFormats = <> + Printer.RightMargin = 0 + Printer.TopMargin = 0 + left = 136 + top = 168 + end + object VpResourceEditDialog1: TVpResourceEditDialog + Version = 'v1.04' + DataStore = VpFlexDataStore1 + Options = [] + Placement.Position = mpCenter + Placement.Top = 10 + Placement.Left = 10 + Placement.Height = 250 + Placement.Width = 400 + left = 136 + top = 232 + end + object VpFlexDataStore1: TVpFlexDataStore + CategoryColorMap.Category0.Color = clNavy + CategoryColorMap.Category0.Description = 'Category 0' + CategoryColorMap.Category1.Color = clRed + CategoryColorMap.Category1.Description = 'Category 1' + CategoryColorMap.Category2.Color = clYellow + CategoryColorMap.Category2.Description = 'Category 2' + CategoryColorMap.Category3.Color = clLime + CategoryColorMap.Category3.Description = 'Category 3' + CategoryColorMap.Category4.Color = clPurple + CategoryColorMap.Category4.Description = 'Category 4' + CategoryColorMap.Category5.Color = clTeal + CategoryColorMap.Category5.Description = 'Category 5' + CategoryColorMap.Category6.Color = clFuchsia + CategoryColorMap.Category6.Description = 'Category 6' + CategoryColorMap.Category7.Color = clOlive + CategoryColorMap.Category7.Description = 'Category 7' + CategoryColorMap.Category8.Color = clAqua + CategoryColorMap.Category8.Description = 'Category 8' + CategoryColorMap.Category9.Color = clMaroon + CategoryColorMap.Category9.Description = 'Category 9' + EnableEventTimer = True + PlayEventSounds = True + AutoConnect = False + AutoCreate = False + DayBuffer = 31 + DataSources.ResourceDataSource = DsResources + DataSources.EventsDataSource = DsEvents + DataSources.ContactsDataSource = DsContacts + DataSources.TasksDataSource = DsTasks + ResourceID = 0 + OnSetFilterCriteria = VpFlexDataStore1SetFilterCriteria + left = 136 + top = 101 + ResourceFieldMappings = ( + 'ResourceID' + 'ResourceID' + 'Description' + 'Description' + 'Notes' + 'Notes' + 'ImageIndex' + 'ImageIndex' + 'ResourceActive' + 'ResourceActive' + 'UserField0' + 'UserField0' + 'UserField1' + 'UserField1' + 'UserField2' + 'UserField2' + 'UserField3' + 'UserField3' + 'UserField4' + 'UserField4' + 'UserField5' + 'UserField5' + 'UserField6' + 'UserField6' + 'UserField7' + 'UserField7' + 'UserField8' + 'UserField8' + 'UserField9' + 'UserField9' + ) + EventFieldMappings = ( + 'RecordID' + 'RecordID' + 'ResourceID' + 'ResourceID' + 'StartTime' + 'StartTime' + 'EndTime' + 'EndTime' + 'Description' + 'Description' + 'Location' + 'Location' + 'Notes' + 'Notes' + 'Category' + 'Category' + 'AllDayEvent' + 'AllDayEvent' + 'DingPath' + 'DingPath' + 'AlarmSet' + 'AlarmSet' + 'AlarmAdvance' + 'AlarmAdvance' + 'AlarmAdvanceType' + 'AlarmAdvanceType' + 'SnoozeTime' + 'SnoozeTime' + 'RepeatCode' + 'RepeatCode' + 'RepeatRangeEnd' + 'RepeatRangeEnd' + 'CustomInterval' + 'CustomInterval' + ) + ContactFieldMappings = ( + 'RecordID' + 'RecordID' + 'ResourceID' + 'ResourceID' + 'FirstName' + 'FirstName' + 'LastName' + 'LastName' + 'Birthdate' + 'Birthdate' + 'Anniversary' + 'Anniversary' + 'Title' + 'Title' + 'Company' + 'Company' + 'Job_Position' + 'Job_Position' + 'Address' + 'Address' + 'City' + 'City' + 'State' + 'State' + 'Zip' + 'Zip' + 'Country' + 'Country' + 'Notes' + 'Notes' + 'Phone1' + 'Phone1' + 'Phone2' + 'Phone2' + 'Phone3' + 'Phone3' + 'Phone4' + 'Phone4' + 'Phone5' + 'Phone5' + 'PhoneType1' + 'PhoneType1' + 'PhoneType2' + 'PhoneType2' + 'PhoneType3' + 'PhoneType3' + 'PhoneType4' + 'PhoneType4' + 'PhoneType5' + 'PhoneType5' + 'Category' + 'Category' + 'EMail' + 'EMail' + 'Custom1' + 'Custom1' + 'Custom2' + 'Custom2' + 'Custom3' + 'Custom3' + 'Custom4' + 'Custom4' + ) + TaskFieldMappings = ( + 'RecordID' + 'RecordID' + 'ResourceID' + 'ResourceID' + 'Complete' + 'Complete' + 'Description' + 'Description' + 'Details' + 'Details' + 'CreatedOn' + 'CreatedOn' + 'Priority' + 'Priority' + 'Category' + 'Category' + 'CompletedOn' + 'CompletedOn' + 'DueDate' + 'DueDate' + ) + end + object DsResources: TDataSource + DataSet = QryResources + left = 240 + top = 428 + end + object DsContacts: TDataSource + DataSet = QryContacts + left = 240 + top = 496 + end + object DsEvents: TDataSource + DataSet = QryEvents + left = 240 + top = 560 + end + object DsTasks: TDataSource + DataSet = QryTasks + left = 240 + top = 621 + end + object QryResources: TSQLQuery + PacketRecords = -1 + FieldDefs = < + item + Name = 'ResourceID' + Attributes = [faReadonly] + DataType = ftAutoInc + Precision = -1 + end + item + Name = 'Description' + DataType = ftString + Precision = -1 + Size = 255 + end + item + Name = 'Notes' + DataType = ftString + Precision = -1 + Size = 255 + end + item + Name = 'ImageIndex' + DataType = ftInteger + Precision = -1 + end + item + Name = 'ResourceActive' + DataType = ftBoolean + Precision = -1 + end + item + Name = 'UserField0' + DataType = ftString + Precision = -1 + Size = 100 + end + item + Name = 'UserField1' + DataType = ftString + Precision = -1 + Size = 100 + end + item + Name = 'UserField2' + DataType = ftString + Precision = -1 + Size = 100 + end + item + Name = 'UserField3' + DataType = ftString + Precision = -1 + Size = 100 + end + item + Name = 'UserField4' + DataType = ftString + Precision = -1 + Size = 100 + end + item + Name = 'UserField5' + DataType = ftString + Precision = -1 + Size = 100 + end + item + Name = 'UserField6' + DataType = ftString + Precision = -1 + Size = 100 + end + item + Name = 'UserField7' + DataType = ftString + Precision = -1 + Size = 100 + end + item + Name = 'UserField8' + DataType = ftString + Precision = -1 + Size = 100 + end + item + Name = 'UserField9' + DataType = ftString + Precision = -1 + Size = 100 + end> + Database = SQLite3Connection1 + Transaction = SQLTransaction1 + SQL.Strings = ( + 'SELECT * FROM Resources' + ) + UpdateSQL.Strings = ( + '' + ) + DeleteSQL.Strings = ( + '' + ) + Options = [sqoKeepOpenOnCommit, sqoAutoApplyUpdates, sqoAutoCommit] + Params = <> + left = 136 + top = 428 + end + object QryContacts: TSQLQuery + PacketRecords = -1 + FieldDefs = < + item + Name = 'RecordID' + Attributes = [faReadonly] + DataType = ftAutoInc + Precision = -1 + end + item + Name = 'ResourceID' + DataType = ftInteger + Precision = -1 + end + item + Name = 'FirstName' + DataType = ftString + Precision = -1 + Size = 50 + end + item + Name = 'LastName' + DataType = ftString + Precision = -1 + Size = 50 + end + item + Name = 'Birthdate' + DataType = ftDateTime + Precision = -1 + end + item + Name = 'Anniversary' + DataType = ftDateTime + Precision = -1 + end + item + Name = 'Title' + DataType = ftString + Precision = -1 + Size = 50 + end + item + Name = 'Company' + DataType = ftString + Precision = -1 + Size = 50 + end + item + Name = 'Job_Position' + DataType = ftString + Precision = -1 + Size = 30 + end + item + Name = 'Address' + DataType = ftString + Precision = -1 + Size = 100 + end + item + Name = 'City' + DataType = ftString + Precision = -1 + Size = 50 + end + item + Name = 'State' + DataType = ftString + Precision = -1 + Size = 25 + end + item + Name = 'Zip' + DataType = ftString + Precision = -1 + Size = 10 + end + item + Name = 'Country' + DataType = ftString + Precision = -1 + Size = 25 + end + item + Name = 'Notes' + DataType = ftString + Precision = -1 + Size = 255 + end + item + Name = 'Phone1' + DataType = ftString + Precision = -1 + Size = 25 + end + item + Name = 'Phone2' + DataType = ftString + Precision = -1 + Size = 25 + end + item + Name = 'Phone3' + DataType = ftString + Precision = -1 + Size = 25 + end + item + Name = 'Phone4' + DataType = ftString + Precision = -1 + Size = 25 + end + item + Name = 'Phone5' + DataType = ftString + Precision = -1 + Size = 25 + end + item + Name = 'PhoneType1' + DataType = ftInteger + Precision = -1 + end + item + Name = 'PhoneType2' + DataType = ftInteger + Precision = -1 + end + item + Name = 'PhoneType3' + DataType = ftInteger + Precision = -1 + end + item + Name = 'PhoneType4' + DataType = ftInteger + Precision = -1 + end + item + Name = 'PhoneType5' + DataType = ftInteger + Precision = -1 + end + item + Name = 'Category' + DataType = ftInteger + Precision = -1 + end + item + Name = 'EMail' + DataType = ftString + Precision = -1 + Size = 100 + end + item + Name = 'Custom1' + DataType = ftString + Precision = -1 + Size = 100 + end + item + Name = 'Custom2' + DataType = ftString + Precision = -1 + Size = 100 + end + item + Name = 'Custom3' + DataType = ftString + Precision = -1 + Size = 100 + end + item + Name = 'Custom4' + DataType = ftString + Precision = -1 + Size = 100 + end> + Database = SQLite3Connection1 + Transaction = SQLTransaction1 + SQL.Strings = ( + 'SELECT * FROM Contacts' + ) + UpdateSQL.Strings = ( + '' + ) + DeleteSQL.Strings = ( + '' + ) + Options = [sqoKeepOpenOnCommit, sqoAutoApplyUpdates, sqoAutoCommit] + Params = <> + left = 136 + top = 496 + end + object QryEvents: TSQLQuery + PacketRecords = -1 + FieldDefs = < + item + Name = 'RecordID' + Attributes = [faReadonly] + DataType = ftAutoInc + Precision = -1 + end + item + Name = 'ResourceID' + DataType = ftInteger + Precision = -1 + end + item + Name = 'StartTime' + DataType = ftDateTime + Precision = -1 + end + item + Name = 'EndTime' + DataType = ftDateTime + Precision = -1 + end + item + Name = 'Description' + DataType = ftString + Precision = -1 + Size = 255 + end + item + Name = 'Location' + DataType = ftString + Precision = -1 + Size = 255 + end + item + Name = 'Notes' + DataType = ftString + Precision = -1 + Size = 255 + end + item + Name = 'Category' + DataType = ftInteger + Precision = -1 + end + item + Name = 'AllDayEvent' + DataType = ftBoolean + Precision = -1 + end + item + Name = 'DingPath' + DataType = ftString + Precision = -1 + Size = 255 + end + item + Name = 'AlarmSet' + DataType = ftBoolean + Precision = -1 + end + item + Name = 'AlarmAdvance' + DataType = ftInteger + Precision = -1 + end + item + Name = 'AlarmAdvanceType' + DataType = ftInteger + Precision = -1 + end + item + Name = 'SnoozeTime' + DataType = ftDateTime + Precision = -1 + end + item + Name = 'RepeatCode' + DataType = ftInteger + Precision = -1 + end + item + Name = 'RepeatRangeEnd' + DataType = ftDateTime + Precision = -1 + end + item + Name = 'CustomInterval' + DataType = ftInteger + Precision = -1 + end> + Database = SQLite3Connection1 + Transaction = SQLTransaction1 + SQL.Strings = ( + 'SELECT * FROM Events' + ) + UpdateSQL.Strings = ( + '' + ) + DeleteSQL.Strings = ( + '' + ) + Options = [sqoKeepOpenOnCommit, sqoAutoApplyUpdates, sqoAutoCommit] + Params = <> + left = 136 + top = 560 + end + object QryTasks: TSQLQuery + PacketRecords = -1 + FieldDefs = < + item + Name = 'RecordID' + Attributes = [faReadonly] + DataType = ftAutoInc + Precision = -1 + end + item + Name = 'ResourceID' + DataType = ftInteger + Precision = -1 + end + item + Name = 'Complete' + DataType = ftBoolean + Precision = -1 + end + item + Name = 'Description' + DataType = ftString + Precision = -1 + Size = 255 + end + item + Name = 'Details' + DataType = ftString + Precision = -1 + Size = 255 + end + item + Name = 'CreatedOn' + DataType = ftDateTime + Precision = -1 + end + item + Name = 'Priority' + DataType = ftInteger + Precision = -1 + end + item + Name = 'Category' + DataType = ftInteger + Precision = -1 + end + item + Name = 'CompletedOn' + DataType = ftDateTime + Precision = -1 + end + item + Name = 'DueDate' + DataType = ftDateTime + Precision = -1 + end> + Database = SQLite3Connection1 + Transaction = SQLTransaction1 + SQL.Strings = ( + 'SELECT * FROM Tasks' + ) + UpdateSQL.Strings = ( + '' + ) + DeleteSQL.Strings = ( + '' + ) + Options = [sqoKeepOpenOnCommit, sqoAutoApplyUpdates, sqoAutoCommit] + Params = <> + left = 136 + top = 621 + end + object SQLTransaction1: TSQLTransaction + Active = False + Database = SQLite3Connection1 + Options = [] + left = 136 + top = 368 + end + object SQLite3Connection1: TSQLite3Connection + Connected = False + LoginPrompt = False + DatabaseName = 'data.db' + KeepConnection = False + Transaction = SQLTransaction1 + Options = [] + left = 136 + top = 312 + end +end diff --git a/components/tvplanit/examples/datastores/flex/sqlite3/unit1.pas b/components/tvplanit/examples/datastores/flex/sqlite3/unit1.pas new file mode 100644 index 000000000..1ac1d3ba1 --- /dev/null +++ b/components/tvplanit/examples/datastores/flex/sqlite3/unit1.pas @@ -0,0 +1,328 @@ +unit Unit1; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls, + StdCtrls, ComCtrls, + db, DBGrids, DbCtrls, sqldb, sqlite3conn, + VpBaseDS, VpDayView, VpWeekView, VpTaskList, VpContactGrid, VpMonthView, + VpResEditDlg, VpContactButtons, VpData, VpFlxDS; + +type + + { TForm1 } + + TForm1 = class(TForm) + BtnNewRes: TButton; + BtnEditRes: TButton; + DsTasks: TDataSource; + DsEvents: TDataSource; + DsContacts: TDataSource; + DsResources: TDataSource; + PageControl1: TPageControl; + Panel1: TPanel; + Panel2: TPanel; + Splitter1: TSplitter; + Splitter2: TSplitter; + Splitter3: TSplitter; + QryResources: TSQLQuery; + QryContacts: TSQLQuery; + QryEvents: TSQLQuery; + QryTasks: TSQLQuery; + SQLite3Connection1: TSQLite3Connection; + SQLTransaction1: TSQLTransaction; + TabSheet1: TTabSheet; + TabSheet2: TTabSheet; + VpContactButtonBar1: TVpContactButtonBar; + VpContactGrid1: TVpContactGrid; + VpControlLink1: TVpControlLink; + VpDayView1: TVpDayView; + VpFlexDataStore1: TVpFlexDataStore; + VpMonthView1: TVpMonthView; + VpResourceCombo1: TVpResourceCombo; + VpResourceEditDialog1: TVpResourceEditDialog; + VpTaskList1: TVpTaskList; + VpWeekView1: TVpWeekView; + procedure BtnNewResClick(Sender: TObject); + procedure BtnEditResClick(Sender: TObject); + procedure Button1Click(Sender: TObject); + procedure FormCreate(Sender: TObject); + procedure FormDestroy(Sender: TObject); + procedure VpFlexDataStore1SetFilterCriteria(aTable: TDataset; + aUseDateTime: Boolean; aResourceID: Integer; aStartDateTime, + aEndDateTime: TDateTime); + private + procedure CreateContacts; + procedure CreateDB(AFileName: String); + procedure CreateEvents; + procedure CreateResources; + procedure CreateTasks; + public + { public declarations } + end; + +var + Form1: TForm1; + +implementation + +{$R *.lfm} + +uses + LazFileUtils; + +const + DB_NAME = 'data.db'; + + // More information on the use of these values is below. + // They need not be set as constants in your application. They can be any valid value + APPLICATION_ID = 1189021115; // must be a 32-bit Unsigned Integer (Longword 0 .. 4294967295) + USER_VERSION = 23400001; // must be a 32-bit Signed Integer (LongInt -2147483648 .. 2147483647) + + +{ TForm1 } + +// Adds a new resource +procedure TForm1.BtnNewResClick(Sender: TObject); +begin + VpResourceEditDialog1.AddNewResource; +end; + +// Edits the currently selected resource +procedure TForm1.BtnEditResClick(Sender: TObject); +begin + // Open the resource editor dialog, everything is done here. + VpResourceEditDialog1.Execute; +end; + +procedure TForm1.Button1Click(Sender: TObject); +begin + VpFlexDatastore1.Load; +end; + +procedure TForm1.CreateDB(AFileName: String); +begin + SQLite3Connection1.Close; // Ensure the connection is closed when we start + + // Create the database and the tables + try + SQLite3Connection1.DatabaseName := AFileName; + SQLite3Connection1.Open; + SQLTransaction1.Active := true; + + // Per the SQLite Documentation (edited for clarity): + // The pragma user_version is used to set or get the value of the user-version. + // The user-version is a big-endian 32-bit signed integer stored in the database header at offset 60. + // The user-version is not used internally by SQLite. It may be used by applications for any purpose. + // http://www.sqlite.org/pragma.html#pragma_schema_version + SQLite3Connection1.ExecuteDirect('PRAGMA user_version = ' + IntToStr(user_version) + ';'); + + // Per the SQLite Documentation: + // The application_id PRAGMA is used to query or set the 32-bit unsigned big-endian + // "Application ID" integer located at offset 68 into the database header. + // Applications that use SQLite as their application file-format should set the + // Application ID integer to a unique integer so that utilities such as file(1) can + // determine the specific file type rather than just reporting "SQLite3 Database". + // A list of assigned application IDs can be seen by consulting the magic.txt file + // in the SQLite source repository. + // http://www.sqlite.org/pragma.html#pragma_application_id + SQLite3Connection1.ExecuteDirect('PRAGMA application_id = ' + IntToStr(application_id) + ';'); + + CreateContacts; + CreateEvents; + CreateTasks; + CreateResources; + + SQLTransaction1.Commit; + SQLite3Connection1.Close; + + except + ShowMessage(Format('Unable to create database "%s".', [AFileName])); + end; +end; + +procedure TForm1.CreateContacts; +begin + SQLite3Connection1.ExecuteDirect( + 'CREATE TABLE Contacts (' + + '"RecordID" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, '+ + '"ResourceID" INTEGER NOT NULL, ' + + '"FirstName" VARCHAR(50), '+ + '"LastName" VARCHAR(50), '+ + '"Birthdate" DATETIME, '+ + '"Anniversary" DATETIME, '+ + '"Title" VARCHAR(50), '+ + '"Company" VARCHAR(50), '+ + '"Job_Position" VARCHAR(30), '+ + '"Address" VARCHAR(100), '+ + '"City" VARCHAR(50), '+ + '"State" VARCHAR(25), '+ + '"Zip" VARCHAR(10), '+ + '"Country" VARCHAR(25), '+ + '"Notes" VARCHAR(1024), '+ + '"Phone1" VARCHAR(25), '+ + '"Phone2" VARCHAR(25), '+ + '"Phone3" VARCHAR(25), '+ + '"Phone4" VARCHAR(25), '+ + '"Phone5" VARCHAR(25), '+ + '"PhoneType1" INTEGER, '+ + '"PhoneType2" INTEGER, '+ + '"PhoneType3" INTEGER, '+ + '"PhoneType4" INTEGER, '+ + '"PhoneType5" INTEGER, '+ + '"Category" INTEGER, '+ + '"EMail" VARCHAR (100), '+ + '"Custom1" VARCHAR (100), '+ + '"Custom2" VARCHAR (100), '+ + '"Custom3" VARCHAR (100), '+ + '"Custom4" VARCHAR (100)); ' + ); + SQLite3Connection1.ExecuteDirect( + 'CREATE UNIQUE INDEX "Contacts_RecordID_idx" ON "Contacts" ("RecordID");' + ); + SQLite3Connection1.ExecuteDirect( + 'CREATE INDEX "Contacts_ResourceID_idx" ON "Contacts" ("ResourceID");' + ); +end; + +procedure TForm1.CreateEvents; +begin + SQLite3Connection1.ExecuteDirect( + 'CREATE TABLE Events (' + + '"RecordID" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, ' + + '"ResourceID" INTEGER NOT NULL, ' + + '"StartTime" DATETIME NOT NULL, ' + + '"EndTime" DATETIME NOT NULL, ' + + '"Description" VARCHAR (255), ' + + '"Location" VARCHAR (255), ' + + '"Notes" VARCHAR (1024), ' + + '"Category" INTEGER, ' + + '"AllDayEvent" BOOLEAN, ' + + '"DingPath" VARCHAR (255), ' + + '"AlarmSet" BOOLEAN, ' + + '"AlarmAdvance" INTEGER, ' + + '"AlarmAdvanceType" INTEGER, ' + + '"SnoozeTime" DATETIME, ' + + '"RepeatCode" INTEGER, ' + + '"RepeatRangeEnd" DATETIME, ' + + '"CustomInterval" INTEGER );' + ); + SQLite3Connection1.ExecuteDirect( + 'CREATE UNIQUE INDEX "Events_RecordID_idx" ON "Events" ("RecordID");' + ); + SQLite3Connection1.ExecuteDirect( + 'CREATE INDEX "Events_ResourceID_idx" ON "Events" ("ResourceID");' + ); + SQLite3Connection1.ExecuteDirect( + 'CREATE INDEX "Events_StartTime_idx" ON "Events" ("StartTime");' + ); + SQLIte3Connection1.ExecuteDirect( + 'CREATE INDEX "Events_EndTime_idx" ON "Events" ("EndTime");'); +end; + +procedure TForm1.CreateResources; +begin + SQLite3Connection1.ExecuteDirect( + 'CREATE TABLE Resources (' + + '"ResourceID" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, '+ + '"Description" VARCHAR (255), ' + + '"Notes" VARCHAR (1024), ' + + '"ImageIndex" INTEGER, ' + + '"ResourceActive" BOOLEAN );' + ); + SQLite3Connection1.ExecuteDirect( + 'CREATE UNIQUE INDEX "Resources_ResourceID_idx" ON "Resources" ("ResourceID");' + ); +end; + +procedure TForm1.CreateTasks; +begin + SQLite3Connection1.ExecuteDirect( + 'CREATE TABLE Tasks (' + + '"RecordID" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, ' + + '"ResourceID" INTEGER NOT NULL, ' + + '"Complete" BOOLEAN, ' + + '"Description" VARCHAR(255), ' + + '"Details" VARCHAR(1024), ' + + '"CreatedOn" DATETIME, ' + + '"Priority" INTEGER, ' + + '"Category" INTEGER, ' + + '"CompletedOn" DATETIME, ' + + '"DueDate" DATETIME);' + ); + SQLite3Connection1.ExecuteDirect( + 'CREATE UNIQUE INDEX "Tasks_RecordID_idx" ON "Tasks" ("RecordID");' + ); + SQLite3Connection1.ExecuteDirect( + 'CREATE INDEX "Tasks_ResourceID_idx" ON "Tasks" ("ResourceID");' + ); +end; + +// Setting up the database connection and the datastore. Preselect a resource +// in the resource combo. +procedure TForm1.FormCreate(Sender: TObject); +begin + try + // Connection + Sqlite3Connection1.DatabaseName := DB_NAME; + + // Transaction + SQLTransaction1.DataBase := Sqlite3Connection1; + + if not FileExists(AppendPathDelim(Application.Location) + DB_NAME) then + CreateDB(AppendPathDelim(Application.Location) + DB_NAME); + + // Connect the datastore. This opens the datasets and loads them into the store. + VpFlexDatastore1.Connected := true; + + // Pre-select the first resource item + if VpFlexDatastore1.Resources.Count > 0 then + VpFlexDatastore1.Resource := VpFlexDatastore1.Resources.Items[0]; + + PageControl1.ActivePageIndex := 0; + + except + on E:Exception do + begin + MessageDlg('ERROR', mtError, [mbOK], 0); + Close; + end; + end; +end; + +procedure TForm1.FormDestroy(Sender: TObject); +begin + Sqlite3Connection1.Connected := false; +end; + +{ This event handler is used by the planner to filter those records from the + specified table which belong to the requested resource ID and are within + the requested time interval. + Note that SQLDB uses the DBF syntax for filtering dates, i.e. + - Convert DateTime field values to strings using DTOS() + - Date parameters must be quoted and formatted as "yyyymmdd". + See: http://forum.lazarus.freepascal.org/index.php?topic=23077.0 } +procedure TForm1.VpFlexDataStore1SetFilterCriteria(ATable: TDataset; + AUseDateTime: Boolean; AResourceID: Integer; AStartDateTime, + AEndDateTime: TDateTime); +begin + if AUseDateTime then + ATable.Filter := Format( + '(ResourceID = %d) AND (' + + '((DTOS(StartTime) >= "%s") and (DTOS(EndTime) <= "%s")) OR ' + + '((RepeatCode > 0) and (DTOS(RepeatRangeEnd) >= "%s")) )', [ + AResourceID, + FormatDateTime('yyyymmdd', AStartDateTime), + FormatDateTime('yyyymmdd', AEndDateTime), + FormatDateTime('yyyymmdd', AStartDateTime) + ]) + else + ATable.Filter := Format('ResourceID = %d', [AResourceID]); + ATable.Filtered := true; +end; + +end. +