Web Application Opener - WebSnap (12)

zhaozj2021-02-08  197

Web Application Opener - WebSnap!

Chapter 10, DateTime Bar Demolition and Lookupfield, Postback Technique

In the write database program, we often need to use the Lookup Field, for example, when the user selects a certain customer, bring out the company's company name, which is not difficult in the general Windows program, but now we are body In Web Application, problems and techniques that need to be considered are different because the WEB's way of operation is different. The first is the way to display the lookup ComboBox, which is the industry commonly known as window action. We can use two in Web Application. The way achieves the same effect, one is to display the content directly in ComboBox (Select), the other is to open a new browsing window, both have some advantages and disadvantages, directly displaying the content in comboBox, we must face a choice It is to download all the information to the Client side, then processed by HTML Script mode, or wait for the user to re-read once, let the web page re-read once, with this chance, we will fill the LOOKUP data In the HTML, this is Postback technology, the first way must be determined by the amount of data, if the amount of data is too large, this treatment is very time, the advantage is that once the transfer is completed, the user can use faster Speed ​​picking information, postback is only the necessary information, such as the customer number, to choose a customer number Postback to WebServer, then we can get the customer number selected by the user, and then get the LOOKUP information, and finally Reallocate the information and the web page The disadvantage of this way is that you must handle this action because of the current WebSnap does not understand the support of Postback, the advantage is that your information has been protected, but the user can see it. At the same time, it is more efficient than the previous method, here I use Postback technology, which is more actual for you.

In addition to the lookup of Lookup, we have another problem, that is, the problem is input, in fact, this problem is not very important, because you only need to prompt the input example, let the user know the correct date you need for your web page and Time format, but the technique that disassembles a date to three fields is entered, but you can open the window you use WebSnap, so I will discuss this technology with you. 12-1 change three, DateTime column demolition

Before starting the writing, let me think about it, how can I remove a DateTime's Adapterfield to three columns? First we have to build three virtual AdapterField to store the year, month, day three values ​​after the disassembly, and then replace the original DateTime field is displayed on the webpage, and when the user has built these three fields, We must save these three fields to the original Adapterfield, or save them back to the database. In the above process, we have a few critical must be resolved first, we will originally in that event. DateTime data, and store these three virtual Adapterfield? In that event, save these values ​​back to the database? The first question believes that you have a little spectrum, that is, the OnGetValue event, we can be in virtual On the ONGETVALUE event in the field, the value is removed, and it is sent back to WebSnap on the webpage. Let's solve this problem first. The first step is of course adding these three virtual AdapterField to dsaorders. DataSetAdapter:

After writing their online ONGETVALUE events, because we will use the schedule, month, day code, so I write her into a letter, and use:

