Tutorial: MSSQL- Windows Form Development
Multi-User Application With Custom Record Lockout #5
[Phase In Record Lock-Out System]

Dr. Thomas E. Hicks
Computer Science Department
Trinity University


Purpose

The purpose of this series of tutorials is to show how to configure a Windows Application Form, using Visual Studio, to process a multi-form, multi-user network application. This tutorial will briefly review many of the concepts demonstrated in some of the other tutorials.

Prerequisite Condition: each of our major database tables must have a unique, auto-incremented, integer field called ID.

This portion of the tutorial ????????????????????????????/


About Part 1 Of Tutorial

This tutorial is fourth in a series of Windows Form Development Multi-User Application With Custom Record Lockout #1 [Database Configuration, Database Authentication, Generic Database Utilities, Etc.]. The topics in part 1 are as follows:


About Part 2 Of Tutorial

This tutorial is fourth in a series of Windows Form Development Multi-User Application With Custom Record Lockout #2 [Query Set Views & Navigation Buttons & Filters & Order By]. The topics in part 2 are as follows:


About Part 3 Of Tutorial

This tutorial is fourth in a series of Windows Form Development Multi-User Application With Custom Record Lockout #3 [Login, RecoordLock DB, Authentication, Configure Dynamic Data Combo, Password Fields, CheckBoxes, & Tab Control]. The topics in part 3 are as follows:


About Part 4 Of Tutorial

This tutorial is fourth in a series of Windows Form Development Multi-User Application With Custom Record Lockout #4 [Edit Mode, Normal Mode, Record-Lock Database,  Record-Lockout Timing, Insert Lock Request, Complete Lock Request]. The topics in part 4 are as follows:


Sections In This Tutorial Part 5

Part V-A: Edit Mode & Normal Mode

Part V-B: Edit Mode & Normal Mode

Part V-C :Edit Mode & Normal Mode

Part V-D :Edit Mode & Normal Mode

Part V-E :Edit Mode & Normal Mode

Part V-F:  For You To Do


 If You Have Difficulty With This Tutorial,  You Might Find These Help Prepare You For This Tutorial
I Recommend That My Students Complete The Tutorials In This Order!

 

Tutorial: MSSQL TU Database-Construction Using Microsoft SQL Server

Tutorial: MSSQL-Forms - Windows Application & Basic Form Properties

Tutorial: MSSQL-Forms - Windows Application - Labels & Textboxes

Tutorial: MSSQL-Forms - Windows Application - Buttons

Tutorial: MSSQL-Connection\MSSQL-Connections

Tutorial: MSSQL-Forms - Windows Application - Menu - Multiple Forms

Tutorial: MSSQL-Visual Studio MenuStrip Application With Multiple Windows

MSSQL-Forms - Windows Application - Web Browser

MSSQL-Windows-Forms-ComboBox.html


Copy Project

1] Copy folder Library-Net-Multi-User-3 to folder Library-Net-Multi-User-4. I always recommend making a backup copy about ever hour or so.

 


Update TestingMaster In Users.cs

1]  Change the UserClassDiagnosticLevel to 12. (See Below!)

2] Open the User.cs form. Replace function TestingMaster with a pasted copy of the block of code below!

        //================================================================================//
        //                                  TestingMaster                                 //
        //================================================================================//
        //  Purpose: Testing Master which evokes TestModule1, TestModule2, ...            //
        //                                                                                //
        //  Written By : Dr. Thomas E. Hicks                    Environment : .NET 2005/8 //
        //        Date : xx/xx/xxxx                                Language : C#          //
        //================================================================================//
        public void TestingMaster()
        {
            int UserClassDiagnosticLevel = 36;

        }
2] Add function TestAll.
        //================================================================================//
        //                                  TestingAll                                    //
        //================================================================================//
        //  Purpose: Test all of the functions: TestModule11, TestModule12, ...           //
        //                                                                                //
        //  Written By : Dr. Thomas E. Hicks                    Environment : .NET 2005/8 //
        //        Date : xx/xx/xxxx                                Language : C#          //
        //================================================================================//
        public void TestAll()
        {
        }

Include Testing Code In Users.cs

1] Add the following Test function shells to Users.cs.

        //================================================================================//
        //                                  TestModule24                                  //
        //================================================================================//
        public void TestModule24()
        {
            MessageBox.Show("TestModule24");
        }


Part IV-B:
Record Lock Timing Support Functions

1] Many different librarians will have the ability to scroll through our User records with the Users.cs form above. Occasionally one of the librarians will want to make some changes to a given record. It is possible that two or more concurrent users will want to make changes to the same record at the same time. If we allow one user to lock the record - make changes - and then free the record, the potential to avoid concurrent user anomaly problems is optimized.

2] Problem 1: Many databases have the ability to lock a database table, but few have the ability to lock a table record. Locking the entire database greatly limits the functionality of other users!

3] Problem 2: Even the very few databases which offer the ability to lock a record, have no mechanism to determine who has locked the record.

4] Problem 3: Few of the databases have the utilities necessary to easily do timing calculations; we generally have to write some of our own functions.

5] Problem 4: Most computers do not have their clocks synchronized; users may be in different time zones. It is critical that all timings be relative to the SQL Server, as opposed to the user's personal computer.

6] The Record Lock-Out strategy demonstrated in this tutorial can be used in both web-oriented databases and multi-user network databases.  The logic can be applied to databases, MySQL, DBase, and other database engines.
 


Functions ComputeNoDays &  ComputeNoSeconds

1] Now to functionalize this. Change the UserClassDiagnosticLevel to 26. (See Below!)

2] Write function ComputeNoDays which accepts a DateTime Object and explicitly returns the number of days that have passed since Dec. 31st, 1999; thus starting our system timing with the year y2k.

3] Write function ComputeNoSeconds which accepts a DateTime Object and explicitly returns the number of seconds that have passed thus far on the last day.

4]   Copy the code from TestModule25 to TestModule26 and make the following changes.

5] Execute the Users Test Module. Examine the test module carefully to make sure that you understand what it is attempting to do. Examine the output carefully to make sure that it matches that below and is consistent with the test code above.

6] The first block of code (1/1/2000) is 1 Second into Day 1 into y2k.

7] The second block of code  (1/1/2001) is one minute two seconds [60+2] into  is Day 367 [366+1] into y2k.

8] The third block of code  (1/3/2002) is one hour [60x60 seconds] into  is Day 734 [366 + 365 +3] into y2k

9] Suppose a user were to lock a record [on 1/1/2001 12:01:02] for 120 seconds. The two functions above enable us to get CurrentNoDays = 367 and CurrentNoSeconds = 62. The two functions above enable us to  calculate LockExpireDay = 367 and LockExpireSecond = 182; when another user attempts to lock this same record, we shall use these functions, with the current date, to see if a record lock has expired. We shall discuss this later.


Part IV-F:
For You To Do

1] There is not much opportunity for you to put really see the value of these utilities until we complete Part 5 of this tutorial.


Add & Modify Code

1] Gradually phase in the following items from Users.cs to Books.cs. I included my test code (and made modifications to make it work), but this is optional. Make sure that the Books.cs includes the following: