Rapid Agile Development for Prototyping and Rapid Application Development

Navigation: <Root level>

Worked Example

 

 

 

 

Worked Example with kissOrders Demo Database

 

The kissOrders Demo Database creation SQL Scripts (MS SQL Server & MySQL) are available to download from https://www.rapidagiledevelopment.com/free-trial-downloads/

 

To illustrate Table & File Manifests an example of manually (without the Wizard) creating:

 

1.Data Access Layer (DAL) (Data Access Objects (DAO))

2.Business Logic Layer (BLL) (Business Layer Objects (BLO))

3.Value Objects (VO also known as Data Transfer Objects, DTO or Plain Old CLR Objects, POCO)

4.SQL CRUD Stored Procedures

 

for the Customer Table in the kissOrders demo database (download from https://www.rapidagiledevelopment.com/free-trial-downloads/ will be presented next.

 

Create a kissOrders DataModel Database from the SQL Scripts supplied in the demo zip. Additionally create an empty (no tables etc) kissOrdersTest and optionally an empty kissOrdersDeploy.

 

Add DataSources for all the kissOrders databases created.

 

Add a new Solution and set DataSources for Data Model, Test Database and optionally, the Deployment Database:

 

 

Set  Paths to the relevant Visual Studio Projects (create the Projects in Visual Studio and copy the paths) that kiss!® will generate SQL and Code for:

 

 

 

If generating Web Services add the location of the Web Services including the folder the Web Services are in. The Namespaces will be added once the C.R.U.D. Template Wizard has been run for the first time:

 

 

After adding a Solution called kissOrders and setting up a Data Source to the kissOrders database (this time on SQL Server 2014 but MySQL5.6 is also supported), select the Solution in the tree view and click Synchronise Data Model:

 

 

 

Once Synchronisation is complete, click Add | Project from the context menu:

 

 

Add 2 Projects, one called Code (Type = Code) & one called SQL (Type = SQL):

 

 

If version numbers need to be maintained on a Project by Project basis, uncheck "Cascade Version Numbers" in the Solution dialog which will enable  in the Project dialog:

 

 

There should now be 2 Projects shown in the main form:

 

 

 

SQL Script Generation

 

 

Select the SQL Project and add a Table Manifest setting Auto incrementing Version Numbers on the Manifests, if required, by clicking:

 

 

 

SQL CRUD Table Manifest

 

All System level Templates and Placeholders are added the first time kiss!® is used. If no modifications are required simply select the appropriate Template for the Table Manifest.

 

 

Templates can be modified in the Template Editor by entering text or selecting from the Placeholder context menu. Key Words can be highlighted in the Template Editor by clicking “Format Text” but unfortunately no validation on the SQL or Code is performed. User Defined Templates can be written in either C#, VB.NET or SQL using the relevant Placeholders where appropriate.

 

The Template Editor Context Menu for SQL Templates:

 

 

Add a Table Manifest to the SQL Project. In this example just the Customer table is selected but any & all Tables can be selected provided they meet the Naming Requirements for Code Generation as set out in . In this example “Must have IDENTITY” is checked as there is an IDENTITY column. With “Create File Manifest” checked a File Manifest will be created automatically.

 

 

 

Select the required Template in the Table Manifest:

 

 

 

Set the Manifest Template combo box selections as shown. Manifest Template determines which Template will be applied to the selected Tables while File Manifest is the Target Manifest for Generated Output. Click “OK” to save.

 

To test the Generated SQL, select the SQL Project and click Generate  in the tree view:

 

 

There will now be a Generated SQL Script in the SQL CRUD File Manifest:

 

 

This SQL Script can now be executed to test. Repeat these steps if necessary for other supplied Templates or User Defined Templates. Insert, Select, Update & Delete SQL Scripts are available as separate Templates if required.

 

 

Manually added SQL Scripts can be viewed, edited & executed in the SQL Tool! or other SQL editor. Modifying Generated SQL Scripts is not recommended:

 

 

 

The File Manifest set in the Table Manifest receives the Generated Output:

 

 

 

Code Generation

To Generate the DAL & BLL for the SQL already generated select the Code Project first add 3 File Manifests to the Code Project. In this example the DAL & BLL will be in C# set by later selecting the *.cs file extension and a C# Code Template in the Table Manifest. VB.NET could optionally be generated by selecting VB.NET Templates and *.vb file extension.

 

There are Templates to generate either Value Object (VO) results or Dataset results.

 

Add seven Table Manifests (use the default names) to the Code Project, one each for the DAL & BLL, VOs, DOs, DOMs,Web Services & Enums. The WebServiceConfig_Exports Project will be added automatically the first time the Solution is generated:

 

 

All steps can be taken using VB.NET Templates and MySQL if required.

 

Select the Solution (kissOrders), right click and select “Generate”:

 

 

Clicking “Generate” at the Solution Level generates & concatenates all Manifests as appropriate. There will now be a Generated DAL & BLL to be used in conjunction with the SQL CRUD Scripts generated earlier:

 

 

 

Using the Generated Code

 

In Visual Studio add DAL, BLL, VO, DO, DOM, Enum and Web Service Class Library projects to a Windows Form Solution and set the references as required.

 

Application and Class Library Projects in Visual Studio:

 

 

References to Class Libraries from Application:

 

 

 

Add Custom & Generated folders to the Visual Studio projects as shown and set the Code Table Manifest’s Output Directory in kiss!® to match the folders in Visual Studio (the Custom & Generated directories are added to the Output Directory by kiss!®). The kissOrders.Customer Table is used as an example:

 

 

 

Regenerate the kissOrders Solution in kiss!® and add the Custom & Generated Files to the relevant Class Library projects in Visual Studio.

 

After adding the relevant references to your application the BLL can be called as follows:

 

Object Declarations:

 

        private CustomerMSSQLBLO _CustomerMSSQLBLO = new CustomerMSSQLBLO();
        private CustomerWS.CustomerWSSoapClient _CustomerWSSoapClient = new CustomerWS.CustomerWSSoapClient();
        private CustomerWCF.iCustomerWCFClient _iCustomerWCFClient = new CustomerWCF.iCustomerWCFClient();
        private List<kissOrders.SQLServer2014.ValueObjects.CustomerVO> _CustomerVOs = null;
        private List<CustomerWS.CustomerVO> _CustomerWSVOs = null;       
        private KissOrders _KissOrders = new KissOrders("Integrated Security=SSPI;Persist Security Info=False;User ID=;Initial Catalog=kissOrdersTest;Data Source=CBS1\\SQLSERVER2012");

 

 

Insert Declaration:

 

        private void InsertRecord()
        {
            try
            {
                switch (ConfigurationObject.Instance().Transport)
                {
                    case Transport.tranClientServer:
                        _CustomerMSSQLBLO.Insert( txtName.Text, txtSurname.Text, dtpDOB.Value, string.Empty);
                        break;
                    case Transport.tranWCFServices:
                        _iCustomerWCFClient.Insert(txtName.Text, txtSurname.Text, dtpDOB.Value, string.Empty);
                        break;
                    case Transport.tranWebServices:
                        _CustomerWSSoapClient.Insert(txtName.Text, txtSurname.Text, dtpDOB.Value, string.Empty);
                        break;
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

 

          

SelectAll Declaration:

 

        private void SelectAll()
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;

                switch (ConfigurationObject.Instance().Transport)
                {
                    case Transport.tranClientServer:
                        _CustomerVOs = _CustomerMSSQLBLO.SelectAllOrderByPrimaryKey();
                        dgvCustomers.DataSource = _CustomerVOs;
                        break;
                    case Transport.tranWCFServices:
                        _CustomerVOs = _iCustomerWCFClient.SelectAllOrderByPrimaryKey().ToList();
                        dgvCustomers.DataSource = _CustomerVOs;
                        break;
                    case Transport.tranWebServices:
                        _CustomerWSVOs = _CustomerWSSoapClient.SelectAllOrderByPrimaryKey().ToList();
                        dgvCustomers.DataSource = _CustomerWSVOs;
                        break;
                }

                Cursor.Current = Cursors.Default;
            }
            catch (System.Exception ex)
            {
                Cursor.Current = Cursors.Default;
                MessageBox.Show(ex.Message);
            }
        }

 

 

Update Declaration:

 

        private void UpdateRecord()
        {
            try
            {
                switch (ConfigurationObject.Instance().Transport)
                {
                    case Transport.tranClientServer:
                        _CustomerMSSQLBLO.Save(_CustomerID, txtName.Text, txtSurname.Text, dtpDOB.Value, string.Empty);
                        break;
                    case Transport.tranWCFServices:
                        _iCustomerWCFClient.Update(_CustomerID, txtName.Text, txtSurname.Text, dtpDOB.Value, string.Empty);
                        break;
                    case Transport.tranWebServices:
                        _CustomerWSSoapClient.Update(_CustomerID, txtName.Text, txtSurname.Text, dtpDOB.Value, string.Empty);
                        break;
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

 

 

Save Declaration (Instead of Insert & Update):

 

        private void Save()
        {
            try
            {
                if (_CustomerVO == null)
                {
                    _CustomerVO = new CustomerVO();
                }

                _CustomerVO.Name = txtName.Text;
                _CustomerVO.Surname = txtSurname.Text;
                _CustomerVO.DoB = dtpDOB.Value;

                switch (ConfigurationObject.Instance().Transport)
                {
                    case Transport.tranClientServer:
                        _CustomerDO.Save(_CustomerVO);
                        break;
                    case Transport.tranWCFServices:
                        _iCustomerWCFClient.Save(_CustomerID, txtName.Text, txtSurname.Text, dtpDOB.Value, string.Empty);
                        break;
                    case Transport.tranWebServices:
                        _CustomerWSSoapClient.Save(_CustomerID, txtName.Text, txtSurname.Text, dtpDOB.Value, string.Empty);
                        break;
                    case Transport.tranLinqSQL:
                        _Customer = new Customer();

                        _Customer.Name = txtName.Text;
                        _Customer.Surname = txtSurname.Text;
                        _Customer.DoB = dtpDOB.Value;

                        _KissOrders.Customer.InsertOnSubmit(_Customer);
                        _KissOrders.SubmitChanges();
                        break;
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

 

 

Delete Declaration:
 

        private void DeleteRecord()
        {
            try
            {
                switch (ConfigurationObject.Instance().Transport)
                {
                    case Transport.tranClientServer:
                        _CustomerMSSQLBLO.Delete(_CustomerID);
                        break;
                    case Transport.tranWCFServices:
                        _iCustomerWCFClient.Delete(_CustomerID);
                        break;
                    case Transport.tranWebServices:
                        _CustomerWSSoapClient.Delete(_CustomerID);
                        break;
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

www.rapidagiledevelopment.com by Cove Bay Software Limited Copyright © 2015