PC SOFT

ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Home | Sign in | English EN
New WINDEV 26 feature!
  • In this lesson you will learn the following concepts
  • Overview
  • Creating the project
  • Creating the analysis
  • Creating the description of data files
  • Creating a data file: using a preset data file
  • Creating a data file: creating the data file and items
  • Importing a CSV file
  • Direct import of existing data files
  • Creating links
  • Generating the analysis
Lesson 3.2. Project and analysis
In this lesson you will learn the following concepts
  • Creating a project.
  • Creating an analysis.
Lesson duration

Estimated time: 40 mn
Previous LessonTable of contentsNext Lesson
Overview
To create an application with a database, you must:
  • Create the project linked to the application. This project will group all application elements (windows, codes, queries, reports, etc.).
  • Create the analysis linked to the project. The analysis is used to describe all data files handled by the application.

Note

This lesson will show you how to create an application with an HFSQL database. As already seen in the previous lesson, WINDEV allows you to create applications that handle other databases.
The "Appendix 2. Using data from an external database" lesson presents the operations that must be performed to create a project and an analysis based on an SQL database (via OLE DB or via Native Connectors).
Creating the project
We will first create a project. We briefly explained how to create a project in the WLanguage lesson. In this lesson, we will see how to create a project in detail.

  • To create the project:
    1. Start WINDEV.
    2. Go to the WINDEV home page (Ctrl + <).
    3. On the home page, click "Create a project" and select "Windows or Linux application". The project creation wizard starts. The different steps of the wizard will help you create your project. The information specified in this wizard can be modified later.

      Tip

      To create a project, you can also:
      1. Click Create an element in the quick access buttons.
      2. The element creation window appears: click "Project".
    4. The first step of the wizard allows you to select the operating system for which the project is intended. Select "Windows platform" and go to the next step of the wizard ("Next").
    5. For this lesson, we are going to create a "blank" project. You can also create a project based on an existing example, provided with WINDEV. Select "Create a blank project" and go to the next step of the wizard.
    6. WINDEV then prompts you to enter the platform description. Keep the default options ("32-bit Windows executable" and "Executable with windows"). Go to the next step of the wizard.
    7. The wizard prompts you to enter the project name, location and description. In our case, name the project "WD My First Database".
    8. WINDEV proposes to create this project in the "\My projects\WD My First Database" directory. You can keep this location or modify it via the [...] button. For the project summary, type "The purpose of project is to manage customers and their orders".
      Project creation wizard
    9. The different steps of the wizard are specified on the left. These steps can be clicked directly. Since the other steps in the "Description" are not strictly necessary, you can click "Guidelines" directly.
    10. This step is used to define the code style. Don't modify the suggested options. Go to the next step.
    11. This step is used to define the style book. Select "Phoenix".
      Project creation wizard - Style book
      Go to the next step.
    12. Click the "Database" step. We are now going to specify the information regarding the database.
    13. Select "Yes, create a new database" and validate. The analysis creation wizard starts.

Note