TExtractDateTo = (extYear, extMonth, extDay); TdmData = class (TWebDataModule) ... ... ... ... ... ... ... ... ... ... ... private procedure ExtractDateToAdapterField (var Value: Variant; AFullValue: Variant; ExtOption: TExtractDateTo); ... ... ... ... ... ... ... ... ... ... ... procedure TdmData.ExtractDateToAdapterField (var Value: Variant; AFullValue: Variant; ExtOption: TExtractDateTo); var vYear, vMonth, vDay: Word; begin DecodeDate (AFullValue, vYear, vMonth, vDay); case ExtOption of extYear : Value: = vYear; extMonth: Value: = vMonth; extDay: Value: = vDay; end; end; procedure TdmData.AdaptSaleDate_YearGetValue (Sender: TObject; var Value: Variant); begin ExtractDateToAdapterField (Value, AdaptSaleDate.Value, extYear) ; end; procedure TdmData.AdaptSaleDate_MonthGetValue (Sender: TObject; var Value: Variant); begin ExtractDateToAdapterField (Value, AdaptSaleDate.Value, extMonth); end; procedure TdmData.AdaptSaleDate_DayGetValue (Sender: T Object; var value: variant; begin extractDatetoadapterfield (value); EXTDAY, END; we start designing the webpage of the programming information, please add a Page Module in the project, named her Edit, then Of course, Uses DMDATA and HOME two modules, and add the title graphics with the guides, then open Visual Page Designer, here we still add two Adapterform, one is to display the title graphics and the guided column, the other is let Users have been used, here we use LayoutGroup to include a web page, so add ADAPTERFIELDGROUP in Adapterform2, and set her Adapter to DMData.dsaorders, and set the custom property to border = "1", which will make this FieldGroup Single box display style:

Add a LayoutGroup under AdapterfieldGroup2, and press the right button to select Add Column, and join the ORDERNO and Custno two columns. We can also use the LayoutGroup's DisplayColumns characteristic value to control these Field ranks, set her 2.

Then add the second LayoutGroup to AdapterfieldGroup2, join our virtual Adapterfield to:

After you finish, you will see this less exciting ranks:

This can be solved by LayoutGroup's DisplayColumns, set the displayColumns of LayoutGroup2 to 3.

The DISPLAYWIDTH, MAXLENGTH, and CAPTION characteristics of these three fields are set.

In the figure, we set the CAPTION of this Field to Saledate and set DisplayWidth and Maxlength to 4, which allows the user to enter the string length, and then empty the two Field caution of the month, and set DisplayWidth, Maxlength is 2.

After adding an AdapterCommandGroup to Adapterform2, the value of Her DisplayComponents is connected to AdapterfieldGroup2, and join the APPLY, Cancel.

OK! This is the web page that is completed into a compilation. It is necessary to return to Grid Module, add an Edit Action at the last information, so that the user can pass the web page that is repaired by this action.

I use HyperLink to display this Edit Action, you can adjust the style of displaying action via setting cmdeditrow, in addition to this feature, we have to set her PageName features for Edit, so you can click on the user After selecting this Action, guiding our programming web.

No mistakes, we have successfully removed a column to three columns. Is this very useful? I believe that you will get a lot of its use from this example, not only the Literature is entered in the date. Next, we will continue to handle the reserved storage, we can handle this issue in this virtual Adapterfield's onupdateValue event:

private ... ... ... ... ... ... ... procedure UpdatePartDate (AField: TDataSetAdapterField; AYear, AMonth, ADay: TAdapterField); ... ... ... ... ... ... ... ... ... procedure TdmData.UpdatePartDate (AField: TDataSetAdapterField; AYear, AMonth, ADay: TAdapterField) , VAR Year, Month, Day: Word; Begin Decodedate (Afield.Value, Year, Month, Day); if Assigned (Ayear.Arth) Then Year: = ayear.Alue.Values ​​[0]; if Assigned (Amonth.ActionValue ) THEN MONTH: = AMONTH.ActionValue.values ​​[0]; if assigned (aday.actionvalue) Then day: = aday.actionValue.values ​​[0]; if (Encodedate (Year, Month, Day) <> dsaorders.DataSet. FieldByName (AField.FieldName) .AsDateTime) then dsaOrders.DataSet.FieldByName (AField.FieldName) .AsDateTime: = EncodeDate (Year, Month, Day); end; procedure TdmData.AdaptSaleDate_YearUpdateValue (Sender: TObject; Value: Variant); begin UpdatePartDate (adaptsaledate, adaptsaledate_mont, adaptsaledate_day; end;! I didn't write, I only wrote an adaptsaratedate_y Ear.onUpdateValue, do you update the three fields? If the user only modifies the month? This is actually very simple, she only needs it to determine whether the user has modified whether the user has modified the webpage. The value in ActionValue is compared with the current value. When there is a value thereof, it will perform Update's actions, which means that when the value in the web page is changed, WebSNAP will be existing. The value of the ActionValue, when there is a value different, the Update action is performed, and the onupdateValue event in Adapterfield is called, which is why I can only write an event to Update 3 Reasons. The small traps such as such a small trap are everywhere in WebSNAP. If you know how to use them, the efficiency of the program will have a considerable help.

12-2 Postback technology

Next we will show how to use Postback technology in WebSNAP, which allows us to deal with the Lookup Field problem, please return to Delphi IDE, join two Table and a DataSource to Web DataModule, and set their Tablename separately For items (order fiction), EMPLOYEE (employee gear), set items with Orders to master-detail: then join a DataSetAdapter, connect to Items Table, and add a DatasetValuelist to Employee Table, and put her namedfield Set to Empno:

The Fields Designer, which is connected to the open DSaorders, adds an Adapterfield, which is used to display the name of the worker name:

After selecting AdapTempno, set her Valuelist to DSVLEMPLOYEE (DataSetValueliSt components of employment workers):

After completing, we can write the relevant program code. We must add a private variable to this module. This is for the status of the status is Postback, or is also a general situation:

PRIVATE FISPOSTBACK: BOOLEAN;

The AdapTempName.onGetValue event called the name of the staff:

procedure TdmData.AdaptEmpNameGetValue (Sender: TObject; var Value: Variant); var LocateValue: Integer; begin if not tbEmployee.Active then tbEmployee.Open; if Assigned (AdaptEmpNo.ActionValue) and FIsPostBack then LocateValue: = AdaptEmpNo.ActionValue.Values ​​[ 0] else LocateValue: = AdaptEmpNo.Value; if tbEmployee.Locate ( 'EmpNo', LocateValue, []) then Value: = tbEmployee.FieldByName ( 'LastName') AsString '' tbEmployee.FieldByName ( 'FirstName').. Asstring else value: = '; end;

We have to write an event for the information after maintaining Postback, that is, the AdaptOrderNo.onGetValue event:

procedure TdmData.AdaptOrderNoGetValue (Sender: TObject; Field: TField; var Value: Variant); begin if Assigned (TDataSetAdapterField (Sender) .ActionValue) and FIsPostBack then Value: = TDataSetAdapterField (Sender) .ActionValue.Values ​​[0] else Value: = FIELD.VALUE; END; set this event to AdapTCustNo, AdapTemPno, Adaptsaledate, Adaptorderno, these four adapterfield:

The Action Designer, which is the most open DSaorders, adds an adaptection, and writes the correlation code, it is completed by Postback's basic capabilities:

procedure TdmData.ActionPostBackExecute (Sender: TObject; Params: TStrings); var vLocateParams: TLocateParams; begin FIsPostBack: = True; vLocateParams: = dsaOrders.LocateParamsList.Add; vLocateParams.AdapterName: = dsaOrders.Name; vLocateParams.AddParam ( 'OrderNo' Adaptorderno.actionValue.Values ​​[0]); dsaorders.locate; end; procedure tdmdata.ActionpostbackaftergetResponse (Sender: Tobject; params: tstrings); begin fispostback: = FALSE; END

Please open the original Edit Module, rewrite the screen of the web page, set the layoutgroup2.displaycolumns 4, then add Empno, Empname, these two columns, turn the Empname's CAPTION CAPTION, and set the viewMode to VMDisplay:

Then add our new POSTBACK ACTION in AdaptercommandGroup2:

Then put her DisplayType characteristics into CTanchor, and PageName is set to Edit:

After completing, please cut to the html page, you will find this HTML code below, react it with her:

Go back to the Browser page, select the Empno field in layoutgroup1, and attach the code on the CUSTOM characteristic value to ONCHANGE:

After completion, remove the Postback action in AdapterCommandGroup2 and press the right click on AdapterPageProducer, add an adapterform, which is used to display the details, add an adaptergrid in her, link to DSAITEMS (order frank DataSetAdapter): This will complete the technology of Postback, the execution screen is as follows:

In this technology, we learned how to use Custom to join Client-Side Script, and use her to complete our Postback technology, this technology is quite interesting, you can try Custno to change to the same SELECT, I believe you will get a lot of inspiration !

This chapter

Postback technology is important in writing a database web page, almost indispensable, so you have to familiarize her, in the above program, we use the Action's AftergetResponse event, and clear the postback flag in the event, this The event will be triggered after the Action executes and generates Response data, just in line with our needs.

转载请注明原文地址:https://www.9cbs.com/read-3109.html

New Post(0)