Set up workstation and server clock synchronization in C/S system

Source: Internet
Author: User
Tags local time microsoft sql server odbc connection sybase sybase database win32

Summary

In practice, it is often required that the clocks of each workstation in the client/server architecture be synchronized with the server clock; This paper illustrates a solution based on Sybase database and PowerBuilder development tool.

First, the preface

PowerBuilder through the Data window object, the database can be operated conveniently and directly, so it has become the first Choice development tool for developing Client/server mode application. In the development of hospital information Management system, we used PowerBuilder as the foreground development tool, Sybase as the background database.

In hospital information management system, there are many modules require workstation time and server to keep in sync, such as: outpatient fee system requires to be able to evenly to the Siyao window distribution prescriptions, hospital pharmacies to be placed according to the ward to send orders in time order. To solve this problem, we have written a corresponding program, the main idea is: the use of dynamic cursors to obtain server time, WIN32 API functions to set the local time, the specific implementation of the following methods:

Second, the realization method:

1, connect the database

PowerBuilder supports a variety of database management systems (DBMS), such as Sybase, Oracle, Informix, Microsoft SQL Server, and so on, depending on the type of database, using a private interface or ODBC connection database. Establish the interface configuration file (DB profile).

2. Create Application object, write script in Application object event

The script for the 1>, Application object Open event is as follows:

startupfile = "settime.ini"
sqlca.DBMS= ProfileString (startupfile, "database", "dbms", "")
sqlca.database=ProfileString(startupfile,"database","database","")
sqlca.userid=ProfileString(startupfile,"database","userid","")
sqlca.dbpass=ProfileString(startupfile,"database","dbpass", "")
sqlca.logid=ProfileString(startupfile, "database", "logid","")
sqlca.logpass=ProfileString (startupfile, "database","LogPassWord", "")
sqlca.servername=ProfileString(startupfile,"database",ervername","")
sqlca.dbparm= ProfileString (startupfile, "database", "dbparm", "")
connect;
f_setlocaltime() //调用自定义函数完成设置本地工作站时间

The script in the 2>, Application object Close event is as follows:

DISCONNECT Using SQLCA;

3, the definition of WIN32 API functions for external functions

In the Script Brush workspace, select Declare > Global External functions ..., which defines the WIN32 API function as an external function, defined as follows:

FUNCTION LONG setlocaltime (ref systemtime systimeptr) LIBRARY "Kernel32.dll"

4. Define the structure of access time parameters

Click the Structure Painter button in Painterbar or Powerpanel to define a structure named: SYSTEMTIME, the variables that compose the structure and the corresponding data types are as follows:

integer wyear
integer wmonth
integer wdayofweek
integer wday
integer whour
integer wminute
integer wsecond
integer wmillisecond

5, create user-defined functions to complete the setup workstation time this article is from http://bianceng.cn (Introduction to programming)

Create a custom function named F_settime with the following script:

systemtime s_systime //声明前面已定义结构类型的变量
datetime nettime
declare cur_time dynamic cursor for sqlsa; //声明动态游标
prepare sqlsa from "select getdate()";
open dynamic cur_time ;
fetch cur_time into :nettime; //通过数据库获取服务器时间
close cur_time;
s_systime.wmonth=month(date(nettime))
s_systime.wday=day(date(nettime))
s_systime.wyear=year(date(nettime))
s_systime.whour=hour(time(nettime))
s_systime.wminute=minute(time(nettime))
s_systime.wsecond=second(time(nettime))
s_systime.wmillisecond=30
SetLocalTime(s_systime) //调用WIN32 API函数,设置工作站时间。

6. Create an executable application

Click the Project button in PowerBar or Powerpanel to open project painter. Select Project dialog box appears, click New to create a new project object, enter the executable program name (such as: Settime.exe), click OK. Then click Build to create the executable file.

7. To install the executable program to each workstation

The generated executable program (such as: Settime.exe) is placed into the Windows Startup menu of each workstation, and the workstation automatically corrects the native time per server time each time Windows is started.

Third, concluding remarks

The above method is to create a stand-alone executable file to achieve the workstation and server time synchronization, programming, you can also in the application of the Open event or program login corresponding event call the above F_settime function, to achieve workstation time and server synchronization. This method has been applied in the development of hospital information management system and achieved good results.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.