To better understand the different lessons of this part and optimize your training, we advise you to create the "WD My First Database" project.
A corrected example is available at any time to check the validity of the operations performed.
To open the corrected project, go to the WINDEV home page (Ctrl + <), click "Tutorial" and select "My first database (Answers)".
Creating the analysis
  • The steps of the analysis creation wizard are as follows:
    1. Specify the analysis name and directory. By default, the analysis name corresponds to the project name and the analysis directory is a ".ana" directory in the project directory. We will keep these default parameters.
      Analysis creation wizard
      Go to the next step of the wizard.
    2. Next, you can choose the types of databases used by the project. Select "HFSQL Classic" (WINDEV's default database).
      Analysis creation wizard - Selecting the database
      Go to the next step of the wizard.
    3. Validate. The data file creation wizard starts automatically.
Creating the description of data files
Our customer and order management application will be associated with the following analysis. This analysis includes five different data files (tables):
  • Customer,
  • Order,
  • PaymentMode,
  • OrderLine,
  • Product.
Data model editor - Lesson analysis
To create the data files of this analysis, we will use different methods available in WINDEV.

Creating a data file: using a preset data file

  • The steps of the data file creation wizard are:
    1. In the wizard, select "Select a description among the preset data files".
      Preset data file creation wizard
      Go to the next step of the wizard.
    2. The list of preset data files is displayed. We are going to create the "Customer" data file. In the list of data files, select "Customer". Go to the next step.
    3. The wizard proposes the list of items that will be included in Customer data file. This list is very impressive because it allows you to manage several types of Customer data files.
      Data file creation wizard - Items to include
    4. Check the following items: CustomerID, Company, LastName, FirstName, Address, ZipCode, City, StateDep, Country, Phone, Cell, Email.
    5. Validate the wizard.
    6. The "Customer" data file is automatically created in the data model editor.
      Customer data file in the editor
    7. The element creation window appears. We are now going to create the data file containing the orders.

Creating a data file: creating the data file and items

  • To create a data file from the element creation window:
    1. Click "Data" then "Data file".

      Note

      You can also create a data file from the data model editor: in the ribbon, on the "Analysis" pane, in the "Creation" group, click "New file".
    2. The data file creation wizard starts.
    3. In the wizard, select "Create a new data file description".
      Data file creation wizard
    4. Go to the next step of the wizard.
    5. We are going to create the "Order" data file. Name the data file "Order" in the wizard. This name will be used:
      • to manipulate the data file in the code. The variable associated with the data file will be "Order".
      • to build the name of the associated physical data file ("Order.fic" file). The caption and description of the elements represented by the records in the data file appear automatically.

        Note

        In the wizard, the control "A record represents" is used to get an understandable caption during the description of links between data files. A caption is automatically created from the data file name.
        In our case, type "An order".
        Data file creation wizard - General settings
    6. In the "Automatic identifier" section, keep "8-byte automatic identifier". If an automatic identifier is defined on the data file, it means that the data file includes a unique key, automatically managed by WINDEV.

      Note

      To create the identifier (an identifier is a unique key), you can create an item of type "Automatic ID".
      This identifier is automatically managed by WINDEV. Whenever a record is added to the data file, WINDEV automatically assigns a value to the data file identifier. This value is unique.
    7. Go to the next step and select the type of database associated with the data file. We are going to work on HFSQL Classic data files. Go to the next step.
    8. Click "Finish" to validate. The data file is automatically created in the analysis. The description window of the items and indexes appears.
      Data file description
We are going to create the items of the "Order" data file. In the data file description window, you will notice that an item was automatically created: "OrderID". This item corresponds to the automatic file identifier. This item consists of the letters "ID" and the name of the data file.
We are going to create the other items of this data file.
  • First, we are going to create the "Date" item. This item will contain the order date.
    1. In the item description window, double-click in the "Name" column of the first empty row. This column automatically becomes editable. Type "Date".
    2. Click the "Caption" column. The item name is automatically displayed. We are going to modify the item caption by clicking on it: type "Order date". In the "Type" column, the "Text" type is automatically selected. Expand the list and select the "Date" type.
      Description of items
    3. This item will be a key item (index) in our data file: keys are used access and sort data faster.
      • In the case of an SQL database, the engine makes the best use of indexes.
      • For a sequential search in a data file, simply specify the search index (i.e., the key).

        Note

        The concept of key is part of the item characteristics. When creating an item, you have the ability to specify whether it is:
        • not key,
        • unique key: the value of this key will be unique in the entire data file (i.e. in all the data file records).
        • key with duplicates: the value of this key can be multiple times in the data file.
    4. The key can be defined as follows: re-select the row of the "Date" item to activate the description controls on the right-hand side of the window. Then, simply specify the type of key used. In our case, the date is a key with duplicates.
      Description of items
    5. You must also define the search direction of the key. The search direction is used to define the default sort for this item. In our case, when a browse is performed on this key, the default sort order will be "ascending".
  • We are now going to create the "Status" item that is used to find out the order status.
    1. Position the cursor on a new table row. Enter:
      • the name: Status
      • the caption: Status
      • the type: Radio Button, List Box, Combo Box. In the window that appears, you can select the type of control created by default for this item. It will be a radio button in this case. Validate the window.
    2. In the lower section of the screen, click the link to display the parameters of the control bound to the selected item.
      Control parameters
      The information typed in the new window that is displayed will be automatically used when creating windows linked to the data file. You will find here the control type and the caption.
      We are going to type the following options in the "Content" tab:
      • Click the "Content" tab.
      • Click the "+" button to add the first option.
      • The option 1 corresponds to Pending. Type "Pending" in the first Edit control.
      • Click the "+" button to add the second option.
      • Type "Validated" instead of "Option 2".
      • Click the "+" button again.
      • Type "Canceled" instead of "Option 3".
        Control parameters
    3. Validate the description window of the control linked to the item.
    4. Similarly:
      • Move the cursor to a new table row and create the "TotalBT" item. Select the "Currency" type for this item.
      • Move the cursor to a new table row and create the "TotalIOT" item. Select the "Currency" type for this item.
    5. That's it, the description of the "Order" data file is complete. Validate the description window of items.
    6. The "Order" data file appears in the data model editor. It is possible to enlarge the displayed data file. Simply click the data file, select the black handle at the bottom of the data file and move the mouse down.
      Data files in the editor

Importing a CSV file

A different method will be used to create the "PaymentMode" data file, which contains the payment characteristics: importing a CSV file.

Note

A CSV file is a text file that uses a specific format. This file contains data on each line. Data is separated by a delimiter character (a comma, semicolon or tab).
From the CSV file containing the data, WINDEV will create:
  • the description of the data file in the analysis,
  • the HFSQL data file with the data in the CSV file.
  • To import a CSV file into the analysis:
    1. In the ribbon, on the "Analysis" tab, in the "Creation" group, expand "Import" and select "Import file/table descriptions...".

      Tip

      To import a CSV file (or any other file) into the analysis, you can also drag the CSV file from Windows explorer and drop it onto the data model editor. This will be presented in the next paragraph.
    2. The file import wizard starts.
    3. Go to the next step.
    4. Select the format of the files to import. In this case, select "Text file".
      Data file import wizard
      Go to the next step of the wizard.
    5. Specify the path of the file to import: "\Tutorial\WD\Exercises\WD My First Database\PaymentMode.csv" in the WINDEV setup directory.
    6. Go to the next step of the wizard.
    7. Specify the following import options:
      • The records are delimited by: "<Carriage Return/Line Feed>".
      • The columns are delimited by: "<Semicolon>".
      • The strings are delimited by: "<None>".
      • Decimal separator: "<Automatic: dot or comma>"
        Text file import options
    8. Don't forget to check "The first row contains the names of the columns".
    9. Go to the next step.
    10. The structure of the data file that will be created is displayed.
      Import options
      Keep the default options. Go to the next step of the wizard.
    11. The content of the CSV file will be automatically converted to HFSQL. The wizard proposes to create the HFSQL file in the project directory.
      Create HFSQL files
      Keep the default options and go to the next step.
    12. Validate the wizard. WINDEV creates the data file.
  • Let's examine the description of the imported data file:
    1. Select the "PaymentMode" data file.
    2. Right-click to open the context menu and select "Data file description".
    3. Change the data file caption in the window that appears: delete "(Imported)".
    4. Click Description of items to open the description of the data file items.
    5. This data file contains no automatic identifier and no unique key. We are going to switch the "Code" item to unique key:
      • Select the code item if necessary.
      • On the right side of the screen, click "Unique key".
        Key management
    6. We get the following data:
      Description of items (PaymentMode data file)
    7. Validate the item and data file description windows.

Direct import of existing data files

The last method for creating data files consists in importing the existing HFSQL data files. This method will be used to create the "Product" data file.

  • To import HFSQL data files:
    1. In the Windows file explorer, open the following WINDEV subdirectory: "\Tutorial\WD\Exercises\WD My First Database".
    2. Select the "Product.fic" file.
    3. Drag the file "Product.fic" and drop it onto the WINDEV data model editor.
    4. The import wizard starts. Validate the different steps. The data file appears in the data model editor.
All necessary data files are now in the data model editor.

Caution!

Only the description of the "Product" data file was imported into the analysis of our project. The data from the "Product" data file has not been imported into the project yet.
  • To manipulate the data from the file that has been just imported:
    1. Open the file explorer on the directory of your project: on the "Home" tab, in the "General" group, click Browse project directory.
      Home tab
    2. Open a new file explorer on the "\Tutorial\WD\Exercises\WD My First Database" directory.
    3. Copy the "Product.fic", "Product.mmo" and "Product.ndx" files from "\Tutorial\WD\Exercises\WD My First Database" to the EXE subdirectory of your project directory.
      Remark: Three files must be copied:
      • "Product.fic": file containing the data,
      • "Product.mmo": memo file containing the product images,
      • "Product.ndx": file containing the indexes to optimize the searches performed in the data file.
Creating links
All data file descriptions required by the account management application have been created.
Data files in the data model editor
Now we will create the links between the data files. A link is used to define the integrity constraints (cardinalities) between two data files.
  • First, let's create the link between the "Customer" and "Order" data files: a customer can have one or more orders and each order is linked to a customer.
    1. On the "Analysis" tab, in the "Creation" group, click "New link". The mouse cursor turns into a pen.
    2. Click the "Customer" data file, then the "Order" data file.
    3. The link creation wizard starts.
    4. Answer the questions asked by the wizard:
      Link creation wizard
      • Each Customer has at least one Order: No
      • Each Customer can have several Orders: Yes
      • Each Order has at least one Customer: Yes
      • Each Order can have several Customers: No

        Note

        You can also specify the link cardinalities directly in the wizard.
        Modifying cardinalities
    5. Go to the next step. The wizard automatically proposes the key used by the link (CustomerID).
      Link creation wizard
    6. Go to the next step of the wizard. The wizard proposes to create the "CustomerID" key in the Order data file to store the customer corresponding to the order.
      Link creation wizard
    7. Accept this option by going to the next step.
    8. This step defines the integrity rules that will be automatically applied. In our case, you can set the behavior when deleting a customer and when modifying the customer identifier.
    9. Validate the integrity rules by going to the next step of the wizard.
    10. Click "Finish". The link is automatically created in the data model editor.
  • Likewise, create a link between the PaymentMode and Order data files. These two data files are linked as follows:
    • An order must have a payment mode.
    • A payment mode can be used in several orders.
    In the wizard:
    • The cardinalities are as follows: PaymentMode (0,n), Order (1,1)
    • The link key corresponds to the "Code" item.
  • Now we will create a link between the "Product" and "Order" data files. This link will be used to create a link file, the file of order lines.
    1. Likewise, create the link between the data files.
    2. Answer the questions asked by the wizard:
      • Each Product has at least one Order: No
      • Each Product can have several Orders: Yes
      • Each Order has at least one Product: No
      • Each Order can have several Products: Yes
        Link creation wizard
    3. Go to the next step. The wizard proposes to create a relation file. Keep "Create the relation file automatically" and go to the next step.
    4. The wizard proposes the unique key of the Product data file. Select "Reference". Go to the next step.
    5. Validate the key creation by going to the next step.
    6. Keep the default options regarding the integrity rules and go to the next step.
    7. The wizard proposes the unique key of the Order data file to use: "OrderID". Go to the next step.
    8. Validate the key creation by going to the next step.
    9. Keep the default options regarding the integrity rules and go to the next step.
    10. Click "Finish". The relation file is automatically created in the data model editor.
      Data model editor
  • We will modify the relation file created by WINDEV. This relation file will contain the order lines. We are going to:
    • Modify the name of the data file.
    • Modify the name of its items.
    • Add items to find out the quantity of products ordered and the total of the order line.
  • First, we are going to rename the data file. We already did something similar when we changed the caption of the imported data file. However, in this case, not only the caption will be modified: we will also rename the physical file linked to the data file description.
    1. Select the "Product_Order" data file.
    2. Right-click to open the context menu and select "Data file description".
    3. In the window that appears, change:
      • the name of the data file to "OrderLine".
      • the name on the disk to "OrderLine".
        Description of data files
  • We are now going to modify the items of this relation file.
    1. Click Description of items to open the description of the data file items.
      Description of items
    2. This relation file has 3 items. Select the "Reference_OrderID" item. This item is a composite key.

      Note

      A composite key is a set of items that constitute an index.
      This type of key is used to browse the data file according to complex criteria or to perform specific searches on several items at the same time.
    3. To rename this item:
      • Click the "Name" column.
      • Replace "Reference_OrderID" by "OrderLineID".
      • Click the "Caption" column.
      • Replace the current caption with "Identifier of OrderLine".
  • Now we are now going to add 3 new items to this relation file: Quantity, TotalIOT and TotalBT.
    1. Move the cursor to a new row and create the "Quantity" item. Select the "Numeric" type for this item.
    2. Move the cursor to a new row and create the "TotalIOT" item. Select the "Currency" type for this item.
    3. A window indicates that the item already exists in the analysis and offers you to reuse its characteristics:
      Creating an item
      Keep the selected options and validate ("OK").
    4. Move the cursor to a new row and create the "TotalBT" item. Select the "Currency" type for this item. Once again, use the existing description.
    5. The description of the "OrderLine" data file items is as follows.
      Description of items
    6. Validate the item description and the data file description (click "OK").
  • The analysis is as follows:
    Data model editor
Generating the analysis
Generating the analysis consists in validating changes made to the analysis (new data files, add or delete items, etc.) and in applying them to the entire project (pages, bound controls, reports, etc.). The project will thus "know" all the data files, items and links defined in the analysis. It will be very easy to handle these elements in the different editors of WINDEV.
If changes have been made to the analysis, a synchronization dialog box appears automatically when the data model editor is closed.
You also have the ability to generate the analysis manually. That's what we are going to do.
  • To generate the analysis:
    1. In the ribbon of the data model editor, on the "Analysis" tab, in the "Analysis" group, click "Generation".
    2. The analysis generation is automatically started.
The descriptions of the analysis data files have been modified.
To update the data files of the application, WINDEV automatically starts the procedure for modifying the data files. This operation is used to update the data files (".fic" files) according to their description in the analysis.
  • The automatic modification wizard starts. Validate the different steps until you reach the screen that lists the data files to take into account.
    • WINDEV detects that the PaymentMode data file must be updated. Keep this data file selected.
    • WINDEV detects that the Product data file is out of sync. Select this data file.
      Automatic data modification
    • Go to the next step.
    • The wizard proposes to make a back up copy of the existing data files, don't change anything and go to the next step.
    • The wizard proposes to type the passwords for protecting the data files modified by the automatic modification. Keep the default options and go to the next step.
    • The list of data files to modify is displayed. Validate the wizard.
    • The data files are updated.
  • Close the data model editor.
We have covered the main steps to create an analysis.
Once your analysis has been defined and generated, you can:
  • Create a full application via the RAD (Rapid Application Development).
  • Create a full custom application. This method will be used to develop a full application based on a database in part 4 of this tutorial. This application will be based on an analysis corresponding to the one that was created in this part.
Previous LessonTable of contentsNext Lesson
Minimum version required
  • Version 26
Comments
Click [Add] to post a comment